Home | History | Annotate | Download | only in server
      1 //
      2 // Copyright (C) 2015 The Android Open Source Project
      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 #ifndef TPM_MANAGER_SERVER_MOCK_TPM_NVRAM_H_
     18 #define TPM_MANAGER_SERVER_MOCK_TPM_NVRAM_H_
     19 
     20 #include "tpm_manager/server/tpm_nvram.h"
     21 
     22 #include <map>
     23 #include <string>
     24 
     25 #include <gmock/gmock.h>
     26 
     27 namespace tpm_manager {
     28 
     29 struct NvSpace {
     30   std::string data;
     31   bool written;
     32 };
     33 
     34 class MockTpmNvram : public TpmNvram {
     35  public:
     36   MockTpmNvram();
     37   ~MockTpmNvram() override;
     38 
     39   MOCK_METHOD2(DefineNvram, bool(uint32_t, size_t));
     40   MOCK_METHOD1(DestroyNvram, bool(uint32_t));
     41   MOCK_METHOD2(WriteNvram, bool(uint32_t, const std::string&));
     42   MOCK_METHOD2(ReadNvram, bool(uint32_t, std::string*));
     43   MOCK_METHOD2(IsNvramDefined, bool(uint32_t, bool*));
     44   MOCK_METHOD2(IsNvramLocked, bool(uint32_t, bool*));
     45   MOCK_METHOD2(GetNvramSize, bool(uint32_t, size_t*));
     46 
     47  private:
     48   bool FakeDefineNvram(uint32_t index, size_t length);
     49   bool FakeDestroyNvram(uint32_t index);
     50   bool FakeWriteNvram(uint32_t index, const std::string& data);
     51   bool FakeReadNvram(uint32_t index, std::string* data);
     52   bool FakeIsNvramDefined(uint32_t index, bool* defined);
     53   bool FakeIsNvramLocked(uint32_t index, bool* locked);
     54   bool FakeGetNvramSize(uint32_t index, size_t* size);
     55 
     56   std::map<uint32_t, NvSpace> nvram_map_;
     57 };
     58 
     59 }  // namespace tpm_manager
     60 
     61 #endif  // TPM_MANAGER_SERVER_MOCK_TPM_NVRAM_H_
     62