From 87d659ca1a14fe8cf4871b8db0f42d005964f565 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 12 Jul 2024 12:37:10 +0200 Subject: app/windows: add basic main window --- .lcovrc | 1 + CMakeLists.txt | 1 + app/CMakeLists.txt | 22 +++++++++++++++++++++- app/include/turns/app/windows/main.hpp | 23 +++++++++++++++++++++++ app/src/application.cpp | 4 +++- app/src/windows/main.cpp | 16 ++++++++++++++++ app/tests/windows/main.cpp | 34 ++++++++++++++++++++++++++++++++++ res/CMakeLists.txt | 4 ++-- res/tests/main.cpp | 12 ------------ res/windows/main_window.ui | 2 +- res/windows/windows.cmb | 2 +- test_support/CMakeLists.txt | 14 ++++++++++++++ test_support/src/gtk_main.cpp | 12 ++++++++++++ 13 files changed, 129 insertions(+), 18 deletions(-) create mode 100644 app/include/turns/app/windows/main.hpp create mode 100644 app/src/windows/main.cpp create mode 100644 app/tests/windows/main.cpp delete mode 100644 res/tests/main.cpp create mode 100644 test_support/CMakeLists.txt create mode 100644 test_support/src/gtk_main.cpp diff --git a/.lcovrc b/.lcovrc index b65ebd3..fd6c8bc 100644 --- a/.lcovrc +++ b/.lcovrc @@ -3,5 +3,6 @@ exclude = /usr/include/* exclude = */catch2/* exclude = */tests/* +exclude = app/src/application.cpp ignore_errors = unused,empty \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b6ae2a..1a15236 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ include("Catch") add_subdirectory("app") add_subdirectory("domain") add_subdirectory("res") +add_subdirectory("test_support") # License diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 88dea68..824e107 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -2,6 +2,7 @@ add_library("app" "src/application.cpp" + "src/windows/main.cpp" ) add_library("turns::app" ALIAS "app") @@ -11,6 +12,9 @@ target_compile_options("app" PUBLIC "$<$:-Wextra>" "$<$:-Werror>" "$<$:-pedantic-errors>" + PRIVATE + "$<$,$>:-fprofile-arcs>" + "$<$,$>:-ftest-coverage>" ) target_include_directories("app" PUBLIC @@ -18,6 +22,8 @@ target_include_directories("app" PUBLIC ) target_link_libraries("app" PUBLIC + "$<$,$>:gcov>" + "PkgConfig::adwaita" "PkgConfig::gtkmm" @@ -51,4 +57,18 @@ configure_file("desktop.in" install(FILES "${CMAKE_CURRENT_BINARY_DIR}/turns.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" -) \ No newline at end of file +) + +# Tests + +add_executable("app-tests" + "tests/windows/main.cpp" +) + +target_link_libraries("app-tests" PRIVATE + "Catch2::Catch2" + "turns::app" + "turns::gtk-test-main" +) + +catch_discover_tests("app-tests") \ No newline at end of file diff --git a/app/include/turns/app/windows/main.hpp b/app/include/turns/app/windows/main.hpp new file mode 100644 index 0000000..9d2e1c3 --- /dev/null +++ b/app/include/turns/app/windows/main.hpp @@ -0,0 +1,23 @@ +#ifndef TURNS_APP_WINDOWS_MAIN_WINDOW_HPP +#define TURNS_APP_WINDOWS_MAIN_WINDOW_HPP + +#include +#include +#include +#include + +namespace turns::app::windows +{ + + struct main : Gtk::ApplicationWindow + { + main(BaseObjectType * base, Glib::RefPtr const builder); + + private: + AdwApplicationWindow * m_adw; + AdwWindowTitle * m_title; + }; + +} // namespace turns::app + +#endif \ No newline at end of file diff --git a/app/src/application.cpp b/app/src/application.cpp index 014171e..660782e 100644 --- a/app/src/application.cpp +++ b/app/src/application.cpp @@ -1,5 +1,7 @@ #include "turns/app/application.hpp" +#include "turns/app/windows/main.hpp" + #include #include #include @@ -18,7 +20,7 @@ namespace turns::app : Gtk::Application{"ch.arknet.Turns"} { auto builder = Gtk::Builder::create_from_resource("/turns/windows/main_window.ui"); - auto main_window = builder->get_widget("main_window"); + auto main_window = Gtk::Builder::get_widget_derived(builder, "main_window"); m_main_window = ADW_APPLICATION_WINDOW(main_window->gobj()); diff --git a/app/src/windows/main.cpp b/app/src/windows/main.cpp new file mode 100644 index 0000000..f8437a6 --- /dev/null +++ b/app/src/windows/main.cpp @@ -0,0 +1,16 @@ +#include "turns/app/windows/main.hpp" + +#include + +namespace turns::app::windows +{ + + main::main(BaseObjectType * base, Glib::RefPtr const builder) + : Gtk::ApplicationWindow{base} + , m_adw{ADW_APPLICATION_WINDOW(gobj())} + , m_title(ADW_WINDOW_TITLE(builder->get_widget("title")->gobj())) + { + adw_window_title_set_subtitle(m_title, "No active turn-order"); + } + +} // namespace turns::app::windows \ No newline at end of file diff --git a/app/tests/windows/main.cpp b/app/tests/windows/main.cpp new file mode 100644 index 0000000..d2ad60e --- /dev/null +++ b/app/tests/windows/main.cpp @@ -0,0 +1,34 @@ +#include "turns/app/windows/main.hpp" + +#include + +#include + +#include +#include +#include + +using namespace std::string_literals; + +namespace turns::app::windows::tests +{ + + TEST_CASE("Newly constructed main window", "[windows]") + { + auto builder = Gtk::Builder::create_from_resource("/turns/windows/main_window.ui"); + auto instance = Gtk::Builder::get_widget_derived
(builder, "main_window"); + + SECTION("construction via builder succeeds") + { + REQUIRE(instance); + } + + SECTION("the window title is not empty") + { + auto widget = builder->get_widget("title"); + auto adw = ADW_WINDOW_TITLE(widget->gobj()); + REQUIRE(adw_window_title_get_subtitle(adw) != ""s); + } + } + +} // namespace turns::app::windows::tests \ No newline at end of file diff --git a/res/CMakeLists.txt b/res/CMakeLists.txt index 4969787..f823bec 100644 --- a/res/CMakeLists.txt +++ b/res/CMakeLists.txt @@ -29,16 +29,16 @@ add_library("turns::res" ALIAS "res") # Tests add_executable("res-tests" - "tests/main.cpp" "tests/windows.cpp" ) -target_link_libraries("res-tests" +target_link_libraries("res-tests" PRIVATE "Catch2::Catch2" "$<$:-Wl,--whole-archive>" "turns::res" "$<$:-Wl,--no-whole-archive>" + "turns::gtk-test-main" ) catch_discover_tests("res-tests") \ No newline at end of file diff --git a/res/tests/main.cpp b/res/tests/main.cpp deleted file mode 100644 index 02173f9..0000000 --- a/res/tests/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include -#include - -auto main(int argc, char * argv[]) -> int -{ - Gtk::init_gtkmm_internals(); - adw_init(); - - return Catch::Session().run(argc, argv); -} \ No newline at end of file diff --git a/res/windows/main_window.ui b/res/windows/main_window.ui index 5489996..c9dbf26 100644 --- a/res/windows/main_window.ui +++ b/res/windows/main_window.ui @@ -18,7 +18,7 @@ - + Turns diff --git a/res/windows/windows.cmb b/res/windows/windows.cmb index e911ec0..8236b71 100644 --- a/res/windows/windows.cmb +++ b/res/windows/windows.cmb @@ -14,7 +14,7 @@ (1,3,"AdwHeaderBar","header",2,None,"top",None,-1,None,None), (1,4,"GtkScrolledWindow",None,2,None,None,None,-1,None,None), (1,5,"GtkListBox","entry_list",4,None,None,None,-1,None,None), - (1,6,"AdwWindowTitle",None,3,None,None,None,-1,None,None), + (1,6,"AdwWindowTitle","title",3,None,None,None,-1,None,None), (1,7,"GtkMenuButton","open_menu",3,None,"start",None,None,None,None), (1,8,"GtkButton","add_participant",3,None,"start",None,None,None,None), (1,9,"(menu)","main_menu",None,None,None,None,-1,None,None), diff --git a/test_support/CMakeLists.txt b/test_support/CMakeLists.txt new file mode 100644 index 0000000..04bb256 --- /dev/null +++ b/test_support/CMakeLists.txt @@ -0,0 +1,14 @@ +add_library("test_support-gtk" OBJECT + "src/gtk_main.cpp" +) + +add_library("turns::gtk-test-main" ALIAS "test_support-gtk") + +target_compile_features("test_support-gtk" PRIVATE + "cxx_std_23" +) + +target_link_libraries("test_support-gtk" PUBLIC + "PkgConfig::adwaita" + "PkgConfig::gtkmm" +) \ No newline at end of file diff --git a/test_support/src/gtk_main.cpp b/test_support/src/gtk_main.cpp new file mode 100644 index 0000000..02173f9 --- /dev/null +++ b/test_support/src/gtk_main.cpp @@ -0,0 +1,12 @@ +#include + +#include +#include + +auto main(int argc, char * argv[]) -> int +{ + Gtk::init_gtkmm_internals(); + adw_init(); + + return Catch::Session().run(argc, argv); +} \ No newline at end of file -- cgit v1.2.3