aboutsummaryrefslogtreecommitdiff
path: root/epid/common-testhelper/unittests/finite_field_wrapper-test.cc
blob: 1ce59d0c73c74408173fabcf31c1fb7296a15985 (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
/*############################################################################
  # 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 FiniteField C++ wrapper unit tests.
 */

#include "gtest/gtest.h"

#include "epid/common-testhelper/errors-testhelper.h"
#include "epid/common-testhelper/finite_field_wrapper-testhelper.h"
#include "epid/common-testhelper/ffelement_wrapper-testhelper.h"

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

namespace {

// Use Test Fixture for SetUp and TearDown
class FiniteFieldObjTest : public ::testing::Test {
 public:
  static const BigNumStr prime_str;
  static const FpElemStr ground_str;
};

/// Intel(R) EPID 2.0 parameter p
const BigNumStr FiniteFieldObjTest::prime_str = {
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2,
    0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99,
    0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D};

const FpElemStr FiniteFieldObjTest::ground_str = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

TEST_F(FiniteFieldObjTest, ObjDefaultConstructedIsNotNull) {
  FiniteFieldObj ff;
  EXPECT_NE(nullptr, (FiniteField*)ff);
}

TEST_F(FiniteFieldObjTest, AssignmentCopiesPointer) {
  FiniteFieldObj ff1;
  FiniteFieldObj ff2;
  EXPECT_NE((FiniteField*)ff1, (FiniteField*)ff2);
  ff1 = ff2;
  EXPECT_EQ((FiniteField*)ff1, (FiniteField*)ff2);
}

TEST_F(FiniteFieldObjTest, CopyConstructorCopiesPointer) {
  FiniteFieldObj ff1;
  FiniteFieldObj ff2(ff1);
  EXPECT_EQ((FiniteField*)ff1, (FiniteField*)ff2);
}

TEST_F(FiniteFieldObjTest, ConstructorDoesNotThrow) {
  FiniteFieldObj ff1;
  FiniteFieldObj ff2(this->prime_str);
  FfElementObj ffe(&ff2, this->ground_str);
  FiniteFieldObj ff3(ff2, ffe, 2);
}

TEST_F(FiniteFieldObjTest, CanCastConstToConstPointer) {
  FiniteFieldObj const ff;
  FiniteField const* ff_ptr = ff;
  (void)ff_ptr;
}

TEST_F(FiniteFieldObjTest, CanGetConstPointerFromConst) {
  FiniteFieldObj const ff;
  FiniteField const* ff_ptr = ff.getc();
  (void)ff_ptr;
}

/*
The following tests are expected to result in
compile time errors (by design)
*/
/*
TEST_F(FiniteFieldObjTest, CannotCastConstToNonConstPointer) {
  FiniteFieldObj const ff;
  FiniteField * ff_ptr = ff;
  (void) ff_ptr;
}

TEST_F(FiniteFieldObjTest, CannotGetNonConstPointerFromConst) {
  FiniteFieldObj const ff;
  FiniteField * ff_ptr = ff.get();
  (void) ff_ptr;
}
*/

TEST_F(FiniteFieldObjTest, CanCastNonConstToConstPointer) {
  FiniteFieldObj ff;
  FiniteField const* ff_ptr = ff;
  (void)ff_ptr;
}

TEST_F(FiniteFieldObjTest, CanGetConstPointerFromNonConst) {
  FiniteFieldObj ff;
  FiniteField const* ff_ptr = ff.getc();
  (void)ff_ptr;
}

TEST_F(FiniteFieldObjTest, CanCastNonConstToNonConstPointer) {
  FiniteFieldObj ff;
  FiniteField* ff_ptr = ff;
  (void)ff_ptr;
}

TEST_F(FiniteFieldObjTest, CanGetNonConstPointerFromNonConst) {
  FiniteFieldObj ff;
  FiniteField* ff_ptr = ff.get();
  (void)ff_ptr;
}

}  // namespace