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