Converted tests for chunk_t
authorTobias Brunner <tobias@strongswan.org>
Tue, 26 Mar 2013 15:39:44 +0000 (16:39 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Jun 2013 09:03:11 +0000 (11:03 +0200)
src/libcharon/plugins/unit_tester/Makefile.am
src/libcharon/plugins/unit_tester/tests.h
src/libcharon/plugins/unit_tester/tests/test_chunk.c [deleted file]
src/libstrongswan/tests/Makefile.am
src/libstrongswan/tests/test_chunk.c [new file with mode: 0644]
src/libstrongswan/tests/test_runner.c
src/libstrongswan/tests/test_runner.h

index b597b92..db11d93 100644 (file)
@@ -20,7 +20,6 @@ libstrongswan_unit_tester_la_SOURCES = \
        tests/test_rsa_gen.c \
        tests/test_cert.c \
        tests/test_med_db.c \
-       tests/test_chunk.c \
        tests/test_pool.c \
        tests/test_agent.c
 
index 527bb25..4fd358e 100644 (file)
@@ -27,7 +27,6 @@ DEFINE_TEST("RSA key generation", test_rsa_gen, FALSE)
 DEFINE_TEST("RSA subjectPublicKeyInfo loading", test_rsa_load_any, FALSE)
 DEFINE_TEST("X509 certificate", test_cert_x509, FALSE)
 DEFINE_TEST("Mediation database key fetch", test_med_db, FALSE)
-DEFINE_TEST("Base64 converter", test_chunk_base64, FALSE)
 DEFINE_TEST("IP pool", test_pool, FALSE)
 DEFINE_TEST("SSH agent", test_agent, FALSE)
 
diff --git a/src/libcharon/plugins/unit_tester/tests/test_chunk.c b/src/libcharon/plugins/unit_tester/tests/test_chunk.c
deleted file mode 100644 (file)
index 2e0905b..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (C) 2008 Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * 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.
- */
-
-#include <library.h>
-#include <daemon.h>
-
-/*******************************************************************************
- * Base64 encoding/decoding test
- ******************************************************************************/
-bool test_chunk_base64()
-{
-       /* test vectors from RFC4648:
-        *
-        * BASE64("") = ""
-        * BASE64("f") = "Zg=="
-        * BASE64("fo") = "Zm8="
-        * BASE64("foo") = "Zm9v"
-        * BASE64("foob") = "Zm9vYg=="
-        * BASE64("fooba") = "Zm9vYmE="
-        * BASE64("foobar") = "Zm9vYmFy"
-        */
-
-       typedef struct {
-               char *in;
-               char *out;
-       } testdata_t;
-
-       testdata_t test[] = {
-               {"", ""},
-               {"f", "Zg=="},
-               {"fo", "Zm8="},
-               {"foo", "Zm9v"},
-               {"foob", "Zm9vYg=="},
-               {"fooba", "Zm9vYmE="},
-               {"foobar", "Zm9vYmFy"},
-       };
-       int i;
-
-       for (i = 0; i < countof(test); i++)
-       {
-               chunk_t out;
-
-               out = chunk_to_base64(chunk_create(test[i].in, strlen(test[i].in)), NULL);
-
-               if (!streq(out.ptr, test[i].out))
-               {
-                       DBG1(DBG_CFG, "base64 conversion error - should %s, is %s",
-                               test[i].out, out.ptr);
-                       return FALSE;
-               }
-               free(out.ptr);
-       }
-
-       for (i = 0; i < countof(test); i++)
-       {
-               chunk_t out;
-
-               out = chunk_from_base64(chunk_create(test[i].out, strlen(test[i].out)), NULL);
-
-               if (!strneq(out.ptr, test[i].in, out.len))
-               {
-                       DBG1(DBG_CFG, "base64 conversion error - should %s, is %#B",
-                               test[i].in, &out);
-                       return FALSE;
-               }
-               free(out.ptr);
-       }
-       return TRUE;
-}
-
index 45aab87..bb1ce91 100644 (file)
@@ -5,7 +5,7 @@ check_PROGRAMS = $(TESTS)
 test_runner_SOURCES = \
   test_runner.c test_runner.h \
   test_linked_list.c test_enumerator.c test_linked_list_enumerator.c \
-  test_hashtable.c test_identification.c
+  test_chunk.c test_hashtable.c test_identification.c
 
 
 test_runner_CFLAGS = \
diff --git a/src/libstrongswan/tests/test_chunk.c b/src/libstrongswan/tests/test_chunk.c
new file mode 100644 (file)
index 0000000..151775e
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Copyright (C) 2008 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+
+#include <check.h>
+
+#include <utils/chunk.h>
+
+/*******************************************************************************
+ * BASE64 encoding test
+ */
+
+START_TEST(test_base64)
+{
+       /* test vectors from RFC4648:
+        *
+        * BASE64("") = ""
+        * BASE64("f") = "Zg=="
+        * BASE64("fo") = "Zm8="
+        * BASE64("foo") = "Zm9v"
+        * BASE64("foob") = "Zm9vYg=="
+        * BASE64("fooba") = "Zm9vYmE="
+        * BASE64("foobar") = "Zm9vYmFy"
+        */
+       typedef struct {
+               char *in;
+               char *out;
+       } testdata_t;
+
+       testdata_t test[] = {
+               {"", ""},
+               {"f", "Zg=="},
+               {"fo", "Zm8="},
+               {"foo", "Zm9v"},
+               {"foob", "Zm9vYg=="},
+               {"fooba", "Zm9vYmE="},
+               {"foobar", "Zm9vYmFy"},
+       };
+       int i;
+
+       for (i = 0; i < countof(test); i++)
+       {
+               chunk_t out;
+
+               out = chunk_to_base64(chunk_create(test[i].in, strlen(test[i].in)), NULL);
+               ck_assert_str_eq(out.ptr, test[i].out);
+               free(out.ptr);
+       }
+
+       for (i = 0; i < countof(test); i++)
+       {
+               chunk_t out;
+
+               out = chunk_from_base64(chunk_create(test[i].out, strlen(test[i].out)), NULL);
+               fail_unless(strneq(out.ptr, test[i].in, out.len),
+                                       "base64 conversion error - should '%s', is %#B",
+                                       test[i].in, &out);
+               free(out.ptr);
+       }
+}
+END_TEST
+
+Suite *chunk_suite_create()
+{
+       Suite *s;
+       TCase *tc;
+
+       s = suite_create("chunk");
+
+       tc = tcase_create("base64");
+       tcase_add_test(tc, test_base64);
+       suite_add_tcase(s, tc);
+
+       return s;
+}
index 114ba39..03287e5 100644 (file)
@@ -32,6 +32,7 @@ int main()
        library_init(NULL);
 
        sr = srunner_create(NULL);
+       srunner_add_suite(sr, chunk_suite_create());
        srunner_add_suite(sr, enumerator_suite_create());
        srunner_add_suite(sr, linked_list_suite_create());
        srunner_add_suite(sr, linked_list_enumerator_suite_create());
index 490bf54..7593c6a 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <check.h>
 
+Suite *chunk_suite_create();
 Suite *enumerator_suite_create();
 Suite *linked_list_suite_create();
 Suite *linked_list_enumerator_suite_create();