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() : storage_(), |
| 33 // callback(BuildCallback(this, &MyClass::OnDataReady)) {} |
| 34 // |
| 35 // ~MyClass() {} |
| 36 // |
| 37 // void Write() { |
| 38 // storage_.Put("key", "value"); |
| 39 // } |
| 40 // |
| 41 // void Read() { |
| 42 // storage_.Get("key", *callback_); |
| 43 // } |
| 44 // |
| 45 // private: |
| 46 // void OnDataReady(bool success, |
| 47 // const std::string& key, |
| 48 // const std::string& data) { |
| 49 // ... |
| 50 // } |
| 51 // |
| 52 // FakeStorage storage_; |
| 53 // scoped_ptr<Storage::Callback> callback_; |
| 54 // |
| 55 // DISALLOW_COPY_AND_ASSIGN(MyClass); |
| 56 // }; |
| 57 class FakeStorage : public Storage { |
| 58 public: |
| 59 FakeStorage(); |
| 60 virtual ~FakeStorage(); |
| 61 |
| 62 // Storage implementation. |
| 63 virtual void Put(const std::string& key, const std::string& data); |
| 64 virtual void Get(const std::string& key, const Callback& data_ready) const; |
| 65 |
| 66 private: |
| 67 std::map<std::string, std::string> data_; |
| 68 }; |
| 69 |
| 70 } // namespace addressinput |
| 71 } // namespace i18n |
| 72 |
| 73 #endif // I18N_ADDRESSINPUT_FAKE_STORAGE_H_ |
OLD | NEW |