Key event copy and assignment ops added 76/125076/5
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Thu, 13 Apr 2017 13:35:38 +0000 (14:35 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Thu, 13 Apr 2017 15:57:17 +0000 (16:57 +0100)
Change-Id: Ia2057b4fe23e60e2fb44c293fc1680cbe6434c97

automated-tests/src/dali/utc-Dali-KeyEvent.cpp
dali/devel-api/events/key-event-devel.h
dali/devel-api/file.list
dali/public-api/events/key-event.cpp
dali/public-api/events/key-event.h

index dde1fecc110f04a174e2130e63d89cef5899c5ca..fc7aeaee0140472110451dec8757d8e13ea2e44a 100644 (file)
@@ -106,6 +106,58 @@ int UtcDaliKeyEventConstructor(void)
   END_TEST;
 }
 
+int UtcDaliKeyEventAssignment(void)
+{
+  // Test Assignment operator
+  KeyEvent event(TEST_STRING_1,"i", 99, SHIFT_MODIFIER, 0, KeyEvent::Down);  // set name to test, key string to i and modifier to shift
+
+  DALI_TEST_EQUALS(TEST_STRING_1, event.keyPressedName, TEST_LOCATION); // check key name
+  DALI_TEST_EQUALS("i", event.keyPressed, TEST_LOCATION); // check key string
+  DALI_TEST_EQUALS(99, event.keyCode, TEST_LOCATION); // check keyCode
+  DALI_TEST_EQUALS(SHIFT_MODIFIER, event.keyModifier, TEST_LOCATION); // check modifier
+  DALI_TEST_EQUALS(KeyEvent::Down, event.state, TEST_LOCATION); // check state
+
+  KeyEvent event2(TEST_STRING_1,"j", 88, CTRL_MODIFIER, 0, KeyEvent::Up);  // set name to test, key string to i and modifier to shift
+
+  DALI_TEST_EQUALS(TEST_STRING_1, event2.keyPressedName, TEST_LOCATION); // check key name
+  DALI_TEST_EQUALS("j", event2.keyPressed, TEST_LOCATION); // check key string
+  DALI_TEST_EQUALS(88, event2.keyCode, TEST_LOCATION); // check keyCode
+  DALI_TEST_EQUALS(CTRL_MODIFIER, event2.keyModifier, TEST_LOCATION); // check modifier
+  DALI_TEST_EQUALS(KeyEvent::Up, event2.state, TEST_LOCATION); // check state
+
+  event = event2;
+
+  DALI_TEST_EQUALS(TEST_STRING_1, event.keyPressedName, TEST_LOCATION); // check key name
+  DALI_TEST_EQUALS("j", event.keyPressed, TEST_LOCATION); // check key string
+  DALI_TEST_EQUALS(88, event.keyCode, TEST_LOCATION); // check keyCode
+  DALI_TEST_EQUALS(CTRL_MODIFIER, event.keyModifier, TEST_LOCATION); // check modifier
+  DALI_TEST_EQUALS(KeyEvent::Up, event.state, TEST_LOCATION); // check state
+
+  END_TEST;
+}
+
+int UtcDaliKeyEventCopy(void)
+{
+  // Test Assignment operator
+  KeyEvent event(TEST_STRING_1,"i", 99, SHIFT_MODIFIER, 0, KeyEvent::Down);  // set name to test, key string to i and modifier to shift
+
+  DALI_TEST_EQUALS(TEST_STRING_1, event.keyPressedName, TEST_LOCATION); // check key name
+  DALI_TEST_EQUALS("i", event.keyPressed, TEST_LOCATION); // check key string
+  DALI_TEST_EQUALS(99, event.keyCode, TEST_LOCATION); // check keyCode
+  DALI_TEST_EQUALS(SHIFT_MODIFIER, event.keyModifier, TEST_LOCATION); // check modifier
+  DALI_TEST_EQUALS(KeyEvent::Down, event.state, TEST_LOCATION); // check state
+
+  KeyEvent event2( event );
+
+  DALI_TEST_EQUALS(TEST_STRING_1, event2.keyPressedName, TEST_LOCATION); // check key name
+  DALI_TEST_EQUALS("i", event2.keyPressed, TEST_LOCATION); // check key string
+  DALI_TEST_EQUALS(99, event2.keyCode, TEST_LOCATION); // check keyCode
+  DALI_TEST_EQUALS(SHIFT_MODIFIER, event2.keyModifier, TEST_LOCATION); // check modifier
+  DALI_TEST_EQUALS(KeyEvent::Down, event2.state, TEST_LOCATION); // check state
+
+  END_TEST;
+}
+
 // Positive test case for a method
 int UtcDaliKeyEventIsShiftModifier(void)
 {
index 87af795fa94f934d606e95af788b83d1458f2a16..13ffd20be31e0a001ac4208913a2111376e726be 100644 (file)
@@ -26,9 +26,21 @@ namespace Dali
 
 namespace DevelKeyEvent
 {
-  std::string GetDeviceName( KeyEvent& keyEvent );
-
-  void SetDeviceName( KeyEvent& keyEvent, std::string deviceName );
+  /**
+   * @brief Get the device name the key event originated from
+   *
+   * @param[in] keyEvent the KeyEvent to retrieve the device name from
+   * @return the device name
+   */
+  std::string GetDeviceName( const KeyEvent& keyEvent );
+
+  /**
+   * @brief Set the device name to the KeyEvent
+   *
+   * @param[in] keyEvent the KeyEvent to set the device name on
+   * @param[in] deviceName device name string to set
+   */
+  void SetDeviceName( KeyEvent& keyEvent, const std::string& deviceName );
 
 }
 
index 84f9117c568203887497748bc3b79ae5ccd72e28..282357303cc431bf49a984bd470031292e541eec 100644 (file)
@@ -37,7 +37,8 @@ devel_api_core_common_header_files = \
   $(devel_api_src_dir)/common/stage-devel.h
 
 devel_api_core_events_header_files = \
-  $(devel_api_src_dir)/events/hit-test-algorithm.h
+  $(devel_api_src_dir)/events/hit-test-algorithm.h \
+  $(devel_api_src_dir)/events/key-event-devel.h
 
 devel_api_core_images_header_files = \
   $(devel_api_src_dir)/images/distance-field.h \
index 7ed937f1af11223bd02d7b58c074054117a98666..27e3ed4253614746719b314aba192a1576f74d57 100644 (file)
@@ -34,10 +34,30 @@ const int KEY_INVALID_CODE = -1;
 
 struct KeyEventImpl
 {
+  KeyEventImpl()
+    :deviceName("")
+  {
+  };
+
+  KeyEventImpl& operator=( const KeyEventImpl& rhs )
+  {
+    if( this != &rhs )
+    {
+      deviceName = rhs.deviceName;
+    }
+
+    return *this;
+  }
+
+  KeyEventImpl( const KeyEventImpl& rhs )
+  {
+    deviceName =  rhs.deviceName;
+  }
+
   std::string deviceName;
 };
 
-typedef std::map< KeyEvent*, KeyEventImpl*> KeyEventMap;
+typedef std::map< const KeyEvent*, KeyEventImpl*> KeyEventMap;
 typedef KeyEventMap::const_iterator KeyEventMapIter;
 
 
@@ -65,8 +85,35 @@ KeyEvent::KeyEvent(const std::string& keyName, const std::string& keyString, int
   time(timeStamp),
   state(keyState)
 {
-  KeyEventImpl* impl = new KeyEventImpl;
-  keyEventImplMap[this] = impl;
+  keyEventImplMap[this] = new KeyEventImpl;
+}
+
+KeyEvent::KeyEvent( const KeyEvent& rhs )
+: keyPressedName( rhs.keyPressedName ),
+  keyPressed( rhs.keyPressed ),
+  keyCode( rhs.keyCode ),
+  keyModifier( rhs.keyModifier ),
+  time( rhs.time ),
+  state( rhs.state )
+{
+  keyEventImplMap[this] = new KeyEventImpl( *keyEventImplMap[ &rhs ] );
+}
+
+KeyEvent& KeyEvent::operator=( const KeyEvent& rhs )
+{
+  if( this != &rhs )
+  {
+    keyPressedName = rhs.keyPressedName;
+    keyPressed = rhs.keyPressed;
+    keyCode = rhs.keyCode;
+    keyModifier = rhs.keyModifier;
+    time = rhs.time;
+    state = rhs.state;
+
+    *keyEventImplMap[ this ] = *keyEventImplMap[ &rhs ];
+  }
+
+  return *this;
 }
 
 KeyEvent::~KeyEvent()
@@ -105,23 +152,19 @@ bool KeyEvent::IsAltModifier() const
   return false;
 }
 
-std::string DevelKeyEvent::GetDeviceName( KeyEvent& keyEvent )
+std::string DevelKeyEvent::GetDeviceName( const KeyEvent& keyEvent )
 {
-  KeyEventMapIter search;
-
-  search = keyEventImplMap.find( &keyEvent );
-
-  std::string result = "";
+  KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
 
   if( search != keyEventImplMap.end())
   {
-    result = search->second->deviceName;
+    return search->second->deviceName;
   }
 
-  return result;
+  return std::string("");
 }
 
-void DevelKeyEvent::SetDeviceName( KeyEvent& keyEvent, std::string deviceName )
+void DevelKeyEvent::SetDeviceName( KeyEvent& keyEvent, const std::string& deviceName )
 {
   KeyEventMapIter search = keyEventImplMap.find( &keyEvent );
 
index 5d20f7cae886d362338f40589e113a0e87b9e5f8..f0d5681a4e8c1024042bc587d7434070b465f674 100644 (file)
@@ -80,6 +80,21 @@ struct DALI_IMPORT_API KeyEvent
    */
   KeyEvent(const std::string& keyName, const std::string& keyString, int keyCode, int keyModifier, unsigned long timeStamp, const State& keyState);
 
+  /**
+   * @brief Copy constructor.
+   * @SINCE_1_2.36
+   * @param[in] rhs A reference to the copied handle
+   */
+  KeyEvent( const KeyEvent& rhs );
+
+  /**
+   * @brief Assignment operator.
+   * @SINCE_1_2.36
+   * @param[in] rhs A reference to the copied handle
+   * @return A reference to this
+   */
+  KeyEvent& operator=( const KeyEvent& rhs );
+
   /**
    * @brief Destructor.
    * @SINCE_1_0.0