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// An implementation of the Source interface, that reads address metadata from a 16// text file, to be used in tests. 17 18#ifndef I18N_ADDRESSINPUT_TEST_TESTDATA_SOURCE_H_ 19#define I18N_ADDRESSINPUT_TEST_TESTDATA_SOURCE_H_ 20 21#include <libaddressinput/source.h> 22#include <libaddressinput/util/basictypes.h> 23 24#include <string> 25 26namespace i18n { 27namespace addressinput { 28 29// Gets address metadata from a text file. Sample usage: 30// class MyClass { 31// public: 32// MyClass() : source_(), 33// data_ready_(BuildCallback(this, &MyClass::OnDataReady)) {} 34// 35// ~MyClass() {} 36// 37// void GetData(const std::string& key) { 38// source_.Get(key, *data_ready_); 39// } 40// 41// private: 42// void OnDataReady(bool success, 43// const std::string& key, 44// std::string* data) { 45// ... 46// delete data; 47// } 48// 49// TestdataSource source_; 50// const scoped_ptr<const Source::Callback> data_ready_; 51// 52// DISALLOW_COPY_AND_ASSIGN(MyClass); 53// }; 54class TestdataSource : public Source { 55 public: 56 // Will return aggregate data if |aggregate| is set to true. 57 explicit TestdataSource(bool aggregate); 58 virtual ~TestdataSource(); 59 60 // Source implementation. 61 virtual void Get(const std::string& key, const Callback& data_ready) const; 62 63 private: 64 const bool aggregate_; 65 DISALLOW_COPY_AND_ASSIGN(TestdataSource); 66}; 67 68} // namespace addressinput 69} // namespace i18n 70 71#endif // I18N_ADDRESSINPUT_TEST_TESTDATA_SOURCE_H_ 72