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 <stdarg.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_error.h"
|
|
|
|
#include "check_impl.h"
|
|
|
|
#include "check_str.h"
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static const char *tr_type_str (TestResult * tr);
|
|
|
|
static int percent_passed (TestStats * t);
|
2009-07-16 17:39:16 +00:00
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
char *
|
|
|
|
tr_str (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
const char *exact_msg;
|
|
|
|
char *rstr;
|
2009-10-12 11:49:35 +00:00
|
|
|
|
|
|
|
exact_msg = (tr->rtype == CK_ERROR) ? "(after this point) " : "";
|
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
rstr = ck_strdup_printf ("%s:%d:%s:%s:%s:%d: %s%s",
|
2009-10-12 11:49:35 +00:00
|
|
|
tr->file, tr->line,
|
|
|
|
tr_type_str (tr), tr->tcname, tr->tname, tr->iter, exact_msg, tr->msg);
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
return rstr;
|
|
|
|
}
|
|
|
|
|
2009-12-17 20:09:48 +00:00
|
|
|
char *
|
|
|
|
tr_short_str (TestResult * tr)
|
|
|
|
{
|
|
|
|
const char *exact_msg;
|
|
|
|
char *rstr;
|
|
|
|
|
|
|
|
exact_msg = (tr->rtype == CK_ERROR) ? "(after this point) " : "";
|
|
|
|
|
|
|
|
rstr = ck_strdup_printf ("%s:%d: %s%s",
|
|
|
|
tr->file, tr->line, exact_msg, tr->msg);
|
|
|
|
|
|
|
|
return rstr;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
char *
|
|
|
|
sr_stat_str (SRunner * sr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
TestStats *ts;
|
2009-10-12 11:49:35 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
ts = sr->stats;
|
2009-10-12 11:49:35 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
str = ck_strdup_printf ("%d%%: Checks: %d, Failures: %d, Errors: %d",
|
2009-10-12 11:49:35 +00:00
|
|
|
percent_passed (ts), ts->n_checked, ts->n_failed, ts->n_errors);
|
2009-07-16 17:39:16 +00:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
char *
|
|
|
|
ck_strdup_printf (const char *fmt, ...)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
/* Guess we need no more than 100 bytes. */
|
2014-11-15 11:53:32 +00:00
|
|
|
int n;
|
|
|
|
size_t size = 100;
|
2009-07-16 17:39:16 +00:00
|
|
|
char *p;
|
|
|
|
va_list ap;
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
p = (char *) emalloc (size);
|
2009-07-16 17:39:16 +00:00
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
while (1) {
|
|
|
|
/* Try to print in the allocated space. */
|
|
|
|
va_start (ap, fmt);
|
|
|
|
n = vsnprintf (p, size, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
/* If that worked, return the string. */
|
2014-11-15 11:53:32 +00:00
|
|
|
if (n > -1 && n < (int) size)
|
2009-10-12 11:49:35 +00:00
|
|
|
return p;
|
|
|
|
|
|
|
|
/* Else try again with more space. */
|
|
|
|
if (n > -1) /* C99 conform vsnprintf() */
|
2014-11-15 11:53:32 +00:00
|
|
|
size = (size_t) n + 1; /* precisely what is needed */
|
2009-10-12 11:49:35 +00:00
|
|
|
else /* glibc 2.0 */
|
|
|
|
size *= 2; /* twice the old size */
|
|
|
|
|
2014-11-15 11:53:32 +00:00
|
|
|
p = (char *) erealloc (p, size);
|
2009-10-12 11:49:35 +00:00
|
|
|
}
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static const char *
|
|
|
|
tr_type_str (TestResult * tr)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
const char *str = NULL;
|
2014-11-15 11:53:32 +00:00
|
|
|
|
2009-07-16 17:39:16 +00:00
|
|
|
if (tr->ctx == CK_CTX_TEST) {
|
|
|
|
if (tr->rtype == CK_PASS)
|
|
|
|
str = "P";
|
|
|
|
else if (tr->rtype == CK_FAILURE)
|
|
|
|
str = "F";
|
|
|
|
else if (tr->rtype == CK_ERROR)
|
|
|
|
str = "E";
|
|
|
|
} else
|
|
|
|
str = "S";
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2009-10-12 11:49:35 +00:00
|
|
|
static int
|
|
|
|
percent_passed (TestStats * t)
|
2009-07-16 17:39:16 +00:00
|
|
|
{
|
|
|
|
if (t->n_failed == 0 && t->n_errors == 0)
|
|
|
|
return 100;
|
|
|
|
else if (t->n_checked == 0)
|
|
|
|
return 0;
|
|
|
|
else
|
2009-10-12 11:49:35 +00:00
|
|
|
return (int) ((float) (t->n_checked - (t->n_failed + t->n_errors)) /
|
|
|
|
(float) t->n_checked * 100);
|
2009-07-16 17:39:16 +00:00
|
|
|
}
|