Add initial source codes for gtest 48/168048/1 accepted/tizen/unified/20180130.144322 accepted/tizen/unified/20180222.142207 submit/tizen/20180129.223849 submit/tizen/20180222.121108
authorhyunuktak <hyunuk.tak@samsung.com>
Wed, 24 Jan 2018 00:53:30 +0000 (09:53 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Wed, 24 Jan 2018 00:53:34 +0000 (09:53 +0900)
Change-Id: Ic71f106ab0e96bf52cf45f40ded9f2faf0147a95
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
28 files changed:
CMakeLists.txt
include/stc-iptables-gdbus.h
include/stc-iptables-util.h
include/stc-iptables.h
interfaces/stc-iptables-iface.xml
packaging/stc-iptables.spec
src/CMakeLists.txt
src/helper/helper-ip6tables.c
src/helper/helper-iptables.c
src/stc-iptables-gdbus.c
src/stc-iptables-log.c
src/stc-iptables-util.c
src/stc-iptables.c
test/stc_ipt_rule.c
test/stc_ipt_rule.h
unittest/CMakeLists.txt [new file with mode: 0755]
unittest/chain.cpp [new file with mode: 0755]
unittest/chain.h [new file with mode: 0755]
unittest/gdbus.cpp [new file with mode: 0755]
unittest/gdbus.h [new file with mode: 0755]
unittest/manager.cpp [new file with mode: 0755]
unittest/manager.h [new file with mode: 0755]
unittest/rule.cpp [new file with mode: 0755]
unittest/rule.h [new file with mode: 0755]
unittest/stcmgr.cpp [new file with mode: 0755]
unittest/stcmgr.h [new file with mode: 0755]
unittest/unittest.cpp [new file with mode: 0755]
unittest/unittest.h [new file with mode: 0755]

index bc5fb9a..655fd71 100644 (file)
@@ -1,5 +1,5 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(stc-iptables C)
+PROJECT(stc-iptables C CXX)
 
 SET(PACKAGE ${PROJECT_NAME})
 SET(INTERFACES "${CMAKE_SOURCE_DIR}/interfaces")
@@ -13,3 +13,7 @@ SET(TARGET_STC_IPT_TEST "stc_ipt_test")
 
 ADD_SUBDIRECTORY(src)
 ADD_SUBDIRECTORY(test)
+
+IF(BUILD_GTESTS)
+       ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
index 234e002..221ecd3 100755 (executable)
 #include "generated-code.h"
 
 #define STC_IPTABLES_DBUS_SERVICE               "net.stc.iptables"
+#define STC_IPTABLES_DBUS_MANAGER_INTERFACE     STC_IPTABLES_DBUS_SERVICE ".manager"
 #define STC_IPTABLES_DBUS_RULE_INTERFACE        STC_IPTABLES_DBUS_SERVICE ".rule"
 #define STC_IPTABLES_DBUS_CHAIN_INTERFACE       STC_IPTABLES_DBUS_SERVICE ".chain"
+#define STC_IPTABLES_DBUS_SERVICE_MANAGER_PATH  "/net/stc/iptables/manager"
 #define STC_IPTABLES_DBUS_SERVICE_RULE_PATH     "/net/stc/iptables/rule"
 #define STC_IPTABLES_DBUS_SERVICE_CHAIN_PATH    "/net/stc/iptables/chain"
 
index 0f3d919..fc19907 100755 (executable)
@@ -62,6 +62,9 @@ typedef enum {
        STC_ERROR_NONE = 0                 /**< Successful */
 } stc_error_e;
 
+gboolean handle_iptables_stop(StcManager *object,
+                                  GDBusMethodInvocation *invocation);
+
 /* iptables */
 gboolean handle_iptables_add_rule(StcRule *object,
                               GDBusMethodInvocation *invocation,
index ec8f850..a7d55a5 100755 (executable)
@@ -27,6 +27,7 @@
 typedef struct {
        GMainLoop *main_loop;
 
+       gpointer manager_obj;
        gpointer rule_obj;
        gpointer chain_obj;
 
@@ -36,5 +37,6 @@ typedef struct {
 } stc_iptables_s;
 
 stc_iptables_s *stc_get_iptables(void);
+void stc_stop_iptables(void);
 
 #endif /* __STC_IPTABLES_H__ */
index 9f07458..0e3ee98 100755 (executable)
@@ -3,6 +3,11 @@
                <method name='Init'>
                </method>
        </interface>
+       <interface name="net.stc.iptables.manager">
+               <method name='Stop'>
+                       <arg type='i' name='error_code' direction='out'/>
+               </method>
+       </interface>
        <interface name="net.stc.iptables.rule">
                <method name='IptAddRule'>
                        <arg type='a{sv}' name='rules' direction='in'/>
index 29b61fa..ae3d02d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-iptables
 Summary:    STC(Smart Traffic Control) iptables
-Version:    0.0.10
+Version:    0.0.11
 Release:    0
 Group:      Network & Connectivity/Other
 License:    GPL-2.0+
@@ -13,6 +13,11 @@ BuildRequires:  pkgconfig(gio-unix-2.0)
 BuildRequires:  pkgconfig(libiptc)
 BuildRequires:  pkgconfig(libip6tc)
 
+%if 0%{?gtests:1}
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(gmock)
+%endif
+
 %description
 A smart traffic control iptables to manage iptables rules using libiptc
 
@@ -35,6 +40,8 @@ export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
 %cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
        -DBIN_DIR=%{_bindir} \
        -DLIB_PATH=%{_lib} \
+       -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
+       -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0}
 
 make %{?_smp_mflags}
 
@@ -76,3 +83,7 @@ chown network_fw:network_fw /opt/usr/data/network
 #Test
 %{_bindir}/stc_ipt_test
 %attr(755,root,root) %{_bindir}/stc_ipt_test
+
+%if 0%{?gtests:1}
+%{_bindir}/gtest*
+%endif
index eed8daa..75197c2 100755 (executable)
@@ -27,10 +27,20 @@ FILE(GLOB HELPER_SRCS               ${HELPER_SOURCE_DIR}/*.c)
 SET(SRCS ${SRCS} ${SOURCE_SRCS} ${HELPER_SRCS})
 
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration -fvisibility=hidden")
+IF(BUILD_GTESTS)
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fprofile-arcs -ftest-coverage")
+ELSE(BUILD_GTESTS)
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration -fvisibility=hidden")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+ENDIF(BUILD_GTESTS)
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
+IF(BUILD_GTESTS)
+       ADD_DEFINITIONS(-DTIZEN_GTESTS)
+ENDIF(BUILD_GTESTS)
+
 ADD_CUSTOM_COMMAND(
        WORKING_DIRECTORY
        OUTPUT ${SOURCE_DIR}/generated-code.c
index a8eccdd..341d332 100755 (executable)
@@ -90,8 +90,8 @@ static int __create_entry_data(unsigned char *entry, unsigned char *mask,
        unsigned int size_match = 0;
 
        if (!rule->chain) {
-               STC_LOGE("Invalid parameters");
-               return STC_ERROR_INVALID_PARAMETER;
+               STC_LOGE("Invalid parameters"); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
        }
 
        e = (ip6t_entry_t *)(entry);
@@ -114,8 +114,8 @@ static int __create_entry_data(unsigned char *entry, unsigned char *mask,
                        memset(&(e->ipv6.outiface_mask), 0xFF, IFNAMSIZ);
                        break;
                default:
-                       STC_LOGE("Invalid parameter");
-                       return STC_ERROR_INVALID_PARAMETER;
+                       STC_LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+                       return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
                }
        }
 
@@ -155,38 +155,38 @@ int ip6tables_add_rule(ip6tables_rule_s *rule)
        const char *chain = rule->chain;
 
        if (__create_entry_data(entry, mask, rule) != 0) {
-               STC_LOGE("Failed to create entry");
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to create entry"); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        handle = ip6tc_init(IP6TC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_is_chain(chain, handle)) {
-               STC_LOGW("chain not present [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGW("chain not present [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (ip6tc_check_entry(chain, (const ip6t_entry_t *)entry, mask, handle)) {
-               STC_LOGW("Entry already present");
-               ip6tc_free(handle);
-               return STC_ERROR_NONE;
+               STC_LOGW("Entry already present"); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_NONE; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_append_entry(chain, (const ip6t_entry_t *)entry, handle)) {
-               STC_LOGW("ip6tc_append_entry failed [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGW("ip6tc_append_entry failed [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_commit(handle)) {
-               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        ip6tc_free(handle);
@@ -204,32 +204,32 @@ int ip6tables_remove_rule(ip6tables_rule_s *rule)
        const char *chain = rule->chain;
 
        if (__create_entry_data(entry, mask, rule) != 0) {
-               STC_LOGE("Failed to create entry");
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to create entry"); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        handle = ip6tc_init(IP6TC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_is_chain(chain, handle)) {
-               STC_LOGW("chain not present [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGW("chain not present [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_delete_entry(chain, (const ip6t_entry_t *)entry, mask, handle)) {
-               STC_LOGW("ip6tc_delete_entry failed [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGW("ip6tc_delete_entry failed [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_commit(handle)) {
-               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        ip6tc_free(handle);
@@ -244,26 +244,26 @@ int ip6tables_add_chain(const char *chain)
 
        handle = ip6tc_init(IP6TC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (ip6tc_is_chain(chain, handle)) {
-               STC_LOGW("chain already exists");
-               ip6tc_free(handle);
-               return STC_ERROR_NONE;
+               STC_LOGW("chain already exists"); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_NONE; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_create_chain(chain, handle)) {
-               STC_LOGE("Failed to create chaing [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to create chaing [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_commit(handle)) {
-               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        ip6tc_free(handle);
@@ -278,28 +278,28 @@ int ip6tables_remove_chain(const char *chain)
 
        handle = ip6tc_init(IP6TC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_is_chain(chain, handle)) {
-               STC_LOGW("chain not present");
-               ip6tc_free(handle);
-               return STC_ERROR_NONE;
+               STC_LOGW("chain not present"); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_NONE; //LCOV_EXCL_LINE
        }
 
        ip6tc_flush_entries(chain, handle);
 
        if (!ip6tc_delete_chain(chain, handle)) {
-               STC_LOGE("Failed to delete chain [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to delete chain [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_commit(handle)) {
-               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        ip6tc_free(handle);
@@ -314,26 +314,26 @@ int ip6tables_flush_chain(const char *chain)
 
        handle = ip6tc_init(IP6TC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("ip6tc_init failed [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_is_chain(chain, handle)) {
-               STC_LOGW("chain not present");
-               ip6tc_free(handle);
-               return STC_ERROR_NONE;
+               STC_LOGW("chain not present"); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_NONE; //LCOV_EXCL_LINE
        }
 
        if(!ip6tc_flush_entries(chain, handle)) {
-               STC_LOGE("Failed to flush chain [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to flush chain [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!ip6tc_commit(handle)) {
-               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno));
-               ip6tc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to ip6tc_commit [%s]", ip6tc_strerror(errno)); //LCOV_EXCL_LINE
+               ip6tc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        ip6tc_free(handle);
index 09bf14b..d07df88 100755 (executable)
@@ -90,8 +90,8 @@ static int __create_entry_data(unsigned char *entry, unsigned char *mask,
        unsigned int size_match = 0;
 
        if (!rule->chain) {
-               STC_LOGE("Invalid parameters");
-               return STC_ERROR_INVALID_PARAMETER;
+               STC_LOGE("Invalid parameters"); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
        }
 
        e = (ipt_entry_t *)(entry);
@@ -114,8 +114,8 @@ static int __create_entry_data(unsigned char *entry, unsigned char *mask,
                        memset(&(e->ip.outiface_mask), 0xFF, IFNAMSIZ);
                        break;
                default:
-                       STC_LOGE("Invalid parameter");
-                       return STC_ERROR_INVALID_PARAMETER;
+                       STC_LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+                       return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
                }
        }
 
@@ -155,38 +155,38 @@ int iptables_add_rule(iptables_rule_s *rule)
        const char *chain = rule->chain;
 
        if (__create_entry_data(entry, mask, rule) != 0) {
-               STC_LOGE("Failed to create entry");
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to create entry"); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        handle = iptc_init(IPTC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_is_chain(chain, handle)) {
-               STC_LOGW("chain not present [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGW("chain not present [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (iptc_check_entry(chain, (const ipt_entry_t *)entry, mask, handle)) {
-               STC_LOGW("Entry already present");
-               iptc_free(handle);
-               return STC_ERROR_NONE;
+               STC_LOGW("Entry already present"); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_NONE; //LCOV_EXCL_LINE
        }
 
        if (!iptc_append_entry(chain, (const ipt_entry_t *)entry, handle)) {
-               STC_LOGW("iptc_append_entry failed [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGW("iptc_append_entry failed [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_commit(handle)) {
-               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        iptc_free(handle);
@@ -204,32 +204,32 @@ int iptables_remove_rule(iptables_rule_s *rule)
        const char *chain = rule->chain;
 
        if (__create_entry_data(entry, mask, rule) != 0) {
-               STC_LOGE("Failed to create entry");
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to create entry"); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        handle = iptc_init(IPTC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_is_chain(chain, handle)) {
-               STC_LOGW("chain not present [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGW("chain not present [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_delete_entry(chain, (const ipt_entry_t *)entry, mask, handle)) {
-               STC_LOGW("iptc_delete_entry failed [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGW("iptc_delete_entry failed [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        if (!iptc_commit(handle)) {
-               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        iptc_free(handle);
@@ -244,26 +244,26 @@ int iptables_add_chain(const char *chain)
 
        handle = iptc_init(IPTC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (iptc_is_chain(chain, handle)) {
-               STC_LOGW("chain already exists");
-               iptc_free(handle);
-               return STC_ERROR_NONE;
+               STC_LOGW("chain already exists"); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_NONE; //LCOV_EXCL_LINE
        }
 
        if (!iptc_create_chain(chain, handle)) {
-               STC_LOGE("Failed to create chaing [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to create chaing [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_commit(handle)) {
-               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        iptc_free(handle);
@@ -278,28 +278,28 @@ int iptables_remove_chain(const char *chain)
 
        handle = iptc_init(IPTC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_is_chain(chain, handle)) {
-               STC_LOGW("chain not present");
-               iptc_free(handle);
-               return STC_ERROR_NONE;
+               STC_LOGW("chain not present"); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_NONE; //LCOV_EXCL_LINE
        }
 
        iptc_flush_entries(chain, handle);
 
        if (!iptc_delete_chain(chain, handle)) {
-               STC_LOGE("Failed to delete chain [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to delete chain [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_commit(handle)) {
-               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        iptc_free(handle);
@@ -314,26 +314,26 @@ int iptables_flush_chain(const char *chain)
 
        handle = iptc_init(IPTC_TABLE);
        if (handle == NULL) {
-               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno));
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("iptc_init failed [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_is_chain(chain, handle)) {
-               STC_LOGW("chain not present");
-               iptc_free(handle);
-               return STC_ERROR_NONE;
+               STC_LOGW("chain not present"); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_NONE; //LCOV_EXCL_LINE
        }
 
        if (!iptc_flush_entries(chain, handle)) {
-               STC_LOGE("Failed to flush chain [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to flush chain [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
 
        if (!iptc_commit(handle)) {
-               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno));
-               iptc_free(handle);
-               return STC_ERROR_OPERATION_FAILED;
+               STC_LOGE("Failed to iptc_commit [%s]", iptc_strerror(errno)); //LCOV_EXCL_LINE
+               iptc_free(handle); //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE
        }
 
        iptc_free(handle);
index 9b7b2d8..4770e1d 100755 (executable)
 #include "stc-iptables.h"
 #include "stc-iptables-gdbus.h"
 
+static gboolean __stc_iptables_gdbus_manager_init(stc_iptables_s *stc_iptables)
+{
+       __STC_LOG_FUNC_ENTER__;
+       gboolean ret = TRUE;
+       gchar *s = NULL;
+
+       StcObjectSkeleton *object = NULL;
+       StcManager *manager = NULL;
+       s = g_strdup_printf(STC_IPTABLES_DBUS_SERVICE_MANAGER_PATH);
+
+       /* Add interface to default object path */
+       object = stc_object_skeleton_new(s);
+       g_free(s);
+
+       manager = stc_manager_skeleton_new();
+       stc_object_skeleton_set_manager(object, manager);
+       g_object_unref(manager);
+
+       g_signal_connect(manager, "handle-stop",
+                        G_CALLBACK(handle_iptables_stop),
+                        stc_iptables);
+
+       g_dbus_object_manager_server_export(stc_iptables->obj_mgr,
+                                           G_DBUS_OBJECT_SKELETON(object));
+       g_object_unref(object);
+
+       stc_iptables->manager_obj = (gpointer)manager;
+
+       __STC_LOG_FUNC_EXIT__;
+       return ret;
+}
+
 static gboolean __stc_iptables_gdbus_chain_init(stc_iptables_s *stc_iptables)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -127,13 +159,18 @@ static void __stc_iptables_gdbus_on_bus_acquired(GDBusConnection *connection,
 
        stc_iptables->connection = connection;
 
+       if (__stc_iptables_gdbus_manager_init(stc_iptables) == FALSE) {
+               STC_LOGE("Can not signal connect to manager"); //LCOV_EXCL_LINE
+               /* Deinitialize and quit iptables */
+       }
+
        if (__stc_iptables_gdbus_chain_init(stc_iptables) == FALSE) {
-               STC_LOGE("Can not signal connect to chain");
+               STC_LOGE("Can not signal connect to chain"); //LCOV_EXCL_LINE
                /* Deinitialize and quit iptables */
        }
 
        if (__stc_iptables_gdbus_rule_init(stc_iptables) == FALSE) {
-               STC_LOGE("Can not signal connect to rule");
+               STC_LOGE("Can not signal connect to rule"); //LCOV_EXCL_LINE
                /* Deinitialize and quit iptables */
        }
 
@@ -150,12 +187,14 @@ static void __stc_iptables_gdbus_on_name_acquired(GDBusConnection *connection,
        STC_LOGD("name : %s", name);
 }
 
+//LCOV_EXCL_START
 static void __stc_iptables_gdbus_on_name_lost(GDBusConnection *connection,
                                             const gchar *name,
                                             gpointer user_data)
 {
        STC_LOGD("name : %s", name);
 }
+//LCOV_EXCL_STOP
 
 void stc_iptables_gdbus_init(gpointer stc_data)
 {
@@ -183,6 +222,7 @@ void stc_iptables_gdbus_deinit(gpointer stc_data)
 
        g_bus_unown_name(stc_iptables->gdbus_owner_id);
 
+       stc_iptables->manager_obj = NULL;
        stc_iptables->rule_obj = NULL;
        stc_iptables->chain_obj = NULL;
 
@@ -198,8 +238,8 @@ void stc_iptables_gdbus_dict_foreach(GVariantIter *iter,
        GVariant *value = NULL;
 
        if (!cb) {
-               __STC_LOG_FUNC_EXIT__;
-               return;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
index 05725a5..6eb9646 100755 (executable)
@@ -30,6 +30,7 @@
 
 static FILE *log_file = NULL;
 
+//LCOV_EXCL_START
 static void __stc_iptables_log_update_file_revision(int rev)
 {
        int next_log_rev = 0;
@@ -69,6 +70,7 @@ static void __stc_iptables_log_make_backup(void)
 
        g_free(backup);         
 }
+//LCOV_EXCL_STOP
 
 static void __stc_iptables_log_get_local_time(char *strtime, const int size)
 {
@@ -104,6 +106,7 @@ void stc_iptables_log(const char *format, ...)
                log_size = buf.st_size;
 
        if (log_size >= MAX_LOG_SIZE) {
+               //LCOV_EXCL_START
                fclose(log_file);
                log_file = NULL;
 
@@ -115,6 +118,7 @@ void stc_iptables_log(const char *format, ...)
                        va_end(ap);
                        return;
                }
+               //LCOV_EXCL_STOP
        }
 
        __stc_iptables_log_get_local_time(strtime, sizeof(strtime));
@@ -132,6 +136,11 @@ gboolean stc_iptables_log_sync(gpointer data)
                fsync(log_file->_fileno);
        }
 
+#ifdef TIZEN_GTESTS
+       void __gcov_flush(void);
+       __gcov_flush();
+#endif
+
        return TRUE;
 }
 
index 78dac42..e18e600 100755 (executable)
@@ -17,6 +17,7 @@
 
 #include <string.h>
 
+#include "stc-iptables.h"
 #include "stc-iptables-util.h"
 #include "helper-iptables.h"
 #include "helper-ip6tables.h"
 
 static const gchar *stc_iptables_err_strs[] = {
                "ERROR_NONE",
-               "FAIL",
-               "DB_FAILED",
+               "NOT_PERMITTED",
                "OUT_OF_MEMORY",
+               "PERMISSION_DENIED",
+               "INVALID_OPERATION",
                "INVALID_PARAMETER",
-               "NO_DATA",
-               "UNINITIALIZED",
-               "NOTIMPL"
+               "OPERATION_FAILED"
        };
 
 void __stc_extract_rule(const char *key, GVariant *value,
@@ -78,7 +78,7 @@ void __stc_extract_rule(const char *key, GVariant *value,
                STC_LOGD("target: [%s]", rule->target);
 
        } else {
-               STC_LOGD("Unknown rule");
+               STC_LOGD("Unknown rule"); //LCOV_EXCL_LINE
        }
 }
 
@@ -118,10 +118,29 @@ void __stc_extract_6_rule(const char *key, GVariant *value,
                STC_LOGD("target: [%s]", rule->target);
 
        } else {
-               STC_LOGD("Unknown rule");
+               STC_LOGD("Unknown rule"); //LCOV_EXCL_LINE
        }
 }
 
+gboolean handle_iptables_stop(StcManager *object,
+                                  GDBusMethodInvocation *invocation)
+{
+       __STC_LOG_FUNC_ENTER__;
+       GVariant *return_parameters = NULL;
+
+       STC_LOGI("stc manager stop");
+
+       return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
+
+       STC_DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+       STC_IPTABLES_DBUS_REPLY(invocation, return_parameters);
+
+       stc_stop_iptables();
+
+       __STC_LOG_FUNC_EXIT__;
+       return TRUE;
+}
+
 gboolean handle_iptables_add_rule(StcRule *object,
                               GDBusMethodInvocation *invocation,
                               GVariant *rules,
@@ -146,6 +165,7 @@ gboolean handle_iptables_add_rule(StcRule *object,
 
                        ret = iptables_add_rule(rule);
                        if (ret != STC_ERROR_NONE) {
+                                //LCOV_EXCL_START
                                STC_LOGE("Failed add rule [%s:%d:%s:%d:%s:%s]", rule->chain,
                                         rule->type, rule->ifname, rule->classid,
                                         rule->nfacct_name, rule->target);
@@ -158,15 +178,16 @@ gboolean handle_iptables_add_rule(StcRule *object,
                                STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
                                __STC_LOG_FUNC_EXIT__;
                                return TRUE;
+                                //LCOV_EXCL_STOP
                        }
                }
 
                g_variant_iter_free(iter);
        } else {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation,
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                              STC_ERROR_INVALID_PARAMETER);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -201,6 +222,7 @@ gboolean handle_iptables_remove_rule(StcRule *object,
 
                        ret = iptables_remove_rule(rule);
                        if (ret != STC_ERROR_NONE) {
+                                //LCOV_EXCL_START
                                STC_LOGE("Failed remove rule [%s:%d:%s:%d:%s:%s]", rule->chain,
                                         rule->type, rule->ifname, rule->classid,
                                         rule->nfacct_name, rule->target);
@@ -213,15 +235,16 @@ gboolean handle_iptables_remove_rule(StcRule *object,
                                STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
                                __STC_LOG_FUNC_EXIT__;
                                return TRUE;
+                                //LCOV_EXCL_STOP
                        }
                }
 
                g_variant_iter_free(iter);
        } else {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation,
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                              STC_ERROR_INVALID_PARAMETER);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -244,9 +267,9 @@ gboolean handle_iptables_add_chain(StcChain *object,
 
        ret = iptables_add_chain(chain);
        if (ret < STC_ERROR_NONE) {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -269,9 +292,9 @@ gboolean handle_iptables_remove_chain(StcChain *object,
 
        ret = iptables_remove_chain(chain);
        if (ret < STC_ERROR_NONE) {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -294,9 +317,9 @@ gboolean handle_iptables_flush_chain(StcChain *object,
 
        ret = iptables_flush_chain(chain);
        if (ret < STC_ERROR_NONE) {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -332,6 +355,7 @@ gboolean handle_ip6tables_add_rule(StcRule *object,
 
                        ret = ip6tables_add_rule(rule);
                        if (ret != STC_ERROR_NONE) {
+                                //LCOV_EXCL_START
                                STC_LOGE("Failed add rule [%s:%d:%s:%d:%s:%s]", rule->chain,
                                         rule->type, rule->ifname, rule->classid,
                                         rule->nfacct_name, rule->target);
@@ -344,15 +368,16 @@ gboolean handle_ip6tables_add_rule(StcRule *object,
                                STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
                                __STC_LOG_FUNC_EXIT__;
                                return TRUE;
+                                //LCOV_EXCL_STOP
                        }
                }
 
                g_variant_iter_free(iter);
        } else {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation,
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                              STC_ERROR_INVALID_PARAMETER);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -387,6 +412,7 @@ gboolean handle_ip6tables_remove_rule(StcRule *object,
 
                        ret = ip6tables_remove_rule(rule);
                        if (ret != STC_ERROR_NONE) {
+                                //LCOV_EXCL_START
                                STC_LOGE("Failed remove rule [%s:%d:%s:%d:%s:%s]", rule->chain,
                                         rule->type, rule->ifname, rule->classid,
                                         rule->nfacct_name, rule->target);
@@ -399,15 +425,16 @@ gboolean handle_ip6tables_remove_rule(StcRule *object,
                                STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
                                __STC_LOG_FUNC_EXIT__;
                                return TRUE;
+                                //LCOV_EXCL_STOP
                        }
                }
 
                g_variant_iter_free(iter);
        } else {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation,
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, //LCOV_EXCL_LINE
                                              STC_ERROR_INVALID_PARAMETER);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -430,9 +457,9 @@ gboolean handle_ip6tables_add_chain(StcChain *object,
 
        ret = ip6tables_add_chain(chain);
        if (ret < STC_ERROR_NONE) {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -455,9 +482,9 @@ gboolean handle_ip6tables_remove_chain(StcChain *object,
 
        ret = ip6tables_remove_chain(chain);
        if (ret < STC_ERROR_NONE) {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
@@ -480,9 +507,9 @@ gboolean handle_ip6tables_flush_chain(StcChain *object,
 
        ret = ip6tables_flush_chain(chain);
        if (ret < STC_ERROR_NONE) {
-               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret);
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               STC_IPTABLES_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
index e9843aa..32fd285 100755 (executable)
@@ -15,6 +15,8 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <stdlib.h>
+
 #include "stc-iptables.h"
 #include "stc-iptables-util.h"
 #include "stc-iptables-gdbus.h"
@@ -27,8 +29,8 @@ static void __stc_iptables_deinit(void)
        __STC_LOG_FUNC_ENTER__;
 
        if (!g_stc_iptables) {
-               STC_LOGE("Memory for iptables structure is not allocated");
-               return;
+               STC_LOGE("Memory for iptables structure is not allocated"); //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        stc_iptables_gdbus_deinit((gpointer)g_stc_iptables);
@@ -45,8 +47,8 @@ static stc_iptables_s *__stc_iptables_init(void)
 
        stc_iptables = MALLOC0(stc_iptables_s, 1);
        if (!stc_iptables) {
-               STC_LOGE("Failed to allocate memory for iptables structure");
-               return NULL;
+               STC_LOGE("Failed to allocate memory for iptables structure"); //LCOV_EXCL_LINE
+               return NULL; //LCOV_EXCL_LINE
        }
        g_stc_iptables = stc_iptables;
 
@@ -65,8 +67,12 @@ gint32 main(gint32 argc, gchar *argv[])
 
        STC_LOGI("Smart Traffic Control Iptables");
 
+#ifdef TIZEN_GTESTS
+       setenv("GCOV_PREFIX", "/tmp/daemon", 1);
+#endif
+
        if (daemon(0, 0) != 0)
-               STC_LOGE("Can't start daemon");
+               STC_LOGE("Can't start daemon"); //LCOV_EXCL_LINE
 
        /* Initialize required subsystems */
 #if !GLIB_CHECK_VERSION(2, 35, 0)
@@ -103,7 +109,15 @@ fail:
        return ret;
 }
 
+//LCOV_EXCL_START
 stc_iptables_s *stc_get_iptables(void)
 {
        return g_stc_iptables;
 }
+//LCOV_EXCL_STOP
+
+void stc_stop_iptables(void)
+{
+       if (g_stc_iptables && g_stc_iptables->main_loop)
+               g_main_loop_quit(g_stc_iptables->main_loop);
+}
index d486736..27e9f71 100755 (executable)
@@ -363,7 +363,7 @@ static int test_stc_ipt_remove_rule(MManager *mm, struct menu_data *menu)
        return err;
 }
 
-int test_stc_ipt_clear_rule(void)
+void test_stc_ipt_clear_rule(void)
 {
        if (g_rule)
                __test_rule_free(g_rule);
index 0ec3e98..ff4ab59 100755 (executable)
@@ -17,6 +17,6 @@
 #ifndef __TEST_STC_IPT_RULE_H__
 #define __TEST_STC_IPT_RULE_H__
 
-int test_stc_ipt_clear_rule(void);
+void test_stc_ipt_clear_rule(void);
 
 #endif /** __TEST_STC_IPT_RULE_H__ */
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..debaf4f
--- /dev/null
@@ -0,0 +1,32 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-stc-iptables C CXX)
+
+SET(GTEST_TEST "gtest-stc-iptables")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+       glib-2.0
+       gio-2.0
+       gmock
+       dlog
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB GTEST_TEST_SRCS *.cpp)
+SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
+
+ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl -lgcov)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION ${BIN_DIR})
diff --git a/unittest/chain.cpp b/unittest/chain.cpp
new file mode 100755 (executable)
index 0000000..aa25af6
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "chain.h"
+
+Chain::Chain()
+{
+       Create();
+}
+
+Chain::~Chain()
+{
+       Destroy();
+}
+
+error_e Chain::SetChainName(const char *name)
+{
+       if (name == NULL || strlen(name) == 0)
+               this->m_ChainName[0] = '\0';
+       else
+               g_strlcpy(this->m_ChainName, name, CHAIN_NAME_LEN);
+
+       return ERROR_NONE;
+}
+
+error_e Chain::AddChain(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       params = g_variant_new("(s)", this->m_ChainName);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_CHAIN_PATH,
+               STC_IPT_DBUS_CHAIN_INTERFACE,
+               STC_IPT_METHOD_IPT_ADD_CHAIN,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to add chain [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Chain::Add6Chain(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       params = g_variant_new("(s)", this->m_ChainName);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_CHAIN_PATH,
+               STC_IPT_DBUS_CHAIN_INTERFACE,
+               STC_IPT_METHOD_IP6T_ADD_CHAIN,
+               params,
+               &error);
+       
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }       
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to add 6 chain [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Chain::FlushChain(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       params = g_variant_new("(s)", this->m_ChainName);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_CHAIN_PATH,
+               STC_IPT_DBUS_CHAIN_INTERFACE,
+               STC_IPT_METHOD_IPT_FLUSH_CHAIN,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to flush chain [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Chain::Flush6Chain(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       params = g_variant_new("(s)", this->m_ChainName);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_CHAIN_PATH,
+               STC_IPT_DBUS_CHAIN_INTERFACE,
+               STC_IPT_METHOD_IP6T_FLUSH_CHAIN,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to flush 6 chain [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Chain::RemoveChain(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       params = g_variant_new("(s)", this->m_ChainName);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_CHAIN_PATH,
+               STC_IPT_DBUS_CHAIN_INTERFACE,
+               STC_IPT_METHOD_IPT_REMOVE_CHAIN,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to remove chain [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Chain::Remove6Chain(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       params = g_variant_new("(s)", this->m_ChainName);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_CHAIN_PATH,
+               STC_IPT_DBUS_CHAIN_INTERFACE,
+               STC_IPT_METHOD_IP6T_REMOVE_CHAIN,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to remove 6 chain [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
diff --git a/unittest/chain.h b/unittest/chain.h
new file mode 100755 (executable)
index 0000000..37f0ab3
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_IPT_CHAIN_H__
+#define __STC_IPT_CHAIN_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "stcmgr.h"
+#include "gdbus.h"
+
+#define STC_IPT_METHOD_IPT_ADD_CHAIN      "IptAddChain"
+#define STC_IPT_METHOD_IPT_FLUSH_CHAIN    "IptFlushChain"
+#define STC_IPT_METHOD_IPT_REMOVE_CHAIN   "IptRemoveChain"
+
+#define STC_IPT_METHOD_IP6T_ADD_CHAIN     "Ip6tAddChain"
+#define STC_IPT_METHOD_IP6T_FLUSH_CHAIN   "Ip6tFlushChain"
+#define STC_IPT_METHOD_IP6T_REMOVE_CHAIN  "Ip6tRemoveChain"
+
+class Chain : public GDbus {
+private:
+       char m_ChainName[CHAIN_NAME_LEN];
+public:
+       Chain();
+       ~Chain();
+       error_e SetChainName(const char *name);
+       error_e AddChain(void);
+       error_e Add6Chain(void);
+       error_e FlushChain(void);
+       error_e Flush6Chain(void);
+       error_e RemoveChain(void);
+       error_e Remove6Chain(void);
+};
+
+#endif /* __STC_IPT_CHAIN_H__ */
diff --git a/unittest/gdbus.cpp b/unittest/gdbus.cpp
new file mode 100755 (executable)
index 0000000..da8b37f
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "gdbus.h"
+
+GDbus::GDbus()
+{
+       this->m_pConnection = NULL;
+       this->m_pCancellable = NULL;
+}
+
+GDbus::~GDbus()
+{
+       GDBusConnection *conn = this->m_pConnection;
+       GCancellable *cancel = this->m_pCancellable;
+
+       if (cancel) {
+               g_cancellable_cancel(cancel);
+               g_object_unref(cancel);
+               cancel = NULL;
+       }
+
+       if (conn) {
+               g_object_unref(conn);
+               conn = NULL;
+       }
+}
+
+error_e GDbus::Create(void)
+{
+       GError *err = NULL;
+
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+       g_type_init();
+#endif
+
+       this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (this->m_pConnection == NULL) {
+               if (err != NULL) {
+                       GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message);
+                       g_error_free(err);
+               }
+
+               return ERROR_OPERATION_FAILED;
+       }
+
+       this->m_pCancellable = g_cancellable_new();
+
+       return ERROR_NONE;
+}
+
+error_e GDbus::Destroy(void)
+{
+       g_cancellable_cancel(this->m_pCancellable);
+       g_object_unref(this->m_pCancellable);
+       this->m_pCancellable = NULL;
+
+       g_object_unref(this->m_pConnection);
+       this->m_pConnection = NULL;
+
+       return ERROR_NONE;
+}
+
+GDBusConnection *GDbus::GetConnection(void)
+{
+       return this->m_pConnection;
+}
+
+GCancellable *GDbus::GetCancellable(void)
+{
+       return this->m_pCancellable;
+}
+
+error_e GDbus::ConvertErrorStringToEnum(const char *error)
+{
+       if (NULL != strstr(error, "NOT_PERMITTED"))
+               return ERROR_NOT_PERMITTED;
+       else if (NULL != strstr(error, "OUT_OF_MEMORY"))
+               return ERROR_OUT_OF_MEMORY;
+       else if (NULL != strstr(error, "PERMISSION_DENIED"))
+               return ERROR_PERMISSION_DENIED;
+       else if (NULL != strstr(error, "INVALID_OPERATION"))
+               return ERROR_INVALID_OPERATION;
+       else if (NULL != strstr(error, "INVALID_PARAMETER"))
+               return ERROR_INVALID_PARAMETER;
+       else if (NULL != strstr(error, "OPERATION_FAILED"))
+               return ERROR_OPERATION_FAILED;
+
+       return ERROR_OPERATION_FAILED;
+}
+
+GVariant *GDbus::InvokeMethod(const char *dest, const char *path,
+       const char *iface_name, const char *method, GVariant *params, error_e *dbus_error)
+{
+       GError *error = NULL;
+       GVariant *reply = NULL;
+       GDBusConnection *connection = NULL;
+       *dbus_error = ERROR_NONE;
+
+       connection = GetConnection();
+       if (connection == NULL) {
+               GLOGD("GDBusconnection is NULL");
+               *dbus_error = ERROR_NOT_INITIALIZED;
+               return reply;
+       }
+
+       reply = g_dbus_connection_call_sync(connection,
+                       dest,
+                       path,
+                       iface_name,
+                       method,
+                       params,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       DBUS_REPLY_TIMEOUT,
+                       GetCancellable(),
+                       &error);
+
+       if (reply == NULL) {
+               if (error != NULL) {
+                       GLOGD("g_dbus_connection_call_sync() failed "
+                               "error [%d: %s]", error->code, error->message);
+                       *dbus_error = ConvertErrorStringToEnum(error->message);
+                       g_error_free(error);
+               } else {
+                       GLOGD("g_dbus_connection_call_sync() failed");
+                       *dbus_error = ERROR_OPERATION_FAILED;
+               }
+
+               return NULL;
+       }
+
+       return reply;
+}
+
+error_e GDbus::InvokeMethodNonblock(const char *dest, const char *path,
+       const char *iface_name, const char *method, GVariant *params, int timeout,
+       GAsyncReadyCallback notify_func, void *user_data)
+{
+       GDBusConnection *connection = NULL;
+
+       connection = GetConnection();
+       if (connection == NULL) {
+               GLOGD("GDBusconnection is NULL");
+               return ERROR_NOT_INITIALIZED;
+       }
+
+       g_dbus_connection_call(connection,
+                       dest,
+                       path,
+                       iface_name,
+                       method,
+                       params,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       timeout,
+                       GetCancellable(),
+                       (GAsyncReadyCallback) notify_func,
+                       (gpointer)user_data);
+
+       return ERROR_NONE;
+}
diff --git a/unittest/gdbus.h b/unittest/gdbus.h
new file mode 100755 (executable)
index 0000000..7c66526
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_IPT_GDBUS_H__
+#define __STC_IPT_GDBUS_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "stcmgr.h"
+
+#define GMAINTIMEOUT 10000
+#define DBUS_REPLY_TIMEOUT (120 * 1000)
+
+#define STC_IPT_DBUS_SERVICE               "net.stc.iptables"
+#define STC_IPT_DBUS_MANAGER_INTERFACE     STC_IPT_DBUS_SERVICE ".manager"
+#define STC_IPT_DBUS_RULE_INTERFACE        STC_IPT_DBUS_SERVICE ".rule"
+#define STC_IPT_DBUS_CHAIN_INTERFACE       STC_IPT_DBUS_SERVICE ".chain"
+#define STC_IPT_DBUS_SERVICE_MANAGER_PATH  "/net/stc/iptables/manager"
+#define STC_IPT_DBUS_SERVICE_RULE_PATH     "/net/stc/iptables/rule"
+#define STC_IPT_DBUS_SERVICE_CHAIN_PATH    "/net/stc/iptables/chain"
+
+class GDbus {
+private:
+       GDBusConnection *m_pConnection;
+       GCancellable *m_pCancellable;
+public:
+       GDbus();
+       ~GDbus();
+       error_e Create(void);
+       error_e Destroy(void);
+       GDBusConnection *GetConnection(void);
+       GCancellable *GetCancellable(void);
+       error_e ConvertErrorStringToEnum(const char *error);
+       GVariant *InvokeMethod(const char *dest, const char *path,
+               const char *iface_name, const char *method, GVariant *params, error_e *dbus_error);
+       error_e InvokeMethodNonblock(const char *dest, const char *path,
+               const char *iface_name, const char *method, GVariant *params, int timeout,
+               GAsyncReadyCallback notify_func, void *user_data);
+};
+
+#endif /* __STC_IPT_GDBUS_H__ */
diff --git a/unittest/manager.cpp b/unittest/manager.cpp
new file mode 100755 (executable)
index 0000000..bd031b5
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "manager.h"
+
+Manager::Manager()
+{
+       Create();
+}
+
+Manager::~Manager()
+{
+       Destroy();
+}
+
+error_e Manager::StopManager(void)
+{
+       GVariant *message = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_MANAGER_PATH,
+               STC_IPT_DBUS_MANAGER_INTERFACE,
+               STC_IPT_METHOD_MANAGER_STOP,
+               NULL,
+               &error);
+
+       if (message == NULL) {
+               GLOGD("Failed to invoke dbus method");
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Successfully stop manager [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
diff --git a/unittest/manager.h b/unittest/manager.h
new file mode 100755 (executable)
index 0000000..42d154a
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_IPT_MANAGER_H__
+#define __STC_IPT_MANAGER_H__
+
+#include "stcmgr.h"
+#include "gdbus.h"
+
+#define STC_IPT_METHOD_MANAGER_STOP   "Stop"
+
+class Manager : public GDbus {
+private:
+public:
+       Manager();
+       ~Manager();
+       error_e StopManager(void);
+};
+
+
+#endif /* __STC_IPT_MANAGER_H__ */
diff --git a/unittest/rule.cpp b/unittest/rule.cpp
new file mode 100755 (executable)
index 0000000..e451301
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "rule.h"
+
+Rule::Rule()
+{
+       Create();
+}
+
+Rule::~Rule()
+{
+       Destroy();
+}
+
+error_e Rule::SetRule(const char *chain, ipt_rule_type_e rule_type,
+               const char *iface_name, int classid, const char *nfacct_name,
+               const char *target_name)
+{
+       if (chain == NULL || strlen(chain) == 0)
+               this->m_ChainName[0] = '\0';
+       else
+               g_strlcpy(this->m_ChainName, chain, CHAIN_NAME_LEN);
+
+       switch (rule_type) {
+       case IPT_RULE_IN:
+       case IPT_RULE_OUT:
+               this->m_RuleType = rule_type;
+               break;
+       default:
+               return ERROR_INVALID_PARAMETER;
+       }
+
+       if (iface_name == NULL || strlen(iface_name) == 0)
+               this->m_IfaceName[0] = '\0';
+       else
+               g_strlcpy(this->m_IfaceName, iface_name, IFACE_NAME_LEN);
+
+       if (classid > 0)
+               this->m_ClassID = classid;
+
+       if (nfacct_name == NULL || strlen(nfacct_name) == 0)
+               this->m_NfacctName[0] = '\0';
+       else
+               g_strlcpy(this->m_NfacctName, nfacct_name, NFACCT_NAME_LEN);
+
+       if (target_name == NULL || strlen(target_name) == 0)
+               this->m_TargetName[0] = '\0';
+       else
+               g_strlcpy(this->m_TargetName, target_name, TARGET_NAME_LEN);
+
+       return ERROR_NONE;
+}
+
+void Rule::MakeRuleParams(GVariant **params)
+{
+       GVariantBuilder *builder;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       g_variant_builder_add(builder, "{sv}", RULE_CHAIN,
+               g_variant_new_string(this->m_ChainName));
+
+       g_variant_builder_add(builder, "{sv}", RULE_TYPE,
+               g_variant_new_uint32(this->m_RuleType));
+
+       g_variant_builder_add(builder, "{sv}", RULE_IFNAME,
+               g_variant_new_string(this->m_IfaceName));
+
+       g_variant_builder_add(builder, "{sv}", RULE_CGROUP,
+               g_variant_new_uint32(this->m_ClassID));
+
+       g_variant_builder_add(builder, "{sv}", RULE_NFACCT,
+               g_variant_new_string(this->m_NfacctName));
+
+       g_variant_builder_add(builder, "{sv}", RULE_TARGET,
+               g_variant_new_string(this->m_TargetName));
+
+       *params = g_variant_new("(a{sv})", builder);
+       g_variant_builder_unref(builder);
+}
+
+error_e Rule::AddRule(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       MakeRuleParams(&params);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_RULE_PATH,
+               STC_IPT_DBUS_RULE_INTERFACE,
+               STC_IPT_METHOD_IPT_ADD_RULE,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to add rule [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Rule::Add6Rule(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       MakeRuleParams(&params);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_RULE_PATH,
+               STC_IPT_DBUS_RULE_INTERFACE,
+               STC_IPT_METHOD_IP6T_ADD_RULE,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to add 6 rule [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Rule::RemoveRule(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       MakeRuleParams(&params);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_RULE_PATH,
+               STC_IPT_DBUS_RULE_INTERFACE,
+               STC_IPT_METHOD_IPT_REMOVE_RULE,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to remove rule [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
+
+error_e Rule::Remove6Rule(void)
+{
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+       error_e error = ERROR_NONE;
+       int result = 0;
+
+       MakeRuleParams(&params);
+
+       message = InvokeMethod(STC_IPT_DBUS_SERVICE,
+               STC_IPT_DBUS_SERVICE_RULE_PATH,
+               STC_IPT_DBUS_RULE_INTERFACE,
+               STC_IPT_METHOD_IP6T_REMOVE_RULE,
+               params,
+               &error);
+
+       if (message == NULL) {
+               if (error == ERROR_NONE ||
+                       error == ERROR_INVALID_OPERATION) {
+                       GLOGD("Failed to invoke dbus method but it's normal operation");
+                       return ERROR_NONE;
+               }
+
+               GLOGD("Failed to invoke dbus method [%d]", error);
+               return error;
+       }
+
+       g_variant_get(message, "(i)", &result);
+       GLOGD("Succeeded to remove 6 rule [%d]", result);
+       g_variant_unref(message);
+
+       return ERROR_NONE;
+}
\ No newline at end of file
diff --git a/unittest/rule.h b/unittest/rule.h
new file mode 100755 (executable)
index 0000000..d7b2ffa
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_IPT_RULE_H__
+#define __STC_IPT_RULE_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "stcmgr.h"
+#include "gdbus.h"
+
+#define RULE_CHAIN   "chain"
+#define RULE_TYPE    "type"
+#define RULE_IFNAME  "ifname"
+#define RULE_CGROUP  "cgroup"
+#define RULE_NFACCT  "nfacct"
+#define RULE_TARGET  "target"
+
+#define STC_IPT_METHOD_IPT_ADD_RULE       "IptAddRule"
+#define STC_IPT_METHOD_IPT_REMOVE_RULE    "IptRemoveRule"
+
+#define STC_IPT_METHOD_IP6T_ADD_RULE      "Ip6tAddRule"
+#define STC_IPT_METHOD_IP6T_REMOVE_RULE   "Ip6tRemoveRule"
+
+typedef enum {
+       IPT_RULE_IN,
+       IPT_RULE_OUT
+} ipt_rule_type_e;
+
+class Rule : public GDbus {
+private:
+       char m_ChainName[CHAIN_NAME_LEN];       
+       char m_IfaceName[IFACE_NAME_LEN];
+       char m_NfacctName[NFACCT_NAME_LEN];
+       char m_TargetName[TARGET_NAME_LEN];
+       int m_ClassID;
+       ipt_rule_type_e m_RuleType;
+public:
+       Rule();
+       ~Rule();
+       error_e SetRule(const char *chain, ipt_rule_type_e rule_type,
+               const char *iface_name, int classid, const char *nfacct_name,
+               const char *target_name);
+       void MakeRuleParams(GVariant **params);
+       error_e AddRule(void);
+       error_e Add6Rule(void);
+       error_e RemoveRule(void);
+       error_e Remove6Rule(void);
+};
+
+#endif /* __STC_IPT_RULE_H__ */
diff --git a/unittest/stcmgr.cpp b/unittest/stcmgr.cpp
new file mode 100755 (executable)
index 0000000..c3f401f
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "stcmgr.h"
diff --git a/unittest/stcmgr.h b/unittest/stcmgr.h
new file mode 100755 (executable)
index 0000000..26e1948
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_MGR_H__
+#define __STC_MGR_H__
+
+#include <glib.h>
+
+#define CHAIN_NAME_LEN 128
+#define IFACE_NAME_LEN 64
+#define NFACCT_NAME_LEN 128
+#define TARGET_NAME_LEN 64
+
+#ifdef USE_DLOG
+#include <dlog.h>
+#undef LOG_TAG
+#define LOG_TAG "STC_GTEST"
+#define GLOGD(format, args...) LOGD(format, ##args)
+#else
+#define GLOGD(format, args...)
+#endif
+
+typedef enum {
+       ERROR_NONE = 0,
+       ERROR_NOT_PERMITTED = -1,
+       ERROR_OUT_OF_MEMORY = -2,
+       ERROR_PERMISSION_DENIED = -3,
+       ERROR_RESOURCE_BUSY = -4,
+       ERROR_INVALID_OPERATION = -5,
+       ERROR_INVALID_PARAMETER = -6,
+       ERROR_NOT_SUPPORTED = -7,
+       ERROR_OPERATION_FAILED = -8,
+       ERROR_NOT_INITIALIZED = -9,
+       ERROR_ALREADY_INITIALIZED = -10,
+       ERROR_IN_PROGRESS = -11,
+} error_e;
+
+#endif /* __STC_MGR_H__ */
diff --git a/unittest/unittest.cpp b/unittest/unittest.cpp
new file mode 100755 (executable)
index 0000000..a874a30
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+
+#include "unittest.h"
+#include "chain.h"
+#include "rule.h"
+#include "manager.h"
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+#define TEST_IN_CHAIN  "GTEST_IN"
+#define TEST_OUT_CHAIN "GTEST_OUT"
+#define TEST_IFNAME    "seth_w0"
+
+#define TARGET_ACCEPT  "ACCEPT"
+#define TARGET_DROP    "DROP"
+
+typedef struct {
+       int classid;
+       const char *nfacct;
+} cgroup_nfacct_s;
+
+static cgroup_nfacct_s examples_in[] = {
+       {21, "c2_1_21_seth_w0"}, {22, "c2_1_22_seth_w0"},
+       {23, "c2_1_23_seth_w0"}, {24, "c2_1_24_seth_w0"},
+       {25, "c2_1_25_seth_w0"}, {26, "c2_1_26_seth_w0"},
+       {27, "c2_1_27_seth_w0"}, {28, "c2_1_28_seth_w0"},
+       {29, "c2_1_29_seth_w0"},
+};
+
+static cgroup_nfacct_s examples_out[] = {
+       {21, "c4_1_21_seth_w0"}, {22, "c4_1_22_seth_w0"},
+       {23, "c4_1_23_seth_w0"}, {24, "c4_1_24_seth_w0"},
+       {25, "c4_1_25_seth_w0"}, {26, "c4_1_26_seth_w0"},
+       {27, "c4_1_27_seth_w0"}, {28, "c4_1_28_seth_w0"},
+       {29, "c4_1_29_seth_w0"},
+};
+
+static int exams_in_cnt = sizeof(examples_in) / sizeof(examples_in[0]);
+static int exams_out_cnt = sizeof(examples_out) / sizeof(examples_out[0]);
+
+TEST(StcIptables_Chain_Set, Add_p)
+{
+       error_e ret = ERROR_NONE;
+       Chain chain;
+
+       ret = chain.SetChainName(TEST_IN_CHAIN);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.AddChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.Add6Chain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.SetChainName(TEST_OUT_CHAIN);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.AddChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.Add6Chain();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcIptables_Chain_Set, Flush_p)
+{
+       error_e ret = ERROR_NONE;
+       Chain chain;
+
+       ret = chain.SetChainName(TEST_IN_CHAIN);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.FlushChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.Flush6Chain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.SetChainName(TEST_OUT_CHAIN);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.FlushChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.Flush6Chain();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcIptables_Rule_Set, AddIn_p)
+{
+       error_e ret = ERROR_NONE;
+       int index;
+       Rule rule;
+
+       for (index = 0; index < exams_in_cnt; ++index) {
+               ret = rule.SetRule(TEST_IN_CHAIN,
+                       IPT_RULE_IN,
+                       TEST_IFNAME,
+                       examples_in[index].classid,
+                       examples_in[index].nfacct,
+                       (index % 2) ? TARGET_ACCEPT : TARGET_DROP);
+               EXPECT_EQ(ERROR_NONE, ret);
+
+               ret = rule.AddRule();
+               EXPECT_EQ(ERROR_NONE, ret);
+
+               ret = rule.Add6Rule();
+               EXPECT_EQ(ERROR_NONE, ret);
+       }
+}
+
+TEST(StcIptables_Rule_Set, AddOut_p)
+{
+       error_e ret = ERROR_NONE;
+       int index;
+       Rule rule;
+
+       for (index = 0; index < exams_out_cnt; ++index) {
+               ret = rule.SetRule(TEST_OUT_CHAIN,
+                       IPT_RULE_OUT,
+                       TEST_IFNAME,
+                       examples_out[index].classid,
+                       examples_out[index].nfacct,
+                       (index % 2) ? TARGET_ACCEPT : TARGET_DROP);
+               EXPECT_EQ(ERROR_NONE, ret);
+
+               ret = rule.AddRule();
+               EXPECT_EQ(ERROR_NONE, ret);
+
+               ret = rule.Add6Rule();
+               EXPECT_EQ(ERROR_NONE, ret);
+       }
+}
+
+TEST(StcIptables_Rule_Unset, RemoveIn_p)
+{
+       error_e ret = ERROR_NONE;
+       int index;
+       Rule rule;
+
+       for (index = 0; index < exams_in_cnt; ++index) {
+               ret = rule.SetRule(TEST_IN_CHAIN,
+                       IPT_RULE_IN,
+                       TEST_IFNAME,
+                       examples_in[index].classid,
+                       examples_in[index].nfacct,
+                       (index % 2) ? TARGET_ACCEPT : TARGET_DROP);
+               EXPECT_EQ(ERROR_NONE, ret);
+
+               ret = rule.RemoveRule();
+               EXPECT_EQ(ERROR_NONE, ret);
+
+               ret = rule.Remove6Rule();
+               EXPECT_EQ(ERROR_NONE, ret);
+       }
+}
+
+TEST(StcIptables_Rule_Unset, RemoveOut_p)
+{
+       error_e ret = ERROR_NONE;
+       int index;
+       Rule rule;
+
+       for (index = 0; index < exams_out_cnt; ++index) {
+               ret = rule.SetRule(TEST_OUT_CHAIN,
+                       IPT_RULE_OUT,
+                       TEST_IFNAME,
+                       examples_out[index].classid,
+                       examples_out[index].nfacct,
+                       (index % 2) ? TARGET_ACCEPT : TARGET_DROP);
+               EXPECT_EQ(ERROR_NONE, ret);
+
+               ret = rule.RemoveRule();
+               EXPECT_EQ(ERROR_NONE, ret);
+
+               ret = rule.Remove6Rule();
+               EXPECT_EQ(ERROR_NONE, ret);
+       }
+}
+
+TEST(StcIptables_Chain_Unset, Flush_p)
+{
+       error_e ret = ERROR_NONE;
+       Chain chain;
+
+       ret = chain.SetChainName(TEST_IN_CHAIN);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.FlushChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.Flush6Chain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.SetChainName(TEST_OUT_CHAIN);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.FlushChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.Flush6Chain();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcIptables_Chain_Unset, Remove_p)
+{
+       error_e ret = ERROR_NONE;
+       Chain chain;
+
+       ret = chain.SetChainName(TEST_IN_CHAIN);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.RemoveChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.Remove6Chain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.SetChainName(TEST_OUT_CHAIN);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.RemoveChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = chain.Remove6Chain();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+
+TEST(StcIptables_Manager, Stop_p)
+{
+       error_e ret = ERROR_NONE;
+       Manager mgr;
+
+       ret = mgr.StopManager();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+int main(int argc, char **argv)
+{
+       InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/unittest.h b/unittest/unittest.h
new file mode 100755 (executable)
index 0000000..552c16d
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __STC_IPT_UNITTEST_H__
+#define __STC_IPT_UNITTEST_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <glib.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STC_IPT_UNITTEST_H__ */
\ No newline at end of file