summaryrefslogtreecommitdiff
path: root/dviware/dvi2bitmap/test/t3.cc
blob: 9bc6fd8b6b53e0c9580fc9f99a6161acbddeda57 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

#include "config.h"

#include <iostream>
#include <string>


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

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

#include "PageRange.h"

int usecounts;
int nfails = 0;

int counts[] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};

#if 0
char sel(PageRange&, int i);
char sel(PageRange& p, int i) 
{
    if (usecounts >= 0) {
	counts[usecounts] = i;
	return p.isSelected(1, counts) ? '+' : '-';
    } else {
	counts[0] = 1;
	return p.isSelected(i, counts) ? '+' : '-';
    }
}

void show_selections(PageRange& pr, string prefix, int from, int to)
{
    cout << prefix;
    for (; from <= to; from++)
	cout << ' ' << from << sel(pr, from);
    cout << endl;
    return;
}
#endif

// If issel is true, assert that page i is selected in the pagerange p
// If global usecounts is >=0 then set counts[usecounts] to number i and 
// test that (the DVI sequence number which is the first argument to
// isSelected is then irrelevant).
void sel(string label, PageRange& p, int i, bool issel);
void sel(string label, PageRange& p, int i, bool issel)
{
    int testn;
    
    if (usecounts >= 0) {
	counts[usecounts] = i;
	testn = 1;
    } else {
	counts[0] = 1;
	testn = i;
    }
    
    if (issel) {
	if (!p.isSelected(testn, counts)) {
	    cerr << label << ": page " << testn << " unselected" << endl;
	    nfails++;
	}
    } else {
	if (p.isSelected(testn, counts)) {
	    cerr << label << ": page " << testn << " selected" << endl;
	    nfails++;
	}
    }
}

int main (int argc, char **argv)
{
    usecounts = -1;
    PageRange pr1;
    sel("1-1", pr1, 4, true);
    sel("1-1", pr1, 5, true);
    sel("1-1", pr1, 6, true);
    sel("1-1", pr1, 7, true);

    pr1.addSpec('p', "=5");
    sel("1-2", pr1, 4, false);
    sel("1-2", pr1, 5, true);
    sel("1-2", pr1, 6, true);
    sel("1-2", pr1, 7, true);

    pr1.addSpec('l', "=6");
    sel("1-3", pr1, 4, false);
    sel("1-3", pr1, 5, true);
    sel("1-3", pr1, 6, true);
    sel("1-3", pr1, 7, false);

    PageRange pr2;
    pr2.addSpec('P', "=3,5-7");
    sel("2", pr2, 1, false);
    sel("2", pr2, 2, false);
    sel("2", pr2, 3, true);
    sel("2", pr2, 4, false);
    sel("2", pr2, 5, true);
    sel("2", pr2, 6, true);
    sel("2", pr2, 7, true);
    sel("2", pr2, 8, false);

    usecounts = 0;
    PageRange pr3;
    sel("3-1", pr3, 4, true);
    sel("3-1", pr3, 5, true);
    sel("3-1", pr3, 6, true);
    sel("3-1", pr3, 7, true);
    
    pr3.addSpec('p', "5");
    sel("3-2", pr3, 4, false);
    sel("3-2", pr3, 5, true);
    sel("3-2", pr3, 6, true);
    sel("3-2", pr3, 7, true);

    pr3.addSpec('l', "6");
    sel("3-3", pr3, 4, false);
    sel("3-3", pr3, 5, true);
    sel("3-3", pr3, 6, true);
    sel("3-3", pr3, 7, false);
    
    PageRange pr4;
    pr4.addSpec('P', "3,5-7");
    sel("4", pr4, 1, false);
    sel("4", pr4, 2, false);
    sel("4", pr4, 3, true);
    sel("4", pr4, 4, false);
    sel("4", pr4, 5, true);
    sel("4", pr4, 6, true);
    sel("4", pr4, 7, true);
    sel("4", pr4, 8, false);

    usecounts = 4;
    PageRange pr5;
    sel("5-1", pr5, 4, true);
    sel("5-1", pr5, 5, true);
    sel("5-1", pr5, 6, true);
    sel("5-1", pr5, 7, true);

    pr5.addSpec('p', ":4:5");
    sel("5-2", pr5, 4, false);
    sel("5-2", pr5, 5, true);
    sel("5-2", pr5, 6, true);
    sel("5-2", pr5, 7, true);

    pr5.addSpec('l', ":4:6");
    sel("5-3", pr5, 4, false);
    sel("5-3", pr5, 5, true);
    sel("5-3", pr5, 6, true);
    sel("5-3", pr5, 7, false);
    
    PageRange pr6;
    pr6.addSpec('P', ":4:3,5-7");
    sel("6", pr6, 1, false);
    sel("6", pr6, 2, false);
    sel("6", pr6, 3, true);
    sel("6", pr6, 4, false);
    sel("6", pr6, 5, true);
    sel("6", pr6, 6, true);
    sel("6", pr6, 7, true);
    sel("6", pr6, 8, false);

    exit(nfails);
}