Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <sal/types.h>
11 : #include "cppunit/TestAssert.h"
12 : #include "cppunit/TestFixture.h"
13 : #include "cppunit/extensions/HelperMacros.h"
14 : #include "cppunit/plugin/TestPlugIn.h"
15 :
16 : #include "osl/file.hxx"
17 : #include "osl/process.h"
18 :
19 : #include "scanner.hxx"
20 :
21 : namespace
22 : {
23 1038 : struct Symbol
24 : {
25 : sal_uInt16 line;
26 : sal_uInt16 col1;
27 : sal_uInt16 col2;
28 : rtl::OUString text;
29 : double number;
30 : SbxDataType type;
31 : };
32 :
33 : /**
34 : * Perform tests on Scanner.
35 : */
36 30 : class ScannerTest : public CppUnit::TestFixture
37 : {
38 : private:
39 : void testBlankLines();
40 : void testOperators();
41 : void testAlphanum();
42 : void testComments();
43 : void testGoto();
44 : void testGotoCompatible();
45 : void testExclamation();
46 : void testNumbers();
47 : void testDataType();
48 : void testHexOctal();
49 :
50 : // Adds code needed to register the test suite
51 2 : CPPUNIT_TEST_SUITE(ScannerTest);
52 :
53 : // Declares the method as a test to call
54 1 : CPPUNIT_TEST(testBlankLines);
55 1 : CPPUNIT_TEST(testOperators);
56 1 : CPPUNIT_TEST(testAlphanum);
57 1 : CPPUNIT_TEST(testComments);
58 1 : CPPUNIT_TEST(testGoto);
59 1 : CPPUNIT_TEST(testGotoCompatible);
60 1 : CPPUNIT_TEST(testExclamation);
61 1 : CPPUNIT_TEST(testNumbers);
62 1 : CPPUNIT_TEST(testDataType);
63 1 : CPPUNIT_TEST(testHexOctal);
64 :
65 : // End of test suite definition
66 2 : CPPUNIT_TEST_SUITE_END();
67 : };
68 :
69 1 : const static rtl::OUString cr(RTL_CONSTASCII_USTRINGPARAM("\n"));
70 1 : const static rtl::OUString rem(RTL_CONSTASCII_USTRINGPARAM("REM"));
71 1 : const static rtl::OUString asdf(RTL_CONSTASCII_USTRINGPARAM("asdf"));
72 1 : const static rtl::OUString dot(RTL_CONSTASCII_USTRINGPARAM("."));
73 1 : const static rtl::OUString goto_(RTL_CONSTASCII_USTRINGPARAM("goto"));
74 1 : const static rtl::OUString excl(RTL_CONSTASCII_USTRINGPARAM("!"));
75 :
76 80 : std::vector<Symbol> getSymbols(const rtl::OUString& source, sal_Int32& errors, bool bCompatible = false)
77 : {
78 80 : std::vector<Symbol> symbols;
79 80 : SbiScanner scanner(source);
80 80 : scanner.EnableErrors();
81 80 : scanner.SetCompatible(bCompatible);
82 353 : while(scanner.NextSym())
83 : {
84 193 : Symbol symbol;
85 193 : symbol.line = scanner.GetLine();
86 193 : symbol.col1 = scanner.GetCol1();
87 193 : symbol.col2 = scanner.GetCol2();
88 193 : symbol.text = scanner.GetSym();
89 193 : symbol.number = scanner.GetDbl();
90 193 : symbol.type = scanner.GetType();
91 193 : symbols.push_back(symbol);
92 193 : }
93 80 : errors = scanner.GetErrors();
94 80 : return symbols;
95 : }
96 :
97 64 : std::vector<Symbol> getSymbols(const rtl::OUString& source, bool bCompatible = false)
98 : {
99 : sal_Int32 i;
100 64 : return getSymbols(source, i, bCompatible);
101 : }
102 :
103 1 : void ScannerTest::testBlankLines()
104 : {
105 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM(""));
106 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("\r\n"));
107 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("\n"));
108 1 : const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("\r"));
109 1 : const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("\r\n\r\n"));
110 1 : const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("\n\r"));
111 1 : const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("\n\r\n"));
112 1 : const rtl::OUString source8(RTL_CONSTASCII_USTRINGPARAM("\r\n\r"));
113 1 : const rtl::OUString source9(RTL_CONSTASCII_USTRINGPARAM(" "));
114 :
115 1 : std::vector<Symbol> symbols;
116 1 : symbols = getSymbols(source1);
117 1 : CPPUNIT_ASSERT(symbols.empty());
118 :
119 1 : symbols = getSymbols(source2);
120 1 : CPPUNIT_ASSERT(symbols.size() == 1);
121 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
122 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
123 :
124 1 : symbols = getSymbols(source3);
125 1 : CPPUNIT_ASSERT(symbols.size() == 1);
126 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
127 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
128 :
129 1 : symbols = getSymbols(source4);
130 1 : CPPUNIT_ASSERT(symbols.size() == 1);
131 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
132 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
133 :
134 1 : symbols = getSymbols(source5);
135 1 : CPPUNIT_ASSERT(symbols.size() == 2);
136 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
137 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
138 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
139 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
140 :
141 1 : symbols = getSymbols(source6);
142 1 : CPPUNIT_ASSERT(symbols.size() == 2);
143 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
144 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
145 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
146 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
147 :
148 1 : symbols = getSymbols(source7);
149 1 : CPPUNIT_ASSERT(symbols.size() == 2);
150 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
151 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
152 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
153 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
154 :
155 1 : symbols = getSymbols(source8);
156 1 : CPPUNIT_ASSERT(symbols.size() == 2);
157 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
158 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
159 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
160 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
161 :
162 1 : symbols = getSymbols(source9);
163 1 : CPPUNIT_ASSERT(symbols.size() == 1);
164 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
165 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
166 1 : }
167 :
168 1 : void ScannerTest::testOperators()
169 : {
170 1 : const rtl::OUString sourceE(RTL_CONSTASCII_USTRINGPARAM("="));
171 1 : const rtl::OUString sourceLT(RTL_CONSTASCII_USTRINGPARAM("<"));
172 1 : const rtl::OUString sourceGT(RTL_CONSTASCII_USTRINGPARAM(">"));
173 1 : const rtl::OUString sourceLTE(RTL_CONSTASCII_USTRINGPARAM("<="));
174 1 : const rtl::OUString sourceGTE(RTL_CONSTASCII_USTRINGPARAM(">="));
175 1 : const rtl::OUString sourceEE(RTL_CONSTASCII_USTRINGPARAM("=="));
176 1 : const rtl::OUString sourceNE(RTL_CONSTASCII_USTRINGPARAM("<>"));
177 1 : const rtl::OUString sourceA(RTL_CONSTASCII_USTRINGPARAM(":="));
178 :
179 1 : std::vector<Symbol> symbols;
180 :
181 1 : symbols = getSymbols(sourceE);
182 1 : CPPUNIT_ASSERT(symbols.size() == 2);
183 1 : CPPUNIT_ASSERT(symbols[0].text == sourceE);
184 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
185 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
186 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
187 :
188 1 : symbols = getSymbols(sourceLT);
189 1 : CPPUNIT_ASSERT(symbols.size() == 2);
190 1 : CPPUNIT_ASSERT(symbols[0].text == sourceLT);
191 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
192 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
193 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
194 :
195 1 : symbols = getSymbols(sourceGT);
196 1 : CPPUNIT_ASSERT(symbols.size() == 2);
197 1 : CPPUNIT_ASSERT(symbols[0].text == sourceGT);
198 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
199 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
200 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
201 :
202 1 : symbols = getSymbols(sourceLTE);
203 1 : CPPUNIT_ASSERT(symbols.size() == 2);
204 1 : CPPUNIT_ASSERT(symbols[0].text == sourceLTE);
205 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
206 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
207 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
208 :
209 1 : symbols = getSymbols(sourceGTE);
210 1 : CPPUNIT_ASSERT(symbols.size() == 2);
211 1 : CPPUNIT_ASSERT(symbols[0].text == sourceGTE);
212 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
213 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
214 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
215 :
216 1 : symbols = getSymbols(sourceEE);
217 1 : CPPUNIT_ASSERT(symbols.size() == 3);
218 1 : CPPUNIT_ASSERT(symbols[0].text == sourceE);
219 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
220 1 : CPPUNIT_ASSERT(symbols[1].text == sourceE);
221 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
222 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
223 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
224 :
225 1 : symbols = getSymbols(sourceNE);
226 1 : CPPUNIT_ASSERT(symbols.size() == 2);
227 1 : CPPUNIT_ASSERT(symbols[0].text == sourceNE);
228 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
229 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
230 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
231 :
232 1 : symbols = getSymbols(sourceA);
233 1 : CPPUNIT_ASSERT(symbols.size() == 2);
234 1 : CPPUNIT_ASSERT(symbols[0].text == sourceA);
235 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
236 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
237 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
238 1 : }
239 :
240 1 : void ScannerTest::testAlphanum()
241 : {
242 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("asdfghefg"));
243 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("1asfdasfd"));
244 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("AdfsaAUdsl10987"));
245 1 : const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("asdfa_mnvcnm"));
246 1 : const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("_asdf1"));
247 1 : const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("_6"));
248 1 : const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("joxclk_"));
249 1 : const rtl::OUString source8(RTL_CONSTASCII_USTRINGPARAM(" asdf "));
250 1 : const rtl::OUString source9(RTL_CONSTASCII_USTRINGPARAM(" 19395 asdfa "));
251 1 : const rtl::OUString source10(RTL_CONSTASCII_USTRINGPARAM("\n1\n2\na sdf"));
252 1 : const rtl::OUString source11(RTL_CONSTASCII_USTRINGPARAM("asdf.asdf"));
253 1 : const rtl::OUString source12(RTL_CONSTASCII_USTRINGPARAM(".."));
254 :
255 1 : std::vector<Symbol> symbols;
256 :
257 1 : symbols = getSymbols(source1);
258 1 : CPPUNIT_ASSERT(symbols.size() == 2);
259 1 : CPPUNIT_ASSERT(symbols[0].text == source1);
260 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
261 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
262 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
263 :
264 1 : symbols = getSymbols(source2);
265 1 : CPPUNIT_ASSERT(symbols.size() == 3);
266 1 : CPPUNIT_ASSERT(symbols[0].text.isEmpty()); // Can't start symbol with a digit
267 1 : CPPUNIT_ASSERT(symbols[0].number == 1);
268 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
269 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("asfdasfd")));
270 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
271 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
272 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
273 :
274 1 : symbols = getSymbols(source3);
275 1 : CPPUNIT_ASSERT(symbols.size() == 2);
276 1 : CPPUNIT_ASSERT(symbols[0].text == source3);
277 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
278 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
279 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
280 :
281 1 : symbols = getSymbols(source4);
282 1 : CPPUNIT_ASSERT(symbols.size() == 2);
283 1 : CPPUNIT_ASSERT(symbols[0].text == source4);
284 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
285 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
286 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
287 :
288 1 : symbols = getSymbols(source5);
289 1 : CPPUNIT_ASSERT(symbols.size() == 2);
290 1 : CPPUNIT_ASSERT(symbols[0].text == source5);
291 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
292 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
293 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
294 :
295 1 : symbols = getSymbols(source6);
296 1 : CPPUNIT_ASSERT(symbols.size() == 2);
297 1 : CPPUNIT_ASSERT(symbols[0].text == source6);
298 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
299 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
300 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
301 :
302 1 : symbols = getSymbols(source7);
303 1 : CPPUNIT_ASSERT(symbols.size() == 2);
304 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("joxclk_")));
305 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
306 1 : CPPUNIT_ASSERT(source7 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("joxclk "))); // Change the trailing '_' to a ' '
307 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
308 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
309 :
310 1 : symbols = getSymbols(source8);
311 1 : CPPUNIT_ASSERT(symbols.size() == 2);
312 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("asdf")));
313 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
314 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
315 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
316 :
317 1 : symbols = getSymbols(source9);
318 1 : CPPUNIT_ASSERT(symbols.size() == 3);
319 1 : CPPUNIT_ASSERT(symbols[0].text.isEmpty());
320 1 : CPPUNIT_ASSERT(symbols[0].number = 19395);
321 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
322 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("asdfa")));
323 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
324 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
325 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
326 :
327 1 : symbols = getSymbols(source10);
328 1 : CPPUNIT_ASSERT(symbols.size() == 8);
329 1 : CPPUNIT_ASSERT(symbols[0].text == cr);
330 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
331 1 : CPPUNIT_ASSERT(symbols[1].text.isEmpty());
332 1 : CPPUNIT_ASSERT(symbols[1].number == 1);
333 1 : CPPUNIT_ASSERT(symbols[1].type == SbxINTEGER);
334 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
335 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
336 1 : CPPUNIT_ASSERT(symbols[3].text.isEmpty());
337 1 : CPPUNIT_ASSERT(symbols[3].number == 2);
338 1 : CPPUNIT_ASSERT(symbols[3].type == SbxINTEGER);
339 1 : CPPUNIT_ASSERT(symbols[4].text == cr);
340 1 : CPPUNIT_ASSERT(symbols[4].type == SbxVARIANT);
341 1 : CPPUNIT_ASSERT(symbols[5].text.getLength() == 1);
342 1 : CPPUNIT_ASSERT(symbols[5].text[0] == 'a');
343 1 : CPPUNIT_ASSERT(symbols[5].type == SbxVARIANT);
344 1 : CPPUNIT_ASSERT(symbols[6].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdf")));
345 1 : CPPUNIT_ASSERT(symbols[6].type == SbxVARIANT);
346 1 : CPPUNIT_ASSERT(symbols[7].text == cr);
347 1 : CPPUNIT_ASSERT(symbols[7].type == SbxVARIANT);
348 :
349 1 : symbols = getSymbols(source11);
350 1 : CPPUNIT_ASSERT(symbols.size() == 4);
351 1 : CPPUNIT_ASSERT(symbols[0].text == asdf);
352 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
353 1 : CPPUNIT_ASSERT(symbols[1].text == dot);
354 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
355 1 : CPPUNIT_ASSERT(symbols[2].text == asdf);
356 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
357 1 : CPPUNIT_ASSERT(symbols[3].text == cr);
358 1 : CPPUNIT_ASSERT(symbols[3].type == SbxVARIANT);
359 :
360 1 : symbols = getSymbols(source12);
361 1 : CPPUNIT_ASSERT(symbols.size() == 3);
362 1 : CPPUNIT_ASSERT(symbols[0].text == dot);
363 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
364 1 : CPPUNIT_ASSERT(symbols[1].text == dot);
365 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
366 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
367 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
368 1 : }
369 :
370 1 : void ScannerTest::testComments()
371 : {
372 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("REM asdf"));
373 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("REMasdf"));
374 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("'asdf"));
375 1 : const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("asdf _\n'100"));
376 1 : const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("'asdf _\n100"));
377 1 : const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("'asdf _\n'100"));
378 1 : const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("'asdf _\n 1234 _\n asdf'"));
379 :
380 1 : std::vector<Symbol> symbols;
381 :
382 1 : symbols = getSymbols(source1);
383 1 : CPPUNIT_ASSERT(symbols.size() == 1);
384 1 : CPPUNIT_ASSERT(symbols[0].text == rem);
385 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
386 :
387 1 : symbols = getSymbols(source2);
388 1 : CPPUNIT_ASSERT(symbols.size() == 2);
389 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REMasdf")));
390 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
391 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
392 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
393 :
394 1 : symbols = getSymbols(source3);
395 1 : CPPUNIT_ASSERT(symbols.size() == 1);
396 1 : CPPUNIT_ASSERT(symbols[0].text == rem);
397 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
398 :
399 1 : symbols = getSymbols(source4);
400 1 : CPPUNIT_ASSERT(symbols.size() == 2);
401 1 : CPPUNIT_ASSERT(symbols[0].text == asdf);
402 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
403 1 : CPPUNIT_ASSERT(symbols[1].text == rem);
404 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
405 :
406 1 : symbols = getSymbols(source5);
407 1 : CPPUNIT_ASSERT(symbols.size() == 3);
408 1 : CPPUNIT_ASSERT(symbols[0].text == rem);
409 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
410 1 : CPPUNIT_ASSERT(symbols[1].text.isEmpty());
411 1 : CPPUNIT_ASSERT(symbols[1].number == 100);
412 1 : CPPUNIT_ASSERT(symbols[1].type == SbxINTEGER);
413 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
414 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
415 :
416 1 : symbols = getSymbols(source6);
417 1 : CPPUNIT_ASSERT(symbols.size() == 2);
418 1 : CPPUNIT_ASSERT(symbols[0].text == rem);
419 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
420 1 : CPPUNIT_ASSERT(symbols[1].text == rem);
421 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
422 :
423 1 : symbols = getSymbols(source7);
424 1 : CPPUNIT_ASSERT(symbols.size() == 4);
425 1 : CPPUNIT_ASSERT(symbols[0].text == rem);
426 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
427 1 : CPPUNIT_ASSERT(symbols[1].text.isEmpty());
428 1 : CPPUNIT_ASSERT(symbols[1].number == 1234);
429 1 : CPPUNIT_ASSERT(symbols[1].type == SbxINTEGER);
430 1 : CPPUNIT_ASSERT(symbols[2].text == asdf);
431 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
432 1 : CPPUNIT_ASSERT(symbols[3].text == rem);
433 1 : CPPUNIT_ASSERT(symbols[3].type == SbxVARIANT);
434 1 : }
435 :
436 1 : void ScannerTest::testGoto()
437 : {
438 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("goto"));
439 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("go to"));
440 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("go\nto"));
441 :
442 1 : std::vector<Symbol> symbols;
443 :
444 1 : symbols = getSymbols(source1);
445 1 : CPPUNIT_ASSERT(symbols.size() == 2);
446 1 : CPPUNIT_ASSERT(symbols[0].text == goto_);
447 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
448 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
449 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
450 :
451 1 : symbols = getSymbols(source2);
452 1 : CPPUNIT_ASSERT(symbols.size() == 3);
453 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("go")));
454 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
455 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("to")));
456 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
457 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
458 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
459 :
460 1 : symbols = getSymbols(source3);
461 1 : CPPUNIT_ASSERT(symbols.size() == 4);
462 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("go")));
463 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
464 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
465 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
466 1 : CPPUNIT_ASSERT(symbols[2].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("to")));
467 1 : CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT);
468 1 : CPPUNIT_ASSERT(symbols[3].text == cr);
469 1 : CPPUNIT_ASSERT(symbols[3].type == SbxVARIANT);
470 1 : }
471 :
472 1 : void ScannerTest::testGotoCompatible()
473 : {
474 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("goto"));
475 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("go to"));
476 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("go\nto"));
477 :
478 1 : std::vector<Symbol> symbols;
479 :
480 1 : symbols = getSymbols(source1, true);
481 1 : CPPUNIT_ASSERT(symbols.size() == 2);
482 1 : CPPUNIT_ASSERT(symbols[0].text == goto_);
483 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
484 :
485 1 : symbols = getSymbols(source2, true);
486 1 : CPPUNIT_ASSERT(symbols.size() == 2);
487 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(goto_));
488 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
489 :
490 1 : symbols = getSymbols(source3, true);
491 1 : CPPUNIT_ASSERT(symbols.size() == 4);
492 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("go")));
493 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
494 1 : CPPUNIT_ASSERT(symbols[2].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("to")));
495 1 : CPPUNIT_ASSERT(symbols[3].text == cr);
496 1 : }
497 :
498 1 : void ScannerTest::testExclamation()
499 : {
500 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("asdf!asdf"));
501 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("!1234"));
502 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("!_3"));
503 1 : const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("!$"));
504 1 : const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("!%"));
505 1 : const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("!\n"));
506 :
507 1 : std::vector<Symbol> symbols;
508 :
509 1 : symbols = getSymbols(source1);
510 1 : CPPUNIT_ASSERT(symbols.size() == 4);
511 1 : CPPUNIT_ASSERT(symbols[0].text == asdf);
512 1 : CPPUNIT_ASSERT(symbols[1].text == excl);
513 1 : CPPUNIT_ASSERT(symbols[2].text == asdf);
514 1 : CPPUNIT_ASSERT(symbols[3].text == cr);
515 :
516 1 : symbols = getSymbols(source2);
517 1 : CPPUNIT_ASSERT(symbols.size() == 3);
518 1 : CPPUNIT_ASSERT(symbols[0].text == excl);
519 1 : CPPUNIT_ASSERT(symbols[1].text.isEmpty());
520 1 : CPPUNIT_ASSERT(symbols[1].number == 1234);
521 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
522 :
523 1 : symbols = getSymbols(source3);
524 1 : CPPUNIT_ASSERT(symbols.size() == 3);
525 1 : CPPUNIT_ASSERT(symbols[0].text == excl);
526 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_3")));
527 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
528 :
529 1 : symbols = getSymbols(source4);
530 1 : CPPUNIT_ASSERT(symbols.size() == 3);
531 1 : CPPUNIT_ASSERT(symbols[0].text == excl);
532 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("$")));
533 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
534 :
535 1 : symbols = getSymbols(source5);
536 1 : CPPUNIT_ASSERT(symbols.size() == 3);
537 1 : CPPUNIT_ASSERT(symbols[0].text == excl);
538 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")));
539 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
540 :
541 1 : symbols = getSymbols(source6);
542 1 : CPPUNIT_ASSERT(symbols.size() == 2);
543 1 : CPPUNIT_ASSERT(symbols[0].text == excl);
544 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
545 1 : }
546 :
547 1 : void ScannerTest::testNumbers()
548 : {
549 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("12345"));
550 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("1.2.3"));
551 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("123.4"));
552 1 : const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("0.5"));
553 1 : const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("5.0"));
554 1 : const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("0.0"));
555 1 : const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("-3"));
556 1 : const rtl::OUString source8(RTL_CONSTASCII_USTRINGPARAM("-0.0"));
557 1 : const rtl::OUString source9(RTL_CONSTASCII_USTRINGPARAM("12dE3"));
558 1 : const rtl::OUString source10(RTL_CONSTASCII_USTRINGPARAM("12e3"));
559 1 : const rtl::OUString source11(RTL_CONSTASCII_USTRINGPARAM("12D+3"));
560 1 : const rtl::OUString source12(RTL_CONSTASCII_USTRINGPARAM("12e++3"));
561 1 : const rtl::OUString source13(RTL_CONSTASCII_USTRINGPARAM("12e-3"));
562 1 : const rtl::OUString source14(RTL_CONSTASCII_USTRINGPARAM("12e-3+"));
563 1 : const rtl::OUString source15(RTL_CONSTASCII_USTRINGPARAM("1,2,3"));
564 1 : const rtl::OUString source16(RTL_CONSTASCII_USTRINGPARAM("1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
565 :
566 1 : std::vector<Symbol> symbols;
567 : sal_Int32 errors;
568 :
569 1 : symbols = getSymbols(source1, errors);
570 1 : CPPUNIT_ASSERT(symbols.size() == 2);
571 1 : CPPUNIT_ASSERT(symbols[0].number == 12345);
572 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
573 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
574 1 : CPPUNIT_ASSERT(errors == 0);
575 :
576 1 : symbols = getSymbols(source2, errors);
577 1 : CPPUNIT_ASSERT(symbols.size() == 2);
578 1 : CPPUNIT_ASSERT(symbols[0].number == 1.23);
579 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
580 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
581 1 : CPPUNIT_ASSERT(errors == 1);
582 :
583 1 : symbols = getSymbols(source3, errors);
584 1 : CPPUNIT_ASSERT(symbols.size() == 2);
585 1 : CPPUNIT_ASSERT(symbols[0].number == 123.4);
586 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
587 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
588 1 : CPPUNIT_ASSERT(errors == 0);
589 :
590 1 : symbols = getSymbols(source4, errors);
591 1 : CPPUNIT_ASSERT(symbols.size() == 2);
592 1 : CPPUNIT_ASSERT(symbols[0].number == .5);
593 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
594 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
595 1 : CPPUNIT_ASSERT(errors == 0);
596 :
597 1 : symbols = getSymbols(source5, errors);
598 1 : CPPUNIT_ASSERT(symbols.size() == 2);
599 1 : CPPUNIT_ASSERT(symbols[0].number == 5);
600 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
601 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
602 1 : CPPUNIT_ASSERT(errors == 0);
603 :
604 1 : symbols = getSymbols(source6, errors);
605 1 : CPPUNIT_ASSERT(symbols.size() == 2);
606 1 : CPPUNIT_ASSERT(symbols[0].number == 0);
607 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
608 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
609 1 : CPPUNIT_ASSERT(errors == 0);
610 :
611 1 : symbols = getSymbols(source7, errors);
612 1 : CPPUNIT_ASSERT(symbols.size() == 3);
613 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-")));
614 1 : CPPUNIT_ASSERT(symbols[1].number == 3);
615 1 : CPPUNIT_ASSERT(symbols[1].type == SbxINTEGER);
616 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
617 1 : CPPUNIT_ASSERT(errors == 0);
618 :
619 1 : symbols = getSymbols(source8, errors);
620 1 : CPPUNIT_ASSERT(symbols.size() == 3);
621 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-")));
622 1 : CPPUNIT_ASSERT(symbols[1].number == 0);
623 1 : CPPUNIT_ASSERT(symbols[1].type == SbxDOUBLE);
624 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
625 1 : CPPUNIT_ASSERT(errors == 0);
626 :
627 1 : symbols = getSymbols(source9, errors);
628 1 : CPPUNIT_ASSERT(symbols.size() == 2);
629 1 : CPPUNIT_ASSERT(symbols[0].number == 12000);
630 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
631 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
632 1 : CPPUNIT_ASSERT(errors == 1);
633 :
634 1 : symbols = getSymbols(source10, errors);
635 1 : CPPUNIT_ASSERT(symbols.size() == 2);
636 1 : CPPUNIT_ASSERT(symbols[0].number == 12000);
637 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
638 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
639 1 : CPPUNIT_ASSERT(errors == 0);
640 :
641 1 : symbols = getSymbols(source11, errors);
642 1 : CPPUNIT_ASSERT(symbols.size() == 2);
643 1 : CPPUNIT_ASSERT(symbols[0].number == 12000);
644 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
645 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
646 1 : CPPUNIT_ASSERT(errors == 0);
647 :
648 1 : symbols = getSymbols(source12, errors);
649 1 : CPPUNIT_ASSERT(symbols.size() == 4);
650 1 : CPPUNIT_ASSERT(symbols[0].number == 12);
651 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
652 1 : CPPUNIT_ASSERT(symbols[1].text == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("+")));
653 1 : CPPUNIT_ASSERT(symbols[2].number == 3);
654 1 : CPPUNIT_ASSERT(symbols[2].type == SbxINTEGER);
655 1 : CPPUNIT_ASSERT(symbols[3].text == cr);
656 1 : CPPUNIT_ASSERT(errors == 0);
657 :
658 1 : symbols = getSymbols(source13, errors);
659 1 : CPPUNIT_ASSERT(symbols.size() == 2);
660 1 : CPPUNIT_ASSERT(symbols[0].number == .012);
661 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
662 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
663 1 : CPPUNIT_ASSERT(errors == 0);
664 :
665 1 : symbols = getSymbols(source14, errors);
666 1 : CPPUNIT_ASSERT(symbols.size() == 3);
667 1 : CPPUNIT_ASSERT(symbols[0].number == .012);
668 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
669 1 : CPPUNIT_ASSERT(symbols[1].text == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("+")));
670 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
671 1 : CPPUNIT_ASSERT(errors == 0);
672 :
673 1 : symbols = getSymbols(source15, errors);
674 1 : CPPUNIT_ASSERT(symbols.size() == 6);
675 1 : CPPUNIT_ASSERT(symbols[0].number == 1);
676 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
677 1 : CPPUNIT_ASSERT(symbols[1].text == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(",")));
678 1 : CPPUNIT_ASSERT(symbols[2].number == 2);
679 1 : CPPUNIT_ASSERT(symbols[2].type == SbxINTEGER);
680 1 : CPPUNIT_ASSERT(symbols[3].text == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(",")));
681 1 : CPPUNIT_ASSERT(symbols[4].number == 3);
682 1 : CPPUNIT_ASSERT(symbols[4].type == SbxINTEGER);
683 1 : CPPUNIT_ASSERT(symbols[5].text == cr);
684 1 : CPPUNIT_ASSERT(errors == 0);
685 :
686 1 : symbols = getSymbols(source16, errors);
687 1 : CPPUNIT_ASSERT(symbols.size() == 2);
688 1 : CPPUNIT_ASSERT(symbols[0].number == 1);
689 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
690 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
691 : // This error is from a "buffer overflow" which is stupid because
692 : // the buffer is artificially constrained by the scanner.
693 1 : CPPUNIT_ASSERT(errors == 1); // HACK
694 1 : }
695 :
696 1 : void ScannerTest::testDataType()
697 : {
698 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("asdf%"));
699 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("asdf&"));
700 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("asdf!"));
701 1 : const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("asdf#"));
702 1 : const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("asdf@"));
703 1 : const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("asdf$"));
704 1 : const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("asdf "));
705 :
706 1 : std::vector<Symbol> symbols;
707 :
708 1 : symbols = getSymbols(source1);
709 1 : CPPUNIT_ASSERT(symbols.size() == 2);
710 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
711 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
712 :
713 1 : symbols = getSymbols(source2);
714 1 : CPPUNIT_ASSERT(symbols.size() == 2);
715 1 : CPPUNIT_ASSERT(symbols[0].type == SbxLONG);
716 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
717 :
718 1 : symbols = getSymbols(source3);
719 1 : CPPUNIT_ASSERT(symbols.size() == 2);
720 1 : CPPUNIT_ASSERT(symbols[0].type == SbxSINGLE);
721 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
722 :
723 1 : symbols = getSymbols(source4);
724 1 : CPPUNIT_ASSERT(symbols.size() == 2);
725 1 : CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE);
726 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
727 :
728 1 : symbols = getSymbols(source5);
729 1 : CPPUNIT_ASSERT(symbols.size() == 2);
730 1 : CPPUNIT_ASSERT(symbols[0].type == SbxCURRENCY);
731 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
732 :
733 1 : symbols = getSymbols(source6);
734 1 : CPPUNIT_ASSERT(symbols.size() == 2);
735 1 : CPPUNIT_ASSERT(symbols[0].type == SbxSTRING);
736 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
737 :
738 1 : symbols = getSymbols(source7);
739 1 : CPPUNIT_ASSERT(symbols.size() == 2);
740 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
741 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
742 1 : }
743 :
744 1 : void ScannerTest::testHexOctal()
745 : {
746 1 : const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("&HA"));
747 1 : const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("&HASDF"));
748 1 : const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("&H10"));
749 1 : const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("&&H&1H1&H1"));
750 1 : const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("&O&O12"));
751 1 : const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("&O10"));
752 1 : const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("&HO"));
753 1 : const rtl::OUString source8(RTL_CONSTASCII_USTRINGPARAM("&O123000000000000000000000"));
754 1 : const rtl::OUString source9(RTL_CONSTASCII_USTRINGPARAM("&H1.23"));
755 :
756 1 : std::vector<Symbol> symbols;
757 :
758 1 : symbols = getSymbols(source1);
759 1 : CPPUNIT_ASSERT(symbols.size() == 2);
760 1 : CPPUNIT_ASSERT(symbols[0].number == 10);
761 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
762 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
763 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
764 :
765 1 : symbols = getSymbols(source2);
766 1 : CPPUNIT_ASSERT(symbols.size() == 2);
767 1 : CPPUNIT_ASSERT(symbols[0].number == 2783);
768 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
769 1 : CPPUNIT_ASSERT(symbols[0].type = SbxINTEGER);
770 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
771 :
772 1 : symbols = getSymbols(source3);
773 1 : CPPUNIT_ASSERT(symbols.size() == 2);
774 1 : CPPUNIT_ASSERT(symbols[0].number == 16);
775 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
776 1 : CPPUNIT_ASSERT(symbols[0].type = SbxINTEGER);
777 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
778 :
779 1 : symbols = getSymbols(source4);
780 1 : CPPUNIT_ASSERT(symbols.size() == 6);
781 1 : CPPUNIT_ASSERT(symbols[0].number == 0);
782 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&")));
783 1 : CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
784 1 : CPPUNIT_ASSERT(symbols[1].number == 0);
785 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString());
786 1 : CPPUNIT_ASSERT(symbols[1].type == SbxINTEGER);
787 1 : CPPUNIT_ASSERT(symbols[2].number == 1);
788 1 : CPPUNIT_ASSERT(symbols[2].text == rtl::OUString());
789 1 : CPPUNIT_ASSERT(symbols[2].type == SbxINTEGER);
790 1 : CPPUNIT_ASSERT(symbols[3].number == 1);
791 1 : CPPUNIT_ASSERT(symbols[3].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("H1")));
792 1 : CPPUNIT_ASSERT(symbols[3].type == SbxLONG);
793 1 : CPPUNIT_ASSERT(symbols[4].number == 1);
794 1 : CPPUNIT_ASSERT(symbols[4].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("H1")));
795 1 : CPPUNIT_ASSERT(symbols[4].type == SbxVARIANT);
796 1 : CPPUNIT_ASSERT(symbols[5].text == cr);
797 :
798 1 : symbols = getSymbols(source5);
799 1 : CPPUNIT_ASSERT(symbols.size() == 3);
800 1 : CPPUNIT_ASSERT(symbols[0].number == 0);
801 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
802 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
803 1 : CPPUNIT_ASSERT(symbols[1].number == 0);
804 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("O12")));
805 1 : CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
806 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
807 :
808 1 : symbols = getSymbols(source6);
809 1 : CPPUNIT_ASSERT(symbols.size() == 2);
810 1 : CPPUNIT_ASSERT(symbols[0].number == 8);
811 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
812 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
813 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
814 :
815 1 : symbols = getSymbols(source7);
816 1 : CPPUNIT_ASSERT(symbols.size() == 2);
817 1 : CPPUNIT_ASSERT(symbols[0].number == 0);
818 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
819 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
820 :
821 1 : symbols = getSymbols(source8);
822 1 : CPPUNIT_ASSERT(symbols.size() == 2);
823 : // TODO: this line fails on 64 bit systems!!!
824 : // CPPUNIT_ASSERT(symbols[0].number == -1744830464);
825 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
826 1 : CPPUNIT_ASSERT(symbols[1].text == cr);
827 :
828 1 : symbols = getSymbols(source9);
829 1 : CPPUNIT_ASSERT(symbols.size() == 3);
830 1 : CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
831 1 : CPPUNIT_ASSERT(symbols[0].number == 1);
832 1 : CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
833 1 : CPPUNIT_ASSERT(symbols[1].number == .23);
834 1 : CPPUNIT_ASSERT(symbols[1].text == rtl::OUString());
835 1 : CPPUNIT_ASSERT(symbols[1].type == SbxDOUBLE);
836 1 : CPPUNIT_ASSERT(symbols[2].text == cr);
837 1 : }
838 :
839 : // Put the test suite in the registry
840 1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScannerTest);
841 : } // namespace
842 4 : CPPUNIT_PLUGIN_IMPLEMENT();
843 :
844 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|