createprimary-test.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. /// TPM2_CreatePrimary unit tests.
  17. /*! \file */
  18. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  19. #include "gtest/gtest.h"
  20. #include "epid/common-testhelper/epid2params_wrapper-testhelper.h"
  21. #include "epid/common-testhelper/errors-testhelper.h"
  22. #include "epid/common-testhelper/prng-testhelper.h"
  23. #include "epid/member/tpm2/unittests/tpm2-testhelper.h"
  24. extern "C" {
  25. #include "epid/member/tpm2/createprimary.h"
  26. }
  27. namespace {
  28. TEST_F(EpidTpm2Test, CreatePrimaryFailsGivenNullParameters) {
  29. Epid2ParamsObj epid2params;
  30. Tpm2CtxObj tss(nullptr, nullptr, nullptr, epid2params);
  31. G1ElemStr res = {0};
  32. EXPECT_EQ(kEpidBadArgErr, Tpm2CreatePrimary(tss, nullptr));
  33. EXPECT_EQ(kEpidBadArgErr, Tpm2CreatePrimary(nullptr, &res));
  34. }
  35. TEST_F(EpidTpm2Test, CreatePrimaryWorksGivenValidParameter) {
  36. Prng prng;
  37. Epid2ParamsObj epid2params;
  38. Tpm2CtxObj tss(Prng::Generate, &prng, nullptr, epid2params);
  39. G1ElemStr res = {0};
  40. THROW_ON_EPIDERR(Tpm2SetHashAlg(tss, kSha256));
  41. EXPECT_EQ(kEpidNoErr, Tpm2CreatePrimary(tss, &res));
  42. }
  43. } // namespace