diff options
author | Janne Heikkilä <janne.heikkila@symbio.com> | 2010-10-22 14:54:25 +0300 |
---|---|---|
committer | Stanislav Ionascu <stanislav.ionascu@nokia.com> | 2010-12-30 12:55:15 +0200 |
commit | cc5e7d9acb7ed3fc0e94a976d663406a8f6b0bfc (patch) | |
tree | 6d8662c5a441ec79d310f9aad7f84e401799124a /tests | |
parent | f0be6883dfae636784f6a3f3a995d21db2bbe89c (diff) |
Fixes: NB#199035 - MObjectMenu doesn't work without a target widget
RevBy: Stanislav Ionascu
Details: Passing target widget to objectmenu's constructor is now optional. Menu
will also include/show actions that are added to the objectmenu itself.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ut_mobjectmenu/ut_mobjectmenu.cpp | 72 | ||||
-rw-r--r-- | tests/ut_mobjectmenu/ut_mobjectmenu.h | 3 |
2 files changed, 67 insertions, 8 deletions
diff --git a/tests/ut_mobjectmenu/ut_mobjectmenu.cpp b/tests/ut_mobjectmenu/ut_mobjectmenu.cpp index ef46c5cf..11b4b713 100644 --- a/tests/ut_mobjectmenu/ut_mobjectmenu.cpp +++ b/tests/ut_mobjectmenu/ut_mobjectmenu.cpp @@ -47,21 +47,24 @@ void Ut_MObjectMenu::cleanupTestCase() void Ut_MObjectMenu::testConstructionAndDestruction() { + //test construction and destruction with target widget MWidget *widget = new MWidget(); MObjectMenu *menu = new MObjectMenu(widget); MObjectMenuModel *model = dynamic_cast<MObjectMenuModel *>(menu->model()); - - // check that the model has been created. QVERIFY(model != NULL); - - // check that the action count is zero QVERIFY(model->actions().count() == 0); - delete menu; delete widget; + + //test construction and destruction without target widget + menu = new MObjectMenu(NULL); + model = dynamic_cast<MObjectMenuModel *>(menu->model()); + QVERIFY(model != NULL); + QVERIFY(model->actions().count() == 0); + delete menu; } -void Ut_MObjectMenu::testActionsAddingAndRemoving() +void Ut_MObjectMenu::testActionsUsingTargetWidget() { MWidget *widget = new MWidget(); MAction *action1 = new MAction("Test1", widget); @@ -117,7 +120,6 @@ void Ut_MObjectMenu::testActionsAddingAndRemoving() QCOMPARE(model->actions().at(0), action2); QCOMPARE(model->actions().at(1), action1); - action1->setText("Test234"); QCOMPARE(addedSpy.count(), 2); QCOMPARE(removedSpy.count(), 1); @@ -125,6 +127,62 @@ void Ut_MObjectMenu::testActionsAddingAndRemoving() QCOMPARE(model->actions().count(), 2); QCOMPARE(model->actions().at(0), action2); QCOMPARE(model->actions().at(1), action1); + + delete widget; + delete menu; +} + +void Ut_MObjectMenu::testActionsUsingObjectMenu() +{ + MObjectMenu *menu = new MObjectMenu(NULL); + MObjectMenuModel *model = dynamic_cast<MObjectMenuModel *>(menu->model()); + QCOMPARE(model->actions().count(), 0); + + QSignalSpy addedSpy(model, SIGNAL(actionAdded(MAction *))); + QSignalSpy removedSpy(model, SIGNAL(actionRemoved(MAction *))); + QSignalSpy modifiedSpy(model, SIGNAL(actionModified(MAction *))); + + MAction *action1 = new MAction("Test1", menu); + MAction *action2 = new MAction("Test2", menu); + + menu->addAction(action1); + QCOMPARE(addedSpy.count(), 1); + QCOMPARE(removedSpy.count(), 0); + QCOMPARE(modifiedSpy.count(), 0); + QCOMPARE(model->actions().count(), 1); + QCOMPARE(model->actions().at(0), action1); + + menu->removeAction(action1); + QCOMPARE(addedSpy.count(), 1); + QCOMPARE(removedSpy.count(), 1); + QCOMPARE(modifiedSpy.count(), 0); + QCOMPARE(model->actions().count(), 0); + + menu->addAction(action1); + menu->addAction(action2); + QCOMPARE(addedSpy.count(), 3); + QCOMPARE(removedSpy.count(), 1); + QCOMPARE(modifiedSpy.count(), 0); + QCOMPARE(model->actions().count(), 2); + QCOMPARE(model->actions().at(0), action1); + QCOMPARE(model->actions().at(1), action2); + + action1->setText("Test234"); + QCOMPARE(addedSpy.count(), 3); + QCOMPARE(removedSpy.count(), 1); + QCOMPARE(modifiedSpy.count(), 1); + QCOMPARE(model->actions().count(), 2); + QCOMPARE(model->actions().at(0), action1); + QCOMPARE(model->actions().at(1), action2); + + menu->removeAction(action1); + menu->removeAction(action2); + QCOMPARE(addedSpy.count(), 3); + QCOMPARE(removedSpy.count(), 3); + QCOMPARE(modifiedSpy.count(), 1); + QCOMPARE(model->actions().count(), 0); + + delete menu; } void Ut_MObjectMenu::testCursorPosition() diff --git a/tests/ut_mobjectmenu/ut_mobjectmenu.h b/tests/ut_mobjectmenu/ut_mobjectmenu.h index 0b7fc0be..ef3fd52f 100644 --- a/tests/ut_mobjectmenu/ut_mobjectmenu.h +++ b/tests/ut_mobjectmenu/ut_mobjectmenu.h @@ -40,7 +40,8 @@ private slots: void cleanupTestCase(); void testConstructionAndDestruction(); - void testActionsAddingAndRemoving(); + void testActionsUsingTargetWidget(); + void testActionsUsingObjectMenu(); void testCursorPosition(); void testTitle(); void testIconId(); |