mirror of https://github.com/linuxdeepin/dtkcore
fix(build): skip failed unit test
- gsettings schema remvove from dtkcommon, Skip - if DSYSINFO_PREFIX empty, Skip - add_definitions ==> target_compile_definitions - setting cache variable move to dtkcore.cmake
This commit is contained in:
parent
8d8bf815f4
commit
844a68df95
|
@ -16,6 +16,8 @@ set (TOOL_INSTALL_DIR "${CMAKE_INSTALL_LIBEXECDIR}/dtk${PROJECT_VERSION_MAJOR}/D
|
|||
set (MKSPECS_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/mkspecs/modules" CACHE STRING "Install dir for qt pri files")
|
||||
set (FEATURES_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/mkspecs/features" CACHE STRING "Install dir for qt prf files")
|
||||
set (CONFIG_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${DtkCore}" CACHE STRING "Install dir for cmake config files")
|
||||
set (DSG_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "PREFIX of DSG_DATA_DIRS")
|
||||
set (DSYSINFO_PREFIX "" CACHE STRING "PREFIX of DSysInfo")
|
||||
|
||||
set (BUILD_EXAMPLES ON CACHE BOOL "Build examples")
|
||||
set (BUILD_VERSION "0" CACHE STRING "buildversion")
|
||||
|
|
|
@ -6,10 +6,6 @@ set(CMAKE_AUTOMOC ON)
|
|||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set (DSG_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}" CACHE STRING "PREFIX of DSG_DATA_DIRS")
|
||||
add_definitions(-DPREFIX="${DSG_PREFIX_PATH}")
|
||||
add_definitions(-DLIBDTKCORE_LIBRARY)
|
||||
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
|
||||
if(LINUX)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
@ -123,6 +119,15 @@ set_target_properties(${LIB_NAME} PROPERTIES
|
|||
EXPORT_NAME Core
|
||||
)
|
||||
|
||||
target_compile_definitions(${LIB_NAME} PUBLIC
|
||||
PREFIX="${DSG_PREFIX_PATH}"
|
||||
DSYSINFO_PREFIX="${DSYSINFO_PREFIX}"
|
||||
)
|
||||
|
||||
target_compile_definitions(${LIB_NAME} PRIVATE
|
||||
LIBDTKCORE_LIBRARY
|
||||
)
|
||||
|
||||
target_include_directories(${LIB_NAME} PRIVATE
|
||||
${uchardet_INCLUDE_DIRS}
|
||||
)
|
||||
|
|
|
@ -25,29 +25,15 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef OS_VERSION_TEST_FILE
|
||||
#define OS_VERSION_FILE "/etc/os-version"
|
||||
#else
|
||||
#define OS_VERSION_FILE OS_VERSION_TEST_FILE
|
||||
#endif
|
||||
#define OS_VERSION_FILE DSYSINFO_PREFIX"/etc/os-version"
|
||||
#define LSB_RELEASE_FILE DSYSINFO_PREFIX"/etc/lsb-release"
|
||||
#define OS_RELEASE_FILE DSYSINFO_PREFIX"/etc/os-release"
|
||||
#define DEEPIN_VERSION_FILE DSYSINFO_PREFIX"/etc/deepin-version"
|
||||
|
||||
#ifndef LSB_RELEASE_TEST_FILE
|
||||
#define LSB_RELEASE_FILE "/etc/lsb-release"
|
||||
#else
|
||||
#define LSB_RELEASE_FILE LSB_RELEASE_TEST_FILE
|
||||
#endif
|
||||
|
||||
#ifndef OS_RELEASE_TEST_FILE
|
||||
#define OS_RELEASE_FILE "/etc/os-release"
|
||||
#else
|
||||
#define OS_RELEASE_FILE OS_RELEASE_TEST_FILE
|
||||
#endif
|
||||
|
||||
#ifndef DEEPIN_VERSION_TEST_FILE
|
||||
#define DEEPIN_VERSION_FILE "/etc/deepin-version"
|
||||
#else
|
||||
#define DEEPIN_VERSION_FILE DEEPIN_VERSION_TEST_FILE
|
||||
#endif
|
||||
static inline bool inTest()
|
||||
{
|
||||
return !QLatin1String(DSYSINFO_PREFIX).isEmpty();
|
||||
}
|
||||
|
||||
DCORE_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -164,12 +150,11 @@ bool DSysInfoPrivate::splitA_BC_DMode()
|
|||
|
||||
void DSysInfoPrivate::ensureDeepinInfo()
|
||||
{
|
||||
#ifndef DEEPIN_VERSION_TEST_FILE
|
||||
if (static_cast<int>(deepinType) >= 0)
|
||||
if (static_cast<int>(deepinType) >= 0 && !inTest())
|
||||
return;
|
||||
#else
|
||||
deepinTypeMap.clear(); // clear cache for test
|
||||
#endif
|
||||
|
||||
if (inTest())
|
||||
deepinTypeMap.clear(); // clear cache for test
|
||||
|
||||
QFile file(DEEPIN_VERSION_FILE);
|
||||
|
||||
|
@ -242,10 +227,8 @@ void DSysInfoPrivate::ensureDeepinInfo()
|
|||
|
||||
bool DSysInfoPrivate::ensureOsVersion()
|
||||
{
|
||||
#ifndef OS_VERSION_TEST_FILE // Always re-read the file when testing
|
||||
if (osBuild.A > 0)
|
||||
if (osBuild.A > 0 && !inTest())
|
||||
return true;
|
||||
#endif
|
||||
|
||||
DDesktopEntry entry(OS_VERSION_FILE);
|
||||
bool ok = false;
|
||||
|
@ -382,11 +365,12 @@ static bool readEtcFile(DSysInfoPrivate *info, const char *filename,
|
|||
quint8 valid_data_count = 0;
|
||||
char buf[1024];
|
||||
|
||||
#ifdef OS_RELEASE_TEST_FILE
|
||||
// for test clear cache
|
||||
info->productTypeString.clear();
|
||||
info->productType = DSysInfo::UnknownType;
|
||||
#endif
|
||||
|
||||
if (inTest()) {
|
||||
// for test clear cache
|
||||
info->productTypeString.clear();
|
||||
info->productType = DSysInfo::UnknownType;
|
||||
}
|
||||
|
||||
while (valid_data_count < 3) {
|
||||
int buf_length = file.readLine(buf, sizeof(buf));
|
||||
|
@ -426,7 +410,7 @@ static bool readEtcFile(DSysInfoPrivate *info, const char *filename,
|
|||
static bool readOsRelease(DSysInfoPrivate *info)
|
||||
{
|
||||
if (!readEtcFile(info, OS_RELEASE_FILE, "ID=", "VERSION_ID=", "PRETTY_NAME="))
|
||||
return readEtcFile(info, "/usr/lib/os-release", "ID=", "VERSION_ID=", "PRETTY_NAME=");
|
||||
return readEtcFile(info, DSYSINFO_PREFIX"/usr/lib/os-release", "ID=", "VERSION_ID=", "PRETTY_NAME=");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -439,11 +423,9 @@ static bool readLsbRelease(DSysInfoPrivate *info)
|
|||
|
||||
void DSysInfoPrivate::ensureReleaseInfo()
|
||||
{
|
||||
#ifndef OS_RELEASE_TEST_FILE // Always re-read the file when testing
|
||||
if (productType >= 0) {
|
||||
if (productType >= 0 && !inTest()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
readOsRelease(this);
|
||||
|
@ -639,10 +621,9 @@ QString DSysInfo::deepinCopyright()
|
|||
*/
|
||||
DSysInfo::UosType DSysInfo::uosType()
|
||||
{
|
||||
#ifndef OS_VERSION_TEST_FILE
|
||||
if (!DSysInfo::isDeepin())
|
||||
if (!DSysInfo::isDeepin() && !inTest())
|
||||
return UosTypeUnknown;
|
||||
#endif
|
||||
|
||||
siGlobal->ensureOsVersion();
|
||||
|
||||
UosType ost = UosTypeUnknown;
|
||||
|
|
|
@ -11,7 +11,7 @@ set(CMAKE_AUTORCC ON)
|
|||
set(CMAKE_CXX_FLAGS "-fno-access-control")
|
||||
add_compile_options(-fsanitize=address)
|
||||
add_link_options(-fsanitize=address)
|
||||
add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}")
|
||||
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
|
||||
|
||||
|
@ -61,6 +61,11 @@ add_executable(${BIN_NAME}
|
|||
./data.qrc
|
||||
)
|
||||
|
||||
target_compile_definitions(${BIN_NAME} PUBLIC
|
||||
PREFIX="${DSG_PREFIX_PATH}"
|
||||
DSYSINFO_PREFIX="${DSYSINFO_PREFIX}"
|
||||
)
|
||||
|
||||
add_dependencies(${BIN_NAME} ${TEST_SO_NAME})
|
||||
target_link_libraries(
|
||||
${BIN_NAME} PRIVATE
|
||||
|
|
|
@ -14,12 +14,7 @@ export ASAN_OPTIONS="halt_on_error=0"
|
|||
# back to project directroy
|
||||
cd ..
|
||||
|
||||
osv_def="-DOS_VERSION_TEST_FILE=\"/tmp/etc/os-version\""
|
||||
lsb_def="-DLSB_RELEASE_TEST_FILE=\"/tmp/etc/lsb-release\""
|
||||
os_def="-DOS_RELEASE_TEST_FILE=\"/tmp/etc/os-release\""
|
||||
dpv_def="-DDEEPIN_VERSION_TEST_FILE=\"/tmp/etc/deepin-version\""
|
||||
|
||||
cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_EXAMPLE=OFF -DBUILD_DOCS=OFF -DEnableCov=ON ${osv_def} ${lsb_def} ${os_def} ${dpv_def}
|
||||
cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_EXAMPLES=OFF -DBUILD_DOCS=OFF -DEnableCov=ON -DDSYSINFO_PREFIX=/tmp
|
||||
|
||||
cmake --build build -j$(nproc)
|
||||
|
||||
|
|
|
@ -13,7 +13,20 @@
|
|||
|
||||
DCORE_USE_NAMESPACE
|
||||
|
||||
TEST(ut_DSysInfo, testOsVersion)
|
||||
class ut_DSysInfo : public testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override {
|
||||
if (QLatin1String(DSYSINFO_PREFIX).isEmpty()) {
|
||||
GTEST_SKIP_("DSYSINFO_PREFIX not defined...");
|
||||
}
|
||||
}
|
||||
void TearDown() override {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ut_DSysInfo, testOsVersion)
|
||||
{
|
||||
FileGuard guard("/tmp/etc/os-version");
|
||||
DDesktopEntry entry(guard.fileName());
|
||||
|
@ -195,7 +208,7 @@ TEST(ut_DSysInfo, testOsVersion)
|
|||
ASSERT_TRUE(DSysInfo::udpateVersion() == QStringLiteral(""));
|
||||
}
|
||||
|
||||
TEST(ut_DSysInfo, testdistributionInfo)
|
||||
TEST_F(ut_DSysInfo, testdistributionInfo)
|
||||
{
|
||||
FileGuard fg("/tmp/share/deepin/distribution.info");
|
||||
DDesktopEntry entry(fg.fileName());
|
||||
|
@ -228,7 +241,7 @@ TEST(ut_DSysInfo, testdistributionInfo)
|
|||
guard.restore();
|
||||
}
|
||||
|
||||
TEST(ut_DSysInfo, osRelease)
|
||||
TEST_F(ut_DSysInfo, osRelease)
|
||||
{
|
||||
FileGuard fg("/tmp/etc/os-release");
|
||||
DDesktopEntry entry(fg.fileName());
|
||||
|
@ -262,7 +275,7 @@ TEST(ut_DSysInfo, osRelease)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(ut_DSysInfo, isDDE)
|
||||
TEST_F(ut_DSysInfo, isDDE)
|
||||
{
|
||||
FileGuard fg("/tmp/etc/os-release");
|
||||
DDesktopEntry entry(fg.fileName());
|
||||
|
@ -309,7 +322,7 @@ TEST(ut_DSysInfo, isDDE)
|
|||
|
||||
}
|
||||
|
||||
TEST(ut_DSysInfo, deepinVersion)
|
||||
TEST_F(ut_DSysInfo, deepinVersion)
|
||||
{
|
||||
FileGuard fg("/tmp/etc/deepin-version");
|
||||
DDesktopEntry entry(fg.fileName());
|
||||
|
@ -359,7 +372,7 @@ TEST(ut_DSysInfo, deepinVersion)
|
|||
ASSERT_FALSE(DSysInfo::isCommunityEdition());
|
||||
}
|
||||
|
||||
TEST(ut_DSysInfo, other)
|
||||
TEST_F(ut_DSysInfo, other)
|
||||
{
|
||||
qDebug() << DSysInfo::computerName();
|
||||
qDebug() << DSysInfo::memoryInstalledSize();
|
||||
|
|
|
@ -27,6 +27,7 @@ protected:
|
|||
|
||||
void ut_GSettings::SetUp()
|
||||
{
|
||||
GTEST_SKIP_("Do not test GSettingsBackend. schema was removed...");
|
||||
QFile file("/tmp/test.json");
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return;
|
||||
|
|
|
@ -16,6 +16,10 @@ add_executable(${BIN_NAME}
|
|||
${dci_SRCS}
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_compile_definitions(${BIN_NAME} PUBLIC
|
||||
DSYSINFO_PREFIX="${DSYSINFO_PREFIX}")
|
||||
|
||||
target_link_libraries(${BIN_NAME} PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::CorePrivate
|
||||
|
|
Loading…
Reference in New Issue