void Ut_LauncherPageView::testUpdateData()
{
    QSharedPointer<LauncherButton> widget1(new LauncherButton(""));
    QSharedPointer<LauncherButton> widget2(new LauncherButton(""));
    LauncherPageModel::LauncherButtonList widgets;
    widgets.append(widget1);
    widgets.append(widget2);
    controller->model()->setLauncherButtons(widgets);

    MLayout* mainLayout = dynamic_cast<MLayout *>(controller->layout());
    QVERIFY(mainLayout != NULL);
    QCOMPARE(mainLayout->count(), 2);
    mainLayout->removeItem(widget1.data());
    mainLayout->removeItem(widget2.data());
    QCOMPARE(mainLayout->count(), 0);

    QList<const char*> modifications;
    modifications.append(LauncherPageModel::LauncherButtons);
    emit updateDataRequested(modifications);
    QCOMPARE(mainLayout->count(), 2);

    mainLayout->removeItem(widget1.data());
    mainLayout->removeItem(widget2.data());
    QCOMPARE(mainLayout->count(), 0);

    QList<const char*> modifications2;
    modifications.append("does not match");
    emit updateDataRequested(modifications2);
    QCOMPARE(mainLayout->count(), 0);
}
void Ut_LauncherPageView::testAddButtonsToPage()
{
    QSharedPointer<LauncherButton> widget1(new LauncherButton(""));
    QSharedPointer<LauncherButton> widget2(new LauncherButton(""));
    QSharedPointer<LauncherButton> widget3(new LauncherButton(""));
    QSharedPointer<LauncherButton> widget4(new LauncherButton(""));
    LauncherPageModel::LauncherButtonList widgets;
    widgets.append(widget1);
    controller->model()->setLauncherButtons(widgets);
    // add several widgets so that the order is tested better
    widgets.append(widget2);
    widgets.append(widget3);
    widgets.append(widget4);
    controller->model()->setLauncherButtons(widgets);

    MLayout* mainLayout = dynamic_cast<MLayout *>(controller->layout());
    QVERIFY(mainLayout != NULL);

    QCOMPARE(mainLayout->count(), widgets.count());
    for (int i = 0; i < mainLayout->count(); i++) {
        QCOMPARE(mainLayout->itemAt(i), widgets.at(i).data());
    }
}
void Ut_LauncherPageView::testRemovingButtonFromLayout()
{
    QSharedPointer<LauncherButton> widget1(new LauncherButton(""));
    QSharedPointer<LauncherButton> widget2(new LauncherButton(""));
    LauncherPageModel::LauncherButtonList widgets;
    widgets.append(widget1);
    widgets.append(widget2);
    controller->model()->setLauncherButtons(widgets);

    widgets.removeOne(widget1);
    controller->model()->setLauncherButtons(widgets);

    MLayout* mainLayout = dynamic_cast<MLayout *>(controller->layout());
    QVERIFY(mainLayout != NULL);
    QCOMPARE(mainLayout->count(), 1);
    QCOMPARE(mainLayout->itemAt(0), widget2.data());
    // verify that button destructor has not been called when there is still ref in QSharedPointer
    QCOMPARE(gLauncherButtonStub->stubCallCount("~LauncherButton"), 0);
}