--- /dev/null
+/* Copyright (C) 2003 TSUTSUMI Kikuo.
+ This file is part of the CCUnit Library.
+
+ The CCUnit 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.
+
+ The CCUnit 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 the CCUnit Library; see the file COPYING.LESSER.
+ If not, write to the Free Software Foundation, Inc., 59 Temple
+ Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+/*
+ * $Id$
+ */
+/**@file
+ * TestFailure module implementation.
+ */
+
+#include <stdio.h>
+#include <ccunit/CCUnitTestFailure.h>
+
+/** @addtogroup CCUnitTestFailure TestFailure
+ * @{
+ */
+
+/**
+ * convert failure object to string.
+ * @param f failure object.
+ * @return string as failure.
+ */
+static const char* toString (CCUnitTestFailure* f)
+{
+ if (!f)
+ return NULL;
+ else
+ {
+ char* str = NULL;
+ size_t size = 63;
+ size_t require;
+ for (str = malloc (size); str != NULL; str = realloc (str, size))
+ {
+ if (!f->expect && !f->actual)
+ {
+ require = snprintf (str, size,
+ "%s:%u: %s\n", f->file, f->line, f->condstr);
+ }
+ else
+ {
+ require = snprintf (str, size,
+ "%s:%u: %s\n"
+ "\texpect: %s\n"
+ "\tactual: %s\n",
+ f->file, f->line, f->condstr,
+ f->expect,
+ f->actual);
+ }
+ if (require < 0)
+ size *= 2;
+ else if (require >= size)
+ size = require + 1;
+ else
+ {
+ str = realloc (str, require + 1);
+ break;
+ }
+ }
+ return str;
+ }
+}
+
+CCUnitTestFailure* ccunit_newTestFailure (const char* file,
+ unsigned int line,
+ const char* condstr,
+ const char* expect,
+ const char* actual)
+{
+ CCUnitTestFailure* f = calloc (1, sizeof (*f));
+ f->file = file;
+ f->line = line;
+ f->condstr = condstr;
+ f->expect = safe_strdup (expect);
+ f->actual = safe_strdup (actual);
+ f->toString = toString;
+ return f;
+}
+
+void ccunit_deleteTestFailure (CCUnitTestFailure* failure)
+{
+ safe_free ((char*)failure->expect);
+ safe_free ((char*)failure->actual);
+ safe_free (failure);
+}
+
+/** @} */
--- /dev/null
+/* -*- C -*- */
+/* Copyright (C) 2003 TSUTSUMI Kikuo.
+ This file is part of the CCUnit Library.
+
+ The CCUnit 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.
+
+ The CCUnit 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 the CCUnit Library; see the file COPYING.LESSER.
+ If not, write to the Free Software Foundation, Inc., 59 Temple
+ Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+/*
+ * $Id$
+ */
+/** @file
+ * TestFailure module.
+ */
+
+#ifndef CCUNITTESTFAILURE_H
+#define CCUNITTESTFAILURE_H
+
+#include <ccunit/CCUnitConfig.h>
+
+/**
+ * @defgroup CCUnitTestFailure TestFailure
+ *
+ * Collects a failed test together with the failed assertion.
+ *
+ * @{
+ */
+
+/**
+ * Collects a failed test together with the failed assertion.
+ * @see TestResult
+ */
+typedef struct CCUnitTestFailure CCUnitTestFailure;
+
+/**
+ * Collects a failed test together with the failed assertion.
+ * @see TestResult
+ */
+struct CCUnitTestFailure
+{
+ const char* file; /**< file name */
+ unsigned int line; /**< line No. */
+ const char* condstr; /**< test condition */
+ const char* expect; /**< expect value as string */
+ const char* actual; /**< actual value as string */
+ const char* (*toString)(CCUnitTestFailure*failure); /**< convert string function */
+};
+
+/**
+ * create new test failure.
+ *
+ * @param file file name cause failure.
+ * @param line line number cause failure.
+ * @param condstr test condition as string.
+ * @param expect expect value as string.
+ * @param actual actual value as string.
+ * @return new failure object.
+ */
+extern CCUnitTestFailure* ccunit_newTestFailure (const char* file,
+ unsigned int line,
+ const char* condstr,
+ const char* expect,
+ const char* actual);
+
+/**
+ * delete test failure object.
+ *
+ * @param failure failure object.
+ */
+extern void ccunit_deleteTestFailure (CCUnitTestFailure* failure);
+
+/** @} */
+
+#endif