File: ut_dlog.cpp

package info (click to toggle)
dtkcore 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,728 kB
  • sloc: cpp: 22,021; ansic: 183; python: 68; xml: 58; makefile: 27; sh: 15
file content (39 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download
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
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#define private public
#include "log/LogManager.h"
#undef private

#include "dpathbuf.h"
#include "dstandardpaths.h"
#include "test_helper.hpp"
#include <gtest/gtest.h>

DCORE_USE_NAMESPACE

TEST(ut_DLogManager, testDLogManager)
{
    DPathBuf logPath(QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first());

    logPath = logPath / "tests.log";

    ASSERT_EQ(DLogManager::getlogFilePath(), logPath.toString());
}

TEST(ut_DLogManager, testDefaultLogPath)
{
    EnvGuard guard;
    guard.unset("HOME");

    // unset HOME env will not init default log file path
    ASSERT_TRUE(DLogManager::getlogFilePath().contains(DStandardPaths::homePath()));
}

TEST(ut_DLogManager, testSetInvalidLogPath)
{
    QString tmp = QDir::tempPath();
    DLogManager::setlogFilePath(tmp);
    // set log file path to a dir is not supported
    ASSERT_NE(DLogManager::getlogFilePath(), tmp);
}