2 * Copyright (C) - 2013 Simon Marchi <simon.marchi@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by as
6 * published by the Free Software Foundation; only version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <src/common/utils.h>
27 int lttng_opt_quiet
= 1;
28 int lttng_opt_verbose
= 3;
30 struct valid_test_input
{
32 uint64_t expected_result
;
35 /* Valid test cases */
36 static struct valid_test_input valid_tests_inputs
[] = {
43 { "0x1234k", 4771840 },
45 { "1024G", 1099511627776 },
47 static const int num_valid_tests
= sizeof(valid_tests_inputs
) / sizeof(valid_tests_inputs
[0]);
49 /* Invalid test cases */
50 static char *invalid_tests_inputs
[] = { "", "-1", "k", "4611686018427387904G" };
51 static const int num_invalid_tests
= sizeof(invalid_tests_inputs
) / sizeof(invalid_tests_inputs
[0]);
53 static void test_utils_parse_size_suffix(void)
59 /* Test valid cases */
60 for (i
= 0; i
< num_valid_tests
; i
++) {
62 sprintf(name
, "valid test case: %s", valid_tests_inputs
[i
].input
);
64 ret
= utils_parse_size_suffix(valid_tests_inputs
[i
].input
, &result
);
65 ok(ret
== 0 && result
== valid_tests_inputs
[i
].expected_result
, name
);
68 /* Test invalid cases */
69 for (i
= 0; i
< num_invalid_tests
; i
++) {
71 sprintf(name
, "invalid test case: %s", invalid_tests_inputs
[i
]);
73 ret
= utils_parse_size_suffix(invalid_tests_inputs
[i
], &result
);
78 int main(int argc
, char **argv
)
80 plan_tests(num_valid_tests
+ num_invalid_tests
);
82 diag("utils_parse_size_suffix tests");
84 test_utils_parse_size_suffix();