tests: camerabin2: Refactor tests a little

Refactor camerabin2 tests a little
This commit is contained in:
Thiago Santos 2011-09-29 18:20:44 -03:00
parent f6c0e2cd26
commit 009c440f44

View file

@ -166,8 +166,8 @@ static guint bus_source;
static GMainLoop *main_loop;
static gint capture_count = 0;
guint32 test_id = 0;
static const gchar *image_filename;
static const gchar *video_filename;
static gchar *image_filename;
static gchar *video_filename;
static GstBuffer *preview_buffer;
static gchar *preview_filename;
@ -199,24 +199,31 @@ validate_taglist_foreach (const GstTagList * list, const gchar * tag,
/* helper function for filenames */
static const gchar *
static gchar *
make_test_file_name (const gchar * base_name, gint num)
{
/* num == -1 means to keep the %d in the resulting string to be used on
* multifilesink like location */
if (num == -1) {
return g_strdup_printf ("%s" G_DIR_SEPARATOR_S
"gstcamerabin2test_%s_%u_%%03d.cap", g_get_tmp_dir (), base_name,
test_id);
} else {
return g_strdup_printf ("%s" G_DIR_SEPARATOR_S
"gstcamerabin2test_%s_%u_%03d.cap", g_get_tmp_dir (), base_name,
test_id, num);
}
}
static const gchar *
make_const_file_name (const gchar * filename, gint num)
{
static gchar file_name[1000];
/* num == -1 means to keep the %d in the resulting string to be used on
* multifilesink like location */
if (num == -1) {
g_snprintf (file_name, 999, "%s" G_DIR_SEPARATOR_S
"gstcamerabin2test_%s_%u_%%03d.cap", g_get_tmp_dir (), base_name,
test_id);
} else {
g_snprintf (file_name, 999, "%s" G_DIR_SEPARATOR_S
"gstcamerabin2test_%s_%u_%03d.cap", g_get_tmp_dir (), base_name,
test_id, num);
}
g_snprintf (file_name, 999, filename, num);
GST_INFO ("capturing to: %s", file_name);
return file_name;
}
@ -320,7 +327,7 @@ extract_jpeg_tags (const gchar * filename, gint num)
{
GstBus *bus;
GMainLoop *loop = g_main_loop_new (NULL, FALSE);
const gchar *filepath = make_test_file_name (filename, num);
const gchar *filepath = make_const_file_name (filename, num);
gchar *pipeline_str = g_strdup_printf ("filesrc location=%s ! "
"jpegparse ! fakesink", filepath);
GstElement *pipeline;
@ -425,6 +432,11 @@ teardown (void)
gst_tag_list_free (tags_found);
tags_found = NULL;
g_free (video_filename);
g_free (image_filename);
video_filename = NULL;
image_filename = NULL;
GST_INFO ("done");
}
@ -497,7 +509,7 @@ check_file_validity (const gchar * filename, gint num, GstTagList * taglist,
GstElement *playbin = gst_element_factory_make ("playbin2", NULL);
GstElement *fakevideo = gst_element_factory_make ("fakesink", NULL);
GstElement *fakeaudio = gst_element_factory_make ("fakesink", NULL);
gchar *uri = g_strconcat ("file://", make_test_file_name (filename, num),
gchar *uri = g_strconcat ("file://", make_const_file_name (filename, num),
NULL);
GST_DEBUG ("checking uri: %s", uri);
@ -643,7 +655,7 @@ GST_START_TEST (test_single_image_capture)
g_object_get (camera, "idle", &idle, NULL);
fail_unless (idle);
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
check_file_validity (IMAGE_FILENAME, 0, NULL, 0, 0, NO_AUDIO);
check_file_validity (image_filename, 0, NULL, 0, 0, NO_AUDIO);
}
GST_END_TEST;
@ -697,7 +709,7 @@ GST_START_TEST (test_multiple_image_captures)
fail_unless (idle);
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
for (i = 0; i < 3; i++) {
check_file_validity (IMAGE_FILENAME, i, NULL, widths[i], heights[i],
check_file_validity (image_filename, i, NULL, widths[i], heights[i],
NO_AUDIO);
}
}
@ -748,7 +760,7 @@ GST_START_TEST (test_single_video_recording)
fail_unless (idle);
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
check_file_validity (VIDEO_FILENAME, 0, NULL, 0, 0, WITH_AUDIO);
check_file_validity (video_filename, 0, NULL, 0, 0, WITH_AUDIO);
}
GST_END_TEST;
@ -813,7 +825,7 @@ GST_START_TEST (test_multiple_video_recordings)
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
for (i = 0; i < 3; i++) {
check_file_validity (VIDEO_FILENAME, i, NULL, widths[i], heights[i],
check_file_validity (video_filename, i, NULL, widths[i], heights[i],
WITH_AUDIO);
}
}
@ -845,10 +857,8 @@ GST_START_TEST (test_image_video_cycle)
g_object_get (camera, "idle", &idle, NULL);
fail_unless (idle);
img_filename = make_test_file_name (IMAGE_FILENAME, i);
vid_filename = make_test_file_name (VIDEO_FILENAME, i);
/* take a picture */
img_filename = make_const_file_name (image_filename, i);
g_object_set (camera, "mode", 1, NULL);
g_object_set (camera, "location", img_filename, NULL);
g_signal_emit_by_name (camera, "start-capture", NULL);
@ -860,6 +870,7 @@ GST_START_TEST (test_image_video_cycle)
check_preview_image (camera, img_filename, i);
/* now go to video */
vid_filename = make_const_file_name (video_filename, i);
g_object_set (camera, "mode", 2, NULL);
g_object_set (camera, "location", vid_filename, NULL);
@ -882,8 +893,8 @@ GST_START_TEST (test_image_video_cycle)
/* validate all the files */
for (i = 0; i < 2; i++) {
check_file_validity (IMAGE_FILENAME, i, NULL, 0, 0, NO_AUDIO);
check_file_validity (VIDEO_FILENAME, i, NULL, 0, 0, WITH_AUDIO);
check_file_validity (image_filename, i, NULL, 0, 0, NO_AUDIO);
check_file_validity (video_filename, i, NULL, 0, 0, WITH_AUDIO);
}
}
@ -980,8 +991,7 @@ GST_START_TEST (test_image_capture_with_tags)
GST_TAG_GEO_LOCATION_ELEVATION, 0.0, NULL);
/* set still image mode */
g_object_set (camera, "mode", 1,
"location", make_test_file_name (IMAGE_FILENAME, -1), NULL);
g_object_set (camera, "mode", 1, "location", image_filename, NULL);
if (gst_element_set_state (GST_ELEMENT (camera), GST_STATE_PLAYING) ==
GST_STATE_CHANGE_FAILURE) {
@ -1008,7 +1018,7 @@ GST_START_TEST (test_image_capture_with_tags)
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
for (i = 0; i < 3; i++) {
check_file_validity (IMAGE_FILENAME, i, taglists[i], 0, 0, NO_AUDIO);
check_file_validity (image_filename, i, taglists[i], 0, 0, NO_AUDIO);
gst_tag_list_free (taglists[i]);
}
}
@ -1029,8 +1039,7 @@ GST_START_TEST (test_video_capture_with_tags)
taglists[2] = gst_tag_list_new_full (GST_TAG_COMMENT, "test3", NULL);
/* set video mode */
g_object_set (camera, "mode", 2,
"location", make_test_file_name (VIDEO_FILENAME, -1), NULL);
g_object_set (camera, "mode", 2, "location", video_filename, NULL);
/* set a profile that has xmp support for more tags being saved */
{
@ -1086,7 +1095,7 @@ GST_START_TEST (test_video_capture_with_tags)
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
for (i = 0; i < 3; i++) {
check_file_validity (VIDEO_FILENAME, i, taglists[i], 0, 0, NO_AUDIO);
check_file_validity (video_filename, i, taglists[i], 0, 0, NO_AUDIO);
gst_tag_list_free (taglists[i]);
}
}
@ -1189,7 +1198,7 @@ GST_START_TEST (test_idle_property)
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
check_file_validity (VIDEO_FILENAME, 0, NULL, 0, 0, WITH_AUDIO);
check_file_validity (video_filename, 0, NULL, 0, 0, WITH_AUDIO);
}
GST_END_TEST;
@ -1255,7 +1264,7 @@ GST_START_TEST (test_image_custom_filter)
check_preview_image (camera, image_filename, 0);
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
check_file_validity (IMAGE_FILENAME, 0, NULL, 0, 0, NO_AUDIO);
check_file_validity (image_filename, 0, NULL, 0, 0, NO_AUDIO);
fail_unless (vf_probe_counter > 0);
fail_unless (image_probe_counter == 1);
@ -1336,7 +1345,7 @@ GST_START_TEST (test_video_custom_filter)
check_preview_image (camera, video_filename, 0);
gst_element_set_state (GST_ELEMENT (camera), GST_STATE_NULL);
check_file_validity (VIDEO_FILENAME, 0, NULL, 0, 0, WITH_AUDIO);
check_file_validity (video_filename, 0, NULL, 0, 0, WITH_AUDIO);
fail_unless (vf_probe_counter > 0);
fail_unless (video_probe_counter > 0);
@ -1399,8 +1408,7 @@ GST_START_TEST (test_image_location_switching)
g_object_get (camera, "camera-source", &src, NULL);
for (i = 0; i < LOCATION_SWITCHING_FILENAMES_COUNT; i++) {
filenames[i] =
g_strdup (make_test_file_name ("image-switching-filename-test", i));
filenames[i] = make_test_file_name ("image-switching-filename-test", i);
}
filenames[LOCATION_SWITCHING_FILENAMES_COUNT] = NULL;