Skip to content

Commit b9e8c5f

Browse files
committed
libutil/test: add encode_size() unit tests
Problem: There are no tests of the encode_size() convenience function. Add a set of unit tests for this interface.
1 parent 851610b commit b9e8c5f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/common/libutil/test/parse_size.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,40 @@ static void test_parse (void)
8888
}
8989
}
9090

91+
const struct entry encode_tests[] = {
92+
{ "0", 0, 0 },
93+
{ "1K", 1024, 0 },
94+
{ "1.5K", 1024*1.5, 0 },
95+
{ "4K", 4096, 0 },
96+
{ "1M", 1048576, 0 },
97+
{ "1.000001M", 1048577, 0 },
98+
{ "8.75M", 1024*1024*8.75, 0 },
99+
{ "2G", 2147483648, 0 },
100+
{ "512", 512, 0 },
101+
{ "1.22G", 1024*1024*1024*1.22, 0 },
102+
{ "4T", 4398046511104, 0 },
103+
{ "4.04T", 4398046511104*1.01, 0 },
104+
{ "8.5P", 1125899906842624UL * 8.5, 0 },
105+
{ "16E", UINT64_MAX, 0 },
106+
};
107+
108+
static void test_encode (void)
109+
{
110+
for (int i = 0; i < ARRAY_SIZE (encode_tests); i++) {
111+
const struct entry *te = &encode_tests[i];
112+
const char *result = encode_size (te->val);
113+
is (result, te->s,
114+
"encode_size (%ju) = %s",
115+
(uintmax_t) te->val,
116+
result);
117+
}
118+
}
119+
91120
int main (int argc, char **argv)
92121
{
93122
plan (NO_PLAN);
94123
test_parse ();
124+
test_encode ();
95125
done_testing ();
96126
return 0;
97127
}

0 commit comments

Comments
 (0)