2 * UCW Library -- Test of Tableprinter Types
4 * (c) 2014 Robert Kessl <robert.kessl@economia.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/mempool.h>
12 #include <ucw/xtypes.h>
13 #include <ucw/table-types.h>
20 static void test_size_correct(struct fastbuf *out)
22 const char *size_strs[] = {
34 4 * 1024LLU * 1024LLU,
35 4 * 1024LLU * 1024LLU * 1024LLU,
36 4 * 1024LLU * 1024LLU * 1024LLU * 1024LLU
39 struct mempool *pool = mp_new(4096);
42 while(size_strs[i] != NULL) {
44 const char *parse_err = xt_size.parse(size_strs[i], &result, pool);
48 ASSERT_MSG(size_parsed[i] == result, "xt_size.parse parsed an incorrect value.");
49 const char *result_str = xt_size.format(&result, i | SIZE_UNITS_FIXED, pool);
50 bprintf(out, "%s %s\n", size_strs[i], result_str);
58 static void test_size_parse_errors(struct fastbuf *out)
60 const char *size_strs[] = {
68 struct mempool *pool = mp_new(4096);
70 while(size_strs[i] != NULL) {
72 const char *parse_err = xt_size.parse(size_strs[i], &result, pool);
73 if(parse_err == NULL) {
74 bprintf(out, "xt_size.parse did not result in error while parsing: '%s'.\n", size_strs[i]);
76 bprintf(out, "xt_size.parse error: '%s'.\n", parse_err);
88 out = bfdopen_shared(1, 4096);
90 test_size_correct(out);
91 test_size_parse_errors(out);