typedef struct _syscommon_plugin_backend_deviced_display_funcs {
int (*load_display_config) (struct syscommon_deviced_display_config **);
+ int (*on_changed_setting_value) (int, int);
} syscommon_plugin_backend_deviced_display_funcs;
#ifdef __cplusplus
int syscommon_plugin_deviced_display_put_backend(void);
/**
- * @brief Load the backend config of deviced-displaymodule
+ * @brief Load the backend config of deviced-display module
* @return @c 0 on success, otherwise a negative error value
*/
int syscommon_plugin_deviced_display_load_config(struct syscommon_deviced_display_config **);
+/**
+ * @brief Let plugin know about setting value change
+ * @param[in] key Key of which setting value has changed
+ * @param[in] value Value that a key has changed to
+ * @return @c 0 on success, otherwise a negative error value
+ */
+
+int syscommon_plugin_deviced_display_notify_setting_value_changed(int key, int value);
+
#ifdef __cplusplus
}
#endif
* THE SOFTWARE.
*/
#include <assert.h>
+#include <errno.h>
#include <glib.h>
return g_display_funcs->load_display_config(data);
}
+
+EXPORT
+int syscommon_plugin_deviced_display_notify_setting_value_changed(int key, int value)
+{
+ int ret = 0;
+
+ if (!g_display_funcs) {
+ ret = syscommon_plugin_deviced_display_get_backend();
+ if (ret < 0)
+ return ret;
+ }
+
+ assert(g_display_funcs);
+
+ if (!g_display_funcs->on_changed_setting_value)
+ return -EOPNOTSUPP;
+
+ return g_display_funcs->on_changed_setting_value(key, value);
+}
SET(TEST_DRIVER "test-driver")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/plugin-api/common/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/plugin-api/deviced/include)
FILE(GLOB TEST_DRIVER_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
FILE(GLOB LIBCOMMON_SRCS
FILE(GLOB RESOURCE_MANAGER_SRCS
"${CMAKE_SOURCE_DIR}/tests/resource-manager/*.c"
"${CMAKE_SOURCE_DIR}/src/resource-manager/*.c")
+FILE(GLOB PLUGIN_API_COMMON_SRCS
+ "${CMAKE_SOURCE_DIR}/src/plugin-api/common/src/*.c")
+FILE(GLOB PLUGIN_API_DEVICED_SRCS
+ "${CMAKE_SOURCE_DIR}/tests/plugin-api/deviced/*.c"
+ "${CMAKE_SOURCE_DIR}/src/plugin-api/deviced/src/*.c")
SET(SRCS
${TEST_DRIVER_SRCS}
${LIBCOMMON_SRCS}
- ${RESOURCE_MANAGER_SRCS})
+ ${RESOURCE_MANAGER_SRCS}
+ ${PLUGIN_API_COMMON_SRCS}
+ ${PLUGIN_API_DEVICED_SRCS})
SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=open")
SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=open64")
+SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=dlopen")
+SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=dlclose")
+SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=dlsym")
+SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=access")
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED
cmocka)
ADD_EXECUTABLE(${TEST_DRIVER} ${SRCS})
-TARGET_LINK_LIBRARIES(${TEST_DRIVER} ${REQUIRED_PKGS_LDFLAGS})
+TARGET_LINK_LIBRARIES(${TEST_DRIVER} "${REQUIRED_PKGS_LDFLAGS} -ldl")
# Suppress implicit declaration warning for __real functions.
SET_TARGET_PROPERTIES(${TEST_DRIVER} PROPERTIES COMPILE_FLAGS "-Wno-implicit-function-declaration")
SET_TARGET_PROPERTIES(${TEST_DRIVER} PROPERTIES LINK_FLAGS "${WRAP_FLAGS} -Wl,--export-dynamic")
--- /dev/null
+#include <system/syscommon-plugin-common-interface.h>
+#include <system/syscommon-plugin-deviced-common-interface.h>
+#include <system/syscommon-plugin-deviced-display.h>
+#include <system/syscommon-plugin-deviced-display-interface.h>
+
+#include "../../test-main.h"
+
+#define EXPORT __attribute__ ((visibility("default")))
+
+static struct syscommon_deviced_display_config configurations = {
+ 0, /* define plugin own configurations */ };
+
+static int load_display_config(struct syscommon_deviced_display_config **data)
+{
+ if (!data)
+ return -EINVAL;
+
+ *data = &configurations;
+
+ return 0;
+}
+
+static int on_changed_setting_value(int key, int value)
+{
+ check_expected(key);
+
+ switch (key) {
+ case 1:
+ check_expected(value);
+ // do something
+ break;
+ case 2:
+ check_expected(value);
+ // do something
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static syscommon_plugin_backend_deviced_display_funcs g_display_funcs = {
+ .load_display_config = load_display_config,
+ .on_changed_setting_value = on_changed_setting_value,
+};
+
+static int deviced_display_init(void **data)
+{
+ *data = (void *)&g_display_funcs;
+
+ return 0;
+}
+
+static int deviced_display_exit(void *data)
+{
+ return 0;
+}
+
+syscommon_plugin_backend EXPORT system_plugin_backend_deviced_display_data = {
+ .name = "test-deviced-display",
+ .vendor = "Samsung",
+ .init = deviced_display_init,
+ .exit = deviced_display_exit,
+};
--- /dev/null
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+#include "../../test-main.h"
+#include "../../test-mock.h"
+
+#include <system/syscommon-plugin-common-interface.h>
+
+extern syscommon_plugin_backend system_plugin_backend_deviced_display_data;
+
+static int setup_plugin_deviced(void **state)
+{
+ int ret;
+
+ mock_set_plugin_funcs(&system_plugin_backend_deviced_display_data);
+
+ ret = syscommon_plugin_deviced_display_get_backend();
+ assert_int_equal(ret, 0);
+
+ return 0;
+}
+
+static int teardown_plugin_deviced(void **state)
+{
+ syscommon_plugin_deviced_display_put_backend();
+
+ mock_unset_plugin_funcs();
+
+ return 0;
+}
+
+static void test_notify_setting_value_changed(void **state)
+{
+ int ret;
+
+ expect_value(on_changed_setting_value, key, 1);
+ expect_value(on_changed_setting_value, value, 1);
+
+ ret = syscommon_plugin_deviced_display_notify_setting_value_changed(1, 1);
+ assert_int_equal(ret, 0);
+}
+
+static const struct CMUnitTest testsuite_plugin_api_deviced[] = {
+ cmocka_unit_test(test_notify_setting_value_changed),
+};
+TESTSUITE_FIXTURE(testsuite_plugin_api_deviced, setup_plugin_deviced, teardown_plugin_deviced)
#include <stdio.h>
+#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
+#include <dlfcn.h>
#include <unistd.h>
#include "test-main.h"
//static FILE *__fp = NULL;
+static void *plugin_funcs = NULL;
+
+int __wrap_access(const char *pathname, int mode)
+{
+ return 0;
+}
+
int __wrap_open(const char *pathname, int flags)
{
const char *mock_pathname;
will_return(__wrap_open, flags);
}
+void mock_set_plugin_funcs(void *funcs)
+{
+ plugin_funcs = funcs;
+}
+
+void mock_unset_plugin_funcs(void)
+{
+ plugin_funcs = NULL;
+}
+
+extern void* __real_dlopen(const char *filename, int flags);
+void *__wrap_dlopen(const char *filename, int flags)
+{
+ if (plugin_funcs)
+ return (void *)(intptr_t) 1;
+
+ return __real_dlopen(filename, flags);
+}
+
+extern int __real_dlclose(void *handle);
+int __wrap_dlclose(void *handle)
+{
+ if (plugin_funcs)
+ return 0;
+
+ return __real_dlclose(handle);
+}
+
+extern void* __real_dlsym(void *handle, const char *symbol);
+void *__wrap_dlsym(void *handle, const char *symbol)
+{
+ if (plugin_funcs)
+ return plugin_funcs;
+
+ return __real_dlsym(handle, symbol);
+}
+
/*
FILE *__wrap_fopen(const char *pathname, const char *mode)
{
void mock_open(const char *pathname, int flags);
+void mock_set_plugin_funcs(void *funcs);
+void mock_unset_plugin_funcs(void);
+
#endif //__TEST_MOCK_H__