1 // Copyright (C) 2010-2015 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 
11 #include <gtest/gtest.h>
12 #include <vector>
13 
14 #include <util/range_utilities.h>
15 
16 using namespace std;
17 using namespace isc::util;
18 
TEST(RangeUtilitiesTest,isZero)19 TEST(RangeUtilitiesTest, isZero) {
20 
21     vector<uint8_t> vec(32,0);
22 
23     EXPECT_TRUE(isRangeZero(vec.begin(), vec.end()));
24 
25     EXPECT_TRUE(isRangeZero(vec.begin(), vec.begin()+1));
26 
27     vec[5] = 1;
28     EXPECT_TRUE(isRangeZero(vec.begin(), vec.begin()+5));
29     EXPECT_FALSE(isRangeZero(vec.begin(), vec.begin()+6));
30 }
31 
TEST(RangeUtilitiesTest,randomFill)32 TEST(RangeUtilitiesTest, randomFill) {
33 
34     srandom(time(NULL));
35 
36     vector<uint8_t> vec1(16,0);
37     vector<uint8_t> vec2(16,0);
38 
39     // Testing if returned value is actually random is extraordinary difficult.
40     // Let's just generate bunch of vectors and see if we get the same
41     // value. If we manage to do that in 100 tries, pseudo-random generator
42     // really sucks.
43     fillRandom(vec1.begin(), vec1.end());
44     for (int i=0; i<100; i++) {
45         fillRandom(vec2.begin(), vec2.end());
46         if (vec1 == vec2)
47             FAIL();
48     }
49 
50 }
51