1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
|
# ip.test -*- tcl -*-
#
# Tests for the Tcllib ip package
#
# -------------------------------------------------------------------------
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -------------------------------------------------------------------------
# RCS: @(#) $Id: ipMore.test,v 1.4 2006/10/09 21:41:40 andreas_kupries Exp $
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.2
testsNeedTcltest 2.2
testing {
useLocal ip.tcl ip
}
# -------------------------------------------------------------------------
::tcltest::testConstraint Cextension \
[llength [info commands ::ip::prefixToNativec]]
# -------------------------------------------------------------------------
logger::setlevel critical
namespace eval ::ip::test {
::tcltest::test load-1 {} -setup {
} -constraints {
} -cleanup {
} -body {
} -result {}
::tcltest::test ip::prefixToNativeTcl-1 {} -setup {
} -constraints {
} -cleanup {
} -body {
ip::prefixToNativeTcl 1.1.1.0/24
} -result {0x01010100 0xffffff00}
::tcltest::test ip::prefixToNativeTcl-2 {} -setup {
} -constraints {
} -cleanup {
} -body {
ip::prefixToNativeTcl {1.1.1.0/24 1.0.0.0/8 2.1.1.0/24 1.1.1.1/32}
} -result {{0x01010100 0xffffff00} {0x01000000 0xff000000} {0x02010100 0xffffff00} {0x01010101 0xffffffff}}
::tcltest::test ip::prefixToNativeTcl-3 {} -setup {
} -constraints {
} -cleanup {
} -body {
ip::prefixToNativeTcl ""
} -result {}
::tcltest::test ip::prefixToNativec-1 {} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
ip::prefixToNativec 1.1.1.0/24
} -result {0x01010100 0xFFFFFF00}
::tcltest::test ip::prefixToNativec-2 {} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
ip::prefixToNativec 1.1.1.0/255.255.255.0
} -result {0x01010100 0xFFFFFF00}
::tcltest::test ip::prefixToNativec-3 {} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
ip::prefixToNativec 1.1.1.0
} -result {0x01010100 0xFFFFFFFF}
::tcltest::test ip::prefixToNativec-4 {} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
ip::prefixToNativec {1.1.1.0/24 1.0.0.0/8 2.1.1.0/24 1.1.1.1/32}
} -result {{0x01010100 0xFFFFFF00} {0x01000000 0xFF000000} {0x02010100 0xFFFFFF00} {0x01010101 0xFFFFFFFF}}
::tcltest::test ip::prefixToNativec-5 {} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
ip::prefixToNativec {1.1.1.0/24 1.0AAF0/8 2.1.1.0/24 1.1.1.1/32}
} -result {} -returnCodes error
::tcltest::test ip::prefixToNativec-6 {} -setup {
} -constraints {
Cextension
} -cleanup {
unset y
} -body {
set y {1.1.1.0/24 1.0.0.0/8 2.1.1.0/24 1.1.1.1/32}
ip::prefixToNativec $y
lindex $y 0
} -result {1.1.1.0/24}
::tcltest::test ip::nativeToPrefix-1 {
single address test
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nativeToPrefix {0x01010100 0xffffff00} -ipv4
} -result {1.1.1.0/24}
::tcltest::test ip::nativeToPrefix-2 {
multi list test
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nativeToPrefix {{0x01010100 0xffffff00} {0x01000000 0xff000000} {0x02010100 0xffffff00} {0x01010101 0xffffffff}} -ipv4
} -result {1.1.1.0/24 1.0.0.0/8 2.1.1.0/24 1.1.1.1/32}
::tcltest::test ip::nativeToPrefix-3 {
0 test
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nativeToPrefix {0x0 0x0} -ipv4
} -result {0.0.0.0/0}
::tcltest::test ip::nativeToPrefix-4 {
0 test, check default is ipv4
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nativeToPrefix {0x0 0x0}
} -result {0.0.0.0/0}
::tcltest::test ip::toInteger-1 {} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::toInteger 1.1.1.0
} -result {16843008}
::tcltest::test ::ip::toHex-1 {} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::toHex 1.1.1.0
} -result {0x01010100}
::tcltest::test ::ip:broadcastAddress-1 {
dotted form
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::broadcastAddress 1.1.1.0/24
} -result {1.1.1.255}
::tcltest::test ::ip:broadcastAddress-2 {
native form
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::broadcastAddress {0x01010100 0xffffff00}
} -result {0x010101ff}
::tcltest::test ::ip:maskToLength-1 {
hexform
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::maskToLength 0xffffff00 -ipv4
} -result {24}
::tcltest::test ::ip:maskToLength-2 {
dotted form
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::maskToLength 255.255.255.0
} -result {24}
::tcltest::test ::ip:maskToLength-3 {
zero form
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::maskToLength 0.0.0.0
} -result {0}
::tcltest::test ::ip:maskToLength-4 {
zero form
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::maskToLength 0x0 -ipv4
} -result {0}
::tcltest::test ::ip:maskToLength-5 {
zero form, defualt is ipv4
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::maskToLength 0x0
} -result {0}
::tcltest::test ::ip::lengthToMask-1 {
dotted form
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::lengthToMask 24 -ipv4
} -result {255.255.255.0}
::tcltest::test ::ip::lengthToMask-2 {
dotted form, default is ipv4
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::lengthToMask 24
} -result {255.255.255.0}
::tcltest::test ::ip:maskToInt-1 {
integer form
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::maskToInt 32
} -result {4294967295}
::tcltest::test ::ip:maskToInt-2 {
dotted form
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::maskToInt 255.255.255.255
} -result {4294967295}
::tcltest::test ::ip:intToString-1 {
convert 255.255.255.255
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::intToString 4294967295 -ipv4
} -result {255.255.255.255}
::tcltest::test ::ip:intToString-2 {
convert hex to string
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::intToString 0x01010101 -ipv4
} -result {1.1.1.1}
::tcltest::test ::ip:intToString-3 {
convert hex to string, default is ipv4
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::intToString 0x01010101
} -result {1.1.1.1}
::tcltest::test ::ip:nextNet-1 {
255.255.255.0/32 -> 255.255.255.1
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::nextNet 0xffffff00 0xffffffff -ipv4
} -result {0xffffff01}
::tcltest::test ::ip:nextNet-2 {
1.0.0.0/24 -> 1.0.1.0/24
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nextNet 0x01000000 0xffffff00 -ipv4
} -result {0x01000100}
::tcltest::test ::ip:nextNet-3 {
1.1.28.0/24 -> 1.1.29.0
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nextNet 0x01011c00 0xffffff00 -ipv4
} -result {0x01011d00}
::tcltest::test ::ip:nextNet-4 {
1.1.28.0/24 -> 1.1.29.0 by 1
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nextNet 0x01011c00 0xffffff00 1 -ipv4
} -result {0x01011d00}
::tcltest::test ::ip:nextNet-5 {
1.1.1.1/32 -> 1.1.29.0 by 2
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nextNet 0x01010101 [ip::maskToInt 32] 2 -ipv4
} -result {0x01010103}
::tcltest::test ::ip:nextNet-6 {
1.1.1.1/32 -> 1.1.29.0 by 2
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nextNet 1.1.1.1 32 2
} -result {0x01010103}
::tcltest::test ::ip:nextNet-7 {
1.1.1.1/32 -> 1.1.29.0 by 2
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nextNet 1.1.1.1 255.255.255.255 2
} -result {0x01010103}
::tcltest::test ::ip:nextNet-8 {
1.1.1.1/32 -> 1.1.29.0 by 2, default is ipv4
} -setup {
} -constraints {
} -cleanup {
} -body {
ip::nextNet 0x01010101 [ip::maskToInt 32] 2
} -result {0x01010103}
::tcltest::test ::ip:isOverlap-1 {
no overlap test
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::isOverlap 1.1.1.0/24 2.1.0.1/32
} -result {0}
::tcltest::test ::ip:isOverlap-2 {
yes overlap test
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::isOverlap 1.1.1.0/24 2.1.0.1/32 1.1.1.1/32
} -result {1}
::tcltest::test ::ip:isOverlapNative-1 {
no overlap test
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::isOverlapNative -ipv4 0x01010100 0xffffff00 {{0x02010001 0xffffffff}}
} -result {0}
::tcltest::test ::ip:isOverlapNative-2 {
yes overlap test
} -setup {
} -constraints {
} -cleanup {
} -body {
set a [::ip::isOverlapNative -ipv4 0x01010100 0xffffff00 {{0x02010001 0xffffffff} {0x01010101 0xffffffff}} ]
expr $a > 0
} -result {1}
::tcltest::test ::ip:isOverlapNativeTcl-1 {
no overlap test
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::isOverlapNativeTcl -ipv4 0x01010100 0xffffff00 {{0x02010001 0xffffffff}}
} -result {0}
::tcltest::test ::ip:isOverlapNativeTcl-2 {
yes overlap test
} -setup {
} -constraints {
} -cleanup {
} -body {
set a [::ip::isOverlapNativeTcl -ipv4 0x01010100 0xffffff00 {{0x02010001 0xffffffff} {0x01010101 0xffffffff}}]
expr $a > 0
} -result {1}
::tcltest::test ::ip:isOverlapNativeTcl-3 {
yes overlap test
} -setup {
} -constraints {
} -cleanup {
} -body {
set a [::ip::isOverlapNativeTcl -ipv4 0x01010100 0xffffff00 {{0x02010001 0xffffffff} {0x01010101 0xffffffff}}]
} -result {2}
::tcltest::test ::ip:isOverlapNativeTcl-4 {
-all overlap test
} -setup {
} -constraints {
} -cleanup {
} -body {
set a [::ip::isOverlapNativeTcl -ipv4 -all 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
{0x01010101 0xffffffff}
{0x01010102 0xffffffff}
}]
} -result {2 3}
::tcltest::test ::ip:isOverlapNativeTcl-5 {
-all overlap test with -inline
} -setup {
} -constraints {
} -cleanup {
} -body {
set a [::ip::isOverlapNativeTcl -ipv4 -all -inline 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
{0x01010101 0xffffffff}
{0x01010102 0xffffffff}
}]
} -result {{0x01010101 0xffffffff} {0x01010102 0xffffffff}}
::tcltest::test ::ip:isOverlapNativeTcl-6 {
test with -inline
} -setup {
} -constraints {
} -cleanup {
} -body {
set a [::ip::isOverlapNativeTcl -ipv4 -inline 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
{0x01010101 0xffffffff}
{0x01010102 0xffffffff}
}]
} -result {{0x01010101 0xffffffff}}
::tcltest::test ::ip:isOverlapNativeTcl-7 {
test with -all -inline one element return
} -setup {
} -constraints {
} -cleanup {
} -body {
set a [::ip::isOverlapNativeTcl -ipv4 -all -inline 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
{0x01010101 0xffffffff}
}]
} -result {{0x01010101 0xffffffff}}
::tcltest::test ::ip:isOverlapNativeTcl-8 {
test with -inline
} -setup {
} -constraints {
} -cleanup {
} -body {
set a [::ip::isOverlapNativeTcl -ipv4 -inline 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
}]
} -result {}
::tcltest::test ::ip:isOverlapNativec-1 {
no overlap test
} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
::ip::isOverlapNativec -ipv4 0x01010100 0xffffff00 {{0x02010001 0xffffffff}}
} -result {0}
::tcltest::test ::ip:isOverlapNativec-2 {
yes overlap test
} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
set a [::ip::isOverlapNativec -ipv4 0x01010100 0xffffff00 {{0x02010001 0xffffffff} {0x01010101 0xffffffff}}]
expr $a > 0
} -result {1}
::tcltest::test ::ip:isOverlapNativec-3 {
yes overlap test
} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
set a [::ip::isOverlapNativec -ipv4 0x01010100 0xffffff00 {{0x02010001 0xffffffff} {0x01010101 0xffffffff}}]
} -result {2}
::tcltest::test ::ip:isOverlapNativec-4 {
-all overlap test
} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
set a [::ip::isOverlapNativec -ipv4 -all 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
{0x01010101 0xffffffff}
{0x01010102 0xffffffff}
}]
} -result {2 3}
::tcltest::test ::ip:isOverlapNativec-5 {
-all overlap test with -inline
} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
set a [::ip::isOverlapNativec -ipv4 -all -inline 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
{0x01010101 0xffffffff}
{0x01010102 0xffffffff}
}]
} -result {{0x01010101 0xffffffff} {0x01010102 0xffffffff}}
::tcltest::test ::ip:isOverlapNativec-6 {
test with -inline
} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
set a [::ip::isOverlapNativec -ipv4 -inline 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
{0x01010101 0xffffffff}
{0x01010102 0xffffffff}
}]
} -result {{0x01010101 0xffffffff}}
::tcltest::test ::ip:isOverlapNativec-7 {
test with -all -inline one element return
} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
set a [::ip::isOverlapNativec -ipv4 -all -inline 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
{0x01010101 0xffffffff}
}]
} -result {{0x01010101 0xffffffff}}
::tcltest::test ::ip:isOverlapNativec-8 {
test with -inline with not overlaps, returns nothing
} -setup {
} -constraints {
Cextension
} -cleanup {
} -body {
set a [::ip::isOverlapNativec -ipv4 -inline 0x01010100 0xffffff00 {
{0x02010001 0xffffffff}
}]
} -result {}
::tcltest::test ::ip:ipToLayer2Multicast-1 {
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::ipToLayer2Multicast 224.0.0.2
} -result {01.00.5e.00.00.02}
::tcltest::test ::ip:ipHostFromPrefix-1 {
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::ipHostFromPrefix 1.1.1.1/32
} -result {1.1.1.1}
::tcltest::test ::ip:ipHostFromPrefix-2 {
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::ipHostFromPrefix 1.1.1.0/24
} -result {1.1.1.1}
::tcltest::test ::ip:ipHostFromPrefix-3 {
} -setup {
} -constraints {
} -cleanup {
unset x
unset exlList
unset testPrefix
} -body {
set testPrefix 1.1.1.0/24
set exlList {
1.1.1.18/32
1.1.1.13/32
1.1.1.17/32
2.1.1.0/24
1.1.0.0/16
1.1.1.12/30
1.1.1.4/30
}
set x [::ip::ipHostFromPrefix $testPrefix -exclude $exlList ]
ip::longestPrefixMatch $x [concat $exlList [list $testPrefix]] -ipv4
} -result {1.1.1.0/24}
::tcltest::test ::ip:reduceToAggregates {
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::reduceToAggregates {1.1.1.0/24 1.1.0.0/8 2.1.1.0/24 1.1.1.1/32 }
} -result {1.0.0.0/8 2.1.1.0/24}
::tcltest::test ::ip:longestPrefixMatch-1 {
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::longestPrefixMatch 1.1.1.1/32 {1.1.1.0/24 1.1.0.0/8 2.1.1.0/24 1.1.1.1/32 } -ipv4
} -result {1.1.1.1/32}
::tcltest::test ::ip:longestPrefixMatch-2 {
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::longestPrefixMatch 1.1.1.1 {1.1.1.0/24 1.0.0.0/8 2.1.1.0/24 1.1.1.0/28 } -ipv4
} -result {1.1.1.0/28}
::tcltest::test ::ip:longestPrefixMatch-3 {
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::longestPrefixMatch 1.1.1.1 {2.1.1.0/24 2.0.0.0/8} -ipv4
} -result {}
::tcltest::test ::ip:longestPrefixMatch-4 {
} -setup {
} -constraints {
} -cleanup {
unset x
unset y
} -body {
set x 128.0.0.2
set y {1.0.0.0/8 2.2.0.0/16 128.0.0.0/16 3.3.3.3/32}
::ip::longestPrefixMatch $x $y -ipv4
# there was a problem when using varibles, it looked like
# tcl was modifying the original variables in an
# upvar fashion
::ip::longestPrefixMatch $x $y -ipv4
} -result {128.0.0.0/16}
::tcltest::test ::ip:longestPrefixMatch-5 {
check where the match list is only a single prefix (non-match case)
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::longestPrefixMatch 128.0.0.2 {1.0.0.0/8} -ipv4
} -result {}
::tcltest::test ::ip:longestPrefixMatch-6 {
check where the match list is only a single prefix (match case)
} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::longestPrefixMatch 128.0.0.2 {128.0.0.0/8} -ipv4
} -result {128.0.0.0/8}
::tcltest::test ::ip:cmpDotIP-1 {
test sorting of cmpDotIP
} -setup {
set iplist {1.0.0.0 2.2.0.0 128.0.0.0 3.3.3.3}
} -constraints {
} -cleanup {
unset iplist
} -body {
set a [lsort -command ip::cmpDotIP $iplist]
} -result {1.0.0.0 2.2.0.0 3.3.3.3 128.0.0.0}
::tcltest::test ip::distance-1 {basic distance} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::distance 1.1.1.0 1.1.1.5
} -result 5
::tcltest::test ip::distance-2 {distance, not enough args} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::distance
} -returnCodes error -result {wrong # args: should be "::ip::distance ip1 ip2"}
::tcltest::test ip::distance-3 {distance, too many args} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::distance 1.1.1.1 1.1.1.5 1.1.1.19
} -returnCodes error -result {wrong # args: should be "::ip::distance ip1 ip2"}
::tcltest::test ip::nextIp-1 {basic nextIp} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::nextIp 1.1.1.0 5
} -result 1.1.1.5
::tcltest::test ip::nextIp-2 {nextIp, not enough args} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::nextIp
} -returnCodes error -result {wrong # args: should be "::ip::nextIp ip ?offset?"}
::tcltest::test ip::nextIp-3 {nextIp, too many args} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::nextIp 1.1.1.1 1.1.1.5 1.1.1.19
} -returnCodes error -result {wrong # args: should be "::ip::nextIp ip ?offset?"}
foreach {n delta ip1 ip2} {
0 4294967295 0.0.0.0 255.255.255.255
1 -4294967295 255.255.255.255 0.0.0.0
2 7709 10.11.12.13 10.11.42.42
3 -7709 10.11.42.42 10.11.12.13
4 1994195353 54.229.115.42 173.194.116.195
5 -1994195353 173.194.116.195 54.229.115.42
} {
::tcltest::test ip::distance-4.$n {basic distance} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::distance $ip1 $ip2
} -result $delta
::tcltest::test ip::nextIp-4.$n {basic nextIp} -setup {
} -constraints {
} -cleanup {
} -body {
::ip::nextIp $ip1 $delta
} -result $ip2
}
}
namespace delete ::ip::test
testsuiteCleanup
#
# ;;; Local Variables:
# ;;; mode: tcl
# ;;; indent-tabs-mode:nil
# ;;; End:
|