cleanup and document GUI testing

This commit is contained in:
qPCR4vir 2016-03-04 00:44:48 +01:00
parent 8bbfb38a50
commit 39dab0f126
3 changed files with 87 additions and 53 deletions

View File

@ -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 - 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 - make
- ls - ls
- ./clicked - ./audio_player
- ./HelloWord - ./a_group_impl
- ./animate-bmp
- ./background-effects - ./background-effects
- ./categ - ./categ
- ./calculator
- ./clicked
- ./decore - ./decore
- ./dock - ./dock
- ./drag-button - ./drag-button
- ./draw - ./draw
- ./file_explorer - ./file_explorer
#- ./example_menu - ./example_menu
- ./example_listbox - ./example_listbox
#- ./example_combox - ./example_combox
#- ./example.button - ./example.button
#- ./MontiHall - ./HelloWord
- ./a_group_impl - ./MontiHall
#- ./animate-bmp - ./helloworld_demo
#- ./calculator - ./notepad
#- ./helloworld_demo
#- ./notepad

View File

@ -1,14 +1,14 @@
/* /**
* Nana GUI Library Definition * Nana GUI Library Definition
* Nana C++ Library(http://www.nanapro.org) * 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. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
* *
* @file: nana/gui/wvl.hpp * @file nana/gui/wvl.hpp
* @description: * @description
* the header file contains the files required for running of Nana.GUI * the header file contains the files required for running of Nana.GUI
*/ */
@ -16,7 +16,6 @@
#define NANA_GUI_WVL_HPP #define NANA_GUI_WVL_HPP
#include "programming_interface.hpp" #include "programming_interface.hpp"
#include "screen.hpp" #include "screen.hpp"
#include "widgets/form.hpp" #include "widgets/form.hpp"
@ -60,7 +59,26 @@ namespace nana
template<typename Form, bool IsVisible = true> template<typename Form, bool IsVisible = true>
using form_loader = detail::form_loader<Form, IsVisible>; using form_loader = detail::form_loader<Form, IsVisible>;
void exec(unsigned wait = 0, std::function<void()> = {}, 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<void()> = {} ///< 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 }//end namespace nana
#endif #endif

View File

@ -14,18 +14,9 @@
#include <nana/gui/wvl.hpp> #include <nana/gui/wvl.hpp>
#include <nana/gui/detail/bedrock.hpp> #include <nana/gui/detail/bedrock.hpp>
#include <thread> #include <thread>
#include <iostream> #include <iostream>
#define NANA_AUTOMATIC_GUI_TESTING
inline unsigned Wait_or_not(unsigned wait = 0)
{
#ifdef NANA_AUTOMATIC_GUI_TESTING
return wait;
#else
return 0;
#endif
}
namespace nana namespace nana
{ {
@ -37,38 +28,60 @@ namespace nana
} }
} }
void exec(unsigned wait, std::function<void()> f, unsigned wait_end, form *fm ) void click(widget& w)
{ {
#ifdef NANA_ADD_DEF_AUTOMATIC_GUI_TESTING arg_click arg;
if (!wait) arg.window_handle = w.handle();
wait = 10; w.events().click.emit(arg);
if (!f) }
f = []() {API::exit(); };
#endif
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"; void pump()
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?
}
});
detail::bedrock::instance().pump_event(nullptr, false); 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::function<void()>f // = {} ///< 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()) if (t.joinable())
t.join(); t.join();
#else
pump();
#endif
} }
}//end namespace nana }//end namespace nana