ecpoint_wrapper-test.cc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 EcPoint C++ wrapper unit tests.
  19. */
  20. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  21. #include "gtest/gtest.h"
  22. #include "epid/common-testhelper/ecgroup_wrapper-testhelper.h"
  23. #include "epid/common-testhelper/ecpoint_wrapper-testhelper.h"
  24. #include "epid/common-testhelper/errors-testhelper.h"
  25. extern "C" {
  26. #include "epid/common/math/bignum.h"
  27. }
  28. namespace {
  29. // Use Test Fixture for SetUp and TearDown
  30. class EcPointObjTest : public ::testing::Test {
  31. public:
  32. static EcGroupObj group;
  33. static const G1ElemStr group_str_1;
  34. static const G1ElemStr group_str_2;
  35. };
  36. const G1ElemStr EcPointObjTest::group_str_1 = {
  37. {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D,
  38. 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A,
  39. 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}},
  40. {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F,
  41. 0x30, 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96,
  42. 0xF7, 0xCD, 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}};
  43. const G1ElemStr EcPointObjTest::group_str_2 = {
  44. {{{0xE6, 0x65, 0x23, 0x9B, 0xD4, 0x07, 0x16, 0x83, 0x38, 0x23, 0xB2,
  45. 0x67, 0x57, 0xEB, 0x0F, 0x23, 0x3A, 0xF4, 0x8E, 0xDA, 0x71, 0x5E,
  46. 0xD9, 0x98, 0x63, 0x98, 0x2B, 0xBC, 0x78, 0xD1, 0x94, 0xF2}}},
  47. {{{0x63, 0xB0, 0xAD, 0xB8, 0x2C, 0xE8, 0x14, 0xFD, 0xA2, 0x39, 0x0E,
  48. 0x66, 0xB7, 0xD0, 0x6A, 0xAB, 0xEE, 0xFA, 0x2E, 0x24, 0x9B, 0xB5,
  49. 0x14, 0x35, 0xFE, 0xB6, 0xB0, 0xFF, 0xFD, 0x5F, 0x73, 0x19}}}};
  50. EcGroupObj EcPointObjTest::group;
  51. TEST_F(EcPointObjTest, ObjDefaultConstructedIsNotNull) {
  52. EcPointObj point(&group);
  53. EXPECT_NE(nullptr, (EcPoint*)point);
  54. }
  55. TEST_F(EcPointObjTest, AssignmentDoesNotCopyPointer) {
  56. EcPointObj point1(&group, group_str_1);
  57. EcPointObj point2(&group, group_str_2);
  58. EXPECT_NE((EcPoint*)point1, (EcPoint*)point2);
  59. point1 = point2;
  60. EXPECT_NE((EcPoint*)point1, (EcPoint*)point2);
  61. }
  62. TEST_F(EcPointObjTest, CopyConstructorDoesNotCopyPointer) {
  63. EcPointObj point1(&group, group_str_1);
  64. EcPointObj point2(point1);
  65. EXPECT_NE((EcPoint*)point1, (EcPoint*)point2);
  66. }
  67. TEST_F(EcPointObjTest, CanCastConstToConstPointer) {
  68. EcPointObj const point(&group);
  69. EcPoint const* point_ptr = point;
  70. (void)point_ptr;
  71. }
  72. TEST_F(EcPointObjTest, CanGetConstPointerFromConst) {
  73. EcPointObj const point(&group);
  74. EcPoint const* point_ptr = point.getc();
  75. (void)point_ptr;
  76. }
  77. /*
  78. The following tests are expected to result in
  79. compile time errors (by design)
  80. */
  81. /*
  82. TEST_F(EcPointObjTest, CannotCastConstToNonConstPointer) {
  83. EcPointObj const point(&group);
  84. EcPoint * point_ptr = point;
  85. (void) point_ptr;
  86. }
  87. TEST_F(EcPointObjTest, CannotGetNonConstPointerFromConst) {
  88. EcPointObj const point(&group);
  89. EcPoint * point_ptr = point.get();
  90. (void) point_ptr;
  91. }
  92. */
  93. TEST_F(EcPointObjTest, CanCastNonConstToConstPointer) {
  94. EcPointObj point(&group);
  95. EcPoint const* point_ptr = point;
  96. (void)point_ptr;
  97. }
  98. TEST_F(EcPointObjTest, CanGetConstPointerFromNonConst) {
  99. EcPointObj point(&group);
  100. EcPoint const* point_ptr = point.getc();
  101. (void)point_ptr;
  102. }
  103. TEST_F(EcPointObjTest, CanCastNonConstToNonConstPointer) {
  104. EcPointObj point(&group);
  105. EcPoint* point_ptr = point;
  106. (void)point_ptr;
  107. }
  108. TEST_F(EcPointObjTest, CanGetNonConstPointerFromNonConst) {
  109. EcPointObj point(&group);
  110. EcPoint* point_ptr = point.get();
  111. (void)point_ptr;
  112. }
  113. } // namespace