tests/vision-provider : add mmi-vision-provider-tests 18/265218/1
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 12 Oct 2021 00:19:58 +0000 (09:19 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Wed, 13 Oct 2021 01:35:55 +0000 (10:35 +0900)
init, shutdown, classification_from_image - success/fail, video - classification success and video stream finish

Change-Id: Ib2b3199b1109d21fe01421fdb8732fcd9449a78f

src/modules/modality_vision/vision.h
tests/vision-provider/main.cpp [new file with mode: 0644]
tests/vision-provider/main.h [new file with mode: 0644]
tests/vision-provider/meson.build [new file with mode: 0644]
tests/vision-provider/mmi-vision-provider-tests.cpp [new file with mode: 0644]

index 6a0b716..ee46084 100644 (file)
@@ -26,5 +26,7 @@
 
 void vision_init(void);
 void vision_shutdown(void);
+int image_classification_init(void);
+int classification_from_image(const char *path_to_image);
 
 #endif // __VISION_H__
\ No newline at end of file
diff --git a/tests/vision-provider/main.cpp b/tests/vision-provider/main.cpp
new file mode 100644 (file)
index 0000000..3187c80
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+* 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 "main.h"
+
+int main(int argc, char **argv)
+{
+       auto testResults = false;
+
+#ifdef TIZEN_TEST_GCOV
+        setenv("GCOV_PREFIX", "/tmp", 1);
+#endif
+       try
+       {
+               ::testing::InitGoogleMock(&argc, argv);
+               ::testing::FLAGS_gtest_death_test_style = "fast";
+       }
+       catch ( ... )
+       {
+               PRINT("Error occurred while trying to initialize GoogleTest.\n");
+               exit(EXIT_FAILURE);
+       }
+
+       try
+       {
+               testResults = (RUN_ALL_TESTS() == 0) ? true : false;
+       }
+       catch (const ::testing::internal::GoogleTestFailureException &e)
+       {
+               testResults = false;
+               PRINT("GoogleTestFailureException has been thrown: %s\n", e.what());
+       }
+
+#ifdef TIZEN_TEST_GCOV
+        __gcov_flush();
+#endif
+       return testResults;
+}
+
diff --git a/tests/vision-provider/main.h b/tests/vision-provider/main.h
new file mode 100644 (file)
index 0000000..6be5338
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+* 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.
+*/
+
+#ifndef __MMI_VISION_PROVIDER_TESTS_H__
+#define __MMI_VISION_PROVIDER_TESTS_H__
+
+#include <stdio.h>
+#include <gmock/gmock.h>
+#include <Ecore.h>
+
+#define PRINT printf
+
+#ifdef TIZEN_TEST_GCOV
+extern "C" void __gcov_flush(void);
+#endif
+
+using ::testing::TestWithParam;
+using ::testing::Bool;
+using ::testing::Values;
+using ::testing::Combine;
+
+#endif //__MMI_VISION_PROVIDER_TESTS_H__
diff --git a/tests/vision-provider/meson.build b/tests/vision-provider/meson.build
new file mode 100644 (file)
index 0000000..feb5c57
--- /dev/null
@@ -0,0 +1,19 @@
+modality_vision_tests_srcs = [
+       'main.cpp',
+       'mmi-vision-provider-tests.cpp',
+       '../ecore-event-dispatcher.cpp',
+       ]
+
+gmock_dep = dependency('gmock', method : 'pkg-config')
+ecore_dep = dependency('ecore', method : 'pkg-config')
+
+modality_vision_tests_rpath = ('/' + get_option('libdir') + '/provider/')
+
+executable(
+       'modality_vision-tests',
+       modality_vision_tests_srcs,
+       dependencies : [mmimgr_declared_dep, mmivision_declared_dep, gmock_dep, ecore_dep],
+       install_rpath: modality_vision_tests_rpath,
+       install_dir : mmi_manager_prefix_bindir,
+       install : true
+       )
diff --git a/tests/vision-provider/mmi-vision-provider-tests.cpp b/tests/vision-provider/mmi-vision-provider-tests.cpp
new file mode 100644 (file)
index 0000000..a170871
--- /dev/null
@@ -0,0 +1,228 @@
+/*
+* 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 "main.h"
+
+extern "C" {
+#include "mmi-vision-provider.h"
+#include "vision.h"
+}
+
+#include <Ecore.h>
+#include <string.h>
+#include <gtest/gtest.h>
+
+void wait_for_dispatch();
+
+class MMIVisionProviderTest : public ::testing::Test
+{
+public:
+       void SetUp(void) override
+       {
+               ecore_init();
+       }
+
+       void TearDown(void) override
+       {
+               ecore_shutdown();
+       }
+};
+
+TEST_F(MMIVisionProviderTest, MMIVisionProviderSetGetMode)
+{
+       bool r = false;
+       mmi_provider_op_mode op_mode = MODALITY_PROVIDER_MODE_NONE;
+
+       r = vision_set_mode(MODALITY_PROVIDER_MODE_PROPAGATE_EVENT);
+       EXPECT_EQ(r, true);
+
+       op_mode = vision_get_mode();
+       EXPECT_EQ(op_mode, MODALITY_PROVIDER_MODE_PROPAGATE_EVENT);
+}
+
+TEST_F(MMIVisionProviderTest, MMIVisionProviderSetModeFail)
+{
+       bool r = false;
+
+       r = vision_set_mode(MODALITY_PROVIDER_MODE_NONE);
+       EXPECT_EQ(r, false);
+}
+
+class MMIVisionProviderVisionTest : public ::testing::Test
+{
+public:
+       void SetUp(void) override
+       {
+               ecore_init();
+       }
+
+       void TearDown(void) override
+       {
+               ecore_shutdown();
+       }
+};
+
+TEST_F(MMIVisionProviderVisionTest, MMIVisionProviderVisionInit)
+{
+       int res = 0;
+       vision_init();
+
+       res = 1;
+       EXPECT_EQ(res, 1);
+
+       vision_shutdown();
+}
+
+TEST_F(MMIVisionProviderVisionTest, MMIVisionProviderClassificationInit)
+{
+       int res = 0;
+
+       res = image_classification_init();
+
+       EXPECT_EQ(res, 0);
+
+       vision_shutdown();
+}
+
+static Eina_Bool
+_vison_video_working_finish(void *data, int type, void *event)
+{
+       int *wait = (int*)data;
+       *wait = 1;
+
+       return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_vison_image_event(void *data, int type, void *event)
+{
+       int *success = (int*)data;
+       *success = 1;
+
+       return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_vision_video_classfication_success(void *data, int type, void *event)
+{
+       int *success = (int*)data;
+       *success = 1;
+
+       return ECORE_CALLBACK_PASS_ON;
+}
+
+TEST_F(MMIVisionProviderVisionTest, MMIVisionProviderImage)
+{
+       int res = 0;
+       int timer = 0;
+       int success = 0;
+       const char *image_path = "/usr/share/mmi-provider/sample_no.jpg";
+       static Ecore_Event_Handler *_event_handlers;
+
+       MMI_VISION_EVENT_PROPAGATE = ecore_event_type_new();
+       MMI_VISION_EVENT_FINISH = ecore_event_type_new();
+       MMI_PROVIDER_EVENT_VISION = ecore_event_type_new();
+
+       vision_init();
+
+       _event_handlers = ecore_event_handler_add(MMI_PROVIDER_EVENT_VISION, _vison_image_event, &success);
+       EXPECT_NE(_event_handlers, nullptr);
+
+       res = classification_from_image(image_path);
+       wait_for_dispatch();
+
+       EXPECT_EQ(success, 1);
+
+       EXPECT_EQ(res, 0);
+       ecore_event_handler_del(_event_handlers);
+       _event_handlers = NULL;
+
+       vision_shutdown();
+}
+
+TEST_F(MMIVisionProviderVisionTest, MMIVisionProviderImageFail)
+{
+       int res = 0;
+       int timer = 0;
+       int success = 0;
+       const char *image_path = NULL;
+       static Ecore_Event_Handler *_event_handlers;
+
+       MMI_VISION_EVENT_PROPAGATE = ecore_event_type_new();
+       MMI_VISION_EVENT_FINISH = ecore_event_type_new();
+       MMI_PROVIDER_EVENT_VISION = ecore_event_type_new();
+
+       vision_init();
+
+       _event_handlers = ecore_event_handler_add(MMI_PROVIDER_EVENT_VISION, _vison_image_event, &success);
+       EXPECT_NE(_event_handlers, nullptr);
+
+       res = classification_from_image(image_path);
+       wait_for_dispatch();
+
+       EXPECT_EQ(success, 0);
+
+       EXPECT_NE(res, 0);
+       ecore_event_handler_del(_event_handlers);
+       _event_handlers = NULL;
+
+       vision_shutdown();
+}
+
+TEST_F(MMIVisionProviderVisionTest, MMIVisionProviderVideo)
+{
+       int res = 0;
+       int wait = 0;
+       int timer = 0;
+       int success = 0;
+       static Ecore_Event_Handler *_event_handlers[2];
+
+       MMI_VISION_EVENT_PROPAGATE = ecore_event_type_new();
+       MMI_VISION_EVENT_FINISH = ecore_event_type_new();
+       MMI_PROVIDER_EVENT_VISION = ecore_event_type_new();
+
+       vision_init();
+
+       _event_handlers[0] = ecore_event_handler_add(MMI_VISION_EVENT_FINISH, _vison_video_working_finish, &wait);
+       _event_handlers[1] = ecore_event_handler_add(MMI_PROVIDER_EVENT_VISION, _vision_video_classfication_success, &success);
+       EXPECT_NE(_event_handlers[0], nullptr);
+       EXPECT_NE(_event_handlers[1], nullptr);
+
+       res = vision_set_mode(MODALITY_PROVIDER_MODE_PROPAGATE_EVENT);
+
+       while(timer != 1500000)
+       {
+               ecore_main_loop_iterate();
+               timer++;
+       }
+       EXPECT_EQ(success, 1);
+       EXPECT_EQ(wait, 1);
+
+       EXPECT_EQ(res, 1);
+       ecore_event_handler_del(_event_handlers[0]);
+       ecore_event_handler_del(_event_handlers[1]);
+       _event_handlers[0] = NULL;
+       _event_handlers[1] = NULL;
+
+       vision_shutdown();
+}