]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/tests/suites/test_test_rng.c
identification: Support prefixes in string constructors for an explicit type
[thirdparty/strongswan.git] / src / libstrongswan / tests / suites / test_test_rng.c
1 /*
2 * Copyright (C) 2013 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "test_suite.h"
17
18 #include <tests/utils/test_rng.h>
19 #include <utils/test.h>
20
21 START_TEST(test_test_rng)
22 {
23 rng_t *entropy;
24 chunk_t in, in1, in2, out;
25
26 in1 = chunk_from_chars(0x01, 0x02, 0x03, 0x04, 0x05, 0x06);
27 in2 = chunk_from_chars(0x07, 0x08);
28 in = chunk_cat("cc", in1, in2);
29
30 entropy = test_rng_create(in);
31 ck_assert(entropy->allocate_bytes(entropy, 6, &out));
32 ck_assert(chunk_equals(in1, out));
33 ck_assert(entropy->get_bytes(entropy, 2, out.ptr));
34 ck_assert(memeq(in2.ptr, out.ptr, in2.len));
35 ck_assert(!entropy->get_bytes(entropy, 4, out.ptr));
36 chunk_free(&out);
37 ck_assert(!entropy->allocate_bytes(entropy, 4, &out));
38 entropy->destroy(entropy);
39 chunk_free(&in);
40 }
41 END_TEST
42
43
44 Suite *test_rng_suite_create()
45 {
46 Suite *s;
47 TCase *tc;
48
49 s = suite_create("test_rng");
50
51 tc = tcase_create("test_rng");
52 tcase_add_test(tc, test_test_rng);
53 suite_add_tcase(s, tc);
54
55 return s;
56 }