• 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 "avcodec_log.h"
21 #include "securec.h"
22 
23 namespace {
24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecUnitTest"};
25 }
26 namespace OHOS {
27 #define LOG_MAX_SIZE 200
28 #define UNITTEST_CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)                                                         \
29     do {                                                                                                               \
30         if (!(cond)) {                                                                                                 \
31             char ch[LOG_MAX_SIZE];                                                                                     \
32             (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                     \
33             (void)printf("%s", ch);                                                                                    \
34             (void)printf("\n");                                                                                        \
35             return ret;                                                                                                \
36         }                                                                                                              \
37     } while (0)
38 
39 #define UNITTEST_CHECK_AND_RETURN_LOG(cond, fmt, ...)                                                                  \
40     do {                                                                                                               \
41         if (!(cond)) {                                                                                                 \
42             char ch[LOG_MAX_SIZE];                                                                                     \
43             (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                     \
44             (void)printf("%s", ch);                                                                                    \
45             (void)printf("\n");                                                                                        \
46             return;                                                                                                    \
47         }                                                                                                              \
48     } while (0)
49 
50 #define UNITTEST_CHECK_AND_BREAK_LOG(cond, fmt, ...)                                                                   \
51     if (!(cond)) {                                                                                                     \
52         char ch[LOG_MAX_SIZE];                                                                                         \
53         (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                         \
54         (void)printf("%s", ch);                                                                                        \
55         (void)printf("\n");                                                                                            \
56         break;                                                                                                         \
57     }
58 
59 #define UNITTEST_CHECK_AND_CONTINUE_LOG(cond, fmt, ...)                                                                \
60     if (!(cond)) {                                                                                                     \
61         char ch[LOG_MAX_SIZE];                                                                                         \
62         (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                         \
63         (void)printf("%s", ch);                                                                                        \
64         (void)printf("\n");                                                                                            \
65         continue;                                                                                                      \
66     }
67 
68 #define UNITTEST_INFO_LOG(fmt, ...)                                                                                    \
69     do {                                                                                                               \
70         char ch[LOG_MAX_SIZE];                                                                                         \
71         (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__);                                                         \
72         (void)printf("%s", ch);                                                                                        \
73         (void)printf("\n");                                                                                            \
74         AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Info, "%{public}s", ch);                                                 \
75     } while (0)
76 } // namespace OHOS
77 
78 #endif // UNITTEST_LOG_H