aboutsummaryrefslogtreecommitdiff
path: root/epid/common-testhelper/unittests/bignum_wrapper-test.cc
blob: 83dba24f6b40b7298443b38aece02797507d1880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*############################################################################
  # Copyright 2016 Intel Corporation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  ############################################################################*/

/*!
 * \file
 * \brief Bignum C++ wrapper unit tests.
 */

#include "gtest/gtest.h"

#include "epid/common-testhelper/errors-testhelper.h"
#include "epid/common-testhelper/bignum_wrapper-testhelper.h"

extern "C" {
#include "epid/common/math/bignum.h"
#include "epid/common/src/memory.h"
}

namespace {

// Use Test Fixture for SetUp and TearDown
class BigNumObjTest : public ::testing::Test {
 public:
  static const BigNumStr str_0;
  static const std::vector<unsigned char> vec_0;
};

const BigNumStr BigNumObjTest::str_0 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

const std::vector<unsigned char> BigNumObjTest::vec_0 = {0, 0, 0, 0,
                                                         0, 0, 0, 0};

TEST_F(BigNumObjTest, ObjDefaultConstructedIsNotNull) {
  BigNumObj bn;
  EXPECT_NE(nullptr, (BigNum*)bn);
}

TEST_F(BigNumObjTest, ObjConstructedWithSizeIsNotNull) {
  BigNumObj bn1(1);
  EXPECT_NE(nullptr, (BigNum*)bn1);
  BigNumObj bn32(32);
  EXPECT_NE(nullptr, (BigNum*)bn32);
}

TEST_F(BigNumObjTest, AssignmentDoesNotCopyPointer) {
  BigNumObj bn1;
  BigNumObj bn2;
  EXPECT_NE((BigNum*)bn1, (BigNum*)bn2);
  bn1 = bn2;
  EXPECT_NE((BigNum*)bn1, (BigNum*)bn2);
}

TEST_F(BigNumObjTest, CopyConstructorDoesNotCopyPointer) {
  BigNumObj bn1;
  BigNumObj bn2(bn1);
  EXPECT_NE((BigNum*)bn1, (BigNum*)bn2);
}

TEST_F(BigNumObjTest, ConstructorDoesNotThrow) {
  BigNumObj bn1;
  BigNumObj bn2(32);
  BigNumObj bn3(32, this->str_0);
  BigNumObj bn4(32, this->vec_0);
  BigNumObj bn5(this->str_0);
  BigNumObj bn6(this->vec_0);

  EXPECT_NE((BigNum*)bn1, (BigNum*)bn2);
  EXPECT_NE((BigNum*)bn1, (BigNum*)bn3);
  EXPECT_NE((BigNum*)bn1, (BigNum*)bn4);
  EXPECT_NE((BigNum*)bn1, (BigNum*)bn5);
  EXPECT_NE((BigNum*)bn1, (BigNum*)bn6);

  EXPECT_NE((BigNum*)bn2, (BigNum*)bn1);
  EXPECT_NE((BigNum*)bn2, (BigNum*)bn3);
  EXPECT_NE((BigNum*)bn2, (BigNum*)bn4);
  EXPECT_NE((BigNum*)bn2, (BigNum*)bn5);
  EXPECT_NE((BigNum*)bn2, (BigNum*)bn6);

  EXPECT_NE((BigNum*)bn3, (BigNum*)bn1);
  EXPECT_NE((BigNum*)bn3, (BigNum*)bn2);
  EXPECT_NE((BigNum*)bn3, (BigNum*)bn4);
  EXPECT_NE((BigNum*)bn3, (BigNum*)bn5);
  EXPECT_NE((BigNum*)bn3, (BigNum*)bn6);

  EXPECT_NE((BigNum*)bn4, (BigNum*)bn1);
  EXPECT_NE((BigNum*)bn4, (BigNum*)bn2);
  EXPECT_NE((BigNum*)bn4, (BigNum*)bn3);
  EXPECT_NE((BigNum*)bn4, (BigNum*)bn5);
  EXPECT_NE((BigNum*)bn4, (BigNum*)bn6);

  EXPECT_NE((BigNum*)bn5, (BigNum*)bn1);
  EXPECT_NE((BigNum*)bn5, (BigNum*)bn2);
  EXPECT_NE((BigNum*)bn5, (BigNum*)bn3);
  EXPECT_NE((BigNum*)bn5, (BigNum*)bn4);
  EXPECT_NE((BigNum*)bn5, (BigNum*)bn6);

  EXPECT_NE((BigNum*)bn6, (BigNum*)bn1);
  EXPECT_NE((BigNum*)bn6, (BigNum*)bn2);
  EXPECT_NE((BigNum*)bn6, (BigNum*)bn3);
  EXPECT_NE((BigNum*)bn6, (BigNum*)bn4);
  EXPECT_NE((BigNum*)bn6, (BigNum*)bn5);
}

TEST_F(BigNumObjTest, CanCastConstToConstPointer) {
  BigNumObj const bn;
  BigNum const* bn_ptr = bn;
  (void)bn_ptr;
}

TEST_F(BigNumObjTest, CanGetConstPointerFromConst) {
  BigNumObj const bn;
  BigNum const* bn_ptr = bn.getc();
  (void)bn_ptr;
}

/*
The following tests are expected to result in
compile time errors (by design)
*/
/*
TEST_F(BigNumObjTest, CannotCastConstToNonConstPointer) {
  BigNumObj const bn;
  BigNum * bn_ptr = bn;
  (void) bn_ptr;
}

TEST_F(BigNumObjTest, CannotGetNonConstPointerFromConst) {
  BigNumObj const bn;
  BigNum * bn_ptr = bn.get();
  (void) bn_ptr;
}
*/

TEST_F(BigNumObjTest, CanCastNonConstToConstPointer) {
  BigNumObj bn;
  BigNum const* bn_ptr = bn;
  (void)bn_ptr;
}

TEST_F(BigNumObjTest, CanGetConstPointerFromNonConst) {
  BigNumObj bn;
  BigNum const* bn_ptr = bn.getc();
  (void)bn_ptr;
}

TEST_F(BigNumObjTest, CanCastNonConstToNonConstPointer) {
  BigNumObj bn;
  BigNum* bn_ptr = bn;
  (void)bn_ptr;
}

TEST_F(BigNumObjTest, CanGetNonConstPointerFromNonConst) {
  BigNumObj bn;
  BigNum* bn_ptr = bn.get();
  (void)bn_ptr;
}

}  // namespace