summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2013-02-12 10:19:48 +0100
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-12 12:34:37 +0200
commitaf9be951d5da9ff42b5b5af9251eede003614678 (patch)
tree236370de6b572f121b2ca213b26489eb884443cd
parent8a9d7d098752ed51762859124438d29e281ca76b (diff)
downloadconnman-af9be951d5da9ff42b5b5af9251eede003614678.tar.gz
connman-af9be951d5da9ff42b5b5af9251eede003614678.tar.bz2
connman-af9be951d5da9ff42b5b5af9251eede003614678.zip
test-nat: Move tests to test-iptables
These are iptables related tests. So let's move them over.
-rw-r--r--Makefile.am9
-rw-r--r--unit/test-iptables.c77
-rw-r--r--unit/test-nat.c165
3 files changed, 79 insertions, 172 deletions
diff --git a/Makefile.am b/Makefile.am
index 15d59da7..60eb46e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -249,7 +249,7 @@ noinst_PROGRAMS += tools/supplicant-test \
tools/dbus-test tools/polkit-test \
tools/iptables-test tools/tap-test tools/wpad-test \
tools/stats-tool tools/private-network-test \
- unit/test-session unit/test-ippool unit/test-nat \
+ unit/test-session unit/test-ippool \
unit/test-iptables
tools_supplicant_test_SOURCES = $(gdbus_sources) tools/supplicant-test.c \
@@ -295,14 +295,9 @@ 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 unit/test-iptables.c
+ src/iptables.c src/nat.c unit/test-iptables.c
unit_test_iptables_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ -ldl
unit_objects += $(unit_test_iptables_OBJECTS)
-
-unit_test_nat_SOURCES = $(gdbus_sources) src/log.c src/dbus.c \
- src/iptables.c src/nat.c unit/test-nat.c
-unit_test_nat_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ @XTABLES_LIBS@ -ldl
-unit_objects += $(unit_nat_ippool_OBJECTS)
endif
test_scripts = test/get-state test/list-services \
diff --git a/unit/test-iptables.c b/unit/test-iptables.c
index d9170125..1e94647e 100644
--- a/unit/test-iptables.c
+++ b/unit/test-iptables.c
@@ -233,6 +233,79 @@ static void test_iptables_rule2(void)
g_assert(err == 0);
}
+struct connman_notifier *nat_notifier;
+
+struct connman_service {
+ char *dummy;
+};
+
+char *connman_service_get_interface(struct connman_service *service)
+{
+ return "eth0";
+}
+
+int connman_notifier_register(struct connman_notifier *notifier)
+{
+ nat_notifier = notifier;
+
+ return 0;
+}
+
+void connman_notifier_unregister(struct connman_notifier *notifier)
+{
+ nat_notifier = NULL;
+}
+
+static void test_nat_basic0(void)
+{
+ int err;
+
+ err = __connman_nat_enable("bridge", "192.168.2.1", 24);
+ g_assert(err == 0);
+
+ /* test that table is empty */
+ err = __connman_iptables_append("nat", "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");
+}
+
+static void test_nat_basic1(void)
+{
+ struct connman_service *service;
+ int err;
+
+ service = g_try_new0(struct connman_service, 1);
+ g_assert(service);
+
+ nat_notifier->default_changed(service);
+
+ err = __connman_nat_enable("bridge", "192.168.2.1", 24);
+ g_assert(err == 0);
+
+ /* test that table is not empty */
+ err = __connman_iptables_append("nat", "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");
+
+ /* test that table is empty again */
+ err = __connman_iptables_delete("nat", "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[])
{
int err;
@@ -242,6 +315,7 @@ int main(int argc, char *argv[])
__connman_log_init(argv[0], "*", FALSE, FALSE,
"Unit Tests Connection Manager", VERSION);
__connman_iptables_init();
+ __connman_nat_init();
g_test_add_func("/iptables/basic0", test_iptables_basic0);
g_test_add_func("/iptables/basic1", test_iptables_basic1);
@@ -252,9 +326,12 @@ int main(int argc, char *argv[])
g_test_add_func("/iptables/rule0", test_iptables_rule0);
g_test_add_func("/iptables/rule1", test_iptables_rule1);
g_test_add_func("/iptables/rule2", test_iptables_rule2);
+ g_test_add_func("/nat/basic0", test_nat_basic0);
+ g_test_add_func("/nat/basic1", test_nat_basic1);
err = g_test_run();
+ __connman_nat_cleanup();
__connman_iptables_cleanup();
return err;
diff --git a/unit/test-nat.c b/unit/test-nat.c
deleted file mode 100644
index df8a2b59..00000000
--- a/unit/test-nat.c
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- *
- * Connection Manager
- *
- * Copyright (C) 2012 BWM CarIT GmbH. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <glib.h>
-
-#include "../src/connman.h"
-
-/* #define DEBUG */
-#ifdef DEBUG
-#include <stdio.h>
-
-#define LOG(fmt, arg...) do { \
- fprintf(stdout, "%s:%s() " fmt "\n", \
- __FILE__, __func__ , ## arg); \
-} while (0)
-#else
-#define LOG(fmt, arg...)
-#endif
-
-struct connman_notifier *nat_notifier;
-
-struct connman_service {
- char *dummy;
-};
-
-char *connman_service_get_interface(struct connman_service *service)
-{
- return "eth0";
-}
-
-int connman_notifier_register(struct connman_notifier *notifier)
-{
- nat_notifier = notifier;
-
- return 0;
-}
-
-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;
-
- err = __connman_nat_enable("bridge", "192.168.2.1", 24);
- g_assert(err == 0);
-
- /* test that table is empty */
- 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");
-}
-
-static void test_nat_basic1(void)
-{
- struct connman_service *service;
- int err;
-
- service = g_try_new0(struct connman_service, 1);
- g_assert(service);
-
- nat_notifier->default_changed(service);
-
- err = __connman_nat_enable("bridge", "192.168.2.1", 24);
- g_assert(err == 0);
-
- /* test that table is not empty */
- 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");
-
- /* test that table is empty again */
- 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[])
-{
- int err;
-
- g_test_init(&argc, &argv, NULL);
-
- __connman_log_init(argv[0], "*", FALSE, TRUE, "test-nat", VERSION);
- __connman_iptables_init();
- __connman_nat_init();
-
- 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();
-
- __connman_nat_cleanup();
- __connman_iptables_cleanup();
- __connman_log_cleanup(TRUE);
-
- return err;
-}