A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
config-test-suite.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#include "ns3/config.h"
21
#include "ns3/test.h"
22
#include "ns3/integer.h"
23
#include "ns3/traced-value.h"
24
#include "ns3/trace-source-accessor.h"
25
#include "ns3/callback.h"
26
27
#include "ns3/singleton.h"
28
#include "ns3/object.h"
29
#include "ns3/object-vector.h"
30
#include "ns3/names.h"
31
#include "ns3/pointer.h"
32
#include "ns3/log.h"
33
34
35
#include <sstream>
36
37
using namespace
ns3;
38
39
// ===========================================================================
40
// An object with some attributes that we can play with using config.
41
// ===========================================================================
42
class
ConfigTestObject
:
public
Object
43
{
44
public
:
45
static
TypeId
GetTypeId (
void
);
46
47
void
AddNodeA (
Ptr<ConfigTestObject>
a);
48
void
AddNodeB (
Ptr<ConfigTestObject>
b);
49
50
void
SetNodeA (
Ptr<ConfigTestObject>
a);
51
void
SetNodeB (
Ptr<ConfigTestObject>
b);
52
53
int8_t GetA (
void
)
const
;
54
int8_t GetB (
void
)
const
;
55
56
private
:
57
std::vector<Ptr<ConfigTestObject> >
m_nodesA
;
58
std::vector<Ptr<ConfigTestObject> >
m_nodesB
;
59
Ptr<ConfigTestObject>
m_nodeA
;
60
Ptr<ConfigTestObject>
m_nodeB
;
61
int8_t
m_a
;
62
int8_t
m_b
;
63
TracedValue<int16_t>
m_trace
;
64
};
65
66
TypeId
67
ConfigTestObject::GetTypeId
(
void
)
68
{
69
static
TypeId
tid =
TypeId
(
"ConfigTestObject"
)
70
.
SetParent
<
Object
> ()
71
.AddAttribute (
"NodesA"
,
""
,
72
ObjectVectorValue
(),
73
MakeObjectVectorAccessor
(&
ConfigTestObject::m_nodesA
),
74
MakeObjectVectorChecker<ConfigTestObject> ())
75
.AddAttribute (
"NodesB"
,
""
,
76
ObjectVectorValue
(),
77
MakeObjectVectorAccessor
(&
ConfigTestObject::m_nodesB
),
78
MakeObjectVectorChecker<ConfigTestObject> ())
79
.AddAttribute (
"NodeA"
,
""
,
80
PointerValue
(),
81
MakePointerAccessor (&
ConfigTestObject::m_nodeA
),
82
MakePointerChecker<ConfigTestObject> ())
83
.AddAttribute (
"NodeB"
,
""
,
84
PointerValue
(),
85
MakePointerAccessor (&
ConfigTestObject::m_nodeB
),
86
MakePointerChecker<ConfigTestObject> ())
87
.AddAttribute (
"A"
,
""
,
88
IntegerValue
(10),
89
MakeIntegerAccessor (&
ConfigTestObject::m_a
),
90
MakeIntegerChecker<int8_t> ())
91
.AddAttribute (
"B"
,
""
,
92
IntegerValue
(9),
93
MakeIntegerAccessor (&
ConfigTestObject::m_b
),
94
MakeIntegerChecker<int8_t> ())
95
.AddAttribute (
"Source"
,
"XX"
,
96
IntegerValue
(-1),
97
MakeIntegerAccessor (&
ConfigTestObject::m_trace
),
98
MakeIntegerChecker<int16_t> ())
99
.AddTraceSource (
"Source"
,
"XX"
,
100
MakeTraceSourceAccessor
(&
ConfigTestObject::m_trace
))
101
;
102
return
tid;
103
}
104
105
void
106
ConfigTestObject::SetNodeA
(
Ptr<ConfigTestObject>
a)
107
{
108
m_nodeA = a;
109
}
110
111
void
112
ConfigTestObject::SetNodeB
(
Ptr<ConfigTestObject>
b)
113
{
114
m_nodeB = b;
115
}
116
117
void
118
ConfigTestObject::AddNodeA
(
Ptr<ConfigTestObject>
a)
119
{
120
m_nodesA.push_back (a);
121
}
122
123
void
124
ConfigTestObject::AddNodeB
(
Ptr<ConfigTestObject>
b)
125
{
126
m_nodesB.push_back (b);
127
}
128
129
int8_t
130
ConfigTestObject::GetA
(
void
)
const
131
{
132
return
m_a;
133
}
134
135
int8_t
136
ConfigTestObject::GetB
(
void
)
const
137
{
138
return
m_b;
139
}
140
141
// ===========================================================================
142
// Test for the ability to register and use a root namespace
143
// ===========================================================================
144
class
RootNamespaceConfigTestCase
:
public
TestCase
145
{
146
public
:
147
RootNamespaceConfigTestCase
();
148
virtual
~RootNamespaceConfigTestCase
() {}
149
150
private
:
151
virtual
void
DoRun (
void
);
152
};
153
154
RootNamespaceConfigTestCase::RootNamespaceConfigTestCase
()
155
:
TestCase
(
"Check ability to register a root namespace and use it"
)
156
{
157
}
158
159
void
160
RootNamespaceConfigTestCase::DoRun
(
void
)
161
{
162
IntegerValue
iv;
163
//
164
// Create an object and register its attributes directly in the root
165
// namespace.
166
//
167
Ptr<ConfigTestObject>
root = CreateObject<ConfigTestObject> ();
168
Config::RegisterRootNamespaceObject
(root);
169
170
//
171
// We should find the default values there.
172
//
173
root->
GetAttribute
(
"A"
, iv);
174
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" not initialized as expected"
);
175
176
//
177
// Now use the config mechanism to set the attribute; and we should find the
178
// new value.
179
//
180
Config::Set
(
"/A"
,
IntegerValue
(1));
181
root->
GetAttribute
(
"A"
, iv);
182
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 1,
"Object Attribute \"A\" not set correctly"
);
183
184
//
185
// We should find the default values of "B" too.
186
//
187
root->
GetAttribute
(
"B"
, iv);
188
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 9,
"Object Attribute \"B\" not initialized as expected"
);
189
190
//
191
// Now use the config mechanism to set the attribute; and we should find the
192
// new value.
193
//
194
Config::Set
(
"/B"
,
IntegerValue
(-1));
195
root->
GetAttribute
(
"B"
, iv);
196
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -1,
"Object Attribute \"B\" not set correctly"
);
197
}
198
199
// ===========================================================================
200
// Test for the ability to add an object under the root namespace.
201
// ===========================================================================
202
class
UnderRootNamespaceConfigTestCase
:
public
TestCase
203
{
204
public
:
205
UnderRootNamespaceConfigTestCase
();
206
virtual
~UnderRootNamespaceConfigTestCase
() {}
207
208
private
:
209
virtual
void
DoRun
(
void
);
210
};
211
212
UnderRootNamespaceConfigTestCase::UnderRootNamespaceConfigTestCase
()
213
:
TestCase
(
"Check ability to register an object under the root namespace and use it"
)
214
{
215
}
216
217
void
218
UnderRootNamespaceConfigTestCase::DoRun
(
void
)
219
{
220
IntegerValue
iv;
221
//
222
// Create an object and register its attributes directly in the root
223
// namespace.
224
//
225
Ptr<ConfigTestObject>
root = CreateObject<ConfigTestObject> ();
226
Config::RegisterRootNamespaceObject
(root);
227
228
Ptr<ConfigTestObject>
a = CreateObject<ConfigTestObject> ();
229
root->
SetNodeA
(a);
230
231
//
232
// We should find the default values there.
233
//
234
a->
GetAttribute
(
"A"
, iv);
235
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" not initialized as expected"
);
236
237
//
238
// Now use the config mechanism to set the attribute; and we should find the
239
// new value.
240
//
241
Config::Set
(
"/NodeA/A"
,
IntegerValue
(1));
242
a->
GetAttribute
(
"A"
, iv);
243
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 1,
"Object Attribute \"A\" not set correctly"
);
244
245
246
//
247
// We should find the default values of "B" too.
248
//
249
a->
GetAttribute
(
"B"
, iv);
250
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 9,
"Object Attribute \"B\" not initialized as expected"
);
251
252
//
253
// Now use the config mechanism to set the attribute; and we should find the
254
// new value.
255
//
256
Config::Set
(
"/NodeA/B"
,
IntegerValue
(-1));
257
a->
GetAttribute
(
"B"
, iv);
258
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -1,
"Object Attribute \"B\" not set correctly"
);
259
260
//
261
// Try and set through a nonexistent path. Should do nothing.
262
//
263
Config::Set
(
"/NodeB/A"
,
IntegerValue
(1234));
264
a->
GetAttribute
(
"A"
, iv);
265
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 1,
"Object Attribute \"A\" unexpectedly set via bad path"
);
266
267
Config::Set
(
"/NodeB/B"
,
IntegerValue
(1234));
268
a->
GetAttribute
(
"B"
, iv);
269
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -1,
"Object Attribute \"B\" unexpectedly set via bad path"
);
270
271
//
272
// Step down one level of recursion and try again
273
//
274
Ptr<ConfigTestObject>
b = CreateObject<ConfigTestObject> ();
275
276
//
277
// We should find the default values there.
278
//
279
b->
GetAttribute
(
"A"
, iv);
280
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" not initialized as expected"
);
281
b->GetAttribute (
"B"
, iv);
282
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 9,
"Object Attribute \"B\" not initialized as expected"
);
283
284
//
285
// Now tell A that it has a B; and we should be able to set this new object's
286
// Attributes.
287
//
288
a->
SetNodeB
(b);
289
290
Config::Set
(
"/NodeA/NodeB/A"
,
IntegerValue
(4));
291
Config::Set
(
"/NodeA/NodeB/B"
,
IntegerValue
(-4));
292
b->GetAttribute (
"A"
, iv);
293
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 4,
"Object Attribute \"A\" not set as expected"
);
294
b->GetAttribute (
"B"
, iv);
295
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -4,
"Object Attribute \"B\" not set as expected"
);
296
297
298
//
299
// Try '*' for attributes
300
//
301
Config::Set
(
"/*/A"
,
IntegerValue
(2));
302
a->
GetAttribute
(
"A"
, iv);
303
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 2,
"Object Attribute \"A\" not set correctly"
);
304
b->GetAttribute (
"A"
, iv);
305
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 4,
"Object Attribute \"A\" not set correctly"
);
306
}
307
308
// ===========================================================================
309
// Test for the ability to deal configure with vectors of objects.
310
// ===========================================================================
311
class
ObjectVectorConfigTestCase
:
public
TestCase
312
{
313
public
:
314
ObjectVectorConfigTestCase
();
315
virtual
~ObjectVectorConfigTestCase
() {}
316
317
private
:
318
virtual
void
DoRun
(
void
);
319
};
320
321
ObjectVectorConfigTestCase::ObjectVectorConfigTestCase
()
322
:
TestCase
(
"Check ability to configure vectors of Object using regular expressions"
)
323
{
324
}
325
326
void
327
ObjectVectorConfigTestCase::DoRun
(
void
)
328
{
329
IntegerValue
iv;
330
331
//
332
// Create a root namespace object
333
//
334
Ptr<ConfigTestObject>
root = CreateObject<ConfigTestObject> ();
335
Config::RegisterRootNamespaceObject
(root);
336
337
//
338
// Create an object under the root.
339
//
340
Ptr<ConfigTestObject>
a = CreateObject<ConfigTestObject> ();
341
root->
SetNodeA
(a);
342
343
//
344
// Create an object one level down.
345
//
346
Ptr<ConfigTestObject>
b = CreateObject<ConfigTestObject> ();
347
a->
SetNodeB
(b);
348
349
//
350
// Add four objects to the ObjectVector Attribute at the bottom of the
351
// object hierarchy. By this point, we believe that the Attributes
352
// will be initialized correctly.
353
//
354
Ptr<ConfigTestObject>
obj0 = CreateObject<ConfigTestObject> ();
355
Ptr<ConfigTestObject>
obj1 = CreateObject<ConfigTestObject> ();
356
Ptr<ConfigTestObject>
obj2 = CreateObject<ConfigTestObject> ();
357
Ptr<ConfigTestObject>
obj3 = CreateObject<ConfigTestObject> ();
358
b->
AddNodeB
(obj0);
359
b->
AddNodeB
(obj1);
360
b->
AddNodeB
(obj2);
361
b->
AddNodeB
(obj3);
362
363
//
364
// Set an Attribute of the zeroth Object in the vector by explicitly writing
365
// the '0' and make sure that only the one thing changed.
366
//
367
Config::Set
(
"/NodeA/NodeB/NodesB/0/A"
,
IntegerValue
(-11));
368
obj0->
GetAttribute
(
"A"
, iv);
369
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -11,
"Object Attribute \"A\" not set as expected"
);
370
371
obj1->GetAttribute (
"A"
, iv);
372
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" unexpectedly set"
);
373
374
obj2->GetAttribute (
"A"
, iv);
375
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" unexpectedly set"
);
376
377
obj3->GetAttribute (
"A"
, iv);
378
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" unexpectedly set"
);
379
380
//
381
// Start using regular expression-like syntax to set Attributes. First try
382
// the OR syntax. Make sure that the two objects changed and nothing else
383
//
384
Config::Set
(
"/NodeA/NodeB/NodesB/0|1/A"
,
IntegerValue
(-12));
385
obj0->
GetAttribute
(
"A"
, iv);
386
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -12,
"Object Attribute \"A\" not set as expected"
);
387
388
obj1->GetAttribute (
"A"
, iv);
389
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -12,
"Object Attribute \"A\" not set as expected"
);
390
391
obj2->GetAttribute (
"A"
, iv);
392
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" unexpectedly set"
);
393
394
obj3->GetAttribute (
"A"
, iv);
395
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" unexpectedly set"
);
396
397
//
398
// Make sure that extra '|' are allowed at the start and end of the regular expression
399
//
400
Config::Set
(
"/NodeA/NodeB/NodesB/|0|1|/A"
,
IntegerValue
(-13));
401
obj0->
GetAttribute
(
"A"
, iv);
402
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -13,
"Object Attribute \"A\" not set as expected"
);
403
404
obj1->GetAttribute (
"A"
, iv);
405
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -13,
"Object Attribute \"A\" not set as expected"
);
406
407
obj2->GetAttribute (
"A"
, iv);
408
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" unexpectedly set"
);
409
410
obj3->GetAttribute (
"A"
, iv);
411
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" unexpectedly set"
);
412
413
//
414
// Try the [x-y] syntax
415
//
416
Config::Set
(
"/NodeA/NodeB/NodesB/[0-2]/A"
,
IntegerValue
(-14));
417
obj0->
GetAttribute
(
"A"
, iv);
418
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -14,
"Object Attribute \"A\" not set as expected"
);
419
420
obj1->GetAttribute (
"A"
, iv);
421
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -14,
"Object Attribute \"A\" not set as expected"
);
422
423
obj2->GetAttribute (
"A"
, iv);
424
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -14,
"Object Attribute \"A\" not set as expected"
);
425
426
obj3->GetAttribute (
"A"
, iv);
427
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), 10,
"Object Attribute \"A\" unexpectedly set"
);
428
429
//
430
// Try the [x-y] syntax at the other limit
431
//
432
Config::Set
(
"/NodeA/NodeB/NodesB/[1-3]/A"
,
IntegerValue
(-15));
433
obj0->
GetAttribute
(
"A"
, iv);
434
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -14,
"Object Attribute \"A\" unexpectedly set"
);
435
436
obj1->GetAttribute (
"A"
, iv);
437
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -15,
"Object Attribute \"A\" not set as expected"
);
438
439
obj2->GetAttribute (
"A"
, iv);
440
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -15,
"Object Attribute \"A\" not set as expected"
);
441
442
obj3->GetAttribute (
"A"
, iv);
443
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -15,
"Object Attribute \"A\" not set as expected"
);
444
445
//
446
// Combine the [x-y] syntax and the OR sntax
447
//
448
Config::Set
(
"/NodeA/NodeB/NodesB/[0-1]|3/A"
,
IntegerValue
(-16));
449
obj0->
GetAttribute
(
"A"
, iv);
450
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -16,
"Object Attribute \"A\" not set as expected"
);
451
452
obj1->GetAttribute (
"A"
, iv);
453
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -16,
"Object Attribute \"A\" not set as expected"
);
454
455
obj2->GetAttribute (
"A"
, iv);
456
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -15,
"Object Attribute \"A\" unexpectedly set"
);
457
458
obj3->GetAttribute (
"A"
, iv);
459
NS_TEST_ASSERT_MSG_EQ
(iv.
Get
(), -16,
"Object Attribute \"A\" not set as expected"
);
460
}
461
462
// ===========================================================================
463
// Test for the ability to trace configure with vectors of objects.
464
// ===========================================================================
465
class
ObjectVectorTraceConfigTestCase
:
public
TestCase
466
{
467
public
:
468
ObjectVectorTraceConfigTestCase
();
469
virtual
~ObjectVectorTraceConfigTestCase
() {}
470
471
void
Trace
(int16_t oldValue, int16_t newValue) {
m_newValue
= newValue; }
472
void
TraceWithPath
(std::string path, int16_t old, int16_t newValue) {
m_newValue
= newValue;
m_path
= path; }
473
474
private
:
475
virtual
void
DoRun
(
void
);
476
477
int16_t
m_newValue
;
478
std::string
m_path
;
479
};
480
481
ObjectVectorTraceConfigTestCase::ObjectVectorTraceConfigTestCase
()
482
:
TestCase
(
"Check ability to trace connect through vectors of Object using regular expressions"
)
483
{
484
}
485
486
void
487
ObjectVectorTraceConfigTestCase::DoRun
(
void
)
488
{
489
IntegerValue
iv;
490
491
//
492
// Create a root namespace object
493
//
494
Ptr<ConfigTestObject>
root = CreateObject<ConfigTestObject> ();
495
Config::RegisterRootNamespaceObject
(root);
496
497
//
498
// Create an object under the root.
499
//
500
Ptr<ConfigTestObject>
a = CreateObject<ConfigTestObject> ();
501
root->
SetNodeA
(a);
502
503
//
504
// Create an object one level down.
505
//
506
Ptr<ConfigTestObject>
b = CreateObject<ConfigTestObject> ();
507
a->
SetNodeB
(b);
508
509
//
510
// Add four objects to the ObjectVector Attribute at the bottom of the
511
// object hierarchy. By this point, we believe that the Attributes
512
// will be initialized correctly.
513
//
514
Ptr<ConfigTestObject>
obj0 = CreateObject<ConfigTestObject> ();
515
Ptr<ConfigTestObject>
obj1 = CreateObject<ConfigTestObject> ();
516
Ptr<ConfigTestObject>
obj2 = CreateObject<ConfigTestObject> ();
517
Ptr<ConfigTestObject>
obj3 = CreateObject<ConfigTestObject> ();
518
b->
AddNodeB
(obj0);
519
b->
AddNodeB
(obj1);
520
b->
AddNodeB
(obj2);
521
b->
AddNodeB
(obj3);
522
523
//
524
// Do a trace connect to some of the sources. We already checked parsing of
525
// the regular expressions, so we'll concentrate on the tracing part of the
526
// puzzle here.
527
//
528
Config::ConnectWithoutContext
(
"/NodeA/NodeB/NodesB/[0-1]|3/Source"
,
529
MakeCallback
(&
ObjectVectorTraceConfigTestCase::Trace
,
this
));
530
531
//
532
// If we bug the trace source referred to by index '0' above, we should see
533
// the trace fire.
534
//
535
m_newValue
= 0;
536
obj0->
SetAttribute
(
"Source"
,
IntegerValue
(-1));
537
NS_TEST_ASSERT_MSG_EQ
(
m_newValue
, -1,
"Trace 0 did not fire as expected"
);
538
539
//
540
// If we bug the trace source referred to by index '1' above, we should see
541
// the trace fire.
542
//
543
m_newValue
= 0;
544
obj1->SetAttribute (
"Source"
,
IntegerValue
(-2));
545
NS_TEST_ASSERT_MSG_EQ
(
m_newValue
, -2,
"Trace 1 did not fire as expected"
);
546
547
//
548
// If we bug the trace source referred to by index '2' which is skipped above,
549
// we should not see the trace fire.
550
//
551
m_newValue
= 0;
552
obj2->SetAttribute (
"Source"
,
IntegerValue
(-3));
553
NS_TEST_ASSERT_MSG_EQ
(
m_newValue
, 0,
"Trace 2 fired unexpectedly"
);
554
555
//
556
// If we bug the trace source referred to by index '3' above, we should see
557
// the trace fire.
558
//
559
m_newValue
= 0;
560
obj3->SetAttribute (
"Source"
,
IntegerValue
(-4));
561
NS_TEST_ASSERT_MSG_EQ
(
m_newValue
, -4,
"Trace 3 did not fire as expected"
);
562
563
//
564
// Do a trace connect (with context) to some of the sources.
565
//
566
Config::Connect
(
"/NodeA/NodeB/NodesB/[0-1]|3/Source"
,
567
MakeCallback
(&
ObjectVectorTraceConfigTestCase::TraceWithPath
,
this
));
568
569
//
570
// If we bug the trace source referred to by index '0' above, we should see
571
// the trace fire with the expected context path.
572
//
573
m_newValue
= 0;
574
m_path
=
""
;
575
obj0->
SetAttribute
(
"Source"
,
IntegerValue
(-1));
576
NS_TEST_ASSERT_MSG_EQ
(
m_newValue
, -1,
"Trace 0 did not fire as expected"
);
577
NS_TEST_ASSERT_MSG_EQ
(
m_path
,
"/NodeA/NodeB/NodesB/0/Source"
,
"Trace 0 did not provide expected context"
);
578
579
//
580
// If we bug the trace source referred to by index '1' above, we should see
581
// the trace fire with the expected context path.
582
//
583
m_newValue
= 0;
584
m_path
=
""
;
585
obj1->SetAttribute (
"Source"
,
IntegerValue
(-2));
586
NS_TEST_ASSERT_MSG_EQ
(
m_newValue
, -2,
"Trace 1 did not fire as expected"
);
587
NS_TEST_ASSERT_MSG_EQ
(
m_path
,
"/NodeA/NodeB/NodesB/1/Source"
,
"Trace 1 did not provide expected context"
);
588
589
//
590
// If we bug the trace source referred to by index '2' which is skipped above,
591
// we should not see the trace fire.
592
//
593
m_newValue
= 0;
594
m_path
=
""
;
595
obj2->SetAttribute (
"Source"
,
IntegerValue
(-3));
596
NS_TEST_ASSERT_MSG_EQ
(
m_newValue
, 0,
"Trace 2 fired unexpectedly"
);
597
598
//
599
// If we bug the trace source referred to by index '3' above, we should see
600
// the trace fire with the expected context path.
601
//
602
m_newValue
= 0;
603
m_path
=
""
;
604
obj3->SetAttribute (
"Source"
,
IntegerValue
(-4));
605
NS_TEST_ASSERT_MSG_EQ
(
m_newValue
, -4,
"Trace 3 did not fire as expected"
);
606
NS_TEST_ASSERT_MSG_EQ
(
m_path
,
"/NodeA/NodeB/NodesB/1/Source"
,
"Trace 1 did not provide expected context"
);
607
}
608
609
// ===========================================================================
610
// The Test Suite that glues all of the Test Cases together.
611
// ===========================================================================
612
class
ConfigTestSuite
:
public
TestSuite
613
{
614
public
:
615
ConfigTestSuite
();
616
};
617
618
ConfigTestSuite::ConfigTestSuite
()
619
:
TestSuite
(
"config"
, UNIT)
620
{
621
AddTestCase
(
new
RootNamespaceConfigTestCase
, TestCase::QUICK);
622
AddTestCase
(
new
UnderRootNamespaceConfigTestCase
, TestCase::QUICK);
623
AddTestCase
(
new
ObjectVectorConfigTestCase
, TestCase::QUICK);
624
}
625
626
static
ConfigTestSuite
configTestSuite
;
src
core
test
config-test-suite.cc
Generated on Tue May 14 2013 11:08:19 for ns-3 by
1.8.1.2