• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ecma-helpers.h"
18 
19 #include "test-common.h"
20 
21 /**
22  * Unit test's main function.
23  */
24 int
main(void)25 main (void)
26 {
27   TEST_INIT ();
28 
29   const lit_utf8_byte_t *strings[] =
30   {
31     (const lit_utf8_byte_t *) "1",
32     (const lit_utf8_byte_t *) "0.5",
33     (const lit_utf8_byte_t *) "12345",
34     (const lit_utf8_byte_t *) "12345.123",
35     (const lit_utf8_byte_t *) "1e-45",
36     (const lit_utf8_byte_t *) "-2.5e+38",
37     (const lit_utf8_byte_t *) "NaN",
38     (const lit_utf8_byte_t *) "Infinity",
39     (const lit_utf8_byte_t *) "-Infinity",
40     (const lit_utf8_byte_t *) "0",
41     (const lit_utf8_byte_t *) "0",
42   };
43 
44   const ecma_number_t nums[] =
45   {
46     (ecma_number_t) 1.0,
47     (ecma_number_t) 0.5,
48     (ecma_number_t) 12345.0,
49     (ecma_number_t) 12345.123,
50     (ecma_number_t) 1.0e-45,
51     (ecma_number_t) -2.5e+38,
52     (ecma_number_t) NAN,
53     (ecma_number_t) INFINITY,
54     (ecma_number_t) -INFINITY,
55     (ecma_number_t) +0.0,
56     (ecma_number_t) -0.0
57   };
58 
59   for (uint32_t i = 0;
60        i < sizeof (nums) / sizeof (nums[0]);
61        i++)
62   {
63     lit_utf8_byte_t str[64];
64 
65     lit_utf8_size_t str_size = ecma_number_to_utf8_string (nums[i], str, sizeof (str));
66 
67     if (strncmp ((char *) str, (char *) strings[i], str_size) != 0)
68     {
69       return 1;
70     }
71   }
72 
73   return 0;
74 } /* main */
75