1 // Copyright 2015 The Weave Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef LIBWEAVE_INCLUDE_WEAVE_PROVIDER_TEST_MOCK_CONFIG_STORE_H_ 6 #define LIBWEAVE_INCLUDE_WEAVE_PROVIDER_TEST_MOCK_CONFIG_STORE_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 #include <gmock/gmock.h> 13 #include <weave/provider/config_store.h> 14 15 namespace weave { 16 namespace provider { 17 namespace test { 18 19 class MockConfigStore : public ConfigStore { 20 public: 21 explicit MockConfigStore(bool set_expectations = true) { 22 using testing::_; 23 using testing::Return; 24 25 if (!set_expectations) 26 return; 27 28 EXPECT_CALL(*this, LoadDefaults(_)) 29 .WillRepeatedly(testing::Invoke([](Settings* settings) { 30 settings->firmware_version = "TEST_FIRMWARE"; 31 settings->oem_name = "TEST_OEM"; 32 settings->model_name = "TEST_MODEL"; 33 settings->model_id = "ABCDE"; 34 settings->name = "TEST_NAME"; 35 settings->client_id = "TEST_CLIENT_ID"; 36 settings->client_secret = "TEST_CLIENT_SECRET"; 37 settings->api_key = "TEST_API_KEY"; 38 return true; 39 })); 40 EXPECT_CALL(*this, LoadSettings()) 41 .WillRepeatedly(Return(R"({ 42 "version": 1, 43 "device_id": "TEST_DEVICE_ID" 44 })")); 45 EXPECT_CALL(*this, LoadSettings(_)).WillRepeatedly(Return("")); 46 EXPECT_CALL(*this, SaveSettings(_, _, _)) 47 .WillRepeatedly(testing::WithArgs<1, 2>(testing::Invoke( 48 [](const std::string& json, const DoneCallback& callback) { 49 if (!callback.is_null()) 50 callback.Run(nullptr); 51 }))); 52 } 53 MOCK_METHOD1(LoadDefaults, bool(Settings*)); 54 MOCK_METHOD1(LoadSettings, std::string(const std::string&)); 55 MOCK_METHOD3(SaveSettings, 56 void(const std::string&, 57 const std::string&, 58 const DoneCallback&)); 59 MOCK_METHOD0(LoadSettings, std::string()); 60 }; 61 62 } // namespace test 63 } // namespace provider 64 } // namespace weave 65 66 #endif // LIBWEAVE_INCLUDE_WEAVE_PROVIDER_TEST_MOCK_CONFIG_STORE_H_ 67