A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
names-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16 
17 #include "ns3/test.h"
18 #include "ns3/names.h"
19 
20 using namespace ns3;
21 
22 // ===========================================================================
23 // Cook up a couple of simple object class that we can use in the object
24 // naming tests. They do nothing but be of the right type.
25 // ===========================================================================
26 class TestObject : public Object
27 {
28 public:
29  static TypeId GetTypeId (void)
30  {
31  static TypeId tid = TypeId ("TestObject")
35  return tid;
36  }
37  TestObject () {}
38  virtual void Dispose (void) {}
39 };
40 
42 {
43 public:
44  static TypeId GetTypeId (void)
45  {
46  static TypeId tid = TypeId ("AlternateTestObject")
50  return tid;
51  }
53  virtual void Dispose (void) {}
54 };
55 
56 // ===========================================================================
57 // Test case to make sure that the Object Name Service can do its most basic
58 // job and add associations between Objects using the lowest level add
59 // function, which is:
60 //
61 // Add (Ptr<Object> context, std::string name, Ptr<Object> object);
62 //
63 // All other add functions will just translate into this form, so this is the
64 // most basic Add functionality.
65 // ===========================================================================
66 class BasicAddTestCase : public TestCase
67 {
68 public:
70  virtual ~BasicAddTestCase ();
71 
72 private:
73  virtual void DoRun (void);
74  virtual void DoTeardown (void);
75 };
76 
78  : TestCase ("Check low level Names::Add and Names::FindName functionality")
79 {
80 }
81 
83 {
84 }
85 
86 void
88 {
89  Names::Clear ();
90 }
91 
92 void
94 {
95  std::string found;
96 
97  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
98  Names::Add (Ptr<Object> (0, false), "Name One", objectOne);
99 
100  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
101  Names::Add (Ptr<Object> (0, false), "Name Two", objectTwo);
102 
103  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
104  Names::Add (objectOne, "Child", childOfObjectOne);
105 
106  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
107  Names::Add (objectTwo, "Child", childOfObjectTwo);
108 
109  found = Names::FindName (objectOne);
110  NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
111 
112  found = Names::FindName (objectTwo);
113  NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
114 
115  found = Names::FindName (childOfObjectOne);
116  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
117 
118  found = Names::FindName (childOfObjectTwo);
119  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
120 }
121 
122 // ===========================================================================
123 // Test case to make sure that the Object Name Service can correctly use a
124 // string context in the most basic ways
125 //
126 // Add (std::string context, std::string name, Ptr<Object> object);
127 //
128 // High level path-based functions will translate into this form, so this is
129 // the second most basic Add functionality.
130 // ===========================================================================
132 {
133 public:
135  virtual ~StringContextAddTestCase ();
136 
137 private:
138  virtual void DoRun (void);
139  virtual void DoTeardown (void);
140 };
141 
143  : TestCase ("Check string context Names::Add and Names::FindName functionality")
144 
145 {
146 }
147 
149 {
150 }
151 
152 void
154 {
155  Names::Clear ();
156 }
157 
158 void
160 {
161  std::string found;
162 
163  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
164  Names::Add ("/Names", "Name One", objectOne);
165 
166  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
167  Names::Add ("/Names", "Name Two", objectTwo);
168 
169  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
170  Names::Add ("/Names/Name One", "Child", childOfObjectOne);
171 
172  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
173  Names::Add ("/Names/Name Two", "Child", childOfObjectTwo);
174 
175  found = Names::FindName (objectOne);
176  NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
177 
178  found = Names::FindName (objectTwo);
179  NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
180 
181  found = Names::FindName (childOfObjectOne);
182  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
183 
184  found = Names::FindName (childOfObjectTwo);
185  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
186 }
187 
188 // ===========================================================================
189 // Test case to make sure that the Object Name Service can correctly use a
190 // fully qualified path to add assocations
191 //
192 // Add (std::string name, Ptr<Object> object);
193 // ===========================================================================
195 {
196 public:
198  virtual ~FullyQualifiedAddTestCase ();
199 
200 private:
201  virtual void DoRun (void);
202  virtual void DoTeardown (void);
203 };
204 
206  : TestCase ("Check fully qualified path Names::Add and Names::FindName functionality")
207 
208 {
209 }
210 
212 {
213 }
214 
215 void
217 {
218  Names::Clear ();
219 }
220 
221 void
223 {
224  std::string found;
225 
226  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
227  Names::Add ("/Names/Name One", objectOne);
228 
229  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
230  Names::Add ("/Names/Name Two", objectTwo);
231 
232  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
233  Names::Add ("/Names/Name One/Child", childOfObjectOne);
234 
235  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
236  Names::Add ("/Names/Name Two/Child", childOfObjectTwo);
237 
238  found = Names::FindName (objectOne);
239  NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
240 
241  found = Names::FindName (objectTwo);
242  NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
243 
244  found = Names::FindName (childOfObjectOne);
245  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
246 
247  found = Names::FindName (childOfObjectTwo);
248  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
249 }
250 
251 // ===========================================================================
252 // Test case to make sure that the Object Name Service can correctly use a
253 // relative path to add assocations. This functionality is provided as a
254 // convenience so clients don't always have to provide the name service
255 // namespace name in all of their strings.
256 //
257 //
258 // Add (std::string name, Ptr<Object> object);
259 // ===========================================================================
261 {
262 public:
264  virtual ~RelativeAddTestCase ();
265 
266 private:
267  virtual void DoRun (void);
268  virtual void DoTeardown (void);
269 };
270 
272  : TestCase ("Check relative path Names::Add and Names::FindName functionality")
273 
274 {
275 }
276 
278 {
279 }
280 
281 void
283 {
284  Names::Clear ();
285 }
286 
287 void
289 {
290  std::string found;
291 
292  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
293  Names::Add ("Name One", objectOne);
294 
295  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
296  Names::Add ("Name Two", objectTwo);
297 
298  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
299  Names::Add ("Name One/Child", childOfObjectOne);
300 
301  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
302  Names::Add ("Name Two/Child", childOfObjectTwo);
303 
304  found = Names::FindName (objectOne);
305  NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
306 
307  found = Names::FindName (objectTwo);
308  NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
309 
310  found = Names::FindName (childOfObjectOne);
311  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
312 
313  found = Names::FindName (childOfObjectTwo);
314  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
315 }
316 
317 // ===========================================================================
318 // Test case to make sure that the Object Name Service can rename objects in
319 // its most basic way, which is
320 //
321 // Rename (Ptr<Object> context, std::string oldname, std::string newname);
322 //
323 // All other rename functions will just translate into this form, so this is the
324 // most basic rename functionality.
325 // ===========================================================================
327 {
328 public:
330  virtual ~BasicRenameTestCase ();
331 
332 private:
333  virtual void DoRun (void);
334  virtual void DoTeardown (void);
335 };
336 
338  : TestCase ("Check low level Names::Rename functionality")
339 {
340 }
341 
343 {
344 }
345 
346 void
348 {
349  Names::Clear ();
350 }
351 
352 void
354 {
355  std::string found;
356 
357  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
358  Names::Add (Ptr<Object> (0, false), "Name", objectOne);
359 
360  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
361  Names::Add (objectOne, "Child", childOfObjectOne);
362 
363  found = Names::FindName (objectOne);
364  NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
365 
366  Names::Rename (Ptr<Object> (0, false), "Name", "New Name");
367 
368  found = Names::FindName (objectOne);
369  NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
370 
371  found = Names::FindName (childOfObjectOne);
372  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
373 
374  Names::Rename (objectOne, "Child", "New Child");
375 
376  found = Names::FindName (childOfObjectOne);
377  NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
378 }
379 
380 // ===========================================================================
381 // Test case to make sure that the Object Name Service can rename objects
382 // using a string context
383 //
384 // Rename (std::string context, std::string oldname, std::string newname);
385 // ===========================================================================
387 {
388 public:
390  virtual ~StringContextRenameTestCase ();
391 
392 private:
393  virtual void DoRun (void);
394  virtual void DoTeardown (void);
395 };
396 
398  : TestCase ("Check string context-based Names::Rename functionality")
399 {
400 }
401 
403 {
404 }
405 
406 void
408 {
409  Names::Clear ();
410 }
411 
412 void
414 {
415  std::string found;
416 
417  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
418  Names::Add ("/Names", "Name", objectOne);
419 
420  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
421  Names::Add ("/Names/Name", "Child", childOfObjectOne);
422 
423  found = Names::FindName (objectOne);
424  NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
425 
426  Names::Rename ("/Names", "Name", "New Name");
427 
428  found = Names::FindName (objectOne);
429  NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
430 
431  found = Names::FindName (childOfObjectOne);
432  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
433 
434  Names::Rename ("/Names/New Name", "Child", "New Child");
435 
436  found = Names::FindName (childOfObjectOne);
437  NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
438 }
439 
440 // ===========================================================================
441 // Test case to make sure that the Object Name Service can rename objects
442 // using a fully qualified path name
443 //
444 // Rename (std::string oldpath, std::string newname);
445 // ===========================================================================
447 {
448 public:
451 
452 private:
453  virtual void DoRun (void);
454  virtual void DoTeardown (void);
455 };
456 
458  : TestCase ("Check fully qualified path Names::Rename functionality")
459 {
460 }
461 
463 {
464 }
465 
466 void
468 {
469  Names::Clear ();
470 }
471 
472 void
474 {
475  std::string found;
476 
477  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
478  Names::Add ("/Names/Name", objectOne);
479 
480  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
481  Names::Add ("/Names/Name/Child", childOfObjectOne);
482 
483  found = Names::FindName (objectOne);
484  NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
485 
486  Names::Rename ("/Names/Name", "New Name");
487 
488  found = Names::FindName (objectOne);
489  NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
490 
491  found = Names::FindName (childOfObjectOne);
492  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
493 
494  Names::Rename ("/Names/New Name/Child", "New Child");
495 
496  found = Names::FindName (childOfObjectOne);
497  NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
498 }
499 
500 // ===========================================================================
501 // Test case to make sure that the Object Name Service can rename objects
502 // using a relaltive path name
503 //
504 // Rename (std::string oldpath, std::string newname);
505 // ===========================================================================
507 {
508 public:
510  virtual ~RelativeRenameTestCase ();
511 
512 private:
513  virtual void DoRun (void);
514  virtual void DoTeardown (void);
515 };
516 
518  : TestCase ("Check relative path Names::Rename functionality")
519 {
520 }
521 
523 {
524 }
525 
526 void
528 {
529  Names::Clear ();
530 }
531 
532 void
534 {
535  std::string found;
536 
537  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
538  Names::Add ("Name", objectOne);
539 
540  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
541  Names::Add ("Name/Child", childOfObjectOne);
542 
543  found = Names::FindName (objectOne);
544  NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
545 
546  Names::Rename ("Name", "New Name");
547 
548  found = Names::FindName (objectOne);
549  NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
550 
551  found = Names::FindName (childOfObjectOne);
552  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
553 
554  Names::Rename ("New Name/Child", "New Child");
555 
556  found = Names::FindName (childOfObjectOne);
557  NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
558 }
559 
560 // ===========================================================================
561 // Test case to make sure that the Object Name Service can look up an object
562 // and return its fully qualified path name
563 //
564 // FindPath (Ptr<Object> object);
565 // ===========================================================================
567 {
568 public:
569  FindPathTestCase ();
570  virtual ~FindPathTestCase ();
571 
572 private:
573  virtual void DoRun (void);
574  virtual void DoTeardown (void);
575 };
576 
578  : TestCase ("Check Names::FindPath functionality")
579 {
580 }
581 
583 {
584 }
585 
586 void
588 {
589  Names::Clear ();
590 }
591 
592 void
594 {
595  std::string found;
596 
597  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
598  Names::Add ("Name", objectOne);
599 
600  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
601  Names::Add ("/Names/Name/Child", childOfObjectOne);
602 
603  found = Names::FindPath (objectOne);
604  NS_TEST_ASSERT_MSG_EQ (found, "/Names/Name", "Could not Names::Add and Names::FindPath an Object");
605 
606  found = Names::FindPath (childOfObjectOne);
607  NS_TEST_ASSERT_MSG_EQ (found, "/Names/Name/Child", "Could not Names::Add and Names::FindPath a child Object");
608 
609  Ptr<TestObject> objectNotThere = CreateObject<TestObject> ();
610  found = Names::FindPath (objectNotThere);
611  NS_TEST_ASSERT_MSG_EQ (found, "", "Unexpectedly found a non-existent Object");
612 }
613 
614 // ===========================================================================
615 // Test case to make sure that the Object Name Service can find Objects using
616 // the lowest level find function, which is:
617 //
618 // Find (Ptr<Object> context, std::string name);
619 // ===========================================================================
621 {
622 public:
624  virtual ~BasicFindTestCase ();
625 
626 private:
627  virtual void DoRun (void);
628  virtual void DoTeardown (void);
629 };
630 
632  : TestCase ("Check low level Names::Find functionality")
633 {
634 }
635 
637 {
638 }
639 
640 void
642 {
643  Names::Clear ();
644 }
645 
646 void
648 {
649  Ptr<TestObject> found;
650 
651  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
652  Names::Add ("Name One", objectOne);
653 
654  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
655  Names::Add ("Name Two", objectTwo);
656 
657  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
658  Names::Add ("Name One/Child", childOfObjectOne);
659 
660  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
661  Names::Add ("Name Two/Child", childOfObjectTwo);
662 
663  found = Names::Find<TestObject> (Ptr<Object> (0, false), "Name One");
664  NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via object context");
665 
666  found = Names::Find<TestObject> (Ptr<Object> (0, false), "Name Two");
667  NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via object context");
668 
669  found = Names::Find<TestObject> (objectOne, "Child");
670  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via object context");
671 
672  found = Names::Find<TestObject> (objectTwo, "Child");
673  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via object context");
674 }
675 
676 // ===========================================================================
677 // Test case to make sure that the Object Name Service can find Objects using
678 // a string context-based find function, which is:
679 //
680 // Find (std::string context, std::string name);
681 // ===========================================================================
683 {
684 public:
686  virtual ~StringContextFindTestCase ();
687 
688 private:
689  virtual void DoRun (void);
690  virtual void DoTeardown (void);
691 };
692 
694  : TestCase ("Check string context-based Names::Find functionality")
695 {
696 }
697 
699 {
700 }
701 
702 void
704 {
705  Names::Clear ();
706 }
707 
708 void
710 {
711  Ptr<TestObject> found;
712 
713  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
714  Names::Add ("Name One", objectOne);
715 
716  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
717  Names::Add ("Name Two", objectTwo);
718 
719  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
720  Names::Add ("Name One/Child", childOfObjectOne);
721 
722  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
723  Names::Add ("Name Two/Child", childOfObjectTwo);
724 
725  found = Names::Find<TestObject> ("/Names", "Name One");
726  NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
727 
728  found = Names::Find<TestObject> ("/Names", "Name Two");
729  NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
730 
731  found = Names::Find<TestObject> ("/Names/Name One", "Child");
732  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
733 
734  found = Names::Find<TestObject> ("/Names/Name Two", "Child");
735  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
736 }
737 
738 // ===========================================================================
739 // Test case to make sure that the Object Name Service can find Objects using
740 // a fully qualified path name-based find function, which is:
741 //
742 // Find (std::string name);
743 // ===========================================================================
745 {
746 public:
748  virtual ~FullyQualifiedFindTestCase ();
749 
750 private:
751  virtual void DoRun (void);
752  virtual void DoTeardown (void);
753 };
754 
756  : TestCase ("Check fully qualified path Names::Find functionality")
757 {
758 }
759 
761 {
762 }
763 
764 void
766 {
767  Names::Clear ();
768 }
769 
770 void
772 {
773  Ptr<TestObject> found;
774 
775  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
776  Names::Add ("/Names/Name One", objectOne);
777 
778  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
779  Names::Add ("/Names/Name Two", objectTwo);
780 
781  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
782  Names::Add ("/Names/Name One/Child", childOfObjectOne);
783 
784  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
785  Names::Add ("/Names/Name Two/Child", childOfObjectTwo);
786 
787  found = Names::Find<TestObject> ("/Names/Name One");
788  NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
789 
790  found = Names::Find<TestObject> ("/Names/Name Two");
791  NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
792 
793  found = Names::Find<TestObject> ("/Names/Name One/Child");
794  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
795 
796  found = Names::Find<TestObject> ("/Names/Name Two/Child");
797  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
798 }
799 
800 // ===========================================================================
801 // Test case to make sure that the Object Name Service can find Objects using
802 // a relative path name-based find function, which is:
803 //
804 // Find (std::string name);
805 // ===========================================================================
807 {
808 public:
810  virtual ~RelativeFindTestCase ();
811 
812 private:
813  virtual void DoRun (void);
814  virtual void DoTeardown (void);
815 };
816 
818  : TestCase ("Check relative path Names::Find functionality")
819 {
820 }
821 
823 {
824 }
825 
826 void
828 {
829  Names::Clear ();
830 }
831 
832 void
834 {
835  Ptr<TestObject> found;
836 
837  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
838  Names::Add ("Name One", objectOne);
839 
840  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
841  Names::Add ("Name Two", objectTwo);
842 
843  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
844  Names::Add ("Name One/Child", childOfObjectOne);
845 
846  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
847  Names::Add ("Name Two/Child", childOfObjectTwo);
848 
849  found = Names::Find<TestObject> ("Name One");
850  NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
851 
852  found = Names::Find<TestObject> ("Name Two");
853  NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
854 
855  found = Names::Find<TestObject> ("Name One/Child");
856  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
857 
858  found = Names::Find<TestObject> ("Name Two/Child");
859  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
860 }
861 
862 // ===========================================================================
863 // Test case to make sure that the Object Name Service can find Objects using
864 // a second type.
865 // ===========================================================================
867 {
868 public:
870  virtual ~AlternateFindTestCase ();
871 
872 private:
873  virtual void DoRun (void);
874  virtual void DoTeardown (void);
875 };
876 
878  : TestCase ("Check GetObject operation in Names::Find")
879 {
880 }
881 
883 {
884 }
885 
886 void
888 {
889  Names::Clear ();
890 }
891 
892 void
894 {
895  Ptr<TestObject> testObject = CreateObject<TestObject> ();
896  Names::Add ("Test Object", testObject);
897 
898  Ptr<AlternateTestObject> alternateTestObject = CreateObject<AlternateTestObject> ();
899  Names::Add ("Alternate Test Object", alternateTestObject);
900 
901  Ptr<TestObject> foundTestObject;
902  Ptr<AlternateTestObject> foundAlternateTestObject;
903 
904  foundTestObject = Names::Find<TestObject> ("Test Object");
905  NS_TEST_ASSERT_MSG_EQ (foundTestObject, testObject,
906  "Could not find a previously named TestObject via GetObject");
907 
908  foundAlternateTestObject = Names::Find<AlternateTestObject> ("Alternate Test Object");
909  NS_TEST_ASSERT_MSG_EQ (foundAlternateTestObject, alternateTestObject,
910  "Could not find a previously named AlternateTestObject via GetObject");
911 
912 
913  foundAlternateTestObject = Names::Find<AlternateTestObject> ("Test Object");
914  NS_TEST_ASSERT_MSG_EQ (foundAlternateTestObject, 0,
915  "Unexpectedly able to GetObject<AlternateTestObject> on a TestObject");
916 
917  foundTestObject = Names::Find<TestObject> ("Alternate Test Object");
918  NS_TEST_ASSERT_MSG_EQ (foundTestObject, 0,
919  "Unexpectedly able to GetObject<TestObject> on an AlternateTestObject");
920 }
921 
922 class NamesTestSuite : public TestSuite
923 {
924 public:
925  NamesTestSuite ();
926 };
927 
929  : TestSuite ("object-name-service", UNIT)
930 {
931  AddTestCase (new BasicAddTestCase, TestCase::QUICK);
932  AddTestCase (new StringContextAddTestCase, TestCase::QUICK);
933  AddTestCase (new FullyQualifiedAddTestCase, TestCase::QUICK);
934  AddTestCase (new RelativeAddTestCase, TestCase::QUICK);
935  AddTestCase (new BasicRenameTestCase, TestCase::QUICK);
936  AddTestCase (new StringContextRenameTestCase, TestCase::QUICK);
937  AddTestCase (new FullyQualifiedRenameTestCase, TestCase::QUICK);
938  AddTestCase (new RelativeRenameTestCase, TestCase::QUICK);
939  AddTestCase (new FindPathTestCase, TestCase::QUICK);
940  AddTestCase (new BasicFindTestCase, TestCase::QUICK);
941  AddTestCase (new StringContextFindTestCase, TestCase::QUICK);
942  AddTestCase (new FullyQualifiedFindTestCase, TestCase::QUICK);
943  AddTestCase (new RelativeFindTestCase, TestCase::QUICK);
944  AddTestCase (new AlternateFindTestCase, TestCase::QUICK);
945 }
946