]>
git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/tests/suites/test_test_rng.c
2 * Copyright (C) 2013 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
16 #include "test_suite.h"
18 #include <tests/utils/test_rng.h>
19 #include <utils/test.h>
21 START_TEST(test_test_rng
)
24 chunk_t in
, in1
, in2
, out
;
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
);
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
));
37 ck_assert(!entropy
->allocate_bytes(entropy
, 4, &out
));
38 entropy
->destroy(entropy
);
44 Suite
*test_rng_suite_create()
49 s
= suite_create("test_rng");
51 tc
= tcase_create("test_rng");
52 tcase_add_test(tc
, test_test_rng
);
53 suite_add_tcase(s
, tc
);