18466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// Copyright (C) 2014 Google Inc. 28466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 38466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// Licensed under the Apache License, Version 2.0 (the "License"); 48466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// you may not use this file except in compliance with the License. 58466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// You may obtain a copy of the License at 68466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 78466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// http://www.apache.org/licenses/LICENSE-2.0 88466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 98466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// Unless required by applicable law or agreed to in writing, software 108466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// distributed under the License is distributed on an "AS IS" BASIS, 118466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// See the License for the specific language governing permissions and 138466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// limitations under the License. 148466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 158466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// A mock implementation of the Source interface to be used in tests. 168466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 178466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com#ifndef I18N_ADDRESSINPUT_TEST_MOCK_SOURCE_H_ 188466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com#define I18N_ADDRESSINPUT_TEST_MOCK_SOURCE_H_ 198466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 208466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com#include <libaddressinput/source.h> 218466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com#include <libaddressinput/util/basictypes.h> 228466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 238466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com#include <map> 248466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com#include <string> 258466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 268466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.comnamespace i18n { 278466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.comnamespace addressinput { 288466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 298466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// Gets address metadata from a key-value map. Sample usage: 308466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// class MyClass { 318466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// public: 328466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// MyClass() : source_(), 338466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// data_ready_(BuildCallback(this, &MyClass::OnDataReady)) { 348466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// source_.data_.insert( 358466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// std::make_pair("data/XA", "{\"id\":\"data/XA\"}")); 368466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// } 378466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 388466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// ~MyClass() {} 398466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 408466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// void GetData(const std::string& key) { 418466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// source_.Get(key, *data_ready_); 428466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// } 438466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 448466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// private: 458466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// void OnDataReady(bool success, 468466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// const std::string& key, 478466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// std::string* data) { 488466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// ... 498466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// delete data; 508466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// } 518466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 528466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// MockSource source_; 538466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// const scoped_ptr<const Source::Callback> data_ready_; 548466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// 558466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// DISALLOW_COPY_AND_ASSIGN(MyClass); 568466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com// }; 578466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.comclass MockSource : public Source { 588466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com public: 598466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com MockSource(); 608466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com virtual ~MockSource(); 618466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 628466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com // Source implementation. 638466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com virtual void Get(const std::string& key, const Callback& data_ready) const; 648466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 658466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com std::map<std::string, std::string> data_; 668466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 678466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com private: 688466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com DISALLOW_COPY_AND_ASSIGN(MockSource); 698466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com}; 708466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 718466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com} // namespace addressinput 728466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com} // namespace i18n 738466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com 748466869ca5e66ec41d133c8ca2f25789028ef4dfroubert@google.com#endif // I18N_ADDRESSINPUT_TEST_MOCK_SOURCE_H_ 75