aboutsummaryrefslogtreecommitdiff
path: root/include/weave/provider/test/mock_config_store.h
blob: a7eb374306c9a466e389a936d056224c6b49e950 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2015 The Weave Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef LIBWEAVE_INCLUDE_WEAVE_PROVIDER_TEST_MOCK_CONFIG_STORE_H_
#define LIBWEAVE_INCLUDE_WEAVE_PROVIDER_TEST_MOCK_CONFIG_STORE_H_

#include <map>
#include <string>
#include <vector>

#include <gmock/gmock.h>
#include <weave/provider/config_store.h>

namespace weave {
namespace provider {
namespace test {

class MockConfigStore : public ConfigStore {
 public:
  explicit MockConfigStore(bool set_expectations = true) {
    using testing::_;
    using testing::Return;

    if (!set_expectations)
      return;

    EXPECT_CALL(*this, LoadDefaults(_))
        .WillRepeatedly(testing::Invoke([](Settings* settings) {
          settings->firmware_version = "TEST_FIRMWARE";
          settings->oem_name = "TEST_OEM";
          settings->model_name = "TEST_MODEL";
          settings->model_id = "ABCDE";
          settings->name = "TEST_NAME";
          settings->client_id = "TEST_CLIENT_ID";
          settings->client_secret = "TEST_CLIENT_SECRET";
          settings->api_key = "TEST_API_KEY";
          return true;
        }));
    EXPECT_CALL(*this, LoadSettings())
        .WillRepeatedly(Return(R"({
          "version": 1,
          "device_id": "TEST_DEVICE_ID"
        })"));
    EXPECT_CALL(*this, LoadSettings(_)).WillRepeatedly(Return(""));
    EXPECT_CALL(*this, SaveSettings(_, _, _))
        .WillRepeatedly(testing::WithArgs<1, 2>(testing::Invoke(
            [](const std::string& json, const DoneCallback& callback) {
              if (!callback.is_null())
                callback.Run(nullptr);
            })));
  }
  MOCK_METHOD1(LoadDefaults, bool(Settings*));
  MOCK_METHOD1(LoadSettings, std::string(const std::string&));
  MOCK_METHOD3(SaveSettings,
               void(const std::string&,
                    const std::string&,
                    const DoneCallback&));
  MOCK_METHOD0(LoadSettings, std::string());
};

}  // namespace test
}  // namespace provider
}  // namespace weave

#endif  // LIBWEAVE_INCLUDE_WEAVE_PROVIDER_TEST_MOCK_CONFIG_STORE_H_