#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;
IFACE_DATACALL,
0,
0,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.SetRstriction();
IFACE_WIFI,
2,
1,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.SetRstriction();
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;
IFACE_DATACALL,
0,
0,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.GetRstriction();
IFACE_WIFI,
0,
0,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.GetRstriction();
IFACE_DATACALL,
0,
0,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.GetRstriction();
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)
{
IFACE_DATACALL,
0,
0,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.UnsetRstriction();
IFACE_WIFI,
2,
1,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.UnsetRstriction();
IFACE_WIRED,
100000,
80000,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.UnsetRstriction();
IFACE_DATACALL,
0,
0,
- ROAMING_UNKNOWN);
+ ROAMING_UNKNOWN,
+ GTEST_MAC);
EXPECT_EQ(ERROR_NONE, ret);
ret = rest.UnsetRstriction();
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;