A Discrete-Event Network Simulator
API
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:
33  static TypeId GetTypeId (void)
34  {
35  static TypeId tid = TypeId ("TestObject")
36  .SetParent<Object> ()
37  .SetGroupName ("Core")
38  .HideFromDocumentation ()
39  .AddConstructor<TestObject> ();
40  return tid;
41  }
42  TestObject () {}
43  virtual void Dispose (void) {}
44 };
45 
47 {
48 public:
53  static TypeId GetTypeId (void)
54  {
55  static TypeId tid = TypeId ("AlternateTestObject")
56  .SetParent<Object> ()
57  .SetGroupName ("Core")
58  .HideFromDocumentation ()
59  .AddConstructor<AlternateTestObject> ();
60  return tid;
61  }
63  virtual void Dispose (void) {}
64 };
65 
66 // ===========================================================================
67 // Test case to make sure that the Object Name Service can do its most basic
68 // job and add associations between Objects using the lowest level add
69 // function, which is:
70 //
71 // Add (Ptr<Object> context, std::string name, Ptr<Object> object);
72 //
73 // All other add functions will just translate into this form, so this is the
74 // most basic Add functionality.
75 // ===========================================================================
76 class BasicAddTestCase : public TestCase
77 {
78 public:
80  virtual ~BasicAddTestCase ();
81 
82 private:
83  virtual void DoRun (void);
84  virtual void DoTeardown (void);
85 };
86 
88  : TestCase ("Check low level Names::Add and Names::FindName functionality")
89 {
90 }
91 
93 {
94 }
95 
96 void
98 {
99  Names::Clear ();
100 }
101 
102 void
104 {
105  std::string found;
106 
107  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
108  Names::Add (Ptr<Object> (0, false), "Name One", objectOne);
109 
110  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
111  Names::Add (Ptr<Object> (0, false), "Name Two", objectTwo);
112 
113  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
114  Names::Add (objectOne, "Child", childOfObjectOne);
115 
116  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
117  Names::Add (objectTwo, "Child", childOfObjectTwo);
118 
119  found = Names::FindName (objectOne);
120  NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
121 
122  found = Names::FindName (objectTwo);
123  NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
124 
125  found = Names::FindName (childOfObjectOne);
126  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
127 
128  found = Names::FindName (childOfObjectTwo);
129  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
130 }
131 
132 // ===========================================================================
133 // Test case to make sure that the Object Name Service can correctly use a
134 // string context in the most basic ways
135 //
136 // Add (std::string context, std::string name, Ptr<Object> object);
137 //
138 // High level path-based functions will translate into this form, so this is
139 // the second most basic Add functionality.
140 // ===========================================================================
142 {
143 public:
145  virtual ~StringContextAddTestCase ();
146 
147 private:
148  virtual void DoRun (void);
149  virtual void DoTeardown (void);
150 };
151 
153  : TestCase ("Check string context Names::Add and Names::FindName functionality")
154 
155 {
156 }
157 
159 {
160 }
161 
162 void
164 {
165  Names::Clear ();
166 }
167 
168 void
170 {
171  std::string found;
172 
173  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
174  Names::Add ("/Names", "Name One", objectOne);
175 
176  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
177  Names::Add ("/Names", "Name Two", objectTwo);
178 
179  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
180  Names::Add ("/Names/Name One", "Child", childOfObjectOne);
181 
182  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
183  Names::Add ("/Names/Name Two", "Child", childOfObjectTwo);
184 
185  found = Names::FindName (objectOne);
186  NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
187 
188  found = Names::FindName (objectTwo);
189  NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
190 
191  found = Names::FindName (childOfObjectOne);
192  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
193 
194  found = Names::FindName (childOfObjectTwo);
195  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
196 }
197 
198 // ===========================================================================
199 // Test case to make sure that the Object Name Service can correctly use a
200 // fully qualified path to add assocations
201 //
202 // Add (std::string name, Ptr<Object> object);
203 // ===========================================================================
205 {
206 public:
208  virtual ~FullyQualifiedAddTestCase ();
209 
210 private:
211  virtual void DoRun (void);
212  virtual void DoTeardown (void);
213 };
214 
216  : TestCase ("Check fully qualified path Names::Add and Names::FindName functionality")
217 
218 {
219 }
220 
222 {
223 }
224 
225 void
227 {
228  Names::Clear ();
229 }
230 
231 void
233 {
234  std::string found;
235 
236  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
237  Names::Add ("/Names/Name One", objectOne);
238 
239  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
240  Names::Add ("/Names/Name Two", objectTwo);
241 
242  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
243  Names::Add ("/Names/Name One/Child", childOfObjectOne);
244 
245  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
246  Names::Add ("/Names/Name Two/Child", childOfObjectTwo);
247 
248  found = Names::FindName (objectOne);
249  NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
250 
251  found = Names::FindName (objectTwo);
252  NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
253 
254  found = Names::FindName (childOfObjectOne);
255  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
256 
257  found = Names::FindName (childOfObjectTwo);
258  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
259 }
260 
261 // ===========================================================================
262 // Test case to make sure that the Object Name Service can correctly use a
263 // relative path to add assocations. This functionality is provided as a
264 // convenience so clients don't always have to provide the name service
265 // namespace name in all of their strings.
266 //
267 //
268 // Add (std::string name, Ptr<Object> object);
269 // ===========================================================================
271 {
272 public:
274  virtual ~RelativeAddTestCase ();
275 
276 private:
277  virtual void DoRun (void);
278  virtual void DoTeardown (void);
279 };
280 
282  : TestCase ("Check relative path Names::Add and Names::FindName functionality")
283 
284 {
285 }
286 
288 {
289 }
290 
291 void
293 {
294  Names::Clear ();
295 }
296 
297 void
299 {
300  std::string found;
301 
302  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
303  Names::Add ("Name One", objectOne);
304 
305  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
306  Names::Add ("Name Two", objectTwo);
307 
308  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
309  Names::Add ("Name One/Child", childOfObjectOne);
310 
311  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
312  Names::Add ("Name Two/Child", childOfObjectTwo);
313 
314  found = Names::FindName (objectOne);
315  NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
316 
317  found = Names::FindName (objectTwo);
318  NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
319 
320  found = Names::FindName (childOfObjectOne);
321  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
322 
323  found = Names::FindName (childOfObjectTwo);
324  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
325 }
326 
327 // ===========================================================================
328 // Test case to make sure that the Object Name Service can rename objects in
329 // its most basic way, which is
330 //
331 // Rename (Ptr<Object> context, std::string oldname, std::string newname);
332 //
333 // All other rename functions will just translate into this form, so this is the
334 // most basic rename functionality.
335 // ===========================================================================
337 {
338 public:
340  virtual ~BasicRenameTestCase ();
341 
342 private:
343  virtual void DoRun (void);
344  virtual void DoTeardown (void);
345 };
346 
348  : TestCase ("Check low level Names::Rename functionality")
349 {
350 }
351 
353 {
354 }
355 
356 void
358 {
359  Names::Clear ();
360 }
361 
362 void
364 {
365  std::string found;
366 
367  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
368  Names::Add (Ptr<Object> (0, false), "Name", objectOne);
369 
370  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
371  Names::Add (objectOne, "Child", childOfObjectOne);
372 
373  found = Names::FindName (objectOne);
374  NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
375 
376  Names::Rename (Ptr<Object> (0, false), "Name", "New Name");
377 
378  found = Names::FindName (objectOne);
379  NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
380 
381  found = Names::FindName (childOfObjectOne);
382  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
383 
384  Names::Rename (objectOne, "Child", "New Child");
385 
386  found = Names::FindName (childOfObjectOne);
387  NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
388 }
389 
390 // ===========================================================================
391 // Test case to make sure that the Object Name Service can rename objects
392 // using a string context
393 //
394 // Rename (std::string context, std::string oldname, std::string newname);
395 // ===========================================================================
397 {
398 public:
400  virtual ~StringContextRenameTestCase ();
401 
402 private:
403  virtual void DoRun (void);
404  virtual void DoTeardown (void);
405 };
406 
408  : TestCase ("Check string context-based Names::Rename functionality")
409 {
410 }
411 
413 {
414 }
415 
416 void
418 {
419  Names::Clear ();
420 }
421 
422 void
424 {
425  std::string found;
426 
427  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
428  Names::Add ("/Names", "Name", objectOne);
429 
430  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
431  Names::Add ("/Names/Name", "Child", childOfObjectOne);
432 
433  found = Names::FindName (objectOne);
434  NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
435 
436  Names::Rename ("/Names", "Name", "New Name");
437 
438  found = Names::FindName (objectOne);
439  NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
440 
441  found = Names::FindName (childOfObjectOne);
442  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
443 
444  Names::Rename ("/Names/New Name", "Child", "New Child");
445 
446  found = Names::FindName (childOfObjectOne);
447  NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
448 }
449 
450 // ===========================================================================
451 // Test case to make sure that the Object Name Service can rename objects
452 // using a fully qualified path name
453 //
454 // Rename (std::string oldpath, std::string newname);
455 // ===========================================================================
457 {
458 public:
461 
462 private:
463  virtual void DoRun (void);
464  virtual void DoTeardown (void);
465 };
466 
468  : TestCase ("Check fully qualified path Names::Rename functionality")
469 {
470 }
471 
473 {
474 }
475 
476 void
478 {
479  Names::Clear ();
480 }
481 
482 void
484 {
485  std::string found;
486 
487  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
488  Names::Add ("/Names/Name", objectOne);
489 
490  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
491  Names::Add ("/Names/Name/Child", childOfObjectOne);
492 
493  found = Names::FindName (objectOne);
494  NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
495 
496  Names::Rename ("/Names/Name", "New Name");
497 
498  found = Names::FindName (objectOne);
499  NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
500 
501  found = Names::FindName (childOfObjectOne);
502  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
503 
504  Names::Rename ("/Names/New Name/Child", "New Child");
505 
506  found = Names::FindName (childOfObjectOne);
507  NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
508 }
509 
510 // ===========================================================================
511 // Test case to make sure that the Object Name Service can rename objects
512 // using a relaltive path name
513 //
514 // Rename (std::string oldpath, std::string newname);
515 // ===========================================================================
517 {
518 public:
520  virtual ~RelativeRenameTestCase ();
521 
522 private:
523  virtual void DoRun (void);
524  virtual void DoTeardown (void);
525 };
526 
528  : TestCase ("Check relative path Names::Rename functionality")
529 {
530 }
531 
533 {
534 }
535 
536 void
538 {
539  Names::Clear ();
540 }
541 
542 void
544 {
545  std::string found;
546 
547  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
548  Names::Add ("Name", objectOne);
549 
550  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
551  Names::Add ("Name/Child", childOfObjectOne);
552 
553  found = Names::FindName (objectOne);
554  NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
555 
556  Names::Rename ("Name", "New Name");
557 
558  found = Names::FindName (objectOne);
559  NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
560 
561  found = Names::FindName (childOfObjectOne);
562  NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
563 
564  Names::Rename ("New Name/Child", "New Child");
565 
566  found = Names::FindName (childOfObjectOne);
567  NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
568 }
569 
570 // ===========================================================================
571 // Test case to make sure that the Object Name Service can look up an object
572 // and return its fully qualified path name
573 //
574 // FindPath (Ptr<Object> object);
575 // ===========================================================================
577 {
578 public:
579  FindPathTestCase ();
580  virtual ~FindPathTestCase ();
581 
582 private:
583  virtual void DoRun (void);
584  virtual void DoTeardown (void);
585 };
586 
588  : TestCase ("Check Names::FindPath functionality")
589 {
590 }
591 
593 {
594 }
595 
596 void
598 {
599  Names::Clear ();
600 }
601 
602 void
604 {
605  std::string found;
606 
607  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
608  Names::Add ("Name", objectOne);
609 
610  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
611  Names::Add ("/Names/Name/Child", childOfObjectOne);
612 
613  found = Names::FindPath (objectOne);
614  NS_TEST_ASSERT_MSG_EQ (found, "/Names/Name", "Could not Names::Add and Names::FindPath an Object");
615 
616  found = Names::FindPath (childOfObjectOne);
617  NS_TEST_ASSERT_MSG_EQ (found, "/Names/Name/Child", "Could not Names::Add and Names::FindPath a child Object");
618 
619  Ptr<TestObject> objectNotThere = CreateObject<TestObject> ();
620  found = Names::FindPath (objectNotThere);
621  NS_TEST_ASSERT_MSG_EQ (found, "", "Unexpectedly found a non-existent Object");
622 }
623 
624 // ===========================================================================
625 // Test case to make sure that the Object Name Service can find Objects using
626 // the lowest level find function, which is:
627 //
628 // Find (Ptr<Object> context, std::string name);
629 // ===========================================================================
631 {
632 public:
634  virtual ~BasicFindTestCase ();
635 
636 private:
637  virtual void DoRun (void);
638  virtual void DoTeardown (void);
639 };
640 
642  : TestCase ("Check low level Names::Find functionality")
643 {
644 }
645 
647 {
648 }
649 
650 void
652 {
653  Names::Clear ();
654 }
655 
656 void
658 {
659  Ptr<TestObject> found;
660 
661  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
662  Names::Add ("Name One", objectOne);
663 
664  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
665  Names::Add ("Name Two", objectTwo);
666 
667  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
668  Names::Add ("Name One/Child", childOfObjectOne);
669 
670  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
671  Names::Add ("Name Two/Child", childOfObjectTwo);
672 
673  found = Names::Find<TestObject> (Ptr<Object> (0, false), "Name One");
674  NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via object context");
675 
676  found = Names::Find<TestObject> (Ptr<Object> (0, false), "Name Two");
677  NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via object context");
678 
679  found = Names::Find<TestObject> (objectOne, "Child");
680  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via object context");
681 
682  found = Names::Find<TestObject> (objectTwo, "Child");
683  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via object context");
684 }
685 
686 // ===========================================================================
687 // Test case to make sure that the Object Name Service can find Objects using
688 // a string context-based find function, which is:
689 //
690 // Find (std::string context, std::string name);
691 // ===========================================================================
693 {
694 public:
696  virtual ~StringContextFindTestCase ();
697 
698 private:
699  virtual void DoRun (void);
700  virtual void DoTeardown (void);
701 };
702 
704  : TestCase ("Check string context-based Names::Find functionality")
705 {
706 }
707 
709 {
710 }
711 
712 void
714 {
715  Names::Clear ();
716 }
717 
718 void
720 {
721  Ptr<TestObject> found;
722 
723  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
724  Names::Add ("Name One", objectOne);
725 
726  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
727  Names::Add ("Name Two", objectTwo);
728 
729  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
730  Names::Add ("Name One/Child", childOfObjectOne);
731 
732  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
733  Names::Add ("Name Two/Child", childOfObjectTwo);
734 
735  found = Names::Find<TestObject> ("/Names", "Name One");
736  NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
737 
738  found = Names::Find<TestObject> ("/Names", "Name Two");
739  NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
740 
741  found = Names::Find<TestObject> ("/Names/Name One", "Child");
742  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
743 
744  found = Names::Find<TestObject> ("/Names/Name Two", "Child");
745  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
746 }
747 
748 // ===========================================================================
749 // Test case to make sure that the Object Name Service can find Objects using
750 // a fully qualified path name-based find function, which is:
751 //
752 // Find (std::string name);
753 // ===========================================================================
755 {
756 public:
758  virtual ~FullyQualifiedFindTestCase ();
759 
760 private:
761  virtual void DoRun (void);
762  virtual void DoTeardown (void);
763 };
764 
766  : TestCase ("Check fully qualified path Names::Find functionality")
767 {
768 }
769 
771 {
772 }
773 
774 void
776 {
777  Names::Clear ();
778 }
779 
780 void
782 {
783  Ptr<TestObject> found;
784 
785  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
786  Names::Add ("/Names/Name One", objectOne);
787 
788  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
789  Names::Add ("/Names/Name Two", objectTwo);
790 
791  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
792  Names::Add ("/Names/Name One/Child", childOfObjectOne);
793 
794  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
795  Names::Add ("/Names/Name Two/Child", childOfObjectTwo);
796 
797  found = Names::Find<TestObject> ("/Names/Name One");
798  NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
799 
800  found = Names::Find<TestObject> ("/Names/Name Two");
801  NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
802 
803  found = Names::Find<TestObject> ("/Names/Name One/Child");
804  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
805 
806  found = Names::Find<TestObject> ("/Names/Name Two/Child");
807  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
808 }
809 
810 // ===========================================================================
811 // Test case to make sure that the Object Name Service can find Objects using
812 // a relative path name-based find function, which is:
813 //
814 // Find (std::string name);
815 // ===========================================================================
817 {
818 public:
820  virtual ~RelativeFindTestCase ();
821 
822 private:
823  virtual void DoRun (void);
824  virtual void DoTeardown (void);
825 };
826 
828  : TestCase ("Check relative path Names::Find functionality")
829 {
830 }
831 
833 {
834 }
835 
836 void
838 {
839  Names::Clear ();
840 }
841 
842 void
844 {
845  Ptr<TestObject> found;
846 
847  Ptr<TestObject> objectOne = CreateObject<TestObject> ();
848  Names::Add ("Name One", objectOne);
849 
850  Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
851  Names::Add ("Name Two", objectTwo);
852 
853  Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
854  Names::Add ("Name One/Child", childOfObjectOne);
855 
856  Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
857  Names::Add ("Name Two/Child", childOfObjectTwo);
858 
859  found = Names::Find<TestObject> ("Name One");
860  NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
861 
862  found = Names::Find<TestObject> ("Name Two");
863  NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
864 
865  found = Names::Find<TestObject> ("Name One/Child");
866  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
867 
868  found = Names::Find<TestObject> ("Name Two/Child");
869  NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
870 }
871 
872 // ===========================================================================
873 // Test case to make sure that the Object Name Service can find Objects using
874 // a second type.
875 // ===========================================================================
877 {
878 public:
880  virtual ~AlternateFindTestCase ();
881 
882 private:
883  virtual void DoRun (void);
884  virtual void DoTeardown (void);
885 };
886 
888  : TestCase ("Check GetObject operation in Names::Find")
889 {
890 }
891 
893 {
894 }
895 
896 void
898 {
899  Names::Clear ();
900 }
901 
902 void
904 {
905  Ptr<TestObject> testObject = CreateObject<TestObject> ();
906  Names::Add ("Test Object", testObject);
907 
908  Ptr<AlternateTestObject> alternateTestObject = CreateObject<AlternateTestObject> ();
909  Names::Add ("Alternate Test Object", alternateTestObject);
910 
911  Ptr<TestObject> foundTestObject;
912  Ptr<AlternateTestObject> foundAlternateTestObject;
913 
914  foundTestObject = Names::Find<TestObject> ("Test Object");
915  NS_TEST_ASSERT_MSG_EQ (foundTestObject, testObject,
916  "Could not find a previously named TestObject via GetObject");
917 
918  foundAlternateTestObject = Names::Find<AlternateTestObject> ("Alternate Test Object");
919  NS_TEST_ASSERT_MSG_EQ (foundAlternateTestObject, alternateTestObject,
920  "Could not find a previously named AlternateTestObject via GetObject");
921 
922 
923  foundAlternateTestObject = Names::Find<AlternateTestObject> ("Test Object");
924  NS_TEST_ASSERT_MSG_EQ (foundAlternateTestObject, 0,
925  "Unexpectedly able to GetObject<AlternateTestObject> on a TestObject");
926 
927  foundTestObject = Names::Find<TestObject> ("Alternate Test Object");
928  NS_TEST_ASSERT_MSG_EQ (foundTestObject, 0,
929  "Unexpectedly able to GetObject<TestObject> on an AlternateTestObject");
930 }
931 
932 class NamesTestSuite : public TestSuite
933 {
934 public:
935  NamesTestSuite ();
936 };
937 
939  : TestSuite ("object-name-service", UNIT)
940 {
941  AddTestCase (new BasicAddTestCase, TestCase::QUICK);
942  AddTestCase (new StringContextAddTestCase, TestCase::QUICK);
943  AddTestCase (new FullyQualifiedAddTestCase, TestCase::QUICK);
944  AddTestCase (new RelativeAddTestCase, TestCase::QUICK);
945  AddTestCase (new BasicRenameTestCase, TestCase::QUICK);
946  AddTestCase (new StringContextRenameTestCase, TestCase::QUICK);
947  AddTestCase (new FullyQualifiedRenameTestCase, TestCase::QUICK);
948  AddTestCase (new RelativeRenameTestCase, TestCase::QUICK);
949  AddTestCase (new FindPathTestCase, TestCase::QUICK);
950  AddTestCase (new BasicFindTestCase, TestCase::QUICK);
951  AddTestCase (new StringContextFindTestCase, TestCase::QUICK);
952  AddTestCase (new FullyQualifiedFindTestCase, TestCase::QUICK);
953  AddTestCase (new RelativeFindTestCase, TestCase::QUICK);
954  AddTestCase (new AlternateFindTestCase, TestCase::QUICK);
955 }
956 
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
static TypeId GetTypeId(void)
Register this type.
A suite of tests to run.
Definition: test.h:1333
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
encapsulates test code
Definition: test.h:1147
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~BasicFindTestCase()
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:161
static NamesTestSuite namesTestSuite
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void Dispose(void)
virtual ~FindPathTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void Dispose(void)
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
static TypeId GetTypeId(void)
Register this type.
virtual ~BasicAddTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual void DoRun(void)
Implementation to actually run this TestCase.
a unique identifier for an interface.
Definition: type-id.h:58
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904