2009-07-16 17:39:16 +00:00
|
|
|
/*
|
|
|
|
* Check: a unit test framework for C
|
|
|
|
* Copyright (C) 2001, 2002 Arien Malec
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-07-16 17:39:16 +00:00
|
|
|
*/
|
|
|
|
|
check: Apply GStreamer-specific patches
Reintroduced patches:
* Make sure that fail_if(1) actually fails
from commit 9f99d056a263e71a5e6181224829def906cf0226
New patches due to updated libcheck (based on 0.9.14):
* Checks in m4/check-checks.m4 to cater for new dependencies
* Conditional compile-time compat POSIX fallbacks for libcheck
* Avoid relative paths for libcheck header files
* Make timer_create() usage depend on posix timers, not librt
* Rely on default AX_PTHREAD behavior to allow HAVE_PTHREAD to be used
when checking for types and functions (like clock_gettime())
* Avoid double declaration of clock_gettime() when availabe outside of
librt by making compat clock_gettime() declaration conditional
* check 0.9.9 renamed _fail_unless() and 0.9.12 later renamed it again
to _ck_assert_failed(), so ASSERT_{CRITICAL,WARNING}() now calls this
function
* Remove libcheck fallback infrastructure for malloc(), realloc(),
gettimeofday() and snprintf() since either they appear to be
available or they introduce even more dependencies.
The result is an embedded check in gstreamer that has been tested by
running check tests in core, -base, -good, -bad, -ugly and rtsp-server
on Linux, OSX and Windows.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=727826
2014-11-15 12:26:47 +00:00
|
|
|
#include "libcompat.h"
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-12-14 11:54:32 +00:00
|
|
|
#include "internal-check.h"
|
2009-07-16 17:39:16 +00:00
|
|
|
#include "check_list.h"
|
|
|
|
#include "check_impl.h"
|
|
|
|
#include "check_str.h"
|
|
|
|
#include "check_print.h"
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static void srunner_fprint_summary (FILE * file, SRunner * sr,
|
|
|
|
enum print_output print_mode);
|
|
|
|
static void srunner_fprint_results (FILE * file, SRunner * sr,
|
|
|
|
enum print_output print_mode);
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
srunner_print (SRunner * sr, enum print_output print_mode)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
srunner_fprint (stdout, sr, print_mode);
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
|
|
|
srunner_fprint (FILE * file, SRunner * sr, enum print_output print_mode)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
if (print_mode == CK_ENV) {
|
2009-10-12 11:49:35 +00:00
|
|
|
print_mode = get_env_printmode ();
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
srunner_fprint_summary (file, sr, print_mode);
|
|
|
|
srunner_fprint_results (file, sr, print_mode);
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static void
|
|
|
|
srunner_fprint_summary (FILE * file, SRunner * sr, enum print_output print_mode)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
2009-12-17 20:09:48 +00:00
|
|
|
#if ENABLE_SUBUNIT
|
|
|
|
if (print_mode == CK_SUBUNIT)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
if (print_mode >= CK_MINIMAL) {
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = sr_stat_str (sr);
|
|
|
|
fprintf (file, "%s\n", str);
|
2009-10-12 11:49:35 +00:00
|
|
|
free (str);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static void
|
|
|
|
srunner_fprint_results (FILE * file, SRunner * sr, enum print_output print_mode)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
List *resultlst;
|
2009-10-12 11:49:35 +00:00
|
|
|
|
2009-12-17 20:09:48 +00:00
|
|
|
#if ENABLE_SUBUNIT
|
|
|
|
if (print_mode == CK_SUBUNIT)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
resultlst = sr->resultlst;
|
2009-10-12 11:49:35 +00:00
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
for (check_list_front (resultlst); !check_list_at_end (resultlst);
|
|
|
|
check_list_advance (resultlst)) {
|
|
|
|
TestResult *tr = (TestResult *) check_list_val (resultlst);
|
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
tr_fprint (file, tr, print_mode);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
2013-07-23 19:39:53 +00:00
|
|
|
fprint_xml_esc (FILE * file, const char *str)
|
|
|
|
{
|
|
|
|
for (; *str != '\0'; str++) {
|
|
|
|
|
|
|
|
switch (*str) {
|
|
|
|
|
|
|
|
/* handle special characters that must be escaped */
|
|
|
|
case '"':
|
|
|
|
fputs (""", file);
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
fputs ("'", file);
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
fputs ("<", file);
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
fputs (">", file);
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
fputs ("&", file);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* regular characters, print as is */
|
|
|
|
default:
|
|
|
|
fputc (*str, file);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
void
|
|
|
|
tr_fprint (FILE * file, TestResult * tr, enum print_output print_mode)
|
|
|
|
{
|
|
|
|
if (print_mode == CK_ENV) {
|
|
|
|
print_mode = get_env_printmode ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((print_mode >= CK_VERBOSE && tr->rtype == CK_PASS) ||
|
|
|
|
(tr->rtype != CK_PASS && print_mode >= CK_NORMAL)) {
|
|
|
|
char *trstr = tr_str (tr);
|
|
|
|
|
|
|
|
fprintf (file, "%s\n", trstr);
|
|
|
|
free (trstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
void
|
2009-12-17 20:09:48 +00:00
|
|
|
tr_xmlprint (FILE * file, TestResult * tr,
|
|
|
|
enum print_output print_mode CK_ATTRIBUTE_UNUSED)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
char result[10];
|
2014-11-15 11:53:32 +00:00
|
|
|
char *path_name = NULL;
|
|
|
|
char *file_name = NULL;
|
|
|
|
char *slash = NULL;
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
switch (tr->rtype) {
|
2009-10-12 11:49:35 +00:00
|
|
|
case CK_PASS:
|
2014-11-15 11:53:32 +00:00
|
|
|
snprintf (result, sizeof (result), "%s", "success");
|
2009-10-12 11:49:35 +00:00
|
|
|
break;
|
|
|
|
case CK_FAILURE:
|
2014-11-15 11:53:32 +00:00
|
|
|
snprintf (result, sizeof (result), "%s", "failure");
|
2009-10-12 11:49:35 +00:00
|
|
|
break;
|
|
|
|
case CK_ERROR:
|
2014-11-15 11:53:32 +00:00
|
|
|
snprintf (result, sizeof (result), "%s", "error");
|
2009-10-12 11:49:35 +00:00
|
|
|
break;
|
|
|
|
case CK_TEST_RESULT_INVALID:
|
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
break;
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
if (tr->file) {
|
|
|
|
slash = strrchr (tr->file, '/');
|
|
|
|
if (slash == NULL) {
|
|
|
|
slash = strrchr (tr->file, '\\');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slash == NULL) {
|
|
|
|
path_name = strdup (".");
|
|
|
|
file_name = tr->file;
|
|
|
|
} else {
|
|
|
|
path_name = strdup (tr->file);
|
|
|
|
path_name[slash - tr->file] = 0; /* Terminate the temporary string. */
|
|
|
|
file_name = slash + 1;
|
|
|
|
}
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
2009-10-12 11:49:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
fprintf (file, " <test result=\"%s\">\n", result);
|
2014-11-15 11:53:32 +00:00
|
|
|
fprintf (file, " <path>%s</path>\n",
|
|
|
|
(path_name == NULL ? "" : path_name));
|
|
|
|
fprintf (file, " <fn>%s:%d</fn>\n",
|
|
|
|
(file_name == NULL ? "" : file_name), tr->line);
|
2009-10-12 11:49:35 +00:00
|
|
|
fprintf (file, " <id>%s</id>\n", tr->tname);
|
|
|
|
fprintf (file, " <iteration>%d</iteration>\n", tr->iter);
|
2014-11-15 11:53:32 +00:00
|
|
|
fprintf (file, " <duration>%d.%06d</duration>\n",
|
|
|
|
tr->duration < 0 ? -1 : tr->duration / US_PER_SEC,
|
|
|
|
tr->duration < 0 ? 0 : tr->duration % US_PER_SEC);
|
2013-07-23 19:39:53 +00:00
|
|
|
fprintf (file, " <description>");
|
|
|
|
fprint_xml_esc (file, tr->tcname);
|
|
|
|
fprintf (file, "</description>\n");
|
|
|
|
fprintf (file, " <message>");
|
|
|
|
fprint_xml_esc (file, tr->msg);
|
|
|
|
fprintf (file, "</message>\n");
|
2009-10-12 11:49:35 +00:00
|
|
|
fprintf (file, " </test>\n");
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
free (path_name);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
enum print_output
|
|
|
|
get_env_printmode (void)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
char *env = getenv ("CK_VERBOSITY");
|
2014-11-15 11:53:32 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
if (env == NULL)
|
|
|
|
return CK_NORMAL;
|
|
|
|
if (strcmp (env, "silent") == 0)
|
|
|
|
return CK_SILENT;
|
|
|
|
if (strcmp (env, "minimal") == 0)
|
|
|
|
return CK_MINIMAL;
|
|
|
|
if (strcmp (env, "verbose") == 0)
|
|
|
|
return CK_VERBOSE;
|
|
|
|
return CK_NORMAL;
|
|
|
|
}
|