Debian Codegraph @

tests/ut_dlog.cpp

raw
1 // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4 #define private public
5 #include "log/LogManager.h"
6 #undef private
7
8 #include "dpathbuf.h"
9 #include "dstandardpaths.h"
10 #include "test_helper.hpp"
11 #include <gtest/gtest.h>
12
13 DCORE_USE_NAMESPACE
14
15 TEST(ut_DLogManager, testDLogManager)
16 {
17 DPathBuf logPath(QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first());
18
19 logPath = logPath / "tests.log";
20
21 ASSERT_EQ(DLogManager::getlogFilePath(), logPath.toString());
22 }
23
24 TEST(ut_DLogManager, testDefaultLogPath)
25 {
26 EnvGuard guard;
27 guard.unset("HOME");
28
29 // unset HOME env will not init default log file path
30 ASSERT_TRUE(DLogManager::getlogFilePath().contains(DStandardPaths::homePath()));
31 }
32
33 TEST(ut_DLogManager, testSetInvalidLogPath)
34 {
35 QString tmp = QDir::tempPath();
36 DLogManager::setlogFilePath(tmp);
37 // set log file path to a dir is not supported
38 ASSERT_NE(DLogManager::getlogFilePath(), tmp);
39 }