aa74bc199971ebed780ec9e7f3f107fb8857f95c
[libguestfs.git] / regressions / rhbz557655.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2009 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # Regression test for:
20 # https://bugzilla.redhat.com/show_bug.cgi?id=557655
21 # "guestfish number parsing should not use atoi, should support '0...' for octal and '0x...' for hexadecimal"
22
23 set -e
24 rm -f test.out
25 export LANG=C
26 unset LIBGUESTFS_DEBUG
27
28 ../fish/guestfish >> test.out 2>&1 <<EOF
29 # set-memsize is just a convenient non-daemon function that
30 # takes a single integer argument.
31 set-memsize 0
32 get-memsize
33 set-memsize 0x10
34 get-memsize
35 set-memsize 010
36 get-memsize
37 set-memsize -1073741824
38 get-memsize
39 set-memsize 1073741823
40 get-memsize
41
42 # the following should all provoke error messages:
43 -set-memsize -9000000000000000
44 -set-memsize 9000000000000000
45 -set-memsize 0x900000000000
46 -set-memsize 07777770000000000000
47 -set-memsize ABC
48 -set-memsize 09
49 -set-memsize 123K
50 -set-memsize 123L
51 EOF
52
53 ../fish/guestfish >> test.out 2>&1 <<EOF
54 alloc test1.img 10M
55 run
56 part-disk /dev/sda mbr
57 mkfs ext2 /dev/sda1
58 mount /dev/sda1 /
59
60 touch /test
61
62 # truncate-size takes an Int64 argument
63 truncate-size /test 1234
64 filesize /test
65 truncate-size /test 0x4d2
66 filesize /test
67 truncate-size /test 02322
68 filesize /test
69
70 # should parse OK, but underlying filesystem will reject it:
71 -truncate-size /test 0x7fffffffffffffff
72
73 # larger than 64 bits, should be an error:
74 -truncate-size /test 0x10000000000000000
75
76 # these should all provoke parse errors:
77 -truncate-size /test ABC
78 -truncate-size /test 09
79 -truncate-size /test 123K
80 -truncate-size /test 123L
81 EOF
82
83 diff -u test.out rhbz557655-expected.out
84 rm test.out test1.img