add shm data test; fixup macros
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 19 Sep 2012 21:31:04 +0000 (14:31 -0700)
committerU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 19 Sep 2012 21:31:04 +0000 (14:31 -0700)
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
src/common/test.h
src/core/Makefile.am
src/core/harness.h
src/core/test_display_data.cpp
src/core/test_shm_data.cpp [new file with mode: 0644]

index 9a7333b..5dd5ae0 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _WAYLAND_TEST_TEST_H_
 #define _WAYLAND_TEST_TEST_H_
 
+#include <iostream>
 #include <boost/foreach.hpp>
 #include <map>
 #include <vector>
@@ -49,7 +50,7 @@ typedef Singleton<GlobalTestSuite> TheGlobalTestSuite;
 #define TEST(name, suite) \
        class class_ ## name { \
        public: \
-       START_TEST(name) \
+       START_TEST(ck_ ## name) \
        { \
                run(); \
        } \
@@ -57,7 +58,7 @@ typedef Singleton<GlobalTestSuite> TheGlobalTestSuite;
        static void run(); \
        static bool registered; \
        }; \
-       bool class_ ## name::registered = TheGlobalTestSuite::instance().registerTest(class_ ## name::name, suite "/" # name); \
+       bool class_ ## name::registered = TheGlobalTestSuite::instance().registerTest(class_ ## name::ck_ ## name, suite "/" # name); \
        void class_ ## name::run()
 
 #endif
index 8adefe5..4ecb6b4 100644 (file)
@@ -6,7 +6,8 @@ libwfits_core_la_SOURCES = \
        harness.cpp \
        test_bind_interface.cpp \
        test_cursor.cpp \
-       test_display_data.cpp
+       test_display_data.cpp \
+       test_shm_data.cpp
 
 libwfits_core_la_LIBADD = \
        $(top_builddir)/src/common/libwfits-common.la \
index 4f8fadc..2004c9b 100644 (file)
@@ -46,11 +46,11 @@ private:
        Tests                           tests_;
 };
 
-#define WFITS_CORE_HARNESS_TEST_CASE(Harness, suite) \
+#define WFITS_CORE_HARNESS_TEST_CASE(HarnessClass, suite) \
 \
-TEST(Harness, "Core/" suite) \
+TEST(HarnessClass, "Core/" suite) \
 { \
-       ::Harness().run(); \
+       HarnessClass().run(); \
 }
 
 #endif
index 13b3690..5f72a14 100644 (file)
@@ -1,12 +1,12 @@
 #include "harness.h"
 
-class SetDataTest : public CoreTestHarness
+class DisplayDataTest : public CoreTestHarness
 {
 public:
        void setup()
        {
                queueTest(
-                       boost::bind(&SetDataTest::test, boost::ref(*this))
+                       boost::bind(&DisplayDataTest::test, boost::ref(*this))
                );
        }
        
@@ -28,8 +28,7 @@ public:
                d = static_cast<std::string*>(wl_display_get_user_data(*this));
                FAIL_UNLESS_EQUAL(d, &p);
                FAIL_UNLESS_EQUAL(*d, p);
-               std::cout << "SANITY" << std::endl;
        }
 };
 
-WFITS_CORE_HARNESS_TEST_CASE(SetDataTest, "Display");
\ No newline at end of file
+WFITS_CORE_HARNESS_TEST_CASE(DisplayDataTest, "Display");
\ No newline at end of file
diff --git a/src/core/test_shm_data.cpp b/src/core/test_shm_data.cpp
new file mode 100644 (file)
index 0000000..0584a65
--- /dev/null
@@ -0,0 +1,45 @@
+#include "harness.h"
+
+class ShmDataTest : public CoreTestHarness
+{
+public:
+       void handleGlobal(uint32_t id, const std::string& iface, uint32_t version)
+       {
+               if (iface == "wl_shm")
+               {
+                       shm_ = static_cast<wl_shm*>(wl_display_bind(*this, id, &wl_shm_interface));
+                       FAIL_IF_EQUAL(shm_, NULL);
+               }
+       }
+
+       void setup()
+       {
+               queueTest(
+                       boost::bind(&ShmDataTest::test, boost::ref(*this))
+               );
+       }
+       
+       void test()
+       {
+               int a = random();
+               int *r;
+               for (unsigned i(0); i < 1000; ++i)
+               {
+                       wl_shm_set_user_data(shm_, &a);
+                       r = static_cast<int*>(wl_shm_get_user_data(shm_));
+                       FAIL_UNLESS_EQUAL(r, &a);
+                       FAIL_UNLESS_EQUAL(*r, a);
+                       a = random();
+               }
+
+               std::string *d, p("This is my data");
+               wl_shm_set_user_data(shm_, &p);
+               d = static_cast<std::string*>(wl_shm_get_user_data(shm_));
+               FAIL_UNLESS_EQUAL(d, &p);
+               FAIL_UNLESS_EQUAL(*d, p);
+       }
+private:
+       wl_shm* shm_;
+};
+
+WFITS_CORE_HARNESS_TEST_CASE(ShmDataTest, "Shm");
\ No newline at end of file