xref: /haiku/src/tests/add-ons/print/ppd/test/Test.cpp (revision 4420c1ceffd7f2246e4303d59cf02ed122980e9d)
1*4420c1ceSMichael Pfeiffer /*
2*4420c1ceSMichael Pfeiffer  * Copyright 2008, Haiku.
3*4420c1ceSMichael Pfeiffer  * Distributed under the terms of the MIT license.
4*4420c1ceSMichael Pfeiffer  *
5*4420c1ceSMichael Pfeiffer  * Authors:
6*4420c1ceSMichael Pfeiffer  *		Michael Pfeiffer <laplace@users.sourceforge.net>
7*4420c1ceSMichael Pfeiffer  */
8*4420c1ceSMichael Pfeiffer 
9*4420c1ceSMichael Pfeiffer #include <stdio.h>
10*4420c1ceSMichael Pfeiffer #include <stdlib.h>
11*4420c1ceSMichael Pfeiffer #include <string.h>
12*4420c1ceSMichael Pfeiffer #include <List.h>
13*4420c1ceSMichael Pfeiffer 
14*4420c1ceSMichael Pfeiffer void TestScanner();
15*4420c1ceSMichael Pfeiffer void TestParser();
16*4420c1ceSMichael Pfeiffer void TestPPDParser(bool all, bool verbose = true);
17*4420c1ceSMichael Pfeiffer void TestExtractUI();
18*4420c1ceSMichael Pfeiffer 
19*4420c1ceSMichael Pfeiffer const char* gPPDFile = "aptollw1.ppd";
20*4420c1ceSMichael Pfeiffer 
21*4420c1ceSMichael Pfeiffer static BList gArgs;
22*4420c1ceSMichael Pfeiffer 
enabled(const char * name,const char * arg)23*4420c1ceSMichael Pfeiffer bool enabled(const char* name, const char* arg)
24*4420c1ceSMichael Pfeiffer {
25*4420c1ceSMichael Pfeiffer 	gArgs.AddItem((void*)name);
26*4420c1ceSMichael Pfeiffer 	if (arg == NULL) return false;
27*4420c1ceSMichael Pfeiffer 	if (strcmp(arg, "all") == 0) return true;
28*4420c1ceSMichael Pfeiffer 	return strcmp(arg, name) == 0;
29*4420c1ceSMichael Pfeiffer }
30*4420c1ceSMichael Pfeiffer 
printArgs(const char * programName)31*4420c1ceSMichael Pfeiffer void printArgs(const char* programName)
32*4420c1ceSMichael Pfeiffer {
33*4420c1ceSMichael Pfeiffer 	fprintf(stderr, "%s: argument\n", programName);
34*4420c1ceSMichael Pfeiffer 	fprintf(stderr, "Argument is missing. The available arguments are:\n");
35*4420c1ceSMichael Pfeiffer 	fprintf(stderr, "  all\n");
36*4420c1ceSMichael Pfeiffer 	for (int i = 0; i < gArgs.CountItems(); i ++) {
37*4420c1ceSMichael Pfeiffer 		fprintf(stderr, "  %s\n", (const char*)gArgs.ItemAt(i));
38*4420c1ceSMichael Pfeiffer 	}
39*4420c1ceSMichael Pfeiffer }
40*4420c1ceSMichael Pfeiffer 
main(int argc,char * argv[])41*4420c1ceSMichael Pfeiffer int main(int argc, char* argv[])
42*4420c1ceSMichael Pfeiffer {
43*4420c1ceSMichael Pfeiffer 	const char* arg = argc >= 2 ? argv[1] : NULL;
44*4420c1ceSMichael Pfeiffer 
45*4420c1ceSMichael Pfeiffer 	if (argc >= 3) {
46*4420c1ceSMichael Pfeiffer 		gPPDFile = argv[2];
47*4420c1ceSMichael Pfeiffer 	}
48*4420c1ceSMichael Pfeiffer 
49*4420c1ceSMichael Pfeiffer 	if (enabled("scanner", arg)) {
50*4420c1ceSMichael Pfeiffer 		TestScanner();
51*4420c1ceSMichael Pfeiffer 	}
52*4420c1ceSMichael Pfeiffer 	if (enabled("parser", arg)) {
53*4420c1ceSMichael Pfeiffer 		TestParser();
54*4420c1ceSMichael Pfeiffer 	}
55*4420c1ceSMichael Pfeiffer 	if (enabled("ppd", arg)) {
56*4420c1ceSMichael Pfeiffer 		TestPPDParser(true);
57*4420c1ceSMichael Pfeiffer 	}
58*4420c1ceSMichael Pfeiffer 	if (enabled("header", arg)) {
59*4420c1ceSMichael Pfeiffer 		TestPPDParser(false);
60*4420c1ceSMichael Pfeiffer 	}
61*4420c1ceSMichael Pfeiffer 	if (enabled("ui", arg)) {
62*4420c1ceSMichael Pfeiffer 		TestExtractUI();
63*4420c1ceSMichael Pfeiffer 	}
64*4420c1ceSMichael Pfeiffer 	if (enabled("ppd-timing", arg)) {
65*4420c1ceSMichael Pfeiffer 		TestPPDParser(true, false);
66*4420c1ceSMichael Pfeiffer 	}
67*4420c1ceSMichael Pfeiffer 	if (enabled("header-timing", arg)) {
68*4420c1ceSMichael Pfeiffer 		TestPPDParser(false, false);
69*4420c1ceSMichael Pfeiffer 	}
70*4420c1ceSMichael Pfeiffer 
71*4420c1ceSMichael Pfeiffer 	if (arg == NULL) {
72*4420c1ceSMichael Pfeiffer 		printArgs(argv[0]);
73*4420c1ceSMichael Pfeiffer 	}
74*4420c1ceSMichael Pfeiffer }
75