summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/macros/tests/xmlhandlertests.cpp
blob: 9a0ebcb1d3bf911bb69f897c8edbe5eda7c64ff9 (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/***************************************************************************
 * This file is part of the KDE project
 * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 * You should have received a copy of the GNU Library General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 ***************************************************************************/

#include "xmlhandlertests.h"
#include "testaction.h"
#include "komacrotestbase.h"

#include "../lib/action.h"
#include "../lib/manager.h"
#include "../lib/macro.h"
#include "../lib/variable.h"
#include "../lib/macroitem.h"

#include <ostream>
#include <cfloat>

#include <qdom.h>

#include <kdebug.h>
#include <kunittest/runner.h>
#include <kxmlguiclient.h>

using namespace KUnitTest;
using namespace KoMacroTest;

namespace KoMacroTest {

	/**
	* Register KoMacroTest::CommonTests as TestSuite.
	*/
	KUNITTEST_SUITE("KoMacroTestSuite")
	KUNITTEST_REGISTER_TESTER(XMLHandlerTests);

	class XMLHandlerTests::Private
	{
		public:		
		/**
		* An KXMLGUIClient instance created on @a setUp() and
		* passed to the @a KoMacro::Manager to bridge to the
		* app-functionality.
		*/
		KXMLGUIClient* xmlguiclient;

		/**
		* An @a TestObject instance used internaly to test
		* handling and communication with from QObject
		* inheritated instances.
		*/
		KSharedPtr<KoMacro::Action> testaction;

		Private()
			: xmlguiclient(0)
			, testaction(0)
		{
		}
	};
}

XMLHandlerTests::XMLHandlerTests()
	: KUnitTest::SlotTester()
	, d( new Private() ) // create the private d-pointer instance.
{
}

XMLHandlerTests::~XMLHandlerTests()
{
	delete d->xmlguiclient;
	delete d;
}


void XMLHandlerTests::setUp()
{
	d->xmlguiclient = new KXMLGUIClient();
	
	//Singelton more or less ...
	if (::KoMacro::Manager::self() == 0) {	
		::KoMacro::Manager::init( d->xmlguiclient );
	}
	
	d->testaction = new TestAction();
	::KoMacro::Manager::self()->publishAction(d->testaction);	
}

void XMLHandlerTests::tearDown()
{
	delete d->xmlguiclient;
}

/**
* Test the @a KoMacro::XMLHandler parseXML() and toXML()-function.
*/
void XMLHandlerTests::testParseAndToXML()
{
	kdDebug()<<"===================== testParseAndToXML() ======================" << endl;

	// 1.Test - Correct DomElement.
	testCorrectDomElement();
	// 2.Test - XML-document with bad root element.
	testBadRoot();
	// 3.Test - XML-document with a missing Variable.
	testMissingVariable();
	// 4.Test - One more Variable in XML-Document.
	testMoreVariables();
	// 5.Test - XML-document with wrong macro-xmlversion.
	testWrongVersion();
	// 6.Test - XML-document if it has a wrong structure like wrong parathesis
	// 	or missing end tag.
	testWrongXMLStruct();
	// 7.Test-XML-document with maximum field-size.
	testMaxNum();
	// 8.Test-XML-document with maximum+1 field-size.
	testMaxNum2();
	// 9.Test-XML-document with minimum field-size.
	testMinNum();
	// 10.Test-XML-document with minimum-1 field-size.
	testMinNum2();
	// 11.Test - With a to big number.
	testBigNumber();
	// 12.Test - With two MacroItems.
	testTwoMacroItems();
}

/***************************************************************************
* Begin of Sub-methos of testParseXML().
***************************************************************************/
// 1.Test - Correct DomElement.
void XMLHandlerTests::testCorrectDomElement()
{
	// Local Init
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	// Part 1: From XML to a Macro.
	// Test-XML-document with normal allocated variables.
	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" >0</variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" >0.6</variable>"
				      "</item>"
				    "</macro>");
	// Set the XML-document with the above string.
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	// Is our XML parseable by calling parseXML()?
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);
	
	// Is the parsen content in the Macro correct ?
	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testbool"] = true;
	isvariableok["testdouble"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	// Transform back by calling toXML().
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);

	// Test the Compare-method when a Variable will change, it must fail.
	macro->items().first()->variable("teststring")->setVariant("bla");
	isvariableok.replace("teststring",false);
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
}

// 2.Test - XML-document with bad root element.
void XMLHandlerTests::testBadRoot()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<maro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" >0</variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" >0.6</variable>"
				      "</item>"
				    "</maro>");
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_XASSERT(macro->parseXML(elem),true);

	//no assertMacroContentEqToXML(), because parsing failed.
	assertMacroContentEqToXML(macro,elem,true,false,QMap<QString,bool>());

	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,true,false,QMap<QString,bool>());
}

// 3.Test - XML-document with a missing Variable.
void XMLHandlerTests::testMissingVariable()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" >0</variable>"
						"<variable name=\"testdouble\" >0.6</variable>"
				      "</item>"
				    "</macro>");
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();	
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);

	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testdouble"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
}

// 4.Test - One more Variable in XML-Document.
void XMLHandlerTests::testMoreVariables()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" >0</variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" >0.6</variable>"
						"<variable name=\"testbla\" >somethingwrong</variable>"
				      "</item>"
				    "</macro>");
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);

	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testbool"] = true;
	isvariableok["testdouble"] = true;
	isvariableok["testbla"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
}

// 5.Test - XML-document with wrong macro-xmlversion.
void XMLHandlerTests::testWrongVersion()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"2\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" >0</variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" >0.6</variable>"
				      "</item>"
				    "</macro>");
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_XASSERT(macro->parseXML(elem),true);

	//no assertMacroContentEqToXML(), because parsing failed.
	assertMacroContentEqToXML(macro,elem,true,false,QMap<QString,bool>());
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,true,false,QMap<QString,bool>());
}

// 6.Test - XML-document if it has a wrong structure like wrong parathesis
// 	or missing end tag.
void XMLHandlerTests::testWrongXMLStruct()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "macro xmlversion=\"1\">>"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" >0</variable>"
				      "</item>"
				    "</macro>");
	KOMACROTEST_XASSERT(doomdocument.setContent(xml),true);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_XASSERT(macro->parseXML(elem),true);

	//no assertMacroContentEqToXML(), because parsing failed.
	assertMacroContentEqToXML(macro,elem,true,false,QMap<QString,bool>());
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,true,false,QMap<QString,bool>());
}

// 7.Test-XML-document with maximum field-size.
void XMLHandlerTests::testMaxNum()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" > %1 </variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" > %2 </variable>"
				      "</item>"
				    "</macro>").arg(INT_MAX).arg(DBL_MAX);
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);

	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testbool"] = true;
	isvariableok["testdouble"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
}

// 8.Test-XML-document with maximum+1 field-size.
void XMLHandlerTests::testMaxNum2()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" > %1 </variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" > %2 </variable>"
				      "</item>"
				    "</macro>").arg(INT_MAX+1).arg(DBL_MAX+1);
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);

	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testbool"] = true;
	isvariableok["testdouble"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
}

// 9.Test-XML-document with minimum field-size.
void XMLHandlerTests::testMinNum()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" > %1 </variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" > %2 </variable>"
				      "</item>"
				    "</macro>").arg(INT_MIN).arg(DBL_MIN);
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);

	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testbool"] = true;
	isvariableok["testdouble"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
}

// 10.Test-XML-document with minimum+1 field-size.
void XMLHandlerTests::testMinNum2()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" > %1 </variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" > %2 </variable>"
				      "</item>"
				    "</macro>").arg(INT_MIN-1).arg(DBL_MIN-1);
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);

	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testbool"] = true;
	isvariableok["testdouble"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
}

// 11.Test - With a to big number.
void XMLHandlerTests::testBigNumber()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" > 0123456789012345678901234567890123456789 </variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" > %1 </variable>"
				      "</item>"
				    "</macro>").arg(DBL_MAX+1);
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);

	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testbool"] = true;
	isvariableok["testdouble"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
}

// 12.Test - With two MacroItems.
void XMLHandlerTests::testTwoMacroItems()
{
	KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
	QDomDocument doomdocument;

	const QString xml = QString("<!DOCTYPE macros>"
				    "<macro xmlversion=\"1\">"
				      "<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >test_string</variable>"
						"<variable name=\"testint\" >0</variable>"
						"<variable name=\"testbool\" >true</variable>"
						"<variable name=\"testdouble\" >0.6</variable>"
						"<variable name=\"testbla\" >somethingwrong</variable>"
				      "</item>"
					"<item action=\"testaction\" >"
    					"<variable name=\"teststring\" >testBBstring2</variable>"
						"<variable name=\"testint\" >4</variable>"
						"<variable name=\"testbool\" >false</variable>"
						"<variable name=\"testdouble\" >0.7</variable>"
						"<variable name=\"testbla\" >somethingwrong2</variable>"
				      "</item>"
				    "</macro>");
	doomdocument.setContent(xml);
	const QDomElement elem = doomdocument.documentElement();
	KOMACROTEST_ASSERT(macro->parseXML(elem),true);

	QMap<QString,bool> isvariableok;
	isvariableok["teststring"] = true;
	isvariableok["testint"] = true;
	isvariableok["testbool"] = true;
	isvariableok["testdouble"] = true;
	assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
	
	const QDomElement elem2 = macro->toXML();
	assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
}
/***************************************************************************
* End of Sub-methos of testParseAndToXML().
***************************************************************************/

/** 
* Compares a XML-Element with a Macro. Call sub-asserts.
* @p macro The parsen @a Macro.
* @p elem The given @a QDomElement which is parsen.
* @p isitemsempty Bool for expectation of an empty @a MacroItem -List.
* @p isactionset Bool for expectation that the @a Action -names are equal.
* @p isvariableok QMap of Bools for comparing each @a Variable .
*/
void XMLHandlerTests::assertMacroContentEqToXML(const KSharedPtr<KoMacro::Macro> macro,
	const QDomElement& elem,
	const bool isitemsempty,
	const bool isactionset,
	const QMap<QString, bool> isvariableok)
{
	// Make an Iterator over the MacroItems of the Macro.
	const QValueList<KSharedPtr<KoMacro::MacroItem > > macroitems = macro->items();
	QValueList<KSharedPtr<KoMacro::MacroItem > >::ConstIterator 
		mit(macroitems.constBegin()), end(macroitems.constEnd());

	//1.comparison - Is the MacroItem-list empty?
	{
		if( isitemsempty ) {
			KOMACROTEST_XASSERT(macroitems.empty(),false);
			kdDebug() << "There is no correct MacroItem parsen." << endl;
			return;
		}
		else {
			KOMACROTEST_ASSERT(macroitems.empty(),false);
		}
	}

	// Got to the first item-elements of the elem (there is only one in the tests).
	QDomNode itemnode = elem.firstChild();

	// Iterate over the MacroItems and item-elements.
	while(mit != end && ! itemnode.isNull()) {
		const KSharedPtr<KoMacro::MacroItem> macroitem = *mit;
		const QDomElement itemelem = itemnode.toElement();
		
		//2.comparison - Is the Action-name equal?
		{
			if( ! isactionset) {
				KOMACROTEST_XASSERT(macroitem->action()->name() == itemelem.attribute("action"),true);
				kdDebug() 	<< "Action-name not equal: " 
							<< macroitem->action()->name()
							<< " != " << itemelem.attribute("action") << endl;
				return;
			}
			else {
				KOMACROTEST_ASSERT(macroitem->action()->name() == itemelem.attribute("action"),true);
			}
		}

		// Go down to MacroItem->Variable and item->variable and compare them.
		QMap<QString, KSharedPtr<KoMacro::Variable > > mvariables = macroitem->variables();
		QDomNode varnode = itemelem.firstChild();

		while ( ! varnode.isNull()) {
			const QDomElement varelem = varnode.toElement();
			const KSharedPtr<KoMacro::Variable> varitem = mvariables.find(varelem.attribute("name")).data();
			
			//3.comparison - Is the content of the Variable
			// in the MacroItem and and item equal?
			{
				const bool var = *isvariableok.find(varelem.attribute("name"));
				if( ! var ) {
					KOMACROTEST_XASSERT(varitem->variant() == QVariant(varelem.text()), !var);
					kdDebug() 	<< "The content of the Variable: " << varitem->name() 
								<< " is not equal." << varitem->variant()
								<< "!=" << varelem.text() << endl;
				}
				else {
					KOMACROTEST_ASSERT(varitem->variant() == QVariant(varelem.text()), var);
				}

			}

			// Erase the MacroItem from the map, because it is parsen correctly.
			mvariables.erase(varitem->name());
			// Go to next Variable in node-tree.
			varnode = varnode.nextSibling();
		}

		//4.comparison - Is every MacroItem parsen?
		{
			KOMACROTEST_ASSERT(mvariables.empty(),true);
			kdDebug() << "There are non-filled variable in the MacroItem: " << mvariables.count() <<endl;
		}

		// Go to next MacroItem and next item-element.
		mit++;
		itemnode = itemnode.nextSibling();
	}
}

// Prints a QMap of Variables to kdDebug().
void XMLHandlerTests::printMvariables(const QMap<QString, KSharedPtr<KoMacro::Variable > > mvariables, const QString s)
{
	//QValueList<QString>::ConstIterator kit (keys.constBegin()), end(keys.constEnd());
	QMap<QString, KSharedPtr<KoMacro::Variable > >::ConstIterator mvit (mvariables.constBegin()), end(mvariables.constEnd());
	while(mvit != end){
		const KoMacro::Variable * v = *mvit;
		kdDebug() << s << ": " << v->name() << endl;
		mvit++;
	}
}

#include "xmlhandlertests.moc"