test: add testcases for user-session agent and custom contexts 15/141815/3
authorMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 1 Aug 2017 12:11:48 +0000 (21:11 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 2 Aug 2017 03:57:54 +0000 (12:57 +0900)
Change-Id: Id80170c2541600b7c103cf2060f12d61f8c4844b
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
testsuite/src/job-scheduler/JobSchedulerTest.cpp
testsuite/src/job-scheduler/JobSpecs.cpp

index 9e09b31f8e3aab36fc16c2781e5877a0063740a0..42e5eec7203e2c7c4770ed8b052d82c96263c337 100644 (file)
@@ -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", &registered);
+       ASSERT_CMPINT(error, ==, E_NONE);
+       ASSERT(!registered);
+
+       error = ctx_sched_custom_is_registered(__scheduler, "http://samsung.com/context/custom/test_1", "context-test", &registered);
+       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");
index 58ed82faa7a09f4091350ea72bbfd965dfd014f2..611244156dd9d0959f5d1394501901717afb4a3d 100644 (file)
@@ -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;