test: add hidden jobs to test job-scheduler actions 91/140991/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 27 Jul 2017 11:11:59 +0000 (20:11 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 27 Jul 2017 11:11:59 +0000 (20:11 +0900)
Change-Id: I84e4c1fdb906223903b66f0493d58f4af5ea6e24
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
testsuite/src/job-scheduler/JobSchedulerTest.cpp
testsuite/src/job-scheduler/JobSpecs.cpp
testsuite/src/main.cpp

index 7d8bc22..e3581fb 100644 (file)
@@ -261,6 +261,7 @@ bool __print_job(ctx_sched_job_h job)
 {
        int error = 0;
        int jobId = -1;
+       bool started = false;
        char* data = NULL;
        size_t length = 0;
 
@@ -271,6 +272,13 @@ bool __print_job(ctx_sched_job_h job)
                return false;
        }
 
+       error = ctx_sched_job_is_started(job, &started);
+
+       if (error != E_NONE) {
+               ctx_sched_job_destroy(job);
+               return false;
+       }
+
        error = ctx_sched_job_get_user_data(job, &data, &length);
 
        if (error != E_NONE) {
@@ -278,10 +286,14 @@ bool __print_job(ctx_sched_job_h job)
                return false;
        }
 
-       data[length - 1] = '\0';
-       g_print("> Job-%d: %s\n", jobId, data);
-       g_free(data);
-       ctx_sched_job_destroy(job);
+       if (data) {
+               data[length - 1] = '\0';
+               g_print("> Job-%d (%s): %s\n", jobId, started ? "started" : "stopped", data);
+               g_free(data);
+       } else {
+               g_print("> Job-%d (%s): (nil)\n", jobId, started ? "started" : "stopped");
+       }
 
+       ctx_sched_job_destroy(job);
        return true;
 }
index bb24bcf..3f4dbef 100644 (file)
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <app_control.h>
+#include <app_control_internal.h>
 #include "../shared.h"
 #include "JobSchedulerTest.h"
 
@@ -22,6 +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);
+
 ctx_sched_job_h sched::create_job(ctx_sched_h scheduler, int num)
 {
        bool success = true;
@@ -40,6 +47,15 @@ ctx_sched_job_h sched::create_job(ctx_sched_h scheduler, int num)
        case 4:
                success = __create_on_demand_notification_job(scheduler, &job);
                break;
+       case 5:
+               success = __create_dbus_test(scheduler, &job);
+               break;
+       case 6:
+               success = __create_app_control_test(scheduler, &job);
+               break;
+       case 7:
+               success = __create_notification_test(scheduler, &job);
+               break;
        default:
                g_print("> Bad choice\n");
                break;
@@ -255,3 +271,78 @@ bool __create_on_demand_notification_job(ctx_sched_h scheduler, ctx_sched_job_h*
        //TODO
        return false;
 }
+
+static bool __create_action_test(ctx_sched_h scheduler, ctx_sched_job_h* job)
+{
+       int error = E_NONE;
+       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);
+
+       // Earjack state trigger
+       jobContext = __create_earjack_trigger(scheduler);
+       ASSERT(jobContext != NULL);
+
+       error = ctx_sched_job_add_trigger(*job, jobContext);
+       if (error != E_NONE)
+               ctx_sched_job_context_destroy(jobContext);
+       ASSERT_CMPINT(error, ==, E_NONE);
+
+       return true;
+}
+
+bool __create_dbus_test(ctx_sched_h scheduler, ctx_sched_job_h* job)
+{
+       int error = E_NONE;
+       bool success = __create_action_test(scheduler, job);
+       ASSERT(success);
+
+       // Set the action DBus
+       GVariant* param = g_variant_new("(s)", "sensor/pedometer");
+       error = ctx_sched_job_set_dbus(*job,
+                       "org.tizen.context", "/org/tizen/context/SensorRecorder",
+                       "org.tizen.context.SensorRecorder", "IsSupported", param);
+       g_variant_unref(param);
+       ASSERT_CMPINT(error, ==, E_NONE);
+
+       return true;
+}
+
+bool __create_app_control_test(ctx_sched_h scheduler, ctx_sched_job_h* job)
+{
+       int error = E_NONE;
+       bool success = __create_action_test(scheduler, job);
+       ASSERT(success);
+
+       app_control_h ctrl = NULL;
+       app_control_create(&ctrl);
+       app_control_set_operation(ctrl, APP_CONTROL_OPERATION_DEFAULT);
+       app_control_set_app_id(ctrl, "org.tizen.gallery");
+
+       bundle* b = NULL;
+       app_control_export_as_bundle(ctrl, &b);
+
+       app_control_destroy(ctrl);
+
+       error = ctx_sched_job_set_app_control(*job, b);
+       if (error != E_NONE)
+               bundle_free(b);
+
+       ASSERT_CMPINT(error, ==, E_NONE);
+
+       return true;
+}
+
+bool __create_notification_test(ctx_sched_h scheduler, ctx_sched_job_h* job)
+{
+       int error = E_NONE;
+       bool success = __create_action_test(scheduler, job);
+       ASSERT(success);
+
+       error = ctx_sched_job_set_notification(*job, "Job Scheduler", "Notification Test", NULL, NULL);
+       ASSERT_CMPINT(error, ==, E_NONE);
+
+       return true;
+}
index 04d76c1..fc56bc2 100644 (file)
@@ -34,7 +34,7 @@ static void __signal_handler(int signo)
 
 static void __print_usage()
 {
-       g_print("Usage: context-test TESTSUITE\n\n");
+       g_print("\nUsage: context-test TESTSUITE\n\n");
        g_print("TESTSUITE can be one of the followings:\n");
        g_print("  a\t to test app-history\n");
        g_print("  j\t to test job-scheduler\n");
@@ -47,10 +47,8 @@ int main(int argc, char** argv)
        signal(SIGTERM, __signal_handler);
        signal(SIGQUIT, __signal_handler);
 
-       test_default(&argc, &argv);
-       g_print("\n");
-
        if (argc < 2) {
+               test_default(&argc, &argv);
                __print_usage();
                return EXIT_SUCCESS;
        }
@@ -61,6 +59,7 @@ int main(int argc, char** argv)
        case 'j':
                return test_job_scheduler(&argc, &argv);
        default:
+               test_default(&argc, &argv);
                __print_usage();
                return EXIT_SUCCESS;
        }