From 6bf3e10eed8ae35f0aaeb08f7a4594d1668fe6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 15 Mar 2022 06:26:48 +0200 Subject: [PATCH] test packed users iterator --- README.md | 2 +- src/sections.zig | 21 +++++++++++++++------ src/user.zig | 8 +++----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 57bef21..adbeb42 100644 --- a/README.md +++ b/README.md @@ -377,7 +377,7 @@ Section creation order: 1. ✅ userGids. No dependencies. 1. ✅ Users. Requires `userGids` and shell. 1. ✅ Groupmembers. Requires Users. -1. Groups. Requires Groupmembers. +1. ✅ Groups. Requires Groupmembers. 1. `idx_*`. Requires offsets to Groups and Users. 1. Header. diff --git a/src/sections.zig b/src/sections.zig index bd07010..87f7539 100644 --- a/src/sections.zig +++ b/src/sections.zig @@ -563,7 +563,7 @@ test "test corpus" { try testing.expectEqual(groupsOfVidmantas[2], g_all); } -test "test groups and group members" { +test "test groups, group members and users" { const allocator = testing.allocator; var corpus = try testCorpus(allocator); defer corpus.deinit(); @@ -572,12 +572,12 @@ test "test groups and group members" { defer sections.deinit(); const blob = sections.group_members.blob; - var group_idx: usize = 0; - while (group_idx < corpus.groups.len) : (group_idx += 1) { - const offset = sections.group_members.idx2offset[group_idx]; + var i: usize = 0; + while (i < corpus.groups.len) : (i += 1) { + const offset = sections.group_members.idx2offset[i]; var vit = try compress.VarintSliceIterator(blob[offset..]); var it = compress.DeltaDecompressionIterator(&vit); - for (corpus.group2users[group_idx]) |user_idx| { + for (corpus.group2users[i]) |user_idx| { const got_user_offset = (try it.next()).?; const want_user_offset = sections.users.idx2offset[user_idx]; try testing.expectEqual(got_user_offset, want_user_offset); @@ -589,7 +589,16 @@ test "test groups and group members" { sections.users.blob, sections.shell_reader, ); - _ = it; + i = 0; + while (i < corpus.users.len) : (i += 1) { + const user = (try it.next()).?; + try testing.expectEqual(corpus.users[i].uid, user.uid()); + try testing.expectEqual(corpus.users[i].gid, user.gid()); + try testing.expectEqualStrings(corpus.users[i].name, user.name()); + try testing.expectEqualStrings(corpus.users[i].gecos, user.gecos()); + try testing.expectEqualStrings(corpus.users[i].home, user.home()); + try testing.expectEqualStrings(corpus.users[i].shell, user.shell(sections.shell_reader)); + } } test "userGids" { diff --git a/src/user.zig b/src/user.zig index 4da4621..e66f98c 100644 --- a/src/user.zig +++ b/src/user.zig @@ -338,9 +338,10 @@ test "construct PackedUser section" { .shell = "/", } }; var shellIndex = testShellIndex(testing.allocator); + const additional_gids = math.maxInt(u64); defer shellIndex.deinit(); for (users) |user| { - try PackedUser.packTo(&buf, user, math.maxInt(u64), shellIndex); + try PackedUser.packTo(&buf, user, additional_gids, shellIndex); try pad.arrayList(&buf, PackedUser.alignment_bits); } @@ -349,10 +350,7 @@ test "construct PackedUser section" { while (try it1.next()) |user| : (i += 1) { try testing.expectEqual(users[i].uid, user.uid()); try testing.expectEqual(users[i].gid, user.gid()); - try testing.expectEqual( - @as(u64, math.maxInt(u64)), - user.additionalGidsOffset(), - ); + try testing.expectEqual(user.additionalGidsOffset(), additional_gids); try testing.expectEqualStrings(users[i].name, user.name()); try testing.expectEqualStrings(users[i].gecos, user.gecos()); try testing.expectEqualStrings(users[i].home, user.home());