diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-09-14 16:11:28 -0300 |
---|---|---|
committer | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-09-14 16:11:28 -0300 |
commit | ebe349e1d96b28e31c29b3e563da1a65fb176e39 (patch) | |
tree | be1271f3d09159fa9f1a44b96fc62cff9cb3b72e /tests/client | |
parent | 2b9cf1654e8eb602f70e14246c3c583962ce7254 (diff) | |
download | qmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.tar.gz qmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.tar.bz2 qmenumodel-ebe349e1d96b28e31c29b3e563da1a65fb176e39.zip |
Created function to convert from QVariant to GVariant.
Moved QStateAction controler from QACtionGroup.
Diffstat (limited to 'tests/client')
-rw-r--r-- | tests/client/CMakeLists.txt | 22 | ||||
-rw-r--r-- | tests/client/actiongrouptest.cpp | 7 | ||||
-rw-r--r-- | tests/client/convertertest.cpp | 91 |
3 files changed, 113 insertions, 7 deletions
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt index 473ebcd..c427f54 100644 --- a/tests/client/CMakeLists.txt +++ b/tests/client/CMakeLists.txt @@ -24,6 +24,27 @@ macro(declare_test testname) endmacro(declare_test testname)
+macro(declare_simple_test testname)
+ set(TEST_MOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/${testname}.moc)
+ qt4_generate_moc(${testname}.cpp ${TEST_MOC_FILE})
+
+ add_executable(${testname} ${testname}.cpp ${TEST_MOC_FILE})
+ target_link_libraries(${testname}
+ qmenumodelcommon
+ ${QT_QTTEST_LIBRARY}
+ ${QT_QTCORE_LIBRARY}
+ ${QT_QTGUI_LIBRARY}
+ ${QT_QTDBUS_LIBRARY}
+ ${GLIB_LDFLAGS}
+ ${GIO_LDFLAGS})
+
+ add_test(${testname}
+ ${CMAKE_CURRENT_BINARY_DIR}/${testname})
+
+ set_tests_properties(${testname} PROPERTIES
+ TIMEOUT ${CTEST_TESTING_TIMEOUT})
+endmacro(declare_simple_test testname)
+
include_directories(${qmenumodelcommon_SOURCE_DIR}
${dbusmenuscript_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
@@ -45,3 +66,4 @@ declare_test(servicetest) declare_test(menuchangestest)
declare_test(modeltest)
declare_test(actiongrouptest)
+declare_simple_test(convertertest)
diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp index fa2dca5..c77c3d5 100644 --- a/tests/client/actiongrouptest.cpp +++ b/tests/client/actiongrouptest.cpp @@ -91,13 +91,11 @@ private Q_SLOTS: m_model.start(); m_actionGroup.start(); QCOMPARE(m_actionGroup.status(), QDBusObject::Connecting); - QCOMPARE(m_actionGroup.count(), 0); // Make menu available m_script.publishMenu(); QCOMPARE(m_actionGroup.status(), QDBusObject::Connected); - QCOMPARE(m_actionGroup.count(), 0); } /* @@ -108,7 +106,6 @@ private Q_SLOTS: { m_model.start(); m_actionGroup.start(); - QCOMPARE(m_actionGroup.count(), 0); // Make menu available m_script.publishMenu(); @@ -116,12 +113,10 @@ private Q_SLOTS: // Append menus m_script.walk(2); - QCOMPARE(m_actionGroup.count(), 2); // Remove menu from dbus m_script.unpublishMenu(); QCOMPARE(m_actionGroup.status(), QDBusObject::Connecting); - QCOMPARE(m_actionGroup.count(), 0); m_actionGroup.stop(); QCOMPARE(m_actionGroup.status(), QDBusObject::Disconnected); @@ -165,7 +160,6 @@ private Q_SLOTS: // Make menu available and append 2 menus m_script.publishMenu(); m_script.walk(2); - QCOMPARE(m_actionGroup.count(), 2); // Get Action QStateAction *act = m_actionGroup.action(QString("Menu1Act")); @@ -174,7 +168,6 @@ private Q_SLOTS: // Remove 1 menu m_script.walk(1); - QCOMPARE(m_actionGroup.count(), 2); //Check if action is invalid QVERIFY(!act->isValid()); diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp new file mode 100644 index 0000000..496b62a --- /dev/null +++ b/tests/client/convertertest.cpp @@ -0,0 +1,91 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + * + * Authors: + * Renato Araujo Oliveira Filho <renato@canonical.com> + */ + +#include "converter.h" + +#include <QObject> +#include <QtTestGui> +#include <QDebug> + +class ConverterTest : public QObject +{ + Q_OBJECT + +private: + bool compare(const QVariant &qv, const GVariantType *type) + { + bool result; + GVariant *gv = Converter::toGVariant(qv); + result = g_variant_type_equal(g_variant_get_type(gv), type); + if (!result) { + qWarning() << "types are different: QVariant:" << qv.typeName() + << "Result:" << (const char*) g_variant_get_type(gv) + << "Expected:"<< (const char*) type; + } + g_variant_unref(gv); + return result; + } + +private Q_SLOTS: + + + /* + * Test converter QVariant to GVariant + */ + void testToGVariant() + { + // Boolean + QVERIFY(compare(QVariant(true), G_VARIANT_TYPE_BOOLEAN)); + + // Byte + QVERIFY(compare(QVariant::fromValue<uchar>(42), G_VARIANT_TYPE_BYTE)); + + // Int16 + QVERIFY(compare(QVariant::fromValue<short>(-42), G_VARIANT_TYPE_INT16)); + + // UInt16 + QVERIFY(compare(QVariant::fromValue<ushort>(-42), G_VARIANT_TYPE_UINT16)); + + // Int32 + QVERIFY(compare(QVariant(-42), G_VARIANT_TYPE_INT32)); + + // UInt32 + QVERIFY(compare(QVariant((uint)42), G_VARIANT_TYPE_UINT32)); + + // Int64 + QVERIFY(compare(QVariant::fromValue<long>(-42), G_VARIANT_TYPE_INT64)); + + // UInt64 + QVERIFY(compare(QVariant::fromValue<ulong>(42), G_VARIANT_TYPE_UINT64)); + + // Double + QVERIFY(compare(QVariant((double)42.42), G_VARIANT_TYPE_DOUBLE)); + + // String + QVERIFY(compare(QVariant(QString("42")), G_VARIANT_TYPE_STRING)); + + // ByteArray + QVERIFY(compare(QVariant(QByteArray("42")), G_VARIANT_TYPE_BYTESTRING)); + } + +}; + +QTEST_MAIN(ConverterTest) + +#include "convertertest.moc" |