Skip to content

Commit

Permalink
Test helper function nextAligned
Browse files Browse the repository at this point in the history
Make sure the nextAligned function is giving a number that is equal or
larger than the input. Since the code does not work with
non-power-of-two alignments, that is not tested.

Signed-off-by: Marcelo E. Magallon <[email protected]>
  • Loading branch information
Marcelo E. Magallon authored and mem committed Apr 3, 2019
1 parent 22d2d2b commit a9c017e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/sif/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ const (
descrLen = 585
)

func TestNextAligned(t *testing.T) {
cases := []struct {
name string
offset int64
align int
expected int64
}{
{name: "align 0 to 1024", offset: 0, align: 1024, expected: 0},
{name: "align 1 to 1024", offset: 1, align: 1024, expected: 1024},
{name: "align 1023 to 1024", offset: 1023, align: 1024, expected: 1024},
{name: "align 1024 to 1024", offset: 1024, align: 1024, expected: 1024},
{name: "align 1025 to 1024", offset: 1025, align: 1024, expected: 2048},
}

for _, tc := range cases {
actual := nextAligned(tc.offset, tc.align)
if actual != tc.expected {
t.Errorf("nextAligned case: %q, offset: %d, align: %d, expecting: %d, actual: %d\n",
tc.name, tc.offset, tc.align, tc.expected, actual)
}
}
}

func TestDataStructs(t *testing.T) {
var header Header
var descr Descriptor
Expand Down
Binary file modified pkg/sif/testdata/testcontainer1.sif
Binary file not shown.

0 comments on commit a9c017e

Please sign in to comment.