summaryrefslogtreecommitdiffstats
path: root/tcllib/modules/nettool/nettool.test
blob: 384bb2e73a52fe49e14207cc8116727459e0d39f (plain)
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

source [file join \
    [file dirname [file dirname [file join [pwd] [info script]]]] \
    devtools testutilities.tcl]

package require tcltest
testsNeedTcl     8.5
testsNeedTcltest 1.0

testing {
    useLocal nettool.tcl    nettool
}

# Test known busy ports
foreach port {
  80
  3020
  21
  7794
} {
  ::tcltest::test port-busy-$port \
    "Test that port busy returns true for known port $port" \
    [list ::nettool::port_busy $port] 1
}

# Test known free ports
# And test the full range at 7790-7792 to ensure there
# are now edge cases at the start and end of a range
foreach port {
  1028
  2446
  7790 7791 7792 7792
} {
  ::tcltest::test port-free-$port \
    "Test that port busy returns false for known port $port" \
    [list ::nettool::port_busy $port] 0
}

# Test that "next" for block 7790 return 7790
::tcltest::test port-find-0001 \
    "Test that port find returns the first port in unclaimed block starting at 7790" \
    [list ::nettool::find_port 7790] 7790

foreach {port nextport comment} {
  7790 7791 {Start of block}
  7791 7792 {...}
  7792 7793 {End of block}
  7793 7795 {Start of new block}
} {
  ::nettool::claim_port $port
  ::tcltest::test port-claim-0001 \
      "Test that port busy returns true after $port is claimed" \
      [list ::nettool::port_busy $port] 1
  
  # Test that claiming a port makes it busy
  ::tcltest::test port-find-0002 \
      "Test that port find returns the next port in unclaimed block starting at $port following claim" \
      [list ::nettool::find_port $port] $nextport

}

set port 7790
::nettool::claim_port $port
::tcltest::test port-claim-0002 \
    "Test that port busy returns true after $port is claimed" \
    [list ::nettool::port_busy $port] 1
::nettool::release_port $port
::tcltest::test port-claim-0003 \
    "Test that port busy returns false after $port is release" \
    [list ::nettool::port_busy $port] 0
  
# Test that claiming a port makes it busy
::tcltest::test port-find-0004 \
    "Test that port find returns the next port in released block starting at $port following claim" \
    [list ::nettool::find_port 7790] 7790

foreach {port nextport comment} {
  7790 7791 {Start of block}
  7791 7792 {...}
  7792 7793 {End of block}
  7793 7795 {Start of new block}
} {
  ::nettool::release_port $port 
}

# Test that claiming a port makes it busy
::tcltest::test port-allocate-0004 \
    "Test allocate port returns the address of an unclaimed spot and claims it" \
    [list ::nettool::allocate_port 7790] 7790

::tcltest::test port-allocate-0005 \
    "Test allocate port returns the next address of an claimed spot and claims it" \
    [list ::nettool::allocate_port 7790] 7791

::tcltest::test port-allocate-0006 \
    "Test allocate port returns the next address of an claimed spot and claims it" \
    [list ::nettool::allocate_port 7790] 7792


testsuiteCleanup
return