Home | History | Annotate | Download | only in ibus
      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 #ifndef CHROMEOS_DBUS_IBUS_MOCK_IBUS_ENGINE_SERVICE_H_
      6 #define CHROMEOS_DBUS_IBUS_MOCK_IBUS_ENGINE_SERVICE_H_
      7 
      8 #include <string>
      9 #include "chromeos/dbus/ibus/ibus_engine_service.h"
     10 
     11 #include "chromeos/dbus/ibus/ibus_lookup_table.h"
     12 #include "chromeos/dbus/ibus/ibus_property.h"
     13 #include "chromeos/dbus/ibus/ibus_text.h"
     14 
     15 namespace chromeos {
     16 
     17 class IBusText;
     18 
     19 class MockIBusEngineService : public IBusEngineService {
     20  public:
     21 
     22   struct UpdatePreeditArg {
     23     UpdatePreeditArg() : is_visible(false) {}
     24     IBusText ibus_text;
     25     uint32 cursor_pos;
     26     bool is_visible;
     27   };
     28 
     29   struct UpdateAuxiliaryTextArg {
     30     UpdateAuxiliaryTextArg() : is_visible(false) {}
     31     IBusText ibus_text;
     32     bool is_visible;
     33   };
     34 
     35   struct UpdateLookupTableArg {
     36     UpdateLookupTableArg() : is_visible(false) {}
     37     IBusLookupTable lookup_table;
     38     bool is_visible;
     39   };
     40 
     41   struct DeleteSurroundingTextArg {
     42     int32 offset;
     43     uint32 length;
     44   };
     45 
     46   MockIBusEngineService();
     47   virtual ~MockIBusEngineService();
     48 
     49   // IBusEngineService overrides.
     50   virtual void SetEngine(IBusEngineHandlerInterface* handler) OVERRIDE;
     51   virtual void UnsetEngine(IBusEngineHandlerInterface* handler) OVERRIDE;
     52   virtual void RegisterProperties(
     53       const IBusPropertyList& property_list) OVERRIDE;
     54   virtual void UpdatePreedit(const IBusText& ibus_text,
     55                              uint32 cursor_pos,
     56                              bool is_visible,
     57                              IBusEnginePreeditFocusOutMode mode) OVERRIDE;
     58   virtual void UpdateAuxiliaryText(const IBusText& ibus_text,
     59                                    bool is_visible) OVERRIDE;
     60   virtual void UpdateLookupTable(const IBusLookupTable& lookup_table,
     61                                  bool is_visible) OVERRIDE;
     62   virtual void UpdateProperty(const IBusProperty& property) OVERRIDE;
     63   virtual void ForwardKeyEvent(uint32 keyval, uint32 keycode,
     64                                uint32 state) OVERRIDE;
     65   virtual void RequireSurroundingText() OVERRIDE;
     66   virtual void CommitText(const std::string& text) OVERRIDE;
     67   virtual void DeleteSurroundingText(int32 offset, uint32 length) OVERRIDE;
     68 
     69   IBusEngineHandlerInterface* GetEngine() const;
     70 
     71   void Clear();
     72 
     73   int commit_text_call_count() const { return commit_text_call_count_; }
     74   const std::string& last_commit_text() const { return last_commit_text_; }
     75 
     76   int update_preedit_call_count() const { return update_preedit_call_count_; }
     77   const UpdatePreeditArg& last_update_preedit_arg() const {
     78     return *last_update_preedit_arg_.get();
     79   }
     80 
     81   int update_auxiliary_text_call_count() const {
     82     return update_auxiliary_text_call_count_;
     83   }
     84   const UpdateAuxiliaryTextArg& last_update_aux_text_arg() const {
     85     return *last_update_aux_text_arg_.get();
     86   }
     87 
     88   int update_lookup_table_call_count() const {
     89     return update_lookup_table_call_count_;
     90   }
     91   const UpdateLookupTableArg& last_update_lookup_table_arg() const {
     92     return *last_update_lookup_table_arg_.get();
     93   }
     94 
     95   int register_properties_call_count() const {
     96     return register_properties_call_count_;
     97   }
     98   const IBusPropertyList& last_registered_properties() const {
     99     return *last_registered_properties_.get();
    100   }
    101 
    102   int update_property_call_count() const {
    103     return update_property_call_count_;
    104   }
    105   const IBusProperty& last_updated_property() const {
    106     return *last_updated_property_.get();
    107   }
    108 
    109   int delete_surrounding_text_call_count() const {
    110     return delete_surrounding_text_call_count_;
    111   }
    112   const DeleteSurroundingTextArg& last_delete_surrounding_text_arg() const {
    113     return *last_delete_surrounding_text_arg_.get();
    114   }
    115 
    116  private:
    117   int register_properties_call_count_;
    118   int update_preedit_call_count_;
    119   int update_auxiliary_text_call_count_;
    120   int update_lookup_table_call_count_;
    121   int update_property_call_count_;
    122   int forward_key_event_call_count_;
    123   int commit_text_call_count_;
    124   int delete_surrounding_text_call_count_;
    125 
    126   std::string last_commit_text_;
    127   scoped_ptr<UpdatePreeditArg> last_update_preedit_arg_;
    128   scoped_ptr<UpdateAuxiliaryTextArg> last_update_aux_text_arg_;
    129   scoped_ptr<UpdateLookupTableArg> last_update_lookup_table_arg_;
    130   scoped_ptr<IBusPropertyList> last_registered_properties_;
    131   scoped_ptr<IBusProperty> last_updated_property_;
    132   scoped_ptr<DeleteSurroundingTextArg> last_delete_surrounding_text_arg_;
    133 
    134   IBusEngineHandlerInterface* current_engine_;
    135 
    136   DISALLOW_COPY_AND_ASSIGN(MockIBusEngineService);
    137 };
    138 
    139 }  // namespace chromeos
    140 
    141 #endif  // CHROMEOS_DBUS_IBUS_MOCK_IBUS_ENGINE_SERVICE_H_
    142