Annotation of embedaddon/strongswan/src/charon-tkm/tests/utils_tests.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2012 Reto Buerki
                      3:  * Copyright (C) 2012 Adrian-Ken Rueegsegger
                      4:  * HSR Hochschule fuer Technik Rapperswil
                      5:  *
                      6:  * This program is free software; you can redistribute it and/or modify it
                      7:  * under the terms of the GNU General Public License as published by the
                      8:  * Free Software Foundation; either version 2 of the License, or (at your
                      9:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                     10:  *
                     11:  * This program is distributed in the hope that it will be useful, but
                     12:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     13:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     14:  * for more details.
                     15:  */
                     16: 
                     17: #include <tests/test_suite.h>
                     18: 
                     19: #include <tkm/types.h>
                     20: 
                     21: #include "tkm_utils.h"
                     22: 
                     23: START_TEST(test_sequence_to_chunk)
                     24: {
                     25:        key_type key = {5, {0, 1, 2, 3, 4}};
                     26:        chunk_t chunk = chunk_empty;
                     27: 
                     28:        sequence_to_chunk(key.data, key.size, &chunk);
                     29:        fail_if(chunk.len != key.size, "Chunk size mismatch");
                     30: 
                     31:        uint32_t i;
                     32:        for (i = 0; i < key.size; i++)
                     33:        {
                     34:                fail_if(chunk.ptr[i] != i, "Data mismatch");
                     35:        }
                     36:        chunk_free(&chunk);
                     37: }
                     38: END_TEST
                     39: 
                     40: START_TEST(test_chunk_to_sequence)
                     41: {
                     42:        chunk_t chunk = chunk_from_thing("ABCDEFGH");
                     43:        key_type key;
                     44: 
                     45:        chunk_to_sequence(&chunk, &key, sizeof(key_type));
                     46:        fail_if(key.size != chunk.len, "Seq size mismatch");
                     47: 
                     48:        uint32_t i;
                     49:        for (i = 0; i < key.size - 1; i++)
                     50:        {
                     51:                fail_if(key.data[i] != 65 + i, "Data mismatch (1)");
                     52:        }
                     53:        fail_if(key.data[key.size - 1] != 0, "Data mismatch (2)");
                     54: }
                     55: END_TEST
                     56: 
                     57: Suite *make_utility_tests()
                     58: {
                     59:        Suite *s;
                     60:        TCase *tc;
                     61: 
                     62:        s = suite_create("utility tests");
                     63: 
                     64:        tc = tcase_create("chunk<->sequence");
                     65:        tcase_add_test(tc, test_sequence_to_chunk);
                     66:        tcase_add_test(tc, test_chunk_to_sequence);
                     67:        suite_add_tcase(s, tc);
                     68: 
                     69:        return s;
                     70: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>