Skip to content

Commit 60403eb

Browse files
committed
Merge branch 'add-unit-tests'
2 parents c40a7b4 + 8fcbb4f commit 60403eb

12 files changed

Lines changed: 388 additions & 1 deletion

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ set(CMAKE_AUTOMOC ON)
3232
set(CMAKE_AUTORCC ON)
3333

3434
# Define project options
35-
# Example: option(QBAR_BUILD_TESTS "Use to enable/disable build of unit-tests." ON)
35+
option(QBAR_BUILD_TESTS "Use to enable/disable build of unit-tests." ON)
3636

3737
# Manage global compiler options
3838
## For MSVC: force to read source code as UTF-8 file (already default behaviour on GCC/Clang)

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [2.2. Dependencies](#22-dependencies)
1616
- [3. How to build](#3-how-to-build)
1717
- [3.1. CMake Usage](#31-cmake-usage)
18+
- [3.2. CMake options](#32-cmake-options)
1819
- [4. How to use](#4-how-to-use)
1920
- [4.1. Usage](#41-usage)
2021
- [4.2. Library version](#42-library-version)
@@ -79,6 +80,11 @@ add_subdirectory(qbarcode) # Or if library is put in a folder "dependencies" : a
7980
target_link_libraries(${PROJECT_NAME} PRIVATE qbarcode)
8081
```
8182

83+
## 3.2. CMake options
84+
85+
This library provide some **CMake** build options:
86+
- `QBAR_BUILD_TESTS` (default: `ON`): Use to enable/disable unit-tests build
87+
8288
# 4. How to use
8389
## 4.1. Usage
8490

‎tests/CMakeLists.txt‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# CMakeLists file based on project template repository: https://github.com/legerch/projects-template
2+
## Template file version: 2025-07-24
3+
4+
cmake_minimum_required(VERSION 3.20)
5+
6+
# Set project properties
7+
set(PROJECT_NAME qbarcode-tests)
8+
9+
# Set project configuration
10+
## Generic properties
11+
project(${PROJECT_NAME} LANGUAGES CXX)
12+
13+
## Qt specific properties
14+
set(CMAKE_AUTOUIC ON)
15+
set(CMAKE_AUTOMOC ON)
16+
set(CMAKE_AUTORCC ON)
17+
18+
# Define project options
19+
# Example: option(QBAR_TESTS_ENABLE_FEAT1 "Use to enable/disable feature1 for tests." ON)
20+
21+
# Set needed packages
22+
## Qt packages
23+
set(PROJECT_QT_PACKAGES
24+
Core
25+
Test
26+
)
27+
28+
find_package(QT NAMES Qt6 Qt5 COMPONENTS ${PROJECT_QT_PACKAGES} REQUIRED)
29+
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${PROJECT_QT_PACKAGES} REQUIRED)
30+
31+
list(TRANSFORM PROJECT_QT_PACKAGES PREPEND "Qt${QT_VERSION_MAJOR}::")
32+
33+
## Other library packages
34+
### Example: find_package(nlohmann_json 3.11.3 REQUIRED)
35+
find_package(GTest 1.11.0 REQUIRED)
36+
37+
# Defines useful path variables for easier CMake configuration
38+
set(PROJECT_DIR_TESTS_EXTERNAL_RSC "${CMAKE_CURRENT_SOURCE_DIR}/external-ressources/")
39+
40+
# Manage library files
41+
## Set tests compilation definitions
42+
set(PROJECT_DEFS_PRIV
43+
QBAR_TESTS_DIR_EXTERNAL_RSC="${PROJECT_DIR_TESTS_EXTERNAL_RSC}"
44+
)
45+
46+
## Set library linking
47+
### Linking dirs
48+
set(PROJECT_LINKING_DIR
49+
50+
)
51+
52+
### Linking libs
53+
set(PROJECT_LINKING_LIB
54+
${PROJECT_QT_PACKAGES}
55+
GTest::gtest_main
56+
57+
qbarcode
58+
)
59+
60+
## Set tests files
61+
set(FILES_HEADERS
62+
helpers/testsutils.h
63+
)
64+
65+
set(FILES_SOURCES
66+
helpers/testsutils.cpp
67+
68+
payloads_tests.cpp
69+
qrcode_tests.cpp
70+
)
71+
72+
# Add files to the test application
73+
set(PROJECT_FILES ${FILES_HEADERS} ${FILES_SOURCES})
74+
add_executable(${PROJECT_NAME} ${PROJECT_FILES})
75+
76+
# Link needed libraries
77+
target_link_directories(${PROJECT_NAME} PUBLIC ${PROJECT_LINKING_DIR})
78+
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${PROJECT_LINKING_LIB})
79+
80+
# Specify compiler options
81+
target_compile_options(${PROJECT_NAME} PRIVATE
82+
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Werror=return-type -Wshadow -Wlogical-op -Wduplicated-cond -Wduplicated-branches>
83+
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -Werror=return-type -Wshadow -Wlogical-op -Wduplicated-cond -Wduplicated-branches>
84+
$<$<CXX_COMPILER_ID:MSVC>:/W3 /wd4251>
85+
)
86+
87+
# Compile needed definitions
88+
## Application tests related
89+
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PROJECT_DEFS_PRIV})
90+
91+
# Specify include directories
92+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
1.43 KB
Loading
1.55 KB
Loading
1.61 KB
Loading
1.62 KB
Loading
1.17 KB
Loading

‎tests/helpers/testsutils.cpp‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "testsutils.h"
2+
3+
4+
5+
/*****************************/
6+
/* Macro definitions */
7+
/*****************************/
8+
#if !defined(QBAR_TESTS_DIR_EXTERNAL_RSC)
9+
#error "Macro 'QBAR_TESTS_DIR_EXTERNAL_RSC' is not defined, please set up !"
10+
#endif
11+
12+
/*****************************/
13+
/* Start namespace */
14+
/*****************************/
15+
16+
/*****************************/
17+
/* Constants defintitions */
18+
/*****************************/
19+
20+
/*****************************/
21+
/* Functions implementations */
22+
/*****************************/
23+
24+
QFileInfo TestsUtils::getPathRsc(const QString &filename)
25+
{
26+
return QFileInfo(QBAR_TESTS_DIR_EXTERNAL_RSC + filename);
27+
}
28+
29+
QFileInfo TestsUtils::getPathRscCustom(const QFileInfo &fileInfo, const QString &customName)
30+
{
31+
const QString path = fileInfo.absolutePath();
32+
const QString suffix = fileInfo.suffix();
33+
34+
const QString newFile = QString("%1/%2.%3").arg(path, customName, suffix);
35+
return QFileInfo(newFile);
36+
}
37+
38+
qbar::PayloadQrWifi TestsUtils::createPayloadWifi(IdWifiSec idSec, const QString &ssid, const QString &passwd, bool isHidden)
39+
{
40+
qbar::PayloadQrWifi payload;
41+
42+
payload.setSecurityType(idSec);
43+
payload.setSsid(ssid);
44+
payload.setPassword(passwd);
45+
payload.setIsHidden(isHidden);
46+
47+
return payload;
48+
}
49+
50+
/*****************************/
51+
/* End namespace */
52+
/*****************************/
53+
54+
/*****************************/
55+
/* End file */
56+
/*****************************/

‎tests/helpers/testsutils.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef QBAR_TESTS_HELPERS_TESTSUTILS_H
2+
#define QBAR_TESTS_HELPERS_TESTSUTILS_H
3+
4+
#include "qbarcode/payloads/payloadqrwifi.h"
5+
6+
#include <QFileInfo>
7+
8+
using IdWifiSec = qbar::PayloadQrWifi::SecurityType;
9+
10+
class TestsUtils
11+
{
12+
public:
13+
static QFileInfo getPathRsc(const QString &filename);
14+
static QFileInfo getPathRscCustom(const QFileInfo &fileInfo, const QString &customName);
15+
16+
static qbar::PayloadQrWifi createPayloadWifi(IdWifiSec idSec, const QString &ssid, const QString &passwd, bool isHidden);
17+
};
18+
19+
#endif // QBAR_TESTS_HELPERS_TESTSUTILS_H

0 commit comments

Comments
 (0)