File: test.c

package info (click to toggle)
libdiscid 0.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 1,860 kB
  • sloc: sh: 4,948; ansic: 2,475; makefile: 81
file content (78 lines) | stat: -rw-r--r-- 1,955 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* --------------------------------------------------------------------------

   MusicBrainz -- The Internet music metadatabase

   Copyright (C) 2013 Johannes Dewender

   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 Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

--------------------------------------------------------------------------- */
#include <stdio.h>
#include <string.h>

#include "test.h"


char details[DETAIL_LENGTH] = "\0";
int passed = 0;
int tests = 0;


void announce(const char *text) {
	printf("Testing %s ... ", text);
}

void evaluate(int result) {
	if (result) {
		printf("OK\n");
		passed++;
	} else {
		printf("Failed\n");
		if (strlen(details)) {
			printf("%s", details);
		}
	}
	tests++;
}

int equal_int(int result, int expected) {
	if (expected == result) {
		return 1;
	} else {
		snprintf(details, sizeof details,
				"\tExpected : %d\n\tActual   : %d\n",
				expected, result);
		return 0;
	}
}

int equal_str(const char *result, const char *expected) {
	if (strcmp(expected, result) == 0) {
		return 1;
	} else {
		snprintf(details, sizeof details,
				"\tExpected : %s\n\tActual   : %s\n",
				expected, result);
		return 0;
	}
}

int test_result() {
	printf("\n%d tests, %d passed, %d failed\n",
	       tests, passed, tests - passed);
	return passed == tests;
}

/* EOF */