1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/* This file is part of lomiri-action-api
* Copyright 2013 Canonical Ltd.
*
* lomiri-action-api is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* lomiri-action-api is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tst_actioncontext.h"
#include <lomiri/action/ActionContext>
#include <lomiri/action/ActionManager>
#include <lomiri/action/Action>
#include <QtTest/QtTest>
using namespace lomiri::action;
void
TestActionContext::setActive()
{
lomiri::action::ActionContext ctx;
ctx.setActive(false);
QSignalSpy spy(&ctx, SIGNAL(activeChanged(bool)));
ctx.setActive(true);
QVERIFY(ctx.active() == true);
QCOMPARE(spy.count(), 1);
ctx.setActive(false);
QVERIFY(ctx.active() == false);
QCOMPARE(spy.count(), 2);
QList<QVariant> arguments;
arguments = spy.takeFirst();
QVERIFY(arguments.at(0).toBool() == true);
arguments = spy.takeFirst();
QVERIFY(arguments.at(0).toBool() == false);
spy.clear();
ctx.setActive(false);
QCOMPARE(spy.count(), 0);
}
void
TestActionContext::actionOperations()
{
lomiri::action::ActionContext *ctx = new lomiri::action::ActionContext(this);
lomiri::action::Action *action1 = new lomiri::action::Action(this);
lomiri::action::Action *action2 = new lomiri::action::Action(this);
QSignalSpy spy(ctx, SIGNAL(actionsChanged()));
ctx->addAction(action1);
ctx->addAction(action2);
ctx->addAction(action2);
QVERIFY(spy.count() == 2);
QVERIFY(ctx->actions().contains(action1) &&
ctx->actions().contains(action2));
ctx->removeAction(action1);
ctx->removeAction(action1);
QVERIFY(spy.count() == 3);
QVERIFY(!ctx->actions().contains(action1) &&
ctx->actions().contains(action2));
ctx->addAction(action1);
QVERIFY(spy.count() == 4);
QVERIFY(ctx->actions().contains(action1) &&
ctx->actions().contains(action2));
}
void
TestActionContext::deletedActions()
{
/* When action is added to the context and then deleted without
* being removed we must detect this and remove the action from the
* context so that we don't get dangling pointers.
*/
ActionContext *ctx = new ActionContext(this);
Action *action1 = new Action();
Action *action2 = new Action();
ctx->addAction(action1);
ctx->addAction(action2);
QSignalSpy spy(ctx, SIGNAL(actionsChanged()));
// this should now also make the context to remove the action
delete action2;
QCOMPARE(spy.count(), 1);
QVERIFY(!ctx->actions().contains(action2)); // make sure the pointer was removed
action2 = 0;
delete action1;
QCOMPARE(spy.count(), 2);
QVERIFY(!ctx->actions().contains(action1)); // make sure the pointer was removed
action1 = 0;
}
|