From: Mu-Woong Lee Date: Tue, 1 Aug 2017 12:11:48 +0000 (+0900) Subject: test: add testcases for user-session agent and custom contexts X-Git-Tag: submit/tizen/20170802.043634~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F15%2F141815%2F3;p=platform%2Fcore%2Fapi%2Fcontext.git test: add testcases for user-session agent and custom contexts Change-Id: Id80170c2541600b7c103cf2060f12d61f8c4844b Signed-off-by: Mu-Woong Lee --- diff --git a/testsuite/src/job-scheduler/JobSchedulerTest.cpp b/testsuite/src/job-scheduler/JobSchedulerTest.cpp index 9e09b31..42e5eec 100644 --- a/testsuite/src/job-scheduler/JobSchedulerTest.cpp +++ b/testsuite/src/job-scheduler/JobSchedulerTest.cpp @@ -28,6 +28,7 @@ static bool __get_job(); static bool __get_all_job(); static bool __toggle_job_cb(); static bool __publish_context(); +static bool __custom_uri(); 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); @@ -76,6 +77,9 @@ static gboolean __main(gpointer data) case 'p': run_test_case("/scheduler/publish_context", __publish_context); break; + case 'u': + run_test_case("/scheduler/custom_uri", __custom_uri); + break; case 'q': stop_mainloop(); return G_SOURCE_REMOVE; @@ -115,8 +119,11 @@ bool __add_job() 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"); + g_print(" 8. User-session agent test (trigger: contacts db, geofence\n"); + g_print("\n"); + g_print(" 9. Custom trigger test\n"); + g_print("10. Custom requirement test (trigger: earjack)\n"); g_print("\n"); ctx_sched_job_h job = sched::create_job(__scheduler, read_int(" ? ")); @@ -236,6 +243,37 @@ bool __publish_context() return true; } +bool __custom_uri() +{ + int error = E_NONE; + bool registered = false; + + error = ctx_sched_custom_register(__scheduler, "http://samsung.com/context/wrong/something"); + ASSERT_CMPINT(error, ==, E_PARAM); + + error = ctx_sched_custom_register(__scheduler, "http://samsung.com/context/custom/test_1"); + ASSERT_CMPINT(error, ==, E_NONE); + + error = ctx_sched_custom_register(__scheduler, "http://samsung.com/context/custom/test_2"); + ASSERT_CMPINT(error, ==, E_NONE); + + error = ctx_sched_custom_register(__scheduler, "http://samsung.com/context/custom/test_3"); + ASSERT_CMPINT(error, ==, E_NONE); + + error = ctx_sched_custom_unregister(__scheduler, "http://samsung.com/context/custom/test_2"); + ASSERT_CMPINT(error, ==, E_NONE); + + error = ctx_sched_custom_is_registered(__scheduler, "http://samsung.com/context/custom/test_2", "context-test", ®istered); + ASSERT_CMPINT(error, ==, E_NONE); + ASSERT(!registered); + + error = ctx_sched_custom_is_registered(__scheduler, "http://samsung.com/context/custom/test_1", "context-test", ®istered); + ASSERT_CMPINT(error, ==, E_NONE); + ASSERT(registered); + + 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/JobSpecs.cpp b/testsuite/src/job-scheduler/JobSpecs.cpp index 58ed82f..6112441 100644 --- a/testsuite/src/job-scheduler/JobSpecs.cpp +++ b/testsuite/src/job-scheduler/JobSpecs.cpp @@ -27,6 +27,7 @@ static bool __create_on_demand_notification_job(ctx_sched_h scheduler, ctx_sched 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_agent_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); @@ -58,9 +59,12 @@ ctx_sched_job_h sched::create_job(ctx_sched_h scheduler, int num) success = __create_notification_test(scheduler, &job); break; case 8: - success = __create_custom_trigger_test(scheduler, &job); + success = __create_agent_test(scheduler, &job); break; case 9: + success = __create_custom_trigger_test(scheduler, &job); + break; + case 10: success = __create_custom_requirement_test(scheduler, &job); break; default: @@ -354,6 +358,50 @@ bool __create_notification_test(ctx_sched_h scheduler, ctx_sched_job_h* job) return true; } +bool __create_agent_test(ctx_sched_h scheduler, ctx_sched_job_h* job) +{ + int error = E_NONE; + bool supported = false; + ctx_sched_job_context_h jobContext = NULL; + + // Allocate an on-demand job handle + error = ctx_sched_job_create_on_demand(job); + ASSERT_CMPINT(error, ==, E_NONE); + + // Contacts DB + ctx_sched_job_trigger_is_supported(scheduler, CTX_SCHED_URI_CONTACTS_DB, &supported); + if (supported) { + ctx_sched_job_trigger_create(CTX_SCHED_URI_CONTACTS_DB, &jobContext); + ctx_sched_job_context_prepare_attribute_str(jobContext, CTX_SCHED_ATTR_NAME_EVENT); + ctx_sched_job_context_attribute_add_eq_str(jobContext, CTX_SCHED_ATTR_NAME_EVENT, CTX_SCHED_ATTR_VALUE_CHANGED); + ctx_sched_job_add_trigger(*job, jobContext); + } else { + g_print("> Contacts DB change trigger is not supported.\n"); + } + + // Geofence + ctx_sched_job_trigger_is_supported(scheduler, CTX_SCHED_URI_GEOFENCE, &supported); + if (supported) { + ctx_sched_job_trigger_create(CTX_SCHED_URI_GEOFENCE, &jobContext); + + ctx_sched_job_context_prepare_attribute_str(jobContext, CTX_SCHED_ATTR_NAME_EVENT); + ctx_sched_job_context_attribute_add_eq_str(jobContext, CTX_SCHED_ATTR_NAME_EVENT, CTX_SCHED_ATTR_VALUE_IN); + + ctx_sched_job_context_prepare_attribute_int(jobContext, CTX_SCHED_ATTR_NAME_PLACE_ID); + ctx_sched_job_context_attribute_add_eq_int(jobContext, CTX_SCHED_ATTR_NAME_PLACE_ID, 1); + ctx_sched_job_context_attribute_add_eq_int(jobContext, CTX_SCHED_ATTR_NAME_PLACE_ID, 2); + + ctx_sched_job_add_trigger(*job, jobContext); + } else { + g_print("> Geofence trigger is not supported.\n"); + } + + error = ctx_sched_job_set_notification(*job, "Job Scheduler", "User Session Agent Test", NULL, NULL); + ASSERT_CMPINT(error, ==, E_NONE); + + return true; +} + bool __create_custom_trigger_test(ctx_sched_h scheduler, ctx_sched_job_h* job) { int error = E_NONE;