From: Mu-Woong Lee Date: Fri, 28 Jul 2017 06:12:20 +0000 (+0900) Subject: test: add job-scheduler testcases for custom contexts X-Git-Tag: submit/tizen/20170802.043634~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9b3eb498dd68745e7da126104823e9e0ea75dcb;p=platform%2Fcore%2Fapi%2Fcontext.git test: add job-scheduler testcases for custom contexts Change-Id: I6b90456510748d877561e65268bc18e191a4da24 Signed-off-by: Mu-Woong Lee --- diff --git a/testsuite/src/job-scheduler/JobSchedulerTest.cpp b/testsuite/src/job-scheduler/JobSchedulerTest.cpp index e3581fb..9e09b31 100644 --- a/testsuite/src/job-scheduler/JobSchedulerTest.cpp +++ b/testsuite/src/job-scheduler/JobSchedulerTest.cpp @@ -27,6 +27,7 @@ static bool __stop_job(); static bool __get_job(); static bool __get_all_job(); static bool __toggle_job_cb(); +static bool __publish_context(); static void __start_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job, bool timeout, void *cbData); static void __start_job_cb_with_finish(ctx_sched_h scheduler, ctx_sched_job_h job, bool timeout, void *cbData); @@ -40,14 +41,14 @@ static ctx_sched_h __scheduler = NULL; static gboolean __main(gpointer data) { g_print("\n"); - g_print("-------------------------------------------\n"); + g_print("----------------------------------------------\n"); g_print(" (a) add a job (r) remove a job\n"); g_print(" (s) start a job (t) stop a job\n"); g_print(" (g) get a job (G) get all jobs\n"); - g_print(" (c) toggle callbacks (q) quit\n"); - g_print("-------------------------------------------\n"); + g_print(" (c) toggle callbacks (p) publish context\n"); + g_print("----------------------------------------------\n"); - std::string choice = read_str(" a/r/s/t/g/G/c/q ? "); + std::string choice = read_str(" a/r/s/t/g/G/c/p/(q)uit ? "); g_print("\n"); switch (choice.front()) { @@ -72,6 +73,9 @@ static gboolean __main(gpointer data) case 'c': run_test_case("/scheduler/toggle_job_cb", __toggle_job_cb); break; + case 'p': + run_test_case("/scheduler/publish_context", __publish_context); + break; case 'q': stop_mainloop(); return G_SOURCE_REMOVE; @@ -93,13 +97,6 @@ int test_job_scheduler(int *argc, char ***argv) return 0; } - error = ctx_sched_set_job_cb(__scheduler, __start_job_cb, __stop_job_cb, NULL); - if (error != E_NONE) { - ctx_sched_destroy(__scheduler); - g_print(RED("ctx_sched_set_job_cb() failed\n")); - return 0; - } - g_idle_add(__main, NULL); start_mainloop(); @@ -114,6 +111,13 @@ bool __add_job() g_print(" 2. Periodic job, app-control\n"); g_print(" 3. On-demand job, DBus method call, one-time\n"); g_print(" 4. On-demand job, notification\n"); + g_print("\n"); + g_print(" 5. DBus action test (trigger: earjack)\n"); + g_print(" 6. App-control action test (trigger: earjack, target: gallery)\n"); + g_print(" 7. Notification action test (trigger: earjack)\n"); + g_print(" 8. Custom trigger test\n"); + g_print(" 9. Custom requirement test (trigger: earjack)\n"); + g_print("\n"); ctx_sched_job_h job = sched::create_job(__scheduler, read_int(" ? ")); ASSERT(job != NULL); @@ -211,6 +215,27 @@ bool __toggle_job_cb() return true; } +bool __publish_context() +{ + static bool flag = false; + + int error = E_NONE; + const char* payload = NULL; + + flag = !flag; + + if (flag) { + payload = "{\"IsConnected\": 1}"; + } else { + payload = "{\"IsConnected\": 0}"; + } + + error = ctx_sched_publish_context_json(__scheduler, TEST_CUSTOM_URI, payload); + ASSERT_CMPINT(error, ==, E_NONE); + + return true; +} + void __start_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job, bool timeout, void *cbData) { g_print("> A job has been executed (timeout: %s).\n", timeout ? "yes" : "no"); diff --git a/testsuite/src/job-scheduler/JobSchedulerTest.h b/testsuite/src/job-scheduler/JobSchedulerTest.h index e4b61e8..857e52b 100644 --- a/testsuite/src/job-scheduler/JobSchedulerTest.h +++ b/testsuite/src/job-scheduler/JobSchedulerTest.h @@ -17,6 +17,8 @@ #ifndef __CONTEXT_JOB_SCHEDULER_TEST_H__ #define __CONTEXT_JOB_SCHEDULER_TEST_H__ +#define TEST_CUSTOM_URI "http://tizen.org/context/custom/test_item" + #include int test_job_scheduler(int *argc, char ***argv); diff --git a/testsuite/src/job-scheduler/JobSpecs.cpp b/testsuite/src/job-scheduler/JobSpecs.cpp index 3f4dbef..58ed82f 100644 --- a/testsuite/src/job-scheduler/JobSpecs.cpp +++ b/testsuite/src/job-scheduler/JobSpecs.cpp @@ -24,10 +24,11 @@ static bool __create_periodic_app_control_job(ctx_sched_h scheduler, ctx_sched_j static bool __create_on_demand_dbus_job(ctx_sched_h scheduler, ctx_sched_job_h* job); static bool __create_on_demand_notification_job(ctx_sched_h scheduler, ctx_sched_job_h* job); -// Hidden test cases static bool __create_dbus_test(ctx_sched_h scheduler, ctx_sched_job_h* job); static bool __create_app_control_test(ctx_sched_h scheduler, ctx_sched_job_h* job); static bool __create_notification_test(ctx_sched_h scheduler, ctx_sched_job_h* job); +static bool __create_custom_trigger_test(ctx_sched_h scheduler, ctx_sched_job_h* job); +static bool __create_custom_requirement_test(ctx_sched_h scheduler, ctx_sched_job_h* job); ctx_sched_job_h sched::create_job(ctx_sched_h scheduler, int num) { @@ -56,6 +57,12 @@ ctx_sched_job_h sched::create_job(ctx_sched_h scheduler, int num) case 7: success = __create_notification_test(scheduler, &job); break; + case 8: + success = __create_custom_trigger_test(scheduler, &job); + break; + case 9: + success = __create_custom_requirement_test(scheduler, &job); + break; default: g_print("> Bad choice\n"); break; @@ -346,3 +353,60 @@ bool __create_notification_test(ctx_sched_h scheduler, ctx_sched_job_h* job) return true; } + +bool __create_custom_trigger_test(ctx_sched_h scheduler, ctx_sched_job_h* job) +{ + int error = E_NONE; + bool supported = false; + ctx_sched_job_context_h jobContext = NULL; + + error = ctx_sched_job_create_on_demand(job); + ASSERT_CMPINT(error, ==, E_NONE); + + error = ctx_sched_job_trigger_is_supported(scheduler, TEST_CUSTOM_URI, &supported); + ASSERT_RETURN(error == E_NONE, NULL); + ASSERT_RETURN(supported, NULL); + + error = ctx_sched_job_trigger_create(TEST_CUSTOM_URI, &jobContext); + ASSERT_RETURN(error == E_NONE, NULL); + ASSERT_RETURN(jobContext != NULL, NULL); + + ctx_sched_job_context_prepare_attribute_int(jobContext, CTX_SCHED_ATTR_NAME_IS_CONNECTED); + ctx_sched_job_context_attribute_add_eq_int(jobContext, CTX_SCHED_ATTR_NAME_IS_CONNECTED, CTX_SCHED_ATTR_VALUE_TRUE); + + error = ctx_sched_job_add_trigger(*job, jobContext); + if (error != E_NONE) + ctx_sched_job_context_destroy(jobContext); + ASSERT_CMPINT(error, ==, E_NONE); + + error = ctx_sched_job_set_notification(*job, "Job Scheduler", "Custom Trigger Test", NULL, NULL); + ASSERT_CMPINT(error, ==, E_NONE); + + return true; +} + +bool __create_custom_requirement_test(ctx_sched_h scheduler, ctx_sched_job_h* job) +{ + int error = E_NONE; + bool success = __create_action_test(scheduler, job); + ASSERT(success); + + ctx_sched_job_context_h jobContext = NULL; + + error = ctx_sched_job_requirement_create(TEST_CUSTOM_URI, false, &jobContext); + ASSERT_RETURN(error == E_NONE, NULL); + ASSERT_RETURN(jobContext != NULL, NULL); + + ctx_sched_job_context_prepare_attribute_int(jobContext, CTX_SCHED_ATTR_NAME_IS_CONNECTED); + ctx_sched_job_context_attribute_add_eq_int(jobContext, CTX_SCHED_ATTR_NAME_IS_CONNECTED, CTX_SCHED_ATTR_VALUE_TRUE); + + error = ctx_sched_job_add_requirement(*job, jobContext); + if (error != E_NONE) + ctx_sched_job_context_destroy(jobContext); + ASSERT_CMPINT(error, ==, E_NONE); + + error = ctx_sched_job_set_notification(*job, "Job Scheduler", "Custom Requirement Test", NULL, NULL); + ASSERT_CMPINT(error, ==, E_NONE); + + return true; +}