summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-02 13:28:05 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-02 13:59:02 -0500
commit840292befd6ad78e018f5ea16bec80e83d910071 (patch)
treed98d75d5f2e8d9bfa7ceba880ebef23056ee51ef /src/test
parent9480794b277b5ce33e467578ed669996df576bb9 (diff)
Disallow sizes with increasing unit size
Things like 3B4T, 4B50B, 400 100 (meaning 4*1024**4+3, 54, and 500, respectively) are now disallowed. It is necessary to say 4T3B, 54B, 500 instead. I think this was confusing and error prone. As a special form, 400B 100 is allowed, i.e. "B" suffix is treated as different from "", although they mean the same thing.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-util.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 74f83a2629..1de06dbda8 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -460,21 +460,32 @@ static void test_parse_size(void) {
assert_se(parse_size("3.0 K", 1024, &bytes) == 0);
assert_se(bytes == 3*1024);
- assert_se(parse_size("3. 0 K", 1024, &bytes) == 0);
- assert_se(bytes == 3);
+ assert_se(parse_size("3. 0 K", 1024, &bytes) == -EINVAL);
assert_se(parse_size(" 4 M 11.5K", 1024, &bytes) == 0);
assert_se(bytes == 4*1024*1024 + 11 * 1024 + 512);
- assert_se(parse_size("3B3.5G", 1024, &bytes) == 0);
+ assert_se(parse_size("3B3.5G", 1024, &bytes) == -EINVAL);
+
+ assert_se(parse_size("3.5G3B", 1024, &bytes) == 0);
assert_se(bytes == 3ULL*1024*1024*1024 + 512*1024*1024 + 3);
- assert_se(parse_size("3B3G4T", 1024, &bytes) == 0);
+ assert_se(parse_size("3.5G 4B", 1024, &bytes) == 0);
+ assert_se(bytes == 3ULL*1024*1024*1024 + 512*1024*1024 + 4);
+
+ assert_se(parse_size("3B3G4T", 1024, &bytes) == -EINVAL);
+
+ assert_se(parse_size("4T3G3B", 1024, &bytes) == 0);
+ assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3);
+
+ assert_se(parse_size(" 4 T 3 G 3 B", 1024, &bytes) == 0);
assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3);
assert_se(parse_size("12P", 1024, &bytes) == 0);
assert_se(bytes == 12ULL * 1024*1024*1024*1024*1024);
+ assert_se(parse_size("12P12P", 1024, &bytes) == -EINVAL);
+
assert_se(parse_size("3E 2P", 1024, &bytes) == 0);
assert_se(bytes == (3 * 1024 + 2ULL) * 1024*1024*1024*1024*1024);