-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mattrberry/verify
Added `verify` arg, for things such as checksums
- Loading branch information
Showing
4 changed files
with
138 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require "./helper" | ||
|
||
describe BinData do | ||
it "succeeds reading when the verify proc is true" do | ||
io = IO::Memory.new | ||
io.write_byte 0x02 | ||
io.write_byte 0x05 | ||
io.write_byte 0x06 | ||
io.write_byte 0x0B | ||
io.rewind | ||
|
||
r = io.read_bytes VerifyData | ||
r.checksum.should eq 0x0B | ||
end | ||
|
||
it "succeeds writing when the verify proc is true" do | ||
io = IO::Memory.new | ||
io.write_byte 0x02 | ||
io.write_byte 0x05 | ||
io.write_byte 0x06 | ||
io.write_byte 0x0B | ||
io.rewind | ||
|
||
r = VerifyData.new | ||
r.size = 0x02 | ||
r.bytes = Bytes.new 2 | ||
r.bytes[0] = 0x05 | ||
r.bytes[1] = 0x06 | ||
r.checksum = 0x0B | ||
io2 = IO::Memory.new | ||
r.write io2 | ||
io2.rewind | ||
|
||
io2.to_slice.should eq io.to_slice | ||
end | ||
|
||
it "raised an exception when it fails to verify on read" do | ||
io = IO::Memory.new | ||
io.write_byte 0x02 | ||
io.write_byte 0x05 | ||
io.write_byte 0x06 | ||
io.write_byte 0xFF | ||
io.rewind | ||
|
||
expect_raises BinData::VerificationException, "Failed to verify reading basic at VerifyData.checksum" do | ||
r = io.read_bytes VerifyData | ||
end | ||
end | ||
|
||
it "raised an exception when it fails to verify on write" do | ||
io = IO::Memory.new | ||
io.write_byte 0x02 | ||
io.write_byte 0x05 | ||
io.write_byte 0x06 | ||
io.write_byte 0x0B | ||
io.rewind | ||
|
||
r = io.read_bytes VerifyData | ||
r.bytes[0] = 0x0F | ||
io2 = IO::Memory.new | ||
|
||
expect_raises BinData::VerificationException, "Failed to verify writing basic at VerifyData.checksum" do | ||
r.write io2 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters