Added additional test cases for stc-manager firewall dbus methods
[platform/core/connectivity/stc-manager.git] / unittest / unittest.cpp
index 1141021..8b467f7 100644 (file)
 #include "restriction.h"
 #include "statistics.h"
 #include "manager.h"
+#include "stc-manager.h"
+#include "firewall.h"
+
+#define GTEST_MAC "1:c:e:b:00:da"
 
 using ::testing::InitGoogleTest;
 using ::testing::Test;
 using ::testing::TestCase;
 
+typedef enum {
+       FIREWALL_UNKONWN,
+       FIREWALL_UNLOCKED,
+       FIREWALL_LOCKED
+} firewall_lock_e;
+
 TEST(StcManager_Statistics, Init_p)
 {
        error_e ret = ERROR_NONE;
@@ -138,7 +148,8 @@ TEST(StcManager_Restriction, Set_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.SetRstriction();
@@ -150,7 +161,8 @@ TEST(StcManager_Restriction, Set_p)
                IFACE_WIFI,
                2,
                1,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.SetRstriction();
@@ -162,32 +174,14 @@ TEST(StcManager_Restriction, Set_p)
                IFACE_WIRED,
                100000,
                80000,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.SetRstriction();
        EXPECT_EQ(ERROR_NONE, ret);
 }
 
-TEST(StcManager_Restriction, Exclude_p)
-
-{
-       error_e ret = ERROR_NONE;
-       Restriction rest;
-
-       ret = rest.SetRule("TOTAL_DATACALL",
-               "seth_w0",
-               NULL,
-               IFACE_DATACALL,
-               0,
-               0,
-               ROAMING_UNKNOWN);
-       EXPECT_EQ(ERROR_NONE, ret);
-
-       ret = rest.ExcludeRstriction();
-       EXPECT_EQ(ERROR_NONE, ret);
-}
-
 TEST(StcManager_Restriction, Get_p)
 {
        error_e ret = ERROR_NONE;
@@ -199,7 +193,8 @@ TEST(StcManager_Restriction, Get_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.GetRstriction();
@@ -211,7 +206,8 @@ TEST(StcManager_Restriction, Get_p)
                IFACE_WIFI,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.GetRstriction();
@@ -223,7 +219,8 @@ TEST(StcManager_Restriction, Get_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.GetRstriction();
@@ -239,40 +236,6 @@ TEST(StcManager_Restriction, GetAll_p)
        EXPECT_EQ(ERROR_NONE, ret);
 }
 
-TEST(StcManager_Restriction, GetRst_p)
-{
-       error_e ret = ERROR_NONE;
-       Restriction rest;
-       restriction_status_e status = RESTRICTION_UNKNOWN;
-
-       ret = rest.SetRule("Test_tel",
-               "seth_w0",
-               NULL,
-               IFACE_DATACALL,
-               0,
-               0,
-               ROAMING_UNKNOWN);
-       EXPECT_EQ(ERROR_NONE, ret);
-
-       ret = rest.GetRstrictionStatus(&status);
-       EXPECT_EQ(ERROR_NONE, ret);
-       EXPECT_LE(RESTRICTION_UNKNOWN, status);
-       EXPECT_GE(RESTRICTION_LAST_ELEM, status);
-
-       ret = rest.SetRule("Test_eth",
-               "eth0",
-               NULL,
-               IFACE_WIRED,
-               100000,
-               80000,
-               ROAMING_UNKNOWN);
-       EXPECT_EQ(ERROR_NONE, ret);
-
-       ret = rest.GetRstrictionStatus(&status);
-       EXPECT_EQ(ERROR_NONE, ret);
-       EXPECT_LE(RESTRICTION_UNKNOWN, status);
-       EXPECT_GE(RESTRICTION_LAST_ELEM, status);
-}
 
 TEST(StcManager_Restriction, Unset_p)
 {
@@ -285,7 +248,8 @@ TEST(StcManager_Restriction, Unset_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.UnsetRstriction();
@@ -297,7 +261,8 @@ TEST(StcManager_Restriction, Unset_p)
                IFACE_WIFI,
                2,
                1,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.UnsetRstriction();
@@ -309,7 +274,8 @@ TEST(StcManager_Restriction, Unset_p)
                IFACE_WIRED,
                100000,
                80000,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.UnsetRstriction();
@@ -321,7 +287,8 @@ TEST(StcManager_Restriction, Unset_p)
                IFACE_DATACALL,
                0,
                0,
-               ROAMING_UNKNOWN);
+               ROAMING_UNKNOWN,
+               GTEST_MAC);
        EXPECT_EQ(ERROR_NONE, ret);
 
        ret = rest.UnsetRstriction();
@@ -361,6 +328,269 @@ TEST(StcManager_Statistics, Reset_p)
        EXPECT_EQ(ERROR_NONE, ret);
 }
 
+TEST(StcManager_Firewall, Lock_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       int state;
+       f.GetLock(&state);
+       if (state == FIREWALL_LOCKED)
+               f.Unlock();
+
+       ret = f.Lock();
+       EXPECT_EQ(ERROR_NONE, ret);
+       f.Unlock();
+}
+
+TEST(StcManager_Firewall, Unlock_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       int state;
+       f.GetLock(&state);
+       if (state != FIREWALL_LOCKED)
+               f.Lock();
+
+       ret = f.Unlock();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, GetLock_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       int state;
+       f.GetLock(&state);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, AddChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.AddChain("gtest");
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, AddRule_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetRule("gtest",
+                       STC_FW_DIRECTION_IN,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PROTOCOL_TCP,
+                       STC_FW_FAMILY_V4,
+                       "1.1.1.1",
+                       "1.1.1.1",
+                       "2.2.2.2",
+                       "2.2.2.2",
+                       9000,
+                       9000,
+                       9000,
+                       9000,
+                       "wlan0",
+                       STC_FW_RULE_TARGET_ACCEPT);
+
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.AddRule();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, AddRule_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetRule("gtest",
+                       STC_FW_DIRECTION_IN,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PROTOCOL_TCP,
+                       STC_FW_FAMILY_V4,
+                       "1.1.1.1",
+                       "1.1.1.1",
+                       "2.2.2.2",
+                       "2.2.2.2",
+                       9000,
+                       9000,
+                       9000,
+                       9000,
+                       "wlan0",
+                       STC_FW_RULE_TARGET_MAX);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.AddRule();
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, UpdateRule_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetRule("gtest",
+                       STC_FW_DIRECTION_IN,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PROTOCOL_TCP,
+                       STC_FW_FAMILY_V4,
+                       "1.1.1.1",
+                       "1.1.1.1",
+                       "2.2.2.2",
+                       "2.2.2.2",
+                       9000,
+                       9000,
+                       9000,
+                       9000,
+                       "wlan0",
+                       STC_FW_RULE_TARGET_MAX);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.UpdateRule();
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, RemoveRule_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetRule("gtest",
+                       STC_FW_DIRECTION_IN,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_IP_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PORT_SINGLE,
+                       STC_FW_PROTOCOL_TCP,
+                       STC_FW_FAMILY_V4,
+                       "1.1.1.1",
+                       "1.1.1.1",
+                       "2.2.2.2",
+                       "2.2.2.2",
+                       9000,
+                       9000,
+                       9000,
+                       9000,
+                       "wlan0",
+                       STC_FW_RULE_TARGET_MAX);
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.RemoveRule();
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+
+TEST(StcManager_Firewall, SetChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetChain("gtest", 1);
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, SetChain_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.SetChain(NULL, 0);
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, UnsetChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.UnsetChain("gtest");
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, UnsetChain_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.UnsetChain(NULL);
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+
+TEST(StcManager_Firewall, RemoveChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.RemoveChain("gtest");
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, RemoveChain_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.RemoveChain("not_a_chain");
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, FlushChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.AddChain("gtest_chains");
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       ret = f.FlushChain("gtest_chains");
+       EXPECT_EQ(ERROR_NONE, ret);
+
+       f.RemoveChain("gtest_chains");
+}
+
+
+TEST(StcManager_Firewall, FlushChain_n)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.FlushChain(NULL);
+       EXPECT_NE(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, GetAllChain_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.GetAllChain();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
+TEST(StcManager_Firewall, GetAllRule_p)
+{
+       error_e ret = ERROR_NONE;
+       Firewall f;
+
+       ret = f.GetAllRule();
+       EXPECT_EQ(ERROR_NONE, ret);
+}
+
 TEST(StcManager_Manager, Stop_p)
 {
        error_e ret = ERROR_NONE;