OLD | NEW |
| (Empty) |
1 // Copyright (C) 2013 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // | |
15 // A fake storage object to use in tests. Stores data in memory instead of | |
16 // writing it to disk. All operations are synchronous. | |
17 | |
18 #ifndef I18N_ADDRESSINPUT_FAKE_STORAGE_H_ | |
19 #define I18N_ADDRESSINPUT_FAKE_STORAGE_H_ | |
20 | |
21 #include <libaddressinput/storage.h> | |
22 | |
23 #include <map> | |
24 #include <string> | |
25 | |
26 namespace i18n { | |
27 namespace addressinput { | |
28 | |
29 // Stores data in memory. Sample usage: | |
30 // class MyClass { | |
31 // public: | |
32 // MyClass() {} | |
33 // | |
34 // ~MyClass() {} | |
35 // | |
36 // void Write() { | |
37 // storage_.Put("key", make_scoped_ptr(new std::string("value"))); | |
38 // } | |
39 // | |
40 // void Read() { | |
41 // storage_.Get("key", BuildCallback(this, &Myclass:OnDataReady)); | |
42 // } | |
43 // | |
44 // private: | |
45 // void OnDataReady(bool success, | |
46 // const std::string& key, | |
47 // const std::string& data) { | |
48 // ... | |
49 // } | |
50 // | |
51 // FakeStorage storage_; | |
52 // | |
53 // DISALLOW_COPY_AND_ASSIGN(MyClass); | |
54 // }; | |
55 class FakeStorage : public Storage { | |
56 public: | |
57 FakeStorage(); | |
58 virtual ~FakeStorage(); | |
59 | |
60 // Storage implementation. | |
61 virtual void Put(const std::string& key, scoped_ptr<std::string> data); | |
62 virtual void Get(const std::string& key, scoped_ptr<Callback> data_ready) | |
63 const; | |
64 | |
65 std::string SynchronousGet(const std::string& key) const; | |
66 | |
67 private: | |
68 std::map<std::string, std::string> data_; | |
69 }; | |
70 | |
71 } // namespace addressinput | |
72 } // namespace i18n | |
73 | |
74 #endif // I18N_ADDRESSINPUT_FAKE_STORAGE_H_ | |
OLD | NEW |