1 // Copyright (C) 2014 Google Inc.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 // A mock downloader object to use in tests.
17 #ifndef I18N_ADDRESSINPUT_TEST_MOCK_DOWNLOADER_H_
18 #define I18N_ADDRESSINPUT_TEST_MOCK_DOWNLOADER_H_
20 #include <libaddressinput/downloader.h>
25 #include <libaddressinput/util/basictypes.h>
28 namespace addressinput {
30 // "Downloads" serialized validation rules from a key-value map. Sample usage:
33 // MyClass() : downloader_(),
34 // callback_(BuildCallback(this, &MyClass::OnDownloaded)) {
35 // downloader_.data_.insert(
36 // std::make_pair("data/XA", "{\"id\":\"data/XA\"}"));
41 // void GetData(const std::string& key) {
42 // downloader_.Download(std::string(MockDownloader::kMockDataUrl) + key,
47 // void OnDownloaded(bool success,
48 // const std::string& url,
49 // std::string* data) {
54 // MockDownloader downloader_;
55 // const scoped_ptr<const Downloader::Callback> callback_;
57 // DISALLOW_COPY_AND_ASSIGN(MyClass);
59 class MockDownloader : public Downloader {
61 // The mock data URL to be used in tests.
62 static const char kMockDataUrl[];
65 virtual ~MockDownloader();
67 // Downloader implementation.
68 virtual void Download(const std::string& url,
69 const Callback& downloaded) const;
71 std::map<std::string, std::string> data_;
74 DISALLOW_COPY_AND_ASSIGN(MockDownloader);
77 } // namespace addressinput
80 #endif // I18N_ADDRESSINPUT_TEST_MOCK_DOWNLOADER_H_