LibhilogCPPtest.cpp 37.7 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <cstdarg>
#include <ctime>
#include <ostream>
#include <streambuf>
#include <queue>
#include <securec.h>
#include <pthread.h>
#include <sys/time.h>
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#include <gtest/gtest.h>
#include "file_utils.h"
using namespace OHOS;
using namespace HiviewDFX;
using namespace testing::ext;
#define MAX_LINE  ((1024) * (10))
#define MAXBUFFSIZE 1024
class LibhilogCPPtest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
private:
};
void LibhilogCPPtest::SetUp()
{
    CleanCmd();
}
void LibhilogCPPtest::TearDown()
{
}
void LibhilogCPPtest::SetUpTestCase()
{
}
void LibhilogCPPtest::TearDownTestCase()
{
    std::cout << "TearDownTestCase" << std::endl;
}

/**
 * @tc.name Provides user-mode interfaces(CPP)INFO
 * @tc.number DFX_DFT_HilogCPP_0100
 * @tc.desc Provides user-mode interfaces(CPP)INFO
 */
HWTEST_F(LibhilogCPPtest, HILOG_INFO_CPP, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    int i = 1;
    HiLog::Info(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,"
    "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
73 74
    std::string expected{"I 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
75
    sleep(1);
76
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
M
mamingshuai 已提交
77 78
    std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
79
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
80
}
M
mamingshuai 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

/**
 * @tc.name Provides user-mode interfaces(CPP)debug
 * @tc.number DFX_DFT_HilogCPP_0090
 * @tc.desc Provides user-mode interfaces(CPP)debug
 */
HWTEST_F(LibhilogCPPtest, HILOG_DEBUG_CPP, Function|MediumTest|Level0)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    int i = 1;
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Debug(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,"
    "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
100 101
    std::string expected{"D 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
102
    sleep(1);
103
    CmdRun("hilog -L D -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
M
mamingshuai 已提交
104 105
    std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
106
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
}

/**
 * @tc.name Provides user-mode interfaces(CPP)warning
 * @tc.number DFX_DFT_HilogCPP_0130
 * @tc.desc Provides user-mode interfaces(CPP)warning
 */
HWTEST_F(LibhilogCPPtest, HILOG_WARNING_CPP, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    int i = 1;
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Warn(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,%{private}lf,"
    "%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
127 128
    std::string expected{"W 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
129
    sleep(1);
130
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
M
mamingshuai 已提交
131 132
    std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
133
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
}

/**
 * @tc.name Provides user-mode interfaces(CPP)error
 * @tc.number DFX_DFT_HilogCPP_0110
 * @tc.desc Provides user-mode interfaces(CPP)error
  */
HWTEST_F(LibhilogCPPtest, HILOG_ERROR_CPP, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    int i = 1;
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Error(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,"
    "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
154 155
    std::string expected{"E 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
156
    sleep(1);
157
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
M
mamingshuai 已提交
158 159
    std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
160
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
}

/**
 * @tc.name Provides user-mode interfaces(CPP)fatal
 * @tc.number DFX_DFT_HilogCPP_0120
 * @tc.desc Provides user-mode interfaces(CPP)fatal
 */
HWTEST_F(LibhilogCPPtest, HILOG_FATAL_CPP, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    int i = 1;
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,"
    "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
181 182
    std::string expected{"F 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
183
    sleep(1);
184
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
M
mamingshuai 已提交
185 186
    std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
    std::cout<<"expected = " + expected<<std::endl;
187
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
}

/**
 * @tc.desc libhilog-log integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2090
 * @tc.desc libhilog-log integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "INTEGER:%{private}d,%{public}d,%d;", 1, 1, 1);
    std::string expected{"INTEGER:<private>,1,<private>;"};
207
    sleep(1);
208
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
209
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
}

/**
 * @tc.name libhilog-log long integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2100
 * @tc.desc libhilog-log long integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_LONG_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "INTEGER_long:%{private}ld,%{public}ld,%ld;", 2147483647L, 2147483647L, 2147483647L);
    std::string expected{"INTEGER_long:<private>,2147483647,<private>;"};
229
    sleep(1);
230
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
231
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
}

/**
 * @tc.name libhilog-log fixed-length integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2110
 * @tc.desc libhilog-log fixed-length integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_4_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "INTEGER_4:%{private}4d,%{public}4d,%4d;", 2000, 2000, 2000);
    std::string expected{"INTEGER_4:<private>,2000,<private>;"};
251
    sleep(1);
252
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
253
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
}

/**
 * @tc.name libhilog-log short integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2120
 * @tc.desc libhilog-log short integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_SHORT_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "INTEGER_short:%{private}hd,%{public}hd,%hd;", (short)1024, (short)1024, (short)1024);
    std::string expected{"INTEGER_short:<private>,1024,<private>;"};
273
    sleep(1);
274
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
275
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
}

/**
 * @tc.name libhilog-log unsigned integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2130
 * @tc.desc libhilog-log unsigned integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_UN_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "INTEGER_un:%{private}u,%{public}u,%u;", 2147483647u, 2147483647u, 2147483647u);
    std::string expected{"INTEGER_un:<private>,2147483647,<private>;"};
295
    sleep(1);
296
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
297
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
}

/**
 * @tc.name libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2140
 * @tc.desc libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_LONG_UN_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "INTEGER_long_un:%{private}lu,%{public}lu,%lu;", 7483647ul, 2147483647ul, 2147483647ul);
    std::string expected{"INTEGER_long_un:<private>,2147483647,<private>;"};
317
    sleep(1);
318
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
319
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
}

/**
 * @tc.name libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2150
 * @tc.desc libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_4_UN_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "INTEGER_4_un:%{private}4u,%{public}4u,%4u;", 4000, 4000, 4000);
    std::string expected{"INTEGER_4_un:<private>,4000,<private>;"};
339
    sleep(1);
340
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
341
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
}

/**
 * @tc.name libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2160
 * @tc.desc libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_SHORT_UN_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "INTEGER_short_un:%{private}hu,%{public}hu,%hu;", (unsigned short)65535,
    (unsigned short)65535, (unsigned short)65535);
    std::string expected{"INTEGER_short_un:<private>,65535,<private>;"};
362
    sleep(1);
363
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
364
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
}

/**
 * @tc.name libhilog-log float type identifier format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2170
 * @tc.desc libhilog-log float type identifier format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "FLOAT:%{private}f,%{public}f,%f;", 1.01, 1.01, 1.01);
    std::string expected{"FLOAT:<private>,1.010000,<private>;"};
384
    sleep(1);
385
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
386
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
}

/**
 * @tc.name libhilog-log long float type identifier format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2180
 * @tc.desc libhilog-log long float type identifier format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_LONG_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "FLOAT_long:%{private}lf,%{public}lf,%lf;", 2.147483647, 2.147483647, 2.147483647);
    std::string expected{"FLOAT_long:<private>,2.147484,<private>;"};
406
    sleep(1);
407
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
408
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
}

/**
 * @tc.name libhilog-Formatting of fixed-width floating-point identifiers in
 *          the decimal part of the log ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2190
 * @tc.desc libhilog-Formatting of fixed-width floating-point identifiers in
 *          the decimal part of the log ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_POINT2_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "FLOAT_.2:%{private}.2f,%{public}.2f,%.2f;", 2.147483647, 2.147483647, 2.147483647);
    std::string expected{"FLOAT_.2:<private>,2.15,<private>;"};
430
    sleep(1);
431
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
432
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
}

/**
 * @tc.name libhilog-Formatting of floating-point identifiers for
 *          the decimal part and integer part of the log ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2200
 * @tc.desc libhilog-Formatting of floating-point identifiers for
 *          the decimal part and integer part of the log ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_3POINT2_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "FLOAT_3.2:%{private}3.2f,%{public}4.1f,%2.6f;", 32.147483647, 321.147483647, 23.147483647);
    std::string expected{"FLOAT_3.2:<private>,321.1,<private>;"};
454
    sleep(1);
455
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
456
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
}

/**
 * @tc.name libhilog-Formatting log characters ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2210
 * @tc.desc libhilog-Formatting log characters ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_CHAR_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "CHAR:%{private}c,%{public}c,%c;", 'a', 'b', 'c');
    std::string expected{"CHAR:<private>,b,<private>;"};
476
    sleep(1);
477
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
478
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
}

/**
 * @tc.name libhilog-Formatting log octal identifier ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2250
 * @tc.desc libhilog-Formatting log octal identifier ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_OCTAL_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "OCTAL:%{private}o,%{public}o,%o;", 15, 16, 17);
    std::string expected{"OCTAL:<private>,20,<private>;"};
498
    sleep(1);
499
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
500
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
}

/**
 * @tc.name libhilog-Formatting log long octal identifier ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2260
 * @tc.desc libhilog-Formatting log long octal identifier ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_OCTAL_LONG_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "OCTAL_long:%{private}lo,%{public}lo,%lo;", 18ul, 19ul, 20ul);
    std::string expected{"OCTAL_long:<private>,23,<private>;"};
520
    sleep(1);
521
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
522
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
}

/**
 * @tc.name libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2270
 * @tc.desc libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_HEX_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "HEX:%{private}x,%{public}x,%x;", 15, 16, 17);
    std::string expected{"HEX:<private>,10,<private>;"};
542
    sleep(1);
543
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
544
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
}

/**
 * @tc.name libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2280
 * @tc.desc libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_HEX_UPPER_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "HEX_#:%{private}#x,%{public}#x,%#x;", 18, 19, 20);
    std::string expected{"HEX_#:<private>,0x13,<private>;"};
564
    sleep(1);
565
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
566
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
}

/**
 * @tc.name libhilog-Logs are formatted with long hexadecimal identifiers
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2290
 * @tc.desc libhilog-Logs are formatted with long hexadecimal identifiers
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_HEX_LONG_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "HEX_long:%{private}lx,%{public}lx,%lx;", 21l, 22l, 23l);
    std::string expected{"HEX_long:<private>,16,<private>;"};
588
    sleep(1);
589
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
590
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
}

/**
 * @tc.name libhilog-Logs are formatted with uppercase hexadecimal flags
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2300
 * @tc.desc libhilog-Logs are formatted with uppercase hexadecimal flags
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_HEX_X_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "HEX_X:%{private}X,%{public}X,%X;", 24u, 25u, 26u);
    std::string expected{"HEX_X:<private>,19,<private>;"};
612
    sleep(1);
613
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
614
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
}

/**
 * @tc.name libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2310
 * @tc.desc libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_HEX_UPPER_X_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "HEX_#X:%{private}#X,%{public}#X,%#X;", 27, 28, 28);
    std::string expected{"HEX_#X:<private>,0X1C,<private>;"};
636
    sleep(1);
637
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
638
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
}

/**
 * @tc.name libhilog-Logs are formatted with uppercase long hexadecimal identifiers
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2320
 * @tc.desc libhilog-Logs are formatted with uppercase long hexadecimal identifiers
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_HEX_LONG_UPPER_X_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "HEX_long_X:%{private}lX,%{public}lX,%lX;", 30ul, 31ul, 32ul);
    std::string expected{"HEX_long_X:<private>,1F,<private>;"};
660
    sleep(1);
661
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
662
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
}

/**
 * @tc.name libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2220
 * @tc.desc libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_STR_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "STRING:%{private}s,%{public}s,%s;", "STRING1", "STRING2", "STRING3");
    std::string expected{"STRING:<private>,STRING2,<private>;"};
682
    sleep(1);
683
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
684
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
}

/**
 * @tc.name libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2240
 * @tc.desc libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_STR_EMPTY_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "STRING_empty:%{private}s,%{public}s,%s;", "", "", "");
    std::string expected{"STRING_empty:<private>,,<private>;"};
704
    sleep(1);
705
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
706
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
}

/**
 * @tc.name libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2230
 * @tc.desc libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_STR_CHINESE_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "STRING_Chinese:%{private}s,%{public}s,%s;", "中文", "中文", "中文");
    std::string expected{"STRING_Chinese:<private>,中文,<private>;"};
726
    sleep(1);
727
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
728
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
}

/**
 * @tc.name libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2330
 * @tc.desc libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_E_DOUBLE_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "DOUBLE_e:%{private}e,%{public}e,%e;", 1e-30, 2.231e10, 3.999e-13);
    std::string expected{"DOUBLE_e:<private>,2.231000e+10,<private>;"};
748
    sleep(1);
749
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
750
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
}

/**
 * @tc.name libhilog-Formatting Log whith scientific notation capitalized identifiers
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2340
 * @tc.desc libhilog-Formatting Log whith scientific notation capitalized identifiers
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_E_UPPER_DOUBLE_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "DOUBLE_E:%{private}E,%{public}E,%E;", 4.88E2, 5.676767e-2, 6.17E13);
    std::string expected{"DOUBLE_E:<private>,5.676767E-02,<private>;"};
772
    sleep(1);
773
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
774
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
}

/**
 * @tc.name libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers
 *          ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2350
 * @tc.desc libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers
 *          ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_E_AUTO_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "AUTO:%{private}g,%{public}g,%g;", 1e-30, 2.231e10, 3.999e-13);
    std::string expected{"AUTO:<private>,2.231e+10,<private>;"};
796
    sleep(1);
797
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
798
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
}

/**
 * @tc.name libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized
 *          identifiers ({public}, {private}, no identifier)
 * @tc.number DFX_DFT_HilogCPP_2360
 * @tc.desc libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized
 *          identifiers ({public}, {private}, no identifier)
 */
HWTEST_F(LibhilogCPPtest, HILOG_E_UPPER_AUTO_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "AUTO_E:%{private}G,%{public}G,%G;", 4.88E2, 5.676767e-2, 6.17E13);
    std::string expected{"AUTO_E:<private>,0.0567677,<private>;"};
820
    sleep(1);
821
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
822
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
}

/**
 * @tc.name libhilog-The {private} flag parameter of mixed log formatting is hidden
 * @tc.number DFX_DFT_HilogCPP_31
 * @tc.desc libhilog-The {private} flag parameter of mixed log formatting is hidden
 */
HWTEST_F(LibhilogCPPtest, HILOG_PRIVATE_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "private:%{private}d,%{private}lf,%{private}.2f,%{private}s,%{private}c",
    1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"private:<private>,<private>,<private>,<private>,<private>"};
843
    sleep(1);
844
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
845
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
}

/**
 * @tc.name libhilog-The parameters identified by {public} in mixed log formatting are displayed
 * @tc.number DFX_DFT_HilogCPP_31
 * @tc.desc libhilog-The parameters identified by {public} in mixed log formatting are displayed
 */
HWTEST_F(LibhilogCPPtest, HILOG_PUBLIC_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "public:%{public}d,%{public}lf,%{public}.2f,%{public}s,%{public}c",
    1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"public:1,1.000010,2.33,sse,a"};
866
    sleep(1);
867
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
868
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
}

/**
 * @tc.name libhilog-Parameters without any privacy flag are not displayed in mixed log formatting
 * @tc.number DFX_DFT_HilogCPP_31
 * @tc.desc libhilog-Parameters without any privacy flag are not displayed in mixed log formatting
 */
HWTEST_F(LibhilogCPPtest, HILOG_NO_SIGN_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "no_sign:%d,%lf,%.2f,%s,%c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"no_sign:<private>,<private>,<private>,<private>,<private>"};
888
    sleep(1);
889
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
890
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
}

/**
 * @tc.name libhilog-Log privacy flags are used together, and parameters are
 *          correctly displayed or hidden
 * @tc.number DFX_DFT_HilogCPP_31
 * @tc.desc libhilog-Log privacy flags are used together, and parameters are
 *          correctly displayed or hidden
 */
HWTEST_F(LibhilogCPPtest, HILOG_MIX_CPP, Function|MediumTest|Level3)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tag;
    HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"MIX:1,<private>,2.33,<private>,<private>"};
912
    sleep(1);
913
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
914
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
}

/**
 * @tc.name libhilog-log are not truncated with normal length tag
 * @tc.number DFX_DFT_HilogCPP_0280
 * @tc.desc libhilog-log are not truncated with normal length tag
 */
HWTEST_F(LibhilogCPPtest, TAG_CHECK_CPP, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tagNormal;
    HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"};
934
    sleep(1);
935
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
936
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
}

/**
 * @tc.name libhilog-log are truncated with too long tag
 * @tc.number DFX_DFT_HilogCPP_0290
 * @tc.desc libhilog-log are truncated with too long tag
 */
HWTEST_F(LibhilogCPPtest, TAG_OVER_CHECK_CPP, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd003200;
    const char *tagToolong = "HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0"
    "HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tagToolong;
    HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST_:"};
957
    sleep(1);
958
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST_", cmdRunResult);
959
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
}

/**
 * @tc.name libhilog-log domain
 * @tc.number DFX_DFT_HilogCPP_0270
 * @tc.desc libhilog-log domain
 */
HWTEST_F(LibhilogCPPtest, DOMAIN_CHECK_CPP, Function|MediumTest|Level1)
{
    std::string cmdRunResult;
    LogType type = LOG_CORE;
    const unsigned int domain = 0xd001111;
    const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tagNormal;
    HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"01111/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"};
979
    sleep(1);
980
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
981
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
}

/**
 * @tc.name libhilog-log LOG_APP type test
 * @tc.number DFX_DFT_HilogCPP_0280
 * @tc.desc libhilog-log LOG_APP type test
 */
HWTEST_F(LibhilogCPPtest, TYPE_APP_CHECK_CPP, Function|MediumTest|Level2)
{
    std::string cmdRunResult;
    LogType type = LOG_APP;
    const unsigned int domain = 0xd003200;
    const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
    HiLogLabel a;
    a.type = type;
    a.domain = domain;
    a.tag = tagNormal;
    HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
    std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"};
1001
    sleep(1);
1002
    CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
1003
    ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
M
mamingshuai 已提交
1004
}