Fix svace/coverity issue (key events constructor) 46/299046/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 19 Sep 2023 02:07:48 +0000 (11:07 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 19 Sep 2023 03:35:44 +0000 (12:35 +0900)
And also, make default KeyEvent::New() API, for coverage.

Change-Id: Id8fbaea475664db81609a78116c091d15d813713
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-KeyEvent.cpp
dali/devel-api/events/key-event-devel.cpp
dali/devel-api/events/key-event-devel.h
dali/internal/event/events/key-event-impl.cpp
dali/internal/event/events/key-event-impl.h

index b03bacf..3c549a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -45,6 +45,8 @@ const static int SHIFT_AND_CTRL_MODIFIER = SHIFT_MODIFIER | CTRL_MODIFIER;
 const static int SHIFT_AND_ALT_MODIFIER  = SHIFT_MODIFIER | ALT_MODIFIER;
 const static int CTRL_AND_ALT_MODIFIER   = CTRL_MODIFIER | ALT_MODIFIER;
 
+const static int32_t KEY_INVALID_CODE = -1;
+
 const static char* TEST_STRING_1 = "alpha";
 
 // Stores data that is populated in the callback and will be read by the TET cases
@@ -91,6 +93,29 @@ struct KeyEventReceivedFunctor
 
 } // namespace
 
+int UtcDaliKeyEventDefaultConstructor(void)
+{
+  TestApplication application; // Reset all test adapter return codes
+
+  Dali::KeyEvent event = DevelKeyEvent::New();
+  DALI_TEST_CHECK(event);
+
+  DALI_TEST_EQUALS("", event.GetKeyName(), TEST_LOCATION);                            // check key name
+  DALI_TEST_EQUALS("", event.GetLogicalKey(), TEST_LOCATION);                         // check logical key string
+  DALI_TEST_EQUALS("", event.GetKeyString(), TEST_LOCATION);                          // check key string
+  DALI_TEST_EQUALS(KEY_INVALID_CODE, event.GetKeyCode(), TEST_LOCATION);              // check keyCode
+  DALI_TEST_EQUALS(0, event.GetKeyModifier(), TEST_LOCATION);                         // check modifier
+  DALI_TEST_EQUALS(0lu, event.GetTime(), TEST_LOCATION);                              // check time
+  DALI_TEST_EQUALS(KeyEvent::DOWN, event.GetState(), TEST_LOCATION);                  // check state
+  DALI_TEST_EQUALS("", event.GetCompose(), TEST_LOCATION);                            // check compose
+  DALI_TEST_EQUALS("", event.GetDeviceName(), TEST_LOCATION);                         // check device name
+  DALI_TEST_EQUALS(Device::Class::NONE, event.GetDeviceClass(), TEST_LOCATION);       // check device class
+  DALI_TEST_EQUALS(Device::Subclass::NONE, event.GetDeviceSubclass(), TEST_LOCATION); // check device subclass
+  DALI_TEST_EQUALS(false, event.IsRepeat(), TEST_LOCATION);                           // check repeat
+
+  END_TEST;
+}
+
 int UtcDaliKeyEventConstructor(void)
 {
   TestApplication application; // Reset all test adapter return codes
index 0856d39..bf4189a 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.\r
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -23,6 +23,13 @@ namespace Dali
 {\r
 namespace DevelKeyEvent\r
 {\r
+KeyEvent New()\r
+{\r
+  Internal::KeyEventPtr internal = Internal::KeyEvent::New();\r
+\r
+  return KeyEvent(internal.Get());\r
+}\r
+\r
 KeyEvent New(const std::string&           keyName,\r
              const std::string&           logicalKey,\r
              const std::string&           keyString,\r
index 24a0a23..cf88c9f 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_KEY_EVENT_DEVEL_H\r
 \r
 /*\r
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.\r
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -26,6 +26,14 @@ namespace Dali
 namespace DevelKeyEvent\r
 {\r
 /**\r
+ * @brief Creates an initialized KeyEvent as default.\r
+ *\r
+ * @SINCE_2_2.45\r
+ * @return A handle to a newly allocated Dali resource\r
+ */\r
+DALI_CORE_API KeyEvent New();\r
+\r
+/**\r
  * @brief Creates an initialized KeyEvent.\r
  *\r
  * @SINCE_1_9.27\r
index e177329..fdf8b4c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -44,7 +44,8 @@ KeyEvent::KeyEvent()
   mCompose(""),
   mDeviceName(""),
   mDeviceClass(Device::Class::NONE),
-  mDeviceSubclass(Device::Subclass::NONE)
+  mDeviceSubclass(Device::Subclass::NONE),
+  mIsRepeat(false)
 {
 }
 
@@ -74,6 +75,12 @@ KeyEvent::KeyEvent(const std::string&           keyName,
 {
 }
 
+KeyEventPtr KeyEvent::New()
+{
+  KeyEventPtr keyEvent = new KeyEvent();
+  return keyEvent;
+}
+
 KeyEventPtr KeyEvent::New(const std::string&           keyName,
                           const std::string&           logicalKey,
                           const std::string&           keyString,
index 175ab89..c13d23a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_KEY_EVENT_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -68,6 +68,12 @@ public:
            const Device::Subclass::Type deviceSubclass);
 
   /**
+   * Create a new default KeyEvent.
+   * @return A smart-pointer to the newly allocated KeyEvent.
+   */
+  static KeyEventPtr New();
+
+  /**
    * Create a new KeyEvent.
    *
    * @param[in]  keyName         The name of the key pressed or command from the IMF, if later then the some following parameters will be needed.