Skip to content

Commit

Permalink
Test open offset and length combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Jan 19, 2025
1 parent 6b2533e commit 3291929
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
45 changes: 39 additions & 6 deletions macho/universal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,55 @@ import { Universal } from './universal.ts';

const fixtures = fixtureMachos();

for (const { kind, arch, file, archs } of fixtures) {
for (const [index, { kind, arch, file, archs }] of fixtures.entries()) {
Deno.test(`${kind}: ${arch}: ${file}`, async () => {
const [macho] = await fixtureMacho(kind, arch, [file]);
const blob = new Blob([macho]);
const uni = new Universal();

await uni.open(blob);
switch (index % 4) {
case 0: {
const blob = new Blob([macho]);
await uni.open(blob);
assertEquals(uni.offset(), 0);
assertEquals(uni.length(), 0);
break;
}
case 1: {
const blob = new Blob([macho]);
await uni.open(blob, 0, blob.size);
assertEquals(uni.offset(), 0);
assertEquals(uni.length(), blob.size);
break;
}
case 2: {
const blob = new Blob([
new ArrayBuffer(3),
macho,
new ArrayBuffer(3),
]);
await uni.open(blob, 3);
assertEquals(uni.offset(), 3);
assertEquals(uni.length(), 0);
break;
}
case 3: {
const blob = new Blob([
new ArrayBuffer(3),
macho,
new ArrayBuffer(3),
]);
await uni.open(blob, 3, macho.byteLength);
assertEquals(uni.offset(), 3);
assertEquals(uni.length(), macho.byteLength);
break;
}
}
assertEquals(uni.isUniversal(), archs.size > 1);

const architectures = new Set<Architecture>();
uni.architectures(architectures);

assertEquals(architectures.size, archs.size);

uni.architectures(architectures);

assertEquals(architectures.size, archs.size);
});
}
18 changes: 18 additions & 0 deletions macho/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,22 @@ export class Universal {
public isUniversal(): boolean {
return !!this.mArchList;
}

/**
* Get offset in reader.
*
* @returns Byte offset in reader.
*/
public offset(): number {
return this.mBase;
}

/**
* Get length in reader.
*
* @returns Byte length in reader.
*/
public length(): number {
return this.mLength;
}
}

0 comments on commit 3291929

Please sign in to comment.