File tree Expand file tree Collapse file tree 1 file changed +41
-2
lines changed
spec/lib/rex/image_source Expand file tree Collapse file tree 1 file changed +41
-2
lines changed Original file line number Diff line number Diff line change 34
34
end
35
35
36
36
describe "#read" do
37
- context "when offset and len inside range " do
37
+ context "when offset is positive " do
38
38
let ( :offset ) { 1 }
39
39
let ( :len ) { 10 }
40
40
46
46
expect ( subject . read ( offset , len ) . length ) . to eq ( 10 )
47
47
end
48
48
49
- it "returns an String with contents starting at provided offset" do
49
+ it "returns an String with _raw_data contents starting at provided offset" do
50
50
expect ( subject . read ( offset , len ) ) . to start_with ( 'BCD' )
51
51
end
52
52
end
53
+
54
+ context "when offset is negative" do
55
+ let ( :offset ) { -5 }
56
+ let ( :len ) { 2 }
57
+
58
+ it "returns an String" do
59
+ expect ( subject . read ( offset , len ) ) . to be_a_kind_of ( String )
60
+ end
61
+
62
+ it "returns an String of provided length" do
63
+ expect ( subject . read ( offset , len ) . length ) . to eq ( 2 )
64
+ end
65
+
66
+ it "offset is counted from the end of the _raw_data" do
67
+ expect ( subject . read ( offset , len ) ) . to eq ( 'LM' )
68
+ end
69
+ end
70
+
71
+ context "when offset is out of range" do
72
+ let ( :offset ) { 20 }
73
+ let ( :len ) { 2 }
74
+
75
+ it "returns nil" do
76
+ expect ( subject . read ( offset , len ) ) . to be_nil
77
+ end
78
+ end
79
+
80
+ context "when len is bigger than _raw_data" do
81
+ let ( :offset ) { 0 }
82
+ let ( :len ) { 20 }
83
+
84
+ it "returns an String" do
85
+ expect ( subject . read ( offset , len ) ) . to be_a_kind_of ( String )
86
+ end
87
+
88
+ it "returns an String truncated to available contents" do
89
+ expect ( subject . read ( offset , len ) . length ) . to eq ( raw_data . length )
90
+ end
91
+ end
53
92
end
54
93
55
94
describe "#subsource" do
You can’t perform that action at this time.
0 commit comments