From 13fad63f156b69a75f7ccaff927e1d8951a9d5c7 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 22 May 2016 10:19:36 +0200 Subject: [PATCH 1/4] Added initial tests --- CMakeLists.txt | 5 ++++ tests/CMakeLists.txt | 53 +++++++++++++++++++++++++++++++++++++++ tests/cmake_test.cc | 18 +++++++++++++ tests/example_test.cc | 19 ++++++++++++++ tests/stubs/dialogs.cc | 7 ++++++ tests/stubs/dispatcher.cc | 5 ++++ tests/stubs/info.cc | 5 ++++ tests/stubs/terminal.cc | 11 ++++++++ 8 files changed, 123 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/cmake_test.cc create mode 100644 tests/example_test.cc create mode 100644 tests/stubs/dialogs.cc create mode 100644 tests/stubs/dispatcher.cc create mode 100644 tests/stubs/info.cc create mode 100644 tests/stubs/terminal.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 48038a6..93ec00c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,3 +9,8 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|OpenBSD|NetBSD") install(FILES "${CMAKE_SOURCE_DIR}/share/juci.desktop" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/applications") endif() + +if(ENABLE_TESTING) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..479857f --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,53 @@ +add_definitions(-DBOOST_LOG_DYN_LINK) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") + +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" -Wl,--unresolved-symbols=ignore-in-object-files") +else() + message(WARNING "testing only supported for g++") + return() +endif() + +if(APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup") + link_directories(/usr/local/lib /usr/local/opt/gettext/lib) + include_directories(/usr/local/opt/gettext/include) + set(CMAKE_MACOSX_RPATH 1) + set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig") +endif() + +find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) +set(LIBCLANGMM_INCLUDE_DIR ../libclangmm/src) + +include(FindPkgConfig) +pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) + +set(global_includes + ${Boost_INCLUDE_DIRS} + ${GTKMM_INCLUDE_DIRS} + ${GTKSVMM_INCLUDE_DIRS} + ../src + ../tiny-process-library +) + +set(global_libraries + ${GTKMM_LIBRARIES} + ${GTKSVMM_LIBRARIES} + ${Boost_LIBRARIES} +) + +include_directories(${global_includes}) + +add_executable(cmake_test cmake_test.cc + ../src/filesystem.cc ../src/cmake.cc ../src/project_build.cc) +target_link_libraries(cmake_test ${global_libraries}) +add_test(cmake_test cmake_test) + +#Added for example only, and requires display server to work +#However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: +#broadwayd& +#make test +add_executable(example_test example_test.cc + stubs/dispatcher.cc stubs/terminal.cc stubs/info.cc) +target_link_libraries(example_test ${global_libraries}) +add_test(example_test example_test) diff --git a/tests/cmake_test.cc b/tests/cmake_test.cc new file mode 100644 index 0000000..2276bde --- /dev/null +++ b/tests/cmake_test.cc @@ -0,0 +1,18 @@ +#include +#include "cmake.h" +#include "project_build.h" +#include + +int main() { + CMake cmake(JUCI_TESTS_PATH); + + g_assert(cmake.project_path.filename()=="jucipp"); + + auto functions_parameters=cmake.get_functions_parameters("project"); + g_assert(functions_parameters.at(0).second.at(0)=="juci"); + + g_assert(cmake.get_executable(boost::filesystem::path(JUCI_TESTS_PATH)/"cmake_test.cc").filename()=="cmake_test"); + + auto build=Project::Build::create(JUCI_TESTS_PATH); + g_assert(dynamic_cast(build.get())); +} diff --git a/tests/example_test.cc b/tests/example_test.cc new file mode 100644 index 0000000..18e199b --- /dev/null +++ b/tests/example_test.cc @@ -0,0 +1,19 @@ +#include "terminal.h" +#include "info.h" +#include + +//In case one has to test functions that include Terminal::print or Info::print +//Requires display server to work +//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment +//One also has to include the source stubs/dispatcher.cc in CMakeLists.txt for at least Terminal + +//To run the test using broadway backend: +//broadwayd& +//make test + +int main() { + auto app=Gtk::Application::create(); + Terminal::get().print("some message"); + Info::get().print("some message"); + g_assert(true); +} diff --git a/tests/stubs/dialogs.cc b/tests/stubs/dialogs.cc new file mode 100644 index 0000000..7ed8fd0 --- /dev/null +++ b/tests/stubs/dialogs.cc @@ -0,0 +1,7 @@ +#include "dialogs.h" + +Dialog::Message::Message(const std::string &text): Gtk::MessageDialog(text, false, Gtk::MessageType::MESSAGE_INFO, Gtk::ButtonsType::BUTTONS_NONE, true) {} + +bool Dialog::Message::on_delete_event(GdkEventAny *event) { + return true; +} diff --git a/tests/stubs/dispatcher.cc b/tests/stubs/dispatcher.cc new file mode 100644 index 0000000..8c04845 --- /dev/null +++ b/tests/stubs/dispatcher.cc @@ -0,0 +1,5 @@ +#include "dispatcher.h" + +Dispatcher::Dispatcher() {} + +Dispatcher::~Dispatcher() {} diff --git a/tests/stubs/info.cc b/tests/stubs/info.cc new file mode 100644 index 0000000..efd146e --- /dev/null +++ b/tests/stubs/info.cc @@ -0,0 +1,5 @@ +#include "info.h" + +Info::Info() {} + +void Info::print(const std::string &text) {} diff --git a/tests/stubs/terminal.cc b/tests/stubs/terminal.cc new file mode 100644 index 0000000..dabfc6a --- /dev/null +++ b/tests/stubs/terminal.cc @@ -0,0 +1,11 @@ +#include "terminal.h" + +Terminal::Terminal() {} + +bool Terminal::on_motion_notify_event(GdkEventMotion* motion_event) {return false;} +bool Terminal::on_button_press_event(GdkEventButton* button_event) {return false;} +bool Terminal::on_key_press_event(GdkEventKey *event) {return false;} + +size_t Terminal::print(const std::string &message, bool bold) { + return 0; +} From f3e6116e92e2f936a044f1c2b5c1dd10b501c490 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 22 May 2016 14:24:17 +0200 Subject: [PATCH 2/4] Simplified setup of tests, and made tests platform independent --- tests/CMakeLists.txt | 24 ++++++++++++++---------- tests/stubs/config.cc | 3 +++ tests/stubs/terminal.cc | 4 ++++ 3 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 tests/stubs/config.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 479857f..7511498 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,7 @@ add_definitions(-DBOOST_LOG_DYN_LINK) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" -Wl,--unresolved-symbols=ignore-in-object-files") -else() - message(WARNING "testing only supported for g++") - return() -endif() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") if(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup") @@ -36,18 +31,27 @@ set(global_libraries ${Boost_LIBRARIES} ) +set(stub_sources + stubs/config.cc + stubs/dialogs.cc + stubs/dispatcher.cc + stubs/info.cc + stubs/terminal.cc +) + include_directories(${global_includes}) +add_library(stubs_library ${stub_sources}) + add_executable(cmake_test cmake_test.cc ../src/filesystem.cc ../src/cmake.cc ../src/project_build.cc) -target_link_libraries(cmake_test ${global_libraries}) +target_link_libraries(cmake_test ${global_libraries} stubs_library) add_test(cmake_test cmake_test) #Added for example only, and requires display server to work #However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: #broadwayd& #make test -add_executable(example_test example_test.cc - stubs/dispatcher.cc stubs/terminal.cc stubs/info.cc) -target_link_libraries(example_test ${global_libraries}) +add_executable(example_test example_test.cc) +target_link_libraries(example_test ${global_libraries} stubs_library) add_test(example_test example_test) diff --git a/tests/stubs/config.cc b/tests/stubs/config.cc new file mode 100644 index 0000000..a84fe7a --- /dev/null +++ b/tests/stubs/config.cc @@ -0,0 +1,3 @@ +#include "config.h" + +Config::Config() {} diff --git a/tests/stubs/terminal.cc b/tests/stubs/terminal.cc index dabfc6a..f96f60a 100644 --- a/tests/stubs/terminal.cc +++ b/tests/stubs/terminal.cc @@ -6,6 +6,10 @@ bool Terminal::on_motion_notify_event(GdkEventMotion* motion_event) {return fals bool Terminal::on_button_press_event(GdkEventButton* button_event) {return false;} bool Terminal::on_key_press_event(GdkEventKey *event) {return false;} +int Terminal::process(const std::string &command, const boost::filesystem::path &path, bool use_pipes) { + return 0; +} + size_t Terminal::print(const std::string &message, bool bold) { return 0; } From 7a0007653822b5d8ecfda6e5a64b7e7e0133899e Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 22 May 2016 14:48:21 +0200 Subject: [PATCH 3/4] Removed -flto as it is no longer needed --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7511498..f9fc5d5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,7 @@ add_definitions(-DBOOST_LOG_DYN_LINK) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") if(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup") From 3fbb9a28e40a691aa7c9cf3003c37244efed5416 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 22 May 2016 15:04:27 +0200 Subject: [PATCH 4/4] Cleanup of example_test comment --- tests/example_test.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/example_test.cc b/tests/example_test.cc index 18e199b..2f50b4c 100644 --- a/tests/example_test.cc +++ b/tests/example_test.cc @@ -4,10 +4,7 @@ //In case one has to test functions that include Terminal::print or Info::print //Requires display server to work -//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment -//One also has to include the source stubs/dispatcher.cc in CMakeLists.txt for at least Terminal - -//To run the test using broadway backend: +//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: //broadwayd& //make test