Home | History | Annotate | Download | only in unittests
      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 /// TPM Context unit tests.
     17 /*! \file */
     18 
     19 #include <limits.h>
     20 #include <stdint.h>
     21 #include "gtest/gtest.h"
     22 
     23 #include "epid/common-testhelper/epid2params_wrapper-testhelper.h"
     24 #include "epid/member/tpm2/unittests/tpm2-testhelper.h"
     25 
     26 extern "C" {
     27 #include "epid/member/tpm2/context.h"
     28 #include "epid/member/tpm2/getrandom.h"
     29 }
     30 
     31 namespace {
     32 
     33 TEST_F(EpidTpm2Test, GetRandomOnTssReturnsDifferentBufs) {
     34   Epid2ParamsObj epid2params;
     35   Tpm2CtxObj tss(nullptr, nullptr, nullptr, epid2params);
     36   size_t length = 10;
     37   std::vector<uint8_t> buf1(length, (uint8_t)0);
     38   std::vector<uint8_t> buf2(length, (uint8_t)0);
     39   EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tss, length * CHAR_BIT, buf1.data()));
     40   EXPECT_EQ(kEpidNoErr, Tpm2GetRandom(tss, length * CHAR_BIT, buf2.data()));
     41   EXPECT_NE(buf1, buf2);
     42 }
     43 
     44 }  // namespace
     45