Fix coding guidelines issues
[platform/core/api/connection.git] / unittest / include / assert_local.h
1 //
2 // Copyright (c) 2020 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #ifndef _ASSERT_H_
17 #define _ASSERT_H_
18 #include <stdio.h>
19 #include <stdlib.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define assert(exp) \
26         do { \
27                 if (!(exp)) { \
28                         fprintf(stderr, \
29                                 "\n[TCT][%s][Line : %d] Assert Fail; Following expression is not true: %s\n", \
30                                 __FILE__, __LINE__, #exp); \
31                         return 1; \
32                 } \
33         } while (0)
34
35 #define assert_eq(var, ref) \
36         do { \
37                 if (var != ref) { \
38                         fprintf(stderr, \
39                                 "\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) and (%s == 0x%x) are not equal\n", \
40                                 __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
41                         return 1; \
42                 } \
43         } while (0)
44
45 #define assert_eq_no_return(var, ref) \
46         do { \
47                 if (var != ref) { \
48                         fprintf(stderr, \
49                                 "\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) and (%s == 0x%x) are not equal\n", \
50                                 __FILE__, __LINE__, #var, (int)var, #ref, (int)ref); \
51                         return ; \
52                 } \
53         } while (0)
54
55 #define assert_neq_no_return(var, ref) \
56         do { \
57                 if (var == ref) { \
58                         fprintf(stderr, \
59                                 "\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) and (%s == 0x%x) are equal\n", \
60                                 __FILE__, __LINE__,  #var, (int)var, #ref, (int)ref); \
61                         return ; \
62                 } \
63         } while (0)
64
65 #define assert_neq(var, ref) \
66         do { \
67                 if (var == ref) { \
68                         fprintf(stderr, \
69                                 "\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) and (%s == 0x%x) are equal\n", \
70                                 __FILE__, __LINE__,  #var, (int)var, #ref, (int)ref); \
71                         return 1; \
72                 } \
73         } while (0)
74
75 #define assert_gt(var, ref) \
76         do { \
77                 if (var <= ref) { \
78                         fprintf(stderr, \
79                                 "\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not greater than (%s == 0x%x)\n", \
80                                 __FILE__, __LINE__,  #var, (int)var, #ref, (int)ref); \
81                         return 1; \
82                 } \
83         } while (0)
84
85 #define assert_geq(var, ref) \
86         do { \
87                 if (var < ref) { \
88                         fprintf(stderr, \
89                                 "\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not greater than or equal to (%s == 0x%x)\n", \
90                                 __FILE__, __LINE__,  #var, (int)var, #ref, (int)ref); \
91                         return 1; \
92                 } \
93         } while (0)
94
95 #define assert_lt(var, ref) \
96         do { \
97                 if (var >= ref) { \
98                         fprintf(stderr, \
99                                 "\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not lower than (%s == 0x%x)\n", \
100                                 __FILE__, __LINE__,  #var, (int)var, #ref, (int)ref); \
101                         return 1; \
102                 } \
103         } while (0)
104
105 #define assert_leq(var, ref) \
106         do { \
107                 if (var > ref) { \
108                         fprintf(stderr, \
109                                 "\n[TCT][%s][Line : %d] Assert fail; Values (%s == 0x%x) is not lower than or equal to (%s == 0x%x)\n", \
110                                 __FILE__, __LINE__,  #var, (int)var, #ref, (int)ref); \
111                         return 1; \
112                 } \
113         } while (0)
114
115 #ifdef __cplusplus
116 }
117 #endif
118 #endif //  _ASSERT_H_