2016-12-15 20:48:35 +01:00
|
|
|
/*
|
2018-11-23 21:29:54 +01:00
|
|
|
CommandQueue(Test) - verify functionality of SteamDispatcher queue component
|
2016-12-15 20:48:35 +01:00
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2016, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
#include "steam/control/command-queue.hpp"
|
|
|
|
|
#include "steam/control/command-def.hpp"
|
2016-12-25 18:49:57 +01:00
|
|
|
#include "lib/symbol.hpp"
|
2016-12-25 19:30:59 +01:00
|
|
|
#include "lib/util.hpp"
|
2016-12-15 20:48:35 +01:00
|
|
|
|
2018-11-15 23:42:43 +01:00
|
|
|
#include "steam/control/test-dummy-commands.hpp"
|
2016-12-15 20:48:35 +01:00
|
|
|
|
|
|
|
|
|
2024-03-16 02:04:47 +01:00
|
|
|
namespace steam {
|
|
|
|
|
namespace control{
|
|
|
|
|
namespace test {
|
2016-12-15 20:48:35 +01:00
|
|
|
|
2016-12-25 18:49:57 +01:00
|
|
|
using lib::Symbol;
|
2016-12-25 19:30:59 +01:00
|
|
|
using util::isnil;
|
2024-03-16 02:04:47 +01:00
|
|
|
using LERR_(UNBOUND_ARGUMENTS);
|
2016-12-15 20:48:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // test fixture...
|
|
|
|
|
|
2016-12-25 18:49:57 +01:00
|
|
|
const Symbol COMMAND_1{"test.queue.command1"};
|
|
|
|
|
const Symbol COMMAND_3{"test.queue.command3"};
|
2016-12-15 20:48:35 +01:00
|
|
|
|
|
|
|
|
}//(End) test fixture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************//**
|
2018-11-23 21:29:54 +01:00
|
|
|
* @test verify proper working of queue management used within SteamDispatcher.
|
2016-12-15 20:48:35 +01:00
|
|
|
* - can enqueue and dequeue command messages
|
|
|
|
|
* - handling of priority messages
|
|
|
|
|
* @see CommandQueue
|
|
|
|
|
* @see DispatcherLoop
|
2018-11-23 21:29:54 +01:00
|
|
|
* @see SteamDispatcher
|
2016-12-15 20:48:35 +01:00
|
|
|
* @see DispatcherLooper_test
|
|
|
|
|
*/
|
|
|
|
|
class CommandQueue_test : public Test
|
|
|
|
|
{
|
|
|
|
|
|
2016-12-25 18:49:57 +01:00
|
|
|
//------------------FIXTURE
|
|
|
|
|
public:
|
|
|
|
|
CommandQueue_test()
|
|
|
|
|
{
|
|
|
|
|
CommandDef (COMMAND_1)
|
|
|
|
|
.operation (command1::operate)
|
|
|
|
|
.captureUndo (command1::capture)
|
|
|
|
|
.undoOperation (command1::undoIt)
|
|
|
|
|
;
|
|
|
|
|
CommandDef (COMMAND_3)
|
|
|
|
|
.operation (command3::operate)
|
|
|
|
|
.captureUndo (command3::capture)
|
|
|
|
|
.undoOperation (command3::undoIt)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
~CommandQueue_test()
|
|
|
|
|
{
|
|
|
|
|
Command::remove (COMMAND_1);
|
|
|
|
|
Command::remove (COMMAND_3);
|
|
|
|
|
}
|
|
|
|
|
//-------------(End)FIXTURE
|
2016-12-15 20:48:35 +01:00
|
|
|
|
2024-03-16 02:04:47 +01:00
|
|
|
|
2016-12-15 20:48:35 +01:00
|
|
|
virtual void
|
|
|
|
|
run (Arg)
|
|
|
|
|
{
|
|
|
|
|
verifyBasics();
|
2016-12-25 22:26:16 +01:00
|
|
|
verifyExecutabilityCheck();
|
2016-12-15 20:48:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
verifyBasics()
|
|
|
|
|
{
|
2016-12-25 19:30:59 +01:00
|
|
|
Command com11 = Command(COMMAND_1).newInstance();
|
|
|
|
|
Command com12 = Command(COMMAND_1).newInstance();
|
|
|
|
|
|
|
|
|
|
com11.bind(42);
|
|
|
|
|
com12.bind(47);
|
|
|
|
|
|
|
|
|
|
CommandQueue queue;
|
|
|
|
|
CHECK (isnil(queue));
|
|
|
|
|
|
2017-04-16 16:16:26 +02:00
|
|
|
queue.feed (Command{com11});
|
|
|
|
|
queue.feed (Command{com12});
|
2016-12-25 19:30:59 +01:00
|
|
|
|
|
|
|
|
CHECK (2 == queue.size());
|
|
|
|
|
|
|
|
|
|
Command x = queue.pop();
|
|
|
|
|
CHECK (1 == queue.size());
|
2016-12-25 21:52:52 +01:00
|
|
|
CHECK (x == com11);
|
2016-12-25 19:30:59 +01:00
|
|
|
|
|
|
|
|
queue.clear();
|
|
|
|
|
CHECK (0 == queue.size());
|
|
|
|
|
CHECK (queue.empty());
|
2016-12-15 20:48:35 +01:00
|
|
|
}
|
2016-12-25 22:26:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
verifyExecutabilityCheck()
|
|
|
|
|
{
|
|
|
|
|
Command com11 = Command(COMMAND_1).newInstance();
|
|
|
|
|
Command com12 = Command(COMMAND_1).newInstance();
|
|
|
|
|
|
|
|
|
|
com11.bind(42);
|
|
|
|
|
// NOT binding the second command...
|
|
|
|
|
|
|
|
|
|
CommandQueue queue;
|
2017-04-16 16:16:26 +02:00
|
|
|
queue.feed (Command{com11});
|
2016-12-25 22:26:16 +01:00
|
|
|
CHECK (1 == queue.size());
|
|
|
|
|
|
2017-04-16 16:16:26 +02:00
|
|
|
VERIFY_ERROR (UNBOUND_ARGUMENTS, queue.feed (Command{com12}));
|
2016-12-25 22:26:16 +01:00
|
|
|
CHECK (1 == queue.size());
|
|
|
|
|
|
|
|
|
|
queue.pop().execSync();
|
|
|
|
|
VERIFY_ERROR (UNBOUND_ARGUMENTS, com12.execSync());
|
|
|
|
|
}
|
2016-12-15 20:48:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
LAUNCHER (CommandQueue_test, "unit controller");
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
}}} // namespace steam::control::test
|