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 DEMO_LOG_H
17 #define DEMO_LOG_H
18 
19 #include <cstdio>
20 
21 namespace OHOS {
22 #define LOG_MAX_SIZE 200
23 #define DEMO_CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)                                                             \
24     do {                                                                                                               \
25         if (!(cond)) {                                                                                                 \
26             char ch[LOG_MAX_SIZE];                                                                                     \
27             (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                     \
28             (void)printf("%s\n", ch);                                                                                  \
29             return ret;                                                                                                \
30         }                                                                                                              \
31     } while (0)
32 
33 #define DEMO_CHECK_AND_RETURN_LOG(cond, fmt, ...)                                                                      \
34     do {                                                                                                               \
35         if (!(cond)) {                                                                                                 \
36             char ch[LOG_MAX_SIZE];                                                                                     \
37             (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                     \
38             (void)printf("%s\n", ch);                                                                                  \
39             return;                                                                                                    \
40         }                                                                                                              \
41     } while (0)
42 
43 #define DEMO_CHECK_AND_BREAK_LOG(cond, fmt, ...)                                                                       \
44     if (!(cond)) {                                                                                                     \
45         char ch[LOG_MAX_SIZE];                                                                                         \
46         (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                         \
47         (void)printf("%s\n", ch);                                                                                      \
48         break;                                                                                                         \
49     }
50 
51 #define DEMO_CHECK_AND_CONTINUE_LOG(cond, fmt, ...)                                                                    \
52     if (!(cond)) {                                                                                                     \
53         char ch[LOG_MAX_SIZE];                                                                                         \
54         (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                         \
55         (void)printf("%s\n", ch);                                                                                      \
56         continue;                                                                                                      \
57     }
58 } // namespace OHOS
59 #endif // DEMO_LOG_H