Skip to content

Commit

Permalink
move gl and nucleus unit tests to /unittests + make gl tests work aga…
Browse files Browse the repository at this point in the history
…in with new qml gui approach.
  • Loading branch information
adam-ce committed Nov 19, 2023
1 parent bcdc972 commit d38245c
Show file tree
Hide file tree
Showing 38 changed files with 229 additions and 177 deletions.
19 changes: 3 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ endif()

########################################### dependencies #################################################
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL Network Quick QuickControls2 LinguistTools Svg Charts)
qt_policy(
SET QTP0002 NEW
)
if (ALP_ENABLE_POSITIONING)
find_package(Qt6 REQUIRED COMPONENTS Positioning)
endif()
Expand All @@ -90,21 +93,5 @@ add_subdirectory(plain_renderer)
add_subdirectory(app)

if (ALP_UNITTESTS)
alp_add_git_repository(qml_catch2_console URL https://github.com/AlpineMapsOrg/qml_catch2_console.git COMMITISH origin/main DO_NOT_ADD_SUBPROJECT)
include(cmake/alp_add_unittest.cmake)

function(alp_setup_unittest)
if (ANDROID)
install(TARGETS ${ARGV0}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

if (MINGW)
target_compile_options(${ARGV0} PUBLIC "-Wa,-mbig-obj")
endif()
endfunction()

add_subdirectory(unittests)
add_subdirectory(unittests_gl)
endif()
49 changes: 5 additions & 44 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,10 @@
#############################################################################

cmake_minimum_required(VERSION 3.24)
project(alpine-renderer-unittests_nucleus LANGUAGES CXX)
project(alpine-renderer-unittests LANGUAGES CXX)

alp_add_unittest(unittests_nucleus
catch2_helpers.h
test_Camera.cpp
nucleus_utils_stopwatch.cpp
test_DrawListGenerator.cpp
test_helpers.h
test_raster.cpp
test_terrain_mesh_index_generator.cpp
test_srs.cpp
test_tile.cpp
test_tile_conversion.cpp
nucleus_tile_scheduler_util.cpp
nucleus_tile_scheduler_tile_load_service.cpp
nucleus_tile_scheduler_layer_assembler.cpp
nucleus_tile_scheduler_quad_assembler.cpp
nucleus_tile_scheduler_cache.cpp
nucleus_tile_scheduler_scheduler.cpp
nucleus_tile_scheduler_slot_limiter.cpp
nucleus_tile_scheduler_rate_limiter.cpp
RateTester.h RateTester.cpp
test_zppbits.cpp
cache_queries.cpp
)

qt_add_resources(unittests_nucleus "height_data"
PREFIX "/map"
BASE ${renderer_static_data_SOURCE_DIR}
FILES ${renderer_static_data_SOURCE_DIR}/height_data.atb
)
qt_add_resources(unittests_nucleus "test_data"
PREFIX "/test_data"
BASE ${CMAKE_CURRENT_SOURCE_DIR}/data/
FILES
data/170px-Jeune_bouquetin_de_face.jpg
data/test-tile_ortho.jpeg
data/test-tile.png
)
target_link_libraries(unittests_nucleus PUBLIC nucleus Catch2::Catch2 Qt::Test)
target_compile_definitions(unittests_nucleus PUBLIC "ALP_TEST_DATA_DIR=\":/test_data/\"")

if (ANDROID)
add_android_openssl_libraries(unittests_nucleus)
endif()
alp_add_git_repository(qml_catch2_console URL https://github.com/AlpineMapsOrg/qml_catch2_console.git COMMITISH origin/main DO_NOT_ADD_SUBPROJECT)
include(${CMAKE_SOURCE_DIR}/cmake/alp_add_unittest.cmake)

add_subdirectory(nucleus)
add_subdirectory(gl_engine)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cmake_minimum_required(VERSION 3.24)
project(alpine-renderer-unittests_gl_engine LANGUAGES CXX)

alp_add_unittest(unittests_gl_engine
UnittestGlWindow.h UnittestGlWindow.cpp
UnittestGLContext.h UnittestGLContext.cpp
framebuffer.cpp
uniformbuffer.cpp
)
Expand Down
70 changes: 70 additions & 0 deletions unittests/gl_engine/UnittestGLContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*****************************************************************************
* Alpine Terrain Renderer
* Copyright (C) 2023 Adam Celarek
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

#include "UnittestGLContext.h"

#include <cstdio>

#include <QGuiApplication>
#include <QOffscreenSurface>
#include <QOpenGLDebugLogger>
#include <QTimer>
#include <catch2/catch_test_macros.hpp>

UnittestGLContext::UnittestGLContext()
{
QSurfaceFormat surface_format;
surface_format.setDepthBufferSize(24);
surface_format.setOption(QSurfaceFormat::DebugContext);

// Request OpenGL 3.3 core or OpenGL ES 3.0.
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
qDebug("Requesting 3.3 core context");
surface_format.setVersion(3, 3);
surface_format.setProfile(QSurfaceFormat::CoreProfile);
} else {
qDebug("Requesting 3.0 context");
surface_format.setVersion(3, 0);
}
QSurfaceFormat::setDefaultFormat(surface_format);
m_context.setFormat(surface_format);

surface.create();
const auto r = m_context.create();
assert(r);
m_context.makeCurrent(&surface);

QOpenGLDebugLogger logger;
const auto debug_logger_supported = logger.initialize();
#ifndef __EMSCRIPTEN__ // not supported by webassembly and it's ok. errors are printed to the java script console
CHECK(debug_logger_supported);
#endif

if (debug_logger_supported) {
logger.disableMessages(QList<GLuint>({131185}));
QObject::connect(&logger, &QOpenGLDebugLogger::messageLogged, [](const auto& message) {
qDebug() << message;
});
logger.startLogging(QOpenGLDebugLogger::SynchronousLogging);
}
}

void UnittestGLContext::initialise()
{
static UnittestGLContext s_instance;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@

#pragma once

#include <QOffscreenSurface>
#include <QOpenGLWindow>

class UnittestGlWindow : public QOpenGLWindow
class UnittestGLContext
{
Q_OBJECT
int m_argc = 0;
char** m_argv = nullptr;
public:
explicit UnittestGlWindow(int argc, char** argv);
static void initialise();
UnittestGLContext(UnittestGLContext const&) = delete;
UnittestGLContext(UnittestGLContext const&&) = delete;
void operator=(UnittestGLContext const&) = delete;
void operator=(UnittestGLContext const&&) = delete;

public:
void initializeGL() override;
};
private:
UnittestGLContext();
~UnittestGLContext() = default;

QOpenGLContext m_context;
QOffscreenSurface surface;
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "gl_engine/helpers.h"
#include "nucleus/utils/bit_coding.h"

#include "UnittestGLContext.h"

#ifdef ANDROID
#include "GLES3/gl3.h"
#endif
Expand Down Expand Up @@ -67,6 +69,7 @@ ShaderProgram create_debug_shader(const char* fragmentShaderOverride = nullptr)

TEST_CASE("gl framebuffer")
{
UnittestGLContext::initialise();
const auto* c = QOpenGLContext::currentContext();
QOpenGLExtraFunctions* f = c->extraFunctions();
REQUIRE(f);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "gl_engine/UniformBufferObjects.h"
#include "gl_engine/helpers.h"

#include "UnittestGLContext.h"

using Catch::Approx;
using gl_engine::Framebuffer;
using gl_engine::ShaderProgram;
Expand All @@ -62,6 +64,8 @@ ShaderProgram create_debug_shader2(const char* fragmentShaderOverride = nullptr)

TEST_CASE("gl uniformbuffer")
{
UnittestGLContext::initialise();

const auto* c = QOpenGLContext::currentContext();
QOpenGLExtraFunctions* f = c->extraFunctions();
REQUIRE(f);
Expand Down
36 changes: 0 additions & 36 deletions unittests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

#include <chrono>
#include <limits>
#include <cstdio>
#include <iostream>

#include <QGuiApplication>
#include <QTimer>
#include <QtTest/QSignalSpy>
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_session.hpp>

int main( int argc, char* argv[] ) {
Expand All @@ -46,31 +38,3 @@ int main( int argc, char* argv[] ) {
#endif
return result;
}

#ifdef NDEBUG
constexpr bool asserts_are_enabled = false;
#else
constexpr bool asserts_are_enabled = true;
#endif

TEST_CASE("nucleus/main: check that asserts are enabled")
{
CHECK(asserts_are_enabled);
}

TEST_CASE("nucleus/main: check that NaNs are enabled (-ffast-math removes support, -fno-finite-math-only puts it back in)")
{
CHECK(std::isnan(std::numeric_limits<float>::quiet_NaN() * float(std::chrono::system_clock::now().time_since_epoch().count())));
CHECK(std::isnan(double(std::numeric_limits<float>::quiet_NaN() * float(std::chrono::system_clock::now().time_since_epoch().count()))));
}

TEST_CASE("nucleus/main: qt signals and slots")
{
QTimer t;
t.setSingleShot(true);
t.setInterval(1);
QSignalSpy spy(&t, &QTimer::timeout);
t.start();
spy.wait(20);
CHECK(spy.size() == 1);
}
71 changes: 71 additions & 0 deletions unittests/nucleus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#############################################################################
# Alpine Terrain Renderer
# Copyright (C) 2023 Adam Celarek <family name at cg tuwien ac at>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#############################################################################

cmake_minimum_required(VERSION 3.24)
project(alpine-renderer-unittests_nucleus LANGUAGES CXX)

alp_add_unittest(unittests_nucleus
catch2_helpers.h
test_Camera.cpp
nucleus_utils_stopwatch.cpp
test_DrawListGenerator.cpp
test_helpers.h
test_raster.cpp
test_terrain_mesh_index_generator.cpp
test_srs.cpp
test_tile.cpp
test_tile_conversion.cpp
nucleus_tile_scheduler_util.cpp
nucleus_tile_scheduler_tile_load_service.cpp
nucleus_tile_scheduler_layer_assembler.cpp
nucleus_tile_scheduler_quad_assembler.cpp
nucleus_tile_scheduler_cache.cpp
nucleus_tile_scheduler_scheduler.cpp
nucleus_tile_scheduler_slot_limiter.cpp
nucleus_tile_scheduler_rate_limiter.cpp
RateTester.h RateTester.cpp
test_zppbits.cpp
cache_queries.cpp
bits_and_pieces.cpp
)

target_sources(unittests_nucleus
PRIVATE
bits_and_pieces.cpp
)

qt_add_resources(unittests_nucleus "height_data"
PREFIX "/map"
BASE ${renderer_static_data_SOURCE_DIR}
FILES ${renderer_static_data_SOURCE_DIR}/height_data.atb
)
qt_add_resources(unittests_nucleus "test_data"
PREFIX "/test_data"
BASE ${CMAKE_CURRENT_SOURCE_DIR}/data/
FILES
data/170px-Jeune_bouquetin_de_face.jpg
data/test-tile_ortho.jpeg
data/test-tile.png
)
target_link_libraries(unittests_nucleus PUBLIC nucleus Catch2::Catch2 Qt::Test)
target_compile_definitions(unittests_nucleus PUBLIC "ALP_TEST_DATA_DIR=\":/test_data/\"")

if (ANDROID)
add_android_openssl_libraries(unittests_nucleus)
endif()

File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d38245c

Please sign in to comment.