--- /dev/null
+/*
+* 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;
+}
+
--- /dev/null
+/*
+* 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__
--- /dev/null
+/*
+* 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();
+}