finite_field_wrapper-test.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*############################################################################
  2. # Copyright 2016-2017 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 "epid/common-testhelper/epid_gtest-testhelper.h"
  21. #include "gtest/gtest.h"
  22. #include "epid/common-testhelper/errors-testhelper.h"
  23. #include "epid/common-testhelper/ffelement_wrapper-testhelper.h"
  24. #include "epid/common-testhelper/finite_field_wrapper-testhelper.h"
  25. extern "C" {
  26. #include "epid/common/math/bignum.h"
  27. #include "epid/common/types.h"
  28. }
  29. namespace {
  30. // Use Test Fixture for SetUp and TearDown
  31. class FiniteFieldObjTest : public ::testing::Test {
  32. public:
  33. static const BigNumStr prime_str;
  34. static const FpElemStr ground_str;
  35. };
  36. /// Intel(R) EPID 2.0 parameter p
  37. const BigNumStr FiniteFieldObjTest::prime_str = {
  38. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xCD, 0x46, 0xE5, 0xF2,
  39. 0x5E, 0xEE, 0x71, 0xA4, 0x9E, 0x0C, 0xDC, 0x65, 0xFB, 0x12, 0x99,
  40. 0x92, 0x1A, 0xF6, 0x2D, 0x53, 0x6C, 0xD1, 0x0B, 0x50, 0x0D};
  41. const FpElemStr FiniteFieldObjTest::ground_str = {
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. };
  46. TEST_F(FiniteFieldObjTest, ObjDefaultConstructedIsNotNull) {
  47. FiniteFieldObj ff;
  48. EXPECT_NE(nullptr, (FiniteField*)ff);
  49. }
  50. TEST_F(FiniteFieldObjTest, AssignmentCopiesPointer) {
  51. FiniteFieldObj ff1;
  52. FiniteFieldObj ff2;
  53. EXPECT_NE((FiniteField*)ff1, (FiniteField*)ff2);
  54. ff1 = ff2;
  55. EXPECT_EQ((FiniteField*)ff1, (FiniteField*)ff2);
  56. }
  57. TEST_F(FiniteFieldObjTest, CopyConstructorCopiesPointer) {
  58. FiniteFieldObj ff1;
  59. FiniteFieldObj ff2(ff1);
  60. EXPECT_EQ((FiniteField*)ff1, (FiniteField*)ff2);
  61. }
  62. TEST_F(FiniteFieldObjTest, ConstructorDoesNotThrow) {
  63. FiniteFieldObj ff1;
  64. FiniteFieldObj ff2(this->prime_str);
  65. FfElementObj ffe(&ff2, this->ground_str);
  66. FiniteFieldObj ff3(ff2, ffe, 2);
  67. }
  68. TEST_F(FiniteFieldObjTest, CanCastConstToConstPointer) {
  69. FiniteFieldObj const ff;
  70. FiniteField const* ff_ptr = ff;
  71. (void)ff_ptr;
  72. }
  73. TEST_F(FiniteFieldObjTest, CanGetConstPointerFromConst) {
  74. FiniteFieldObj const ff;
  75. FiniteField const* ff_ptr = ff.getc();
  76. (void)ff_ptr;
  77. }
  78. /*
  79. The following tests are expected to result in
  80. compile time errors (by design)
  81. */
  82. /*
  83. TEST_F(FiniteFieldObjTest, CannotCastConstToNonConstPointer) {
  84. FiniteFieldObj const ff;
  85. FiniteField * ff_ptr = ff;
  86. (void) ff_ptr;
  87. }
  88. TEST_F(FiniteFieldObjTest, CannotGetNonConstPointerFromConst) {
  89. FiniteFieldObj const ff;
  90. FiniteField * ff_ptr = ff.get();
  91. (void) ff_ptr;
  92. }
  93. */
  94. TEST_F(FiniteFieldObjTest, CanCastNonConstToConstPointer) {
  95. FiniteFieldObj ff;
  96. FiniteField const* ff_ptr = ff;
  97. (void)ff_ptr;
  98. }
  99. TEST_F(FiniteFieldObjTest, CanGetConstPointerFromNonConst) {
  100. FiniteFieldObj ff;
  101. FiniteField const* ff_ptr = ff.getc();
  102. (void)ff_ptr;
  103. }
  104. TEST_F(FiniteFieldObjTest, CanCastNonConstToNonConstPointer) {
  105. FiniteFieldObj ff;
  106. FiniteField* ff_ptr = ff;
  107. (void)ff_ptr;
  108. }
  109. TEST_F(FiniteFieldObjTest, CanGetNonConstPointerFromNonConst) {
  110. FiniteFieldObj ff;
  111. FiniteField* ff_ptr = ff.get();
  112. (void)ff_ptr;
  113. }
  114. } // namespace