belcard-tester.cpp 2.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
	belcard-tester.cpp
	Copyright (C) 2015  Belledonne Communications SARL

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program 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 General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Sylvain Berfini's avatar
Sylvain Berfini committed
19
#include "belcard-tester.hpp"
20
#include <bctoolbox/logging.h>
Sylvain Berfini's avatar
Sylvain Berfini committed
21 22 23


int main(int argc, char *argv[]) {
Sylvain Berfini's avatar
Sylvain Berfini committed
24 25 26 27
	int i;
	int ret;

	belcard_tester_init(NULL);
28

Sylvain Berfini's avatar
Sylvain Berfini committed
29 30 31 32 33 34
	if (strstr(argv[0], ".libs")) {
		int prefix_length = strstr(argv[0], ".libs") - argv[0] + 1;
		char prefix[200];
		sprintf(prefix, "%s%.*s", argv[0][0] == '/' ? "" : "./", prefix_length, argv[0]);
		bc_tester_set_resource_dir_prefix(prefix);
		bc_tester_set_writable_dir_prefix(prefix);
Sylvain Berfini's avatar
Sylvain Berfini committed
35
	}
36

Sylvain Berfini's avatar
Sylvain Berfini committed
37 38 39 40 41 42 43 44 45
	for(i = 1; i < argc; ++i) {
		int ret = bc_tester_parse_args(argc, argv, i);
		if (ret>0) {
			i += ret - 1;
			continue;
		} else if (ret<0) {
			bc_tester_helper(argv[0], "");
		}
		return ret;
46
	}
Sylvain Berfini's avatar
Sylvain Berfini committed
47 48 49 50 51 52 53 54

	ret = bc_tester_start(argv[0]);
	belcard_tester_uninit();
	return ret;
}

static void log_handler(int lev, const char *fmt, va_list args) {
#ifdef _WIN32
55 56
	vfprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, fmt, args);
	fprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, "\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
57 58 59 60
#else
	va_list cap;
	va_copy(cap,args);
	/* Otherwise, we must use stdio to avoid log formatting (for autocompletion etc.) */
61 62
	vfprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, fmt, cap);
	fprintf(lev == BCTBX_LOG_ERROR ? stderr : stdout, "\n");
Sylvain Berfini's avatar
Sylvain Berfini committed
63 64 65 66 67 68
	va_end(cap);
#endif
}

void belcard_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args)) {
	if (ftester_printf == NULL) ftester_printf = log_handler;
69
	bc_tester_init(ftester_printf, BCTBX_LOG_MESSAGE, BCTBX_LOG_ERROR, "vcards");
70

71
	bc_tester_add_suite(&vcard_general_properties_test_suite);
Sylvain Berfini's avatar
Sylvain Berfini committed
72
	bc_tester_add_suite(&vcard_identification_properties_test_suite);
73
	bc_tester_add_suite(&vcard_addressing_properties_test_suite);
Sylvain Berfini's avatar
Sylvain Berfini committed
74
	bc_tester_add_suite(&vcard_communication_properties_test_suite);
75 76 77 78 79
	bc_tester_add_suite(&vcard_geographical_properties_test_suite);
	bc_tester_add_suite(&vcard_organizational_properties_test_suite);
	bc_tester_add_suite(&vcard_explanatory_properties_test_suite);
	bc_tester_add_suite(&vcard_security_properties_test_suite);
	bc_tester_add_suite(&vcard_calendar_properties_test_suite);
80
	bc_tester_add_suite(&vcard_rfc6474_properties_test_suite);
81
	bc_tester_add_suite(&vcard_test_suite);
Sylvain Berfini's avatar
Sylvain Berfini committed
82 83 84 85
}

void belcard_tester_uninit(void) {
	bc_tester_uninit();
86
}