summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2011-01-01 22:45:29 +0100
committerKarel Zak <kzak@redhat.com>2011-01-03 12:28:48 +0100
commit013bff51a67fe5907532639d35f9d9f1df2c7570 (patch)
treef270146bbbcf19679c993ce1d0be62f03d4cd4e8
parent462363888283fa14db5ded75728632df237e5196 (diff)
downloadutil-linux-old-013bff51a67fe5907532639d35f9d9f1df2c7570.tar.gz
tests: fix strtosize() test
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--lib/Makefile.am3
-rw-r--r--lib/strutils.c24
-rw-r--r--tests/commands.sh.in2
-rw-r--r--tests/expected/misc/strtosize8
-rwxr-xr-xtests/ts/misc/strtosize68
5 files changed, 65 insertions, 40 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 36396a38..0f13237f 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -3,7 +3,7 @@ include $(top_srcdir)/config/include-Makefile.am
AM_CPPFLAGS += -DTEST_PROGRAM
noinst_PROGRAMS = test_blkdev test_ismounted test_wholedisk test_mangle \
- test_tt test_canonicalize test_at
+ test_tt test_canonicalize test_at test_strutils
if LINUX
if HAVE_CPU_SET_T
noinst_PROGRAMS += test_cpuset
@@ -15,6 +15,7 @@ test_ismounted_SOURCES = ismounted.c
test_wholedisk_SOURCES = wholedisk.c
test_mangle_SOURCES = mangle.c
test_at_SOURCES = at.c
+test_strutils_SOURCES = strutils.c
if LINUX
test_cpuset_SOURCES = cpuset.c
endif
diff --git a/lib/strutils.c b/lib/strutils.c
index e8e86865..9a59e67b 100644
--- a/lib/strutils.c
+++ b/lib/strutils.c
@@ -273,3 +273,27 @@ char *size_to_human_string(uint64_t bytes)
return strdup(buf);
}
+
+
+#ifdef TEST_PROGRAM
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
+
+int main(int argc, char *argv[])
+{
+ uintmax_t size = 0;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <number>[suffix]\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ if (strtosize(argv[1], &size))
+ errx(EXIT_FAILURE, "invalid size '%s' value", argv[1]);
+
+ printf("%25s : %20ju\n", argv[1], size);
+ return EXIT_FAILURE;
+}
+#endif /* TEST_PROGRAM */
diff --git a/tests/commands.sh.in b/tests/commands.sh.in
index 19193922..dcd1a30f 100644
--- a/tests/commands.sh.in
+++ b/tests/commands.sh.in
@@ -12,7 +12,7 @@ TS_HELPER_BYTESWAP="$top_builddir/tests/helpers/test_byteswap"
TS_HELPER_MD5="$top_builddir/tests/helpers/test_md5"
TS_HELPER_ISMOUNTED="$top_builddir/lib/test_ismounted"
-TS_HELPER_STRTOSIZE="$top_builddir/lib/test_strtosize"
+TS_HELPER_STRUTILS="$top_builddir/lib/test_strutils"
TS_HELPER_CPUSET="$top_builddir/lib/test_cpuset"
# libmount
diff --git a/tests/expected/misc/strtosize b/tests/expected/misc/strtosize
index 04a2d590..d1c039d2 100644
--- a/tests/expected/misc/strtosize
+++ b/tests/expected/misc/strtosize
@@ -1,4 +1,4 @@
-test_strtosize: invalid size '-1' value
+test_strutils: invalid size '-1' value
0 : 0
1 : 1
123 : 123
@@ -21,10 +21,10 @@ test_strtosize: invalid size '-1' value
1TB : 1000000000000
1PB : 1000000000000000
1EB : 1000000000000000000
-test_strtosize: invalid size '' value
-test_strtosize: invalid size ' ' value
+test_strutils: invalid size '' value
+test_strutils: invalid size ' ' value
1 : 1
-test_strtosize: invalid size '1 ' value
+test_strutils: invalid size '1 ' value
0x0a : 10
0xff00 : 65280
0x80000000 : 2147483648
diff --git a/tests/ts/misc/strtosize b/tests/ts/misc/strtosize
index c1ed2448..7fb2ff99 100755
--- a/tests/ts/misc/strtosize
+++ b/tests/ts/misc/strtosize
@@ -21,40 +21,40 @@ TS_DESC="strtosize"
. $TS_TOPDIR/functions.sh
ts_init "$*"
-$TS_HELPER_STRTOSIZE -1 >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 0 >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1 >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 123 >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 18446744073709551615 >> $TS_OUTPUT 2>&1
-
-$TS_HELPER_STRTOSIZE 1K >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1KiB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1M >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1MiB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1G >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1GiB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1T >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1TiB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1P >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1PiB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1E >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1EiB >> $TS_OUTPUT 2>&1
-
-$TS_HELPER_STRTOSIZE 1KB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1MB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1GB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1TB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1PB >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 1EB >> $TS_OUTPUT 2>&1
-
-$TS_HELPER_STRTOSIZE "" >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE " " >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE " 1" >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE "1 " >> $TS_OUTPUT 2>&1
-
-$TS_HELPER_STRTOSIZE 0x0a >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 0xff00 >> $TS_OUTPUT 2>&1
-$TS_HELPER_STRTOSIZE 0x80000000 >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS -1 >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 0 >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1 >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 123 >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 18446744073709551615 >> $TS_OUTPUT 2>&1
+
+$TS_HELPER_STRUTILS 1K >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1KiB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1M >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1MiB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1G >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1GiB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1T >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1TiB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1P >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1PiB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1E >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1EiB >> $TS_OUTPUT 2>&1
+
+$TS_HELPER_STRUTILS 1KB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1MB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1GB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1TB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1PB >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 1EB >> $TS_OUTPUT 2>&1
+
+$TS_HELPER_STRUTILS "" >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS " " >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS " 1" >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS "1 " >> $TS_OUTPUT 2>&1
+
+$TS_HELPER_STRUTILS 0x0a >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 0xff00 >> $TS_OUTPUT 2>&1
+$TS_HELPER_STRUTILS 0x80000000 >> $TS_OUTPUT 2>&1
ts_finalize