summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2016-11-04 09:40:35 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2016-11-04 09:41:13 +0100
commite3601ac32d8b91baca527d7fa5bec0dc88536c7a (patch)
tree0d5d998c9959dd56eed02bfce90f1e34dc5abd52
parentef9222d2095898d6929c17250a57eaf0f9113a8d (diff)
downloaduca-ufo-e3601ac32d8b91baca527d7fa5bec0dc88536c7a.tar.gz
uca-ufo-e3601ac32d8b91baca527d7fa5bec0dc88536c7a.tar.bz2
uca-ufo-e3601ac32d8b91baca527d7fa5bec0dc88536c7a.tar.xz
uca-ufo-e3601ac32d8b91baca527d7fa5bec0dc88536c7a.zip
Add test program to check stability
-rw-r--r--CMakeLists.txt3
-rw-r--r--tests/test.c127
2 files changed, 130 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 601accc..9b12575 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,3 +46,6 @@ target_link_libraries(ucaufo
install(TARGETS ucaufo
LIBRARY DESTINATION ${LIBUCA_PLUGINDIR})
+
+add_executable(test tests/test.c)
+target_link_libraries(test ucaufo)
diff --git a/tests/test.c b/tests/test.c
new file mode 100644
index 0000000..34a83cf
--- /dev/null
+++ b/tests/test.c
@@ -0,0 +1,127 @@
+#include <stdlib.h>
+#include <string.h>
+#include <uca/uca-camera.h>
+#include <uca/uca-plugin-manager.h>
+
+UcaPluginManager *manager;
+UcaCamera *camera;
+
+static void
+dispose (void)
+{
+ g_object_unref (camera);
+ g_object_unref (manager);
+}
+
+static void
+pass_or_die (GError *error)
+{
+ if (error == NULL)
+ return;
+
+ g_print ("Error: %s\n", error->message);
+ dispose ();
+ exit (1);
+}
+
+static void
+print_header (const gchar *header)
+{
+ guint remaining;
+
+ remaining = 79 - strlen (header);
+ g_print ("%s ", header);
+
+ for (guint i = 0; i < remaining; i++)
+ g_print ("-");
+
+ g_print ("\n");
+}
+
+static void
+check_roi_size (UcaCamera *camera, guint x, guint y, guint width, guint height, GError **error)
+{
+ guint roi_height;
+ guint16 *frame;
+
+ g_object_set (camera, "roi-height", height, NULL);
+ g_object_get (camera, "roi-height", &roi_height, NULL);
+
+ if (height != roi_height) {
+ g_print (" Error: ROI is %u x %u pixels\n", width, roi_height);
+ return;
+ }
+
+ frame = g_malloc0 (2 * width * height);
+
+ uca_camera_start_recording (camera, error);
+
+ if (*error != NULL)
+ goto exit_check_roi_size;
+
+ for (guint i = 0; i < 30; i++) {
+ uca_camera_grab (camera, frame, error);
+
+ if (*error != NULL)
+ goto exit_check_roi_size;
+ }
+
+ uca_camera_stop_recording (camera, error);
+
+ if (*error != NULL)
+ goto exit_check_roi_size;
+
+exit_check_roi_size:
+ g_free (frame);
+}
+
+static void
+test_roi_change (UcaCamera *camera)
+{
+ guint sensor_width;
+ guint sensor_height;
+ guint roi_width;
+ guint roi_height;
+
+ print_header ("Check different region-of-interest sizes");
+
+ g_object_get (camera,
+ "sensor-width", &sensor_width,
+ "sensor-height", &sensor_height,
+ "roi-width", &roi_width,
+ "roi-height", &roi_height,
+ NULL);
+
+ g_print (" Sensor size: %u x %u pixels\n", sensor_width, sensor_height);
+
+ for (roi_height = sensor_height; roi_height > 8; roi_height /= 2) {
+ GError *error = NULL;
+
+ g_print (" Test ROI %u x %u pixels: ", sensor_width, roi_height);
+
+ check_roi_size (camera, 0, 0, sensor_width, sensor_height, &error);
+
+ if (error == NULL) {
+ g_print ("PASS\n");
+ }
+ else {
+ g_print ("FAIL (%s)\n", error->message);
+ g_error_free (error);
+ }
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ GError *error = NULL;
+
+ manager = uca_plugin_manager_new ();
+ camera = uca_plugin_manager_get_camera (manager, "ufo", &error, NULL);
+
+ pass_or_die (error);
+
+ test_roi_change (camera);
+
+ dispose ();
+}