Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: Add missing tests #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions spec/lib/rex/arch/x86_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1039,4 +1039,45 @@
end
end

describe ".register_names_to_ids" do
subject { described_class.register_names_to_ids(registers) }

context "when registers are not provided" do
let(:registers) { nil }

it "returns an empty Array" do
is_expected.to be_an Array
is_expected.to be_empty
end
end

context "when registers are invalid" do
let(:registers) { "not-a-register" }

it "raises an error" do
expect { subject }.to raise_error(NameError)
end
end

context "when registers are valid" do
let(:registers) { " eax, ecx, edx, ebx, esp, ebp, esi, edi " }

it "returns an Array" do
is_expected.to be_an Array
end

it "returns an Integer for each register" do
expect(subject.length).to eq(8)
expect(subject[0]).to be_an Integer
expect(subject[1]).to be_an Integer
expect(subject[2]).to be_an Integer
expect(subject[3]).to be_an Integer
expect(subject[4]).to be_an Integer
expect(subject[5]).to be_an Integer
expect(subject[6]).to be_an Integer
expect(subject[7]).to be_an Integer
end
end
end

end
13 changes: 13 additions & 0 deletions spec/lib/rex/arch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@
end
end

context "when arch is ARCH_PPCE500V2" do
let(:arch) { Rex::Arch::ARCH_PPCE500V2 }
let(:addr) { 0x41424344 }
it "packs addr as 32-bit unsigned, big-endian" do
is_expected.to eq("ABCD")
end
end

context "when arch is ARCH_SPARC" do
let(:arch) { Rex::Arch::ARCH_SPARC }
let(:addr) { 0x41424344 }
Expand Down Expand Up @@ -230,13 +238,17 @@
{
Rex::Arch::ARCH_X86 => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_X86_64 => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_X64 => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_MIPS => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_MIPSLE => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_MIPSBE => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_MIPS64 => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_MIPS64LE => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_PPC => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_PPC64LE => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_PPCE500V2 => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_SPARC => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_SPARC64 => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_ARMLE => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_ARMBE => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_AARCH64 => Rex::Arch::ENDIAN_LITTLE,
Expand All @@ -245,6 +257,7 @@
Rex::Arch::ARCH_RISCV64BE => Rex::Arch::ENDIAN_BIG,
Rex::Arch::ARCH_RISCV64LE => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_LOONGARCH64 => Rex::Arch::ENDIAN_LITTLE,
Rex::Arch::ARCH_ZARCH => Rex::Arch::ENDIAN_BIG,
}
end
subject { described_class.endian(arch) }
Expand Down