[TEST] Add test case for tizen sensor
authorgichan-jang <gichan2.jang@samsung.com>
Tue, 28 Apr 2020 11:31:37 +0000 (20:31 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 29 Apr 2020 04:24:06 +0000 (13:24 +0900)
Add test case for tizen sensor

Signed-off-by: gichan-jang <gichan2.jang@samsung.com>
tests/tizen_capi/unittest_tizen_sensor.cc

index 0bd6cc6..9d41bee 100644 (file)
@@ -410,6 +410,99 @@ TEST (tizensensor_as_source, virtual_sensor_flow_05_n)
 
   g_free (pipeline);
 }
+
+/**
+ * @brief Test for tizen sensor get property
+ */
+TEST (tizensensor_as_source, get_property_1)
+{
+  gchar *pipeline;
+  GstElement *gstpipe;
+  GError *err = NULL;
+  int status = 0;
+
+  /* Create a nnstreamer pipeline */
+  pipeline = g_strdup_printf ("tensor_src_tizensensor name=srcx ! fakesink");
+  gstpipe = gst_parse_launch (pipeline, &err);
+  if (gstpipe) {
+    gboolean silent;
+    guint sequence, freq_n, freq_p, mode;
+    GEnumValue sensor_type;
+    GstElement *sensor_handle;
+
+    sensor_handle = gst_bin_get_by_name (GST_BIN (gstpipe), "srcx");
+    EXPECT_NE (sensor_handle, nullptr);
+    
+    g_object_set (sensor_handle, "silent", TRUE, NULL);
+    g_object_get (sensor_handle, "silent", &silent, NULL);
+    EXPECT_TRUE (silent);
+
+    g_object_set (sensor_handle, "type", SENSOR_LIGHT, NULL);
+    g_object_get (sensor_handle, "type", &sensor_type, NULL);
+    EXPECT_EQ (sensor_type.value, SENSOR_LIGHT);
+
+    g_object_set (sensor_handle, "sequence", 0, NULL);
+    g_object_get (sensor_handle, "sequence", &sequence, NULL);
+    EXPECT_EQ (sequence, 0);
+
+    g_object_set (sensor_handle, "mode", 0, NULL);
+    g_object_get (sensor_handle, "mode", &mode, NULL);
+    EXPECT_EQ (mode, 0);
+
+    g_object_set (sensor_handle, "framerate", 10, 1, NULL);
+    g_object_get (sensor_handle, "framerate", &freq_n, &freq_p, NULL);
+    EXPECT_EQ (freq_n, 10);
+    EXPECT_EQ (freq_p, 1);
+
+    gst_object_unref (sensor_handle);
+    gst_object_unref (gstpipe);
+  } else {
+    status = -1;
+    g_printerr("GST PARSE LAUNCH FAILED: [%s], %s\n",
+      pipeline, (err) ? err->message : "unknown reason");
+    g_clear_error (&err);
+  }
+  EXPECT_EQ (status, ML_ERROR_NONE);
+  g_free (pipeline);
+}
+
+/**
+ * @brief Test for tizen sensor get property
+ */
+TEST (tizensensor_as_source, get_propery_2_n)
+{
+  gchar *pipeline;
+  GstElement *gstpipe;
+  GError *err = NULL;
+  int status = 0;
+
+  /* Create a nnstreamer pipeline */
+  pipeline = g_strdup_printf ("tensor_src_tizensensor name=srcx ! fakesink");
+  gstpipe = gst_parse_launch (pipeline, &err);
+  if (gstpipe) {
+    GstElement *sensor_handle;
+    gchar *str = NULL;
+
+    sensor_handle = gst_bin_get_by_name (GST_BIN (gstpipe), "srcx");
+    EXPECT_NE (sensor_handle, nullptr);
+
+    g_object_get (sensor_handle, "invalid_prop", &str, NULL);
+    /* getting unknown property, str should be null */
+    EXPECT_TRUE (str == NULL);
+
+    status = 0;
+    gst_object_unref (sensor_handle);
+    gst_object_unref (gstpipe);
+  } else {
+    status = -1;
+    g_printerr("GST PARSE LAUNCH FAILED: [%s], %s\n",
+      pipeline, (err) ? err->message : "unknown reason");
+    g_clear_error (&err);
+  }
+  EXPECT_EQ (status, ML_ERROR_NONE);
+  g_free (pipeline);
+}
+
 /**
  * @brief Main GTest
  */