diff options
| author | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2012-09-21 14:29:50 +0200 | 
|---|---|---|
| committer | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2012-09-21 14:29:50 +0200 | 
| commit | 6eaadaa0e4ad8ce906aa8ccee63d91f0d9cb28ea (patch) | |
| tree | 1b37a1eb40ad1fdec0a2bebc167f7f8128497748 /test | |
| parent | e6a6eb9aede59a1f7441b926b36afefd9c42b91d (diff) | |
| parent | 9f262857d13a3e0d7ee214b33b90359c51227718 (diff) | |
Merge branch 'plugins'
Diffstat (limited to 'test')
| -rw-r--r-- | test/CMakeLists.txt | 18 | ||||
| -rw-r--r-- | test/benchmark.c | 32 | ||||
| -rw-r--r-- | test/control.c | 234 | ||||
| -rw-r--r-- | test/enum.c | 88 | ||||
| -rw-r--r-- | test/grab-async.c | 44 | ||||
| -rw-r--r-- | test/grab.c | 40 | ||||
| -rw-r--r-- | test/grab_pylon.c | 96 | ||||
| -rwxr-xr-x | test/run.py | 31 | ||||
| -rw-r--r-- | test/test-mock.c | 181 | 
9 files changed, 313 insertions, 451 deletions
| diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ce45d71..e4e60dc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,10 +10,7 @@ pkg_check_modules(GTHREAD2 gthread-2.0)  pkg_check_modules(GLIB2 glib-2.0>=2.24 REQUIRED)  pkg_check_modules(GOBJECT2 gobject-2.0>=2.24 REQUIRED) -#include_directories(${CMAKE_SOURCE_DIR}/src) -  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/control.glade ${CMAKE_CURRENT_BINARY_DIR}) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run.py ${CMAKE_CURRENT_BINARY_DIR})  # --- Build targets -----------------------------------------------------------  include_directories( @@ -44,14 +41,7 @@ target_link_libraries(benchmark uca ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES})  target_link_libraries(grab uca ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES})  target_link_libraries(grab-async uca ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES}) -add_executable(grab_pylon grab_pylon.c) -target_link_libraries(grab_pylon uca ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES}) - -if (NOT DEFINED WITH_CONTROL_GUI) -    set(WITH_CONTROL_GUI TRUE) -endif() - -if (GTK2_FOUND AND WITH_CONTROL_GUI) +if (GTK2_FOUND)      include_directories(${GTK2_INCLUDE_DIRS})      add_executable(control  @@ -81,6 +71,6 @@ if (HAVE_MOCK_CAMERA)          ${CMAKE_CURRENT_BINARY_DIR}/gtester.xsl)  endif() -add_executable(test-all test-all.c) -target_link_libraries(test-all uca -    ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES}) +#add_executable(test-all test-all.c) +#target_link_libraries(test-all uca +#    ${GLIB2_LIBRARIES} ${GOBJECT2_LIBRARIES}) diff --git a/test/benchmark.c b/test/benchmark.c index 0b4f6f8..ef99fd1 100644 --- a/test/benchmark.c +++ b/test/benchmark.c @@ -20,6 +20,7 @@  #include <string.h>  #include <stdlib.h>  #include "uca-camera.h" +#include "uca-plugin-manager.h"  typedef void (*GrabFrameFunc) (UcaCamera *camera, gpointer buffer, guint n_frames); @@ -37,20 +38,25 @@ sigint_handler(int signal)  static void  print_usage (void)  { -    gchar **types; +    GList *types; +    UcaPluginManager *manager; -    g_print ("Usage: benchmark ("); -    types = uca_camera_get_types (); +    manager = uca_plugin_manager_new (); +    g_print ("Usage: benchmark [ "); +    types = uca_plugin_manager_get_available_cameras (manager); -    for (guint i = 0; types[i] != NULL; i++) { -        if (types[i+1] == NULL) -            g_print ("%s)", types[i]); -        else -            g_print ("%s | ", types[i]); +    if (types == NULL) { +        g_print ("] -- no camera plugin found\n"); +        return;      } -    g_print ("\n"); -    g_strfreev (types); +    for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) { +        gchar *name = (gchar *) it->data; +        if (g_list_next (it) == NULL) +            g_print ("%s ]\n", name); +        else +            g_print ("%s, ", name); +    }  }  static void @@ -227,10 +233,12 @@ benchmark (UcaCamera *camera)  int  main (int argc, char *argv[])  { +    UcaPluginManager *manager;      GIOChannel  *log_channel;      GError      *error = NULL;      (void) signal (SIGINT, sigint_handler); +    g_type_init();      if (argc < 2) {          print_usage(); @@ -241,8 +249,8 @@ main (int argc, char *argv[])      g_assert_no_error (error);      g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, log_channel); -    g_type_init(); -    camera = uca_camera_new(argv[1], &error); +    manager = uca_plugin_manager_new (); +    camera = uca_plugin_manager_new_camera (manager, argv[1], &error);      if (camera == NULL) {          g_error ("Initialization: %s", error->message); diff --git a/test/control.c b/test/control.c index eaa88e3..5a7b702 100644 --- a/test/control.c +++ b/test/control.c @@ -26,6 +26,7 @@  #include "config.h"  #include "uca-camera.h" +#include "uca-plugin-manager.h"  #include "egg-property-tree-view.h" @@ -48,20 +49,17 @@ typedef struct {      int pixel_size;  } ThreadData; -typedef struct { -    ThreadData *thread_data; -    GtkTreeStore *tree_store; -} ValueCellData; -  enum {      COLUMN_NAME = 0,      COLUMN_VALUE,      COLUMN_EDITABLE,      NUM_COLUMNS  }; +     +static UcaPluginManager *plugin_manager; - -static void convert_8bit_to_rgb(guchar *output, guchar *input, int width, int height) +static void +convert_8bit_to_rgb (guchar *output, guchar *input, int width, int height)  {      for (int i = 0, j = 0; i < width*height; i++) {          output[j++] = input[i]; @@ -70,7 +68,8 @@ static void convert_8bit_to_rgb(guchar *output, guchar *input, int width, int he      }  } -static void convert_16bit_to_rgb(guchar *output, guchar *input, int width, int height) +static void +convert_16bit_to_rgb (guchar *output, guchar *input, int width, int height)  {      guint16 *in = (guint16 *) input;      guint16 min = G_MAXUINT16, max = 0; @@ -96,54 +95,58 @@ static void convert_16bit_to_rgb(guchar *output, guchar *input, int width, int h      }  } -static void *grab_thread(void *args) +static void * +grab_thread (void *args)  {      ThreadData *data = (ThreadData *) args;      gchar filename[FILENAME_MAX] = {0,};      gint counter = 0;      while (data->running) { -        uca_camera_grab(data->camera, (gpointer) &data->buffer, NULL); +        uca_camera_grab (data->camera, (gpointer) &data->buffer, NULL);          if (data->store) { -            snprintf(filename, FILENAME_MAX, "frame-%i-%08i.raw", data->timestamp, counter++); -            FILE *fp = fopen(filename, "wb"); -            fwrite(data->buffer, data->width*data->height, data->pixel_size, fp); -            fclose(fp); +            snprintf (filename, FILENAME_MAX, "frame-%i-%08i.raw", data->timestamp, counter++); +            FILE *fp = fopen (filename, "wb"); +            fwrite (data->buffer, data->width*data->height, data->pixel_size, fp); +            fclose (fp);          }          /* FIXME: We should actually check if this is really a new frame and           * just do nothing if it is an already displayed one. */          if (data->pixel_size == 1) -            convert_8bit_to_rgb(data->pixels, data->buffer, data->width, data->height); +            convert_8bit_to_rgb (data->pixels, data->buffer, data->width, data->height);          else if (data->pixel_size == 2) { -            convert_16bit_to_rgb(data->pixels, data->buffer, data->width, data->height); +            convert_16bit_to_rgb (data->pixels, data->buffer, data->width, data->height);          } -        gdk_threads_enter(); -        gdk_flush(); -        gtk_image_clear(GTK_IMAGE(data->image)); -        gtk_image_set_from_pixbuf(GTK_IMAGE(data->image), data->pixbuf); -        gtk_widget_queue_draw_area(data->image, 0, 0, data->width, data->height); -        gdk_threads_leave(); +        gdk_threads_enter (); +        gdk_flush (); +        gtk_image_clear (GTK_IMAGE (data->image)); +        gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); +        gtk_widget_queue_draw_area (data->image, 0, 0, data->width, data->height); +        gdk_threads_leave ();      }      return NULL;  } -gboolean on_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) +gboolean +on_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)  {      return FALSE;  } -void on_destroy(GtkWidget *widget, gpointer data) +void +on_destroy (GtkWidget *widget, gpointer data)  {      ThreadData *td = (ThreadData *) data;      td->running = FALSE; -    g_object_unref(td->camera); -    gtk_main_quit(); +    g_object_unref (td->camera); +    gtk_main_quit ();  } -static void on_toolbutton_run_clicked(GtkWidget *widget, gpointer args) +static void +on_toolbutton_run_clicked (GtkWidget *widget, gpointer args)  {      ThreadData *data = (ThreadData *) args; @@ -153,184 +156,195 @@ static void on_toolbutton_run_clicked(GtkWidget *widget, gpointer args)      GError *error = NULL;      data->running = TRUE; -    uca_camera_start_recording(data->camera, &error); +    uca_camera_start_recording (data->camera, &error);      if (error != NULL) { -        g_printerr("Failed to start recording: %s\n", error->message); +        g_printerr ("Failed to start recording: %s\n", error->message);          return;      } -    if (!g_thread_create(grab_thread, data, FALSE, &error)) { -        g_printerr("Failed to create thread: %s\n", error->message); +    if (!g_thread_create (grab_thread, data, FALSE, &error)) { +        g_printerr ("Failed to create thread: %s\n", error->message);          return;      }  } -static void on_toolbutton_stop_clicked(GtkWidget *widget, gpointer args) +static void +on_toolbutton_stop_clicked (GtkWidget *widget, gpointer args)  {      ThreadData *data = (ThreadData *) args;      data->running = FALSE;      data->store = FALSE;      GError *error = NULL; -    uca_camera_stop_recording(data->camera, &error); +    uca_camera_stop_recording (data->camera, &error);      if (error != NULL) -        g_printerr("Failed to stop: %s\n", error->message); +        g_printerr ("Failed to stop: %s\n", error->message);  } -static void on_toolbutton_record_clicked(GtkWidget *widget, gpointer args) +static void +on_toolbutton_record_clicked (GtkWidget *widget, gpointer args)  {      ThreadData *data = (ThreadData *) args; -    data->timestamp = (int) time(0); +    data->timestamp = (int) time (0);      data->store = TRUE;      GError *error = NULL; -    gtk_statusbar_push(data->statusbar, data->statusbar_context_id, "Recording..."); +    gtk_statusbar_push (data->statusbar, data->statusbar_context_id, "Recording...");      if (data->running != TRUE) {          data->running = TRUE; -        uca_camera_start_recording(data->camera, &error); +        uca_camera_start_recording (data->camera, &error); -        if (!g_thread_create(grab_thread, data, FALSE, &error)) -            g_printerr("Failed to create thread: %s\n", error->message); +        if (!g_thread_create (grab_thread, data, FALSE, &error)) +            g_printerr ("Failed to create thread: %s\n", error->message);      }  } -static void create_main_window(GtkBuilder *builder, const gchar* camera_name) +static void +create_main_window (GtkBuilder *builder, const gchar* camera_name)  {      static ThreadData td;      GError *error = NULL; -    UcaCamera *camera = uca_camera_new(camera_name, &error); +    UcaCamera *camera = uca_plugin_manager_new_camera (plugin_manager, camera_name, &error);      if ((camera == NULL) || (error != NULL)) { -        g_error("%s\n", error->message); -        gtk_main_quit(); +        g_error ("%s\n", error->message); +        gtk_main_quit ();      }      guint bits_per_sample; -    g_object_get(camera, +    g_object_get (camera,              "roi-width", &td.width,              "roi-height", &td.height,              "sensor-bitdepth", &bits_per_sample,              NULL); -    GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "window")); -    GtkWidget *image = GTK_WIDGET(gtk_builder_get_object(builder, "image")); +    GtkWidget *window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); +    GtkWidget *image = GTK_WIDGET (gtk_builder_get_object (builder, "image"));      GtkWidget *property_tree_view = egg_property_tree_view_new (G_OBJECT (camera));      GtkContainer *scrolled_property_window = GTK_CONTAINER (gtk_builder_get_object (builder, "scrolledwindow2"));      gtk_container_add (scrolled_property_window, property_tree_view);      gtk_widget_show_all (GTK_WIDGET (scrolled_property_window)); -    GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, td.width, td.height); -    gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); +    GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, td.width, td.height); +    gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);      td.pixel_size = bits_per_sample > 8 ? 2 : 1;      td.image  = image;      td.pixbuf = pixbuf; -    td.buffer = (guchar *) g_malloc(td.pixel_size * td.width * td.height); -    td.pixels = gdk_pixbuf_get_pixels(pixbuf); +    td.buffer = (guchar *) g_malloc (td.pixel_size * td.width * td.height); +    td.pixels = gdk_pixbuf_get_pixels (pixbuf);      td.running = FALSE; -    td.statusbar = GTK_STATUSBAR(gtk_builder_get_object(builder, "statusbar")); -    td.statusbar_context_id = gtk_statusbar_get_context_id(td.statusbar, "Recording Information"); +    td.statusbar = GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar")); +    td.statusbar_context_id = gtk_statusbar_get_context_id (td.statusbar, "Recording Information");      td.store = FALSE;      td.camera = camera; -    td.property_model = GTK_TREE_MODEL(gtk_builder_get_object(builder, "camera-properties")); - -    g_signal_connect(window, "destroy", G_CALLBACK(on_destroy), &td); -    g_signal_connect(gtk_builder_get_object(builder, "toolbutton_run"), -            "clicked", G_CALLBACK(on_toolbutton_run_clicked), &td); -    g_signal_connect(gtk_builder_get_object(builder, "toolbutton_stop"), -            "clicked", G_CALLBACK(on_toolbutton_stop_clicked), &td); -    g_signal_connect(gtk_builder_get_object(builder, "toolbutton_record"), -            "clicked", G_CALLBACK(on_toolbutton_record_clicked), &td); - -    gtk_widget_show(image); -    gtk_widget_show(window); +    td.property_model = GTK_TREE_MODEL (gtk_builder_get_object (builder, "camera-properties")); + +    g_signal_connect (window, "destroy", G_CALLBACK (on_destroy), &td); +    g_signal_connect (gtk_builder_get_object (builder, "toolbutton_run"), +            "clicked", G_CALLBACK (on_toolbutton_run_clicked), &td); +    g_signal_connect (gtk_builder_get_object (builder, "toolbutton_stop"), +            "clicked", G_CALLBACK (on_toolbutton_stop_clicked), &td); +    g_signal_connect (gtk_builder_get_object (builder, "toolbutton_record"), +            "clicked", G_CALLBACK (on_toolbutton_record_clicked), &td); + +    gtk_widget_show (image); +    gtk_widget_show (window);  } -static void on_button_proceed_clicked(GtkWidget *widget, gpointer data) +static void +on_button_proceed_clicked (GtkWidget *widget, gpointer data)  { -    GtkBuilder *builder = GTK_BUILDER(data); -    GtkWidget *choice_window = GTK_WIDGET(gtk_builder_get_object(builder, "choice-window")); -    GtkTreeView *treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview-cameras")); -    GtkListStore *list_store = GTK_LIST_STORE(gtk_builder_get_object(builder, "camera-types")); +    GtkBuilder *builder = GTK_BUILDER (data); +    GtkWidget *choice_window = GTK_WIDGET (gtk_builder_get_object (builder, "choice-window")); +    GtkTreeView *treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview-cameras")); +    GtkListStore *list_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "camera-types")); -    GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); -    GList *selected_rows = gtk_tree_selection_get_selected_rows(selection, NULL); +    GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); +    GList *selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);      GtkTreeIter iter; -    gtk_widget_destroy(choice_window); -    gboolean valid = gtk_tree_model_get_iter(GTK_TREE_MODEL(list_store), &iter, selected_rows->data); +    gtk_widget_destroy (choice_window); +    gboolean valid = gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &iter, selected_rows->data);      if (valid) {          gchar *data; -        gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, 0, &data, -1); -        create_main_window(builder, data); -        g_free(data); +        gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 0, &data, -1); +        create_main_window (builder, data); +        g_free (data);      } -    g_list_foreach(selected_rows, (GFunc) gtk_tree_path_free, NULL); -    g_list_free(selected_rows); +    g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL); +    g_list_free (selected_rows);  } -static void on_treeview_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data) +static void +on_treeview_keypress (GtkWidget *widget, GdkEventKey *event, gpointer data)  {      if (event->keyval == GDK_KEY_Return) -        gtk_widget_grab_focus(GTK_WIDGET(data)); +        gtk_widget_grab_focus (GTK_WIDGET (data));  } -static void create_choice_window(GtkBuilder *builder) +static void +create_choice_window (GtkBuilder *builder)  { -    gchar **camera_types = uca_camera_get_types(); +    GList *camera_types = uca_plugin_manager_get_available_cameras (plugin_manager); -    GtkWidget *choice_window = GTK_WIDGET(gtk_builder_get_object(builder, "choice-window")); -    GtkTreeView *treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "treeview-cameras")); -    GtkListStore *list_store = GTK_LIST_STORE(gtk_builder_get_object(builder, "camera-types")); -    GtkButton *proceed_button = GTK_BUTTON(gtk_builder_get_object(builder, "button-proceed")); +    GtkWidget *choice_window = GTK_WIDGET (gtk_builder_get_object (builder, "choice-window")); +    GtkTreeView *treeview = GTK_TREE_VIEW (gtk_builder_get_object (builder, "treeview-cameras")); +    GtkListStore *list_store = GTK_LIST_STORE (gtk_builder_get_object (builder, "camera-types")); +    GtkButton *proceed_button = GTK_BUTTON (gtk_builder_get_object (builder, "button-proceed"));      GtkTreeIter iter; -    for (guint i = 0; camera_types[i] != NULL; i++) { -        gtk_list_store_append(list_store, &iter); -        gtk_list_store_set(list_store, &iter, 0, camera_types[i], -1); +    for (GList *it = g_list_first (camera_types); it != NULL; it = g_list_next (it)) { +        gtk_list_store_append (list_store, &iter); +        gtk_list_store_set (list_store, &iter, 0, g_strdup ((gchar *) it->data), -1);      } -    gboolean valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter); +    gboolean valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);      if (valid) { -        GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); -        gtk_tree_selection_unselect_all(selection); -        gtk_tree_selection_select_path(selection, gtk_tree_model_get_path(GTK_TREE_MODEL(list_store), &iter)); +        GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); +        gtk_tree_selection_unselect_all (selection); +        gtk_tree_selection_select_path (selection, gtk_tree_model_get_path (GTK_TREE_MODEL (list_store), &iter));      } -    g_strfreev(camera_types); -    g_signal_connect(proceed_button, "clicked", G_CALLBACK(on_button_proceed_clicked), builder); -    g_signal_connect(treeview, "key-press-event", G_CALLBACK(on_treeview_keypress), proceed_button); -    gtk_widget_show_all(GTK_WIDGET(choice_window)); +    g_signal_connect (proceed_button, "clicked", G_CALLBACK (on_button_proceed_clicked), builder); +    g_signal_connect (treeview, "key-press-event", G_CALLBACK (on_treeview_keypress), proceed_button); +    gtk_widget_show_all (GTK_WIDGET (choice_window)); + +    g_list_foreach (camera_types, (GFunc) g_free, NULL); +    g_list_free (camera_types);  } -int main(int argc, char *argv[]) +int +main (int argc, char *argv[])  {      GError *error = NULL; -    g_thread_init(NULL); -    gdk_threads_init(); -    gtk_init(&argc, &argv); +    g_thread_init (NULL); +    gdk_threads_init (); +    gtk_init (&argc, &argv); -    GtkBuilder *builder = gtk_builder_new(); +    GtkBuilder *builder = gtk_builder_new (); -    if (!gtk_builder_add_from_file(builder, CONTROL_GLADE_PATH, &error)) { -        g_print("Error: %s\n", error->message); +    if (!gtk_builder_add_from_file (builder, CONTROL_GLADE_PATH, &error)) { +        g_print ("Error: %s\n", error->message);          return 1;      } -    create_choice_window(builder); -    gtk_builder_connect_signals(builder, NULL); +    plugin_manager = uca_plugin_manager_new (); +    create_choice_window (builder); +    gtk_builder_connect_signals (builder, NULL); -    gdk_threads_enter(); -    gtk_main(); -    gdk_threads_leave(); +    gdk_threads_enter (); +    gtk_main (); +    gdk_threads_leave (); +    g_object_unref (plugin_manager);      return 0;  } diff --git a/test/enum.c b/test/enum.c deleted file mode 100644 index 75ca596..0000000 --- a/test/enum.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> -   (Karlsruhe Institute of Technology) - -   This library is free software; you can redistribute it and/or modify it -   under the terms of the GNU Lesser General Public License as published by the -   Free Software Foundation; either version 2.1 of the License, or (at your -   option) any later version. - -   This library is distributed in the hope that it will be useful, but WITHOUT -   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -   details. - -   You should have received a copy of the GNU Lesser General Public License along -   with this library; if not, write to the Free Software Foundation, Inc., 51 -   Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#include <stdio.h> -#include "uca.h" - -int count_dots(const char *s) -{ -    int res = 0; -    while (*(s++) != '\0') -        if (*s == '.') -            res++; -    return res; -} - -void print_level(int depth) -{ -    for (int i = 0; i < depth; i++) -        printf("|  "); -    printf("|-- "); -} - -int main(int argc, char *argv[]) -{ -    uca *u = uca_init(NULL); -    if (u == NULL) { -        printf("Couldn't find a camera\n"); -        return 1; -    } - -    /* take first camera */ -    uca_camera *cam = u->cameras; - -    const size_t num_bytes = 256; -    char string_value[num_bytes]; -    uint32_t uint32_value; -    uint8_t uint8_value; - -    while (cam != NULL) { -        for (int i = 0; i < UCA_PROP_LAST; i++) { -            uca_property *prop = uca_get_full_property(i); -            print_level(count_dots(prop->name)); -            printf("%s = ", prop->name); -            switch (prop->type) { -                case uca_string: -                    if (uca_cam_get_property(cam, i, string_value, num_bytes) == UCA_NO_ERROR) { -                        printf("%s ", string_value); -                    } -                    else -                        printf("n/a"); -                    break; -                case uca_uint32t: -                    if (uca_cam_get_property(cam, i, &uint32_value, 0) == UCA_NO_ERROR) { -                        printf("%u %s", uint32_value, uca_unit_map[prop->unit]); -                    } -                    else -                        printf("n/a"); -                    break; -                case uca_uint8t: -                    if (uca_cam_get_property(cam, i, &uint8_value, 0) == UCA_NO_ERROR) { -                        printf("%u %s", uint8_value, uca_unit_map[prop->unit]); -                    } -                    else -                        printf("n/a"); -                    break; -            } -            printf("\n"); -        } -        cam = cam->next; -    } -     -    uca_destroy(u); -    return 0; -} diff --git a/test/grab-async.c b/test/grab-async.c index e1ec114..6132829 100644 --- a/test/grab-async.c +++ b/test/grab-async.c @@ -19,6 +19,7 @@  #include <signal.h>  #include <stdio.h>  #include <stdlib.h> +#include "uca-plugin-manager.h"  #include "uca-camera.h"  static UcaCamera *camera = NULL; @@ -29,7 +30,8 @@ typedef struct {      guint counter;  } CallbackData; -static void sigint_handler(int signal) +static void +sigint_handler(int signal)  {      printf("Closing down libuca\n");      uca_camera_stop_recording(camera, NULL); @@ -37,7 +39,8 @@ static void sigint_handler(int signal)      exit(signal);  } -static void grab_callback(gpointer data, gpointer user_data) +static void +grab_callback(gpointer data, gpointer user_data)  {      CallbackData *cbd = (CallbackData *) user_data;      gchar *filename = g_strdup_printf("frame-%04i.raw", cbd->counter++); @@ -49,16 +52,49 @@ static void grab_callback(gpointer data, gpointer user_data)      g_free(filename);  } -int main(int argc, char *argv[]) +static void +print_usage (void) +{ +    GList *types; +    UcaPluginManager *manager; + +    manager = uca_plugin_manager_new (); +    g_print ("Usage: benchmark [ "); +    types = uca_plugin_manager_get_available_cameras (manager); + +    if (types == NULL) { +        g_print ("] -- no camera plugin found\n"); +        return; +    } + +    for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) { +        gchar *name = (gchar *) it->data; +        if (g_list_next (it) == NULL) +            g_print ("%s ]\n", name); +        else +            g_print ("%s, ", name); +    } +} + +int +main(int argc, char *argv[])  {      CallbackData cbd;      guint sensor_width, sensor_height;      gchar *name; +    UcaPluginManager *manager;      GError *error = NULL;      (void) signal(SIGINT, sigint_handler);      g_type_init(); -    camera = uca_camera_new("pco", &error); + +    if (argc < 2) { +        print_usage(); +        return 1; +    } + +    manager = uca_plugin_manager_new (); +    camera = uca_plugin_manager_new_camera (manager, argv[1], &error);      if (camera == NULL) {          g_print("Error during initialization: %s\n", error->message); diff --git a/test/grab.c b/test/grab.c index 41e6d88..e507d69 100644 --- a/test/grab.c +++ b/test/grab.c @@ -19,6 +19,7 @@  #include <signal.h>  #include <stdio.h>  #include <stdlib.h> +#include "uca-plugin-manager.h"  #include "uca-camera.h"  static UcaCamera *camera = NULL; @@ -31,26 +32,33 @@ static void sigint_handler(int signal)      exit(signal);  } -static void print_usage(void) +static void +print_usage (void)  { -    gchar **types; -     -    g_print("Usage: grab ("); -    types = uca_camera_get_types(); - -    for (guint i = 0; types[i] != NULL; i++) { -        if (types[i+1] == NULL) -            g_print("%s)", types[i]); -        else -            g_print("%s | ", types[i]); +    GList *types; +    UcaPluginManager *manager; + +    manager = uca_plugin_manager_new (); +    g_print ("Usage: benchmark [ "); +    types = uca_plugin_manager_get_available_cameras (manager); + +    if (types == NULL) { +        g_print ("] -- no camera plugin found\n"); +        return;      } -    g_print("\n"); -    g_strfreev(types); +    for (GList *it = g_list_first (types); it != NULL; it = g_list_next (it)) { +        gchar *name = (gchar *) it->data; +        if (g_list_next (it) == NULL) +            g_print ("%s ]\n", name); +        else +            g_print ("%s, ", name); +    }  }  int main(int argc, char *argv[])  { +    UcaPluginManager *manager;      GError *error = NULL;      (void) signal(SIGINT, sigint_handler); @@ -59,13 +67,15 @@ int main(int argc, char *argv[])      guint bits;      gchar *name; +    g_type_init(); +      if (argc < 2) {          print_usage();          return 1;      } -    g_type_init(); -    camera = uca_camera_new(argv[1], &error); +    manager = uca_plugin_manager_new (); +    camera = uca_plugin_manager_new_camera (manager, argv[1], &error);      if (camera == NULL) {          g_print("Error during initialization: %s\n", error->message); diff --git a/test/grab_pylon.c b/test/grab_pylon.c deleted file mode 100644 index 2f9b5a0..0000000 --- a/test/grab_pylon.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (C) 2011, 2012 Matthias Vogelgesang <matthias.vogelgesang@kit.edu> -   (Karlsruhe Institute of Technology) - -   This library is free software; you can redistribute it and/or modify it -   under the terms of the GNU Lesser General Public License as published by the -   Free Software Foundation; either version 2.1 of the License, or (at your -   option) any later version. - -   This library is distributed in the hope that it will be useful, but WITHOUT -   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -   details. - -   You should have received a copy of the GNU Lesser General Public License along -   with this library; if not, write to the Free Software Foundation, Inc., 51 -   Franklin St, Fifth Floor, Boston, MA 02110, USA */ - -#include <glib-object.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include "uca-camera.h" - -#define handle_error(errno) {if ((errno) != UCA_NO_ERROR) printf("error at <%s:%i>\n", \ -    __FILE__, __LINE__);} - -static UcaCamera *camera = NULL; - -void sigint_handler(int signal) -{ -    printf("Closing down libuca\n"); -    uca_camera_stop_recording(camera, NULL); -    g_object_unref(camera); -    exit(signal); -} - -int main(int argc, char *argv[]) -{ -    GError *error = NULL; -    (void) signal(SIGINT, sigint_handler); - -    g_type_init(); -    camera = uca_camera_new("pylon", &error); - -    if (camera == NULL) { -        g_print("Couldn't initialize camera\n"); -        return 1; -    } - -    guint width, height, bits; -    g_object_get(G_OBJECT(camera), -            "sensor-width", &width, -            "sensor-height", &height, -            "sensor-bitdepth", &bits, -            NULL); - -    const int pixel_size = bits == 8 ? 1 : 2; -    g_print("allocate buffer %u, %u, %d\n", width, height, pixel_size); -    gpointer buffer = g_malloc0(width * height * pixel_size); - -    gchar filename[FILENAME_MAX]; - -    for (int i = 0; i < 2; i++) { -        gint counter = 0; -        g_print("Start recording\n"); -        uca_camera_start_recording(camera, &error); -        g_assert_no_error(error); - -        while (counter < 10) { -            g_print(" grab frame ... "); -            uca_camera_grab(camera, &buffer, &error); -            if (error != NULL) { -                g_print("\nError: %s\n", error->message); -                goto cleanup; -            } -            g_print("done\n"); - -            snprintf(filename, FILENAME_MAX, "frame-%08i.raw", counter++); -            FILE *fp = fopen(filename, "wb"); -            fwrite(buffer, width*height, pixel_size, fp); -            fclose(fp); -            //g_usleep(2 * G_USEC_PER_SEC); -        } - -        g_print("Stop recording\n"); -        uca_camera_stop_recording(camera, &error); -        g_assert_no_error(error); -    } - -cleanup: -    uca_camera_stop_recording(camera, NULL); -    g_object_unref(camera); -    g_free(buffer); - -    return error != NULL ? 1 : 0; -} diff --git a/test/run.py b/test/run.py deleted file mode 100755 index 7982617..0000000 --- a/test/run.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python - -import Tkinter -import threading -import subprocess - -class App(object): -    def __init__(self, parent): -        self.parent = parent -        self.canvas = Tkinter.Canvas(root, width=300, height=300) -        self.canvas.pack() -        self.rect = self.canvas.create_rectangle(0, 0, 300, 300, fill='yellow') -        self.run_button = Tkinter.Button(parent, text='Start grabbing', command=self.run_click) -        self.run_button.pack() -         -    def run_grab(self): -        proc = subprocess.Popen(['./grab']) -        proc.wait() -        self.canvas.itemconfig(self.rect, fill='red') -        self.run_button.config(state=Tkinter.NORMAL, text='Close', command=self.parent.destroy) -         -    def run_click(self): -        self.canvas.itemconfig(self.rect, fill='green') -        self.run_button.config(state=Tkinter.DISABLED) -        thread = threading.Thread(None, self.run_grab) -        thread.start() - -if __name__ == '__main__': -    root = Tkinter.Tk() -    app = App(root) -    root.mainloop() diff --git a/test/test-mock.c b/test/test-mock.c index 7594a3a..ca16c59 100644 --- a/test/test-mock.c +++ b/test/test-mock.c @@ -1,176 +1,195 @@  #include <glib.h>  #include "uca-camera.h" -#include "cameras/uca-mock-camera.h" +#include "uca-plugin-manager.h"  typedef struct { -    UcaMockCamera *camera; +    UcaPluginManager *manager; +    UcaCamera *camera;  } Fixture; -static void fixture_setup(Fixture *fixture, gconstpointer data) +static void +fixture_setup (Fixture *fixture, gconstpointer data)  {      GError *error = NULL; -    fixture->camera = uca_mock_camera_new(&error); -    g_assert(error == NULL); -    g_assert(fixture->camera); + +    fixture->manager = uca_plugin_manager_new (); +    uca_plugin_manager_add_path (fixture->manager, "./src"); + +    fixture->camera = uca_plugin_manager_new_camera (fixture->manager, "mock", &error); +    g_assert (error == NULL); +    g_assert (fixture->camera);  } -static void fixture_teardown(Fixture *fixture, gconstpointer data) +static void +fixture_teardown (Fixture *fixture, gconstpointer data)  { -    g_object_unref(fixture->camera); +    g_object_unref (fixture->camera); +    g_object_unref (fixture->manager);  } -static void on_property_change(gpointer instance, GParamSpec *pspec, gpointer user_data) +static void +on_property_change (gpointer instance, GParamSpec *pspec, gpointer user_data)  {      gboolean *success = (gboolean *) user_data;      *success = TRUE;  } -static void test_factory() +static void +test_factory (Fixture *fixture, gconstpointer data)  {      GError *error = NULL; -    UcaCamera *camera = uca_camera_new("fox994m3a0yxmy", &error); -    g_assert_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_FOUND); -    g_assert(camera == NULL); +    UcaCamera *camera = uca_plugin_manager_new_camera (fixture->manager, "fox994m3a0yxmy", &error); +    g_assert_error (error, UCA_PLUGIN_MANAGER_ERROR, UCA_PLUGIN_MANAGER_ERROR_MODULE_NOT_FOUND); +    g_assert (camera == NULL);  } -static void test_recording(Fixture *fixture, gconstpointer data) +static void +test_recording (Fixture *fixture, gconstpointer data)  {      GError *error = NULL; -    UcaCamera *camera = UCA_CAMERA(fixture->camera); +    UcaCamera *camera = UCA_CAMERA (fixture->camera); -    uca_camera_stop_recording(camera, &error); -    g_assert_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING); -    g_error_free(error); +    uca_camera_stop_recording (camera, &error); +    g_assert_error (error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING); +    g_error_free (error);      error = NULL; -    uca_camera_start_recording(camera, &error); -    g_assert_no_error(error); -    uca_camera_stop_recording(camera, &error); -    g_assert_no_error(error); +    uca_camera_start_recording (camera, &error); +    g_assert_no_error (error); +    uca_camera_stop_recording (camera, &error); +    g_assert_no_error (error);  } -static void test_recording_signal(Fixture *fixture, gconstpointer data) +static void +test_recording_signal (Fixture *fixture, gconstpointer data)  { -    UcaCamera *camera = UCA_CAMERA(fixture->camera); +    UcaCamera *camera = UCA_CAMERA (fixture->camera);      gboolean success = FALSE; -    g_signal_connect(G_OBJECT(camera), "notify::is-recording",  +    g_signal_connect (G_OBJECT (camera), "notify::is-recording",              (GCallback) on_property_change, &success); -    uca_camera_start_recording(camera, NULL); -    g_assert(success == TRUE); +    uca_camera_start_recording (camera, NULL); +    g_assert (success == TRUE);      success = FALSE; -    uca_camera_stop_recording(camera, NULL); -    g_assert(success == TRUE); +    uca_camera_stop_recording (camera, NULL); +    g_assert (success == TRUE);  } -static void grab_func(gpointer data, gpointer user_data) +static void +grab_func (gpointer data, gpointer user_data)  {      guint *count = (guint *) user_data;      *count += 1;  } -static void test_recording_async(Fixture *fixture, gconstpointer data) +static void +test_recording_async (Fixture *fixture, gconstpointer data)  { -    UcaCamera *camera = UCA_CAMERA(fixture->camera); +    UcaCamera *camera = UCA_CAMERA (fixture->camera);      guint count = 0; -    uca_camera_set_grab_func(camera, grab_func, &count); +    uca_camera_set_grab_func (camera, grab_func, &count); -    g_object_set(G_OBJECT(camera), +    g_object_set (G_OBJECT (camera),              "frame-rate", 10.0,              "transfer-asynchronously", TRUE,              NULL);      GError *error = NULL; -    uca_camera_start_recording(camera, &error); -    g_assert_no_error(error); +    uca_camera_start_recording (camera, &error); +    g_assert_no_error (error);      /*       * We sleep for an 1/8 of a second at 10 frames per second, thus we should       * record 2 frames.       */ -    g_usleep(G_USEC_PER_SEC / 8); +    g_usleep (G_USEC_PER_SEC / 8); -    uca_camera_stop_recording(camera, &error); -    g_assert_no_error(error); -    g_assert_cmpint(count, ==, 2); +    uca_camera_stop_recording (camera, &error); +    g_assert_no_error (error); +    g_assert_cmpint (count, ==, 2);  } -static void test_recording_property(Fixture *fixture, gconstpointer data) +static void +test_recording_property (Fixture *fixture, gconstpointer data)  { -    UcaCamera *camera = UCA_CAMERA(fixture->camera); +    UcaCamera *camera = UCA_CAMERA (fixture->camera);      gboolean is_recording = FALSE; -    uca_camera_start_recording(camera, NULL); -    g_object_get(G_OBJECT(camera), +    uca_camera_start_recording (camera, NULL); +    g_object_get (G_OBJECT (camera),              "is-recording", &is_recording,              NULL); -    g_assert(is_recording == TRUE); +    g_assert (is_recording == TRUE); -    uca_camera_stop_recording(camera, NULL); -    g_object_get(G_OBJECT(camera), +    uca_camera_stop_recording (camera, NULL); +    g_object_get (G_OBJECT (camera),              "is-recording", &is_recording,              NULL); -    g_assert(is_recording == FALSE); +    g_assert (is_recording == FALSE);  } -static void test_base_properties(Fixture *fixture, gconstpointer data) +static void +test_base_properties (Fixture *fixture, gconstpointer data)  { -    UcaCamera *camera = UCA_CAMERA(fixture->camera); +    UcaCamera *camera = UCA_CAMERA (fixture->camera);      guint n_properties = 0; -    GParamSpec **properties = g_object_class_list_properties(G_OBJECT_GET_CLASS(camera), &n_properties); +    GParamSpec **properties = g_object_class_list_properties (G_OBJECT_GET_CLASS (camera), &n_properties);      GValue val = {0};      for (guint i = 0; i < n_properties; i++) { -        g_value_init(&val, properties[i]->value_type); -        g_object_get_property(G_OBJECT(camera), properties[i]->name, &val); -        g_value_unset(&val); +        g_value_init (&val, properties[i]->value_type); +        g_object_get_property (G_OBJECT (camera), properties[i]->name, &val); +        g_value_unset (&val);      } -    g_free(properties); +    g_free (properties);  } -static void test_binnings_properties(Fixture *fixture, gconstpointer data) +static void +test_binnings_properties (Fixture *fixture, gconstpointer data)  { -    UcaCamera *camera = UCA_CAMERA(fixture->camera); +    UcaCamera *camera = UCA_CAMERA (fixture->camera);      GValueArray *array = NULL; -    g_object_get(G_OBJECT(camera), +    g_object_get (G_OBJECT (camera),              "sensor-horizontal-binnings", &array,              NULL); -    GValue *value = g_value_array_get_nth(array, 0); -    g_assert(value != NULL); -    g_assert(g_value_get_uint(value) == 1); +    GValue *value = g_value_array_get_nth (array, 0); +    g_assert (value != NULL); +    g_assert (g_value_get_uint (value) == 1);  } -static void test_signal(Fixture *fixture, gconstpointer data) +static void +test_signal (Fixture *fixture, gconstpointer data)  { -    UcaCamera *camera = UCA_CAMERA(fixture->camera); +    UcaCamera *camera = UCA_CAMERA (fixture->camera);      gboolean success = FALSE; -    g_signal_connect(camera, "notify::frame-rate", (GCallback) on_property_change, &success); -    g_object_set(G_OBJECT(camera), +    g_signal_connect (camera, "notify::frame-rate", (GCallback) on_property_change, &success); +    g_object_set (G_OBJECT (camera),              "frame-rate", 30.0,              NULL); -    g_assert(success == TRUE); +    g_assert (success == TRUE);  } -int main(int argc, char *argv[]) +int main (int argc, char *argv[])  { -    g_type_init(); -    g_test_init(&argc, &argv, NULL); -    g_test_bug_base("http://ufo.kit.edu/ufo/ticket"); - -    g_test_add_func("/factory", test_factory); -    g_test_add("/recording", Fixture, NULL, fixture_setup, test_recording, fixture_teardown); -    g_test_add("/recording/signal", Fixture, NULL, fixture_setup, test_recording_signal, fixture_teardown); -    g_test_add("/recording/asynchronous", Fixture, NULL, fixture_setup, test_recording_async, fixture_teardown); -    g_test_add("/properties/base", Fixture, NULL, fixture_setup, test_base_properties, fixture_teardown); -    g_test_add("/properties/recording", Fixture, NULL, fixture_setup, test_recording_property, fixture_teardown); -    g_test_add("/properties/binnings", Fixture, NULL, fixture_setup, test_binnings_properties, fixture_teardown); -    g_test_add("/signal", Fixture, NULL, fixture_setup, test_signal, fixture_teardown); - -    return g_test_run(); +    g_type_init (); + +    g_test_init (&argc, &argv, NULL); +    g_test_bug_base ("http://ufo.kit.edu/ufo/ticket"); + +    g_test_add ("/factory", Fixture, NULL, fixture_setup, test_factory, fixture_teardown); +    g_test_add ("/recording", Fixture, NULL, fixture_setup, test_recording, fixture_teardown); +    g_test_add ("/recording/signal", Fixture, NULL, fixture_setup, test_recording_signal, fixture_teardown); +    g_test_add ("/recording/asynchronous", Fixture, NULL, fixture_setup, test_recording_async, fixture_teardown); +    g_test_add ("/properties/base", Fixture, NULL, fixture_setup, test_base_properties, fixture_teardown); +    g_test_add ("/properties/recording", Fixture, NULL, fixture_setup, test_recording_property, fixture_teardown); +    g_test_add ("/properties/binnings", Fixture, NULL, fixture_setup, test_binnings_properties, fixture_teardown); +    g_test_add ("/signal", Fixture, NULL, fixture_setup, test_signal, fixture_teardown); + +    return g_test_run ();  } | 
