Skip to content

Commit 58d6f17

Browse files
committed
add tests
1 parent 9ed0f62 commit 58d6f17

File tree

7 files changed

+421
-18
lines changed

7 files changed

+421
-18
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/tests.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
Desktop:
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest, windows-latest, macos-latest]
13+
14+
runs-on: ${{ matrix.os }}
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Install Xvfb (Linux)
21+
if: runner.os == 'Linux'
22+
run: |
23+
sudo apt install -y xvfb
24+
25+
- name: Install Qt
26+
uses: jurplel/install-qt-action@v4
27+
with:
28+
version: 6.10.1
29+
target: desktop
30+
modules: 'qtpositioning'
31+
cached: true
32+
33+
- name: Configure CMake
34+
shell: bash
35+
run: |
36+
mkdir build
37+
cd build
38+
cmake .. -DSIMPLE_MAP_VIEW_BUILD_TESTS=ON
39+
40+
- name: Build
41+
shell: bash
42+
working-directory: build
43+
run: |
44+
cmake --build .
45+
46+
- name: Run (Linux)
47+
if: runner.os == 'Linux'
48+
working-directory: build
49+
run: xvfb-run ctest --output-on-failure
50+
51+
- name: Run (Windows / macOS)
52+
if: runner.os != 'Linux'
53+
shell: bash
54+
working-directory: build
55+
run: ctest -C Debug --output-on-failure

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ project(SimpleMapView VERSION 1.2.0 LANGUAGES CXX)
88

99
option(SIMPLE_MAP_VIEW_BUILD_QML "Build as QML component" OFF)
1010
option(SIMPLE_MAP_VIEW_BUILD_PYTHON_BINDINGS "Build python bindings" OFF)
11+
option(SIMPLE_MAP_VIEW_BUILD_TESTS "Build the tests" OFF)
1112

1213
set(SIMPLE_MAP_VIEW_QML_URI "com.github.ozguronsoy.SimpleMapView")
1314

@@ -38,12 +39,17 @@ find_package(Qt6 REQUIRED COMPONENTS ${SIMPLE_MAP_VIEW_QT_COMPONENTS})
3839
file(GLOB_RECURSE SIMPLE_MAP_VIEW_HEADERS include/*.h)
3940
file(GLOB_RECURSE SIMPLE_MAP_VIEW_SOURCES src/*.cpp)
4041

41-
if(SIMPLE_MAP_VIEW_BUILD_PYTHON_BINDINGS)
42+
if(SIMPLE_MAP_VIEW_BUILD_TESTS OR SIMPLE_MAP_VIEW_BUILD_PYTHON_BINDINGS)
43+
4244
set(CMAKE_AUTOMOC ON)
4345
set(CMAKE_AUTORCC ON)
4446
set(CMAKE_AUTOUIC ON)
4547
list(APPEND SIMPLE_MAP_VIEW_SOURCES Resources.qrc)
46-
list(APPEND SIMPLE_MAP_VIEW_DEFINITIONS SIMPLE_MAP_VIEW_BUILD_PYTHON_BINDINGS)
48+
49+
if(SIMPLE_MAP_VIEW_BUILD_PYTHON_BINDINGS)
50+
list(APPEND SIMPLE_MAP_VIEW_DEFINITIONS SIMPLE_MAP_VIEW_BUILD_PYTHON_BINDINGS)
51+
endif()
52+
4753
endif()
4854

4955
add_library(SimpleMapView STATIC ${SIMPLE_MAP_VIEW_HEADERS} ${SIMPLE_MAP_VIEW_SOURCES})
@@ -58,4 +64,9 @@ target_link_libraries(SimpleMapView PUBLIC ${SIMPLE_MAP_VIEW_QT_LIBRARIES})
5864
if(SIMPLE_MAP_VIEW_BUILD_PYTHON_BINDINGS)
5965
set_property(TARGET SimpleMapView PROPERTY POSITION_INDEPENDENT_CODE ON)
6066
add_subdirectory(python_bindings)
67+
endif()
68+
69+
if(SIMPLE_MAP_VIEW_BUILD_TESTS)
70+
enable_testing()
71+
add_subdirectory(tests)
6172
endif()

include/SimpleMapView.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ public slots:
212212
QGeoCoordinate screenPositionToGeoCoordinate(const QPointF& screenPosition) const;
213213

214214
signals:
215-
/** A signal that's triggered when the zoom level changes. */
215+
/** Triggered when the zoom level changes. */
216216
void zoomLevelChanged();
217-
/** A signal that's triggered when the center coordinate changes. */
217+
/** Triggered when the center coordinate changes. */
218218
void centerChanged();
219-
/** A signal that's triggered when the tile server changes. */
219+
/** Triggered when the tile server changes. */
220220
void tileServerChanged();
221221

222222
protected:

src/SimpleMapView.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
#endif
3333

34-
#define GET_IN_RANGE(v, minv, maxv) (std::min(std::max((v), (minv)), (maxv)))
35-
3634
SimpleMapView::SimpleMapView(SimpleMapViewBase* parent)
3735
: SimpleMapViewBase(parent),
3836
m_zoomLevel(17),
@@ -104,7 +102,7 @@ int SimpleMapView::minZoomLevel() const
104102

105103
void SimpleMapView::setMinZoomLevel(int minZoomLevel)
106104
{
107-
m_minZoomLevel = GET_IN_RANGE(minZoomLevel, 0, m_maxZoomLevel);
105+
m_minZoomLevel = std::clamp(minZoomLevel, 0, m_maxZoomLevel);
108106
this->setZoomLevel(m_zoomLevel);
109107
}
110108

@@ -115,7 +113,7 @@ int SimpleMapView::maxZoomLevel() const
115113

116114
void SimpleMapView::setMaxZoomLevel(int maxZoomLevel)
117115
{
118-
m_maxZoomLevel = GET_IN_RANGE(maxZoomLevel, m_minZoomLevel, INT_MAX);
116+
m_maxZoomLevel = std::clamp(maxZoomLevel, m_minZoomLevel, INT_MAX);
119117
this->setZoomLevel(m_zoomLevel);
120118
}
121119

@@ -129,7 +127,7 @@ void SimpleMapView::setZoomLevel(int zoomLevel)
129127
if (!this->isEnabled() || m_lockZoom) return;
130128

131129
const int oldZoomLevel = m_zoomLevel;
132-
m_zoomLevel = GET_IN_RANGE(zoomLevel, m_minZoomLevel, m_maxZoomLevel);
130+
m_zoomLevel = std::clamp(zoomLevel, m_minZoomLevel, m_maxZoomLevel);
133131

134132
if (oldZoomLevel != m_zoomLevel)
135133
{
@@ -180,8 +178,8 @@ void SimpleMapView::setCenter(qreal latitude, qreal longitude)
180178

181179
bool isChanged = false;
182180

183-
latitude = GET_IN_RANGE(latitude, -90.0, 90.0);
184-
longitude = GET_IN_RANGE(longitude, -180.0, 180.0);
181+
latitude = std::clamp(latitude, -90.0, 90.0);
182+
longitude = std::clamp(longitude, -180.0, 180.0);
185183

186184
if (latitude != this->latitude())
187185
{
@@ -262,13 +260,13 @@ void SimpleMapView::setTileServer(const QString& tileServer, bool wait)
262260
if (wait)
263261
{
264262
QEventLoop eventLoop;
265-
(void)this->connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
263+
(void)reply->connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
266264
(void)eventLoop.exec();
267265
handleResponse();
268266
}
269267
else
270268
{
271-
(void)this->connect(reply, &QNetworkReply::finished, this, handleResponse);
269+
(void)reply->connect(reply, &QNetworkReply::finished, this, handleResponse);
272270
}
273271
}
274272
else
@@ -610,7 +608,7 @@ void SimpleMapView::downloadTiles(const QString& path, const QGeoCoordinate& p1,
610608

611609
QNetworkReply* reply = m_networkManager.get(request);
612610

613-
(void)this->connect(reply, &QNetworkReply::finished, this,
611+
(void)reply->connect(reply, &QNetworkReply::finished, this,
614612
[this, downloadNextTile, increaseTilePosition, qrcFile, qrcTextStream, x_next, y_next, z_next, p1, p2, x_start, y_start, x_end, y_end, z_end, currentRequestCount, originalZ, dir, progressBar, downloadedTileCount, reply, x, y, z, tilePath]()
615613
{
616614
if (reply->error() == QNetworkReply::NoError)
@@ -878,7 +876,7 @@ void SimpleMapView::fetchTileFromRemote(const QPoint& tilePosition)
878876
QNetworkReply* reply = m_networkManager.get(request);
879877
m_replyMap[tileKey] = reply;
880878

881-
(void)this->connect(reply, &QNetworkReply::finished, this,
879+
(void)reply->connect(reply, &QNetworkReply::finished, this,
882880
[this, reply, tileKey]()
883881
{
884882
if (reply->error() == QNetworkReply::NoError)
@@ -891,7 +889,6 @@ void SimpleMapView::fetchTileFromRemote(const QPoint& tilePosition)
891889
}
892890
else
893891
{
894-
qDebug() << "[SimpleMapView]" << reply->errorString();
895892
if (!m_abortingReplies)
896893
{
897894
m_backupTileServerIndex = 0;

tests/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(SimpleMapViewTests LANGUAGES CXX)
3+
4+
find_package(Qt6 REQUIRED COMPONENTS Test)
5+
6+
add_executable(
7+
SimpleMapViewTests
8+
../Resources.qrc
9+
SimpleMapViewTest.cpp
10+
)
11+
12+
target_link_libraries(
13+
SimpleMapViewTests
14+
SimpleMapView
15+
Qt::Test
16+
)
17+
18+
include(CTest)
19+
add_test(NAME SimpleMapViewTests COMMAND SimpleMapViewTests)

0 commit comments

Comments
 (0)