From 976b5ec275e155e1f3b147c6989e2a01637f6acb Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Tue, 1 Mar 2016 18:59:57 +0100 Subject: [PATCH] explore automatic GUI testing in VS2015, cmake and travis local works vary good in windows with VS2015 --- .travis.yml | 7 ++++--- CMakeLists.txt | 14 +++++++++++++ include/nana/gui/wvl.hpp | 5 ++++- source/gui/wvl.cpp | 43 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5ab94854..be36e3c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,7 @@ matrix: - llvm-toolchain-precise before_install: - - git clone --depth=50 --branch=dev_nana_in_examples https://github.com/qPCR4vir/nana-demo.git nana-demo + - git clone --depth=50 --branch=testing https://github.com/qPCR4vir/nana-demo.git nana-demo - export PATH="$HOME/bin:$PATH" - mkdir ~/bin - wget --no-check-certificate --no-clobber -O /tmp/tools/cmake https://cmake.org/files/v3.4/cmake-3.4.0-rc3-Linux-x86_64.sh || true @@ -70,6 +70,7 @@ before_script : - cd bld script: - - cmake -G"Unix Makefiles" .. -DNANA_CMAKE_ENABLE_JPEG=ON -DNANA_CMAKE_ENABLE_PNG=OFF -DNANA_CMAKE_BUILD_DEMOS=ON -DNANA_CMAKE_ENABLE_AUDIO=OFF -DNANA_CMAKE_FIND_BOOST_FILESYSTEM=ON -DNANA_CMAKE_INCLUDE_EXPERIMENTAL_DEMOS=ON + - cmake -G"Unix Makefiles" .. -DNANA_CMAKE_ENABLE_JPEG=ON -DNANA_CMAKE_ENABLE_PNG=OFF -DNANA_CMAKE_BUILD_DEMOS=ON -DNANA_CMAKE_ENABLE_AUDIO=OFF -DNANA_CMAKE_FIND_BOOST_FILESYSTEM=ON -DNANA_CMAKE_INCLUDE_EXPERIMENTAL_DEMOS=ON -DNANA_CMAKE_AUTOMATIC_GUI_TESTING=ON -DNANA_CMAKE_ADD_DEF_AUTOMATIC_GUI_TESTING=OFF - - make \ No newline at end of file + - make + - clicked \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e223c53c..94fa3494 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,9 @@ option(NANA_CMAKE_VERBOSE_PREPROCESSOR "Show annoying debug messages during comp option(NANA_CMAKE_STOP_VERBOSE_PREPROCESSOR "Stop compilation after showing the annoying debug messages." ON) option(NANA_CMAKE_BUILD_DEMOS "Build all the demos form the nana_demo repository." OFF) option(NANA_CMAKE_INCLUDE_EXPERIMENTAL_DEMOS "" ON) +option(NANA_CMAKE_AUTOMATIC_GUI_TESTING "Activate automatic GUI testing?" OFF) +option(NANA_CMAKE_ADD_DEF_AUTOMATIC_GUI_TESTING "Add defoult automatic GUI test?" OFF) + # The ISO C++ File System Technical Specification (ISO-TS, or STD) is optional. # http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4100.pdf @@ -238,6 +241,17 @@ set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14 ) if (NANA_CMAKE_BUILD_DEMOS) + if(NANA_CMAKE_AUTOMATIC_GUI_TESTING) + add_definitions(-DNANA_AUTOMATIC_GUI_TESTING) + endif(NANA_CMAKE_AUTOMATIC_GUI_TESTING) + + if(NANA_CMAKE_ADD_DEF_AUTOMATIC_GUI_TESTING) + add_definitions(-DNANA_ADD_DEF_AUTOMATIC_GUI_TESTING) + endif(NANA_CMAKE_ADD_DEF_AUTOMATIC_GUI_TESTING) + + NANA_ADD_DEF_AUTOMATIC_GUI_TESTING + + set (demos calculator helloworld_demo notepad widget_show widget_show2 ) if (NANA_CMAKE_INCLUDE_EXPERIMENTAL_DEMOS) list(APPEND demos file_explorer) diff --git a/include/nana/gui/wvl.hpp b/include/nana/gui/wvl.hpp index 1f104bbd..a55ec00b 100644 --- a/include/nana/gui/wvl.hpp +++ b/include/nana/gui/wvl.hpp @@ -15,6 +15,8 @@ #ifndef NANA_GUI_WVL_HPP #define NANA_GUI_WVL_HPP + + #include "programming_interface.hpp" #include "screen.hpp" #include "widgets/form.hpp" @@ -58,6 +60,7 @@ namespace nana template using form_loader = detail::form_loader; - void exec(); + void exec(unsigned wait = 0, std::function = {}); + }//end namespace nana #endif diff --git a/source/gui/wvl.cpp b/source/gui/wvl.cpp index cedca916..912bc3ef 100644 --- a/source/gui/wvl.cpp +++ b/source/gui/wvl.cpp @@ -13,6 +13,22 @@ #include #include +#include + +#include + + +//#define NANA_AUTOMATIC_GUI_TESTING + +inline unsigned Wait(unsigned wait = 0) +{ +#ifdef NANA_AUTOMATIC_GUI_TESTING + return wait; +#else + return 0; +#endif +} + namespace nana { namespace detail @@ -23,8 +39,33 @@ namespace nana } } - void exec() + void exec(unsigned wait, std::function f ) { + #ifdef NANA_ADD_DEF_AUTOMATIC_GUI_TESTING + if (!wait) + wait = 10; + if (!f) + f = []() {API::exit(); }; + #endif + + wait = Wait(wait); + + std::cout << "Will wait " << wait << " sec...\n"; + std::thread t([wait, &f]() + { if (wait) + { + std::cout << "Waiting " << wait << " sec...\n"; + std::this_thread::sleep_for(std::chrono::seconds{ wait } ); + std::cout << "Waited !! running... \n" ; + f(); + //API::exit(); + std::cout << "Runed... \n"; + } + }); + detail::bedrock::instance().pump_event(nullptr, false); + + if (t.joinable()) + t.join(); } }//end namespace nana