summaryrefslogtreecommitdiff
path: root/test/tc_ttl.rb
blob: 0309f984f2e9f73ca08757afc33a2ada0259cdea (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
#!/usr/bin/ruby
# netsed Unit::Tests
# (c) 2010 Julien Viard de Galbert <julien@silicone.homelinux.org>
#
# this file implements checks for the TTL (time-to-live) feature of netsed rules in the class TC_TTLTest.

require 'test/unit'
require './test_helper'

# Test Case for netsed TTL (time-to-live) feature
class TC_TTLTest < Test::Unit::TestCase
  # def setup
  # end

  # def teardown
  # end

  # Check first occurrence
  def test_TTL_1
    datasent   = 'test andrew and andrew'
    dataexpect = 'test mike and andrew'
    serv = TCPServeSingleDataSender.new(SERVER, RPORT, datasent)

    netsed = NetsedRun.new('tcp', LPORT, SERVER, RPORT, ['s/andrew/mike/1'])

    datarecv = TCPSingleDataRecv(SERVER, LPORT, 100)

    serv.join
    netsed.kill

    assert_equal(dataexpect, datarecv)
  end

  # Check 20 occurrences
  def test_TTL_20
    datasent   = '% %% %%% %%%% %%%%% %%%%%% %%%%%%%'
    dataexpect = '/ // /// //// ///// /////% %%%%%%%'
    serv = TCPServeSingleDataSender.new(SERVER, RPORT, datasent)

    netsed = NetsedRun.new('tcp', LPORT, SERVER, RPORT, ['s/%%/%2f/20'])

    datarecv = TCPSingleDataRecv(SERVER, LPORT, 100)

    serv.join
    netsed.kill

    assert_equal(dataexpect, datarecv)
  end

  # Check first occurrence in several connections: the TTL is not global.
  def test_TTL_1_byConnections
    datasent   = 'test andrew and andrew'
    dataexpect = 'test mike and andrew'

    netsed = NetsedRun.new('tcp', LPORT, SERVER, RPORT, ['s/andrew/mike/1'])

    serv = TCPServeSingleDataSender.new(SERVER, RPORT, datasent)
    datarecv = TCPSingleDataRecv(SERVER, LPORT, 100)
    serv.join

    assert_equal(dataexpect, datarecv, 'At first connection')

    # once again
    serv = TCPServeSingleDataSender.new(SERVER, RPORT, datasent)
    datarecv = TCPSingleDataRecv(SERVER, LPORT, 100)
    serv.join

    assert_equal(dataexpect, datarecv, 'At second connection')
  ensure
    netsed.kill
  end

end

# vim:sw=2:sta:et: