From 33147e96ae17a01a3f025a5b7b78bff7943b4851 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 10 Jan 2013 15:54:35 -0300 Subject: Fixed item removal and insertion. Removed debug messages. Fixed tests to work with new tree model structure. --- tests/client/CMakeLists.txt | 4 +- tests/client/modeltest.cpp | 52 +------------------------ tests/client/treetest.cpp | 6 ++- tests/client/treeviewtest.cpp | 88 ------------------------------------------- 4 files changed, 7 insertions(+), 143 deletions(-) delete mode 100644 tests/client/treeviewtest.cpp (limited to 'tests') diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt index 62f7ccb..74439ed 100644 --- a/tests/client/CMakeLists.txt +++ b/tests/client/CMakeLists.txt @@ -54,14 +54,12 @@ endif() declare_test(servicetest) declare_test(menuchangestest) -#declare_test(modeltest) +declare_test(modeltest) declare_test(actiongrouptest) declare_test(qmltest) declare_simple_test(convertertest) -#declare_simple_test(cachetest) declare_simple_test(modelsignalstest) declare_simple_test(treetest) -declare_simple_test(treeviewtest) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qmlfiles.h.in ${CMAKE_CURRENT_BINARY_DIR}/qmlfiles.h) diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index 017f859..7bc9706 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -117,22 +117,9 @@ private Q_SLOTS: QCOMPARE(action.type(), QVariant::String); QCOMPARE(action.toString(), QString("Menu1Act")); - // Section (QObject) - QVariant vSection = m_model.data(m_model.index(2, 0), QMenuModel::LinkSection); - QVERIFY(vSection.isValid()); - QMenuModel *section = qobject_cast(vSection.value()); - QVERIFY(section); - QCOMPARE(section->rowCount(), 2); - - // SubMenu (QObject) - QVariant vSubMenu = m_model.data(m_model.index(3, 0), QMenuModel::LinkSubMenu); - QVERIFY(vSubMenu.isValid()); - QMenuModel *submenu = qobject_cast(vSubMenu.value()); - QVERIFY(submenu); - // Wait for menu load (submenus are loaded async) QTest::qWait(500); - QCOMPARE(submenu->rowCount(), 2); + QCOMPARE(m_model.rowCount(m_model.index(2, 0)), 2); } /* @@ -251,43 +238,6 @@ private Q_SLOTS: delete model; } - - /* - * Test get function - */ - void testGetData() - { - // Make menu available - m_script.publishMenu(); - m_script.run(); - - // create a new model - QDBusMenuModel *model = new QDBusMenuModel(); - model->setBusType(DBusEnums::SessionBus); - model->setBusName(MENU_SERVICE_NAME); - model->setObjectPath(MENU_OBJECT_PATH); - model->start(); - - // Wait for dbus sync - QTest::qWait(500); - - // count - QCOMPARE(model->property("count").toInt(), model->rowCount()); - - QVariantMap data = model->get(0); - - QVERIFY(data.contains("action")); - QVERIFY(data.contains("extra")); - QVERIFY(data.contains("label")); - QVERIFY(data.contains("linkSection")); - QVERIFY(data.contains("linkSubMenu")); - - QCOMPARE(data["action"].toString(), QString("Menu0Act")); - - QVariantMap extra = data["extra"].toMap(); - QCOMPARE(extra.size(), 13); - QCOMPARE(extra["boolean"].toBool(), true); - } }; QTEST_MAIN(ModelTest) diff --git a/tests/client/treetest.cpp b/tests/client/treetest.cpp index 3fce236..b6fec3c 100644 --- a/tests/client/treetest.cpp +++ b/tests/client/treetest.cpp @@ -83,29 +83,33 @@ private Q_SLOTS: QModelIndex row4 = row3.child(0, 0); QVERIFY(row4.isValid()); QCOMPARE(menu.rowCount(row4), 0); + QCOMPARE(menu.data(row4, QMenuModel::Depth).toInt(), 1); QCOMPARE(menu.data(row4, QMenuModel::Label).toString(), QString("menu4")); QModelIndex row5 = row3.child(1, 0); QVERIFY(row5.isValid()); QCOMPARE(menu.rowCount(row5), 2); + QCOMPARE(menu.data(row5, QMenuModel::Depth).toInt(), 1); QCOMPARE(menu.data(row5, QMenuModel::Label).toString(), QString("menu5")); QModelIndex row6 = row5.child(0, 0); QVERIFY(row6.isValid()); QCOMPARE(menu.rowCount(row6), 0); + QCOMPARE(menu.data(row6, QMenuModel::Depth).toInt(), 2); QCOMPARE(menu.data(row6, QMenuModel::Label).toString(), QString("menu6")); QModelIndex row7 = row5.child(1, 0); QVERIFY(row7.isValid()); QCOMPARE(menu.rowCount(row7), 0); + QCOMPARE(menu.data(row7, QMenuModel::Depth).toInt(), 2); QCOMPARE(menu.data(row7, QMenuModel::Label).toString(), QString("menu7")); QModelIndex parent_6 = menu.parent(row6); QVERIFY(parent_6.isValid()); QCOMPARE(menu.rowCount(parent_6), 2); + QCOMPARE(menu.data(parent_6, QMenuModel::Depth).toInt(), 1); QCOMPARE(menu.data(parent_6, QMenuModel::Label).toString(), QString("menu5")); } - }; QTEST_MAIN(TreeTest) diff --git a/tests/client/treeviewtest.cpp b/tests/client/treeviewtest.cpp deleted file mode 100644 index 527ebd3..0000000 --- a/tests/client/treeviewtest.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 3. - * - * 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 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 . - * - * Authors: - * Renato Araujo Oliveira Filho - * Olivier Tilloy - */ - -#include "qmenumodel.h" - -extern "C" { -#include -} - -#include -#include -#include - - -class TestModel : public QMenuModel -{ - Q_OBJECT -public: - TestModel() : QMenuModel(0) - { - GMenu *menu5 = g_menu_new(); - g_menu_append(menu5, "menu6", NULL); - g_menu_append(menu5, "menu7", NULL); - - GMenu *menu3 = g_menu_new(); - g_menu_append(menu3, "menu4", NULL); - g_menu_append_section(menu3, "menu5", G_MENU_MODEL(menu5)); - g_menu_append(menu3, "menu8", NULL); - - GMenu *menu = g_menu_new(); - g_menu_append(menu, "menu0", NULL); - g_menu_append(menu, "menu1", NULL); - g_menu_append(menu, "menu2", NULL); - g_menu_append_section(menu, "menu3", G_MENU_MODEL(menu3)); - - setMenuModel(G_MENU_MODEL(menu)); - - m_menus << menu << menu3 << menu5; - } - -private: - QList m_menus; -}; - -class TreeViewTest : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void initTestCase() - { - g_type_init(); - } - - void testView() - { - TestModel menu; - //QFileSystemModel menu; // = new QFileSystemModel; - //menu.setRootPath(QDir::currentPath()); - QTreeView *tree = new QTreeView; - tree->setModel(&menu); - tree->show(); - QApplication::exec(); - } - -}; - -QTEST_MAIN(TreeViewTest) - -#include "treeviewtest.moc" - -- cgit v1.2.3