DIY-pcap 0.0.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/queue_spec.rb DELETED
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
- describe DIY::Queue do
3
-
4
- before(:each) do
5
- @device_name = FFI::PCap.dump_devices[0][0]
6
- @live = FFI::PCap::Live.new(:dev=>@device_name, :handler => FFI::PCap::Handler, :promisc => true)
7
- @pcap_name = "../simple/pcaps/gre.pcap"
8
- @offline = DIY::Offline.new(@pcap_name)
9
- end
10
-
11
- it "#next_send_pkt" do
12
- $SERVER = nil
13
- q = DIY::Queue.new(@offline)
14
- q.stub(:wait_until).and_return(true)
15
- q.stub(:wait_for_seconds).and_return(nil)
16
- q.next_send_pkt.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt1' ) )
17
- pkt1 = q.instance_variable_get("@expect_recv_queue")[0][0]
18
- pkt2 = q.instance_variable_get("@expect_recv_queue")[1][0]
19
- q.instance_variable_get("@expect_recv_queue").size.should == 2
20
- pkt1.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
21
- pkt2.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt3' ) )
22
- q.instance_variable_set("@expect_recv_queue", [])
23
- q.next_send_pkt.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt4' ) )
24
- q.instance_variable_get("@expect_recv_queue").should == []
25
- lambda { loop { q.next_send_pkt } }.should raise_error
26
- end
27
-
28
- it "#next_send_pkt server" do
29
- $SERVER = true
30
- q = DIY::Queue.new(@offline)
31
- q.stub(:wait_until).and_return(true)
32
- q.stub(:wait_for_seconds).and_return(nil)
33
- q.next_send_pkt.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
34
- q.instance_variable_get("@expect_recv_queue")[0][0].should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt1' ) )
35
- q.instance_variable_set("@expect_recv_queue", [])
36
- q.next_send_pkt.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt3' ) )
37
- q.instance_variable_get("@expect_recv_queue")[0][0].should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt4' ))
38
- q.instance_variable_get("@expect_recv_queue")[1][0].should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt5' ))
39
- $SERVER = nil
40
- end
41
-
42
- it "#comein? server" do
43
- $SERVER = true
44
- q = DIY::Queue.new(@offline)
45
- q.stub(:wait_for_seconds).and_return(nil)
46
- pkt = File.read( File.join( File.dirname(__FILE__), 'helper/pkt1' ) )
47
- pkt2 = File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
48
- q.set_first_gout(pkt).should == pkt[6..11]
49
- q.comein?(pkt).should == true
50
- q.comein?(pkt2).should == false
51
- $SERVER = nil
52
- end
53
-
54
- it "#peek #pop" do
55
- q = DIY::Queue.new(@offline)
56
- q.stub(:wait_until).and_return(true)
57
- q.stub(:wait_for_seconds).and_return(nil)
58
- q.next_send_pkt
59
- q.peek.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
60
- q.pop.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
61
- q.peek.should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt3' ) )
62
- q.pop
63
- q.peek.should == nil
64
- end
65
-
66
- it "#delete" do
67
- q = DIY::Queue.new(@offline)
68
- q.stub(:wait_until).and_return(true)
69
- q.stub(:wait_for_seconds).and_return(nil)
70
- q.next_send_pkt
71
- q.delete(File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )).should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
72
- q.pop
73
- q.peek.should == nil
74
- end
75
-
76
- it "#delete_at" do
77
- q = DIY::Queue.new(@offline)
78
- q.stub(:wait_until).and_return(true)
79
- q.stub(:wait_for_seconds).and_return(nil)
80
- q.next_send_pkt
81
- q.delete_at(0).should == File.read( File.join( File.dirname(__FILE__), 'helper/pkt2' ) )
82
- end
83
-
84
- end
data/spec/sender_spec.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DIY::Sender do
4
-
5
- class FakeLive
6
- def inject
7
- end
8
- end
9
-
10
- it "#before_send" do
11
- live = double(FakeLive)
12
-
13
- before_send_call = lambda { |pkt| pkt[0..2] = "111"; pkt }
14
- pkt = "222222"
15
- npkt = "111222"
16
- live.should_receive(:inject).with(npkt).and_return(nil)
17
- sender = DIY::Sender.new(live )
18
- sender.before_send(&before_send_call)
19
- lambda { sender.inject(pkt) }.should_not raise_error
20
- end
21
- end