Jamoma API  0.6.0.a19
TTNodeLib.test.cpp
1 /*
2  * Unit tests for the NodeLib
3  * Copyright © 2011, Théo de la Hogue
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #ifndef DISABLE_NODELIB
10 
11 #include "TTNodeLib.test.h"
12 
13 #define thisTTClass TTNodeLibTest
14 #define thisTTClassName "nodelib.test"
15 #define thisTTClassTags "test, foundation"
16 
18 {;}
19 
20 TTNodeLibTest::~TTNodeLibTest()
21 {;}
22 
23 void TTNodeLibTestAddressParsing(int& errorCount, int& testAssertionCount)
24 {
25  TTTestLog("\n");
26  TTTestLog("Testing Address Parsing");
27 
28  TTAddress testAddress1("directory1:/gran/parent1/name1.instance1:attribute1");
29 
30  TTSymbol directory1 = testAddress1.getDirectory();
31  TTAddress parent1 = testAddress1.getParent();
32  TTSymbol name1 = testAddress1.getName();
33  TTSymbol instance1 = testAddress1.getInstance();
34  TTSymbol attribute1 = testAddress1.getAttribute();
35  TTAddressType type1 = testAddress1.getType();
36  TTSymbol parentDirectory1 = testAddress1.getParent().getDirectory();
37 
38  TTAddress testAddress2("/gran/parent2/name2.instance2");
39 
40  TTSymbol directory2 = testAddress2.getDirectory();
41  TTAddress parent2 = testAddress2.getParent();
42  TTSymbol name2 = testAddress2.getName();
43  TTSymbol instance2 = testAddress2.getInstance();
44  TTSymbol attribute2 = testAddress2.getAttribute();
45  TTAddressType type2 = testAddress2.getType();
46 
47  TTAddress testAddress3("parent3/name3.instance3");
48 
49  TTSymbol directory3 = testAddress3.getDirectory();
50  TTAddress parent3 = testAddress3.getParent();
51  TTSymbol name3 = testAddress3.getName();
52  TTSymbol instance3 = testAddress3.getInstance();
53  TTSymbol attribute3 = testAddress3.getAttribute();
54  TTAddressType type3 = testAddress3.getType();
55 
56  TTAddress testAddress4("/");
57 
58  TTSymbol directory4 = testAddress4.getDirectory();
59  TTAddress parent4 = testAddress4.getParent();
60  TTSymbol name4 = testAddress4.getName();
61  TTSymbol instance4 = testAddress4.getInstance();
62  TTSymbol attribute4 = testAddress4.getAttribute();
63  TTAddressType type4 = testAddress4.getType();
64 
65  TTAddress testAddress5(":attribute5");
66 
67  TTSymbol directory5 = testAddress5.getDirectory();
68  TTAddress parent5 = testAddress5.getParent();
69  TTSymbol name5 = testAddress5.getName();
70  TTSymbol instance5 = testAddress5.getInstance();
71  TTSymbol attribute5 = testAddress5.getAttribute();
72  TTAddressType type5 = testAddress5.getType();
73 
74  TTAddress testAddress6("/gran/parent6.0/name6.0:attribute6");
75 
76  TTSymbol directory6 = testAddress6.getDirectory();
77  TTAddress parent6 = testAddress6.getParent();
78  TTSymbol name6 = testAddress6.getName();
79  TTSymbol instance6 = testAddress6.getInstance();
80  TTSymbol attribute6 = testAddress6.getAttribute();
81  TTAddressType type6 = testAddress6.getType();
82 
83  TTAddress testAddress7("/*.*");
84 
85  TTSymbol directory7 = testAddress7.getDirectory();
86  TTAddress parent7 = testAddress7.getParent();
87  TTSymbol name7 = testAddress7.getName();
88  TTSymbol instance7 = testAddress7.getInstance();
89  TTSymbol attribute7 = testAddress7.getAttribute();
90  TTAddressType type7 = testAddress7.getType();
91 
92  TTAddress testAddress8("/parent8/t");
93 
94  TTSymbol directory8 = testAddress8.getDirectory();
95  TTAddress parent8 = testAddress8.getParent();
96  TTSymbol name8 = testAddress8.getName();
97  TTSymbol instance8 = testAddress8.getInstance();
98  TTSymbol attribute8 = testAddress8.getAttribute();
99  TTAddressType type8 = testAddress8.getType();
100 
101  TTAddress testAddress9("/parent.0/name.0:attribute9");
102 
103  TTSymbol directory9 = testAddress9.getDirectory();
104  TTAddress parent9 = testAddress9.getParent();
105  TTSymbol name9 = testAddress9.getName();
106  TTSymbol instance9 = testAddress9.getInstance();
107  TTSymbol attribute9 = testAddress9.getAttribute();
108  TTAddressType type9 = testAddress9.getType();
109 
110  TTAddress testAddress10("/parent/0:attribute10");
111 
112  TTSymbol directory10 = testAddress10.getDirectory();
113  TTAddress parent10 = testAddress10.getParent();
114  TTSymbol name10 = testAddress10.getName();
115  TTSymbol instance10 = testAddress10.getInstance();
116  TTSymbol attribute10 = testAddress10.getAttribute();
117  TTAddressType type10 = testAddress10.getType();
118 
119  TTAddress testAddress11("directory11:/");
120 
121  TTSymbol directory11 = testAddress11.getDirectory();
122  TTAddress parent11 = testAddress11.getParent();
123  TTSymbol name11 = testAddress11.getName();
124  TTSymbol instance11 = testAddress11.getInstance();
125  TTSymbol attribute11 = testAddress11.getAttribute();
126  TTAddressType type11 = testAddress11.getType();
127 
128  TTAddress testAddress12("directory12:/1");
129 
130  TTSymbol directory12 = testAddress12.getDirectory();
131  TTAddress parent12 = testAddress12.getParent();
132  TTSymbol name12 = testAddress12.getName();
133  TTSymbol instance12 = testAddress12.getInstance();
134  TTSymbol attribute12 = testAddress12.getAttribute();
135  TTAddressType type12 = testAddress12.getType();
136 
137  TTAddress testAddress13("na-me13");
138 
139  TTSymbol directory13 = testAddress13.getDirectory();
140  TTAddress parent13 = testAddress13.getParent();
141  TTSymbol name13 = testAddress13.getName();
142  TTSymbol instance13 = testAddress13.getInstance();
143  TTSymbol attribute13 = testAddress13.getAttribute();
144  TTAddressType type13 = testAddress13.getType();
145 
146  TTAddress testAddress14("direc-tory14:/par-ent14/na-me14.inst-ance14:attr-ibute14");
147 
148  TTSymbol directory14 = testAddress14.getDirectory();
149  TTAddress parent14 = testAddress14.getParent();
150  TTSymbol name14 = testAddress14.getName();
151  TTSymbol instance14 = testAddress14.getInstance();
152  TTSymbol attribute14 = testAddress14.getAttribute();
153  TTAddressType type14 = testAddress14.getType();
154 
155 
156  // The first set of tests checks parsing of addresses
157  TTTestAssertion("TTAddress: Test fails if parsing of testAddress1 is bad",
158  directory1 == TTSymbol("directory1") &&
159  parent1 == TTAddress("directory1:/gran/parent1") &&
160  name1 == TTSymbol("name1") &&
161  instance1 == TTSymbol("instance1") &&
162  attribute1 == TTSymbol("attribute1") &&
163  type1 == kAddressAbsolute &&
164  parentDirectory1 == directory1,
165  testAssertionCount,
166  errorCount);
167 
168  TTTestAssertion("TTAddress: Test fails if parsing of testAddress2 is bad",
169  directory2 == NO_DIRECTORY &&
170  parent2 == TTAddress("/gran/parent2") &&
171  name2 == TTSymbol("name2") &&
172  instance2 == TTSymbol("instance2") &&
173  attribute2 == NO_ATTRIBUTE &&
174  type2 == kAddressAbsolute,
175  testAssertionCount,
176  errorCount);
177 
178  TTTestAssertion("TTAddress: Test fails if parsing of testAddress3 is bad",
179  directory3 == NO_DIRECTORY &&
180  parent3 == TTAddress("parent3") &&
181  name3 == TTSymbol("name3") &&
182  instance3 == TTSymbol("instance3") &&
183  attribute3 == NO_ATTRIBUTE &&
184  type3 == kAddressRelative,
185  testAssertionCount,
186  errorCount);
187 
188  TTTestAssertion("TTAddress: Test fails if parsing of testAddress4 is bad",
189  directory4 == NO_DIRECTORY &&
190  parent4 == NO_PARENT &&
191  name4 == S_SEPARATOR &&
192  instance4 == NO_INSTANCE &&
193  attribute4 == NO_ATTRIBUTE &&
194  type4 == kAddressAbsolute,
195  testAssertionCount,
196  errorCount);
197 
198  TTTestAssertion("TTAddress: Test fails if parsing of testAddress5 is bad",
199  directory5 == NO_DIRECTORY &&
200  parent5 == NO_PARENT &&
201  name5 == NO_NAME &&
202  instance5 == NO_INSTANCE &&
203  attribute5 == TTSymbol("attribute5") &&
204  type5 == kAddressRelative,
205  testAssertionCount,
206  errorCount);
207 
208  TTTestAssertion("TTAddress: Test fails if parsing of testAddress6 is bad",
209  directory6 == NO_DIRECTORY &&
210  parent6 == TTAddress("/gran/parent6") &&
211  name6 == TTSymbol("name6") &&
212  instance6 == NO_INSTANCE &&
213  attribute6 == TTSymbol("attribute6") &&
214  type6 == kAddressAbsolute,
215  testAssertionCount,
216  errorCount);
217 
218  TTTestAssertion("TTAddress: Test fails if parsing of testAddress7 is bad",
219  directory7 == NO_DIRECTORY &&
220  parent7 == kTTAdrsRoot &&
221  name7 == S_WILDCARD &&
222  instance7 == S_WILDCARD &&
223  attribute7 == NO_ATTRIBUTE &&
224  type7 == kAddressAbsolute,
225  testAssertionCount,
226  errorCount);
227 
228  TTTestAssertion("TTAddress: Test fails if parsing of testAddress8 is bad",
229  directory8 == NO_DIRECTORY &&
230  parent8 == TTAddress("/parent8") &&
231  name8 == TTSymbol("t") &&
232  instance8 == NO_INSTANCE &&
233  attribute8 == NO_ATTRIBUTE &&
234  type8 == kAddressAbsolute,
235  testAssertionCount,
236  errorCount);
237 
238  TTTestAssertion("TTAddress: Test fails if parsing of testAddress9 is bad",
239  directory9 == NO_DIRECTORY &&
240  parent9 == TTAddress("/parent") &&
241  name9 == TTSymbol("name") &&
242  instance9 == NO_INSTANCE &&
243  attribute9 == TTSymbol("attribute9") &&
244  type9 == kAddressAbsolute,
245  testAssertionCount,
246  errorCount);
247 
248  TTTestAssertion("TTAddress: Test fails if parsing of testAddress10 is bad",
249  directory10 == NO_DIRECTORY &&
250  parent10 == TTAddress("/parent") &&
251  name10 == TTSymbol("0") &&
252  instance10 == NO_INSTANCE &&
253  attribute10 == TTSymbol("attribute10") &&
254  type10 == kAddressAbsolute,
255  testAssertionCount,
256  errorCount);
257 
258  TTTestAssertion("TTAddress: Test fails if parsing of testAddress11 is bad",
259  directory11 == TTSymbol("directory11") &&
260  parent11 == NO_PARENT &&
261  name11 == S_SEPARATOR &&
262  instance11 == NO_INSTANCE &&
263  attribute11 == NO_ATTRIBUTE &&
264  type11 == kAddressAbsolute,
265  testAssertionCount,
266  errorCount);
267 
268  TTTestAssertion("TTAddress: Test fails if parsing of testAddress12 is bad",
269  directory12 == TTSymbol("directory12") &&
270  parent12 == kTTAdrsRoot &&
271  name12 == TTSymbol("1") &&
272  instance12 == NO_INSTANCE &&
273  attribute12 == NO_ATTRIBUTE &&
274  type12 == kAddressAbsolute,
275  testAssertionCount,
276  errorCount);
277 
278  TTTestAssertion("TTAddress: Test fails if parsing of testAddress13 is bad",
279  directory13 == NO_DIRECTORY &&
280  parent13 == NO_PARENT &&
281  name13 == TTSymbol("na-me13") &&
282  instance13 == NO_INSTANCE &&
283  attribute13 == NO_ATTRIBUTE &&
284  type13 == kAddressRelative,
285  testAssertionCount,
286  errorCount);
287 
288  TTTestAssertion("TTAddress: Test fails if parsing of testAddress14 is bad",
289  directory14 == TTSymbol("direc-tory14") &&
290  parent14 == TTAddress("direc-tory14:/par-ent14") &&
291  name14 == TTSymbol("na-me14") &&
292  instance14 == TTSymbol("inst-ance14") &&
293  attribute14 == TTSymbol("attr-ibute14") &&
294  type14 == kAddressAbsolute,
295  testAssertionCount,
296  errorCount);
297 }
298 
299 void TTNodeLibTestAddressMethods(int& errorCount, int& testAssertionCount)
300 {
301  TTAddress testAddressA("directory:/gran/parent/name.instance:attribute");
302  TTAddress testAddressB("/parent/name");
303  TTAddress testAddressC("name");
304 
305  TTAddress testAddressD("/gran/parent");
306  TTAddress testAddressE("directory:/gran/parent");
307 
308  TTAddress testAddressF("name.instance:attribute");
309  TTAddress testAddressG("/name.instance:attribute");
310 
311  TTAddress testAddressH("directory:/");
312 
313  TTSymbol testSymbolA("");
314 
315  TTSymbol resultSymbol;
316  TTAddress resultAddress;
317  TTAddress part1, part2;
318 
319  // the first set of tests checks the getNameInstance method
320  TTTestLog("\n");
321  TTTestLog("Testing Address getNameInstance Method");
322 
323  resultSymbol = testAddressA.getNameInstance();
324  TTTestAssertion("TTAddress: Test passes if the getNameInstance() method returns \"name.instance\"",
325  resultSymbol == TTSymbol("name.instance"),
326  testAssertionCount,
327  errorCount);
328 
329  resultSymbol = testAddressB.getNameInstance();
330  TTTestAssertion("TTAddress: Test passes if the getNameInstance() method returns \"name\"",
331  resultSymbol == TTSymbol("name"),
332  testAssertionCount,
333  errorCount);
334 
335  resultSymbol = testAddressC.getNameInstance();
336  TTTestAssertion("TTAddress: Test passes if the getNameInstance() method returns \"name\"",
337  resultSymbol == TTSymbol("name"),
338  testAssertionCount,
339  errorCount);
340 
341  resultSymbol = kTTAdrsEmpty.getNameInstance();
342  TTTestAssertion("TTAddress: Test passes if the getNameInstance() method returns kTTSymEmpty",
343  resultSymbol == kTTSymEmpty,
344  testAssertionCount,
345  errorCount);
346 
347  // the second set of tests checks the appendAddress method
348  TTTestLog("\n");
349  TTTestLog("Testing Address appendAddress Method");
350 
351  resultAddress = testAddressD.appendAddress(kTTAdrsEmpty);
352  TTTestAssertion("TTAddress: Test passes if the appendAddress() method returns the same address",
353  resultAddress == testAddressD,
354  testAssertionCount,
355  errorCount);
356 
357  resultAddress = kTTAdrsEmpty.appendAddress(testAddressD);
358  TTTestAssertion("TTAddress: Test passes if the appendAddress() method returns the same address",
359  resultAddress == testAddressD,
360  testAssertionCount,
361  errorCount);
362 
363  resultAddress = kTTAdrsRoot.appendAddress(testAddressD);
364  TTTestAssertion("TTAddress: Test passes if the appendAddress() method returns the same address",
365  resultAddress == testAddressD,
366  testAssertionCount,
367  errorCount);
368 
369  resultAddress = kTTAdrsEmpty.appendAddress(testAddressE);
370  TTTestAssertion("TTAddress: Test passes if the appendAddress() method returns the same address",
371  resultAddress == testAddressE,
372  testAssertionCount,
373  errorCount);
374 
375  resultAddress = kTTAdrsRoot.appendAddress(testAddressE);
376  TTTestAssertion("TTAddress: Test passes if the appendAddress() method returns the same address",
377  resultAddress == testAddressE,
378  testAssertionCount,
379  errorCount);
380 
381  resultAddress = testAddressD.appendAddress(testAddressF);
382  TTTestAssertion("TTAddress: Test passes if the appendAddress() method returns \"/gran/parent/name.instance:attribute\"",
383  resultAddress == TTAddress("/gran/parent/name.instance:attribute"),
384  testAssertionCount,
385  errorCount);
386 
387  resultAddress = testAddressD.appendAddress(testAddressG);
388  TTTestAssertion("TTAddress: Test passes if the appendAddress() method returns \"/gran/parent/name.instance:attribute\"",
389  resultAddress == TTAddress("/gran/parent/name.instance:attribute"),
390  testAssertionCount,
391  errorCount);
392 
393  // This test checks appendInstance() and appendAttribute() methods
394  resultAddress = kTTAdrsRoot.appendAddress(TTAddress("name")).appendInstance(TTAddress("instance")).appendAttribute(TTAddress("attribute"));
395  TTTestAssertion("TTAddress: Test passes if appendAddress + appendInstance + appendAttribute methods returns \"/name.instance:attribute\"",
396  resultAddress == TTAddress("/name.instance:attribute"),
397  testAssertionCount,
398  errorCount);
399 
400  resultAddress = testAddressH.appendAddress(testAddressF);
401  TTTestAssertion("TTAddress: Test passes if the appendAddress() method returns \"directory:/name.instance:attribute\"",
402  resultAddress == TTAddress("directory:/name.instance:attribute"),
403  testAssertionCount,
404  errorCount);
405 
406  resultAddress = testAddressE.appendAttribute(TTSymbol("attribute"));
407  TTTestAssertion("TTAddress: Test passes if the appendAttribute() method returns \"directory:/gran/parent:attribute\"",
408  resultAddress == TTAddress("directory:/gran/parent:attribute"),
409  testAssertionCount,
410  errorCount);
411 
412  // the third set of tests checks the splitAt method
413  TTTestLog("\n");
414  TTTestLog("Testing Address splitAt Method");
415 
416  testAddressA.splitAt(0, part1, part2);
417  TTTestAssertion("TTAddress: Test passes if splitAt method returns \"directory:/\" and \"gran/parent/name.instance:attribute\"",
418  part1 == TTAddress("directory:/") &&
419  part2 == TTAddress("gran/parent/name.instance:attribute"),
420  testAssertionCount,
421  errorCount);
422 
423  testAddressA.splitAt(1, part1, part2);
424  TTTestAssertion("TTAddress: Test passes if splitAt method returns \"directory:/gran\" and \"parent/name.instance:attribute\"",
425  part1 == TTAddress("directory:/gran") &&
426  part2 == TTAddress("parent/name.instance:attribute"),
427  testAssertionCount,
428  errorCount);
429 
430  testAddressA.splitAt(2, part1, part2);
431  TTTestAssertion("TTAddress: Test passes if splitAt method returns \"directory:/gran/parent\" and \"name.instance:attribute\"",
432  part1 == TTAddress("directory:/gran/parent") &&
433  part2 == TTAddress("name.instance:attribute"),
434  testAssertionCount,
435  errorCount);
436 
437 
438  // the fourth set of tests checks the countSeparator method
439  TTTestLog("\n");
440  TTTestLog("Testing Address countSeparator Method");
441 
442  /*
443  // the fift set of tests checks the listNameInstance method
444  TTTestLog("\n");
445  TTTestLog("Testing Address listNameInstance Method");
446  */
447 
448 }
449 
450 void TTNodeLibTestAddressItem(int& errorCount, int& testAssertionCount)
451 {
452  TTAddressItemPtr aNamespace, aParent, n, f;
453  TTSymbol aSymbol(kTTSymEmpty);
454  TTBoolean aSelection, empty;
455  TTUInt8 size;
456  TTErr err;
457 
458  TTTestLog("\n");
459  TTTestLog("Testing Address Item management");
460 
461  // The first test checks item creation and member access
462  aNamespace = new TTAddressItem(kTTSymEmpty);
463  aSymbol = aNamespace->getSymbol();
464  aParent = aNamespace->getParent();
465  aSelection = aNamespace->getSelection();
466  empty = aNamespace->isEmpty();
467 
468  TTTestAssertion("TTAddressItem: Test fails if the namespace is not empty",
469  empty &&
470  aSymbol == NO_NAME &&
471  aParent == NULL &&
472  aSelection == NO,
473  testAssertionCount,
474  errorCount);
475 
476  // The second set of tests checks item management
477  n = new TTAddressItem(TTSymbol("test"));
478  aNamespace->merge(n);
479 
480  TTTestAssertion("TTAddressItem: Test fails if the namespace size is not equal 1",
481  aNamespace->getSize() == 1,
482  testAssertionCount,
483  errorCount);
484 
485  f = aNamespace->getItem(n->getSymbol());
486 
487  if (f) {
488  aSymbol = f->getSymbol();
489  aParent = f->getParent();
490  aSelection = f->getSelection();
491  empty = f->isEmpty();
492  }
493 
494  TTTestAssertion("TTAddressItem: Test fails if the namespace is not named \"test\" or have no parent",
495  empty &&
496  aSymbol == TTSymbol("test") &&
497  aParent == aNamespace &&
498  aSelection == NO,
499  testAssertionCount,
500  errorCount);
501 
502  aNamespace->destroy(n);
503 
504  TTTestAssertion("TTAddressItem: Test fails if the namespace is not empty",
505  aNamespace->isEmpty(),
506  testAssertionCount,
507  errorCount);
508 
509  // The third set of tests checks item management using TTAddress
510  aNamespace->clear();
511  aNamespace->append(TTAddress("/parent/name"), &f);
512  aNamespace->append(TTAddress("/parent/name.instance"), &f);
513 
514  aSymbol = aNamespace->getSymbol();
515  size = aNamespace->getSize();
516 
517  TTTestAssertion("TTAddressItem: Test fails if the namespace is not named \"\" and size is not equal 1",
518  size == 1 &&
519  aSymbol == kTTSymEmpty,
520  testAssertionCount,
521  errorCount);
522 
523  f = NULL;
524  err = aNamespace->find(TTAddress("/parent"), &f);
525 
526  if (!err) {
527  aSymbol = f->getSymbol();
528  aParent = f->getParent();
529  aSelection = f->getSelection();
530  empty = f->isEmpty();
531  }
532 
533  TTTestAssertion("TTAddressItem: Test fails if the namespace is not named \"\" or have no parent or no child",
534  !empty &&
535  aSymbol == kTTSymEmpty &&
536  aParent == aNamespace->getItem(TTSymbol("parent")) &&
537  aSelection == NO,
538  testAssertionCount,
539  errorCount);
540 
541  n = f;
542  f = NULL;
543  err = aNamespace->find(TTAddress("/parent/name"), &f);
544 
545  if (!err) {
546  aSymbol = f->getSymbol();
547  aParent = f->getParent();
548  aSelection = f->getSelection();
549  empty = f->isEmpty();
550  }
551 
552  TTTestAssertion("TTAddressItem: Test fails if the namespace is not named \"\" or have no parent or is not empty",
553  empty &&
554  aSymbol == kTTSymEmpty &&
555  n != NULL &&
556  aParent == n->getItem(TTSymbol("name")) &&
557  aSelection == NO,
558  testAssertionCount,
559  errorCount);
560 
561  n = f;
562  f = NULL;
563  err = aNamespace->find(TTAddress("/parent/name.instance"), &f);
564 
565  if (!err) {
566  aSymbol = f->getSymbol();
567  aParent = f->getParent();
568  aSelection = f->getSelection();
569  empty = f->isEmpty();
570  }
571 
572  TTTestAssertion("TTAddressItem: Test fails if the namespace is not named \"instance\" or have no parent or is not empty",
573  empty &&
574  aSymbol == TTSymbol("instance") &&
575  aParent == n->getParent() &&
576  aSelection == NO,
577  testAssertionCount,
578  errorCount);
579 
580  f = NULL;
581  aNamespace->append(TTAddress("/parent/name.other"), &f);
582 
583  size = f->getParent()->getSize(); // have to be 3 because there are the empty, "instance" and "other" instances
584 
585  TTTestAssertion("TTAddressItem: Test fails if size is not equal to 3",
586  size == 3,
587  testAssertionCount,
588  errorCount);
589 }
590 
591 void TTNodeLibTestAddressComparison(int& errorCount, int& testAssertionCount)
592 {
594  TTInt8 depthDifference;
595 
596  TTTestLog("\n");
597  TTTestLog("Testing Address Comparison");
598 
599  TTAddress testAddressA("/gran/parent/name.instance");
600  TTAddress testAddressB("/gran");
601  TTAddress testAddressC("gran/parent/name.instance");
602  TTAddress testAddressD("gran");
603 
604  result = testAddressA.compare(testAddressA, depthDifference);
605  TTTestAssertion("TTAddressComparison: Test fails if comparison returns anything else than equality",
606  result == kAddressEqual &&
607  depthDifference == 0,
608  testAssertionCount,
609  errorCount);
610 
611  result = testAddressA.compare(testAddressB, depthDifference);
612  TTTestAssertion("TTAddressComparison: Test passes if comparison returns the address is lower with 2 levels of difference",
613  result == kAddressLower &&
614  depthDifference == 2,
615  testAssertionCount,
616  errorCount);
617 
618  result = testAddressB.compare(testAddressA, depthDifference);
619  TTTestAssertion("TTAddressComparison: Test passes if comparison returns the address is upper with 2 levels of difference",
620  result == kAddressUpper &&
621  depthDifference == -2,
622  testAssertionCount,
623  errorCount);
624 
625  result = testAddressC.compare(testAddressD, depthDifference);
626  TTTestAssertion("TTAddressComparison: Test passes if comparison returns the address is lower with 2 levels of difference",
627  result == kAddressLower &&
628  depthDifference == 2,
629  testAssertionCount,
630  errorCount);
631 
632  result = testAddressD.compare(testAddressC, depthDifference);
633  TTTestAssertion("TTAddressComparison: Test passes if comparison returns the address is upper with 2 levels of difference",
634  result == kAddressUpper &&
635  depthDifference == -2,
636  testAssertionCount,
637  errorCount);
638 
639  result = testAddressA.compare(testAddressD, depthDifference);
640  TTTestAssertion("TTAddressComparison: Test passes if comparison returns the address is lower with 2 levels of difference",
641  result == kAddressDifferent,
642  testAssertionCount,
643  errorCount);
644 
645  result = testAddressC.compare(testAddressB, depthDifference);
646  TTTestAssertion("TTAddressComparison: Test passes if comparison returns the address is upper with 2 levels of difference",
647  result == kAddressDifferent,
648  testAssertionCount,
649  errorCount);
650 }
651 
652 void TTNodeLibTestMiscellaneous(int& errorCount, int& testAssertionCount)
653 {
654  TTTestLog("\n");
655  TTTestLog("Miscellaneous Tests");
656 
657  // test convertUpperCasedName global method
658  TTSymbol testSymbolA = "TestSymbolName";
659  TTSymbol testSymbolB = "testSymbolName";
660  TTSymbol testSymbolC = "testsymbolname";
661  TTAddress result;
662 
663 
664  convertUpperCasedNameInAddress(testSymbolA, result);
665  TTTestAssertion("convertUpperCasedName: Test passes if \"TestSymbolName\" is converted in \"test/symbol/name\"",
666  result == TTAddress("test/symbol/name"),
667  testAssertionCount,
668  errorCount);
669 
670  convertUpperCasedNameInAddress(testSymbolB, result);
671  TTTestAssertion("convertUpperCasedName: Test passes if \"testSymbolName\" is converted in \"test/symbol/name\"",
672  result == TTAddress("test/symbol/name"),
673  testAssertionCount,
674  errorCount);
675 
676  convertUpperCasedNameInAddress(testSymbolC, result);
677  TTTestAssertion("convertUpperCasedName: Test passes if \"testsymbolname\" is not converted",
678  result == testSymbolC,
679  testAssertionCount,
680  errorCount);
681 
682  // test TTSymbol to TTAdress casting
683  TTValue testValue = TTValue(TTSymbol("directory:/gran/parent/name.instance:attribute"));
684  TTAddress testAddress;
685 
686  testAddress = testValue[0];
687 
688  TTSymbol directory = testAddress.getDirectory();
689  TTAddress parent = testAddress.getParent();
690  TTSymbol name = testAddress.getName();
691  TTSymbol instance = testAddress.getInstance();
692  TTSymbol attribute = testAddress.getAttribute();
693  TTAddressType type = testAddress.getType();
694 
695  TTTestAssertion("TTValue::get : Test2 fails if a TTSymbol contained into a value is not casted into a TTAddress during a get method",
696  directory == TTSymbol("directory") &&
697  parent == TTAddress("directory:/gran/parent") &&
698  name == TTSymbol("name") &&
699  instance == TTSymbol("instance") &&
700  attribute == TTSymbol("attribute") &&
701  type == kAddressAbsolute,
702  testAssertionCount,
703  errorCount);
704 
705  // test TTSymbol for TTHash access when a key is stored using a TTAddress
706  TTHash testTable;
707  TTAddress keyAddress = TTAddress("testKeyAddress");
708  TTValue keyValue;
709  TTErr err;
710 
711  testTable.append(keyAddress, keyValue); // store a value into the table using "testKeyAddress" address
712  testValue = TTValue(TTSymbol("testKeyAddress")); // store a "testKeyAddress" symbol into a value
713  testAddress = testValue[0]; // get it as an address
714  err = testTable.lookup(testAddress, keyValue); // use the address to lookup the table
715 
716  TTTestAssertion("TTHash::lookup : Test fails if a TTSymbol cannot be used as storage key for TTHash table when the lookup key is a TTAddress",
717  err == kTTErrNone,
718  testAssertionCount,
719  errorCount);
720 
721  // The test below fails but it have been added only to check the opposite operation.
722  // For instant we don't need this test to pass so it is commented out until we need this feature.
723 
724  /* test TTAddress for TTHash access when a key is stored using a TTSymbol
725  TTSymbol keySymbol = TTSymbol("testKeySymbol");
726  TTSymbol testSymbol;
727 
728  testTable.append(keySymbol, keyValue); // store a value into the table using "testKeySymbol" symbol
729  testValue = TTValue(TTAddress("testKeySymbol")); // store a "testKeySymbol" address into a value
730  testSymbol = testValue[0]; // get it as an symbol
731  err = testTable.lookup(testSymbol, keyValue); // use the symbol to lookup the table
732 
733  TTTestAssertion("TTHash::lookup : Test fails if a TTAddress cannot be used as storage key for TTHash table when the lookup key is a TTSymbol",
734  err == kTTErrNone,
735  testAssertionCount,
736  errorCount);
737  */
738 }
739 
740 // TODO: Benchmarking
741 
742 TTErr TTNodeLibTest::test(TTValue& returnedTestInfo)
743 {
744  int errorCount = 0;
745  int testAssertionCount = 0;
746 
747  TTNodeLibTestAddressParsing(errorCount, testAssertionCount);
748 
749  TTNodeLibTestAddressMethods(errorCount, testAssertionCount);
750 
751  TTNodeLibTestAddressItem(errorCount, testAssertionCount);
752 
753  TTNodeLibTestAddressComparison(errorCount, testAssertionCount);
754 
755  TTNodeLibTestMiscellaneous(errorCount, testAssertionCount);
756 
757  return TTTestFinish(testAssertionCount, errorCount, returnedTestInfo);
758 }
759 
760 #endif
761 
TTAddress appendAddress(const TTAddress &toAppend)
Return a new TTAddress with the appended part.
Definition: TTAddress.h:167
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTSymbol & getInstance()
Get the instance part.
Definition: TTAddress.h:124
this flag means that address1 an address2 refer to nodes which are in a different branch in the tree ...
Definition: TTAddressBase.h:47
TTAddress appendAttribute(TTSymbol anAttribute)
Return a new TTAddress with attribute part.
Definition: TTAddress.h:161
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
Definition: TTHash.cpp:76
TTSymbol & getDirectory()
Get the directory part.
Definition: TTAddress.h:106
TTAddress getParent()
Get a pointer to the parent address.
Definition: TTAddress.h:112
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Definition: TTAddress.h:29
TTAddress appendInstance(const TTSymbol anInstance)
Return a new TTAddress with a instance part.
Definition: TTAddress.h:173
this flag means that an address have no leading slash
Definition: TTAddressBase.h:64
TTAddressType
Type flags to state about absolute or relative address.
Definition: TTAddressBase.h:63
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
Definition: TTHash.h:36
this flag means that address1 an address2 refer to the same node in the tree structure ...
Definition: TTAddressBase.h:48
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
Definition: TTHash.cpp:70
TTSymbol & getAttribute()
Get the attribute part.
Definition: TTAddress.h:130
TTSymbol getNameInstance()
Get the name.instance part.
Definition: TTAddress.h:142
this flag means that an address have a leading slash
Definition: TTAddressBase.h:65
this flag means that address1 refers to a node at a lower level than address2 in the tree structure ...
Definition: TTAddressBase.h:46
TTAddressComparisonFlag
Comparison flags between address returned by address1->compare(address2).
Definition: TTAddressBase.h:45
this flag means that address1 refers to a node at a upper level than address2 in the tree structure ...
Definition: TTAddressBase.h:49
TTAddressType getType()
Get the type.
Definition: TTAddress.h:136
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
signed char TTInt8
8 bit signed integer (char)
Definition: TTBase.h:173
No Error.
Definition: TTBase.h:343
TT_OBJECT_CONSTRUCTOR
Constructor macro.
TTSymbol & getName()
Get the name part.
Definition: TTAddress.h:118
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
unsigned char TTUInt8
8 bit unsigned integer (char)
Definition: TTBase.h:174