Skip to content
Closed
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
11 changes: 11 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ if(APPLE)
)
endif()

# ==================== UNIT TESTS (QtTest) ====================
option(PACKETSENDER_BUILD_TESTS "Build unit tests (QtTest)" OFF)

if(PACKETSENDER_BUILD_TESTS)
find_package(Qt6 REQUIRED COMPONENTS Test)

enable_testing()

add_subdirectory(tests/unit)
endif()

# -------------------
# Packaging
# -------------------
Expand Down
24 changes: 24 additions & 0 deletions src/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Forced architecture" FORCE)

set(TEST_NAME "packetsender_unittests")

add_executable(${TEST_NAME}
translation_test.cpp

../../translations.h
../../translations.cpp
)

target_include_directories(${TEST_NAME} PRIVATE
${CMAKE_SOURCE_DIR} # so #include "translations.h" works cleanly
)

target_link_libraries(${TEST_NAME} PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets # needed because installLanguage uses QApplication
Qt6::Test
)

# Make ctest run it
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
40 changes: 40 additions & 0 deletions src/tests/unit/translation_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Created by Tomas Gallucci on 3/2/26.
//

#include <QtTest/QtTest>
#include "translations.h"

class TranslationTest : public QObject
{
Q_OBJECT

private slots:
void testInstallLanguage_data()
{
QTest::addColumn<QString>("language");
QTest::addColumn<bool>("expected");

QTest::newRow("empty → system default") << "" << true;
QTest::newRow("unsupported") << "Klingon" << false;
QTest::newRow("Spanish (supported)") << "Spanish" << true;
QTest::newRow("German (supported)") << "German" << true;
QTest::newRow("French (supported)") << "French" << true;
QTest::newRow("Italian (supported)") << "Italian" << true;
QTest::newRow("Chinese (supported)") << "Chinese" << true;
}

void testInstallLanguage()
{
QFETCH(QString, language);
QFETCH(bool, expected);

// This exercises both loadAndInstallTranslators() and the map lookup
bool result = Translations::installLanguage(language);

QCOMPARE(result, expected);
}
};

QTEST_MAIN(TranslationTest)
#include "translation_test.moc"