• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 UNITTEST_LOG_H
17 #define UNITTEST_LOG_H
18 
19 #include <cstdio>
20 #include "securec.h"
21 #ifdef TEST_ID
22 #include "avcodec_log.h"
23 #endif
24 
25 namespace OHOS {
26 #define LOG_MAX_SIZE 200
27 
28 #ifdef TEST_ID
29 #define PRINT_TEST_LOG(ch)                                                                                             \
30     do {                                                                                                               \
31         AVCODEC_LOGI("[%{public}d] %{public}s", TEST_ID, ch);                                                          \
32         (void)printf("[%s:%d][%d] %s", __func__, __LINE__, TEST_ID, ch);                                               \
33     } while (0)
34 #else
35 #define PRINT_TEST_LOG(ch)                                                                                             \
36     do {                                                                                                               \
37         (void)printf("[%s:%d] %s", __func__, __LINE__, ch);                                                            \
38     } while (0)
39 #endif
40 
41 #define UNITTEST_CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)                                                         \
42     do {                                                                                                               \
43         if (!(cond)) {                                                                                                 \
44             char ch[LOG_MAX_SIZE];                                                                                     \
45             (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                     \
46             PRINT_TEST_LOG(ch);                                                                                        \
47             (void)printf("\n");                                                                                        \
48             return ret;                                                                                                \
49         }                                                                                                              \
50     } while (0)
51 
52 #define UNITTEST_CHECK_AND_RETURN_LOG(cond, fmt, ...)                                                                  \
53     do {                                                                                                               \
54         if (!(cond)) {                                                                                                 \
55             char ch[LOG_MAX_SIZE];                                                                                     \
56             (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                     \
57             PRINT_TEST_LOG(ch);                                                                                        \
58             (void)printf("\n");                                                                                        \
59             return;                                                                                                    \
60         }                                                                                                              \
61     } while (0)
62 
63 #define UNITTEST_CHECK_AND_INFO_LOG(cond, fmt, ...)                                                                    \
64     do {                                                                                                               \
65         if (!(cond)) {                                                                                                 \
66             char ch[LOG_MAX_SIZE];                                                                                     \
67             (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                     \
68             PRINT_TEST_LOG(ch);                                                                                        \
69             (void)printf("\n");                                                                                        \
70         }                                                                                                              \
71     } while (0)
72 
73 #define UNITTEST_CHECK_AND_BREAK_LOG(cond, fmt, ...)                                                                   \
74     if (!(cond)) {                                                                                                     \
75         char ch[LOG_MAX_SIZE];                                                                                         \
76         (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                         \
77         PRINT_TEST_LOG(ch);                                                                                            \
78         (void)printf("\n");                                                                                            \
79         break;                                                                                                         \
80     }
81 
82 #define UNITTEST_CHECK_AND_CONTINUE_LOG(cond, fmt, ...)                                                                \
83     if (!(cond)) {                                                                                                     \
84         char ch[LOG_MAX_SIZE];                                                                                         \
85         (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                         \
86         PRINT_TEST_LOG(ch);                                                                                            \
87         (void)printf("\n");                                                                                            \
88         continue;                                                                                                      \
89     }
90 
91 #define UNITTEST_INFO_LOG(fmt, ...)                                                                                    \
92     do {                                                                                                               \
93         char ch[LOG_MAX_SIZE];                                                                                         \
94         (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                         \
95         PRINT_TEST_LOG(ch);                                                                                            \
96         (void)printf("\n");                                                                                            \
97     } while (0)
98 } // namespace OHOS
99 
100 #endif // UNITTEST_LOG_H