1 /******************************************************************************
2  *
3  *  versekeytest.cpp -
4  *
5  * $Id: versekeytest.cpp 3305 2014-12-15 02:02:48Z charcoal $
6  *
7  * Copyright 2007-2013 CrossWire Bible Society (http://www.crosswire.org)
8  *	CrossWire Bible Society
9  *	P. O. Box 2528
10  *	Tempe, AZ  85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #include <iostream>
24 #include <stdio.h>
25 #include <stdlib.h>
26 
27 #include <versekey.h>
28 #include <listkey.h>
29 #include <localemgr.h>
30 #include <swmgr.h>
31 #include <swmodule.h>
32 #ifndef NO_SWORD_NAMESPACE
33 using namespace sword;
34 #endif
35 
36 using std::cout;
37 using std::endl;
38 
39 class _System {
40 public:
41 class Out {
42 public:
println(const char * x)43 	void println(const char *x) { cout << x << endl; }
println(int x)44 	void println(int x) { cout << x << endl; }
45 } out;
46 } System;
47 
main(int argc,char ** argv)48 int main(int argc, char **argv) {
49 		VerseKey vk;
50 /*
51 		vk.setTestament(2);
52 		vk.setBook(4);
53 		vk.setChapter(3);
54 		vk.setVerse(1);
55 		System.out.println(vk.getText());
56 		System.out.println(vk.getIndex());
57 		System.out.println(vk.getTestamentIndex());
58 		vk.setVersificationSystem("KJVA");
59 		System.out.println(vk.getText());
60 		System.out.println(vk.getIndex());
61 		System.out.println(vk.getTestamentIndex());
62 		System.out.println("decrementing...");
63 		vk.setVersificationSystem("KJV");
64 		vk.decrement();
65 		System.out.println(vk.getText());
66 		System.out.println(vk.getIndex());
67 		System.out.println(vk.getTestamentIndex());
68 		vk.setVersificationSystem("KJVA");
69 		System.out.println(vk.getText());
70 		System.out.println(vk.getIndex());
71 		System.out.println(vk.getTestamentIndex());
72 */
73 
74 
75 /*
76 VerseKey currentVerse;
77 currentVerse.setAutoNormalize(true);
78 currentVerse.setIntros(true);
79 currentVerse.Persist(1);
80 currentVerse = "jn2";
81 cout << currentVerse << endl;
82 
83 	SWMgr mgr;
84 	SWModule *mod = mgr.getModule("KJVgb");
85 */
86 	VerseKey *parser = new VerseKey(); //(VerseKey *)mod->CreateKey();
87 	parser->setIntros(true);
88 
89 	ListKey result = parser->parseVerseList("[ Testament 1 Heading ]");
90 	cout << "Should be: [ Testament 1 Heading ]\n" << result << "\n\n";
91 
92 	parser->setText("[ Testament 1 Heading ]");
93 	cout << "Should be: [ Testament 1 Heading ]\n" << *parser << "\n\n";
94 
95 	result.clear();
96 
97 	ListKey scope = parser->parseVerseList("amos 2:2", *parser, true);
98 
99 	cout << ((scope++ == scope) ? "single" : "multiple") << "\n";
100 
101 	scope = parser->parseVerseList("amos", *parser, true);
102 
103 	cout << ((scope++ == scope) ? "single" : "multiple") << "\n";
104 
105 	scope = parser->parseVerseList("amos", *parser, true);
106 
107 	scope++;
108 	scope++;
109 	scope++;
110 	scope++;
111 
112 	VerseKey *x = new VerseKey(); //(VerseKey *)mod->CreateKey();
113 	*x = scope;
114 	x->clearBound();
115 
116 	std::cout << "x: " << x->getText() << "\n";
117 
118 	result << *x;
119 
120 	std::cout << result.getText() << "\n";
121 
122 	result = TOP;
123 
124 	std::cout << result.getText() << "\n";
125 
126      const char *bounds = "lk,acts";
127      scope = parser->parseVerseList(bounds, *parser, true);
128 
129      VerseKey boundTest("lk", "acts");
130 
131      boundTest.setText("Is.1.13");
132      std::cout << "Error: " << (int)boundTest.popError() << ": " << boundTest << "\n";
133      boundTest.setText("1Sam.21.1");
134      std::cout << "Error: " << (int)boundTest.popError() << ": " << boundTest << "\n";
135      boundTest.setText("acts.5.1");
136      std::cout << "Error: " << (int)boundTest.popError() << ": " << boundTest << "\n";
137      boundTest.setText("rom.5.1");
138      std::cout << "Error: " << (int)boundTest.popError() << ": " << boundTest << "\n";
139 
140 
141      *x = "Is.1.13";
142      scope = *x;
143      if (scope == *x) std::cout << "Error restricting bounds: " << x->getText() << " is in " << bounds << "\n";
144      if (!scope.popError()) std::cout << "Error restricting bounds: " << x->getText() << " is in " << bounds << "\n";
145 
146      *x = "1Sam.21.1";
147      scope = *x;
148      if (!scope.popError()) std::cout << "Error restricting bounds: " << x->getText() << " is in " << bounds << "\n";
149 
150 /*
151 	VerseKey *y = (VerseKey *)mod->CreateKey();
152 	(*y) = "lev 1.1";
153 	cout << (*y) << "\n";
154 	(*y)++;
155 	cout << (*y) << "\n";
156 	(*y)--;
157 	cout << (*y) << "\n";
158 	(*y)--;
159 	cout << (*y) << "\n";
160 
161 	mod->setKey("Ruth 1.1");
162 	cout << mod->getKeyText() << "\n";
163 	(*mod)++;
164 	cout << mod->getKeyText() << "\n";
165 	(*mod)--;
166 	cout << mod->getKeyText() << "\n";
167 */
168 
169 	cout << "\nNormalization on; headings on ====\n\n";
170 
171 	vk.setAutoNormalize(true);
172 	vk.setIntros(true);
173 
174 	vk = "jn3.50";
175 	cout << "jn.3.50: " << vk << "\n";
176 	vk++;
177 	cout << "++: " << vk << "\n";
178 	vk--;
179 	cout << "--: " << vk << "\n";
180 	vk = MAXVERSE;
181 	cout << "MAXVERSE: " << vk << "\n";
182 	vk = MAXCHAPTER;
183 	cout << "MAXCHAPTER: " << vk << "\n";
184 	vk = TOP;
185 	cout << "TOP: " << vk << "\n";
186 	vk = BOTTOM;
187 	cout << "BOTTOM: " << vk << "\n";
188 
189 	cout << "\nNormalization off; headings on ====\n\n";
190 
191 	vk.setAutoNormalize(false);
192 	vk.setIntros(true);
193 
194 	vk = "jn3.50";
195 	cout << "jn.3.50: " << vk << "\n";
196 	vk++;
197 	cout << "++: " << vk << "\n";
198 	vk--;
199 	cout << "--: " << vk << "\n";
200 	vk = MAXVERSE;
201 	cout << "MAXVERSE: " << vk << "\n";
202 	vk = MAXCHAPTER;
203 	cout << "MAXCHAPTER: " << vk << "\n";
204 	vk = TOP;
205 	cout << "TOP: " << vk << "\n";
206 	vk = BOTTOM;
207 	cout << "BOTTOM: " << vk << "\n";
208 
209 	cout << "\nNormalization on; headings off ====\n\n";
210 
211 	vk.setAutoNormalize(true);
212 	vk.setIntros(false);
213 
214 	vk = "jn3.50";
215 	cout << "jn.3.50: " << vk << "\n";
216 	vk++;
217 	cout << "++: " << vk << "\n";
218 	vk--;
219 	cout << "--: " << vk << "\n";
220 	vk = MAXVERSE;
221 	cout << "MAXVERSE: " << vk << "\n";
222 	vk = MAXCHAPTER;
223 	cout << "MAXCHAPTER: " << vk << "\n";
224 	vk = TOP;
225 	cout << "TOP: " << vk << "\n";
226 	vk = BOTTOM;
227 	cout << "BOTTOM: " << vk << "\n";
228 
229 	cout << "\nNormalization off; headings off ====\n\n";
230 
231 	vk.setAutoNormalize(false);
232 	vk.setIntros(false);
233 
234 	vk = "jn3.50";
235 	cout << "jn.3.50: " << vk << "\n";
236 	vk++;
237 	cout << "++: " << vk << "\n";
238 	vk--;
239 	cout << "--: " << vk << "\n";
240 	vk = MAXVERSE;
241 	cout << "MAXVERSE: " << vk << "\n";
242 	vk = MAXCHAPTER;
243 	cout << "MAXCHAPTER: " << vk << "\n";
244 	vk = TOP;
245 	cout << "TOP: " << vk << "\n";
246 	vk = BOTTOM;
247 	cout << "BOTTOM: " << vk << "\n";
248 
249 	VerseKey yo = "jn.3.16";
250 	VerseKey yo2 = yo++;
251 	cout << yo2 << ": " << (int)yo2.popError() <<  endl;
252 
253 	VerseKey vkey;
254 	VerseKey tmpkey = "1sam 1:1";
255 	vkey.setAutoNormalize(true);
256 	vkey = tmpkey;
257 	int chapter = (vkey.getChapter()-1);
258 	vkey.setChapter(chapter);
259 
260 	cout << tmpkey << ": getChapter() - 1: " << vkey << endl;
261 
262 	cout << "\nBook math\n\n";
263 
264 	vkey = "Mark.1.1";
265 	vkey--;
266 	cout << "Mark.1.1-- = " << vkey << "\n";
267 	vkey++;
268 	cout << "++ = " << vkey << "\n";
269 	vkey.setChapter(vkey.getChapter() - 1);
270 	cout << ".setChapter(.getChapter() - 1) = " << vkey << "\n";
271 
272 	vkey = "Matthew.1.1";
273 	vkey--;
274 	cout << "Matthew.1.1-- = " << vkey << "\n";
275 	vkey++;
276 	cout << "++ = " << vkey << "\n";
277 	vkey.setBook(vkey.getBook() - 1);
278 	cout << ".setBook(.getBook() - 1) = " << vkey << "\n";
279 
280 	cout << "\nChapter math\n\n";
281 
282 	cout << "Matthew.1.1 - 1 chapter\n";
283 	vkey = "Matthew.1.1";
284 	vkey.setChapter(vkey.getChapter() - 1);
285 	cout << ".setChapter(.getChapter() - 1) = " << vkey << "\n";
286 
287 	cout << "\nVerse math\n\n";
288 
289 	cout << "Matthew.1.1 - 1 verse\n";
290 	vkey = "Matthew.1.1";
291 	vkey.setVerse(vkey.getVerse() - 1);
292 	cout << ".setVerse(.getVerse() - 1) = " << vkey << "\n";
293 
294 	return 0;
295 }
296