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
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
|
/***************************************************************************
* This file is part of the KDE project
* copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
* copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
*
* 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 "commontests.h"
#include "testobject.h"
#include "testaction.h"
#include "komacrotestbase.h"
#include "../lib/action.h"
#include "../lib/function.h"
#include "../lib/manager.h"
#include "../lib/macro.h"
#include "../lib/variable.h"
#include "../lib/metaobject.h"
#include "../lib/metamethod.h"
#include "../lib/metaparameter.h"
#include "../lib/exception.h"
#include "../lib/macroitem.h"
#include <ostream>
#include <climits>
#include <tqstringlist.h>
#include <tqdom.h>
#include <kdebug.h>
#include <tdeunittest/runner.h>
#include <kxmlguiclient.h>
using namespace KUnitTest;
using namespace KoMacroTest;
namespace KoMacroTest {
/**
* Register KoMacroTest::CommonTests as TestSuite.
*/
TDEUNITTEST_SUITE("CommonTestsSuite")
TDEUNITTEST_REGISTER_TESTER(CommonTests);
/**
* @internal d-pointer class to be more flexible on future extension of the
* functionality without to much risk to break the binary compatibility.
*/
class CommonTests::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 TQObject
* inheritated instances.
*/
TestObject* testobject;
TestAction* testaction;
TQDomDocument* doomdocument;
/**
* Constructor.
*/
Private()
: xmlguiclient(0)
, testobject(0)
, testaction(0)
, doomdocument(0)
{
}
};
}
typedef TQValueList< TDESharedPtr<KoMacro::MacroItem> >::size_type sizetype;
CommonTests::CommonTests()
: KUnitTest::SlotTester()
, d( new Private() ) // create the private d-pointer instance.
{
}
CommonTests::~CommonTests()
{
delete d->xmlguiclient;
delete d;
}
void CommonTests::setUp()
{
d->xmlguiclient = new KXMLGUIClient();
::KoMacro::Manager::init( d->xmlguiclient );
d->testobject = new TestObject( this );
::KoMacro::Manager::self()->publishObject("TestObject", d->testobject);
d->testaction = new TestAction();
::KoMacro::Manager::self()->publishAction(d->testaction);
d->doomdocument = new TQDomDocument();
TQString const xml = TQString("<!DOCTYPE macros>"
"<macro xmlversion=\"1\">"
"<item action=\"testaction\" >"
"</item>"
"</macro>");
d->doomdocument->setContent(xml);
}
void CommonTests::tearDown()
{
delete d->doomdocument;
delete d->testobject;
delete d->xmlguiclient;
}
void CommonTests::testManager()
{
kdDebug()<<"===================== testManager() ======================" << endl;
//check if manager-guiClient equals xmlguiclient
KOMACROTEST_ASSERT( ::KoMacro::Manager::self()->guiClient(), d->xmlguiclient );
//check if manger-object equals testobject
KOMACROTEST_ASSERT( dynamic_cast<TestObject*>( (TQObject*)::KoMacro::Manager::self()->object("TestObject") ), d->testobject );
}
/*
void CommonTests::testAction()
{
const TQString testString = "teststring";
const TQString testInt = "testint";
const TQString testBool = "testbool";
//TODO: CLEANUP!!!!!!
//TODO: test manipulation of action and macroitem and context.
kdDebug()<<"===================== testAction() ======================" << endl;
//Publish TestAction for the first time.
TQDomElement const domelement = d->doomdocument->documentElement();
TDESharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
//Is our XML parseable ?
KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
//??
macro->execute(this);
//create list of TDESharedPtr from the childs of the macro
TQValueList< TDESharedPtr<KoMacro::MacroItem> >& items = macro->items();
//check that there is one
KOMACROTEST_ASSERT( items.count(), sizetype(1) );
//fetch the first one
TDESharedPtr<KoMacro::Action> actionptr = items[0]->action();
//How do we know that an action exist ?
//-> check that it is not null
KOMACROTEST_XASSERT(sizetype(actionptr.data()), sizetype(0));
//fetch the "teststring"-variable
TDESharedPtr<KoMacro::Variable> variableptr = actionptr->variable("teststring");
//check that it is not null
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
//check that it is " "
KOMACROTEST_ASSERT(variableptr->variant().toString(),TQString("testString"));
//fetch the "testint"-variable
variableptr = actionptr->variable("testint");
//check that it is not null
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
//check that it is " "
KOMACROTEST_ASSERT(variableptr->variant().toInt(),int(0));
//fetch the "testbool"-variable
variableptr = actionptr->variable("testbool");
//check that it is not null
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
//check that it is " "
KOMACROTEST_ASSERT(variableptr->variant().toBool(),true);
actionptr->setVariable("teststring", "STRINGTEST", "TestString");
variableptr = actionptr->variable("teststring");
//check that it is not null
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
//check that it is " "
KOMACROTEST_ASSERT(variableptr->variant().toString(),TQString("TestString"));
actionptr->setVariable("testint","INTTEST",INT_MAX);
variableptr = actionptr->variable("testint");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MAX));
actionptr->setVariable("testbool","BOOLTEST", "false");
variableptr = actionptr->variable("testbool");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(variableptr->variant().toBool(),false);
//create new macroitem for testing
KoMacro::MacroItem* macroitem = new KoMacro::MacroItem();
//set the action
macroitem->setAction(d->testaction);
//append the macroitem to testitems
items.append(macroitem);
//increased ??
KOMACROTEST_ASSERT( items.count(), sizetype(2) );
//Manipulate the macroitem
macroitem->setVariable("teststring", "TeStString");
variableptr = macroitem->variable("teststring");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(variableptr->variant().toString(),TQString("TeStString"));
macroitem->setVariable("testint",INT_MIN);
variableptr = macroitem->variable("testint");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MIN));
macroitem->setVariable("testint",-1);
variableptr = macroitem->variable("testint");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(-1));
//commontests.cpp: In member function 'void KoMacroTest::CommonTests::testAction()':
//commontests.cpp:249: error: call of overloaded 'setVariable(const char [8], int)' is ambiguous
//../lib/macroitem.h:131: note: candidates are: TQStringList KoMacro::MacroItem::setVariable(const TQString&, TDESharedPtr<KoMacro::Variable>)
//../lib/macroitem.h:137: note: TQStringList KoMacro::MacroItem::setVariable(const TQString&, const TQVariant&)
macroitem->setVariable("testint",(int) 0);
variableptr = macroitem->variable("testint");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(0));
macroitem->setVariable("testint",1);
variableptr = macroitem->variable("testint");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(1));
macroitem->setVariable("testint",INT_MAX);
variableptr = macroitem->variable("testint");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MAX));
macroitem->setVariable("testbool","false");
variableptr = macroitem->variable("testbool");
KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
KOMACROTEST_ASSERT(variableptr->variant().toBool(),false);
//secondway for appending an macroitem
//add the manipulated macroitem
macro->addItem(macroitem);
//increased ??
KOMACROTEST_ASSERT( items.count(), sizetype(3));
} */
void CommonTests::testXmlhandler()
{
kdDebug()<<"===================== testXmlhandler() ======================" << endl;
// Local Init
TDESharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
TQDomElement domelement;
// Save old doomdocument
TQString xmlOld = d->doomdocument->toString();
// Part 1: From XML to a Macro.
// Test-XML-document with normal allocated variables.
TQString xml = TQString("<!DOCTYPE macros>"
"<macro xmlversion=\"1\">"
"<item action=\"testaction\" >"
"<variable name=\"teststring\" >testString</variable>"
"<variable name=\"testint\" >0</variable>"
"<variable name=\"testbool\" >true</variable>"
"<variable name=\"testbla\" >somethingwrong</variable>" // TODO Is here a kdDebug-msg enough?
"<variable name=\"testdouble\" >0.6</variable>"
"</item>"
"</macro>");
// Set the XML-document with the above string.
d->doomdocument->setContent(xml);
domelement = d->doomdocument->documentElement();
//Is our XML parseable ?
KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
// Test-XML-document with bad root element.
xml = TQString("<!DOCTYPE macros>"
"<maro xmlversion=\"1\">"
"<item action=\"testaction\" >"
"<variable name=\"teststring\" >testString</variable>"
"<variable name=\"testint\" >0</variable>"
"<variable name=\"testbool\" >true</variable>"
"<variable name=\"testdouble\" >0.6</variable>"
"</item>"
"</maro>");
d->doomdocument->setContent(xml);
domelement = d->doomdocument->documentElement();
KOMACROTEST_ASSERT(macro->parseXML(domelement),false);
// Test-XML-document with wrong macro-xmlversion.
xml = TQString("<!DOCTYPE macros>"
"<macro xmlversion=\"2\">"
"<item action=\"testaction\" >"
"<variable name=\"teststring\" >testString</variable>"
"<variable name=\"testint\" >0</variable>"
"<variable name=\"testbool\" >true</variable>"
"<variable name=\"testdouble\" >0.6</variable>"
"</item>"
"</macro>");
d->doomdocument->setContent(xml);
domelement = d->doomdocument->documentElement();
KOMACROTEST_ASSERT(macro->parseXML(domelement),false);
// TODO Test-XML-document if it has a wrong structure like wrong parathesis
// or missing end tag (is this critical??).
/*xml = TQString("<!DOCTYPE macros>"
"<macro xmlversion=\"1\">"
"<item action=\"testaction\" >"
"<variable name=\"teststring\" >testString</variable>"
"<variable name=\"testint\" >0</variable>"
"<variable name=\"testbool\" >true</variable>"
"</item>"
"</macro>");
d->doomdocument->setContent(xml);
domelement = d->doomdocument->documentElement();
KOMACROTEST_ASSERT(macro->parseXML(domelement),false);*/
// Test-XML-document with wrong item- and variable-tags.
// TODO Could this happen??
xml = TQString("<!DOCTYPE macros>"
"<macro xmlversion=\"1\">"
"<iem action=\"testaction\" >"
"<vle name=\"teststring\" >testString</variable>"
"<v name=\"testint\" >0</variable>"
"<variable name=\"testbool\" >true</variable>"
"<variable name=\"testdouble\" >0.6</variable>"
"</item>"
"</macro>");
d->doomdocument->setContent(xml);
domelement = d->doomdocument->documentElement();
KOMACROTEST_ASSERT(macro->parseXML(domelement),true); //should be false?
// TODO Test-XML-document with maximum field-size.
xml = TQString("<!DOCTYPE macros>"
"<macro xmlversion=\"1\">"
"<item action=\"testaction\" >"
"<variable name=\"teststring\" >testString</variable>"
"<variable name=\"testint\" > 0 </variable>" // the value should be INT_MAX
"<variable name=\"testbool\" >true</variable>"
"<variable name=\"testdouble\" >0.6</variable>" // DBL_MAX
"</item>"
"</macro>");
d->doomdocument->setContent(xml);
domelement = d->doomdocument->documentElement();
KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
// TODO Test-XML-document with minimum field-size.
xml = TQString("<!DOCTYPE macros>"
"<macro xmlversion=\"1\">"
"<item action=\"testaction\" >"
"<variable name=\"teststring\" >testString</variable>"
"<variable name=\"testint\" >0</variable>" // INT_MIN
"<variable name=\"testbool\" >true</variable>"
"<variable name=\"testdouble\" >0.6</variable>" // DBL_MIN
"</item>"
"</macro>");
d->doomdocument->setContent(xml);
domelement = d->doomdocument->documentElement();
KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
// TODO Part 2: Read the parsen macro and make a comparison to the XML-document.
// TODO Part 3: From a Macro to XML.
// RODO Part 4: Compare the transformed XML with the given macro.
// Set back xml-string for other tests.
d->doomdocument->setContent(xmlOld);
}
void CommonTests::testFunction()
{
//TODO: CLEANUP!!!!!!
/*
kdDebug()<<"===================== testFunction() ======================" << endl;
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//create some data
TQString const comment = "Describe what the function does";
TQString const name = "myfunc";
TQString const text = "My Function";
TQString const receiver = "TestObject";
TQString const argument1 = "Some string";
int const argument2 = 12345;
//set "Function"-content in TQDocument
domdocument.setContent(TQString(
"<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver + "\" slot=\"myslot(const TQString & , int)\">"
"<argument>" + argument1 + "</argument>"
"<argument>" + TQString("%1").arg(argument2) + "</argument>"
"</function>"
));
//create an KomacroFunction with our data, and put it into a TDESharedPtr
TDESharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//cast TDESharedPtr to KoMacro-"Function"
KoMacro::Function* func = dynamic_cast<KoMacro::Function*>( functionptr.data() );
//check that function is not null
KOMACROTEST_XASSERT((int) func, 0);
//check domElement
KOMACROTEST_ASSERT( func->domElement(), domdocument.documentElement() );
//check name
KOMACROTEST_ASSERT( TQString(func->name()), name );
//check text
KOMACROTEST_ASSERT( func->text(), text );
//check comment
KOMACROTEST_ASSERT( func->comment(), comment );
//check receiver
KOMACROTEST_ASSERT( func->receiver(), receiver );
//check slot (arguments)
KOMACROTEST_ASSERT( TQString(func->slot()), TQString("myslot(const TQString&,int)") );
//create KoMacro-MetaObject from receiverObject
TDESharedPtr<KoMacro::MetaObject> receivermetaobject = func->receiverObject();
//check that receivermetaobject.data is not null
KOMACROTEST_XASSERT((int) receivermetaobject.data(), 0);
//create KoMacro-MetaMethod from receiverObject
TDESharedPtr<KoMacro::MetaMethod> receivermetamethod = receivermetaobject->slot( func->slot().latin1() );
//check that receivermetamethod.data is not null
KOMACROTEST_XASSERT((int) receivermetamethod.data(), 0);
//create list of variables from func
KoMacro::Variable::List funcvariables = func->variables();
//counter for hardcoded tests see below ...
uint i = 0;
KoMacro::Variable::List::ConstIterator it, end( funcvariables.constEnd() );
for( it = funcvariables.constBegin(); it != end; ++it) {
kdDebug() << "VARIABLE => " << (*it ? (*it)->toString() : "<NULL>") << endl;
//hardcoded test:
// firstrun we have a TQString, secondrun we have an int
switch(i) {
case 0: { // returnvalue
KOMACROTEST_ASSERT(*it, TDESharedPtr<KoMacro::Variable>(NULL));
} break;
case 1: { // first parameter
//check first variable of func is the same as argument1
//TQString const argument1 = "Some string";
KOMACROTEST_ASSERT((*it)->toString(), argument1);
} break;
case 2: { // second parameter
//check second variable of func is the same as argument2
//int const argument2 = 12345;
KOMACROTEST_ASSERT((*it)->toInt(), argument2);
} break;
default: {
} break;
}
i++;
}
//check that we have two arguments + one returnvalue in func
KOMACROTEST_ASSERT( funcvariables.count(), uint(3) );
// check that the first argument (the returnvalue) is empty
KOMACROTEST_ASSERT( funcvariables[0], TDESharedPtr<KoMacro::Variable>(NULL) );
//create a KoMacro-Variable-Ptr from first func argument
TDESharedPtr<KoMacro::Variable> stringvar = funcvariables[1];
//check that it is not null
KOMACROTEST_XASSERT((int) stringvar.data(),0);
//check via TQVariant type that stringvar is from Type Variant
KOMACROTEST_ASSERT( stringvar->type(), KoMacro::MetaParameter::TypeVariant );
//check via metaparameter that variant is from type string
KOMACROTEST_ASSERT( stringvar->variantType(), TQVariant::String );
//chech that stringvar equals argument1
KOMACROTEST_ASSERT( stringvar->toString(), argument1 );
//create a KoMacro-Variable-Ptr from second func argument
TDESharedPtr<KoMacro::Variable> intvar = funcvariables[2];
//check that it is not null
KOMACROTEST_XASSERT((int) intvar.data(), 0);
//check via TQVariant type that stringvar is from Type Variant
KOMACROTEST_ASSERT( intvar->type(), KoMacro::MetaParameter::TypeVariant );
//check that intvar is An String -> we create an string from int because of xml
KOMACROTEST_ASSERT( intvar->variantType(), TQVariant::String );
//check that intvar equals argument2
KOMACROTEST_ASSERT( intvar->toInt(), argument2 );
//returnvalue see testobject ....
TDESharedPtr<KoMacro::Variable> funcreturnvalue = receivermetamethod->invoke( funcvariables );
kdDebug() << "CommonTests::testFunction() RETURNVALUE =====> " << funcreturnvalue->toString() << endl;
KOMACROTEST_ASSERT( funcreturnvalue->toInt(), argument2 );
//check returnvalue
//func->setReturnValue(new KoMacro::Variable("54321"));
//KOMACROTEST_ASSERT( func->returnValue()->toString(), TQString("54321") );
*/
}
void CommonTests::testIntFunction()
{
//TODO: CLEANUP!!!!!!
/*
kdDebug()<<"===================== testIntFunction() ======================" << endl;
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//set "Function"-content in TQDocument
domdocument.setContent(TQString(
"<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const TQString & , int)\">"
"<argument>Some string</argument>"
"<argument>12345</argument>"
"</function>"
));
//create an KomacroFunction with our data, and put it into a TDESharedPtr
TDESharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//Cast data to function
KoMacro::Function* func = dynamic_cast<KoMacro::Function*>( functionptr.data() );
//check that it is not null
KOMACROTEST_XASSERT((int) func, 0);
//execute the function
func->activate();
//Check returnvalue is same value we entered
//KOMACROTEST_ASSERT(func->returnValue()->toString(),TQString("12345"));
*/
}
void CommonTests::testDoubleFunction()
{
//TODO: CLEANUP!!!!!!
/*
kdDebug()<<"===================== testDoubleFunction() ======================" << endl;
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//set "Function"-content in TQDocument
domdocument.setContent(TQString(
"<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const TQString & , double)\">"
"<argument>Some string</argument>"
"<argument>12.56</argument>"
"</function>"
));
//create an KomacroFunction with our data, and put it into a TDESharedPtr
TDESharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//Cast data to function
KoMacro::Function* func = dynamic_cast<KoMacro::Function*>( functionptr.data() );
//check that it is not null
KOMACROTEST_XASSERT((int) func, 0);
//execute the function
func->activate();
//Check returnvalue is same value we entered
//KOMACROTEST_ASSERT(func->returnValue()->toString(),TQString("12.56"));
*/
}
void CommonTests::testTQStringFunction()
{
//TODO: CLEANUP!!!!!!
/*
kdDebug()<<"===================== testTQStringFunction() ======================" << endl;
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//set "Function"-content in TQDocument
domdocument.setContent(TQString(
"<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const TQString &)\">"
"<argument>Some string</argument>"
"</function>"
));
//create an KomacroFunction with our data, and put it into a TDESharedPtr
TDESharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//Cast data to function
KoMacro::Function* func = dynamic_cast<KoMacro::Function*>( functionptr.data() );
//check that it is not null
KOMACROTEST_XASSERT((int) func, 0);
//execute the function func->activate();
//Check returnvalue is same value we entered
//KOMACROTEST_ASSERT(func->returnValue()->toString(),TQString("Some string"));
*/
}
void CommonTests::testMacro()
{
//TODO: CLEANUP!!!!!!
kdDebug()<<"===================== testMacro() ======================" << endl;
TQDomElement const domelement = d->doomdocument->documentElement();
TDESharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
//Is our XML parseable ?
KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
// //create a TQDomDocument
// TQDomDocument domdocument = TQDomDocument();
//
// //Fully fleged content this time with macro,function and action
// domdocument.setContent(TQString(
// "<macro name=\"mymacro\" icon=\"myicon\" text=\"My Macro\" comment=\"Some comment to describe the Macro.\">"
// "<action name=\"myaction\" text=\"My Action\" comment=\"Just some comment\" />"
// "<function name=\"myfunc\" text=\"My Function\" comment=\"Describe what the function does\" receiver=\"TestObject\" slot=\"myslot(const TQString &)\">"
// "<argument>The myfunc argument string</argument>"
// "</function>"
// "</macro>"
// ));
//
// //create Macro
// // TDESharedPtr<KoMacro::Action> macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
// //cast data to Macro
// KoMacro::Macro* macro = dynamic_cast<KoMacro::Macro*>( macroptr.data() );
//check that it is not null
KOMACROTEST_XASSERT(sizetype(macro.data()), sizetype(0));
//check that domeElement given to manager is the sam as in the macro
// KOMACROTEST_ASSERT( macro->toXML(), d->doomdocument->documentElement() );
//check the name
KOMACROTEST_ASSERT( TQString(macro->name()), TQString("testMacro") );
/**
@deprecated values no longer exist
//check the text
KOMACROTEST_ASSERT( macro->text(), TQString("My Macro") );
//check iconname
KOMACROTEST_ASSERT( TQString(macro->icon()), TQString("myicon") );
//check comment
KOMACROTEST_ASSERT( macro->comment(), TQString("Some comment to describe the Macro.") );
*/
//create list of KsharedPtr from the childs of the macro
TQValueList< TDESharedPtr<KoMacro::MacroItem> >& items = macro->items();
//check that there is one
KOMACROTEST_ASSERT( items.count(), sizetype(1) );
//fetch the first one
TDESharedPtr<KoMacro::Action> actionptr = items[0]->action();
//How do we know that an action exist ?
//-> check that it is not null
KOMACROTEST_XASSERT(sizetype(actionptr.data()), sizetype(0));
//check that it has the right name
KOMACROTEST_ASSERT( TQString(actionptr->name()), TQString("testaction") );
//check that it has the right text
KOMACROTEST_ASSERT( actionptr->text(), TQString("Test") );
//check that it has the right comment
// KOMACROTEST_ASSERT( actionptr->comment(), TQString("") );
/*
//fetch the second one
TDESharedPtr<KoMacro::Action> myfuncptr = children[1];
//cast it to function
KoMacro::Function* myfunc = dynamic_cast<KoMacro::Function*>( myfuncptr.data() );
//check that it isn?t null
KOMACROTEST_XASSERT((int) myfunc, 0);
//check it?s name
KOMACROTEST_ASSERT( TQString(myfunc->name()), TQString("myfunc"));
//check it?s text
KOMACROTEST_ASSERT( myfunc->text(), TQString("My Function") );
//check it?s comment
KOMACROTEST_ASSERT( myfunc->comment(), TQString("Describe what the function does") );
//check it?s receiver object
KOMACROTEST_ASSERT( myfunc->receiver(), TQString("TestObject") );
//check it?s slot
KOMACROTEST_ASSERT( myfunc->slot(), TQString("myslot(const TQString&)") );
//exceute it
myfunc->activate();
*/
//create another macro
TDESharedPtr<KoMacro::Macro> yanMacro = KoMacro::Manager::self()->createMacro("testMacro2");
KOMACROTEST_ASSERT(yanMacro->parseXML(domelement),true);
//create two more macros
//TDESharedPtr<KoMacro::Action> yanActionptr2 = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//TDESharedPtr<KoMacro::Action> yanActionptr3 = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//check that they aren?t null
KOMACROTEST_XASSERT(sizetype(yanMacro.data()), sizetype(0));
//KOMACROTEST_XASSERT((int) yanActionptr2.data(), 0);
//KOMACROTEST_XASSERT((int) yanActionptr3.data(), 0);
//create a list of the children from yanMacro
//TQValueList< TDESharedPtr<KoMacro::Action> > yanChildren = yanMacro->children();
//check that there are two
//KOMACROTEST_ASSERT(yanChildren.count(), uint(2));
/*
{
//keep oldsize
const int oldsize = yanChildren.count();
//add a new child to the macro
yanMacro->addChild(yanActionptr2);
//get the children
yanChildren = yanMacro->children();
//get count of children
const int size = yanChildren.count();
//check count has changed
KOMACROTEST_XASSERT(size, oldsize);
}
{
//keep oldsize
const int oldsize = yanChildren.count();
//add a new child to the macro
yanMacro->addChild(yanActionptr3);
//get the children
yanChildren = yanMacro->children();
//get count of children
const int size = yanChildren.count();
//check count has changed
KOMACROTEST_XASSERT(size, oldsize);
//check the hasChildren function
KOMACROTEST_ASSERT(yanMacro->hasChildren(), true);
}
*/
}
void CommonTests::testDom() {
//TODO: CLEANUP!!!!!!
kdDebug()<<"===================== testDom() ======================" << endl;
/*
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//create data for various documents
TQString const comment = "Describe what the function does";
TQString const name = "myfunc";
TQString const text = "My Function";
TQString const receiver1 = "TestObject";
TQString const receiver2 = "GibtsNich";
//create wrong Argument tag
domdocument.setContent(TQString(
"<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const TQString & , int)\">"
"<Arg0ment>Some string</Arg0ment>"
"<Arg0ment>12345</Arg0ment>"
"</function>"
));
//create functiom
TDESharedPtr<KoMacro::Action> macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//try to execute function and catch exception
KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
//create wrong receiver
domdocument.setContent(TQString(
"<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver2 + "\" slot=\"myslot(const TQString & , int)\">"
"<argument>Some string</argument>"
"<argument>12345</argument>"
"</function>"
));
//create function
macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//try to execute function and catch exception
KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
//create "wrong" number of parameters
domdocument.setContent(TQString(
"<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const TQString & , int, double)\">"
"<argument>Some string</argument>"
"<argument>12345</argument>"
"<argument>12345.25</argument>"
"</function>"
));
//create function
macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//try to execute function and catch exception
KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
//create wrong function tag
domdocument.setContent(TQString(
"<NoFunction name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const TQString & , int, double)\">"
"<argument>Some string</argument>"
"<argument>12345</argument>"
"<argument>12345.25</argument>"
"</NoFunction>"
));
//try to create function and catch exception
KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() ));
//create empty function
domdocument.setContent(TQString(
"<function name=\"\" text=\"\" comment=\"\" receiver=\"\" slot=\"\">"
"<argument> </argument>"
"<argument> </argument>"
"<argument> </argument>"
"</function>"
));
//create function
macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//try to execute function and catch exception
KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
//create empty function
domdocument.setContent(TQString(
"<function>"
"</function>"
));
//create function
macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//try to execute function and catch exception
KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
*/
}
void CommonTests::testVariables()
{
//TODO: CLEANUP!!!!!!
kdDebug()<<"===================== testVariables() ======================" << endl;
/*
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//create data
domdocument.setContent(TQString(
"<macro name=\"mymacro123\" text=\"My Macro 123\">"
"<function name=\"func1\" text=\"Function1\" receiver=\"TestObject\" slot=\"myslot(const TQString &)\" >"
"<argument>$MyArgumentVariable</argument>"
"<return>$MyReturnVariable</return>"
"</function>"
"</macro>"
));
//create an macro
TDESharedPtr<KoMacro::Action> macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//cast data to macro
KoMacro::Macro* macro = dynamic_cast<KoMacro::Macro*>( macroptr.data() );
//check that it is not null
KOMACROTEST_XASSERT((int) macro, 0);
//create a list of its children
TQValueList< TDESharedPtr<KoMacro::Action> > children = macro->children();
//Check that there are two children. The first child is always the returnvalue.
KOMACROTEST_ASSERT( children.count(), uint(2) );
//fetch the children
TDESharedPtr<KoMacro::Action> func1ptr = children[1];
//create new context
TDESharedPtr<KoMacro::Context> context = new KoMacro::Context(macroptr);
{
//try to execute function with non-functional variable
KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, func1ptr->activate(context));
KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, context->variable("$MyReturnVariable333"));
}
{
//set variable to be a TQString
context->setVariable("$MyArgumentVariable", new KoMacro::Variable("Some string"));
//execute function
func1ptr->activate(context);
//fetch return value
TDESharedPtr<KoMacro::Variable> returnvariable = context->variable("$MyReturnVariable");
//check that it is not null
KOMACROTEST_XASSERT( (int) returnvariable.data(), 0);
//check that it is "Some String"
KOMACROTEST_ASSERT(returnvariable->toString(),TQString("Some string"));
}
{
//set variable to be an Int
context->setVariable("$MyArgumentVariable", new KoMacro::Variable( 12345 ));
//execute function
func1ptr->activate(context);
//fetch return value
TDESharedPtr<KoMacro::Variable> returnvariable = context->variable("$MyReturnVariable");
//check that it is not null
KOMACROTEST_XASSERT( (int) returnvariable.data(), 0);
//check that it is 12345
KOMACROTEST_ASSERT(returnvariable->toInt(),12345);
}
*/
}
#include "commontests.moc"
|