efl: tying in wfits extension
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 6 Feb 2013 23:59:10 +0000 (15:59 -0800)
committerU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 6 Feb 2013 23:59:10 +0000 (15:59 -0800)
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
src/common/harness.cpp
src/common/harness.h
src/efl/Makefile.am
src/efl/elmtestharness.cpp
src/efl/elmtestharness.h
src/efl/test_window.cpp
src/efl/wayland-fits.cpp [new file with mode: 0644]
src/efl/wayland-fits.h [new file with mode: 0644]

index aa1eab0..8b92e68 100644 (file)
@@ -33,6 +33,7 @@ bool TestHarness::haveStep() const
 
 void TestHarness::runNextStep()
 {
-       steps_.front()();
+       TestStep step(steps_.front());
        steps_.pop_front();
+       step();
 }
index ea48964..6c74969 100644 (file)
@@ -24,7 +24,7 @@ public:
        void runNextStep();
        bool haveStep() const;
 
-private:
+protected:
        TestSteps       steps_;
 };
 
index 6d05bd1..d082574 100644 (file)
@@ -10,6 +10,7 @@ libwfits_efl_la_SOURCES = \
        elmtestharness.cpp              \
        evasobject.cpp                  \
        window.cpp                      \
+       wayland-fits.cpp                \
        test_actionslider.cpp           \
        test_background.cpp             \
        test_bubble.cpp                 \
@@ -40,7 +41,8 @@ libwfits_efl_la_SOURCES = \
        test_panel.cpp                  \
        test_popup.cpp                  \
        test_progressbar.cpp            \
-       test_window.cpp
+       test_window.cpp                 \
+       $(top_srcdir)/src/extensions/protocol/wayland-fits-protocol.c
 
 libwfits_efl_la_LIBADD = \
        $(top_builddir)/src/common/libwfits-common.la \
index 8562706..4f12f5a 100644 (file)
@@ -6,6 +6,7 @@ ElmTestHarness::ElmTestHarness()
        : TestHarness::TestHarness()
        , eventType_(ecore_event_type_new())
        , handler_(NULL)
+       , wfits_()
 {
        return;
 }
@@ -19,6 +20,26 @@ void ElmTestHarness::run()
        elm_run();
 }
 
+
+
+void ElmTestHarness::geometryDone(QueryRequest* request, GeometryCallback callback)
+{
+       if (not request->done) {
+               steps_.push_front(boost::bind(&ElmTestHarness::geometryDone, boost::ref(*this), request, callback));
+       } else {
+               Geometry *geometry = static_cast<Geometry*>(request->data);
+               steps_.push_front(boost::bind(callback, *geometry));
+               delete request;
+               delete geometry;
+       }
+}
+
+void ElmTestHarness::getSurfaceGeometry(wl_surface* surface, GeometryCallback callback)
+{
+       QueryRequest* request = wfits_.makeGeometryRequest(surface);
+       geometryDone(request, callback);
+}
+
 /*static*/
 Eina_Bool ElmTestHarness::idleSetup(void* data)
 {
index a3a8a3d..48da523 100644 (file)
@@ -4,10 +4,16 @@
 #include <Elementary.h>
 #include "common/harness.h"
 #include "application.h"
+#include "wayland-fits.h"
 
 class ElmTestHarness : public TestHarness
 {
 public:
+       typedef WaylandFits::Geometry Geometry;
+       typedef WaylandFits::QueryRequest QueryRequest;
+
+       typedef boost::function<void (Geometry)> GeometryCallback;
+
        /**
         * Construct the test harness.
         **/
@@ -15,6 +21,8 @@ public:
 
        void run();
 
+       void getSurfaceGeometry(wl_surface*, GeometryCallback);
+
 private:
        static Eina_Bool idleSetup(void*);
        static Eina_Bool doSetup(void*, int, void*);
@@ -25,8 +33,11 @@ private:
        static Eina_Bool idleTeardown(void*);
        static Eina_Bool doTeardown(void*, int, void*);
 
+       void geometryDone(QueryRequest*, GeometryCallback);
+
        int                     eventType_; /// custom event type
        Ecore_Event_Handler*    handler_;
+       WaylandFits             wfits_;
 };
 
 #define WAYLAND_ELM_HARNESS_EGL_TEST_CASE(Harness, suite) \
index abcf83a..74fe8d5 100644 (file)
@@ -14,6 +14,8 @@ public:
        WindowResizeTest()
                : ElmTestHarness::ElmTestHarness()
                , window_("WindowResizeTest", "Window Resize Test")
+               , sizes_()
+               , resizeDone_(false)
        {
                return;
        }
@@ -22,14 +24,71 @@ public:
        {
                window_.show();
 
-               queueStep(boost::bind(&Window::setSize, boost::ref(window_), 400, 200));
-               queueStep(boost::bind(&Window::checkSize, boost::ref(window_), 400, 200));
-               queueStep(boost::bind(&Window::setSize, boost::ref(window_), 100, 120));
-               queueStep(boost::bind(&Window::checkSize, boost::ref(window_), 100, 120));
+               sizes_.push_back(Size(-10, -10));
+               sizes_.push_back(Size(-1, 10));
+               sizes_.push_back(Size(10, -1));
+               sizes_.push_back(Size(0, 0));
+
+               for (int w(1); w <= 400; w += 89)
+                       for (int h(3); h <= 400; h += 91)
+                               sizes_.push_back(Size(w, h));
+
+               sizes_.push_back(Size(3000, 3000));
+
+               evas_object_event_callback_add(window_, EVAS_CALLBACK_RESIZE, &onResize, this);
+
+               nextResize();
+       }
+
+       static void onResize(void *data, Evas*, Evas_Object*, void*)
+       {
+               WindowResizeTest *test = static_cast<WindowResizeTest*>(data);
+               test->resizeDone_ = true;
+       }
+
+       void nextResize() {
+               resizeDone_ = false;
+               if (not sizes_.empty()) {
+                       Size size(sizes_.front());
+                       sizes_.pop_front();
+                       queueStep(boost::bind(&Window::setSize, boost::ref(window_), size.first, size.second));
+                       queueStep(boost::bind(&WindowResizeTest::checkResize, boost::ref(*this), size.first, size.second, 20));
+               }
+       }
+
+       void checkResize(int w, int h, unsigned tries)
+       {
+               if (not resizeDone_) {
+                       ASSERT(tries != 0);
+                       queueStep(boost::bind(&WindowResizeTest::checkResize, boost::ref(*this), w, h, --tries));
+               } else {
+                       window_.checkSize(std::max(1, w), std::max(1, h));
+                       checkServerSize(Geometry(), 20);
+               }
+       }
+
+       void checkServerSize(Geometry geometry, unsigned tries) {
+               bool sizeMatch(
+                       window_.getWidth() == geometry.width
+                       and window_.getHeight() == geometry.height);
+
+               if (not sizeMatch) {
+                       ASSERT(tries != 0);
+                       GeometryCallback cb = boost::bind(&WindowResizeTest::checkServerSize, boost::ref(*this), _1, --tries);
+                       getSurfaceGeometry(elm_win_wl_window_get(window_)->surface, cb);
+               } else {
+                       FAIL_UNLESS(sizeMatch);
+                       nextResize();
+               }
        }
 
 private:
+       typedef std::pair<int, int> Size;
+       typedef std::deque<Size> Sizes;
+
        Window  window_;
+       Sizes   sizes_;
+       bool    resizeDone_;
 };
 
 class WindowMoveTest : public ElmTestHarness
diff --git a/src/efl/wayland-fits.cpp b/src/efl/wayland-fits.cpp
new file mode 100644 (file)
index 0000000..d823c29
--- /dev/null
@@ -0,0 +1,89 @@
+#include "common/test.h"
+#include "wayland-fits.h"
+
+WaylandFits::WaylandFits()
+       : wfits_input_(NULL)
+       , wfits_query_(NULL)
+{
+       ecore_wl_init(NULL);
+
+       Ecore_Wl_Global *global;
+       wl_registry *registry = ecore_wl_registry_get();
+       wl_list *globals = ecore_wl_globals_get();
+
+       ASSERT(registry != NULL);
+       ASSERT(globals != NULL);
+
+       wl_list_for_each(global, globals, link) {
+               if (std::string(global->interface) == "wfits_input") {
+                       wfits_input_ = static_cast<wfits_input*>(
+                               wl_registry_bind(
+                                       registry,
+                                       global->id,
+                                       &wfits_input_interface,
+                                       global->version));
+               } else if (std::string(global->interface) == "wfits_query") {
+                       wfits_query_ = static_cast<wfits_query*>(
+                               wl_registry_bind(
+                                       registry,
+                                       global->id,
+                                       &wfits_query_interface,
+                                       global->version));
+               }
+       }
+       ASSERT(wfits_input_ != NULL);
+       ASSERT(wfits_query_ != NULL);
+}
+
+/*virtual*/ WaylandFits::~WaylandFits()
+{
+       wfits_input_destroy(wfits_input_);
+       wfits_query_destroy(wfits_query_);
+       ecore_wl_shutdown();
+}
+
+WaylandFits::Geometry::Geometry()
+       : x(-1)
+       , y(-1)
+       , width(-1)
+       , height(-1)
+{
+       return;
+}
+
+WaylandFits::QueryRequest::QueryRequest()
+       : done(false)
+       , data(NULL)
+{
+       return;
+}
+
+static void
+query_result_surface_geometry(void *data, wfits_query_result *result,
+       wl_fixed_t x, wl_fixed_t y, int32_t w, int32_t h)
+{
+       WaylandFits::QueryRequest* qr = static_cast<WaylandFits::QueryRequest*>(data);
+       WaylandFits::Geometry* g = static_cast<WaylandFits::Geometry*>(qr->data);
+       g->x = wl_fixed_to_int(x);
+       g->y = wl_fixed_to_int(y);
+       g->width = w;
+       g->height = h;
+       qr->done = true;
+
+       wfits_query_result_destroy(result);
+}
+
+WaylandFits::QueryRequest* WaylandFits::makeGeometryRequest(wl_surface* surface) const
+{
+       QueryRequest* request(new QueryRequest);
+       request->data = new Geometry;
+
+       static const wfits_query_result_listener listener = {
+               query_result_surface_geometry,
+       };
+
+       wfits_query_result* result = wfits_query_surface_geometry(wfits_query_, surface);
+       wfits_query_result_add_listener(result, &listener, request);
+
+       return request;
+}
diff --git a/src/efl/wayland-fits.h b/src/efl/wayland-fits.h
new file mode 100644 (file)
index 0000000..baa06f1
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __WAYLAND_EFL_WAYLAND_FITS_H__
+#define __WAYLAND_EFL_WAYLAND_FITS_H__
+
+#include <Ecore.h>
+#include <Ecore_Wayland.h>
+#include "extensions/protocol/wayland-fits-client-protocol.h"
+
+class WaylandFits
+{
+public:
+       WaylandFits();
+
+       virtual ~WaylandFits();
+
+       class Geometry
+       {
+       public:
+               Geometry();
+               int32_t x;
+               int32_t y;
+               int32_t width;
+               int32_t height;
+       };
+
+       class QueryRequest
+       {
+       public:
+               QueryRequest();
+               bool done;
+               void* data;
+       };
+
+       QueryRequest* makeGeometryRequest(wl_surface*) const;
+private:
+       wfits_input*            wfits_input_;
+       wfits_query*            wfits_query_;
+};
+
+#endif