• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
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 __FUNCTIONALEXT_H__
17 #define __FUNCTIONALEXT_H__
18 
19 #include <dlfcn.h>
20 #include <errno.h>
21 #include <math.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include "test.h"
25 
26 #define EPS (0.00001)
27 #define CMPFLAG 0
28 #define ERREXPECT (-1)
29 #define ONREXPECT 1
30 
31 #define EXPECT_TRUE(fun, c)                \
32     do {                                   \
33         if (!(c))                          \
34             t_error("[%s] failed\n", fun); \
35     } while (0)
36 
37 #define EXPECT_FALSE(fun, c)                \
38     do {                                    \
39         if ((c))                            \
40             t_error("[%s] failed \n", fun); \
41     } while (0)
42 
43 #define EXPECT_EQ(fun, a, b)                               \
44     do {                                                   \
45         if ((a) != (b))                                    \
46             t_error("[%s] failed %d != %d \n", fun, a, b); \
47     } while (0)
48 
49 #define EXPECT_LT(fun, a, b)                                                              \
50     do {                                                                                  \
51         if ((a) >= (b))                                                                   \
52             t_error("[%s] failed (errno: %s)  %d >= %d \n", #fun, strerror(errno), a, b); \
53     } while (0)
54 
55 #define EXPECT_MT(fun, a, b)                                                              \
56     do {                                                                                  \
57         if ((a) <= (b))                                                                   \
58             t_error("[%s] failed (errno: %s)  %d >= %d \n", #fun, strerror(errno), a, b); \
59     } while (0)
60 
61 #define EXPECT_NE(fun, a, b)                                   \
62     do {                                                       \
63         if ((int)(a) == (int)(b))                              \
64             t_error("[%s] failed %d == %d \n", fun, (a), (b)); \
65     } while (0)
66 
67 /* char*, char[] comparison */
68 #define EXPECT_STREQ(fun, a, b)                                \
69     do {                                                       \
70         if (strlen(a) != strlen(b) || strcmp((a), (b)) != 0)   \
71             t_error("[%s] failed %s != %s \n", fun, (a), (b)); \
72     } while (0)
73 
74 #define EXPECT_STRLT(fun, a, b)                                                           \
75     do {                                                                                  \
76         if ((a) >= (b))                                                                   \
77             t_error("[%s] failed (errno: %s)  %d >= %d \n", #fun, strerror(errno), a, b); \
78     } while (0)
79 
80 #define EXPECT_STRMT(fun, a, b)                                                           \
81     do {                                                                                  \
82         if ((a) <= (b))                                                                   \
83             t_error("[%s] failed (errno: %s)  %d >= %d \n", #fun, strerror(errno), a, b); \
84     } while (0)
85 
86 /* floating point comparison */
87 #define FLOAT_EQUAL(fun, a, b)                                   \
88     do {                                                         \
89         if (!(fabs((a) - (b)) <= EPS))                           \
90             t_error("[%s] failed %fd != %fd \n", fun, (a), (b)); \
91     } while (0)
92 
93 #define EXPECT_PTREQ(fun, a, b)                            \
94     do {                                                   \
95         if ((a) != (b)) {                                  \
96             t_error("[%s] failed %p != %p \n", fun, a, b); \
97         }                                                  \
98     } while (0)
99 
100 #define EXPECT_PTRNE(fun, a, b)                            \
101     do {                                                   \
102         if ((a) == (b)) {                                  \
103             t_error("[%s] failed %p == %p \n", fun, a, b); \
104         }                                                  \
105     } while (0)
106 
107 #define EXPECT_STRNE(fun, a, b)                                \
108     do {                                                       \
109         if (strcmp((a), (b)) == 0)                             \
110             t_error("[%s] failed %s == %s \n", fun, (a), (b)); \
111     } while (0)
112 
113 #define EXPECT_LONGEQ(fun, a, b)                             \
114     do {                                                     \
115         if ((long)(a) != (long)(b))                          \
116             t_error("[%s] failed %ld != %ld \n", fun, a, b); \
117     } while (0)
118 
119 #define EXPECT_LONGLONGEQ(fun, a, b)                           \
120     do {                                                       \
121         if ((long)(a) != (long)(b))                            \
122             t_error("[%s] failed %lld != %lld \n", fun, a, b); \
123     } while (0)
124 
125 #define EXPECT_GT(fun, a, b)                               \
126     do {                                                   \
127         if ((a) <= (b)) {                                  \
128             t_error("[%s] failed %d <= %d \n", fun, a, b); \
129         }                                                  \
130     } while (0)
131 
132 #define EXPECT_GTE(fun, a, b)                             \
133     do {                                                  \
134         if ((a) < (b)) {                                  \
135             t_error("[%s] failed %d < %d \n", fun, a, b); \
136         }                                                 \
137     } while (0)
138 
139 #endif
140