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 downloader object to use in tests. Reads data from a file instead of |
| 16 // downloading it from a server. |
| 17 |
| 18 #ifndef I18N_ADDRESSINPUT_TEST_FAKE_DOWNLOADER_H_ |
| 19 #define I18N_ADDRESSINPUT_TEST_FAKE_DOWNLOADER_H_ |
| 20 |
| 21 #include <libaddressinput/downloader.h> |
| 22 |
| 23 #include <string> |
| 24 |
| 25 namespace i18n { |
| 26 namespace addressinput { |
| 27 |
| 28 // "Downloads" serialized validation rules from a test data file. Sample usage: |
| 29 // class MyClass { |
| 30 // public: |
| 31 // MyClass() : downloader_(), |
| 32 // callback_(BuildCallback(this, &MyClass::OnDownloaded)) {} |
| 33 // |
| 34 // ~MyClass() {} |
| 35 // |
| 36 // void GetData(const std::string& key) { |
| 37 // downloader_.Download(std::string(FakeDownloader::kFakeDataUrl) + key, |
| 38 // *callback_); |
| 39 // } |
| 40 // |
| 41 // private: |
| 42 // void OnDownloaded(bool success, |
| 43 // const std::string& url, |
| 44 // const std::string& data) { |
| 45 // ... |
| 46 // } |
| 47 // |
| 48 // FakeDownloader downloader_; |
| 49 // scoped_ptr<Downloader::Callback> callback_; |
| 50 // |
| 51 // DISALLOW_COPY_AND_ASSIGN(MyClass); |
| 52 // }; |
| 53 class FakeDownloader : public Downloader { |
| 54 public: |
| 55 // The fake data URL to be used in tests. |
| 56 static const char kFakeDataUrl[]; |
| 57 |
| 58 FakeDownloader(); |
| 59 virtual ~FakeDownloader(); |
| 60 |
| 61 // Downloader implementation. |
| 62 virtual void Download(const std::string& url, |
| 63 const Callback& downloaded) const; |
| 64 }; |
| 65 |
| 66 } // namespace addressinput |
| 67 } // namespace i18n |
| 68 |
| 69 #endif // I18N_ADDRESSINPUT_TEST_FAKE_DOWNLOADER_H_ |
OLD | NEW |