1 /* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "ecma-globals.h" 17 extern "C" 18 { 19 #include "ecma-helpers.h" 20 } 21 22 #include "test-common.h" 23 #include <gtest/gtest.h> 24 /** 25 * Unit test's main function. 26 */ 27 class NumberToStringsTest : public testing::Test{ 28 public: SetUpTestCase()29 static void SetUpTestCase() 30 { 31 GTEST_LOG_(INFO) << "NumberToStringsTest SetUpTestCase"; 32 } 33 TearDownTestCase()34 static void TearDownTestCase() 35 { 36 GTEST_LOG_(INFO) << "NumberToStringsTest TearDownTestCase"; 37 } 38 SetUp()39 void SetUp() override {} TearDown()40 void TearDown() override {} 41 42 }; 43 HWTEST_F(NumberToStringsTest, Test001, testing::ext::TestSize.Level1) 44 { 45 TEST_INIT (); 46 47 const lit_utf8_byte_t *strings[] = 48 { 49 (const lit_utf8_byte_t *) "1", 50 (const lit_utf8_byte_t *) "0.5", 51 (const lit_utf8_byte_t *) "12345", 52 (const lit_utf8_byte_t *) "12345.123", 53 (const lit_utf8_byte_t *) "1e-45", 54 (const lit_utf8_byte_t *) "-2.5e+38", 55 (const lit_utf8_byte_t *) "NaN", 56 (const lit_utf8_byte_t *) "Infinity", 57 (const lit_utf8_byte_t *) "-Infinity", 58 (const lit_utf8_byte_t *) "0", 59 (const lit_utf8_byte_t *) "0", 60 }; 61 62 const ecma_number_t nums[] = 63 { 64 (ecma_number_t) 1.0, 65 (ecma_number_t) 0.5, 66 (ecma_number_t) 12345.0, 67 (ecma_number_t) 12345.123, 68 (ecma_number_t) 1.0e-45, 69 (ecma_number_t) -2.5e+38, 70 (ecma_number_t) NAN, 71 (ecma_number_t) INFINITY, 72 (ecma_number_t) -INFINITY, 73 (ecma_number_t) +0.0, 74 (ecma_number_t) -0.0 75 }; 76 77 for (uint32_t i = 0; 78 i < sizeof (nums) / sizeof (nums[0]); 79 i++) 80 { 81 lit_utf8_byte_t str[64]; 82 83 lit_utf8_size_t str_size = ecma_number_to_utf8_string (nums[i], str, sizeof (str)); 84 85 if (strncmp ((char *) str, (char *) strings[i], str_size) != 0) 86 { 87 return; 88 } 89 } 90 return; 91 } 92