Forráskód Böngészése

Extend ctkTesting(Utilities|Macro) to support QVariant

Jean-Christophe Fillion-Robin 9 éve
szülő
commit
7410aaf8be

+ 25 - 0
Libs/Core/Testing/Cpp/ctkCoreTestingMacrosTest.cpp

@@ -63,6 +63,9 @@ int TestCheckQStringDifferentFailure();
 int TestCheckQStringListSuccess();
 int TestCheckQStringListFailure();
 
+int TestCheckQVariantSuccess();
+int TestCheckQVariantFailure();
+
 //----------------------------------------------------------------------------
 #define TestMacro(MACRO_NAME) \
   if (Test##MACRO_NAME##Success() != EXIT_SUCCESS) \
@@ -90,6 +93,7 @@ int ctkCoreTestingMacrosTest(int , char * [])
   TestMacro(CheckStdStringDifferent)
   TestMacro(CheckQStringDifferent)
   TestMacro(CheckQStringList)
+  TestMacro(CheckQVariant)
   return EXIT_SUCCESS;
 }
 
@@ -360,3 +364,24 @@ int TestCheckQStringListFailure()
   return EXIT_SUCCESS;
 }
 
+//----------------------------------------------------------------------------
+// Test CHECK_QVARIANT
+
+//----------------------------------------------------------------------------
+int TestCheckQVariantSuccess()
+{
+  QVariant actual = QVariant(4);
+  QVariant expected = actual;
+  CHECK_QVARIANT(actual, expected);
+  return EXIT_SUCCESS;
+}
+
+//----------------------------------------------------------------------------
+int TestCheckQVariantFailure()
+{
+  QVariant actual = QVariant(4);
+  QVariant expected = QVariant(2);
+  CHECK_QVARIANT(actual, expected);
+  return EXIT_SUCCESS;
+}
+

+ 17 - 0
Libs/Core/Testing/Cpp/ctkCoreTestingUtilitiesTest.cpp

@@ -30,6 +30,7 @@ bool TestCheckNull();
 bool TestCheckPointer();
 bool TestCheckString();
 bool TestCheckStringList();
+bool TestCheckVariant();
 
 //----------------------------------------------------------------------------
 int ctkCoreTestingUtilitiesTest(int , char * [])
@@ -41,6 +42,7 @@ int ctkCoreTestingUtilitiesTest(int , char * [])
   res = res && TestCheckPointer();
   res = res && TestCheckString();
   res = res && TestCheckStringList();
+  res = res && TestCheckVariant();
   return res ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
@@ -129,3 +131,18 @@ bool TestCheckStringList()
   return true;
 }
 
+//----------------------------------------------------------------------------
+bool TestCheckVariant()
+{
+  QVariant foo = QVariant(4);
+  QVariant bar = QVariant(2);
+  if (!CheckVariant(__LINE__, "TestCheckVariant", QVariant(), QVariant())
+      ||!CheckVariant(__LINE__, "TestCheckVariant", foo, foo)
+      || CheckVariant(__LINE__, "TestCheckVariant Expected Failure", foo, bar))
+    {
+    qWarning() << "Line " << __LINE__ << " - TestCheckVariant failed";
+    return false;
+    }
+  return true;
+}
+

+ 11 - 0
Libs/Core/ctkCoreTestingMacros.h

@@ -194,5 +194,16 @@
     } \
   }
 
+/// Verifies if actual QVariant is the same as expected.
+#define CHECK_QVARIANT(actual, expected) \
+  { \
+  QVariant a = (actual); \
+  QVariant e = (expected); \
+  if (!ctkCoreTestingUtilities::CheckVariant(__LINE__,#actual " != " #expected, a, e)) \
+    { \
+    return EXIT_FAILURE; \
+    } \
+  }
+
 #endif
 

+ 7 - 0
Libs/Core/ctkCoreTestingUtilities.cpp

@@ -78,5 +78,12 @@ bool CheckStringList(int line, const QString& description,
   return CheckList<QString>(line, description, current, expected, "CheckStringList");
 }
 
+//----------------------------------------------------------------------------
+bool CheckVariant(int line, const QString& description,
+                  const QVariant& current, const QVariant& expected)
+{
+  return Check<QVariant>(line, description, current, expected, "CheckVariant");
+}
+
 } // namespace ctkCoreTestingUtilities
 

+ 5 - 0
Libs/Core/ctkCoreTestingUtilities.h

@@ -27,6 +27,7 @@
 // Qt includes
 #include <QString>
 #include <QStringList>
+#include <QVariant>
 
 /// This module provides functions to facilitate writing tests.
 ///
@@ -74,6 +75,10 @@ CTK_CORE_EXPORT
 bool CheckStringList(int line, const QString& description,
                      const QStringList& current, const QStringList& expected);
 
+CTK_CORE_EXPORT
+bool CheckVariant(int line, const QString& description,
+                  const QVariant& current, const QVariant& expected);
+
 } // namespace ctkCoreTestingUtilities
 
 #include "ctkCoreTestingUtilities.tpp"