1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chromeos/dbus/ibus/mock_ibus_engine_service.h" 6 7 #include "chromeos/dbus/ibus/ibus_text.h" 8 9 namespace chromeos { 10 11 MockIBusEngineService::MockIBusEngineService() 12 : register_properties_call_count_(0), 13 update_preedit_call_count_(0), 14 update_auxiliary_text_call_count_(0), 15 update_lookup_table_call_count_(0), 16 update_property_call_count_(0), 17 forward_key_event_call_count_(0), 18 commit_text_call_count_(0), 19 delete_surrounding_text_call_count_(0), 20 last_update_preedit_arg_(new UpdatePreeditArg()), 21 last_update_aux_text_arg_(new UpdateAuxiliaryTextArg()), 22 last_update_lookup_table_arg_(new UpdateLookupTableArg()), 23 last_registered_properties_(new IBusPropertyList()), 24 last_updated_property_(new IBusProperty()), 25 last_delete_surrounding_text_arg_(new DeleteSurroundingTextArg()), 26 current_engine_(NULL) { 27 } 28 29 MockIBusEngineService::~MockIBusEngineService() { 30 } 31 32 void MockIBusEngineService::SetEngine(IBusEngineHandlerInterface* handler) { 33 current_engine_ = handler; 34 } 35 36 void MockIBusEngineService::UnsetEngine(IBusEngineHandlerInterface* handler) { 37 current_engine_ = NULL; 38 } 39 40 void MockIBusEngineService::RegisterProperties( 41 const IBusPropertyList& property_list) { 42 ++register_properties_call_count_; 43 last_registered_properties_->resize(property_list.size()); 44 for (size_t i = 0; i < property_list.size(); ++i) { 45 (*last_registered_properties_)[i] = new IBusProperty(); 46 (*last_registered_properties_)[i]->CopyFrom(*property_list[i]); 47 } 48 } 49 50 void MockIBusEngineService::UpdatePreedit(const IBusText& ibus_text, 51 uint32 cursor_pos, 52 bool is_visible, 53 IBusEnginePreeditFocusOutMode mode) { 54 ++update_preedit_call_count_; 55 last_update_preedit_arg_->ibus_text.CopyFrom(ibus_text); 56 last_update_preedit_arg_->cursor_pos = cursor_pos; 57 last_update_preedit_arg_->is_visible = is_visible; 58 } 59 60 void MockIBusEngineService::UpdateAuxiliaryText(const IBusText& ibus_text, 61 bool is_visible) { 62 ++update_auxiliary_text_call_count_; 63 last_update_aux_text_arg_->ibus_text.CopyFrom(ibus_text); 64 last_update_aux_text_arg_->is_visible = is_visible; 65 } 66 67 void MockIBusEngineService::UpdateLookupTable( 68 const IBusLookupTable& lookup_table, 69 bool is_visible) { 70 ++update_lookup_table_call_count_; 71 last_update_lookup_table_arg_->lookup_table.CopyFrom(lookup_table); 72 last_update_lookup_table_arg_->is_visible = is_visible; 73 } 74 75 void MockIBusEngineService::UpdateProperty(const IBusProperty& property) { 76 ++update_property_call_count_; 77 last_updated_property_->CopyFrom(property); 78 } 79 80 void MockIBusEngineService::ForwardKeyEvent(uint32 keyval, 81 uint32 keycode, 82 uint32 state) { 83 ++forward_key_event_call_count_; 84 } 85 86 void MockIBusEngineService::RequireSurroundingText() { 87 } 88 89 void MockIBusEngineService::CommitText(const std::string& text) { 90 ++commit_text_call_count_; 91 last_commit_text_ = text; 92 } 93 94 void MockIBusEngineService::DeleteSurroundingText(int32 offset,uint32 length) { 95 ++delete_surrounding_text_call_count_; 96 last_delete_surrounding_text_arg_->offset = offset; 97 last_delete_surrounding_text_arg_->length = length; 98 } 99 100 IBusEngineHandlerInterface* MockIBusEngineService::GetEngine() const { 101 return current_engine_; 102 } 103 104 void MockIBusEngineService::Clear() { 105 register_properties_call_count_ = 0; 106 update_preedit_call_count_ = 0; 107 update_auxiliary_text_call_count_ = 0; 108 update_lookup_table_call_count_ = 0; 109 update_property_call_count_ = 0; 110 forward_key_event_call_count_ = 0; 111 commit_text_call_count_ = 0; 112 delete_surrounding_text_call_count_ = 0; 113 last_commit_text_.clear(); 114 last_update_preedit_arg_.reset(new UpdatePreeditArg()); 115 last_update_aux_text_arg_.reset(new UpdateAuxiliaryTextArg()); 116 last_update_lookup_table_arg_.reset(new UpdateLookupTableArg()); 117 last_registered_properties_.reset(new IBusPropertyList()); 118 last_updated_property_.reset(new IBusProperty()); 119 last_delete_surrounding_text_arg_.reset(new DeleteSurroundingTextArg()); 120 } 121 122 } // namespace chromeos 123