]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
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/libstrongswan/tests/Makefile.am
src/libstrongswan/tests/test_chunk.c [moved from src/libcharon/plugins/unit_tester/tests/test_chunk.c with 74% similarity]
src/libstrongswan/tests/test_runner.c
src/libstrongswan/tests/test_runner.h

index b597b928bfdef87569df4547b4c3ab52d3c07b84..db11d934c70eb1d059c0e9554f36ef3a04266061 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 527bb25728998f8aa38a5085951898db4c24f975..4fd358e6bde7a0d51d8354796743e3a097db019d 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)
 
index 45aab8736265f4a47484fd9352498c0625dde4e5..bb1ce91a7b010625e588532251c0ae73c26167cd 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 = \
similarity index 74%
rename from src/libcharon/plugins/unit_tester/tests/test_chunk.c
rename to src/libstrongswan/tests/test_chunk.c
index 2e0905b2c46a4ab5621019e2ec46e54fbd2b491a..151775ef7a3f3b02b9ff6df8bbc996f6b93c3eb6 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2013 Tobias Brunner
  * Copyright (C) 2008 Martin Willi
  * Hochschule fuer Technik Rapperswil
  *
  * for more details.
  */
 
-#include <library.h>
-#include <daemon.h>
+
+#include <check.h>
+
+#include <utils/chunk.h>
 
 /*******************************************************************************
- * Base64 encoding/decoding test
- ******************************************************************************/
-bool test_chunk_base64()
+ * BASE64 encoding test
+ */
+
+START_TEST(test_base64)
 {
        /* test vectors from RFC4648:
         *
@@ -31,7 +35,6 @@ bool test_chunk_base64()
         * BASE64("fooba") = "Zm9vYmE="
         * BASE64("foobar") = "Zm9vYmFy"
         */
-
        typedef struct {
                char *in;
                char *out;
@@ -53,13 +56,7 @@ bool test_chunk_base64()
                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;
-               }
+               ck_assert_str_eq(out.ptr, test[i].out);
                free(out.ptr);
        }
 
@@ -68,15 +65,24 @@ bool test_chunk_base64()
                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;
-               }
+               fail_unless(strneq(out.ptr, test[i].in, out.len),
+                                       "base64 conversion error - should '%s', is %#B",
+                                       test[i].in, &out);
                free(out.ptr);
        }
-       return TRUE;
 }
+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 114ba39e1f8fe6c7429d6cb4601e431b793ca186..03287e53c66f4d00c4bf331dbce116d5ba40d7fc 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 490bf54f804c94c8cc36655f7d7cb740d026c9cc..7593c6aa64503a0f2bafee3bc3b8f14a8abdae23 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();