• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef TEST_UTIL_H
16 #define TEST_UTIL_H
17 #include <csignal>
18 #include <cstdarg>
19 #include <cstdio>
20 #include <cstring>
21 #include <string>
22 
23 #if defined(OHOS_JSVM_HAP)
24 
25 #include <hilog/log.h>
26 
27 #ifndef LOG_DOMAIN
28 #define LOG_DEMAIN 0x0202
29 #endif
30 
31 #ifndef LOG_TAG
32 #define LOG_TAG "JSVMTEST_TAG"
33 #endif
34 
35 #endif  // OHOS_JSVM_HAP
36 
37 void Print(const char *str);
38 void FatalError();
39 void PrintErrorMessage(const std::string &cond, const std::string &file, unsigned int line, const char *fmt, ...);
40 
41 #define CHECK_FATAL(cond, fmt, ...)                                                \
42     do {                                                                           \
43         if (!(cond)) {                                                             \
44             PrintErrorMessage(#cond, __FILE__, __LINE__, fmt "\n", ##__VA_ARGS__); \
45             FatalError();                                                          \
46         }                                                                          \
47     } while (0)
48 
49 #define CHECK(cond) CHECK_FATAL(cond, "must be")
50 #endif
51