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
- 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

View File

@ -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<typename Form, bool IsVisible = true>
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
#endif

View File

@ -14,18 +14,9 @@
#include <nana/gui/wvl.hpp>
#include <nana/gui/detail/bedrock.hpp>
#include <thread>
#include <iostream>
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<void()> 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::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())
t.join();
#else
pump();
#endif
}
}//end namespace nana