ecpoint_wrapper-test.cc 4.1 KB

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