finite_field_wrapper-test.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*############################################################################
  2. # Copyright 2016 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. /*!
  17. * \file
  18. * \brief FiniteField C++ wrapper unit tests.
  19. */
  20. #include "gtest/gtest.h"
  21. #include "epid/common-testhelper/errors-testhelper.h"
  22. #include "epid/common-testhelper/finite_field_wrapper-testhelper.h"
  23. #include "epid/common-testhelper/ffelement_wrapper-testhelper.h"
  24. extern "C" {
  25. #include "epid/common/math/bignum.h"
  26. #include "epid/common/types.h"
  27. }
  28. namespace {
  29. // Use Test Fixture for SetUp and TearDown
  30. class FiniteFieldObjTest : public ::testing::Test {
  31. public:
  32. static const BigNumStr prime_str;
  33. static const FpElemStr ground_str;
  34. };
  35. /// Intel(R) EPID 2.0 parameter p
  36. const BigNumStr FiniteFieldObjTest::prime_str = {
  37. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2,
  38. 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99,
  39. 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D};
  40. const FpElemStr FiniteFieldObjTest::ground_str = {
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44. };
  45. TEST_F(FiniteFieldObjTest, ObjDefaultConstructedIsNotNull) {
  46. FiniteFieldObj ff;
  47. EXPECT_NE(nullptr, (FiniteField*)ff);
  48. }
  49. TEST_F(FiniteFieldObjTest, AssignmentCopiesPointer) {
  50. FiniteFieldObj ff1;
  51. FiniteFieldObj ff2;
  52. EXPECT_NE((FiniteField*)ff1, (FiniteField*)ff2);
  53. ff1 = ff2;
  54. EXPECT_EQ((FiniteField*)ff1, (FiniteField*)ff2);
  55. }
  56. TEST_F(FiniteFieldObjTest, CopyConstructorCopiesPointer) {
  57. FiniteFieldObj ff1;
  58. FiniteFieldObj ff2(ff1);
  59. EXPECT_EQ((FiniteField*)ff1, (FiniteField*)ff2);
  60. }
  61. TEST_F(FiniteFieldObjTest, ConstructorDoesNotThrow) {
  62. FiniteFieldObj ff1;
  63. FiniteFieldObj ff2(this->prime_str);
  64. FfElementObj ffe(&ff2, this->ground_str);
  65. FiniteFieldObj ff3(ff2, ffe, 2);
  66. }
  67. TEST_F(FiniteFieldObjTest, CanCastConstToConstPointer) {
  68. FiniteFieldObj const ff;
  69. FiniteField const* ff_ptr = ff;
  70. (void)ff_ptr;
  71. }
  72. TEST_F(FiniteFieldObjTest, CanGetConstPointerFromConst) {
  73. FiniteFieldObj const ff;
  74. FiniteField const* ff_ptr = ff.getc();
  75. (void)ff_ptr;
  76. }
  77. /*
  78. The following tests are expected to result in
  79. compile time errors (by design)
  80. */
  81. /*
  82. TEST_F(FiniteFieldObjTest, CannotCastConstToNonConstPointer) {
  83. FiniteFieldObj const ff;
  84. FiniteField * ff_ptr = ff;
  85. (void) ff_ptr;
  86. }
  87. TEST_F(FiniteFieldObjTest, CannotGetNonConstPointerFromConst) {
  88. FiniteFieldObj const ff;
  89. FiniteField * ff_ptr = ff.get();
  90. (void) ff_ptr;
  91. }
  92. */
  93. TEST_F(FiniteFieldObjTest, CanCastNonConstToConstPointer) {
  94. FiniteFieldObj ff;
  95. FiniteField const* ff_ptr = ff;
  96. (void)ff_ptr;
  97. }
  98. TEST_F(FiniteFieldObjTest, CanGetConstPointerFromNonConst) {
  99. FiniteFieldObj ff;
  100. FiniteField const* ff_ptr = ff.getc();
  101. (void)ff_ptr;
  102. }
  103. TEST_F(FiniteFieldObjTest, CanCastNonConstToNonConstPointer) {
  104. FiniteFieldObj ff;
  105. FiniteField* ff_ptr = ff;
  106. (void)ff_ptr;
  107. }
  108. TEST_F(FiniteFieldObjTest, CanGetNonConstPointerFromNonConst) {
  109. FiniteFieldObj ff;
  110. FiniteField* ff_ptr = ff.get();
  111. (void)ff_ptr;
  112. }
  113. } // namespace