add func of update rule and add test code 62/242762/1
authordyamy-lee <dyamy.lee@samsung.com>
Thu, 20 Aug 2020 06:08:23 +0000 (15:08 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 1 Sep 2020 01:29:24 +0000 (10:29 +0900)
Change-Id: Ia7891fb079711b6198b786604e4708fa3c900fe5

src/DSWaylandServer/DSWaylandProtocolTrace.cpp
src/DSWaylandServer/DSWaylandProtocolTrace.h
tests/DSWaylandProtocolTrace-test.cpp

index fe89016..869bcb7 100644 (file)
@@ -204,6 +204,18 @@ int DSWaylandProtocolTrace::enableProtocolTrace(bool state)
     return -1;
 }
 
+
+bool DSWaylandProtocolTrace::updateProtocolRule(const int argc, const char **argv)
+{
+    DS_GET_PRIV(DSWaylandProtocolTrace);
+    DSLOG_DBG("DSWaylandProtocolTrace", "argc = %d, argv[0] = %s, argv[1] = %s", argc, argv[0], argv[1]);
+
+    bool ret = false;
+    ret = priv->protocol_rule_set(argc, argv);
+
+    return ret;
+}
+
 DSWaylandProtocolTracePrivate::DSWaylandProtocolTracePrivate(DSWaylandProtocolTrace *p_ptr)
     : DSObjectPrivate(p_ptr), __p_ptr(p_ptr)
 {
@@ -265,6 +277,7 @@ bool DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path)
 bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char **argv)
 {
     DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_rule_set");
+    DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) argc = %d, argv[0] = %s", argc, argv[0]);
     const char * command;
 
     if(argc == 0)
@@ -408,6 +421,8 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char
             }
         }
         rulechecker_rule_print(rc);
+
+        return true;
     }
     else if(!strcasecmp(command, "file"))
     {
@@ -532,6 +547,7 @@ void DSWaylandProtocolTracePrivate::protocol_trace_set(void)
     display = __wlCompositor->display();
     DSLOG_DBG("DSWaylandProtocolTracePriv","get display ");
 
+    //check working
     ds_wl_protocol_logger = wl_display_add_protocol_logger(display, protocol_trace_func, nullptr);
     DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol trace set");
 }
index 70a5d6c..b53e999 100644 (file)
@@ -45,7 +45,7 @@ public:
 
     bool init(void);
     int enableProtocolTrace(bool state);
-    //int registerProtocolRule(void);
+    bool updateProtocolRule(const int argc, const char **argv);
 
 private:
     static std::mutex __mutex;
index e02cf3e..63d0e67 100644 (file)
@@ -45,15 +45,82 @@ TEST_F(DSWaylandProtocolTraceTest, NewDSWaylandProtocolTrace)
         DSWaylandProtocolTrace::releaseInstance();
 }
 
-TEST_F(DSWaylandProtocolTraceTest, BasicMethods)
+TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceInit)
 {
     DSWaylandProtocolTrace *pTrace = DSWaylandProtocolTrace::getInstance();
-    bool trace_state = false; //disable
 
     if(pTrace)
     {
         EXPECT_TRUE(pTrace->init() == true);
+        DSWaylandProtocolTrace::releaseInstance();
+    }
+}
+
+TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceUpdateRule)
+{
+    DSWaylandProtocolTrace *pTrace = DSWaylandProtocolTrace::getInstance();
+
+    if(pTrace)
+    {
+        pTrace->init();
+
+        int argc = 3;
+        char *argv[3];
+        argv[0] = "add";
+        argv[1] = "ALLOW";
+        argv[2] = "all";
+        EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true);
+
+        argc = 2;
+        argv[0] = "remove";
+        argv[1] = "all";
+        argv[2] = nullptr;
+        EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true);
+
+        argc = 1;
+        argv[0] = "print";
+        argv[1] = nullptr;
+        argv[2] = nullptr;
+        EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true);
+
+        argc = 1;
+        argv[0] = "help";
+        argv[1] = nullptr;
+        argv[2] = nullptr;
+        EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true);
+
+        argc = 1;
+        argv[0] = "command";
+        argv[1] = nullptr;
+        argv[2] = nullptr;
+        EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true);
+        DSWaylandProtocolTrace::releaseInstance();
+    }
+
+}
+
+TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceEnableTraceFalse)
+{
+    DSWaylandProtocolTrace *pTrace = DSWaylandProtocolTrace::getInstance();
+    bool trace_state = false; //disable
+
+    if(pTrace)
+    {
+        pTrace->init();
         EXPECT_TRUE(pTrace->enableProtocolTrace(trace_state) ==  0);
         DSWaylandProtocolTrace::releaseInstance();
     }
+}
+
+TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceEnableTraceTrue)
+{
+    DSWaylandProtocolTrace *pTrace = DSWaylandProtocolTrace::getInstance();
+    bool trace_state = true;
+
+    if(pTrace)
+    {
+        pTrace->init();
+        EXPECT_TRUE(pTrace->enableProtocolTrace(trace_state) ==  1);
+        DSWaylandProtocolTrace::releaseInstance();
+    }
 }
\ No newline at end of file