summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-03-29 20:17:26 +0100
committerSébastien Helleu <flashcode@flashtux.org>2019-03-29 20:17:26 +0100
commitfa5b1eed77d6b012ab440f0bd75e1b155985e671 (patch)
tree4e7cfe1c7ed05fc0e71e9957e8e66a1bfa217c57 /tests/unit
parentb3cf270d1d938ffa9960ccb5e39d5a0ed166f594 (diff)
downloadweechat-fa5b1eed77d6b012ab440f0bd75e1b155985e671.zip
core: move parsing of /wait delay in a separate function, with unit tests
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/core/test-core-util.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/unit/core/test-core-util.cpp b/tests/unit/core/test-core-util.cpp
index 86627a3fe..0d29a832d 100644
--- a/tests/unit/core/test-core-util.cpp
+++ b/tests/unit/core/test-core-util.cpp
@@ -95,6 +95,55 @@ TEST(CoreUtil, GetTimeString)
/*
* Tests functions:
+ * util_parse_delay
+ */
+
+TEST(CoreUtil, ParseDelay)
+{
+ /* error: no string */
+ LONGS_EQUAL(-1, util_parse_delay (NULL, -1));
+ LONGS_EQUAL(-1, util_parse_delay (NULL, 0));
+ LONGS_EQUAL(-1, util_parse_delay (NULL, 1));
+ LONGS_EQUAL(-1, util_parse_delay ("", -1));
+ LONGS_EQUAL(-1, util_parse_delay ("", 0));
+ LONGS_EQUAL(-1, util_parse_delay ("", 1));
+
+ /* error: bad default_factor */
+ LONGS_EQUAL(-1, util_parse_delay ("abcd", -1));
+ LONGS_EQUAL(-1, util_parse_delay ("abcd", 0));
+ LONGS_EQUAL(-1, util_parse_delay ("123", -1));
+ LONGS_EQUAL(-1, util_parse_delay ("123", 0));
+
+ /* error: bad unit */
+ LONGS_EQUAL(-1, util_parse_delay ("123a", 1));
+ LONGS_EQUAL(-1, util_parse_delay ("123ss", 1));
+ LONGS_EQUAL(-1, util_parse_delay ("123mss", 1));
+
+ /* error: bad number */
+ LONGS_EQUAL(-1, util_parse_delay ("abcd", 1));
+
+ /* tests with delay == 0 */
+ LONGS_EQUAL(0, util_parse_delay ("0", 1));
+ LONGS_EQUAL(0, util_parse_delay ("0s", 1));
+ LONGS_EQUAL(0, util_parse_delay ("0m", 1));
+ LONGS_EQUAL(0, util_parse_delay ("0h", 1));
+
+ /* tests with delay == 123, default_factor = 1 */
+ LONGS_EQUAL(123, util_parse_delay ("123", 1));
+ LONGS_EQUAL(123, util_parse_delay ("123", 1));
+ LONGS_EQUAL(123 * 1000, util_parse_delay ("123s", 1));
+ LONGS_EQUAL(123 * 1000 * 60, util_parse_delay ("123m", 1));
+ LONGS_EQUAL(123 * 1000 * 60 * 60, util_parse_delay ("123h", 1));
+
+ /* tests with delay == 123, default_factor = 1000 */
+ LONGS_EQUAL(123 * 1000, util_parse_delay ("123", 1000));
+ LONGS_EQUAL(123 * 1000, util_parse_delay ("123s", 1000));
+ LONGS_EQUAL(123 * 1000 * 60, util_parse_delay ("123m", 1000));
+ LONGS_EQUAL(123 * 1000 * 60 * 60, util_parse_delay ("123h", 1000));
+}
+
+/*
+ * Tests functions:
* util_signal_search
* util_catch_signal
*/