mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-15 00:00:16 -04:00
Converted tests for chunk_t
This commit is contained in:
parent
e09461bf77
commit
4e67f19528
@ -20,7 +20,6 @@ libstrongswan_unit_tester_la_SOURCES = \
|
|||||||
tests/test_rsa_gen.c \
|
tests/test_rsa_gen.c \
|
||||||
tests/test_cert.c \
|
tests/test_cert.c \
|
||||||
tests/test_med_db.c \
|
tests/test_med_db.c \
|
||||||
tests/test_chunk.c \
|
|
||||||
tests/test_pool.c \
|
tests/test_pool.c \
|
||||||
tests/test_agent.c
|
tests/test_agent.c
|
||||||
|
|
||||||
|
@ -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("RSA subjectPublicKeyInfo loading", test_rsa_load_any, FALSE)
|
||||||
DEFINE_TEST("X509 certificate", test_cert_x509, FALSE)
|
DEFINE_TEST("X509 certificate", test_cert_x509, FALSE)
|
||||||
DEFINE_TEST("Mediation database key fetch", test_med_db, 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("IP pool", test_pool, FALSE)
|
||||||
DEFINE_TEST("SSH agent", test_agent, FALSE)
|
DEFINE_TEST("SSH agent", test_agent, FALSE)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ check_PROGRAMS = $(TESTS)
|
|||||||
test_runner_SOURCES = \
|
test_runner_SOURCES = \
|
||||||
test_runner.c test_runner.h \
|
test_runner.c test_runner.h \
|
||||||
test_linked_list.c test_enumerator.c test_linked_list_enumerator.c \
|
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 = \
|
test_runner_CFLAGS = \
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2013 Tobias Brunner
|
||||||
* Copyright (C) 2008 Martin Willi
|
* Copyright (C) 2008 Martin Willi
|
||||||
* Hochschule fuer Technik Rapperswil
|
* Hochschule fuer Technik Rapperswil
|
||||||
*
|
*
|
||||||
@ -13,13 +14,16 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <library.h>
|
|
||||||
#include <daemon.h>
|
#include <check.h>
|
||||||
|
|
||||||
|
#include <utils/chunk.h>
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Base64 encoding/decoding test
|
* BASE64 encoding test
|
||||||
******************************************************************************/
|
*/
|
||||||
bool test_chunk_base64()
|
|
||||||
|
START_TEST(test_base64)
|
||||||
{
|
{
|
||||||
/* test vectors from RFC4648:
|
/* test vectors from RFC4648:
|
||||||
*
|
*
|
||||||
@ -31,7 +35,6 @@ bool test_chunk_base64()
|
|||||||
* BASE64("fooba") = "Zm9vYmE="
|
* BASE64("fooba") = "Zm9vYmE="
|
||||||
* BASE64("foobar") = "Zm9vYmFy"
|
* BASE64("foobar") = "Zm9vYmFy"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *in;
|
char *in;
|
||||||
char *out;
|
char *out;
|
||||||
@ -53,13 +56,7 @@ bool test_chunk_base64()
|
|||||||
chunk_t out;
|
chunk_t out;
|
||||||
|
|
||||||
out = chunk_to_base64(chunk_create(test[i].in, strlen(test[i].in)), NULL);
|
out = chunk_to_base64(chunk_create(test[i].in, strlen(test[i].in)), NULL);
|
||||||
|
ck_assert_str_eq(out.ptr, test[i].out);
|
||||||
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);
|
free(out.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,15 +65,24 @@ bool test_chunk_base64()
|
|||||||
chunk_t out;
|
chunk_t out;
|
||||||
|
|
||||||
out = chunk_from_base64(chunk_create(test[i].out, strlen(test[i].out)), NULL);
|
out = chunk_from_base64(chunk_create(test[i].out, strlen(test[i].out)), NULL);
|
||||||
|
fail_unless(strneq(out.ptr, test[i].in, out.len),
|
||||||
if (!strneq(out.ptr, test[i].in, out.len))
|
"base64 conversion error - should '%s', is %#B",
|
||||||
{
|
test[i].in, &out);
|
||||||
DBG1(DBG_CFG, "base64 conversion error - should %s, is %#B",
|
|
||||||
test[i].in, &out);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
free(out.ptr);
|
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;
|
||||||
|
}
|
@ -32,6 +32,7 @@ int main()
|
|||||||
library_init(NULL);
|
library_init(NULL);
|
||||||
|
|
||||||
sr = srunner_create(NULL);
|
sr = srunner_create(NULL);
|
||||||
|
srunner_add_suite(sr, chunk_suite_create());
|
||||||
srunner_add_suite(sr, enumerator_suite_create());
|
srunner_add_suite(sr, enumerator_suite_create());
|
||||||
srunner_add_suite(sr, linked_list_suite_create());
|
srunner_add_suite(sr, linked_list_suite_create());
|
||||||
srunner_add_suite(sr, linked_list_enumerator_suite_create());
|
srunner_add_suite(sr, linked_list_enumerator_suite_create());
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
|
||||||
|
Suite *chunk_suite_create();
|
||||||
Suite *enumerator_suite_create();
|
Suite *enumerator_suite_create();
|
||||||
Suite *linked_list_suite_create();
|
Suite *linked_list_suite_create();
|
||||||
Suite *linked_list_enumerator_suite_create();
|
Suite *linked_list_enumerator_suite_create();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user