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;
31 struct valid_test_input
{
33 uint64_t expected_result
;
36 /* Valid test cases */
37 static struct valid_test_input valid_tests_inputs
[] = {
44 { "0x1234k", 4771840 },
46 { "1024G", 1099511627776 },
69 { "0X40G", 68719476736 },
73 { "020G", 17179869184 },
76 { "0XA0M", 167772160 },
77 { "0xA0G", 171798691840 },
79 static const int num_valid_tests
= sizeof(valid_tests_inputs
) / sizeof(valid_tests_inputs
[0]);
81 /* Invalid test cases */
82 static char *invalid_tests_inputs
[] = {
87 "4611686018427387904G",
104 static const int num_invalid_tests
= sizeof(invalid_tests_inputs
) / sizeof(invalid_tests_inputs
[0]);
106 static void test_utils_parse_size_suffix(void)
112 /* Test valid cases */
113 for (i
= 0; i
< num_valid_tests
; i
++) {
115 sprintf(name
, "valid test case: %s", valid_tests_inputs
[i
].input
);
117 ret
= utils_parse_size_suffix(valid_tests_inputs
[i
].input
, &result
);
118 ok(ret
== 0 && result
== valid_tests_inputs
[i
].expected_result
, name
);
121 /* Test invalid cases */
122 for (i
= 0; i
< num_invalid_tests
; i
++) {
124 sprintf(name
, "invalid test case: %s", invalid_tests_inputs
[i
]);
126 ret
= utils_parse_size_suffix(invalid_tests_inputs
[i
], &result
);
131 int main(int argc
, char **argv
)
133 plan_tests(num_valid_tests
+ num_invalid_tests
);
135 diag("utils_parse_size_suffix tests");
137 test_utils_parse_size_suffix();
139 return exit_status();