1 /* 2 * Copyright (C) 2022 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 "media_log.h" 21 namespace { 22 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "MediaUnitTest"}; 23 } 24 namespace OHOS { 25 #define LOG_MAX_SIZE 200 26 #define UNITTEST_CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 27 do { \ 28 if (!(cond)) { \ 29 (void)printf("%s\n", fmt, ##__VA_ARGS__); \ 30 return ret; \ 31 } \ 32 } while (0) 33 34 #define UNITTEST_CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 35 do { \ 36 if (!(cond)) { \ 37 (void)printf("%s\n", fmt, ##__VA_ARGS__); \ 38 return; \ 39 } \ 40 } while (0) 41 42 #define UNITTEST_CHECK_AND_BREAK_LOG(cond, fmt, ...) \ 43 if (!(cond)) { \ 44 (void)printf("%s\n", fmt, ##__VA_ARGS__); \ 45 break; \ 46 } 47 48 #define UNITTEST_CHECK_AND_CONTINUE_LOG(cond, fmt, ...) \ 49 if (!(cond)) { \ 50 (void)printf("%s\n", fmt, ##__VA_ARGS__); \ 51 continue; \ 52 } 53 #define UNITTEST_INFO_LOG(fmt, ...) \ 54 do { \ 55 char ch[LOG_MAX_SIZE]; \ 56 (void)sprintf_s(ch, LOG_MAX_SIZE, fmt, ##__VA_ARGS__); \ 57 (void)printf("%s", ch); \ 58 (void)printf("\n"); \ 59 MEDIA_LOG(HILOG_INFO, "%{public}s", ch); \ 60 } while (0) 61 } 62 63 #endif // UNITTEST_LOG_H