Improves code coverage and modify unittest package name 67/298967/2
authorInkyun Kil <inkyun.kil@samsung.com>
Mon, 18 Sep 2023 01:54:38 +0000 (10:54 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Mon, 18 Sep 2023 07:05:05 +0000 (16:05 +0900)
Change-Id: I0b0e714d8ae01b4274f64573e8c7b728f236205f
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
15 files changed:
packaging/libwidget_service.spec
parser/lib/widget_plugin_parser_db.cc
src/widget_instance.c
src/widget_service.c
unittest/mock/aul_mock.cc
unittest/mock/aul_mock.h
unittest/mock/pkgmgr-info_mock.cc
unittest/mock/pkgmgr-info_mock.h
unittest/mock/system_info_mock.cc
unittest/mock/system_info_mock.h
unittest/mock/vconf_mock.cc [new file with mode: 0644]
unittest/mock/vconf_mock.h [new file with mode: 0644]
unittest/src/test_widget_plugin_parser.cc
unittest/src/test_widget_service.cc
unittest/src/test_widget_service_instance.cc

index 709f7799c5a89c2cdd90914c2c83b8a2f468d3a1..353a6c7cc4439b76e410a66a5a5aba6d4d7f5d58 100644 (file)
@@ -175,16 +175,16 @@ else
 fi
 
 #################################################
-# widget_service_unittests
+# widget-service-unittests
 #################################################
-%package -n widget_service_unittests
+%package -n widget-service-unittests
 Summary:    GTest for widget_service
 Group:      Development/Libraries
 
-%description -n widget_service_unittests
+%description -n widget-service-unittests
 GTest for widget_service
 
-%files -n widget_service_unittests
+%files -n widget-service-unittests
 %{_bindir}/widget_service_unittests
 %{_bindir}/tizen-unittests/%{name}/run-unittest.sh
 
index 5fcd6bfd30b634849435db22da8ed300c132e169..859fe091fb1dd0189cf582008ee27328e82b9dc9 100644 (file)
@@ -90,7 +90,7 @@ std::string ConvertPath(const std::string& preview_path,
 
   return "";
 }
-
+/* LCOV_EXCL_START */
 bool BusyHandler(int count) {
   constexpr int BUSY_WAITING_USEC = 50000;
   constexpr int BUSY_WAITING_MAX = 20;
@@ -102,7 +102,7 @@ bool BusyHandler(int count) {
 
   return false;
 }
-
+/* LCOV_EXCL_STOP */
 int IsGlobal(uid_t uid) {
   constexpr int ROOT_USER = 0;
 
index 23a2ee576294907c94b189c7e6d0b300e93a1034..22a20cd12b001d2dfb1d5cfc2328fa3a52160659 100644 (file)
@@ -692,7 +692,6 @@ static int __check_valid_sender(char *widget_id, int pid)
        return -1;
 }
 
-/* LCOV_EXCL_START */
 static int __check_valid_sender_v2(const char *sender_pkgid)
 {
        char pkgid[256] = {0, };
@@ -721,7 +720,6 @@ static int __check_valid_sender_v2(const char *sender_pkgid)
 
        return -1;
 }
-/* LCOV_EXCL_STOP */
 
 static int __status_handler(const char *endpoint, aul_app_com_result_e e, bundle *envelope, void *user_data)
 {
index 4fc39ea532cc985f8908b86f4d864b5880e06183..64680ad20e55e2a1879b729f1ee19be7eb29e82f 100644 (file)
@@ -173,17 +173,21 @@ static int check_privilege(const char *privilege)
 
        fd = open("/proc/self/attr/current", O_RDONLY);
        if (fd < 0) {
+/* LCOV_EXCL_START */
                LOGE("open [%d] failed!", errno);
                ret = -1;
+/* LCOV_EXCL_STOP */
                goto out;
        }
 
        ret = read(fd, subject_label, SMACK_LABEL_LEN);
        if (ret < 0) {
+/* LCOV_EXCL_START */
                LOGE("read [%d] failed!", errno);
                close(fd);
                ret = -1;
                goto out;
+/* LCOV_EXCL_STOP */
        }
        close(fd);
 
@@ -284,7 +288,7 @@ static int __change_own(uid_t uid, const char *path)
                printf("chown fail %s", path);
                return WIDGET_ERROR_FAULT;
        }
-
+/* LCOV_EXCL_START */
        mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
        ret = chmod(path, mode);
        if (ret == -1) {
@@ -304,7 +308,7 @@ static int __change_own(uid_t uid, const char *path)
                printf("chmod failed : %s", path);
                return WIDGET_ERROR_FAULT;;
        }
-
+/* LCOV_EXCL_STOP */
        return WIDGET_ERROR_NONE;
 }
 
@@ -322,18 +326,22 @@ static int _recover_db(const char *path, uid_t uid, bool is_init)
                        SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE,
                        NULL);
        if (ret != SQLITE_OK) {
+/* LCOV_EXCL_START */
                _E("Failed to open db[%d]", ret);
                sqlite3_close_v2(db);
                unlink(path);
                return WIDGET_ERROR_FAULT;
+/* LCOV_EXCL_STOP */
        }
 
        ret = sqlite3_exec(db, CREATE_WIDGET_TABLE, NULL, NULL, &errmsg);
        sqlite3_close_v2(db);
        if (ret != SQLITE_OK) {
+/* LCOV_EXCL_START */
                _E("Failed to exec query[%d][%s]", ret, errmsg);
                sqlite3_free(errmsg);
                return WIDGET_ERROR_FAULT;
+/* LCOV_EXCL_STOP */
        }
 
        __change_smack(path);
@@ -355,9 +363,11 @@ static int _integrity_check(sqlite3 *db)
        ret = sqlite3_exec(db, "PRAGMA integrity_check",
                               _check_integrity_cb, NULL, &errmsg);
        if (ret != SQLITE_OK || _is_corrupted) {
+/* LCOV_EXCL_START */
                _E("Failed to exec query[%d][%s]", ret, errmsg);
                sqlite3_free(errmsg);
                return WIDGET_ERROR_FAULT;
+/* LCOV_EXCL_STOP */
        }
 
        return WIDGET_ERROR_NONE;
@@ -562,7 +572,7 @@ static char *_resolution_file_path(void)
 
        return path;
 }
-
+/* LCOV_EXCL_START */
 static void _resolution_update_size_list(int width_type, int height_type, int width, int height)
 {
        int idx = 0;
@@ -619,7 +629,7 @@ static void _resolution_update_size_list(int width_type, int height_type, int wi
 
        _I("size type(%d): %dx%d (%dx%d)\n", idx, width_type, height_type, width, height);
 }
-
+/* LCOV_EXCL_STOP */
 static int _resolution_update_from_file(void)
 {
        int width_type = 0;
@@ -638,7 +648,7 @@ static int _resolution_update_from_file(void)
        file_path = _resolution_file_path();
        if (file_path == NULL)
                return WIDGET_ERROR_OUT_OF_MEMORY;
-
+/* LCOV_EXCL_START */
        dic = iniparser_load(file_path);
        if (dic == NULL) {
                _E("fail to load [%s] ", file_path);
@@ -696,7 +706,7 @@ static int _resolution_update_from_file(void)
 
        return WIDGET_ERROR_NONE;
 }
-
+/* LCOV_EXCL_STOP */
 static int _get_supported_size_type(int width, int height, int *type)
 {
        int i;
@@ -868,25 +878,31 @@ static int _get_widget_supported_sizes(const char *widget_id, uid_t uid,
        sqlite3_reset(stmt);
        width = malloc(sizeof(int) * count);
        if (!width) {
+/* LCOV_EXCL_START */
                _E("Failed to allocate width");
                ret = WIDGET_ERROR_FAULT; /* It shoud be WIDGET_ERROR_OUT_OF_MEMORY */
                goto err;
+/* LCOV_EXCL_STOP */
        }
 
        height = malloc(sizeof(int) * count);
        if (!height) {
+/* LCOV_EXCL_START */
                _E("Failed to allocate height");
                ret = WIDGET_ERROR_FAULT; /* It should be WIDGET_ERROR_OUT_OF_MEMORY */
                goto err;
+/* LCOV_EXCL_STOP */
        }
 
        for (i = 0; i < count; i++) {
                ret = sqlite3_step(stmt);
                if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                        _E("sqlite3_step() is failed. err(%s)",
                                        sqlite3_errmsg(db));
                        ret = WIDGET_ERROR_FAULT;
                        goto err;
+/* LCOV_EXCL_STOP */
                }
                _get_column_int(stmt, 0, &width[i]);
                _get_column_int(stmt, 1, &height[i]);
@@ -963,23 +979,29 @@ static int _get_widget_supported_info(const char *widget_id, uid_t uid,
        sqlite3_reset(stmt);
        width = malloc(sizeof(int) * count);
        if (!width) {
+/* LCOV_EXCL_START */
                _E("Failed to allocate width");
                ret = WIDGET_ERROR_FAULT; /* It should be WIDGET_ERROR_OUT_OF_MEMORY */
                goto err;
+/* LCOV_EXCL_STOP */
        }
 
        height = malloc(sizeof(int) * count);
        if (!height) {
+/* LCOV_EXCL_START */
                _E("Failed to allocate height");
                ret = WIDGET_ERROR_FAULT; /* It should be WIDGET_ERROR_OUT_OF_MEMORY */
                goto err;
+/* LCOV_EXCL_STOP */
        }
 
        type = malloc(sizeof(int) * count);
        if (!type) {
+/* LCOV_EXCL_START */
                _E("Failed to allocate type");
                ret = WIDGET_ERROR_FAULT; /* It should be WIDGET_ERROR_OUT_OF_MEMORY */
                goto err;
+/* LCOV_EXCL_STOP */
        }
 
        for (i = 0; i < count; i++) {
@@ -1046,12 +1068,12 @@ EAPI int widget_service_change_period(const char *pkgname, const char *id, doubl
        widget_instance_h instance;
        struct widget_instance_info_s instance_info;
        int ret;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (!pkgname || !id || period < 0.0f) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -1084,12 +1106,12 @@ EAPI int widget_service_trigger_update(const char *widget_id, const char *id, bu
        int ret;
        bundle_raw *raw = NULL;
        int len;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (!widget_id) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -1184,12 +1206,12 @@ EAPI int widget_service_get_widget_list(widget_list_cb cb, void *data)
        GList *list = NULL;
        GList *tmp;
        struct widget_list_item *item;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (cb == NULL) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -1226,12 +1248,12 @@ EAPI int widget_service_get_widget_list_by_pkgid(const char *pkgid,
        GList *list = NULL;
        GList *tmp;
        struct widget_list_item *item;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (pkgid == NULL || cb == NULL) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -1290,6 +1312,7 @@ static char *_get_main_app_id(const char *widget_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+               /* LCOV_EXCL_START */
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -1300,6 +1323,7 @@ static char *_get_main_app_id(const char *widget_id, uid_t uid)
                sqlite3_finalize(stmt);
                sqlite3_close_v2(db);
                return NULL;
+               /* LCOV_EXCL_STOP */
        }
 
        _get_column_str(stmt, 0, &pkgid);
@@ -1333,13 +1357,13 @@ static char *_get_main_app_id(const char *widget_id, uid_t uid)
 EAPI char *widget_service_get_main_app_id(const char *widget_id)
 {
        char *appid;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
                return NULL;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL) {
                _E("invalid parameter");
                set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
@@ -1370,12 +1394,12 @@ EAPI int widget_service_get_supported_size_types(const char *widget_id,
        int ret;
        int *width = NULL;
        int *height = NULL;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL || cnt == NULL || types == NULL) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -1460,13 +1484,13 @@ static char *_get_app_id_of_setup_app(const char *widget_id, uid_t uid)
 EAPI char *widget_service_get_app_id_of_setup_app(const char *widget_id)
 {
        char *appid;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
                return NULL;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL) {
                _E("invalid parameter");
                set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
@@ -1509,16 +1533,19 @@ static int _get_nodisplay(const char *widget_id, uid_t uid)
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
+/* LCOV_EXCL_START */
                _E("prepare error: %s", sqlite3_errmsg(db));
                sqlite3_close_v2(db);
                set_last_result(WIDGET_ERROR_FAULT);
                return 0;
+/* LCOV_EXCL_STOP */
        }
 
        sqlite3_bind_text(stmt, 1, widget_id, -1, SQLITE_STATIC);
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -1529,6 +1556,7 @@ static int _get_nodisplay(const char *widget_id, uid_t uid)
                sqlite3_finalize(stmt);
                sqlite3_close_v2(db);
                return 0;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_int(stmt, 0, &nodisplay);
@@ -1556,15 +1584,18 @@ static int _get_update_period(const char *widget_id, uid_t uid, double *period)
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
+/* LCOV_EXCL_START */
                _E("prepare error: %s", sqlite3_errmsg(db));
                sqlite3_close_v2(db);
                return WIDGET_ERROR_FAULT;
+/* LCOV_EXCL_STOP */
        }
 
        sqlite3_bind_text(stmt, 1, widget_id, -1, SQLITE_STATIC);
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                if (ret == SQLITE_DONE) {
                        ret = WIDGET_ERROR_NOT_EXIST;
                } else {
@@ -1574,6 +1605,7 @@ static int _get_update_period(const char *widget_id, uid_t uid, double *period)
                sqlite3_finalize(stmt);
                sqlite3_close_v2(db);
                return ret;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_double(stmt, 0, period);
@@ -1602,13 +1634,13 @@ int widget_service_get_update_period(const char *widget_id, double *period)
 EAPI int widget_service_get_nodisplay(const char *widget_id)
 {
        int nodisplay;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
                return 0;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL) {
                _E("invalid parameter");
                set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
@@ -1637,11 +1669,12 @@ EAPI int widget_service_get_nodisplay(const char *widget_id)
 /* deprecated, always return need_of_frame as false */
 EAPI int widget_service_get_need_of_frame(const char *pkgid, widget_size_type_e size_type, bool *need_of_frame)
 {
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (!pkgid) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -1658,11 +1691,12 @@ EAPI int widget_service_get_need_of_frame(const char *pkgid, widget_size_type_e
 /* deprecated, always return need_of_touch_event as false */
 EAPI int widget_service_get_need_of_touch_effect(const char *pkgid, widget_size_type_e size_type, bool *need_of_touch_event)
 {
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (!pkgid) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -1679,11 +1713,12 @@ EAPI int widget_service_get_need_of_touch_effect(const char *pkgid, widget_size_
 /* deprecated, always return need_of_mouse_event as false */
 EAPI int widget_service_get_need_of_mouse_event(const char *pkgid, widget_size_type_e size_type, bool *need_of_mouse_event)
 {
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (!pkgid) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -1729,6 +1764,7 @@ static char *_get_preview_image_path(const char *widget_id, int width,
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -1739,6 +1775,7 @@ static char *_get_preview_image_path(const char *widget_id, int width,
                sqlite3_finalize(stmt);
                sqlite3_close_v2(db);
                return NULL;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_str(stmt, 0, &path);
@@ -1811,13 +1848,13 @@ EAPI char *widget_service_get_preview_image_path(const char *widget_id,
        int buf_len;
        int i;
        int printed;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
                return NULL;
        }
-
+/* LCOV_EXCL_STOP */
        /* TODO: validate size_type */
        if (widget_id == NULL) {
                _E("invalid parameter");
@@ -1908,6 +1945,7 @@ static char *_get_main_widget_id(const char *pkg_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                if (ret != SQLITE_DONE)
                        _E("step error: %s", sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
@@ -1916,6 +1954,7 @@ static char *_get_main_widget_id(const char *pkg_id, uid_t uid)
                set_last_result(ret == SQLITE_DONE ? WIDGET_ERROR_NOT_EXIST :
                                WIDGET_ERROR_FAULT);
                return NULL;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_str(stmt, 0, &widget_id);
@@ -1963,6 +2002,7 @@ static char *_get_icon(const char *widget_id, const char *lang, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                if (ret != SQLITE_DONE)
                        _E("step error: %s", sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
@@ -1971,6 +2011,7 @@ static char *_get_icon(const char *widget_id, const char *lang, uid_t uid)
                set_last_result(ret == SQLITE_DONE ? WIDGET_ERROR_NOT_EXIST :
                                WIDGET_ERROR_FAULT);
                return NULL;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_str(stmt, 0, &icon);
@@ -1987,13 +2028,13 @@ EAPI char *widget_service_get_icon(const char *pkgid, const char *lang)
 {
        char *icon;
        char *widget_id;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
                return NULL;
        }
-
+/* LCOV_EXCL_STOP */
        if (pkgid == NULL) {
                _E("invalid parameter");
                set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
@@ -2058,6 +2099,7 @@ static char *_get_name(const char *widget_id, const char *lang, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                if (ret != SQLITE_DONE)
                        _E("step error: %s", sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
@@ -2066,6 +2108,7 @@ static char *_get_name(const char *widget_id, const char *lang, uid_t uid)
                set_last_result(ret == SQLITE_DONE ? WIDGET_ERROR_NOT_EXIST :
                                WIDGET_ERROR_FAULT);
                return NULL;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_str(stmt, 0, &label);
@@ -2110,12 +2153,13 @@ EAPI char *widget_service_get_name(const char *widget_id, const char *lang)
        char *name;
        char *language;
 
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
                return NULL;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL) {
                _E("invalid parameter");
                set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
@@ -2159,12 +2203,12 @@ EAPI int widget_service_get_supported_sizes(const char *widget_id, int *cnt,
                int **w, int **h)
 {
        int ret;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL || cnt == NULL || w == NULL || h == NULL) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2221,6 +2265,7 @@ static char *_get_widget_id(const char *appid, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                _E("step error: %s", sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
                sqlite3_close_v2(db);
@@ -2228,6 +2273,7 @@ static char *_get_widget_id(const char *appid, uid_t uid)
                set_last_result(ret == SQLITE_DONE ? WIDGET_ERROR_NOT_EXIST :
                                WIDGET_ERROR_FAULT);
                return NULL;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_str(stmt, 0, &classid);
@@ -2287,7 +2333,7 @@ static char *__get_widget_main_appid_from_pkgid_or_appid(const char *id)
 
        if (widget_list == NULL)
                goto end;
-
+/* LCOV_EXCL_START */
        iter = g_list_first(widget_list);
        while (iter) {
                item = (struct widget_list_item *)iter->data;
@@ -2308,7 +2354,7 @@ static char *__get_widget_main_appid_from_pkgid_or_appid(const char *id)
                        free(item);
                }
        }
-
+/* LCOV_EXCL_STOP */
 end:
        if (pkginfo)
                pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
@@ -2324,13 +2370,13 @@ EAPI char *widget_service_get_widget_id(const char *appid)
 {
        char *classid;
        char *widget_id;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
                return NULL;
        }
-
+/* LCOV_EXCL_STOP */
        if (appid == NULL) {
                _E("invalid parameter");
                set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
@@ -2402,6 +2448,7 @@ static char *_get_package_id(const char *widget_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                /* TODO: which error should be set? */
                if (ret == SQLITE_DONE) {
                        set_last_result(WIDGET_ERROR_NOT_EXIST);
@@ -2412,6 +2459,7 @@ static char *_get_package_id(const char *widget_id, uid_t uid)
                sqlite3_finalize(stmt);
                sqlite3_close_v2(db);
                return NULL;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_str(stmt, 0, &pkgid);
@@ -2427,13 +2475,13 @@ static char *_get_package_id(const char *widget_id, uid_t uid)
 EAPI char *widget_service_get_package_id(const char *widget_id)
 {
        char *pkgid;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                set_last_result(WIDGET_ERROR_NOT_SUPPORTED);
                return NULL;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL) {
                _E("invalid parameter");
                set_last_result(WIDGET_ERROR_INVALID_PARAMETER);
@@ -2461,11 +2509,12 @@ EAPI char *widget_service_get_package_id(const char *widget_id)
 EAPI int widget_service_get_size(widget_size_type_e type, int *width,
                int *height)
 {
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (width == NULL || height == NULL) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2480,11 +2529,12 @@ EAPI int widget_service_get_size(widget_size_type_e type, int *width,
 EAPI int widget_service_get_size_type(int width, int height,
                widget_size_type_e *size_type)
 {
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (width <= 0 || height <= 0 || size_type == NULL) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2500,12 +2550,12 @@ EAPI int widget_service_get_content_of_widget_instance(const char *widget_id, co
 {
        char *raw = NULL;
        int ret;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL || widget_instance_id == NULL || b == NULL) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2570,12 +2620,12 @@ EAPI int widget_service_get_widget_instance_list(const char *widget_id, widget_i
        cb_data.cb = cb;
        cb_data.data = data;
        cb_data.cnt = 0;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL || cb == NULL) {
                _E("inavlid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2615,12 +2665,12 @@ EAPI int widget_service_set_lifecycle_event_cb(const char *widget_id, widget_lif
        int ret = WIDGET_ERROR_NONE;
        struct lifecycle_s *cb_info;
        GList *head = lifecycle_cbs;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (cb == NULL) {
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2668,12 +2718,12 @@ EAPI int widget_service_unset_lifecycle_event_cb(const char *widget_id, void **u
        struct lifecycle_s *cb_info;
        struct lifecycle_s *found = NULL;
        GList *head = lifecycle_cbs;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        while (head) {
                cb_info = (struct lifecycle_s *)head->data;
                if (cb_info && widget_id && cb_info->widget_id) {
@@ -2731,6 +2781,7 @@ static int __get_max_instance(const char *widget_id, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                if (ret == SQLITE_DONE) {
                        ret = WIDGET_ERROR_NOT_EXIST;
                } else {
@@ -2740,6 +2791,7 @@ static int __get_max_instance(const char *widget_id, uid_t uid)
                sqlite3_finalize(stmt);
                sqlite3_close_v2(db);
                return ret;
+/* LCOV_EXCL_STOP */
        }
 
        _get_column_int(stmt, 0, &max_instance);
@@ -2754,12 +2806,12 @@ static int __get_max_instance(const char *widget_id, uid_t uid)
 EAPI int widget_service_get_widget_max_count(const char *widget_id)
 {
        int ret;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("Not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL) {
                _E("Invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2779,12 +2831,12 @@ EAPI int widget_service_get_widget_max_count(const char *widget_id)
 EAPI int widget_service_get_instance_count(const char *widget_id, const char *cluster, const char *category)
 {
        int ret;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("Not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL) {
                _E("Invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2804,12 +2856,12 @@ EAPI int widget_service_set_widget_disabled(const char *widget_id,
                bool disabled)
 {
        int ret;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("Not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL) {
                _E("Invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2861,6 +2913,7 @@ static int _get_disable(const char *widget_id, bool *is_disabled, uid_t uid)
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
+/* LCOV_EXCL_START */
                if (ret == SQLITE_DONE) {
                        ret = WIDGET_ERROR_NOT_EXIST;
                } else {
@@ -2871,6 +2924,7 @@ static int _get_disable(const char *widget_id, bool *is_disabled, uid_t uid)
                sqlite3_finalize(stmt);
                sqlite3_close_v2(db);
                return ret;
+/* LCOV_EXCL_STOP */
        }
        _get_column_int(stmt, 0, &disable);
 
@@ -2887,12 +2941,12 @@ EAPI int widget_service_get_widget_disabled(const char *widget_id,
                bool *is_disabled)
 {
        int ret;
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("Not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (widget_id == NULL || is_disabled == NULL) {
                _E("Invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
@@ -2937,12 +2991,12 @@ EAPI int widget_service_set_disable_event_cb(widget_disable_event_cb callback,
                _E("invalid parameter");
                return WIDGET_ERROR_INVALID_PARAMETER;
        }
-
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("Not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (check_privilege("http://tizen.org/privilege/widget.viewer") < 0)
                return WIDGET_ERROR_PERMISSION_DENIED;
 
@@ -2960,11 +3014,12 @@ EAPI int widget_service_set_disable_event_cb(widget_disable_event_cb callback,
 
 EAPI int widget_service_unset_disable_event_cb(void)
 {
+/* LCOV_EXCL_START */
        if (!_is_widget_feature_enabled()) {
                _E("not supported");
                return WIDGET_ERROR_NOT_SUPPORTED;
        }
-
+/* LCOV_EXCL_STOP */
        if (check_privilege("http://tizen.org/privilege/widget.viewer") < 0)
                return WIDGET_ERROR_PERMISSION_DENIED;
 
index 4fa9ce0aea5f10527ff37c6e4889dbf9c74b656a..703cf97d7474800092122a350a3f4b6f8b64496a 100644 (file)
@@ -65,4 +65,8 @@ extern "C" int aul_app_com_create(const char* arg1,
     aul_app_com_permission_h arg2, app_com_cb arg3, void* arg4,
     aul_app_com_connection_h* arg5) {
   return MOCK_HOOK_P5(AulMock, aul_app_com_create, arg1, arg2, arg3, arg4, arg5);
+}
+
+extern "C" int aul_app_get_pkgid_bypid(int pid, char *pkgid, int len) {
+  return MOCK_HOOK_P3(AulMock, aul_app_get_pkgid_bypid, pid, pkgid, len);
 }
\ No newline at end of file
index 5d2587c0f51689d16a06117546cc4aa6c3ca9467..d7751cdd37577db87c9f123eca43911d7c450b77 100644 (file)
@@ -43,6 +43,7 @@ class AulMock : public virtual ModuleMock {
     const char *, char **));
   MOCK_METHOD5(aul_app_com_create, int (const char *, aul_app_com_permission_h,
     app_com_cb, void *, aul_app_com_connection_h *));
+  MOCK_METHOD3(aul_app_get_pkgid_bypid, int (int , char *, int));
 
 };
 
index d9ab1d5584d7302ea9f4db435f8153292044dbc9..37e849149dd37c8b676c675fbf65cf1be2afbb6a 100644 (file)
@@ -40,3 +40,20 @@ extern "C" int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle,
   return MOCK_HOOK_P2(PkgMgrInfoMock, pkgmgrinfo_pkginfo_get_root_path, handle,
       root_path);
 }
+
+extern "C" int pkgmgrinfo_pkginfo_get_pkginfo(const char* arg1,
+    pkgmgrinfo_pkginfo_h* arg2) {
+  return MOCK_HOOK_P2(PkgMgrInfoMock, pkgmgrinfo_pkginfo_get_pkginfo,
+      arg1, arg2);
+}
+
+extern "C" int pkgmgrinfo_appinfo_get_appinfo(const char* arg1,
+    pkgmgrinfo_appinfo_h* arg2) {
+  return MOCK_HOOK_P2(PkgMgrInfoMock, pkgmgrinfo_appinfo_get_appinfo,
+      arg1, arg2);
+}
+
+extern "C" int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h arg1,
+    char** arg2) {
+  return MOCK_HOOK_P2(PkgMgrInfoMock, pkgmgrinfo_appinfo_get_pkgid, arg1, arg2);
+}
\ No newline at end of file
index 6274d4e9df126ac7f42d02d993fa4056fce1cd54..5c2960670c9dc61e19fa5d7d5eef86277bb46efd 100644 (file)
@@ -34,6 +34,12 @@ class PkgMgrInfoMock : public virtual ModuleMock {
       int (pkgmgrinfo_pkginfo_h));
   MOCK_METHOD2(pkgmgrinfo_pkginfo_get_root_path,
       int (pkgmgrinfo_pkginfo_h, char**));
+  MOCK_METHOD2(pkgmgrinfo_pkginfo_get_pkginfo,
+      int (const char*, pkgmgrinfo_pkginfo_h*));
+  MOCK_METHOD2(pkgmgrinfo_appinfo_get_appinfo,
+      int (const char*, pkgmgrinfo_appinfo_h*));
+  MOCK_METHOD2(pkgmgrinfo_appinfo_get_pkgid,
+      int (pkgmgrinfo_appinfo_h, char**));
 };
 
 #endif  // UNIT_TESTS_MOCK_PKGMGR_INFO_MOCK_H_
\ No newline at end of file
index 9d83ca3dae9b5f7787e94b26a3ef2f1c47ced388..e0f6a5529216bed0afbb27bbee8cf382bfa29c63 100644 (file)
@@ -25,4 +25,8 @@ extern "C" uid_t getuid(void) {
 
 extern "C" int system_info_get_platform_bool(const char* arg1, bool* arg2) {
   return MOCK_HOOK_P2(SystemInfoMock, system_info_get_platform_bool, arg1, arg2);
+}
+
+extern "C" int system_info_get_platform_int(const char* arg1, int* arg2) {
+  return MOCK_HOOK_P2(SystemInfoMock, system_info_get_platform_int, arg1, arg2);
 }
\ No newline at end of file
index 3d24290b226dbdb188d4d3f17863d64e5172e076..58c07617fdd2e266e32cd717c41560eef74dd39b 100644 (file)
@@ -32,6 +32,7 @@ class SystemInfoMock : public virtual ModuleMock {
 
   MOCK_METHOD0(getuid, uid_t (void));
   MOCK_METHOD2(system_info_get_platform_bool, int (const char*, bool*));
+  MOCK_METHOD2(system_info_get_platform_int, int (const char*, int*));
 };
 
 #endif  // UNIT_TESTS_MOCK_SYSTEM_INFO_MOCK_H_
\ No newline at end of file
diff --git a/unittest/mock/vconf_mock.cc b/unittest/mock/vconf_mock.cc
new file mode 100644 (file)
index 0000000..758ffbf
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ * 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 "vconf_mock.h"
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" char* vconf_get_str(const char* in_key) {
+  return MOCK_HOOK_P1(VconfMock, vconf_get_str, in_key);
+}
diff --git a/unittest/mock/vconf_mock.h b/unittest/mock/vconf_mock.h
new file mode 100644 (file)
index 0000000..b5f3835
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ * 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.
+ */
+
+#ifndef UNIT_TESTS_MOCK_VCONF_MOCK_H_
+#define UNIT_TESTS_MOCK_VCONF_MOCK_H_
+
+#include <vconf.h>
+#include <gmock/gmock.h>
+
+#include "module_mock.h"
+
+class VconfMock : public virtual ModuleMock {
+ public:
+  virtual ~VconfMock() {}
+
+  MOCK_METHOD1(vconf_get_str, char* (const char*));
+};
+
+#endif  // MOCK_VCONF_MOCUNIT_TESTS_MOCK_VCONF_MOCK_H__H_
\ No newline at end of file
index e4d9fa0fa0f906f7ed64038dedd65c7f37a3d0cd..e2595adc7c99933c606b02724a9411a3135747a7 100644 (file)
@@ -32,7 +32,6 @@
 using ::testing::_;
 using ::testing::DoAll;
 using ::testing::Invoke;
-using ::testing::SetArgPointee;
 using ::testing::Return;
 
 namespace {
index 714dacf35248a0ceb400ab57e97b4ab162fcae69..8e718d1fe155b5723d63225e02ceb9f39de74e6b 100644 (file)
 #include <stdio.h>
 #include <sqlite3.h>
 #include <dlfcn.h>
+#include <unistd.h>
+#include <fcntl.h>
 
+#include "include/widget_instance.h"
 #include "include/widget_service.h"
 #include "include/widget_errno.h"
 #include "include/widget_service_internal.h"
@@ -29,6 +32,7 @@
 #include "glib_mock.h"
 #include "tzplatform_config_mock.h"
 #include "pkgmgr-info_mock.h"
+#include "vconf_mock.h"
 #include "test_fixture.h"
 #include "widget_plugin_parser.hh"
 #include "widget_plugin_parser_error.h"
@@ -36,7 +40,7 @@
 using ::testing::_;
 using ::testing::DoAll;
 using ::testing::Invoke;
-using ::testing::SetArgPointee;
+using ::testing::InvokeArgument;
 using ::testing::Return;
 
 namespace {
@@ -143,12 +147,23 @@ int __fake_pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle) {
   return PMINFO_R_OK;
 }
 
+int __fake_system_info_get_platform_int1(const char *key, int *val) {
+  *val = 320;
+  return SYSTEM_INFO_ERROR_NONE;
+}
+
+int __fake_system_info_get_platform_int2(const char *key, int *val) {
+  *val = 480;
+  return SYSTEM_INFO_ERROR_NONE;
+}
+
 class Mocks : virtual public ::testing::NiceMock<AulMock>,
     virtual public ::testing::NiceMock<CynaraMock>,
     virtual public ::testing::NiceMock<GlibMock>,
     virtual public ::testing::NiceMock<PkgMgrInfoMock>,
     virtual public ::testing::NiceMock<SystemInfoMock>,
-    virtual public ::testing::NiceMock<TzplatformConfigMock> {};
+    virtual public ::testing::NiceMock<TzplatformConfigMock>,
+    virtual public ::testing::NiceMock<VconfMock> {};
 
 constexpr char XML1[] = R"__widget(<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <manifest xmlns="http://tizen.org/ns/packages" api-version="5.5" package="org.tizen.gallery_common" version="1.0.0">
@@ -177,7 +192,6 @@ constexpr char XML1[] = R"__widget(<?xml version="1.0" encoding="UTF-8" standalo
     </widget-application>
 </manifest>
 )__widget";
-
 }  // namespace
 
 class WidgetServiceTest : public TestFixture {
@@ -248,6 +262,23 @@ TEST_F(WidgetServiceTest, GetDisabled) {
   ASSERT_EQ(ret, WIDGET_ERROR_NONE);
 }
 
+TEST_F(WidgetServiceTest, GetDisabled_N) {
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
+      .WillOnce(Return(1));
+
+  int ret = WIDGET_ERROR_NONE;
+  bool is_disabled;
+
+  ret = widget_service_get_widget_disabled(NULL,
+      &is_disabled);
+  ASSERT_EQ(ret, WIDGET_ERROR_INVALID_PARAMETER);
+
+  ret = widget_service_get_widget_disabled("org.tizen.gallery.widget",
+      &is_disabled);
+  ASSERT_EQ(ret, WIDGET_ERROR_PERMISSION_DENIED);
+}
+
+
 void _widget_disable_event_cb(const char *widget_id, bool is_disabled, void *user_data) {
 }
 
@@ -277,8 +308,13 @@ TEST_F(WidgetServiceTest, UnsetDisabledEventCallback) {
       .WillRepeatedly(Invoke(__fake_cynara_check));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
       .WillRepeatedly(Invoke(__fake_cynara_finish));
+
+  bundle *b = bundle_create();
+  bundle_add_str(b, AUL_K_WIDGET_DISABLE, "1");
+  bundle_add_str(b, AUL_K_WIDGET_ID, "widget_id");
   EXPECT_CALL(GetMock<AulMock>(), aul_app_com_create(_, _, _, _, _))
-      .WillRepeatedly(Invoke(__fake_aul_app_com_create));
+      .WillOnce(DoAll(InvokeArgument<2>("end", AUL_APP_COM_R_OK, b, nullptr),
+      Return(0)));
   EXPECT_CALL(GetMock<AulMock>(), aul_app_com_leave(_))
       .WillRepeatedly(Invoke(__fake_aul_app_com_leave));
 
@@ -287,14 +323,20 @@ TEST_F(WidgetServiceTest, UnsetDisabledEventCallback) {
   ret = widget_service_set_disable_event_cb(_widget_disable_event_cb, NULL);
   ret = widget_service_unset_disable_event_cb();
   ASSERT_EQ(ret, WIDGET_ERROR_NONE);
+  bundle_free(b);
 }
 
 TEST_F(WidgetServiceTest, GetSize) {
+  int width, height;
+
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_int(_, _))
+      .Times(2)
+      .WillOnce(Invoke(__fake_system_info_get_platform_int1))
+      .WillOnce(Invoke(__fake_system_info_get_platform_int2));
 
   int ret;
-  int width, height;
 
   ret = widget_service_get_size(WIDGET_SIZE_TYPE_4x4, &width, &height);
   ASSERT_EQ(ret, WIDGET_ERROR_NONE);
@@ -303,6 +345,8 @@ TEST_F(WidgetServiceTest, GetSize) {
 TEST_F(WidgetServiceTest, GetSizeType) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_int(_, _))
+      .WillRepeatedly(Return(0));
 
   int ret;
   widget_size_type_e type;
@@ -384,6 +428,17 @@ TEST_F(WidgetServiceTest, TriggerUpdate) {
   ASSERT_EQ(ret, WIDGET_ERROR_NONE);
 }
 
+TEST_F(WidgetServiceTest, TriggerUpdate_N1) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+
+  int ret;
+
+  ret = widget_service_trigger_update(NULL,
+      "org.tizen.gallery.widget", NULL, 1);
+  ASSERT_EQ(ret, WIDGET_ERROR_INVALID_PARAMETER);
+}
+
 TEST_F(WidgetServiceTest, ChangePeriod) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
@@ -397,6 +452,17 @@ TEST_F(WidgetServiceTest, ChangePeriod) {
   ASSERT_EQ(ret, WIDGET_ERROR_NONE);
 }
 
+TEST_F(WidgetServiceTest, ChangePeriod_N2) {
+   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+
+  int ret;
+
+  ret = widget_service_change_period(NULL,
+      "org.tizen.gallery.widget", 1.0);
+  ASSERT_EQ(ret, WIDGET_ERROR_INVALID_PARAMETER);
+}
+
 int _widget_list_cb(const char *pkgid, const char *widget_id, int is_prime, void *user_data) {
   return 0;
 }
@@ -419,6 +485,28 @@ TEST_F(WidgetServiceTest, GetWidgetList) {
   ASSERT_EQ(ret, 1);
 }
 
+TEST_F(WidgetServiceTest, GetWidgetList_N1) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+
+  int ret;
+
+  ret = widget_service_get_widget_list(NULL, NULL);
+  ASSERT_EQ(ret, WIDGET_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(WidgetServiceTest, GetWidgetList_N3) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
+      .WillRepeatedly(Return(1));
+
+  int ret;
+
+  ret = widget_service_get_widget_list(_widget_list_cb, NULL);
+  ASSERT_EQ(ret, WIDGET_ERROR_PERMISSION_DENIED);
+}
+
 TEST_F(WidgetServiceTest, GetMainAppId) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
@@ -444,6 +532,22 @@ TEST_F(WidgetServiceTest, GetMainAppId) {
   ASSERT_STREQ(p.get(), "org.tizen.mainappid");
 }
 
+TEST_F(WidgetServiceTest, GetMainAppId_N1) {
+  char *app_id = NULL;
+
+  app_id = widget_service_get_main_app_id(NULL);
+  ASSERT_STREQ(app_id, NULL);
+}
+
+TEST_F(WidgetServiceTest, GetMainAppId_N2) {
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
+      .WillRepeatedly(Return(1));
+  char *app_id = NULL;
+
+  app_id = widget_service_get_main_app_id("org.tizen.gallery.widget");
+  ASSERT_STREQ(app_id, NULL);
+}
+
 int _widget_list_by_pkgid_cb(const char *widget_id, int is_prime, void *user_data) {
   return 0;
 }
@@ -465,6 +569,17 @@ TEST_F(WidgetServiceTest, GetWidgetListByPkgId) {
   ASSERT_EQ(ret, WIDGET_ERROR_NONE);
 }
 
+TEST_F(WidgetServiceTest, GetWidgetListByPkgId_N1) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+
+  int ret;
+
+  ret = widget_service_get_widget_list_by_pkgid(NULL,
+      _widget_list_by_pkgid_cb, NULL);
+  ASSERT_EQ(ret, WIDGET_ERROR_INVALID_PARAMETER);
+}
+
 TEST_F(WidgetServiceTest, GetWidgetId) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
@@ -490,6 +605,45 @@ TEST_F(WidgetServiceTest, GetWidgetId) {
   ASSERT_STREQ(p.get(), "org.tizen.gallery.widget");
 }
 
+TEST_F(WidgetServiceTest, GetWidgetId_N) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
+      .Times(2)
+      .WillOnce(Invoke(__fake_cynara_initialize))
+      .WillOnce(Return(1));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
+      .WillRepeatedly(Invoke(__fake_cynara_check));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
+      .WillRepeatedly(Invoke(__fake_cynara_finish));
+  EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
+      .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
+  EXPECT_CALL(GetMock<PkgMgrInfoMock>(), pkgmgrinfo_pkginfo_get_pkginfo(_, _))
+      .Times(2)
+      .WillOnce(Return(1))
+      .WillOnce(Return(0));
+  EXPECT_CALL(GetMock<PkgMgrInfoMock>(), pkgmgrinfo_appinfo_get_appinfo(_, _))
+      .WillRepeatedly(Return(0));
+  EXPECT_CALL(GetMock<PkgMgrInfoMock>(), pkgmgrinfo_appinfo_get_pkgid(_, _))
+      .WillRepeatedly(Invoke([](pkgmgrinfo_appinfo_h info, char **pkgid) -> int {
+        *pkgid = (char *)"org.tizen.gallery.widget";
+        return 0;
+      }));
+
+
+  char *widget_id = NULL;
+
+  widget_id = widget_service_get_widget_id("org.tizen.gallery.widget_invalid");
+  auto p = std::unique_ptr<char, decltype(std::free)*>(widget_id, std::free);
+  EXPECT_NE(p.get(), "org.tizen.gallery.widget");
+
+  widget_id = widget_service_get_widget_id("org.tizen.gallery.widget_invalid");
+  ASSERT_EQ(widget_id, nullptr);
+
+  widget_id = widget_service_get_widget_id(NULL);
+  ASSERT_EQ(widget_id, nullptr);
+}
+
 TEST_F(WidgetServiceTest, GetAppIdOfSetupApp) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
@@ -506,15 +660,42 @@ TEST_F(WidgetServiceTest, GetAppIdOfSetupApp) {
 
   app_id = widget_service_get_app_id_of_setup_app("org.tizen.gallery.widget");
   auto p = std::unique_ptr<char, decltype(std::free)*>(app_id, std::free);
-
   ASSERT_STREQ(p.get(), "org.tizen.setup_appid");
 }
 
+TEST_F(WidgetServiceTest, GetAppIdOfSetupApp_N) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
+      .Times(2)
+      .WillOnce(Invoke(__fake_cynara_initialize))
+      .WillOnce(Return(1));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
+      .WillRepeatedly(Invoke(__fake_cynara_check));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
+      .WillRepeatedly(Invoke(__fake_cynara_finish));
+  EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
+      .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
+
+  char *app_id = NULL;
+
+  app_id = widget_service_get_app_id_of_setup_app("org.tizen.gallery.widget_inv");
+  ASSERT_EQ(app_id, nullptr);
+
+  app_id = widget_service_get_app_id_of_setup_app(NULL);
+  ASSERT_EQ(app_id, nullptr);
+
+  app_id = widget_service_get_app_id_of_setup_app("org.tizen.gallery.widget");
+  ASSERT_EQ(app_id, nullptr);
+}
+
 TEST_F(WidgetServiceTest, GetPackageId) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
-      .WillRepeatedly(Invoke(__fake_cynara_initialize));
+      .Times(2)
+      .WillOnce(Invoke(__fake_cynara_initialize))
+      .WillOnce(Return(1));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
       .WillRepeatedly(Invoke(__fake_cynara_check));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
@@ -527,13 +708,22 @@ TEST_F(WidgetServiceTest, GetPackageId) {
   package_id = widget_service_get_package_id("org.tizen.gallery.widget");
   auto p = std::unique_ptr<char, decltype(std::free)*>(package_id, std::free);
   ASSERT_STREQ(p.get(), "org.tizen.gallery_common");
+
+  //For code coverage
+  package_id = widget_service_get_package_id("org.tizen.gallery.widget");
+  ASSERT_EQ(package_id, nullptr);
+
+  package_id = widget_service_get_package_id(NULL);
+  ASSERT_EQ(package_id, nullptr);
 }
 
 TEST_F(WidgetServiceTest, GetName) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
-      .WillRepeatedly(Invoke(__fake_cynara_initialize));
+      .Times(2)
+      .WillOnce(Invoke(__fake_cynara_initialize))
+      .WillOnce(Return(1));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
       .WillRepeatedly(Invoke(__fake_cynara_check));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
@@ -546,9 +736,16 @@ TEST_F(WidgetServiceTest, GetName) {
   name = widget_service_get_name("org.tizen.gallery.widget", "en-us");
   auto p = std::unique_ptr<char, decltype(std::free)*>(name, std::free);
   ASSERT_STREQ(p.get(), "Gallery");
+
+  // For code coverage
+  name = widget_service_get_name(NULL, "en-us");
+  ASSERT_EQ(name, nullptr);
+
+  name = widget_service_get_name("org.tizen.gallery.widget", "en-us");
+  ASSERT_EQ(name, nullptr);
 }
 
-TEST_F(WidgetServiceTest, GetPreviewImagePath) {
+TEST_F(WidgetServiceTest, GetName2) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
@@ -559,6 +756,33 @@ TEST_F(WidgetServiceTest, GetPreviewImagePath) {
       .WillRepeatedly(Invoke(__fake_cynara_finish));
   EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
       .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
+  char *lang = strdup("en-us");
+  EXPECT_CALL(GetMock<VconfMock>(), vconf_get_str(_))
+      .WillRepeatedly(Return(lang));
+
+  char *name = NULL;
+
+  name = widget_service_get_name("org.tizen.gallery.widget", NULL);
+  auto p = std::unique_ptr<char, decltype(std::free)*>(name, std::free);
+  EXPECT_STREQ(p.get(), "Gallery");
+}
+
+TEST_F(WidgetServiceTest, GetPreviewImagePath) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
+      .Times(2)
+      .WillOnce(Invoke(__fake_cynara_initialize))
+      .WillOnce(Return(1));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
+      .WillRepeatedly(Invoke(__fake_cynara_check));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
+      .WillRepeatedly(Invoke(__fake_cynara_finish));
+  EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
+      .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
+  char *lang = strdup("en-us");
+  EXPECT_CALL(GetMock<VconfMock>(), vconf_get_str(_))
+      .WillRepeatedly(Return(lang));
 
   char *path = NULL;
 
@@ -566,13 +790,24 @@ TEST_F(WidgetServiceTest, GetPreviewImagePath) {
       "org.tizen.gallery.widget", WIDGET_SIZE_TYPE_4x4);
   auto p = std::unique_ptr<char, decltype(std::free)*>(path, std::free);
   ASSERT_STREQ(p.get(), ".//shared/res/preview_gallery_4x4.png");
+
+  // For code coverage
+  path = widget_service_get_preview_image_path(
+      NULL, WIDGET_SIZE_TYPE_4x4);
+  ASSERT_EQ(path, nullptr);
+
+  path = widget_service_get_preview_image_path(
+      "org.tizen.gallery.widget", WIDGET_SIZE_TYPE_4x4);
+  ASSERT_EQ(path, nullptr);
 }
 
 TEST_F(WidgetServiceTest, GetIcon) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
-      .WillRepeatedly(Invoke(__fake_cynara_initialize));
+      .Times(2)
+      .WillOnce(Invoke(__fake_cynara_initialize))
+      .WillOnce(Return(1));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
       .WillRepeatedly(Invoke(__fake_cynara_check));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
@@ -585,13 +820,22 @@ TEST_F(WidgetServiceTest, GetIcon) {
   path = widget_service_get_icon("org.tizen.gallery_common", "");
   auto p = std::unique_ptr<char, decltype(std::free)*>(path, std::free);
   ASSERT_STREQ(p.get(), ".//shared/res/preview_gallery_4x4.png");
+
+  // For code coverage
+  path = widget_service_get_icon(NULL, "");
+  ASSERT_EQ(path, nullptr);
+
+  path = widget_service_get_icon("org.tizen.gallery_common", "");
+  ASSERT_EQ(path, nullptr);
 }
 
 TEST_F(WidgetServiceTest, GetNodisplay) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
-      .WillRepeatedly(Invoke(__fake_cynara_initialize));
+      .Times(2)
+      .WillOnce(Invoke(__fake_cynara_initialize))
+      .WillOnce(Return(1));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
       .WillRepeatedly(Invoke(__fake_cynara_check));
   EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
@@ -603,6 +847,13 @@ TEST_F(WidgetServiceTest, GetNodisplay) {
 
   ret = widget_service_get_nodisplay("org.tizen.gallery.widget");
   ASSERT_EQ(ret, 0);
+
+  //For code coverage
+  ret = widget_service_get_nodisplay(NULL);
+  ASSERT_EQ(ret, 0);
+
+  ret = widget_service_get_nodisplay("org.tizen.gallery.widget");
+  ASSERT_EQ(ret, 0);
 }
 
 TEST_F(WidgetServiceTest, GetSupportedSizes) {
@@ -628,6 +879,27 @@ TEST_F(WidgetServiceTest, GetSupportedSizes) {
   free(h);
 }
 
+TEST_F(WidgetServiceTest, GetSupportedSizes_N) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
+      .WillRepeatedly(Invoke(__fake_cynara_initialize));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
+      .WillRepeatedly(Invoke(__fake_cynara_check));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
+      .WillRepeatedly(Invoke(__fake_cynara_finish));
+  EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
+      .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
+
+  int ret;
+  int cnt = 10;
+  int *w;
+  int *h;
+
+  ret = widget_service_get_supported_sizes("org.tizen.gallery.widget_invalid", &cnt, &w, &h);
+  ASSERT_EQ(ret, WIDGET_ERROR_NOT_EXIST);
+}
+
 TEST_F(WidgetServiceTest, GetSupportedSizeTypes) {
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
@@ -649,6 +921,34 @@ TEST_F(WidgetServiceTest, GetSupportedSizeTypes) {
   free(types);
 }
 
+TEST_F(WidgetServiceTest, GetSupportedSizeTypes_N1) {
+  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
+      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_initialize(_, _))
+      .WillRepeatedly(Invoke(__fake_cynara_initialize));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_check(_, _, _, _, _))
+      .WillRepeatedly(Invoke(__fake_cynara_check));
+  EXPECT_CALL(GetMock<CynaraMock>(), cynara_finish(_))
+      .WillRepeatedly(Invoke(__fake_cynara_finish));
+  EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
+      .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
+
+  int ret;
+  int cnt = 10;
+  int *types;
+
+  ret = widget_service_get_supported_size_types("org.tizen.gallery.widget_invalid", &cnt, &types);
+  ASSERT_EQ(ret, WIDGET_ERROR_NONE);
+}
+
+TEST_F(WidgetServiceTest, GetSupportedSizeTypes_N2) {
+  int ret;
+  int *types;
+
+  ret = widget_service_get_supported_size_types("org.tizen.gallery.widget_invalid", NULL, &types);
+  ASSERT_EQ(ret, WIDGET_ERROR_INVALID_PARAMETER);
+}
+
 static int _widget_instance_list_cb(const char *widget_id, const char *instance_id, void *user_data) {
   return 0;
 }
@@ -683,7 +983,22 @@ int _widget_lifecycle_event_cb(const char *widget_id, widget_lifecycle_event_e l
   return 0;
 }
 
-TEST_F(WidgetServiceTest, SetLifecycleEventCb) {
+TEST_F(WidgetServiceTest, SetUnsetLifecycleEventCb) {
+  bundle *b = bundle_create();
+  int status = WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST;
+  bundle_add_str(b, AUL_K_WIDGET_ID, "org.tizen.gallery.widget");
+  bundle_add_str(b, AUL_K_COM_SENDER_PID, "100");
+  bundle_add_byte(b, AUL_K_WIDGET_STATUS, &status, sizeof(int));
+  bundle_add_str(b, AUL_K_PKGID, "sender");
+  EXPECT_CALL(GetMock<AulMock>(), aul_app_com_create(_, _, _, _, _))
+      .WillOnce(DoAll(InvokeArgument<2>("end", AUL_APP_COM_R_OK, b, nullptr),
+      Return(0)));
+  EXPECT_CALL(GetMock<AulMock>(), aul_app_get_pkgid_bypid(_, _, _))
+      .WillOnce(Invoke([](int pid, char* pkgid, int len) -> int {
+        snprintf(pkgid, len, "%s", "sender");
+        return 0;
+      }));
+
   EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
       .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
 
@@ -692,17 +1007,12 @@ TEST_F(WidgetServiceTest, SetLifecycleEventCb) {
   ret = widget_service_set_lifecycle_event_cb("org.tizen.gallery.widget",
         _widget_lifecycle_event_cb, NULL);
   ASSERT_EQ(ret, WIDGET_ERROR_NONE);
-}
-
-
-TEST_F(WidgetServiceTest, UnsetLifecycleEventCb) {
-  EXPECT_CALL(GetMock<SystemInfoMock>(), system_info_get_platform_bool(_, _))
-      .WillRepeatedly(Invoke(__fake_system_info_get_platform_bool));
-
-  int ret;
-
+  ret = widget_service_set_lifecycle_event_cb("org.tizen.gallery.widget2",
+        _widget_lifecycle_event_cb, NULL);
+  ASSERT_EQ(ret, WIDGET_ERROR_NONE);
   ret = widget_service_unset_lifecycle_event_cb("org.tizen.gallery.widget", NULL);
   ASSERT_EQ(ret, WIDGET_ERROR_NONE);
+  bundle_free(b);
 }
 
 TEST_F(WidgetServiceTest, GetContent) {
index 74a5dfbf1692f7c13ce8aa1d6a975cd7b6e8adfc..d70867522e90485c5db0306a584f3885c2e2965d 100644 (file)
@@ -32,7 +32,7 @@
 using ::testing::_;
 using ::testing::DoAll;
 using ::testing::Invoke;
-using ::testing::SetArgPointee;
+using ::testing::InvokeArgument;
 using ::testing::Return;
 
 namespace {
@@ -41,18 +41,12 @@ const char *__fake_tzplatform_mkpath(enum tzplatform_variable id, const char *pa
   return ".widget_test.db";
 }
 
+char *instance_id = NULL;
 static int __pid = 77;
 int __fake_aul_launch_app_async(const char *appid, bundle *kb) {
   return __pid;
 }
 
-int __fake_aul_app_com_create(const char *endpoint, aul_app_com_permission_h permission,
-    app_com_cb callback, void *user_data, aul_app_com_connection_h *connection) {
-  static int __not_null;
-  *connection = (aul_app_com_connection_h)&__not_null;
-  return 0;
-}
-
 int __fake_aul_app_com_leave(aul_app_com_connection_h connection) {
   return 0;
 }
@@ -130,17 +124,23 @@ class WidgetInstanceTest : public TestFixture {
 };
 
 TEST_F(WidgetInstanceTest, InstanceInit) {
+  bundle *b = bundle_create();
+  int status = WIDGET_INSTANCE_EVENT_APP_RESTART_REQUEST;
+  bundle_add_str(b, AUL_K_WIDGET_ID, "org.tizen.gallery.widget");
+  bundle_add_str(b, AUL_K_COM_SENDER_PID, "100");
+  bundle_add_byte(b, AUL_K_WIDGET_STATUS, &status, sizeof(int));
+
   EXPECT_CALL(GetMock<AulMock>(), aul_app_com_create(_, _, _, _, _))
-      .WillRepeatedly(Invoke(__fake_aul_app_com_create));
+      .WillOnce(DoAll(InvokeArgument<2>("end", AUL_APP_COM_R_OK, b, nullptr),
+      Return(0)));
 
   int ret;
 
   ret = widget_instance_init("org.tizen.gallery.widget");
   ASSERT_EQ(ret, 0);
+  bundle_free(b);
 }
 
-char *instance_id = NULL;
-
 TEST_F(WidgetInstanceTest, InstanceCreate) {
   EXPECT_CALL(GetMock<TzplatformConfigMock>(), tzplatform_mkpath(_, _))
       .WillRepeatedly(Invoke(__fake_tzplatform_mkpath));
@@ -150,6 +150,47 @@ TEST_F(WidgetInstanceTest, InstanceCreate) {
   ASSERT_EQ(ret, 0);
 }
 
+TEST_F(WidgetInstanceTest, InstanceInit2) {
+  bundle *b = bundle_create();
+  int status = WIDGET_INSTANCE_EVENT_CREATE;
+  bundle_add_str(b, AUL_K_WIDGET_ID, "org.tizen.gallery.widget");
+  bundle_add_byte(b, AUL_K_WIDGET_STATUS, &status, sizeof(int));
+  bundle_add_str(b, AUL_K_WIDGET_INSTANCE_ID, instance_id);
+  bundle_add_str(b, WIDGET_K_CONTENT_INFO, "cont_info");
+  bundle_add_str(b, AUL_K_WIDGET_ERROR_CODE, "13");
+
+  bundle *b2 = bundle_dup(b);
+  int status2 = WIDGET_INSTANCE_EVENT_TERMINATE;
+  bundle_del(b2, AUL_K_WIDGET_STATUS);
+  bundle_add_byte(b2, AUL_K_WIDGET_STATUS, &status2, sizeof(int));
+
+  bundle *b4 = bundle_dup(b);
+  int status4 = WIDGET_INSTANCE_EVENT_FAULT;
+  bundle_del(b4, AUL_K_WIDGET_STATUS);
+  bundle_add_byte(b4, AUL_K_WIDGET_STATUS, &status4, sizeof(int));
+
+  bundle *b5 = bundle_dup(b);
+  int status5 = WIDGET_INSTANCE_EVENT_EXTRA_UPDATED;
+  bundle_del(b5, AUL_K_WIDGET_STATUS);
+  bundle_add_byte(b5, AUL_K_WIDGET_STATUS, &status5, sizeof(int));
+
+  EXPECT_CALL(GetMock<AulMock>(), aul_app_com_create(_, _, _, _, _))
+      .WillOnce(DoAll(InvokeArgument<2>("end", AUL_APP_COM_R_OK, b, nullptr),
+      InvokeArgument<2>("end", AUL_APP_COM_R_OK, b2, nullptr),
+      InvokeArgument<2>("end", AUL_APP_COM_R_OK, b4, nullptr),
+      InvokeArgument<2>("end", AUL_APP_COM_R_OK, b5, nullptr),
+      Return(0)));
+
+  int ret;
+
+  ret = widget_instance_init("org.tizen.gallery.widget");
+  ASSERT_EQ(ret, 0);
+  bundle_free(b);
+  bundle_free(b2);
+  bundle_free(b4);
+  bundle_free(b5);
+}
+
 TEST_F(WidgetInstanceTest, InstanceLaunch) {
   EXPECT_CALL(GetMock<AulMock>(), aul_launch_app_async(_, _))
       .WillRepeatedly(Invoke(__fake_aul_launch_app_async));
@@ -321,12 +362,7 @@ TEST_F(WidgetInstanceTest, InstanceUnlistenEvent) {
 }
 
 TEST_F(WidgetInstanceTest, InstanceListenStatus) {
-
-  EXPECT_CALL(GetMock<AulMock>(), aul_app_com_create(_, _, _, _, _))
-      .WillRepeatedly(Invoke(__fake_aul_app_com_create));
-
-  int ret = 0;
-
+  int ret;
   ret = widget_instance_listen_status("org.tizen.gallery.widget",
       _widget_instance_event_cb, NULL);
   ASSERT_EQ(ret, 0);
@@ -369,15 +405,6 @@ TEST_F(WidgetInstanceTest, InstanceSetSdkUtil) {
   bundle_free(b);
 }
 
-TEST_F(WidgetInstanceTest, InstanceRefUnref) {
-  widget_instance_h instance = nullptr;
-
-  instance = widget_instance_ref(ins);
-  ASSERT_NE(instance, nullptr);
-
-  widget_instance_unref(instance);
-}
-
 TEST_F(WidgetInstanceTest, InstanceTerminate) {
   EXPECT_CALL(GetMock<AulMock>(), aul_launch_app_async(_, _))
       .WillRepeatedly(Invoke(__fake_aul_launch_app_async));
@@ -413,4 +440,22 @@ TEST_F(WidgetInstanceTest, InstanceFini) {
 
   ret = widget_instance_fini();
   ASSERT_EQ(ret, 0);
+}
+
+TEST_F(WidgetInstanceTest, InstanceDel_N) {
+  int ret = 0;
+
+  ret = widget_instance_delete("org.tizen.gallery.widget", instance_id);
+  ASSERT_NE(ret, WIDGET_ERROR_NONE);
+}
+
+TEST_F(WidgetInstanceTest, InstanceRefUnref) {
+  widget_instance_h instance = nullptr;
+
+  instance = widget_instance_ref(ins);
+  ASSERT_NE(instance, nullptr);
+
+  widget_instance_unref(instance);
+  widget_instance_unref(instance);
+  widget_instance_unref(instance);
 }
\ No newline at end of file