1 /*
2  * Copyright (c) 2023 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 ASSERT_H
17 #define ASSERT_H
18 
19 #include <benchmark/benchmark.h>
20 
21 template <typename T1, typename T2>
AssertEqual(const T1 & t1,const T2 & t2,const char * printInfo,benchmark::State & state)22 void AssertEqual(const T1 &t1, const T2 &t2, const char* printInfo, benchmark::State& state)
23 {
24     if (t1 != t2) {
25         state.SkipWithError(printInfo);
26     }
27 }
28 
29 template <typename T1, typename T2>
AssertUnequal(const T1 & t1,const T2 & t2,const char * printInfo,benchmark::State & state)30 void AssertUnequal(const T1 &t1, const T2 &t2, const char* printInfo, benchmark::State& state)
31 {
32     if (t1 == t2) {
33         state.SkipWithError(printInfo);
34     }
35 }
36 
37 template <typename T>
AssertFalse(const T & t,const char * printInfo,benchmark::State & state)38 void AssertFalse(const T &t, const char* printInfo, benchmark::State& state)
39 {
40     if (t) {
41         state.SkipWithError(printInfo);
42     }
43 }
44 
45 template <typename T>
AssertTrue(const T & t,const char * printInfo,benchmark::State & state)46 void AssertTrue(const T &t, const char* printInfo, benchmark::State& state)
47 {
48     if (!t) {
49         state.SkipWithError(printInfo);
50     }
51 }
52 
53 template <typename T1, typename T2>
AssertLessThan(const T1 & t1,const T2 & t2,const char * printInfo,benchmark::State & state)54 void AssertLessThan(const T1 &t1, const T2 &t2, const char* printInfo, benchmark::State& state)
55 {
56     if (t1 >= t2) {
57         state.SkipWithError(printInfo);
58     }
59 }
60 
61 template <typename T1, typename T2>
AssertLessThanOrEqual(const T1 & t1,const T2 & t2,const char * printInfo,benchmark::State & state)62 void AssertLessThanOrEqual(const T1 &t1, const T2 &t2, const char* printInfo, benchmark::State& state)
63 {
64     if (t1 > t2) {
65         state.SkipWithError(printInfo);
66     }
67 }
68 
69 template <typename T1, typename T2>
AssertGreaterThan(const T1 & t1,const T2 & t2,const char * printInfo,benchmark::State & state)70 void AssertGreaterThan(const T1 &t1, const T2 &t2, const char* printInfo, benchmark::State& state)
71 {
72     if (t1 <= t2) {
73         state.SkipWithError(printInfo);
74     }
75 }
76 
77 template <typename T1, typename T2>
AssertGreaterThanOrEqual(const T1 & t1,const T2 & t2,const char * printInfo,benchmark::State & state)78 void AssertGreaterThanOrEqual(const T1 &t1, const T2 &t2, const char* printInfo, benchmark::State& state)
79 {
80     if (t1 < t2) {
81         state.SkipWithError(printInfo);
82     }
83 }
84 
AssertStringEqual(const char * str1,const char * str2,const char * printInfo,benchmark::State & state)85 void AssertStringEqual(const char* str1, const char* str2, const char* printInfo, benchmark::State& state)
86 {
87     if (strcmp(str1, str2) != 0) {
88         state.SkipWithError(printInfo);
89     }
90 }
91 #endif