X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Funit%2Ftest_utils_parse_time_suffix.c;h=6a1c3280bc4f48fa2ff9bd357db4396b34bfd222;hp=96482769bb9b87008a7de50cca73a9d3ac6acb7b;hb=refs%2Fheads%2Fsow-2019-0002-rev1;hpb=7010c0332387eea98b52f301458d481f151840a6 diff --git a/tests/unit/test_utils_parse_time_suffix.c b/tests/unit/test_utils_parse_time_suffix.c index 96482769b..6a1c3280b 100644 --- a/tests/unit/test_utils_parse_time_suffix.c +++ b/tests/unit/test_utils_parse_time_suffix.c @@ -1,23 +1,14 @@ /* - * Copyright (C) - 2015 Simon Marchi + * Copyright (C) 2015 Simon Marchi * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by as - * published by the Free Software Foundation; only version 2 of the License. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include #include +#include #include @@ -29,7 +20,7 @@ int lttng_opt_verbose = 3; int lttng_opt_mi; struct valid_test_input { - char *input; + const char *input; uint64_t expected_result; }; @@ -37,16 +28,25 @@ struct valid_test_input { static struct valid_test_input valid_tests_inputs[] = { { "0", 0 }, { "1234", 1234 }, - { "0u", 0 }, - { "1234u", 1234 }, - { "16m", 16000 }, - { "128m", 128000 }, + { "1234us", 1234 }, + { "16ms", 16000 }, + { "128ms", 128000 }, { "32s", 32000000 }, + { "1m", 60000000 }, + { "20m", 1200000000 }, + { "1h", 3600000000 }, + { "5h", 18000000000 }, { "00", 0 }, - { "0m", 0 }, + { "0us", 0 }, + { "0ms", 0 }, { "0s", 0 }, - { "00m", 0 }, + { "0m", 0 }, + { "0h", 0 }, + { "00us", 0 }, + { "00ms", 0 }, { "00s", 0 }, + { "00m", 0 }, + { "00h", 0 }, { "12ms", 12000 }, { "3597us", 3597 }, { "+5", 5 }, @@ -56,7 +56,7 @@ static struct valid_test_input valid_tests_inputs[] = { static const int num_valid_tests = sizeof(valid_tests_inputs) / sizeof(valid_tests_inputs[0]); /* Invalid test cases */ -static char *invalid_tests_inputs[] = { +static const char *invalid_tests_inputs[] = { "", " ", "-1", @@ -79,6 +79,14 @@ static char *invalid_tests_inputs[] = { "14ns", "14ms garbage after value", "0x14s", + "0u", + "5mS", + "5Ms", + "12ussr", + "67msrp", + "14si", + "12mo", + "53hi", }; static const int num_invalid_tests = sizeof(invalid_tests_inputs) / sizeof(invalid_tests_inputs[0]); @@ -90,11 +98,10 @@ static void test_utils_parse_time_suffix(void) /* Test valid cases */ for (i = 0; i < num_valid_tests; i++) { - char name[100]; - - sprintf(name, "valid test case: %s", valid_tests_inputs[i].input); + char name[256]; ret = utils_parse_time_suffix(valid_tests_inputs[i].input, &result); + sprintf(name, "valid test case: %s expected %" PRIu64, valid_tests_inputs[i].input, result); ok(ret == 0 && result == valid_tests_inputs[i].expected_result, name); }