Add unittests for CommandManager and CommandFinder 34/281534/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 14 Sep 2022 09:03:18 +0000 (18:03 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Tue, 20 Sep 2022 02:54:14 +0000 (11:54 +0900)
Change-Id: I278b7c11b3ad4c247b9598e648cdd3d0858140e5
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
tests/iu/CommandFinder_unittests.cpp [new file with mode: 0644]
tests/iu/CommandManager_unittests.cpp [new file with mode: 0644]
tests/meson.build

diff --git a/tests/iu/CommandFinder_unittests.cpp b/tests/iu/CommandFinder_unittests.cpp
new file mode 100644 (file)
index 0000000..e0f8ed6
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "CommandFinder.h"
+
+using namespace std;
+
+namespace {
+
+class CommandFinderTest : public testing::Test {
+    public:
+        virtual void SetUp() {
+            ClickableItem item1;
+            item1.coordX = 10;
+            item1.coordY = 10;
+            item1.width = 10;
+            item1.height = 10;
+            item1.objectId = "id1";
+            item1.label = "test1";
+            item1.index = 1;
+
+            ClickableItem item2;
+            item2.coordX = 20;
+            item2.coordY = 20;
+            item2.width = 10;
+            item2.height = 10;
+            item2.objectId = "id2";
+            item2.label = "test2";
+            item2.index = 2;
+
+            ClickableItem item3;
+            item3.coordX = 30;
+            item3.coordY = 30;
+            item3.width = 10;
+            item3.height = 10;
+            item3.objectId = "id3";
+            item3.label = "";
+            item3.index = 3;
+
+            commands.push_back(make_shared<ClickableItem>(item1));
+            commands.push_back(make_shared<ClickableItem>(item2));
+            commands.push_back(make_shared<ClickableItem>(item3));
+        }
+
+        virtual void TearDown() {
+            commands.clear();
+        }
+
+    public:
+        list<shared_ptr<ClickableItem>> commands;
+};
+
+TEST_F(CommandFinderTest, utc_CommandFinder_Constructor)
+{
+    string target = "test1";
+    auto finder1 = new(nothrow) CommandFinder(target, commands);
+    auto finder2 = new(nothrow) CommandFinder(1, commands);
+
+    EXPECT_NE(finder1, nullptr);
+    EXPECT_NE(finder2, nullptr);
+
+    delete finder1;
+    delete finder2;
+}
+
+TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_p)
+{
+    string target = "test1";
+    auto finder_p = new(nothrow) CommandFinder(target, commands);
+    ASSERT_NE(finder_p, nullptr);
+
+    auto command = finder_p->findCommand();
+    ASSERT_NE(command, nullptr);
+    EXPECT_STREQ(command->objectId.c_str(), "id1");
+
+    delete finder_p;
+}
+
+TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_p2)
+{
+    string target = "text1";
+    auto finder_p = new(nothrow) CommandFinder(target, commands);
+    ASSERT_NE(finder_p, nullptr);
+
+    auto command = finder_p->findCommand();
+    ASSERT_NE(command, nullptr);
+    EXPECT_STREQ(command->objectId.c_str(), "id1");
+
+    delete finder_p;
+}
+
+TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_p3)
+{
+    auto finder_p = new(nothrow) CommandFinder(1, commands);
+    ASSERT_NE(finder_p, nullptr);
+
+    auto command = finder_p->findCommand();
+    ASSERT_NE(command, nullptr);
+    EXPECT_STREQ(command->objectId.c_str(), "id1");
+
+    delete finder_p;
+}
+
+TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_n)
+{
+    string target = "no matched text";
+    auto finder_n = new(nothrow) CommandFinder(target, commands);
+    ASSERT_NE(finder_n, nullptr);
+
+    auto command = finder_n->findCommand();
+    EXPECT_EQ(command, nullptr);
+
+    delete finder_n;
+}
+
+TEST_F(CommandFinderTest, utc_CommandFinder_findCommand_n2)
+{
+    auto finder_n = new(nothrow) CommandFinder(-1, commands);
+    ASSERT_NE(finder_n, nullptr);
+
+    auto command = finder_n->findCommand();
+    EXPECT_EQ(command, nullptr);
+
+    delete finder_n;
+}
+
+} // namespace
diff --git a/tests/iu/CommandManager_unittests.cpp b/tests/iu/CommandManager_unittests.cpp
new file mode 100644 (file)
index 0000000..ad4eee2
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "CommandManager.h"
+
+using namespace std;
+
+namespace {
+
+class CommandManagerTest : public testing::Test {
+    public:
+        virtual void SetUp() {
+        }
+
+        virtual void TearDown() {
+        }
+
+    public:
+        list<shared_ptr<ClickableItem>> commands;
+};
+
+TEST_F(CommandManagerTest, utc_CommandManager_Constructor)
+{
+    auto manager = new(nothrow) CommandManager();
+
+    EXPECT_NE(manager, nullptr);
+
+    delete manager;
+}
+
+TEST_F(CommandManagerTest, utc_CommandManager_addCommand)
+{
+    auto manager = new(nothrow) CommandManager();
+
+    ASSERT_NE(manager, nullptr);
+
+    ClickableItem item1;
+    item1.coordX = 10;
+    item1.coordY = 10;
+    item1.width = 10;
+    item1.height = 10;
+    item1.objectId = "id1";
+    item1.label = "test1";
+    item1.index = 1;
+
+    manager->addCommand(item1);
+
+    delete manager;
+}
+
+TEST_F(CommandManagerTest, utc_CommandFinder_findCommand)
+{
+    auto manager = new(nothrow) CommandManager();
+
+    ASSERT_NE(manager, nullptr);
+
+    ClickableItem item1;
+    item1.coordX = 10;
+    item1.coordY = 10;
+    item1.width = 10;
+    item1.height = 10;
+    item1.objectId = "id1";
+    item1.label = "test1";
+    item1.index = 1;
+
+    ClickableItem item2;
+    item2.coordX = 20;
+    item2.coordY = 20;
+    item2.width = 10;
+    item2.height = 10;
+    item2.objectId = "id2";
+    item2.label = "test2";
+    item2.index = 2;
+
+    manager->addCommand(item1);
+    manager->addCommand(item2);
+
+    string target1 = "test1";
+    auto command1 = manager->findCommand(target1, false);
+    ASSERT_NE(command1, nullptr);
+    EXPECT_STREQ(command1->objectId.c_str(), "id1");
+    command1 = nullptr;
+
+    string target2 = "2";
+    auto command2 = manager->findCommand(target2, true);
+    ASSERT_NE(command2, nullptr);
+    EXPECT_STREQ(command2->objectId.c_str(), "id2");
+    command2 = nullptr;
+
+    delete manager;
+}
+
+TEST_F(CommandManagerTest, utc_CommandFinder_clearCommand)
+{
+    auto manager = new(nothrow) CommandManager();
+
+    ASSERT_NE(manager, nullptr);
+
+    ClickableItem item1;
+    item1.coordX = 10;
+    item1.coordY = 10;
+    item1.width = 10;
+    item1.height = 10;
+    item1.objectId = "id1";
+    item1.label = "test1";
+    item1.index = 1;
+
+    ClickableItem item2;
+    item2.coordX = 20;
+    item2.coordY = 20;
+    item2.width = 10;
+    item2.height = 10;
+    item2.objectId = "id2";
+    item2.label = "test2";
+    item2.index = 2;
+
+    manager->addCommand(item1);
+    manager->addCommand(item2);
+
+    string target1 = "test1";
+    auto command1 = manager->findCommand(target1, false);
+    ASSERT_NE(command1, nullptr);
+    EXPECT_STREQ(command1->objectId.c_str(), "id1");
+    command1 = nullptr;
+
+    manager->cleanCommands();
+
+    auto command2 = manager->findCommand(target1, false);
+    EXPECT_EQ(command2, nullptr);
+
+    delete manager;
+}
+
+} // namespace
index 410dbad..d7607b3 100644 (file)
@@ -11,7 +11,9 @@ mmi_manager_tests_srcs = [
        'iu/mmi_iu_feed_input_event_unittests.cpp',
        'iu/mmi_iu_noinit_unittests.cpp',
        'iu/mmi_iu_unittests.cpp',
-       'iu/output_intent_unittests.cpp'
+       'iu/output_intent_unittests.cpp',
+       'iu/CommandFinder_unittests.cpp',
+       'iu/CommandManager_unittests.cpp'
        ]
 
 gmock_dep = dependency('gmock', method : 'pkg-config')