* Licensed under the GNU Library General Public License, version 2.
* See the included file named LICENSE for license information.
*/
+#define _GNU_SOURCE
#include "wvtest.h"
#include <stdio.h>
#include <string.h>
bool wvtest_start_check_eq(const char *file, int line,
- int a, int b, bool expect_pass)
+ int a, int b, bool expect_pass,
+ const char *a_str, const char *b_str)
+{
+ char *str;
+ char sa[20], sb[20];
+ char *a_op = " == ", *b_op = " == ";
+ sprintf(sa, "%d", a);
+ sprintf(sb, "%d", b);
+ if (strcmp(sa, a_str) == 0)
+ a_str = a_op = "";
+ if (strcmp(sb, b_str) == 0)
+ b_str = b_op = "";
+ asprintf(&str, "%s%s%d %s %s%s%d", a_str, a_op, a, expect_pass ? "==" : "!=",
+ b_str, b_op, b);
+
+ wvtest_start(file, line, str);
+ free(str);
+
+ bool cond = (a == b);
+ if (!expect_pass)
+ cond = !cond;
+
+ wvtest_check(cond, NULL);
+ return cond;
+}
+
+bool wvtest_start_check_eq_ptr(const char *file, int line,
+ void *a, void *b, bool expect_pass)
{
size_t len = 11 + 11 + 8 + 1;
char *str = malloc(len);
- sprintf(str, "%d %s %d", a, expect_pass ? "==" : "!=", b);
+ sprintf(str, "%p %s %p", a, expect_pass ? "==" : "!=", b);
wvtest_start(file, line, str);
free(str);
const char *condstr, bool cond)
{ wvtest_start(file, line, condstr); wvtest_check(cond, NULL); return cond; }
bool wvtest_start_check_eq(const char *file, int line,
- int a, int b, bool expect_pass);
+ int a, int b, bool expect_pass,
+ const char *a_str, const char *b_str);
bool wvtest_start_check_lt(const char *file, int line,
int a, int b);
+bool wvtest_start_check_eq_ptr(const char *file, int line,
+ void *a, void *b, bool expect_pass);
bool wvtest_start_check_eq_str(const char *file, int line,
const char *a, const char *b, bool expect_pass);
bool wvtest_start_check_lt_str(const char *file, int line,
#define WVPASS(cond) \
wvtest_start_check(__FILE__, __LINE__, #cond, (cond))
#define WVPASSEQ(a, b) \
- wvtest_start_check_eq(__FILE__, __LINE__, (a), (b), true)
+ wvtest_start_check_eq(__FILE__, __LINE__, (a), (b), true, #a, #b)
#define WVPASSLT(a, b) \
wvtest_start_check_lt(__FILE__, __LINE__, (a), (b))
+#define WVPASSEQPTR(a, b) \
+ wvtest_start_check_eq_ptr(__FILE__, __LINE__, (a), (b), true)
+#define WVFAILEQPTR(a, b) \
+ wvtest_start_check_eq_ptr(__FILE__, __LINE__, (a), (b), false)
#define WVPASSEQSTR(a, b) \
wvtest_start_check_eq_str(__FILE__, __LINE__, (a), (b), true)
#define WVPASSLTSTR(a, b) \
#define WVFAIL(cond) \
wvtest_start_check(__FILE__, __LINE__, "NOT(" #cond ")", !(cond))
#define WVFAILEQ(a, b) \
- wvtest_start_check_eq(__FILE__, __LINE__, (a), (b), false)
+ wvtest_start_check_eq(__FILE__, __LINE__, (a), (b), false, #a, #b)
#define WVFAILEQSTR(a, b) \
- wvtest_start_check_eq_str(__FILE__, __LINE__, (a), (b), false)
+ wvtest_start_check_eq_str(__FILE__, __LINE__, (a), (b), false)
#define WVPASSNE(a, b) WVFAILEQ(a, b)
#define WVPASSNESTR(a, b) WVFAILEQSTR(a, b)
#define WVFAILNE(a, b) WVPASSEQ(a, b)