tests: Add autofill manager unittests 00/265600/4
authorJihoon Kim <jihoon48.kim@samsung.com>
Mon, 25 Oct 2021 04:56:29 +0000 (13:56 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 25 Oct 2021 05:48:37 +0000 (14:48 +0900)
[----------] 7 tests from AutofillManagerDeniedTest
[ RUN      ] AutofillManagerDeniedTest.utc_autofill_manager_denied_create_p
[       OK ] AutofillManagerDeniedTest.utc_autofill_manager_denied_create_p (5 ms)
[ RUN      ] AutofillManagerDeniedTest.utc_autofill_manager_denied_create_n
[       OK ] AutofillManagerDeniedTest.utc_autofill_manager_denied_create_n (3 ms)
[ RUN      ] AutofillManagerDeniedTest.utc_autofill_manager_denied_destroy
[       OK ] AutofillManagerDeniedTest.utc_autofill_manager_denied_destroy (3 ms)
[ RUN      ] AutofillManagerDeniedTest.utc_autofill_manager_denied_connect_n
[       OK ] AutofillManagerDeniedTest.utc_autofill_manager_denied_connect_n (3 ms)
[ RUN      ] AutofillManagerDeniedTest.utc_autofill_manager_denied_foreach_autofill_service_n
[       OK ] AutofillManagerDeniedTest.utc_autofill_manager_denied_foreach_autofill_service_n (3 ms)
[ RUN      ] AutofillManagerDeniedTest.utc_autofill_manager_denied_get_autofill_service_n
[       OK ] AutofillManagerDeniedTest.utc_autofill_manager_denied_get_autofill_service_n (3 ms)
[ RUN      ] AutofillManagerDeniedTest.utc_autofill_manager_denied_set_autofill_service_n
[       OK ] AutofillManagerDeniedTest.utc_autofill_manager_denied_set_autofill_service_n (3 ms)
[----------] 7 tests from AutofillManagerDeniedTest (24 ms total)

[----------] 11 tests from AutofillManagerTest
[ RUN      ] AutofillManagerTest.utc_autofill_manager_create_p
[       OK ] AutofillManagerTest.utc_autofill_manager_create_p (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_create_n
[       OK ] AutofillManagerTest.utc_autofill_manager_create_n (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_destroy_p
[       OK ] AutofillManagerTest.utc_autofill_manager_destroy_p (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_destroy_n
[       OK ] AutofillManagerTest.utc_autofill_manager_destroy_n (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_connect_n
[       OK ] AutofillManagerTest.utc_autofill_manager_connect_n (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_foreach_autofill_service_n1
[       OK ] AutofillManagerTest.utc_autofill_manager_foreach_autofill_service_n1 (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_foreach_autofill_service_n2
[       OK ] AutofillManagerTest.utc_autofill_manager_foreach_autofill_service_n2 (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_get_autofill_service_n1
[       OK ] AutofillManagerTest.utc_autofill_manager_get_autofill_service_n1 (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_get_autofill_service_n2
[       OK ] AutofillManagerTest.utc_autofill_manager_get_autofill_service_n2 (3 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_set_autofill_service_n1
[       OK ] AutofillManagerTest.utc_autofill_manager_set_autofill_service_n1 (4 ms)
[ RUN      ] AutofillManagerTest.utc_autofill_manager_set_autofill_service_n2
[       OK ] AutofillManagerTest.utc_autofill_manager_set_autofill_service_n2 (3 ms)
[----------] 11 tests from AutofillManagerTest (38 ms total)

Change-Id: If831e2704a5d210623bc771134631589dac8f46d
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
tests/CMakeLists.txt
tests/src/autofill_manager_denied_unittest.cpp [new file with mode: 0644]
tests/src/autofill_manager_unittest.cpp [new file with mode: 0644]
tests/src/cynara_mock.cpp [new file with mode: 0644]
tests/src/cynara_mock.h [new file with mode: 0644]

index ad28419..4f4268f 100644 (file)
@@ -10,6 +10,9 @@ pkg_check_modules(pkgs REQUIRED
        rpc-port
        capi-base-common
        gmock
+       capi-appfw-app-manager
+       cynara-client
+       cynara-session
 )
 
 FOREACH(flag ${pkgs_CFLAGS})
@@ -32,6 +35,8 @@ AUX_SOURCE_DIRECTORY(src SOURCES)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common AUTOFILL_COMMON_SOURCES)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../client AUTOFILL_CLIENT_SOURCES)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../service_lib AUTOFILL_SERVICE_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../manager AUTOFILL_MANAGER_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../privilege_checker AUTOFILL_PRIVILEGE_SOURCES)
 
 ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"")
 
@@ -39,8 +44,18 @@ ADD_EXECUTABLE(${UTC_AUTOFILL}
        ${AUTOFILL_COMMON_SOURCES}
        ${AUTOFILL_CLIENT_SOURCES}
        ${AUTOFILL_SERVICE_SOURCES}
+       ${AUTOFILL_MANAGER_SOURCES}
+       ${AUTOFILL_PRIVILEGE_SOURCES}
        ${SOURCES}
        )
 TARGET_LINK_LIBRARIES(${UTC_AUTOFILL} ${GTEST_LIBRARIES} ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS})
+SET_TARGET_PROPERTIES(${UTC_AUTOFILL} PROPERTIES
+       COMPILE_FLAGS "-fPIE"
+       #Never add any space for LINKFLAGS
+       LINK_FLAGS "-Wl,\
+--wrap=cynara_initialize,\
+--wrap=cynara_finish,\
+--wrap=cynara_session_from_pid,\
+--wrap=cynara_check")
 
 INSTALL(TARGETS ${UTC_AUTOFILL} DESTINATION /usr/bin)
diff --git a/tests/src/autofill_manager_denied_unittest.cpp b/tests/src/autofill_manager_denied_unittest.cpp
new file mode 100644 (file)
index 0000000..6fff893
--- /dev/null
@@ -0,0 +1,124 @@
+//
+// Copyright (c) 2014 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.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include <gtest/gtest.h>
+#include <autofill_manager.h>
+#include <glib.h>
+#include <Ecore.h>
+
+#include "cynara_mock.h"
+
+//& set: CapiUi-autofill-manager
+
+static autofill_manager_h g_amh = NULL;
+
+class AutofillManagerDeniedTest : public testing::Test {
+    public:
+        virtual void SetUp() {
+            ecore_init();
+
+            cynara_check_set_result(CYNARA_API_ACCESS_DENIED);
+
+            autofill_manager_create(&g_amh);
+        }
+        virtual void TearDown() {
+            if (g_amh) {
+                autofill_manager_destroy(g_amh);
+            }
+
+            g_amh = NULL;
+            ecore_shutdown();
+        }
+};
+
+/**
+ * @testcase        utc_autofill_manager_denied_create_p
+ * @since_tizen     5.5
+ * @description     Positive UTC of the function that creates autofill manager instance.
+ */
+TEST_F(AutofillManagerDeniedTest, utc_autofill_manager_denied_create_p)
+{
+    autofill_manager_h amh = NULL;
+    int ret = autofill_manager_create(&amh);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_PERMISSION_DENIED);
+
+    autofill_manager_destroy(amh);
+}
+
+/**
+ * @testcase        utc_autofill_manager_denied_create_n
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that creates autofill manager instance.
+ */
+TEST_F(AutofillManagerDeniedTest, utc_autofill_manager_denied_create_n)
+{
+    int ret = autofill_manager_create(NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_PERMISSION_DENIED);
+}
+
+/**
+ * @testcase        utc_autofill_manager_denied_destroy
+ * @since_tizen     5.5
+ * @description     Positive UTC of the function that destroys autofill manager instance.
+ */
+TEST_F(AutofillManagerDeniedTest, utc_autofill_manager_denied_destroy)
+{
+    int ret = autofill_manager_destroy(NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_PERMISSION_DENIED);
+}
+
+/**
+ * @testcase        utc_autofill_manager_denied_connect_n
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that connects to autofill daemon.
+ */
+TEST_F(AutofillManagerDeniedTest, utc_autofill_manager_denied_connect_n)
+{
+    int ret = autofill_manager_connect(NULL, NULL, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_PERMISSION_DENIED);
+}
+
+/**
+ * @testcase        utc_autofill_manager_denied_foreach_autofill_service_n1
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that retrieves each autofill service app id.
+ */
+TEST_F(AutofillManagerDeniedTest, utc_autofill_manager_denied_foreach_autofill_service_n)
+{
+    int ret = autofill_manager_foreach_autofill_service(NULL, NULL, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_PERMISSION_DENIED);
+}
+
+/**
+ * @testcase        utc_autofill_manager_denied_get_autofill_service_n1
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that gets the current used autofill service app id.
+ */
+TEST_F(AutofillManagerDeniedTest, utc_autofill_manager_denied_get_autofill_service_n)
+{
+    int ret = autofill_manager_get_autofill_service(NULL, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_PERMISSION_DENIED);
+}
+
+/**
+ * @testcase        utc_autofill_manager_denied_set_autofill_service_n1
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that sets which autofill service to use.
+ */
+TEST_F(AutofillManagerDeniedTest, utc_autofill_manager_denied_set_autofill_service_n)
+{
+    int ret = autofill_manager_set_autofill_service(NULL, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_PERMISSION_DENIED);
+}
diff --git a/tests/src/autofill_manager_unittest.cpp b/tests/src/autofill_manager_unittest.cpp
new file mode 100644 (file)
index 0000000..f1ee54e
--- /dev/null
@@ -0,0 +1,195 @@
+//
+// Copyright (c) 2014 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.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include <gtest/gtest.h>
+#include <autofill_manager.h>
+#include <app_manager.h>
+#include <glib.h>
+#include <Ecore.h>
+
+#include "cynara_mock.h"
+
+//& set: CapiUi-autofill-manager
+
+static autofill_manager_h g_amh = NULL;
+
+static bool autofill_service_info_cb(const char* app_id, void* user_data)
+{
+    app_info_h app_h;
+    char *label = NULL;
+
+    app_info_create(app_id, &app_h);
+    app_info_get_label(app_h, &label);
+
+    if (label)
+        free(label);
+
+    app_info_destroy(app_h);
+
+    return true;
+}
+
+class AutofillManagerTest : public testing::Test {
+    public:
+        virtual void SetUp() {
+            ecore_init();
+
+            cynara_check_set_result(CYNARA_API_ACCESS_ALLOWED);
+
+            autofill_manager_create(&g_amh);
+        }
+        virtual void TearDown() {
+            if (g_amh) {
+                autofill_manager_destroy(g_amh);
+            }
+
+            g_amh = NULL;
+            ecore_shutdown();
+        }
+};
+
+/**
+ * @testcase        utc_autofill_manager_create_p
+ * @since_tizen     5.5
+ * @description     Positive UTC of the function that creates autofill manager instance.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_create_p)
+{
+    autofill_manager_h amh = NULL;
+    int ret = autofill_manager_create(&amh);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_NONE);
+
+    autofill_manager_destroy(amh);
+}
+
+/**
+ * @testcase        utc_autofill_manager_create_n
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that creates autofill manager instance.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_create_n)
+{
+    int ret = autofill_manager_create(NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase        utc_autofill_manager_destroy_p
+ * @since_tizen     5.5
+ * @description     Positive UTC of the function that destroys autofill manager instance.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_destroy_p)
+{
+    autofill_manager_h amh = NULL;
+    int ret = autofill_manager_create(&amh);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_NONE);
+
+    ret = autofill_manager_destroy(amh);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_NONE);
+}
+
+/**
+ * @testcase        utc_autofill_manager_destroy_n
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that destroys autofill manager instance.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_destroy_n)
+{
+    int ret = autofill_manager_destroy(NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase        utc_autofill_manager_connect_n
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that connects to autofill daemon.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_connect_n)
+{
+    int ret = autofill_manager_connect(NULL, NULL, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase        utc_autofill_manager_foreach_autofill_service_n1
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that retrieves each autofill service app id.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_foreach_autofill_service_n1)
+{
+    int ret = autofill_manager_foreach_autofill_service(NULL, NULL, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase        utc_autofill_manager_foreach_autofill_service_n2
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that retrieves each autofill service app id.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_foreach_autofill_service_n2)
+{
+    int ret = autofill_manager_foreach_autofill_service(g_amh, autofill_service_info_cb, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_OPERATION_FAILED);
+}
+
+/**
+ * @testcase        utc_autofill_manager_get_autofill_service_n1
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that gets the current used autofill service app id.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_get_autofill_service_n1)
+{
+    int ret = autofill_manager_get_autofill_service(NULL, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase        utc_autofill_manager_get_autofill_service_n2
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that gets the current used autofill service app id.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_get_autofill_service_n2)
+{
+    char *active_autofill_service_appid = NULL;
+
+    int ret = autofill_manager_get_autofill_service(g_amh, &active_autofill_service_appid);
+    if (active_autofill_service_appid)
+    {
+        free(active_autofill_service_appid);
+    }
+    EXPECT_EQ(ret, AUTOFILL_ERROR_OPERATION_FAILED);
+}
+
+/**
+ * @testcase        utc_autofill_manager_set_autofill_service_n1
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that sets which autofill service to use.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_set_autofill_service_n1)
+{
+    int ret = autofill_manager_set_autofill_service(NULL, NULL);
+    EXPECT_EQ(ret, AUTOFILL_ERROR_INVALID_PARAMETER);
+}
+
+/**
+ * @testcase        utc_autofill_manager_set_autofill_service_n2
+ * @since_tizen     5.5
+ * @description     Negative UTC of the function that sets which autofill service to use.
+ */
+TEST_F(AutofillManagerTest, utc_autofill_manager_set_autofill_service_n2)
+{
+    int ret = autofill_manager_set_autofill_service(g_amh, "org.tizen.autofill-service");
+    EXPECT_EQ(ret, AUTOFILL_ERROR_OPERATION_FAILED);
+}
\ No newline at end of file
diff --git a/tests/src/cynara_mock.cpp b/tests/src/cynara_mock.cpp
new file mode 100644 (file)
index 0000000..ff6e88f
--- /dev/null
@@ -0,0 +1,34 @@
+#include "cynara_mock.h"
+#include <string.h>
+#include <stdio.h>
+#include <tizen.h>
+
+static int check_result = CYNARA_API_ACCESS_ALLOWED;
+
+void cynara_check_set_result(int result)
+{
+    check_result = result;
+}
+
+EXPORT_API int __wrap_cynara_initialize(cynara** c, const cynara_configuration* conf)
+{
+    *c = (void *)0x1;
+    return 0;
+}
+
+EXPORT_API int __wrap_cynara_finish(cynara* c)
+{
+    return 0;
+}
+
+EXPORT_API int __wrap_cynara_check(cynara* c, const char* client, const char* client_session,
+    const char* user,
+    const char* privilege)
+{
+    return check_result;
+}
+
+EXPORT_API char *__wrap_cynara_session_from_pid(pid_t pid)
+{
+    return strdup("session");
+}
diff --git a/tests/src/cynara_mock.h b/tests/src/cynara_mock.h
new file mode 100644 (file)
index 0000000..1becb42
--- /dev/null
@@ -0,0 +1,87 @@
+#ifndef MOCK_CYNARA_H_
+#define MOCK_CYNARA_H_
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void cynara;
+typedef void* cynara_configuration;
+
+/*! \brief  indicating that API call was interrupted by user*/
+#define CYNARA_API_INTERRUPTED                  4
+
+/*! \brief  indicating access that cannot be resolved without further actions*/
+#define CYNARA_API_ACCESS_NOT_RESOLVED          3
+
+/*! \brief   indicating access that was checked is allowed */
+#define CYNARA_API_ACCESS_ALLOWED               2
+
+/*! \brief   indicating that access that was checked is denied */
+#define CYNARA_API_ACCESS_DENIED                1
+
+/*! \brief   indicating the result of the one specific API is successful */
+#define CYNARA_API_SUCCESS                      0
+
+/*! \brief   indicating that value is not present in cache */
+#define CYNARA_API_CACHE_MISS                   -1
+
+/*! \brief   indicating that pending requests reached maximum */
+#define CYNARA_API_MAX_PENDING_REQUESTS         -2
+
+/*! \brief   indicating system is running out of memory state */
+#define CYNARA_API_OUT_OF_MEMORY                -3
+
+/*! \brief   indicating the API's parameter is malformed */
+#define CYNARA_API_INVALID_PARAM                -4
+
+/*! \brief   indicating that service is not available */
+#define CYNARA_API_SERVICE_NOT_AVAILABLE        -5
+
+/*! \brief   indicating that provided method is not supported by library */
+#define CYNARA_API_METHOD_NOT_SUPPORTED         -6
+
+/*! \brief   cynara service does not allow to perform requested operation */
+#define CYNARA_API_OPERATION_NOT_ALLOWED        -7
+
+/*! \brief   cynara service failed to perform requested operation */
+#define CYNARA_API_OPERATION_FAILED             -8
+
+/*! \brief   cynara service hasn't found requested bucket */
+#define CYNARA_API_BUCKET_NOT_FOUND             -9
+
+/*! \brief   indicating an unknown error */
+#define CYNARA_API_UNKNOWN_ERROR                -10
+
+/*! \brief   indicating configuration error */
+#define CYNARA_API_CONFIGURATION_ERROR          -11
+
+/*! \brief   indicating invalid parameter in command-line */
+#define CYNARA_API_INVALID_COMMANDLINE_PARAM    -12
+
+/*! \brief   indicating that provided buffer is too short */
+#define CYNARA_API_BUFFER_TOO_SHORT             -13
+
+/*! \brief   indicating that database is corrupted */
+#define CYNARA_API_DATABASE_CORRUPTED           -14
+
+/*! \brief   indicating that user doesn't have enough permission to perform action */
+#define CYNARA_API_PERMISSION_DENIED            -15
+
+void cynara_check_set_result(int result);
+
+int __wrap_cynara_initialize(cynara** c, const cynara_configuration* conf);
+int __wrap_cynara_finish(cynara* c);
+int __wrap_cynara_check(cynara* c, const char* client, const char* client_session,
+                        const char* user,
+                        const char* privilege);
+
+char *__wrap_cynara_session_from_pid(pid_t pid);
+
+#ifdef __cplusplus
+}
+#endif
+#endif  /* MOCK_CYNARA_H_ */