Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / ocrandom / test / linux / randomtest.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6
7
8 extern "C" {
9     #include "ocrandom.h"
10 }
11
12 #include "gtest/gtest.h"
13 #include "math.h"
14
15 #define ARR_SIZE (20)
16
17 int main(int argc, char* argv[]) {
18     testing::InitGoogleTest(&argc, argv);
19     return RUN_ALL_TESTS();
20 }
21
22 TEST(RandomGeneration,OCSeedRandom) {
23     EXPECT_EQ((uint32_t )0, OCSeedRandom());
24 }
25
26 TEST(RandomGeneration,OCGetRandomByte) {
27     uint8_t value = OCGetRandomByte();
28     EXPECT_LE((uint8_t )0, value);
29     EXPECT_GT(pow(2, 8), value);
30 }
31
32 TEST(RandomGeneration,OCGetRandom) {
33     uint32_t value = OCGetRandom();
34     EXPECT_LE((uint8_t )0, value);
35     EXPECT_GT(pow(2, 32), value);
36 }
37
38 TEST(RandomGeneration,OCFillRandomMem) {
39     uint8_t array[ARR_SIZE];
40     memset(array, 0, ARR_SIZE);
41     OCFillRandomMem(array + 1, ARR_SIZE - 2);
42
43     for (int i = 1; i <= ARR_SIZE - 2; i++) {
44         uint8_t value = array[i];
45         EXPECT_LE((uint8_t )0, value);
46         EXPECT_GT(pow(2, 8), value);
47     }
48     EXPECT_EQ((uint8_t )0, array[0]);
49     EXPECT_EQ((uint8_t )0, array[ARR_SIZE - 1]);
50 }
51