test-nat: Add main table tests
[platform/upstream/connman.git] / unit / test-nat.c
index a601871..578ff3e 100644 (file)
@@ -62,6 +62,37 @@ void connman_notifier_unregister(struct connman_notifier *notifier)
        nat_notifier = NULL;
 }
 
+
+static void test_iptables_basic0(void)
+{
+       int err;
+
+       err = __connman_iptables_command("-C INPUT -i session-bridge -j ACCEPT");
+       g_assert(err != 0);
+       err = __connman_iptables_commit("filter");
+       g_assert(err == 0);
+
+       err = __connman_iptables_command("-I INPUT -i session-bridge -j ACCEPT");
+       g_assert(err == 0);
+       err = __connman_iptables_commit("filter");
+       g_assert(err == 0);
+
+       err = __connman_iptables_command("-C INPUT -i session-bridge -j ACCEPT");
+       g_assert(err == 0);
+       err = __connman_iptables_commit("filter");
+       g_assert(err == 0);
+
+       err = __connman_iptables_command("-D INPUT -i session-bridge -j ACCEPT");
+       g_assert(err == 0);
+       err = __connman_iptables_commit("filter");
+       g_assert(err == 0);
+
+       err = __connman_iptables_command("-C INPUT -i session-bridge -j ACCEPT");
+       g_assert(err != 0);
+       err = __connman_iptables_commit("filter");
+       g_assert(err == 0);
+}
+
 static void test_nat_basic0(void)
 {
        int err;
@@ -73,6 +104,9 @@ static void test_nat_basic0(void)
        err = __connman_iptables_command("-t nat -C POSTROUTING "
                                        "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
        g_assert(err != 0);
+       err = __connman_iptables_commit("nat");
+       g_assert(err == 0);
+
 
        __connman_nat_disable("bridge");
 }
@@ -94,6 +128,8 @@ static void test_nat_basic1(void)
        err = __connman_iptables_command("-t nat -C POSTROUTING "
                                        "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
        g_assert(err == 0);
+       err = __connman_iptables_commit("nat");
+       g_assert(err == 0);
 
        __connman_nat_disable("bridge");
 
@@ -101,6 +137,8 @@ static void test_nat_basic1(void)
        err = __connman_iptables_command("-t nat -C POSTROUTING "
                                        "-s 192.168.2.1/24 -o eth0 -j MASQUERADE");
        g_assert(err != 0);
+       err = __connman_iptables_commit("nat");
+       g_assert(err == 0);
 }
 
 int main(int argc, char *argv[])
@@ -113,8 +151,9 @@ int main(int argc, char *argv[])
        __connman_iptables_init();
        __connman_nat_init();
 
-       g_test_add_func("/basic0", test_nat_basic0);
-       g_test_add_func("/basic1", test_nat_basic1);
+       g_test_add_func("/iptables/basic0", test_iptables_basic0);
+       g_test_add_func("/nat/basic0", test_nat_basic0);
+       g_test_add_func("/nat/basic1", test_nat_basic1);
 
        err = g_test_run();