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 21template <typename T1, typename T2> 22void 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 29template <typename T1, typename T2> 30void 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 37template <typename T> 38void AssertFalse(const T &t, const char* printInfo, benchmark::State& state) 39{ 40 if (t) { 41 state.SkipWithError(printInfo); 42 } 43} 44 45template <typename T> 46void AssertTrue(const T &t, const char* printInfo, benchmark::State& state) 47{ 48 if (!t) { 49 state.SkipWithError(printInfo); 50 } 51} 52 53template <typename T1, typename T2> 54void 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 61template <typename T1, typename T2> 62void 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 69template <typename T1, typename T2> 70void 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 77template <typename T1, typename T2> 78void 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 85void 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