JavascriptBigIntTests.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "stdafx.h"
  6. #pragma warning(disable:26434) // Function definition hides non-virtual function in base class
  7. #pragma warning(disable:26439) // Implicit noexcept
  8. #pragma warning(disable:26451) // Arithmetic overflow
  9. #pragma warning(disable:26495) // Uninitialized member variable
  10. #include "catch.hpp"
  11. #pragma warning(disable:4100) // unreferenced formal parameter
  12. #pragma warning(disable:6387) // suppressing preFAST which raises warning for passing null to the JsRT APIs
  13. #pragma warning(disable:6262) // CATCH is using stack variables to report errors, suppressing the preFAST warning.
  14. namespace JavascriptBigIntTests
  15. {
  16. void Test_AddDigit(digit_t digit1, digit_t digit2, digit_t * carry, digit_t expectedResult, digit_t expectedCarry)
  17. {
  18. REQUIRE(g_testHooksLoaded);
  19. digit_t res = g_testHooks.pfAddDigit(digit1, digit2, carry);
  20. //test to check that the result from call to AddDigit is the expected value
  21. REQUIRE(res == expectedResult);
  22. REQUIRE(expectedCarry == *carry);
  23. }
  24. void Test_SubDigit(digit_t digit1, digit_t digit2, digit_t * borrow, digit_t expectedResult, digit_t expectedBorrow)
  25. {
  26. REQUIRE(g_testHooksLoaded);
  27. digit_t res = g_testHooks.pfSubDigit(digit1, digit2, borrow);
  28. //test to check that the result from call to SubtractDigit is the expected value
  29. REQUIRE(res == expectedResult);
  30. REQUIRE(*borrow == expectedBorrow);
  31. }
  32. void Test_MulDigit(digit_t digit1, digit_t digit2, digit_t * high, digit_t expectedResult, digit_t expectedHigh)
  33. {
  34. REQUIRE(g_testHooksLoaded);
  35. digit_t res = g_testHooks.pfMulDigit(digit1, digit2, high);
  36. //test to check that the result from call to SubtractDigit is the expected value
  37. REQUIRE(res == expectedResult);
  38. REQUIRE(*high == expectedHigh);
  39. }
  40. TEST_CASE("AddDigit", "[JavascriptBigIntTests]")
  41. {
  42. digit_t carry = 0;
  43. Test_AddDigit(1, 2, &carry, 3, 0);
  44. digit_t d1 = UINTPTR_MAX;
  45. digit_t d2 = UINTPTR_MAX;
  46. carry = 0;
  47. Test_AddDigit(d1, d2, &carry, UINTPTR_MAX-1, 1);
  48. }
  49. TEST_CASE("SubDigit", "[JavascriptBigIntTests]")
  50. {
  51. digit_t borrow = 0;
  52. Test_SubDigit(3, 2, &borrow, 1, 0);
  53. digit_t d1 = 0;
  54. digit_t d2 = 1;
  55. borrow = 0;
  56. Test_SubDigit(d1, d2, &borrow, UINTPTR_MAX, 1);
  57. }
  58. TEST_CASE("MulDigit", "[JavascriptBigIntTests]")
  59. {
  60. digit_t high = 0;
  61. Test_MulDigit(3, 2, &high, 6, 0);
  62. digit_t d1 = UINTPTR_MAX;
  63. digit_t d2 = 2;
  64. high = 0;
  65. Test_MulDigit(d1, d2, &high, UINTPTR_MAX-1, 1);
  66. }
  67. }