DSTraceIno-test: add more test cases for better code coverage 71/243471/1
authorDuna Oh <duna.oh@samsung.com>
Thu, 3 Sep 2020 02:06:25 +0000 (11:06 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 7 Sep 2020 10:47:01 +0000 (19:47 +0900)
Change-Id: I0c70687ec6b70f4f082073c31160a107755e1c57

src/DSTraceInfo/DSTraceInfo.cpp
src/DSTraceInfo/DSTraceInfo.h
tests/DSTraceInfo-test.cpp

index 608c562..a5c357c 100644 (file)
@@ -50,18 +50,17 @@ bool DSTraceInfo::attachPolicyArea(std::shared_ptr<DSPolicyArea> policyArea)
        DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get());
        __zone = policyAreaPriv->getZone();
 
-       if (__zone == nullptr) {
-               DSLOG_ERR("DSTraceInfo", "No zone attached to this policyArea(%p)", policyArea);
-               return false;
-       }
-
-       __zone->registerCallbackWindowCreated(this, std::bind(&DSTraceInfo::__onWindowCreated, this, std::placeholders::_1));
-       __zone->registerCallbackWindowStackChanged(this, std::bind(&DSTraceInfo::__onWindowStackChanged, this, std::placeholders::_1));
-       __zone->registerCallbackWindowDestroy(this, std::bind(&DSTraceInfo::__onWindowDestroy, this, std::placeholders::_1));
+       if (__zone) {
+               __zone->registerCallbackWindowCreated(this, std::bind(&DSTraceInfo::__onWindowCreated, this, std::placeholders::_1));
+               __zone->registerCallbackWindowStackChanged(this, std::bind(&DSTraceInfo::__onWindowStackChanged, this, std::placeholders::_1));
+               __zone->registerCallbackWindowDestroy(this, std::bind(&DSTraceInfo::__onWindowDestroy, this, std::placeholders::_1));
 
-       __windowList = __zone->getWindowList();
+               __windowList = __zone->getWindowList();
+               return true;
+       }
 
-       return true;
+       DSLOG_ERR("DSTraceInfo", "No zone attached to this policyArea(%p)", policyArea);
+       return false;
 }
 
 void DSTraceInfo::__onEventIdleEnterer(void *data)
@@ -75,16 +74,25 @@ void DSTraceInfo::__onEventIdleEnterer(void *data)
 
 void DSTraceInfo::printWindowsInfo()
 {
+       stPosition pos{0,0};
+       stSize sz{0,0};
+       DSWaylandSurface *dwlSurface{nullptr};
+       DSWaylandClient *dwClient{nullptr};
+       pid_t pid = -1;
+
        DSLOG_INF("DSTraceInfo", "--------------Top level windows: %d--------------", __windowList.size());
        DSLOG_INF("DSTraceInfo", " No   Win_ID   PID    w    h    x    y   (S)kipFoc has(F)ocus (U)serGeom (V)kbdFloating Parent   Title");
 
        for (std::shared_ptr<DSWindow> w : __windowList)
        {
-               stPosition pos = w->getPosition();
-               stSize sz = w->getSize();
-               DSWaylandSurface *dwlSurface = w->surface();
-               DSWaylandClient *dwClient = dwlSurface->getClient();
-               pid_t pid = dwClient->pid();
+               pos = w->getPosition();
+               sz = w->getSize();
+               dwlSurface = w->surface();
+               if (dwlSurface) {
+                       dwClient = dwlSurface->getClient();
+                       if (dwClient) pid = dwClient->pid();
+               }
+
                DSLOG_INF("DSTraceInfo", " %d: %p %d %4d %4d %4d %4d     %c         %c        %c        %c          %p  %s", w->getZOrder(), w.get(), pid, \
                           sz.w, sz.h, pos.x, pos.y, w->getSkipFocus()?'S':' ', w->hasFocus()?'F':' ', w->isAllowUserGeometry()?'U':' ', w->getVkbdFloating()?'V':' ', \
                           w->getParent(), (w->getTitle().compare("") == 0)?"No Title":w->getTitle().c_str());
@@ -115,4 +123,9 @@ void DSTraceInfo::__onWindowDestroy(std::shared_ptr<DSWindow> window)
     __windowUpdated = true;
 }
 
+std::shared_ptr<DSZone> DSTraceInfo::getZone()
+{
+       return __zone;
+}
+
 }
\ No newline at end of file
index 35a6516..1f6d83c 100644 (file)
@@ -39,8 +39,10 @@ class DSTraceInfo : public DSObject
 public:
        explicit DSTraceInfo();
        virtual ~DSTraceInfo();
+
        bool attachPolicyArea(std::shared_ptr<DSPolicyArea> policyArea);
        void printWindowsInfo();
+       std::shared_ptr<DSZone> getZone();
 
 private:
        void __onWindowCreated(std::shared_ptr<DSWindow> window);
index 5d99ebb..367a7f7 100644 (file)
@@ -31,13 +31,36 @@ class DSTraceInfoTest : public ::testing::Test
 public:
         void SetUp(void) override
         {
+                Ecore_Timer *timer = nullptr;
+
+                DSWaylandCompositor::getInstance();
+                eventLoop = DSEventLoop::getInstance();
+                double delayInSecond = 0.5;
+                auto timerCb = [](void *data) -> Eina_Bool {
+                    DSEventLoop *loop = (DSEventLoop *)data;
+                    EXPECT_TRUE(loop->quit() == true);
+                    return EINA_FALSE;
+                };
+
+                timer = ecore_timer_loop_add(delayInSecond, timerCb, eventLoop);
+                EXPECT_TRUE(timer != nullptr);
+
+                eventLoop->run();
+
                 char *xdir = getenv("DEFAULT_XDG_RUNTIME_DIR");
                 setenv("XDG_RUNTIME_DIR", xdir, 1);
         }
         void TearDown(void) override
         {
+                eventLoop->quit();
+                DSEventLoop::releaseInstance();
+                DSWaylandCompositor::releaseInstance();
+
                 unsetenv("XDG_RUNTIME_DIR");
         }
+       DSEventLoop *eventLoop;
+private:
+
 };
 
 TEST_F(DSTraceInfoTest, NewTraceInfo)
@@ -57,10 +80,35 @@ TEST_F(DSTraceInfoTest, attachPolicyArea)
 
 TEST_F(DSTraceInfoTest, printWindowsInfo)
 {
+    std::shared_ptr<DSZone> zone(nullptr);
+
     auto traceInfo = std::make_unique<DSTraceInfo>();
     EXPECT_TRUE(traceInfo != nullptr);
     auto policyArea = std::make_shared<DSPolicyArea>();
     EXPECT_TRUE(policyArea != nullptr);
-    traceInfo->printWindowsInfo();
+    if (traceInfo->attachPolicyArea(policyArea))
+    {
+        std::string title1{"TestWindow1"};
+        std::string title2{"TestWindow2"};
+        zone = traceInfo->getZone();
+
+        auto dswlSurface1 = std::make_shared<DSWaylandSurface>();
+        EXPECT_TRUE(zone->testCreateWindow(dswlSurface1));
+
+        auto dswlSurface2 = std::make_shared<DSWaylandSurface>();
+        EXPECT_TRUE(zone->testCreateWindow(dswlSurface2));
+
+        usleep(100000);
+        eventLoop->testEmitIdleEntererFuncs(nullptr);
+
+        zone->raiseWindow(dswlSurface1.get());
+        eventLoop->testEmitIdleEntererFuncs(nullptr);
+
+        EXPECT_TRUE(zone->testDestroyWindow(dswlSurface1));
+        eventLoop->testEmitIdleEntererFuncs(nullptr);
+
+        EXPECT_TRUE(zone->testDestroyWindow(dswlSurface2));
+        eventLoop->testEmitIdleEntererFuncs(nullptr);
+    }
 }