• 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 #ifndef TEST_COMMON_H
17 #define TEST_COMMON_H
18 
19 #include "jerryscript-port.h"
20 
21 #include <math.h>
22 #include <setjmp.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <string.h>
27 
28 #define JERRY_UNUSED(x) ((void) (x))
29 
30 #define TEST_ASSERT(x) \
31   do \
32   { \
33     if (JERRY_UNLIKELY (!(x))) \
34     { \
35       jerry_port_log (JERRY_LOG_LEVEL_ERROR, \
36                       "TEST: Assertion '%s' failed at %s(%s):%lu.\n", \
37                       #x, \
38                       __FILE__, \
39                       __func__, \
40                       (unsigned long) __LINE__); \
41       jerry_port_fatal (ERR_FAILED_INTERNAL_ASSERTION); \
42     } \
43   } while (0)
44 
45 /**
46  * Test initialization statement that should be included
47  * at the beginning of main function in every unit test.
48  */
49 #define TEST_INIT() \
50 do \
51 { \
52   union { double d; unsigned u; } now = { .d = jerry_port_get_current_time () }; \
53   srand (now.u); \
54 } while (0)
55 
56 /**
57  * Dummy macro to enable the breaking of long string literals into multiple
58  * substrings on separate lines. (Style checker doesn't allow it without putting
59  * the whole literal into parentheses but the compiler warns about parenthesized
60  * string constants.)
61  */
62 #define TEST_STRING_LITERAL(x) x
63 
64 #endif /* !TEST_COMMON_H */
65