1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci * 3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci * You may obtain a copy of the License at 6425bb815Sopenharmony_ci * 7425bb815Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci * 9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci * limitations under the License. 14425bb815Sopenharmony_ci */ 15425bb815Sopenharmony_ci 16425bb815Sopenharmony_ci#include "ecma-globals.h" 17425bb815Sopenharmony_ciextern "C" 18425bb815Sopenharmony_ci{ 19425bb815Sopenharmony_ci #include "ecma-helpers.h" 20425bb815Sopenharmony_ci} 21425bb815Sopenharmony_ci 22425bb815Sopenharmony_ci#include "test-common.h" 23425bb815Sopenharmony_ci#include <gtest/gtest.h> 24425bb815Sopenharmony_ci/** 25425bb815Sopenharmony_ci * Unit test's main function. 26425bb815Sopenharmony_ci */ 27425bb815Sopenharmony_ciclass NumberToStringsTest : public testing::Test{ 28425bb815Sopenharmony_cipublic: 29425bb815Sopenharmony_ci static void SetUpTestCase() 30425bb815Sopenharmony_ci { 31425bb815Sopenharmony_ci GTEST_LOG_(INFO) << "NumberToStringsTest SetUpTestCase"; 32425bb815Sopenharmony_ci } 33425bb815Sopenharmony_ci 34425bb815Sopenharmony_ci static void TearDownTestCase() 35425bb815Sopenharmony_ci { 36425bb815Sopenharmony_ci GTEST_LOG_(INFO) << "NumberToStringsTest TearDownTestCase"; 37425bb815Sopenharmony_ci } 38425bb815Sopenharmony_ci 39425bb815Sopenharmony_ci void SetUp() override {} 40425bb815Sopenharmony_ci void TearDown() override {} 41425bb815Sopenharmony_ci 42425bb815Sopenharmony_ci}; 43425bb815Sopenharmony_ciHWTEST_F(NumberToStringsTest, Test001, testing::ext::TestSize.Level1) 44425bb815Sopenharmony_ci{ 45425bb815Sopenharmony_ci TEST_INIT (); 46425bb815Sopenharmony_ci 47425bb815Sopenharmony_ci const lit_utf8_byte_t *strings[] = 48425bb815Sopenharmony_ci { 49425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "1", 50425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "0.5", 51425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "12345", 52425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "12345.123", 53425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "1e-45", 54425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "-2.5e+38", 55425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "NaN", 56425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "Infinity", 57425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "-Infinity", 58425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "0", 59425bb815Sopenharmony_ci (const lit_utf8_byte_t *) "0", 60425bb815Sopenharmony_ci }; 61425bb815Sopenharmony_ci 62425bb815Sopenharmony_ci const ecma_number_t nums[] = 63425bb815Sopenharmony_ci { 64425bb815Sopenharmony_ci (ecma_number_t) 1.0, 65425bb815Sopenharmony_ci (ecma_number_t) 0.5, 66425bb815Sopenharmony_ci (ecma_number_t) 12345.0, 67425bb815Sopenharmony_ci (ecma_number_t) 12345.123, 68425bb815Sopenharmony_ci (ecma_number_t) 1.0e-45, 69425bb815Sopenharmony_ci (ecma_number_t) -2.5e+38, 70425bb815Sopenharmony_ci (ecma_number_t) NAN, 71425bb815Sopenharmony_ci (ecma_number_t) INFINITY, 72425bb815Sopenharmony_ci (ecma_number_t) -INFINITY, 73425bb815Sopenharmony_ci (ecma_number_t) +0.0, 74425bb815Sopenharmony_ci (ecma_number_t) -0.0 75425bb815Sopenharmony_ci }; 76425bb815Sopenharmony_ci 77425bb815Sopenharmony_ci for (uint32_t i = 0; 78425bb815Sopenharmony_ci i < sizeof (nums) / sizeof (nums[0]); 79425bb815Sopenharmony_ci i++) 80425bb815Sopenharmony_ci { 81425bb815Sopenharmony_ci lit_utf8_byte_t str[64]; 82425bb815Sopenharmony_ci 83425bb815Sopenharmony_ci lit_utf8_size_t str_size = ecma_number_to_utf8_string (nums[i], str, sizeof (str)); 84425bb815Sopenharmony_ci 85425bb815Sopenharmony_ci if (strncmp ((char *) str, (char *) strings[i], str_size) != 0) 86425bb815Sopenharmony_ci { 87425bb815Sopenharmony_ci return; 88425bb815Sopenharmony_ci } 89425bb815Sopenharmony_ci } 90425bb815Sopenharmony_ci return; 91425bb815Sopenharmony_ci} 92