Skip to content

Commit

Permalink
test: merge test_helpers.c and index.c
Browse files Browse the repository at this point in the history
No need to keep them separate. Originally I thought index.c was only
going to contain the list of tests, but that didn't happen.
  • Loading branch information
wm4 committed Nov 8, 2019
1 parent 98b38b0 commit a6c8b4e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 66 deletions.
2 changes: 1 addition & 1 deletion player/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include "demux/demux.h"
#include "misc/thread_tools.h"
#include "sub/osd.h"
#include "test/index.h"
#include "test/tests.h"
#include "video/out/vo.h"

#include "core.h"
Expand Down
3 changes: 1 addition & 2 deletions test/chmap.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "audio/chmap.h"
#include "audio/chmap_sel.h"
#include "index.h"
#include "test_helpers.h"
#include "tests.h"

#define LAYOUTS(...) (char*[]){__VA_ARGS__, NULL}

Expand Down
3 changes: 1 addition & 2 deletions test/gl_video.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "index.h"
#include "test_helpers.h"
#include "tests.h"
#include "video/out/gpu/video.h"

static void run(struct test_ctx *ctx)
Expand Down
3 changes: 1 addition & 2 deletions test/json.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "common/common.h"
#include "index.h"
#include "misc/json.h"
#include "misc/node.h"
#include "test_helpers.h"
#include "tests.h"

struct entry {
const char *src;
Expand Down
3 changes: 1 addition & 2 deletions test/linked_list.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "common/common.h"
#include "index.h"
#include "misc/linked_list.h"
#include "test_helpers.h"
#include "tests.h"

struct list_item {
int v;
Expand Down
29 changes: 0 additions & 29 deletions test/test_helpers.c

This file was deleted.

24 changes: 0 additions & 24 deletions test/test_helpers.h

This file was deleted.

28 changes: 27 additions & 1 deletion test/index.c → test/tests.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "index.h"
#include "player/core.h"
#include "tests.h"

static const struct unittest *unittests[] = {
&test_chmap,
Expand Down Expand Up @@ -55,3 +55,29 @@ bool run_tests(struct MPContext *mpctx)
#ifdef NDEBUG
static_assert(false, "don't define NDEBUG for tests");
#endif

void assert_int_equal_impl(const char *file, int line, int64_t a, int64_t b)
{
if (a != b) {
printf("%s:%d: %"PRId64" != %"PRId64"\n", file, line, a, b);
abort();
}
}

void assert_string_equal_impl(const char *file, int line,
const char *a, const char *b)
{
if (strcmp(a, b) != 0) {
printf("%s:%d: '%s' != '%s'\n", file, line, a, b);
abort();
}
}

void assert_float_equal_impl(const char *file, int line,
double a, double b, double tolerance)
{
if (fabs(a - b) > tolerance) {
printf("%s:%d: %f != %f\n", file, line, a, b);
abort();
}
}
21 changes: 20 additions & 1 deletion test/index.h → test/tests.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include <stdbool.h>
#include <float.h>
#include <inttypes.h>
#include <math.h>

#include "common/common.h"

struct MPContext;

Expand Down Expand Up @@ -30,3 +34,18 @@ extern const struct unittest test_chmap;
extern const struct unittest test_gl_video;
extern const struct unittest test_json;
extern const struct unittest test_linked_list;

#define assert_true(x) assert(x)
#define assert_false(x) assert(!(x))
#define assert_int_equal(a, b) \
assert_int_equal_impl(__FILE__, __LINE__, (a), (b))
#define assert_string_equal(a, b) \
assert_string_equal_impl(__FILE__, __LINE__, (a), (b))
#define assert_float_equal(a, b, tolerance) \
assert_float_equal_impl(__FILE__, __LINE__, (a), (b), (tolerance))

void assert_int_equal_impl(const char *file, int line, int64_t a, int64_t b);
void assert_string_equal_impl(const char *file, int line,
const char *a, const char *b);
void assert_float_equal_impl(const char *file, int line,
double a, double b, double tolerance);
3 changes: 1 addition & 2 deletions wscript_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,9 @@ def swift(task):
## Tests
( "test/chmap.c", "tests" ),
( "test/gl_video.c", "tests" ),
( "test/index.c", "tests" ),
( "test/json.c", "tests" ),
( "test/linked_list.c", "tests" ),
( "test/test_helpers.c", "tests" ),
( "test/tests.c", "tests" ),

## Video
( "video/csputils.c" ),
Expand Down

0 comments on commit a6c8b4e

Please sign in to comment.