2 * Copyright (C) - 2015 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 <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
[] = {
56 static const int num_valid_tests
= sizeof(valid_tests_inputs
) / sizeof(valid_tests_inputs
[0]);
58 /* Invalid test cases */
59 static char *invalid_tests_inputs
[] = {
64 "4611686018427387904s",
80 "14ms garbage after value",
83 static const int num_invalid_tests
= sizeof(invalid_tests_inputs
) / sizeof(invalid_tests_inputs
[0]);
85 static void test_utils_parse_time_suffix(void)
91 /* Test valid cases */
92 for (i
= 0; i
< num_valid_tests
; i
++) {
95 sprintf(name
, "valid test case: %s", valid_tests_inputs
[i
].input
);
97 ret
= utils_parse_time_suffix(valid_tests_inputs
[i
].input
, &result
);
98 ok(ret
== 0 && result
== valid_tests_inputs
[i
].expected_result
, name
);
101 /* Test invalid cases */
102 for (i
= 0; i
< num_invalid_tests
; i
++) {
105 sprintf(name
, "invalid test case: %s", invalid_tests_inputs
[i
]);
107 ret
= utils_parse_time_suffix(invalid_tests_inputs
[i
], &result
);
112 int main(int argc
, char **argv
)
114 plan_tests(num_valid_tests
+ num_invalid_tests
);
116 diag("utils_parse_time_suffix tests");
118 test_utils_parse_time_suffix();
120 return exit_status();