From 39dab0f126dd677257afae79c2755c74034e19f4 Mon Sep 17 00:00:00 2001 From: qPCR4vir Date: Fri, 4 Mar 2016 00:44:48 +0100 Subject: [PATCH] cleanup and document GUI testing --- .travis.yml | 25 ++++++------ include/nana/gui/wvl.hpp | 30 +++++++++++--- source/gui/wvl.cpp | 85 +++++++++++++++++++++++----------------- 3 files changed, 87 insertions(+), 53 deletions(-) diff --git a/.travis.yml b/.travis.yml index d596ff49..b5b40821 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,25 +76,28 @@ 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=OFF -DNANA_CMAKE_AUTOMATIC_GUI_TESTING=ON -DNANA_CMAKE_ADD_DEF_AUTOMATIC_GUI_TESTING=ON - make - ls - - ./clicked - - ./HelloWord + - ./audio_player + - ./a_group_impl + - ./animate-bmp - ./background-effects - ./categ + - ./calculator + - ./clicked - ./decore - ./dock - ./drag-button - ./draw - ./file_explorer - #- ./example_menu + - ./example_menu - ./example_listbox - #- ./example_combox - #- ./example.button - #- ./MontiHall - - ./a_group_impl - #- ./animate-bmp - #- ./calculator - #- ./helloworld_demo - #- ./notepad + - ./example_combox + - ./example.button + - ./HelloWord + - ./MontiHall + - ./helloworld_demo + - ./notepad + + diff --git a/include/nana/gui/wvl.hpp b/include/nana/gui/wvl.hpp index aac2319e..5d6d756c 100644 --- a/include/nana/gui/wvl.hpp +++ b/include/nana/gui/wvl.hpp @@ -1,14 +1,14 @@ -/* +/** * Nana GUI Library Definition * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * - * @file: nana/gui/wvl.hpp - * @description: + * @file nana/gui/wvl.hpp + * @description * the header file contains the files required for running of Nana.GUI */ @@ -16,7 +16,6 @@ #define NANA_GUI_WVL_HPP - #include "programming_interface.hpp" #include "screen.hpp" #include "widgets/form.hpp" @@ -60,7 +59,26 @@ namespace nana template using form_loader = detail::form_loader; - void exec(unsigned wait = 0, std::function = {}, unsigned wait_end=0, form *fm= nullptr); + /// @brief Take control of the GUI and optionaly automaticaly tests it. + /// + /// @detail It transfers to nana the program flow control, which begin pumping messages + /// from the underlying OS, interpreting and sending it with suitable arguments + /// to the nana widgets that registered a response in the corresponding event. + /// It also accept arguments to be used in case of automatic GUI testing. + /// Other Way the arguments are ignored. It seems that only works in simple + /// programs with only one active form ?? + void exec(form *main_form = nullptr, ///< used to close the program + unsigned wait = 1, ///< for the GUI to be constructed, in seconds + unsigned wait_end = 1, ///< for the GUI to be destructed, in seconds + std::function = {} ///< emit events to mimics user actions and may asert results + ); + + /// send a click message to this widget - useffull in GUI testing + void click(widget& w); + + /// in seconds + void Wait(unsigned wait = 0); + }//end namespace nana #endif diff --git a/source/gui/wvl.cpp b/source/gui/wvl.cpp index 0e7e4adc..08714df2 100644 --- a/source/gui/wvl.cpp +++ b/source/gui/wvl.cpp @@ -14,18 +14,9 @@ #include #include #include - #include - -inline unsigned Wait_or_not(unsigned wait = 0) -{ -#ifdef NANA_AUTOMATIC_GUI_TESTING - return wait; -#else - return 0; -#endif -} +#define NANA_AUTOMATIC_GUI_TESTING namespace nana { @@ -37,38 +28,60 @@ namespace nana } } - void exec(unsigned wait, std::function f, unsigned wait_end, form *fm ) + void click(widget& w) { - #ifdef NANA_ADD_DEF_AUTOMATIC_GUI_TESTING - if (!wait) - wait = 10; - if (!f) - f = []() {API::exit(); }; - #endif + arg_click arg; + arg.window_handle = w.handle(); + w.events().click.emit(arg); + } - wait = Wait_or_not(wait); + /// in seconds + void Wait(unsigned wait) + { + if (wait) + std::this_thread::sleep_for(std::chrono::seconds{ wait }); + } - std::cout << "Will wait " << wait << " sec...\n"; - std::thread t([wait, &f, wait_end, fm]() - { if (wait) - { - std::cout << "Waiting " << wait << " sec...\n"; - std::this_thread::sleep_for(std::chrono::seconds{ wait } ); - std::cout << "running... \n" ; - f(); - std::cout << "Done... \n"; - std::cout << "Now waiting anothers " << wait_end << " sec...\n"; - std::this_thread::sleep_for(std::chrono::seconds{ wait_end } ); - std::cout << "Done... \n"; - if (fm) - fm->close(); - API::exit(); // why not works? - } - }); - + void pump() + { detail::bedrock::instance().pump_event(nullptr, false); + } + + void exec(form *main_form, //= nullptr, ///< used to close the program + unsigned wait, // = 1, ///< for the GUI to be constructed, in seconds + unsigned wait_end, // = 1, ///< for the GUI to be destructed, in seconds + std::functionf // = {} ///< emit events to mimics user actions and may asert results + ) + { + #ifdef NANA_AUTOMATIC_GUI_TESTING + //if (!wait) + // wait = 1; + //if (!main_form && !f) + // f = []() {API::exit(); }; + + std::cout << "Will wait " << wait << " sec...\n"; + std::thread t([wait, &f, wait_end, main_form]() + { if (wait) + { + std::cout << "Waiting " << wait << " sec...\n"; + Wait( wait ); + std::cout << "running... \n" ; + if (f) f(); + std::cout << "Done... \n"; + std::cout << "Now waiting anothers " << wait_end << " sec...\n"; + Wait(wait_end); + std::cout << "Done... \n"; + if (main_form) + main_form->close(); + API::exit(); // why not works? + } + }); + pump(); if (t.joinable()) t.join(); + #else + pump(); + #endif } }//end namespace nana