media-check: add results file comparison

Adds a new expected-results argument to receive a file that is used
as a base for comparison with the new results. In case differences are
found, the application will print those issues.
This commit is contained in:
Thiago Santos 2013-08-21 11:03:19 -03:00
parent 549bcc1fd5
commit 044b21521b
3 changed files with 83 additions and 0 deletions

View file

@ -149,6 +149,7 @@ main (int argc, gchar ** argv)
GError *err = NULL;
gchar *output_file = NULL;
gchar *expected_file = NULL;
gchar *output = NULL;
gsize outputlength;
gboolean ret;
@ -157,6 +158,10 @@ main (int argc, gchar ** argv)
{"output-file", 'o', 0, G_OPTION_ARG_FILENAME,
&output_file, "The output file to store the results",
NULL},
{"expected-results", 'e', 0, G_OPTION_ARG_FILENAME,
&expected_file, "The file contained the expected results (or the "
"last results found, for comparison)",
NULL},
{NULL}
};
@ -195,6 +200,34 @@ main (int argc, gchar ** argv)
if (output_file)
gst_validate_media_info_save (&mi, output_file, NULL);
if (expected_file) {
GstValidateMediaInfo *expected_mi;
GError *err = NULL;
if (!g_path_is_absolute (expected_file)) {
gchar *cdir = g_get_current_dir ();
gchar *absolute = g_build_filename (cdir, expected_file, NULL);
g_free (expected_file);
g_free (cdir);
expected_file = absolute;
}
expected_mi = gst_validate_media_info_load (expected_file, &err);
if (expected_mi) {
if (!gst_validate_media_info_compare (expected_mi, &mi)) {
g_print ("Expected results didn't match\n");
ret = FALSE;
}
gst_validate_media_info_free (expected_mi);
} else {
g_print ("Failed to load expected results file: %s\n", err->message);
g_error_free (err);
ret = FALSE;
}
}
gst_validate_media_info_clear (&mi);
g_print ("Media info:\n%s\n", output);

View file

@ -100,6 +100,13 @@ gst_validate_media_info_clear (GstValidateMediaInfo * mi)
gst_validate_stream_info_free (mi->stream_info);
}
void
gst_validate_media_info_free (GstValidateMediaInfo * mi)
{
gst_validate_media_info_clear (mi);
g_free (mi);
}
gchar *
gst_validate_media_info_to_string (GstValidateMediaInfo * mi, gsize * length)
{
@ -662,3 +669,43 @@ gst_validate_media_info_inspect_uri (GstValidateMediaInfo * mi,
return ret;
}
gboolean
gst_validate_media_info_compare (GstValidateMediaInfo * expected,
GstValidateMediaInfo * extracted)
{
gboolean ret = TRUE;
if (expected->duration != extracted->duration) {
g_print ("Duration changed: %" GST_TIME_FORMAT " -> %" GST_TIME_FORMAT "\n",
GST_TIME_ARGS (expected->duration),
GST_TIME_ARGS (extracted->duration));
ret = FALSE;
}
if (expected->file_size != extracted->file_size) {
g_print ("File size changed: %" G_GUINT64_FORMAT " -> %" G_GUINT64_FORMAT
"\n", expected->file_size, extracted->file_size);
ret = FALSE;
}
if (expected->seekable && !extracted->seekable) {
g_print ("File isn't seekable anymore\n");
ret = FALSE;
}
if (expected->playback_error == NULL && extracted->playback_error) {
g_print ("Playback is now failing with: %s\n", extracted->playback_error);
ret = FALSE;
}
if (expected->reverse_playback_error == NULL
&& extracted->reverse_playback_error) {
g_print ("Reverse playback is now failing with: %s\n",
extracted->reverse_playback_error);
ret = FALSE;
}
if (expected->stream_info
&& !gst_caps_is_equal_fixed (expected->stream_info->caps,
extracted->stream_info->caps)) {
g_print ("Media caps changed: '%" GST_PTR_FORMAT "' -> '%" GST_PTR_FORMAT
"'\n", expected->stream_info->caps, extracted->stream_info->caps);
ret = FALSE;
}
return ret;
}

View file

@ -59,6 +59,7 @@ struct _GstValidateMediaInfo {
void gst_validate_media_info_init (GstValidateMediaInfo * mi);
void gst_validate_media_info_clear (GstValidateMediaInfo * mi);
void gst_validate_media_info_free (GstValidateMediaInfo * mi);
gchar * gst_validate_media_info_to_string (GstValidateMediaInfo * mi, gsize * length);
gboolean gst_validate_media_info_save (GstValidateMediaInfo * mi, const gchar * path, GError ** err);
@ -66,6 +67,8 @@ GstValidateMediaInfo * gst_validate_media_info_load (const gchar * path, GError
gboolean gst_validate_media_info_inspect_uri (GstValidateMediaInfo * mi, const gchar * uri, GError ** err);
gboolean gst_validate_media_info_compare (GstValidateMediaInfo * expected, GstValidateMediaInfo * extracted);
G_END_DECLS
#endif /* __GST_VALIDATE_MEDIA_INFO_H__ */