-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Zxilly <[email protected]>
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 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,38 @@ | ||
package wrapper | ||
|
||
import ( | ||
"debug/elf" | ||
"encoding/binary" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGoArchReturnsExpectedArchitectures(t *testing.T) { | ||
tests := []struct { | ||
machine elf.Machine | ||
expectedArch string | ||
byteOrder binary.ByteOrder | ||
}{ | ||
{elf.EM_386, "386", binary.LittleEndian}, | ||
{elf.EM_X86_64, "amd64", binary.LittleEndian}, | ||
{elf.EM_ARM, "arm", binary.LittleEndian}, | ||
{elf.EM_AARCH64, "arm64", binary.LittleEndian}, | ||
{elf.EM_PPC64, "ppc64", binary.BigEndian}, // Adjusted for big endian | ||
{elf.EM_PPC64, "ppc64le", binary.LittleEndian}, // Explicitly little endian | ||
{elf.EM_S390, "s390x", binary.BigEndian}, | ||
{0, "", binary.LittleEndian}, // Test for an unsupported machine type | ||
} | ||
|
||
for _, test := range tests { | ||
mockFile := new(elf.File) | ||
mockFile.FileHeader = elf.FileHeader{ | ||
Machine: test.machine, | ||
ByteOrder: test.byteOrder, | ||
} | ||
wrapper := ElfWrapper{file: mockFile} | ||
|
||
arch := wrapper.GoArch() | ||
assert.Equal(t, test.expectedArch, arch) | ||
} | ||
} |
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,28 @@ | ||
package wrapper | ||
|
||
import ( | ||
"debug/macho" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGoArchReturnsCorrectArchitectureString(t *testing.T) { | ||
tests := []struct { | ||
cpu macho.Cpu | ||
expected string | ||
}{ | ||
{macho.Cpu386, "386"}, | ||
{macho.CpuAmd64, "amd64"}, | ||
{macho.CpuArm, "arm"}, | ||
{macho.CpuArm64, "arm64"}, | ||
{macho.CpuPpc64, "ppc64"}, | ||
{macho.Cpu(0), ""}, // Unsupported CPU type | ||
} | ||
|
||
for _, test := range tests { | ||
m := MachoWrapper{file: &macho.File{FileHeader: macho.FileHeader{Cpu: test.cpu}}} | ||
result := m.GoArch() | ||
assert.Equal(t, test.expected, result) | ||
} | ||
} |
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,32 @@ | ||
package wrapper | ||
|
||
import ( | ||
"debug/pe" | ||
"testing" | ||
) | ||
|
||
func TestGoArchReturnsExpectedArchitectureString(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
machine uint16 | ||
expected string | ||
}{ | ||
{"Returns386ForI386Machine", pe.IMAGE_FILE_MACHINE_I386, "386"}, | ||
{"ReturnsAmd64ForAmd64Machine", pe.IMAGE_FILE_MACHINE_AMD64, "amd64"}, | ||
{"ReturnsArmForArmMachine", pe.IMAGE_FILE_MACHINE_ARMNT, "arm"}, | ||
{"ReturnsArm64ForArm64Machine", pe.IMAGE_FILE_MACHINE_ARM64, "arm64"}, | ||
{"ReturnsEmptyStringForUnknownMachine", 0xFFFF, ""}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
mockFile := &pe.File{FileHeader: pe.FileHeader{Machine: test.machine}} | ||
wrapper := PeWrapper{file: mockFile} | ||
|
||
result := wrapper.GoArch() | ||
if result != test.expected { | ||
t.Errorf("Expected %s, got %s for machine type %v", test.expected, result, test.machine) | ||
} | ||
}) | ||
} | ||
} |
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,12 @@ | ||
package wrapper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewWrapper(t *testing.T) { | ||
ret := NewWrapper(nil) | ||
assert.Equal(t, nil, ret) | ||
} |