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