Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project(dde-network-core
)

option(ENABLE_DEEPIN_NMQT "enable nmqt patch on deepin" OFF)
option(BUILD_TESTS "Build unit tests" OFF)

set(DDE-Network-Core_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src-old")
set(DDE-Network-Core_LIBRARIES dde-network-core)
Expand Down Expand Up @@ -49,7 +50,7 @@ add_subdirectory("src")
# add_subdirectory("src-old")
# add_subdirectory("dcc-network-plugin")
add_subdirectory("dcc-network")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (BUILD_TESTS)
add_subdirectory("tests")
endif()
# add_subdirectory("example")
Expand Down
31 changes: 9 additions & 22 deletions network-service-plugin/dde-network-secret-dialog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(Dnetwork_Secret_Dialog_Name dde-network-secret-dialog)

file(GLOB_RECURSE Dnetwork_Secret_Dialog_SRCS
"*.h"
"*.cpp"
"src/*.h"
"src/*.cpp"
)

list(REMOVE_ITEM Dnetwork_Secret_Dialog_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")

set(QT_VERSION_MAJOR 6)
set(DTK_VERSION_MAJOR 6)
find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget)
Expand All @@ -26,21 +27,7 @@ set(Dnetwork_Secret_Dialog_Libraries
Qt${QT_VERSION_MAJOR}::Widgets
)


add_executable(${Dnetwork_Secret_Dialog_Name}
${Dnetwork_Secret_Dialog_SRCS}
main.cpp
qrc/dde-network-secret-dialog.qrc
)

target_include_directories(${Dnetwork_Secret_Dialog_Name} PUBLIC
${Dnetwork_Secret_Dialog_Includes}
)

target_link_libraries(${Dnetwork_Secret_Dialog_Name} PRIVATE
${Dnetwork_Secret_Dialog_Libraries}
)

## bin
set(DAEMON_LIB_PATH "lib/deepin-daemon" CACHE STRING "daemon lib path")
install(TARGETS ${Dnetwork_Secret_Dialog_Name} DESTINATION ${DAEMON_LIB_PATH})
add_subdirectory("src")
if (BUILD_TESTS)
add_subdirectory(tests)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

set(Dnetwork_Secret_Dialog_Name dde-network-secret-dialog)

add_executable(${Dnetwork_Secret_Dialog_Name}
${Dnetwork_Secret_Dialog_SRCS}
main.cpp
qrc/dde-network-secret-dialog.qrc
)

target_include_directories(${Dnetwork_Secret_Dialog_Name} PUBLIC
${Dnetwork_Secret_Dialog_Includes}
)

target_link_libraries(${Dnetwork_Secret_Dialog_Name} PRIVATE
${Dnetwork_Secret_Dialog_Libraries}
)

## bin
set(DAEMON_LIB_PATH "lib/deepin-daemon" CACHE STRING "daemon lib path")
install(TARGETS ${Dnetwork_Secret_Dialog_Name} DESTINATION ${DAEMON_LIB_PATH})
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

set(UT_Dnetwork_Secret_Dialog_Name ut-dnetwork-secret-dialog)

set(Test_Libraries
-lpthread
-lgcov
-lgtest
-lgmock
)

file(GLOB_RECURSE UT_Dnetwork_Secret_Dialog_SRCS
"*.h"
"*.cpp"
)

add_executable(${UT_Dnetwork_Secret_Dialog_Name}
${Dnetwork_Secret_Dialog_SRCS}
${UT_Dnetwork_Secret_Dialog_SRCS}
)

# 用于测试覆盖率的编译条件
target_compile_options(${UT_Dnetwork_Secret_Dialog_Name} PRIVATE -fprofile-arcs -ftest-coverage)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()

target_include_directories(${UT_Dnetwork_Secret_Dialog_Name} PUBLIC
${Dnetwork_Secret_Dialog_Includes}
../src/
)

target_link_libraries(${UT_Dnetwork_Secret_Dialog_Name} PRIVATE
${Dnetwork_Secret_Dialog_Libraries}
${Test_Libraries}
)
28 changes: 28 additions & 0 deletions network-service-plugin/dde-network-secret-dialog/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <gtest/gtest.h>

Check warning on line 5 in network-service-plugin/dde-network-secret-dialog/tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QApplication>

Check warning on line 7 in network-service-plugin/dde-network-secret-dialog/tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 8 in network-service-plugin/dde-network-secret-dialog/tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#ifdef QT_DEBUG
#include <sanitizer/asan_interface.h>

Check warning on line 11 in network-service-plugin/dde-network-secret-dialog/tests/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sanitizer/asan_interface.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif

int main(int argc, char *argv[])
{
qputenv("QT_QPA_PLATFORM", "offscreen");
QApplication app(argc,argv);
qDebug() << "start dnetwork-secret-dialog test cases ..............";
::testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS();
qDebug() << "end dnetwork-secret-dialog test cases ..............";

#ifdef QT_DEBUG
__sanitizer_set_report_path("asan_dnetwork-secret-dialog.log");
#endif

return ret;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#define private public
#define protected public
#include "networksecretdialog.h"

Check warning on line 7 in network-service-plugin/dde-network-secret-dialog/tests/ut_networksecretdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "networksecretdialog.h" not found.
#undef private
#undef protected

#include <QJsonDocument>

Check warning on line 11 in network-service-plugin/dde-network-secret-dialog/tests/ut_networksecretdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonDocument> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QKeyEvent>

Check warning on line 12 in network-service-plugin/dde-network-secret-dialog/tests/ut_networksecretdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QKeyEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <gtest/gtest.h>

Check warning on line 14 in network-service-plugin/dde-network-secret-dialog/tests/ut_networksecretdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class Ut_NetworkSecretDialog : public testing::Test
{
public:
void SetUp() override;

void TearDown() override;

public:
NetworkSecretDialog *dialog = nullptr;
};

void Ut_NetworkSecretDialog::SetUp()

Check warning on line 27 in network-service-plugin/dde-network-secret-dialog/tests/ut_networksecretdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'SetUp' is never used.
{
QString json = "{\"connName\":\"UtNetworkSecretDialog\", \"connType\":\"Wiredless\", \"secrets\":[\"wep\"]}";
dialog = new NetworkSecretDialog(QJsonDocument::fromJson(json.toUtf8()));
}

void Ut_NetworkSecretDialog::TearDown()

Check warning on line 33 in network-service-plugin/dde-network-secret-dialog/tests/ut_networksecretdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'TearDown' is never used.
{
if (dialog) {
delete dialog;
dialog = nullptr;
}

}

TEST_F(Ut_NetworkSecretDialog, wepIsValidTest)
{
EXPECT_FALSE(dialog->wepKeyIsValid("12345678", NetworkSecretDialog::NotSpecified));
EXPECT_TRUE(dialog->wepKeyIsValid("12345678", NetworkSecretDialog::Passphrase));
}


TEST_F(Ut_NetworkSecretDialog, wpaPskIsValidTest)
{
EXPECT_TRUE(dialog->wpaPskIsValid("12345678"));
EXPECT_TRUE(dialog->wpaPskIsValid("0123456789012345678901234567890123456789012345678901234567890123"));
}

TEST_F(Ut_NetworkSecretDialog, submitTest)
{
//输入无效
dialog->submit();
//修改密码
if (!dialog->m_lineEditList.isEmpty()) {
auto lineEdit = dialog->m_lineEditList.first();
lineEdit->setText("12345678");
Q_EMIT lineEdit->textChanged("12345678");
}
//点击确定按钮
dialog->onButtonsClicked(1, "");
//点击取消按钮
dialog->onButtonsClicked(0, "");
}

TEST_F(Ut_NetworkSecretDialog, coverageTest)
{
QKeyEvent event(QEvent::KeyPress, Qt::Key_0, Qt::NoModifier);
dialog->keyPressEvent(&event);
}