|
92 | 92 | end
|
93 | 93 |
|
94 | 94 | describe "#subsource" do
|
| 95 | + let(:offset) { 2 } |
| 96 | + let(:len) { 10 } |
95 | 97 |
|
| 98 | + it "returns a new Rex::ImageSource::Memory" do |
| 99 | + expect(subject.subsource(offset, len)).to be_kind_of(described_class) |
| 100 | + end |
| 101 | + |
| 102 | + it "returns a new Rex::ImageSource::Memory with provided size" do |
| 103 | + expect(subject.subsource(offset, len).size).to eq(len) |
| 104 | + end |
| 105 | + |
| 106 | + it "returns a new Rex::ImageSource::Memory with file_offset added to the original" do |
| 107 | + expect(subject.subsource(offset, len).file_offset).to eq(offset + subject.file_offset) |
| 108 | + end |
| 109 | + |
| 110 | + it "returns a new Rex::ImageSource::Memory with rawdata from the original" do |
| 111 | + expect(subject.subsource(offset, len).rawdata).to eq(subject.rawdata[offset, len]) |
| 112 | + end |
| 113 | + |
| 114 | + context "when offset is out of range" do |
| 115 | + let(:offset) { 20 } |
| 116 | + let(:len) { 2 } |
| 117 | + |
| 118 | + it "raises an error" do |
| 119 | + expect { subject.subsource(offset, len) }.to raise_error(NoMethodError) |
| 120 | + end |
| 121 | + end |
| 122 | + |
| 123 | + context "when len is bigger than source rawdata" do |
| 124 | + let(:offset) { 2 } |
| 125 | + let(:len) { 20 } |
| 126 | + |
| 127 | + it "returns a new Rex::ImageSource::Memory" do |
| 128 | + expect(subject.subsource(offset, len)).to be_kind_of(described_class) |
| 129 | + end |
| 130 | + |
| 131 | + it "returns a new Rex::ImageSource::Memory with provided size truncated" do |
| 132 | + expect(subject.subsource(offset, len).size).to eq(14) |
| 133 | + end |
| 134 | + |
| 135 | + it "returns a new Rex::ImageSource::Memory with file_offset added to the original" do |
| 136 | + expect(subject.subsource(offset, len).file_offset).to eq(offset + subject.file_offset) |
| 137 | + end |
| 138 | + |
| 139 | + it "returns a new Rex::ImageSource::Memory with rawdata truncated" do |
| 140 | + expect(subject.subsource(offset, len).rawdata).to eq('CDEFGHIJKLMNOP') |
| 141 | + end |
| 142 | + end |
96 | 143 | end
|
97 | 144 |
|
98 | 145 | describe "#close" do
|
|
0 commit comments