A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
names-test-suite.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 */
15
16#include "ns3/names.h"
17#include "ns3/test.h"
18
19/**
20 * \file
21 * \ingroup core-tests
22 * \ingroup config
23 * \ingroup names-tests
24 * Object Names test suite.
25 */
26
27/**
28 * \ingroup core-tests
29 * \defgroup names-tests Object Names test suite
30 */
31
32namespace ns3
33{
34
35namespace tests
36{
37
38/**
39 * \ingroup names-tests
40 * Simple test object to exercise the Name service.
41 */
42class TestObject : public Object
43{
44 public:
45 /**
46 * Register this type.
47 * \return The TypeId.
48 */
50 {
51 static TypeId tid = TypeId("TestObject")
53 .SetGroupName("Core")
54 .HideFromDocumentation()
55 .AddConstructor<TestObject>();
56 return tid;
57 }
58
59 /** Constructor. */
61 {
62 }
63};
64
65/**
66 * \ingroup names-tests
67 * Alternate test object for the Name service.
68 */
70{
71 public:
72 /**
73 * Register this type.
74 * \return The TypeId.
75 */
77 {
78 static TypeId tid = TypeId("AlternateTestObject")
80 .SetGroupName("Core")
81 .HideFromDocumentation()
82 .AddConstructor<AlternateTestObject>();
83 return tid;
84 }
85
86 /** Constructor. */
88 {
89 }
90};
91
92/**
93 * \ingroup names-tests
94 * Test the Object Name Service can do its most basic job.
95 *
96 * Add associations between Objects using the lowest level add
97 * function, which is:
98 *
99 * Add (Ptr<Object> context, std::string name, Ptr<Object> object);
100 *
101 * All other add functions will just translate into this form, so this is the
102 * most basic Add functionality.
103 */
105{
106 public:
107 /** Constructor. */
109 /** Destructor. */
110 ~BasicAddTestCase() override;
111
112 private:
113 void DoRun() override;
114 void DoTeardown() override;
115};
116
118 : TestCase("Check low level Names::Add and Names::FindName functionality")
119{
120}
121
123{
124}
125
126void
128{
129 Names::Clear();
130}
131
132void
134{
135 std::string found;
136
137 Ptr<TestObject> objectOne = CreateObject<TestObject>();
138 Names::Add(Ptr<Object>(nullptr, false), "Name One", objectOne);
139
140 Ptr<TestObject> objectTwo = CreateObject<TestObject>();
141 Names::Add(Ptr<Object>(nullptr, false), "Name Two", objectTwo);
142
143 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
144 Names::Add(objectOne, "Child", childOfObjectOne);
145
146 Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject>();
147 Names::Add(objectTwo, "Child", childOfObjectTwo);
148
149 found = Names::FindName(objectOne);
150 NS_TEST_ASSERT_MSG_EQ(found, "Name One", "Could not Names::Add and Names::FindName an Object");
151
152 found = Names::FindName(objectTwo);
154 "Name Two",
155 "Could not Names::Add and Names::FindName a second Object");
156
157 found = Names::FindName(childOfObjectOne);
159 "Child",
160 "Could not Names::Add and Names::FindName a child Object");
161
162 found = Names::FindName(childOfObjectTwo);
164 "Child",
165 "Could not Names::Add and Names::FindName a child Object");
166}
167
168/**
169 * \ingroup names-tests
170 * Test the Object Name Service can correctly use a string context.
171 *
172 * Add (std::string context, std::string name, Ptr<Object> object);
173 *
174 * High level path-based functions will translate into this form, so this is
175 * the second most basic Add functionality.
176 */
178{
179 public:
180 /** Constructor. */
182 /** Destructor. */
183 ~StringContextAddTestCase() override;
184
185 private:
186 void DoRun() override;
187 void DoTeardown() override;
188};
189
191 : TestCase("Check string context Names::Add and Names::FindName functionality")
192
193{
194}
195
197{
198}
199
200void
202{
203 Names::Clear();
204}
205
206void
208{
209 std::string found;
210
211 Ptr<TestObject> objectOne = CreateObject<TestObject>();
212 Names::Add("/Names", "Name One", objectOne);
213
214 Ptr<TestObject> objectTwo = CreateObject<TestObject>();
215 Names::Add("/Names", "Name Two", objectTwo);
216
217 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
218 Names::Add("/Names/Name One", "Child", childOfObjectOne);
219
220 Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject>();
221 Names::Add("/Names/Name Two", "Child", childOfObjectTwo);
222
223 found = Names::FindName(objectOne);
224 NS_TEST_ASSERT_MSG_EQ(found, "Name One", "Could not Names::Add and Names::FindName an Object");
225
226 found = Names::FindName(objectTwo);
228 "Name Two",
229 "Could not Names::Add and Names::FindName a second Object");
230
231 found = Names::FindName(childOfObjectOne);
233 "Child",
234 "Could not Names::Add and Names::FindName a child Object");
235
236 found = Names::FindName(childOfObjectTwo);
238 "Child",
239 "Could not Names::Add and Names::FindName a child Object");
240}
241
242/**
243 * \ingroup names-tests
244 * Test the Object Name Service can correctly use a
245 * fully qualified path to add associations.
246 *
247 * Add (std::string name, Ptr<Object> object);
248 *
249 */
251{
252 public:
253 /** Constructor. */
255 /** Destructor. */
257
258 private:
259 void DoRun() override;
260 void DoTeardown() override;
261};
262
264 : TestCase("Check fully qualified path Names::Add and Names::FindName functionality")
265
266{
267}
268
270{
271}
272
273void
275{
276 Names::Clear();
277}
278
279void
281{
282 std::string found;
283
284 Ptr<TestObject> objectOne = CreateObject<TestObject>();
285 Names::Add("/Names/Name One", objectOne);
286
287 Ptr<TestObject> objectTwo = CreateObject<TestObject>();
288 Names::Add("/Names/Name Two", objectTwo);
289
290 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
291 Names::Add("/Names/Name One/Child", childOfObjectOne);
292
293 Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject>();
294 Names::Add("/Names/Name Two/Child", childOfObjectTwo);
295
296 found = Names::FindName(objectOne);
297 NS_TEST_ASSERT_MSG_EQ(found, "Name One", "Could not Names::Add and Names::FindName an Object");
298
299 found = Names::FindName(objectTwo);
301 "Name Two",
302 "Could not Names::Add and Names::FindName a second Object");
303
304 found = Names::FindName(childOfObjectOne);
306 "Child",
307 "Could not Names::Add and Names::FindName a child Object");
308
309 found = Names::FindName(childOfObjectTwo);
311 "Child",
312 "Could not Names::Add and Names::FindName a child Object");
313}
314
315/**
316 * \ingroup names-tests
317 * Test the Object Name Service can correctly use a
318 * relative path to add associations.
319 *
320 * This functionality is provided as a convenience so clients
321 * don't always have to provide the name service namespace name
322 * in all of their strings.
323 *
324 * Add (std::string name, Ptr<Object> object);
325 *
326 */
328{
329 public:
330 /** Constructor. */
332 /** Destructor. */
333 ~RelativeAddTestCase() override;
334
335 private:
336 void DoRun() override;
337 void DoTeardown() override;
338};
339
341 : TestCase("Check relative path Names::Add and Names::FindName functionality")
342
343{
344}
345
347{
348}
349
350void
352{
353 Names::Clear();
354}
355
356void
358{
359 std::string found;
360
361 Ptr<TestObject> objectOne = CreateObject<TestObject>();
362 Names::Add("Name One", objectOne);
363
364 Ptr<TestObject> objectTwo = CreateObject<TestObject>();
365 Names::Add("Name Two", objectTwo);
366
367 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
368 Names::Add("Name One/Child", childOfObjectOne);
369
370 Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject>();
371 Names::Add("Name Two/Child", childOfObjectTwo);
372
373 found = Names::FindName(objectOne);
374 NS_TEST_ASSERT_MSG_EQ(found, "Name One", "Could not Names::Add and Names::FindName an Object");
375
376 found = Names::FindName(objectTwo);
378 "Name Two",
379 "Could not Names::Add and Names::FindName a second Object");
380
381 found = Names::FindName(childOfObjectOne);
383 "Child",
384 "Could not Names::Add and Names::FindName a child Object");
385
386 found = Names::FindName(childOfObjectTwo);
388 "Child",
389 "Could not Names::Add and Names::FindName a child Object");
390}
391
392/**
393 * \ingroup names-tests
394 * Test the Object Name Service can rename objects.
395 *
396 * Rename (Ptr<Object> context, std::string oldname, std::string newname);
397 *
398 * All other rename functions will just translate into this form, so this is the
399 * most basic rename functionality.
400 */
402{
403 public:
404 /** Constructor. */
406 /** Destructor. */
407 ~BasicRenameTestCase() override;
408
409 private:
410 void DoRun() override;
411 void DoTeardown() override;
412};
413
415 : TestCase("Check low level Names::Rename functionality")
416{
417}
418
420{
421}
422
423void
425{
426 Names::Clear();
427}
428
429void
431{
432 std::string found;
433
434 Ptr<TestObject> objectOne = CreateObject<TestObject>();
435 Names::Add(Ptr<Object>(nullptr, false), "Name", objectOne);
436
437 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
438 Names::Add(objectOne, "Child", childOfObjectOne);
439
440 found = Names::FindName(objectOne);
441 NS_TEST_ASSERT_MSG_EQ(found, "Name", "Could not Names::Add and Names::FindName an Object");
442
443 Names::Rename(Ptr<Object>(nullptr, false), "Name", "New Name");
444
445 found = Names::FindName(objectOne);
446 NS_TEST_ASSERT_MSG_EQ(found, "New Name", "Could not Names::Rename an Object");
447
448 found = Names::FindName(childOfObjectOne);
450 "Child",
451 "Could not Names::Add and Names::FindName a child Object");
452
453 Names::Rename(objectOne, "Child", "New Child");
454
455 found = Names::FindName(childOfObjectOne);
456 NS_TEST_ASSERT_MSG_EQ(found, "New Child", "Could not Names::Rename a child Object");
457}
458
459/**
460 * \ingroup names-tests
461 * Test the Object Name Service can rename objects
462 * using a string context.
463 *
464 * Rename (std::string context, std::string oldname, std::string newname);
465 *
466 */
468{
469 public:
470 /** Constructor. */
472 /** Destructor. */
474
475 private:
476 void DoRun() override;
477 void DoTeardown() override;
478};
479
481 : TestCase("Check string context-based Names::Rename functionality")
482{
483}
484
486{
487}
488
489void
491{
492 Names::Clear();
493}
494
495void
497{
498 std::string found;
499
500 Ptr<TestObject> objectOne = CreateObject<TestObject>();
501 Names::Add("/Names", "Name", objectOne);
502
503 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
504 Names::Add("/Names/Name", "Child", childOfObjectOne);
505
506 found = Names::FindName(objectOne);
507 NS_TEST_ASSERT_MSG_EQ(found, "Name", "Could not Names::Add and Names::FindName an Object");
508
509 Names::Rename("/Names", "Name", "New Name");
510
511 found = Names::FindName(objectOne);
512 NS_TEST_ASSERT_MSG_EQ(found, "New Name", "Could not Names::Rename an Object");
513
514 found = Names::FindName(childOfObjectOne);
516 "Child",
517 "Could not Names::Add and Names::FindName a child Object");
518
519 Names::Rename("/Names/New Name", "Child", "New Child");
520
521 found = Names::FindName(childOfObjectOne);
522 NS_TEST_ASSERT_MSG_EQ(found, "New Child", "Could not Names::Rename a child Object");
523}
524
525/**
526 * \ingroup names-tests
527 * Test the Object Name Service can rename objects
528 * using a fully qualified path name.
529 *
530 * Rename (std::string oldpath, std::string newname);
531 *
532 */
534{
535 public:
536 /** Constructor. */
538 /** Destructor. */
540
541 private:
542 void DoRun() override;
543 void DoTeardown() override;
544};
545
547 : TestCase("Check fully qualified path Names::Rename functionality")
548{
549}
550
552{
553}
554
555void
557{
558 Names::Clear();
559}
560
561void
563{
564 std::string found;
565
566 Ptr<TestObject> objectOne = CreateObject<TestObject>();
567 Names::Add("/Names/Name", objectOne);
568
569 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
570 Names::Add("/Names/Name/Child", childOfObjectOne);
571
572 found = Names::FindName(objectOne);
573 NS_TEST_ASSERT_MSG_EQ(found, "Name", "Could not Names::Add and Names::FindName an Object");
574
575 Names::Rename("/Names/Name", "New Name");
576
577 found = Names::FindName(objectOne);
578 NS_TEST_ASSERT_MSG_EQ(found, "New Name", "Could not Names::Rename an Object");
579
580 found = Names::FindName(childOfObjectOne);
582 "Child",
583 "Could not Names::Add and Names::FindName a child Object");
584
585 Names::Rename("/Names/New Name/Child", "New Child");
586
587 found = Names::FindName(childOfObjectOne);
588 NS_TEST_ASSERT_MSG_EQ(found, "New Child", "Could not Names::Rename a child Object");
589}
590
591/**
592 * \ingroup names-tests
593 * Test the Object Name Service can rename objects
594 * using a relative path name.
595 *
596 * Rename (std::string oldpath, std::string newname);
597 *
598 */
600{
601 public:
602 /** Constructor. */
604 /** Destructor. */
605 ~RelativeRenameTestCase() override;
606
607 private:
608 void DoRun() override;
609 void DoTeardown() override;
610};
611
613 : TestCase("Check relative path Names::Rename functionality")
614{
615}
616
618{
619}
620
621void
623{
624 Names::Clear();
625}
626
627void
629{
630 std::string found;
631
632 Ptr<TestObject> objectOne = CreateObject<TestObject>();
633 Names::Add("Name", objectOne);
634
635 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
636 Names::Add("Name/Child", childOfObjectOne);
637
638 found = Names::FindName(objectOne);
639 NS_TEST_ASSERT_MSG_EQ(found, "Name", "Could not Names::Add and Names::FindName an Object");
640
641 Names::Rename("Name", "New Name");
642
643 found = Names::FindName(objectOne);
644 NS_TEST_ASSERT_MSG_EQ(found, "New Name", "Could not Names::Rename an Object");
645
646 found = Names::FindName(childOfObjectOne);
648 "Child",
649 "Could not Names::Add and Names::FindName a child Object");
650
651 Names::Rename("New Name/Child", "New Child");
652
653 found = Names::FindName(childOfObjectOne);
654 NS_TEST_ASSERT_MSG_EQ(found, "New Child", "Could not Names::Rename a child Object");
655}
656
657/**
658 * \ingroup names-tests
659 * Test the Object Name Service can look up an object
660 * and return its fully qualified path name.
661 *
662 * FindPath (Ptr<Object> object);
663 *
664 */
666{
667 public:
668 /** Constructor. */
670 /** Destructor. */
671 ~FindPathTestCase() override;
672
673 private:
674 void DoRun() override;
675 void DoTeardown() override;
676};
677
679 : TestCase("Check Names::FindPath functionality")
680{
681}
682
684{
685}
686
687void
689{
690 Names::Clear();
691}
692
693void
695{
696 std::string found;
697
698 Ptr<TestObject> objectOne = CreateObject<TestObject>();
699 Names::Add("Name", objectOne);
700
701 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
702 Names::Add("/Names/Name/Child", childOfObjectOne);
703
704 found = Names::FindPath(objectOne);
706 "/Names/Name",
707 "Could not Names::Add and Names::FindPath an Object");
708
709 found = Names::FindPath(childOfObjectOne);
711 "/Names/Name/Child",
712 "Could not Names::Add and Names::FindPath a child Object");
713
714 Ptr<TestObject> objectNotThere = CreateObject<TestObject>();
715 found = Names::FindPath(objectNotThere);
716 NS_TEST_ASSERT_MSG_EQ(found.empty(), true, "Unexpectedly found a non-existent Object");
717}
718
719/**
720 * \ingroup names-tests
721 * Test the Object Name Service can find Objects.
722 *
723 * Find (Ptr<Object> context, std::string name);
724 *
725 */
727{
728 public:
729 /** Constructor. */
731 /** Destructor. */
732 ~BasicFindTestCase() override;
733
734 private:
735 void DoRun() override;
736 void DoTeardown() override;
737};
738
740 : TestCase("Check low level Names::Find functionality")
741{
742}
743
745{
746}
747
748void
750{
751 Names::Clear();
752}
753
754void
756{
757 Ptr<TestObject> found;
758
759 Ptr<TestObject> objectOne = CreateObject<TestObject>();
760 Names::Add("Name One", objectOne);
761
762 Ptr<TestObject> objectTwo = CreateObject<TestObject>();
763 Names::Add("Name Two", objectTwo);
764
765 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
766 Names::Add("Name One/Child", childOfObjectOne);
767
768 Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject>();
769 Names::Add("Name Two/Child", childOfObjectTwo);
770
771 found = Names::Find<TestObject>(Ptr<Object>(nullptr, false), "Name One");
773 objectOne,
774 "Could not find a previously named Object via object context");
775
776 found = Names::Find<TestObject>(Ptr<Object>(nullptr, false), "Name Two");
778 objectTwo,
779 "Could not find a previously named Object via object context");
780
781 found = Names::Find<TestObject>(objectOne, "Child");
783 childOfObjectOne,
784 "Could not find a previously named child Object via object context");
785
786 found = Names::Find<TestObject>(objectTwo, "Child");
788 childOfObjectTwo,
789 "Could not find a previously named child Object via object context");
790}
791
792/**
793 * \ingroup names-tests
794 * Test the Object Name Service can find Objects using
795 * a string context.
796 *
797 * Find (std::string context, std::string name);
798 *
799 */
801{
802 public:
803 /** Constructor. */
805 /** Destructor. */
807
808 private:
809 void DoRun() override;
810 void DoTeardown() override;
811};
812
814 : TestCase("Check string context-based Names::Find functionality")
815{
816}
817
819{
820}
821
822void
824{
825 Names::Clear();
826}
827
828void
830{
831 Ptr<TestObject> found;
832
833 Ptr<TestObject> objectOne = CreateObject<TestObject>();
834 Names::Add("Name One", objectOne);
835
836 Ptr<TestObject> objectTwo = CreateObject<TestObject>();
837 Names::Add("Name Two", objectTwo);
838
839 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
840 Names::Add("Name One/Child", childOfObjectOne);
841
842 Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject>();
843 Names::Add("Name Two/Child", childOfObjectTwo);
844
845 found = Names::Find<TestObject>("/Names", "Name One");
847 objectOne,
848 "Could not find a previously named Object via string context");
849
850 found = Names::Find<TestObject>("/Names", "Name Two");
852 objectTwo,
853 "Could not find a previously named Object via stribng context");
854
855 found = Names::Find<TestObject>("/Names/Name One", "Child");
857 childOfObjectOne,
858 "Could not find a previously named child Object via string context");
859
860 found = Names::Find<TestObject>("/Names/Name Two", "Child");
862 childOfObjectTwo,
863 "Could not find a previously named child Object via string context");
864}
865
866/**
867 * \ingroup names-tests
868 * Test the Object Name Service can find Objects using
869 * a fully qualified path name.
870 *
871 * Find (std::string name);
872 *
873 */
875{
876 public:
877 /** Constructor. */
879 /** Destructor. */
881
882 private:
883 void DoRun() override;
884 void DoTeardown() override;
885};
886
888 : TestCase("Check fully qualified path Names::Find functionality")
889{
890}
891
893{
894}
895
896void
898{
899 Names::Clear();
900}
901
902void
904{
905 Ptr<TestObject> found;
906
907 Ptr<TestObject> objectOne = CreateObject<TestObject>();
908 Names::Add("/Names/Name One", objectOne);
909
910 Ptr<TestObject> objectTwo = CreateObject<TestObject>();
911 Names::Add("/Names/Name Two", objectTwo);
912
913 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
914 Names::Add("/Names/Name One/Child", childOfObjectOne);
915
916 Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject>();
917 Names::Add("/Names/Name Two/Child", childOfObjectTwo);
918
919 found = Names::Find<TestObject>("/Names/Name One");
921 objectOne,
922 "Could not find a previously named Object via string context");
923
924 found = Names::Find<TestObject>("/Names/Name Two");
926 objectTwo,
927 "Could not find a previously named Object via stribng context");
928
929 found = Names::Find<TestObject>("/Names/Name One/Child");
931 childOfObjectOne,
932 "Could not find a previously named child Object via string context");
933
934 found = Names::Find<TestObject>("/Names/Name Two/Child");
936 childOfObjectTwo,
937 "Could not find a previously named child Object via string context");
938}
939
940/**
941 * \ingroup names-tests
942 * Test the Object Name Service can find Objects using
943 * a relative path name.
944 *
945 * Find (std::string name);
946 *
947 */
949{
950 public:
951 /** Constructor. */
953 /** Destructor. */
954 ~RelativeFindTestCase() override;
955
956 private:
957 void DoRun() override;
958 void DoTeardown() override;
959};
960
962 : TestCase("Check relative path Names::Find functionality")
963{
964}
965
967{
968}
969
970void
972{
973 Names::Clear();
974}
975
976void
978{
979 Ptr<TestObject> found;
980
981 Ptr<TestObject> objectOne = CreateObject<TestObject>();
982 Names::Add("Name One", objectOne);
983
984 Ptr<TestObject> objectTwo = CreateObject<TestObject>();
985 Names::Add("Name Two", objectTwo);
986
987 Ptr<TestObject> childOfObjectOne = CreateObject<TestObject>();
988 Names::Add("Name One/Child", childOfObjectOne);
989
990 Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject>();
991 Names::Add("Name Two/Child", childOfObjectTwo);
992
993 found = Names::Find<TestObject>("Name One");
995 objectOne,
996 "Could not find a previously named Object via string context");
997
998 found = Names::Find<TestObject>("Name Two");
1000 objectTwo,
1001 "Could not find a previously named Object via stribng context");
1002
1003 found = Names::Find<TestObject>("Name One/Child");
1005 childOfObjectOne,
1006 "Could not find a previously named child Object via string context");
1007
1008 found = Names::Find<TestObject>("Name Two/Child");
1010 childOfObjectTwo,
1011 "Could not find a previously named child Object via string context");
1012}
1013
1014/**
1015 * \ingroup names-tests
1016 * Test the Object Name Service can find Objects using
1017 * a second type.
1018 */
1020{
1021 public:
1022 /** Constructor. */
1024 /** Destructor. */
1025 ~AlternateFindTestCase() override;
1026
1027 private:
1028 void DoRun() override;
1029 void DoTeardown() override;
1030};
1031
1033 : TestCase("Check GetObject operation in Names::Find")
1034{
1035}
1036
1038{
1039}
1040
1041void
1043{
1044 Names::Clear();
1045}
1046
1047void
1049{
1050 Ptr<TestObject> testObject = CreateObject<TestObject>();
1051 Names::Add("Test Object", testObject);
1052
1053 Ptr<AlternateTestObject> alternateTestObject = CreateObject<AlternateTestObject>();
1054 Names::Add("Alternate Test Object", alternateTestObject);
1055
1056 Ptr<TestObject> foundTestObject;
1057 Ptr<AlternateTestObject> foundAlternateTestObject;
1058
1059 foundTestObject = Names::Find<TestObject>("Test Object");
1060 NS_TEST_ASSERT_MSG_EQ(foundTestObject,
1061 testObject,
1062 "Could not find a previously named TestObject via GetObject");
1063
1064 foundAlternateTestObject = Names::Find<AlternateTestObject>("Alternate Test Object");
1065 NS_TEST_ASSERT_MSG_EQ(foundAlternateTestObject,
1066 alternateTestObject,
1067 "Could not find a previously named AlternateTestObject via GetObject");
1068
1069 foundAlternateTestObject = Names::Find<AlternateTestObject>("Test Object");
1070 NS_TEST_ASSERT_MSG_EQ(foundAlternateTestObject,
1071 nullptr,
1072 "Unexpectedly able to GetObject<AlternateTestObject> on a TestObject");
1073
1074 foundTestObject = Names::Find<TestObject>("Alternate Test Object");
1075 NS_TEST_ASSERT_MSG_EQ(foundTestObject,
1076 nullptr,
1077 "Unexpectedly able to GetObject<TestObject> on an AlternateTestObject");
1078}
1079
1080/**
1081 * \ingroup names-tests
1082 * Names Test Suite
1083 */
1085{
1086 public:
1087 /** Constructor. */
1089};
1090
1092 : TestSuite("object-name-service")
1093{
1108}
1109
1110/**
1111 * \ingroup names-tests
1112 * NamesTestSuite instance variable.
1113 */
1115
1116} // namespace tests
1117
1118} // namespace ns3
static void Rename(std::string oldpath, std::string newname)
Rename a previously associated name.
Definition: names.cc:783
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition: names.cc:775
static void Clear()
Clear the list of objects associated with names.
Definition: names.cc:843
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
Definition: names.cc:829
static std::string FindPath(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and return the...
Definition: names.cc:836
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Test the Object Name Service can find Objects using a second type.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
~AlternateFindTestCase() override
Destructor.
Alternate test object for the Name service.
static TypeId GetTypeId()
Register this type.
Test the Object Name Service can do its most basic job.
~BasicAddTestCase() override
Destructor.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Test the Object Name Service can find Objects.
~BasicFindTestCase() override
Destructor.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Test the Object Name Service can rename objects.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
~BasicRenameTestCase() override
Destructor.
Test the Object Name Service can look up an object and return its fully qualified path name.
~FindPathTestCase() override
Destructor.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Test the Object Name Service can correctly use a fully qualified path to add associations.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
~FullyQualifiedAddTestCase() override
Destructor.
void DoRun() override
Implementation to actually run this TestCase.
Test the Object Name Service can find Objects using a fully qualified path name.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
~FullyQualifiedFindTestCase() override
Destructor.
Test the Object Name Service can rename objects using a fully qualified path name.
~FullyQualifiedRenameTestCase() override
Destructor.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Test the Object Name Service can correctly use a relative path to add associations.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
~RelativeAddTestCase() override
Destructor.
void DoRun() override
Implementation to actually run this TestCase.
Test the Object Name Service can find Objects using a relative path name.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
~RelativeFindTestCase() override
Destructor.
void DoRun() override
Implementation to actually run this TestCase.
Test the Object Name Service can rename objects using a relative path name.
~RelativeRenameTestCase() override
Destructor.
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
Test the Object Name Service can correctly use a string context.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
~StringContextAddTestCase() override
Destructor.
void DoRun() override
Implementation to actually run this TestCase.
Test the Object Name Service can find Objects using a string context.
~StringContextFindTestCase() override
Destructor.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Test the Object Name Service can rename objects using a string context.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
~StringContextRenameTestCase() override
Destructor.
Simple test object to exercise the Name service.
static TypeId GetTypeId()
Register this type.
static NamesTestSuite g_namesTestSuite
NamesTestSuite instance variable.
#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:145
Every class exported by the ns3 library is enclosed in the ns3 namespace.