File: tst_actionmanager.cpp

package info (click to toggle)
lomiri-action-api 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,104 kB
  • sloc: cpp: 3,784; ansic: 1,052; xml: 64; makefile: 54
file content (892 lines) | stat: -rw-r--r-- 31,230 bytes parent folder | download | duplicates (3)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
/* 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_actionmanager.h"

#include <lomiri/action/ActionManager>
#include <lomiri/action/ActionContext>
#include <lomiri/action/Action>

#include <lomiri/action/PreviewAction>
#include <lomiri/action/PreviewRangeParameter>

#include <QtTest/QtTest>

// needed for gio includes.
#undef signals
#include <gio/gio.h>

using namespace lomiri::action;

void
TestActionManager::initTestCase()
{
    manager = new ActionManager(this);
    dbusc = 0;
    action_group = 0;

    dbusc = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
    QVERIFY2(dbusc != 0, "Could not get session bus.");
    if (dbusc) {
        action_group = g_dbus_action_group_get(dbusc,
                                               g_dbus_connection_get_unique_name(dbusc),
                                               "/com/lomiri/actions");
        QVERIFY2(action_group != 0, "Could not get action group");
    }
}

void
TestActionManager::cleanupTestCase()
{
    g_clear_object(&dbusc);
    g_clear_object(&action_group);
}

void
TestActionManager::cleanup()
{
    // after each test make sure the manager is left in a clean state
    QVERIFY(manager->actions().count() == 1);
    QVERIFY(manager->localContexts().isEmpty());
}


void
TestActionManager::testGlobalContext()
{
    ActionContext *globalctx = manager->globalContext();
    QVERIFY(globalctx != 0);
}

void
TestActionManager::actionOperations()
{
    Action *action1 = new Action(manager);
    action1->setText("My Global Action");
    action1->setName("Global");

    Action *action2 = new Action(manager);
    action2->setText("Foo");


    QSignalSpy spy(manager, SIGNAL(actionsChanged()));
    manager->addAction(action1);
    QCOMPARE(spy.count(), 1);
    manager->addAction(action2);
    QCOMPARE(spy.count(), 2);
    manager->addAction(action2);
    QCOMPARE(spy.count(), 2);

    QSet<Action *>actions = manager->actions();
    QVERIFY(actions.contains(action1) && actions.contains(action2));

    manager->removeAction(action2);
    QCOMPARE(spy.count(), 3);
    manager->removeAction(action2);
    QCOMPARE(spy.count(), 3);
    actions = manager->actions();
    QVERIFY(actions.contains(action1) && !actions.contains(action2));

    manager->removeAction(action1);

    /*! \todo verify from the bus that actions appear there */
}

void
TestActionManager::contextOperations()
{
    ActionContext *gctx = manager->globalContext();
    ActionContext *ctx1 = new ActionContext(manager);
    ActionContext *ctx2 = new ActionContext(manager);
    ActionContext *ctx3 = new ActionContext(manager);

    Action *action1 = new Action(manager);
    Action *action2 = new Action(manager);
    Action *action3 = new Action(manager);
    Action *action4 = new Action(manager);
    Action *action5 = new Action(manager);

    gctx->addAction(action1);

    QSignalSpy ctxspy(manager, SIGNAL(localContextsChanged()));
    manager->addLocalContext(ctx1);
    QCOMPARE(ctxspy.count(), 1);
    ctx1->addAction(action2);
    ctx1->addAction(action3);


    ctx2->addAction(action4);
    ctx2->addAction(action5);
    manager->addLocalContext(ctx2);
    manager->addLocalContext(ctx2);
    QCOMPARE(ctxspy.count(), 2);

    QVERIFY(manager->localContexts().contains(ctx1) &&
            manager->localContexts().contains(ctx2));

    manager->removeLocalContext(ctx2);
    manager->removeLocalContext(ctx2);
    QVERIFY( manager->localContexts().contains(ctx1) &&
            !manager->localContexts().contains(ctx2));
    QCOMPARE(ctxspy.count(), 3);
    manager->addLocalContext(ctx2);
    QCOMPARE(ctxspy.count(), 4);
    QVERIFY(manager->localContexts().contains(ctx1) &&
            manager->localContexts().contains(ctx2));

    ctx2->setActive(true);
    ctx1->setActive(true);
    QVERIFY(!ctx2->active());

    // if new context is added and it's active
    // make it the active local one in the manager.
    ctx3->setActive(true);
    manager->addLocalContext(ctx3);
    QVERIFY(!ctx1->active());
    QVERIFY(!ctx2->active());
    QVERIFY(ctx3->active());


    /*! \todo verify actions from the bus */
    gctx->removeAction(action1);
    gctx->addAction(action1);

    gctx->removeAction(action1);
    manager->removeLocalContext(ctx1);
    manager->removeLocalContext(ctx2);
    manager->removeLocalContext(ctx3);
    QVERIFY(manager->actions().count() == 1);
}

void
TestActionManager::actionPropertyChanges()
{
    ActionContext *ctx1 = new ActionContext(manager);
    ActionContext *ctx2 = new ActionContext(manager);

    Action *action1 = new Action(manager);
    Action *action2 = new Action(manager);
    Action *action3 = new Action(manager);
    Action *action4 = new Action(manager);
    Action *action5 = new Action(manager);
    Action *action6 = new Action(manager);

    QList<QVariant> arguments;

    manager->globalContext()->addAction(action1);
    manager->globalContext()->addAction(action2);
    ctx1->addAction(action3);
    ctx1->addAction(action4);
    ctx2->addAction(action5);
    ctx2->addAction(action6);
    manager->addLocalContext(ctx1);
    manager->addLocalContext(ctx2);

    // force both local context to be disabled
    ctx1->setActive(false);
    ctx2->setActive(false);

    action1->setName("Global");
    action1->setText("My Global Action");
    QSignalSpy action1_spy(action1, SIGNAL(triggered(QVariant)));
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group), "Global", NULL);
    action1_spy.wait();
    QCOMPARE(action1_spy.count(), 1);
    arguments = action1_spy.takeFirst();
    QVERIFY(arguments.at(0).isNull());

    action2->setText("Action2");
    action2->setEnabled(false);


    ctx1->setActive(true);


    action3->setText("Action3");
    action3->setName("InsideContext");

    action4->setName("CallTo");
    action4->setParameterType(Action::String);
    QSignalSpy action4_spy(action4, SIGNAL(triggered(QVariant)));
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "CallTo",
                                   g_variant_new_string("tel://+0123456789"));
    action4_spy.wait();
    QCOMPARE(action4_spy.count(), 1);
    arguments = action4_spy.takeFirst();
    QCOMPARE(arguments.at(0).toString(), QString("tel://+0123456789"));


    ctx2->setActive(true);


    QSignalSpy action5_spy(action5, SIGNAL(triggered(QVariant)));
    action5->setParameterType(Action::Bool);
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   qPrintable(action5->name()),
                                   g_variant_new_boolean(true));
    action5_spy.wait();
    action5->setParameterType(Action::Integer);
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   qPrintable(action5->name()),
                                   g_variant_new_int32(1337));
    action5_spy.wait();
    action5->setParameterType(Action::Real);
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   qPrintable(action5->name()),
                                   g_variant_new_double(5.5f));
    action5_spy.wait();
    QCOMPARE(action5_spy.count(), 3);
    arguments = action5_spy.takeFirst();
    QCOMPARE(arguments.at(0).toBool(), true);
    arguments = action5_spy.takeFirst();
    QCOMPARE(arguments.at(0).toInt(), 1337);
    arguments = action5_spy.takeFirst();
    QCOMPARE(arguments.at(0).toFloat(), 5.5f);

    action6->setParameterType(Action::String);
    action6->setParameterType(Action::None);

    manager->removeLocalContext(ctx1);
    manager->removeLocalContext(ctx2);
    manager->removeAction(action1);
    manager->removeAction(action2);
}

void
TestActionManager::deletedGlobalContext()
{
    // detect if the client accidentally calls delete on global context
    // and make sure we don't crash
    delete manager->globalContext();
}

void
TestActionManager::deletedLocalContext()
{
    // if local context is added to the manager and delete is called for it
    // before it's removed we must detect this and not crash

    ActionContext *ctx1 = new ActionContext();
    ActionContext *ctx2 = new ActionContext();

    Action *action1 = new Action(ctx1);
    Action *action2 = new Action(ctx1);
    Action *action3 = new Action(ctx1);
    Action *action4 = new Action(ctx2);
    Action *action5 = new Action(ctx2);


    ctx1->addAction(action1);
    ctx1->addAction(action2);
    ctx1->addAction(action3);
    manager->addLocalContext(ctx1);

    ctx2->addAction(action4);
    ctx2->addAction(action5);
    manager->addLocalContext(ctx2);

    QSignalSpy ctxspy(manager, SIGNAL(localContextsChanged()));

    delete ctx1;
    QCOMPARE(ctxspy.count(), 1);
    QVERIFY(!manager->localContexts().contains(ctx1));
    ctx1 = 0;

    delete ctx2;
    QCOMPARE(ctxspy.count(), 2);
    QVERIFY(!manager->localContexts().contains(ctx2));
    ctx2 = 0;
}

void
TestActionManager::deletedAction()
{
    // if action is added to the manager and delete is called for it
    // before it's removed we must detect this and not crash

    ActionContext *gctx = manager->globalContext();
    ActionContext *ctx1 = new ActionContext();
    ActionContext *ctx2 = new ActionContext();

    Action *action1 = new Action(gctx);
    Action *action2 = new Action(ctx1);
    Action *action3 = new Action(ctx1);
    Action *action4 = new Action(ctx2);
    Action *action5 = new Action(ctx2);


    gctx->addAction(action1);

    ctx1->addAction(action2);
    ctx1->addAction(action3);
    manager->addLocalContext(ctx1);

    ctx2->addAction(action4);
    ctx2->addAction(action5);
    manager->addLocalContext(ctx2);

    QSignalSpy spy(manager, SIGNAL(actionsChanged()));
    QCOMPARE(manager->actions().count(), 6);

    // delete action1 directly from globalContext
    delete action1;
    QCOMPARE(spy.count(), 1);
    QVERIFY(!manager->actions().contains(action1));
    QCOMPARE(manager->actions().count(), 5);
    action1 = 0;

    // delete action2 directly from ctx1
    delete action2;
    QCOMPARE(spy.count(), 2);
    QVERIFY(!manager->actions().contains(action2));
    QCOMPARE(manager->actions().count(), 4);
    action2 = 0;

    // remove action3 indirectly by destroying ctx1
    delete ctx1;
    QCOMPARE(spy.count(), 3);
    QVERIFY(!manager->actions().contains(action3));
    QCOMPARE(manager->actions().count(), 3);
    ctx1 = 0;
    action3 = 0;

    // delete action4 and action5 indirectly by destroying ctx2
    delete ctx2;
    QCOMPARE(spy.count(), 5); // actionsChanged() gets called multiple times (once per each action in a context)
    QVERIFY(!manager->actions().contains(action4));
    QVERIFY(!manager->actions().contains(action5));
    QCOMPARE(manager->actions().count(), 1);
    QVERIFY(manager->localContexts().isEmpty());
    ctx2 = 0;
    action4 = 0;
    action5 = 0;

}

void
TestActionManager::actionInMultipleContext()
{
    /* If Action is added to multiple contexts
     * the manager has to be aware of the action
     * as long as it's part of any of the contexts.
     */

    ActionContext *gctx = manager->globalContext();
    ActionContext *ctx1 = new ActionContext(manager);
    ActionContext *ctx2 = new ActionContext(manager);

    Action *action1 = new Action(manager);
    Action *action2 = new Action(manager);
    Action *action3 = new Action(manager);

    QSignalSpy spy(manager, SIGNAL(actionsChanged()));

    gctx->addAction(action1);

    ctx1->addAction(action1);
    ctx1->addAction(action2);

    ctx2->addAction(action1);
    ctx2->addAction(action3);

    manager->addLocalContext(ctx1);
    manager->addLocalContext(ctx2);

    // 3 actions have been added in total
    QCOMPARE(spy.count(), 3);
    QCOMPARE(manager->actions().count(), 4);

    spy.clear();
    manager->removeLocalContext(ctx2); // removes only action3, action1 is shared.
    QCOMPARE(spy.count(), 1);
    QCOMPARE(manager->actions().count(), 3);
    // and now add it back
    manager->addLocalContext(ctx2);
    QCOMPARE(spy.count(), 2);
    QCOMPARE(manager->actions().count(), 4);

    spy.clear();
    gctx->removeAction(action1);
    QCOMPARE(spy.count(), 0);
    QCOMPARE(manager->actions().count(), 4);
    QVERIFY(manager->actions().contains(action1));

    ctx1->removeAction(action1);
    QCOMPARE(spy.count(), 0);
    QCOMPARE(manager->actions().count(), 4);
    QVERIFY(manager->actions().contains(action1));

    // remove the action from the last context
    ctx2->removeAction(action1);
    QCOMPARE(spy.count(), 1);
    QCOMPARE(manager->actions().count(), 3);
    QVERIFY(!manager->actions().contains(action1));

    manager->removeLocalContext(ctx1);
    manager->removeLocalContext(ctx2);
}

void
TestActionManager::localContextOverridesGlobalContext()
{
    /* If local context defines an action with the same
     * name with an action in the global context the
     * local context action must override the global
     * one.
     */

    ActionContext *gctx = manager->globalContext();
    ActionContext *ctx1 = new ActionContext(manager);
    ActionContext *ctx2 = new ActionContext(manager);

    Action *action1 = new Action(manager);
    Action *action2 = new Action(manager);
    Action *action3 = new Action(manager);

    QSignalSpy spy1(action1, SIGNAL(triggered(QVariant)));
    QSignalSpy spy2(action2, SIGNAL(triggered(QVariant)));
    QSignalSpy spy3(action3, SIGNAL(triggered(QVariant)));

    action1->setName("MyAction");
    action2->setName("MyAction");
    action3->setName("MyAction");

    ctx1->addAction(action2);
    ctx2->addAction(action3);

    gctx->addAction(action1);
    manager->addLocalContext(ctx1);
    manager->addLocalContext(ctx2);


    /* no local context has been activated.
     * triggering Myaction must now trigger action1
     */
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group), "MyAction", NULL);
    spy1.wait();
    QCOMPARE(spy1.count(), 1);
    QCOMPARE(spy2.count(), 0);
    QCOMPARE(spy3.count(), 0);
    spy1.clear();


    ctx1->setActive(true);
    /* ctx1 is the active one.
     * triggering Myaction must now trigger action2
     */
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group), "MyAction", NULL);
    spy2.wait();
    QCOMPARE(spy1.count(), 0);
    QCOMPARE(spy2.count(), 1);
    QCOMPARE(spy3.count(), 0);
    spy2.clear();


    ctx2->setActive(true);
    /* ctx2 is the active one.
     * triggering Myaction must now trigger action3
     */
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group), "MyAction", NULL);
    spy3.wait();
    QCOMPARE(spy1.count(), 0);
    QCOMPARE(spy2.count(), 0);
    QCOMPARE(spy3.count(), 1);
    spy3.clear();


    manager->removeLocalContext(ctx2);
    /* removed the current active context.
     * triggering Myaction must now trigger action1 again from global context
     */
    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group), "MyAction", NULL);
    spy1.wait();
    QCOMPARE(spy1.count(), 1);
    QCOMPARE(spy2.count(), 0);
    QCOMPARE(spy3.count(), 0);
    spy1.clear();


    gctx->removeAction(action1);
    manager->removeLocalContext(ctx1);

}

void
TestActionManager::previewParameters()
{
    ActionContext *ctx1 = new ActionContext(manager);

    PreviewAction *action1 = new PreviewAction(manager);
    PreviewAction *action2 = new PreviewAction(ctx1);

    PreviewRangeParameter *param1 = new PreviewRangeParameter(action1);

    PreviewRangeParameter *param2 = new PreviewRangeParameter(action2);
    PreviewRangeParameter *param3 = new PreviewRangeParameter(action2);

    action1->setName("MyPreviewAction1");
    action2->setName("MyPreviewAction2");


    // goes in to the global context
    manager->addAction(action1);
    action1->addParameter(param1);

    ctx1->addAction(action2);
    action2->addParameter(param2);
    action2->addParameter(param3);
    manager->addLocalContext(ctx1);

    QSignalSpy spy_action1_started(action1, SIGNAL(started()));
    QSignalSpy spy_action1_triggered(action1, SIGNAL(triggered(QVariant)));
    QSignalSpy spy_action1_cancelled(action1, SIGNAL(cancelled()));
    QSignalSpy spy_action1_resetted(action1, SIGNAL(resetted()));

    QSignalSpy spy_action2_started(action2, SIGNAL(started()));
    QSignalSpy spy_action2_triggered(action2, SIGNAL(triggered(QVariant)));
    QSignalSpy spy_action2_cancelled(action2, SIGNAL(cancelled()));
    QSignalSpy spy_action2_resetted(action2, SIGNAL(resetted()));

    QSignalSpy spy_param1_value(param1, SIGNAL(valueChanged(float)));
    QSignalSpy spy_param2_value(param2, SIGNAL(valueChanged(float)));
    QSignalSpy spy_param3_value(param3, SIGNAL(valueChanged(float)));




    // no context is active, we only have MyPreviewAction1 from globalContext
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("start"));
    QTest::qWait(100);
    QCOMPARE(spy_action1_started.count(),   1);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action1_started.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("reset"));
    QTest::qWait(100);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  1);
    spy_action1_resetted.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("commit"));
    QTest::qWait(100);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 1);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action1_triggered.clear();

    /* we don't actually have a corresponging signal for this state,
     * but HUD sends it anyway when the HUD UI parameterized view is
     * closed, so let's send it
     */
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("end"));
    QTest::qWait(100);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);



    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("start"));
    QTest::qWait(100);
    QCOMPARE(spy_action1_started.count(),   1);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action1_started.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("cancel"));
    QTest::qWait(100);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 1);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action1_cancelled.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("end"));
    QTest::qWait(100);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);



    // activate ctx1
    ctx1->setActive(true);

    QTest::qWait(100);
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("start"));
    QTest::qWait(100);
    QCOMPARE(spy_action2_started.count(),   1);
    QCOMPARE(spy_action2_triggered.count(), 0);
    QCOMPARE(spy_action2_cancelled.count(), 0);
    QCOMPARE(spy_action2_resetted.count(),  0);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action2_started.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("reset"));
    QTest::qWait(100);
    QCOMPARE(spy_action2_started.count(),   0);
    QCOMPARE(spy_action2_triggered.count(), 0);
    QCOMPARE(spy_action2_cancelled.count(), 0);
    QCOMPARE(spy_action2_resetted.count(),  1);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action2_resetted.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("commit"));
    QTest::qWait(100);
    QCOMPARE(spy_action2_started.count(),   0);
    QCOMPARE(spy_action2_triggered.count(), 1);
    QCOMPARE(spy_action2_cancelled.count(), 0);
    QCOMPARE(spy_action2_resetted.count(),  0);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action2_triggered.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("end"));
    QTest::qWait(100);
    QCOMPARE(spy_action2_started.count(),   0);
    QCOMPARE(spy_action2_triggered.count(), 0);
    QCOMPARE(spy_action2_cancelled.count(), 0);
    QCOMPARE(spy_action2_resetted.count(),  0);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);



    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("start"));
    QTest::qWait(100);
    QCOMPARE(spy_action2_started.count(),   1);
    QCOMPARE(spy_action2_triggered.count(), 0);
    QCOMPARE(spy_action2_cancelled.count(), 0);
    QCOMPARE(spy_action2_resetted.count(),  0);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action2_started.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("cancel"));
    QTest::qWait(100);
    QCOMPARE(spy_action2_started.count(),   0);
    QCOMPARE(spy_action2_triggered.count(), 0);
    QCOMPARE(spy_action2_cancelled.count(), 1);
    QCOMPARE(spy_action2_resetted.count(),  0);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);
    spy_action2_cancelled.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("end"));
    QTest::qWait(100);
    QCOMPARE(spy_action2_started.count(),   0);
    QCOMPARE(spy_action2_triggered.count(), 0);
    QCOMPARE(spy_action2_cancelled.count(), 0);
    QCOMPARE(spy_action2_resetted.count(),  0);
    QCOMPARE(spy_action1_started.count(),   0);
    QCOMPARE(spy_action1_triggered.count(), 0);
    QCOMPARE(spy_action1_cancelled.count(), 0);
    QCOMPARE(spy_action1_resetted.count(),  0);



    // now check some range value updates

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("start"));
    QTest::qWait(100);
    spy_action1_started.clear();

    // param1
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-0",
                                   g_variant_new_double(1.0f));
    QTest::qWait(100);
    QCOMPARE(spy_param1_value.count(), 1);
    QCOMPARE(spy_param2_value.count(), 0);
    QCOMPARE(spy_param3_value.count(), 0);
    QCOMPARE(spy_param1_value.takeFirst().at(0).toFloat(), 1.0f);

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-0",
                                   g_variant_new_double(1.1f));
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-0",
                                   g_variant_new_double(1.2f));
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-0",
                                   g_variant_new_double(1.3f));
    QTest::qWait(100);
    QCOMPARE(spy_param1_value.count(), 3);
    QCOMPARE(spy_param2_value.count(), 0);
    QCOMPARE(spy_param3_value.count(), 0);
    QCOMPARE(spy_param1_value.takeFirst().at(0).toFloat(), 1.1f);
    QCOMPARE(spy_param1_value.takeFirst().at(0).toFloat(), 1.2f);
    QCOMPARE(spy_param1_value.takeFirst().at(0).toFloat(), 1.3f);

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("cancel"));
    QTest::qWait(100);
    spy_action1_cancelled.clear();

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction1",
                                   g_variant_new_string("end"));
    QTest::qWait(100);


    // then the others
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("start"));
    QTest::qWait(100);
    spy_action2_started.clear();

    // param2
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-1",
                                   g_variant_new_double(2.0f));
    // param3
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-2",
                                   g_variant_new_double(3.0f));
    QTest::qWait(100);
    QCOMPARE(spy_param1_value.count(), 0);
    QCOMPARE(spy_param2_value.count(), 1);
    QCOMPARE(spy_param3_value.count(), 1);
    QCOMPARE(spy_param2_value.takeFirst().at(0).toFloat(), 2.0f);
    QCOMPARE(spy_param3_value.takeFirst().at(0).toFloat(), 3.0f);

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-1",
                                   g_variant_new_double(2.1f));
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-2",
                                   g_variant_new_double(3.1f));
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-1",
                                   g_variant_new_double(2.2f));
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-2",
                                   g_variant_new_double(3.2f));
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-1",
                                   g_variant_new_double(2.3f));
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-2",
                                   g_variant_new_double(3.3f));
    QTest::qWait(100);
    QCOMPARE(spy_param1_value.count(), 0);
    QCOMPARE(spy_param2_value.count(), 3);
    QCOMPARE(spy_param3_value.count(), 3);
    QCOMPARE(spy_param2_value.takeFirst().at(0).toFloat(), 2.1f);
    QCOMPARE(spy_param2_value.takeFirst().at(0).toFloat(), 2.2f);
    QCOMPARE(spy_param2_value.takeFirst().at(0).toFloat(), 2.3f);
    QCOMPARE(spy_param3_value.takeFirst().at(0).toFloat(), 3.1f);
    QCOMPARE(spy_param3_value.takeFirst().at(0).toFloat(), 3.2f);
    QCOMPARE(spy_param3_value.takeFirst().at(0).toFloat(), 3.3f);

    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("cancel"));
    QTest::qWait(100);
    spy_action2_cancelled.clear();
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "MyPreviewAction2",
                                   g_variant_new_string("end"));
    QTest::qWait(100);


    // update some parameters
    action1->setCommitLabel("Do Stuff");
    param1->setMinimumValue(-50.0f);
    param1->setMaximumValue(50.0f);
    param1->setValue(25.0f);
    /*! \todo there is actually no way of verifying these right now without accessing them from
     *        HUD menumodels or creating a HUD query..
     */


    // remove parameter
    action2->removeParameter(param3);
    g_action_group_activate_action(G_ACTION_GROUP(action_group),
                                   "lomiri-action-range-param-2",
                                   g_variant_new_double(100.0f));
    QTest::qWait(100);
    spy_param3_value.wait(100);
    QCOMPARE(spy_param3_value.count(), 0); // removed parameter should not receive updates.


    manager->removeAction(action1);
    manager->removeLocalContext(ctx1);
}