spec/formatting/binary/string_spec.rb in ronin-0.1.4 vs spec/formatting/binary/string_spec.rb in ronin-0.2.0

- old
+ new

@@ -1,15 +1,77 @@ require 'ronin/formatting/binary' require 'spec_helper' describe String do - before(:all) do - @packed_integer = "" + it "should provide String#depack" do + String.instance_method('depack').should_not be_nil end - it "should provide String#depack" do - @packed_integer.respond_to?('depack').should == true + it "should provide String#hex_escape" do + String.instance_method('hex_escape').should_not be_nil + end + + it "should provide String#xor" do + String.instance_method('xor').should_not be_nil + end + + describe "pack" do + before(:all) do + @integer = 0x1337 + + @i386_packed_int = "7\023\000\000" + @i386_packed_short = "7\023" + @i386_packed_long = "7\023\000\000" + @i386_packed_quad = "7\023\000\000\000\000\000\000" + + @ppc_packed_int = "\000\000\0237" + @ppc_packed_short = "\0237" + @ppc_packed_long = "\000\000\0237" + @ppc_packed_quad = "\000\000\000\000\000\000\0237" + end + + it "should pack itself for a little-endian architecture" do + @i386_packed_int.depack(Arch.i386).should == @integer + end + + it "should pack itself as a short for a little-endian architecture" do + @i386_packed_short.depack(Arch.i386,2).should == @integer + end + + it "Integer#pack should pack itself as a long for a little-endian architecture" do + @i386_packed_long.depack(Arch.i386,4).should == @integer + end + + it "should pack itself as a quad for a little-endian architecture" do + @i386_packed_quad.depack(Arch.i386,8).should == @integer + end + + it "should pack itself for a big-endian architecture" do + @ppc_packed_int.depack(Arch.ppc).should == @integer + end + + it "should pack itself as a short for a big-endian architecture" do + @ppc_packed_short.depack(Arch.ppc,2).should == @integer + end + + it "should pack itself as a long for a big-endian architecture" do + @ppc_packed_long.depack(Arch.ppc,4).should == @integer + end + + it "should pack itself as a quad for a big-endian architecture" do + @ppc_packed_quad.depack(Arch.ppc,8).should == @integer + end + end + + describe "hex_escape" do + before(:all) do + @binary_string = "hello\x4e" + end + + it "should hex escape a String" do + @binary_string.hex_escape.should == "\\x68\\x65\\x6c\\x6c\\x6f\\x4e" + end end describe "xor" do before(:all) do @string = 'hello'