resize-test.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*############################################################################
  2. # Copyright 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. /// ResizeOctStr unit tests.
  17. /*! \file */
  18. #include <vector>
  19. #include "gtest/gtest.h"
  20. extern "C" {
  21. #include "epid/member/src/resize.h"
  22. }
  23. #include "epid/common-testhelper/errors-testhelper.h"
  24. namespace {
  25. TEST(ResizeOctStr, FailsGivenNullPointer) {
  26. uint8_t a[3] = {0, 1, 2};
  27. uint8_t r[3] = {0};
  28. EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(nullptr, sizeof(a), r, sizeof(r)));
  29. EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(a, sizeof(a), nullptr, sizeof(r)));
  30. }
  31. TEST(ResizeOctStr, FailsGivenInvalidSize) {
  32. uint8_t a[3] = {0, 1, 2};
  33. uint8_t r[3] = {0};
  34. EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(a, 0, r, sizeof(r)));
  35. EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(a, sizeof(a), r, 0));
  36. }
  37. TEST(ResizeOctStr, FailsGivenResultIsTooSmall) {
  38. uint8_t a[3] = {0, 1, 2};
  39. uint8_t r[1] = {0};
  40. EXPECT_EQ(kEpidBadArgErr, ResizeOctStr(a, sizeof(a), r, sizeof(r)));
  41. }
  42. TEST(ResizeOctStr, CanShrink) {
  43. uint8_t a[3] = {0, 1, 2};
  44. std::vector<uint8_t> r(2);
  45. std::vector<uint8_t> r_expected = {1, 2};
  46. EXPECT_EQ(kEpidNoErr, ResizeOctStr(a, sizeof(a), r.data(), r.size()));
  47. EXPECT_EQ(r_expected, r);
  48. }
  49. TEST(ResizeOctStr, CanExtend) {
  50. uint8_t a[3] = {0, 1, 2};
  51. std::vector<uint8_t> r(5);
  52. std::vector<uint8_t> r_expected = {0, 0, 0, 1, 2};
  53. EXPECT_EQ(kEpidNoErr, ResizeOctStr(a, sizeof(a), r.data(), r.size()));
  54. EXPECT_EQ(r_expected, r);
  55. }
  56. } // namespace