From: Daniel Wagner <daniel.wag...@bmw-carit.de>

---
 Makefile.am          |  2 +-
 unit/test-iptables.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index e9aa95a..a00f91a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -312,7 +312,7 @@ unit_test_ippool_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -ldl
 unit_objects += $(unit_test_ippool_OBJECTS)
 
 unit_test_iptables_SOURCES = $(gdbus_sources) src/log.c \
-                src/iptables.c src/nat.c unit/test-iptables.c
+                src/iptables.c src/nat.c src/iptctx.c unit/test-iptables.c
 unit_test_iptables_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ -ldl
 unit_objects += $(unit_test_iptables_OBJECTS)
 endif
diff --git a/unit/test-iptables.c b/unit/test-iptables.c
index 203e39a..0305e86 100644
--- a/unit/test-iptables.c
+++ b/unit/test-iptables.c
@@ -315,6 +315,98 @@ static void test_nat_basic1(void)
        g_free(service);
 }
 
+static void test_iptctx_basic0(void)
+{
+       struct iptables_context *ctx;
+       int err;
+
+       ctx = __connman_iptctx_create();
+       g_assert(ctx != NULL);
+
+       err = __connman_iptctx_add_rule(ctx, "filter", "INPUT",
+                                       "-m mark --mark 999 -j LOG");
+       g_assert(err == 0);
+
+       err = __connman_iptctx_enable(ctx);
+       g_assert(err == 0);
+
+       err = __connman_iptctx_disable(ctx);
+       g_assert(err == 0);
+
+       __connman_iptctx_destroy(ctx);
+}
+
+static void test_iptctx_basic1(void)
+{
+       struct iptables_context *ctx;
+       int err;
+
+       ctx = __connman_iptctx_create();
+       g_assert(ctx != NULL);
+
+       err = __connman_iptctx_add_rule(ctx, "filter", "INPUT",
+                                       "-m mark --mark 999 -j LOG");
+       g_assert(err == 0);
+
+       err = __connman_iptctx_add_rule(ctx, "filter", "OUTPUT",
+                                       "-m mark --mark 999 -j LOG");
+       g_assert(err == 0);
+
+       err = __connman_iptctx_enable(ctx);
+       g_assert(err == 0);
+
+       err = __connman_iptctx_disable(ctx);
+       g_assert(err == 0);
+
+       __connman_iptctx_destroy(ctx);
+}
+
+static void test_iptctx_basic2(void)
+{
+       struct iptables_context *ctx;
+       int err;
+
+       ctx = __connman_iptctx_create();
+       g_assert(ctx != NULL);
+
+       err = __connman_iptctx_add_rule(ctx, "mangle", "INPUT",
+                                       "-j CONNMARK --restore-mark");
+       g_assert(err == 0);
+
+       err = __connman_iptctx_add_rule(ctx, "mangle", "POSTROUTING",
+                                       "-j CONNMARK --save-mark");
+       g_assert(err == 0);
+
+       err = __connman_iptctx_enable(ctx);
+       g_assert(err == 0);
+
+       err = __connman_iptctx_disable(ctx);
+       g_assert(err == 0);
+
+       __connman_iptctx_destroy(ctx);
+}
+
+static void test_iptctx_basic3(void)
+{
+       struct iptables_context *ctx;
+       int err;
+
+       ctx = __connman_iptctx_create();
+       g_assert(ctx != NULL);
+
+       err = __connman_iptctx_add_rule(ctx, "filter", "INPUT",
+                                       "-m mark --mark 999");
+       g_assert(err == 0);
+
+       err = __connman_iptctx_enable(ctx);
+       g_assert(err == 0);
+
+       err = __connman_iptctx_disable(ctx);
+       g_assert(err == 0);
+
+       __connman_iptctx_destroy(ctx);
+}
+
 int main(int argc, char *argv[])
 {
        int err;
@@ -337,6 +429,10 @@ int main(int argc, char *argv[])
        g_test_add_func("/iptables/managed0", test_iptables_managed0);
        g_test_add_func("/nat/basic0", test_nat_basic0);
        g_test_add_func("/nat/basic1", test_nat_basic1);
+       g_test_add_func("/iptctx/basic0", test_iptctx_basic0);
+       g_test_add_func("/iptctx/basic1", test_iptctx_basic1);
+       g_test_add_func("/iptctx/basic2", test_iptctx_basic2);
+       g_test_add_func("/iptctx/basic3", test_iptctx_basic3);
 
        err = g_test_run();
 
-- 
1.8.1.3.566.gaa39828

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to