summaryrefslogtreecommitdiff
path: root/dviware/dvi2bitmap/test/t2.cc
blob: ff7091b9274cd9934250b7f6ae5417da8f842841 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

#include "config.h"

#include <iostream>

#if HAVE_CSTD_INCLUDE
#include <cstdlib>
#else
#include <stdlib.h>
#endif

#include <string>

using STD::cerr;
using STD::cout;
using STD::exit;
using STD::endl;
using STD::string;

#include "PkFont.h"

void Usage(void);

struct {
    string fmt;
    string mode;
    string fontname;
    int dpi;
    int basedpi;
    double magnification;
    string expected;		// zero-length if it should fail
} tests[] = {
    { "f=%f m=%m b=%b d=%d M=%M %%", "ibmvga", "cmr10", 330, 110, 3.0,
      "f=cmr10 m=3 b=110 d=330 M=ibmvga %" },
    { "%f%m%b%d%M", "ibmvga", "cmr10", 330, 110, 3.0,
      "cmr103110330ibmvga", },
    { "%f-%f-%%f%%%f", "ibmvga", "cmr10", 330, 110, 3.0,
      "cmr10-cmr10-%f%cmr10", },
    { "%f-%f-%%f%x%f", "ibmvga", "cmr10", 330, 110, 3.0,
      "", },			// fails -- has %x specifier
};
int ntests = sizeof(tests)/sizeof(tests[0]);

char *progname;

int main (int argc, char **argv)
{
    progname = argv[0];

    for (argc--, argv++; argc>0; argc--, argv++)
        if (**argv == '-') {
            switch (*++*argv) {
              case 'v':         // verbose
                PkFont::verbosity (debug);
                break;
              default:
                Usage();
            }
        } else {
            Usage();
        }

    int i;
    int nfails = 0;

    for (i=0; i<ntests; i++) {
	try {
	    string res = PkFont::substitute_font_string
		    (tests[i].fmt, tests[i].mode, tests[i].fontname,
		     tests[i].dpi, tests[i].basedpi, tests[i].magnification);
	    if (tests[i].expected.length() == 0) {
		// should have failed
		nfails++;
		cerr << "Test " << i
		     << " should have thrown an exception, but got <"
		     << res << "> instead" << endl;
	    } else if (res != tests[i].expected) {
		nfails++;
		cerr << "Test " << i << ": expected <" << tests[i].expected
		     << ">, got <" << res << ">" << endl;
	    }
	} catch (PkError& e) {
	    if (tests[i].expected.length() != 0) {
		// should have succeeded
		nfails++;
		cerr << "Test " << i << ": expected <" 
		     << tests[i].expected << ">, but got exception" << endl;
	    }
	}
    }

    exit (nfails);
}


void Usage(void)
{
    cerr << "Usage: " << progname << " [-v]" << endl;
    exit (1);
}