1 /** @file
2 
3     ParseRules unit test
4 
5     @section license License
6 
7     Licensed to the Apache Software Foundation (ASF) under one
8     or more contributor license agreements.  See the NOTICE file
9     distributed with this work for additional information
10     regarding copyright ownership.  The ASF licenses this file
11     to you under the Apache License, Version 2.0 (the
12     "License"); you may not use this file except in compliance
13     with the License.  You may obtain a copy of the License at
14 
15     http://www.apache.org/licenses/LICENSE-2.0
16 
17     Unless required by applicable law or agreed to in writing, software
18     distributed under the License is distributed on an "AS IS" BASIS,
19     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20     See the License for the specific language governing permissions and
21     limitations under the License.
22 */
23 
24 #include "../../../tests/include/catch.hpp"
25 #include <tscore/ParseRules.h>
26 #include <iostream>
27 
28 TEST_CASE("parse_rules", "[libts][parse_rules]")
29 {
30   // test "100"
31   {
32     const char *end = nullptr;
33     int64_t value   = ink_atoi64("100", &end);
34     REQUIRE(value == 100);
35     REQUIRE(*end == '\0');
36   }
37 
38   // testf "1M"
39   {
40     const char *end = nullptr;
41     int64_t value   = ink_atoi64("1M", &end);
42     REQUIRE(value == 1 << 20);
43     REQUIRE(*end == '\0');
44   }
45 
46   // test -100
47   {
48     const char *end = nullptr;
49     int64_t value   = ink_atoi64("-100", &end);
50     REQUIRE(value == -100);
51     REQUIRE(*end == '\0');
52   }
53 
54   // testf "-1M"
55   {
56     const char *end = nullptr;
57     int64_t value   = ink_atoi64("-1M", &end);
58     REQUIRE(value == (1 << 20) * -1);
59     REQUIRE(*end == '\0');
60   }
61 
62   // test "9223372036854775807"
63   {
64     const char *end = nullptr;
65     int64_t value   = ink_atoi64("9223372036854775807", &end);
66     REQUIRE(value == 9223372036854775807ull);
67     REQUIRE(*end == '\0');
68   }
69 
70   // test "-9223372036854775807"
71   {
72     const char *end = nullptr;
73     int64_t value   = ink_atoi64("-9223372036854775807", &end);
74     REQUIRE(value == -9223372036854775807ll);
75     REQUIRE(*end == '\0');
76   }
77 
78   // testf "1.5T" - error case
79   {
80     const char *end = nullptr;
81     int64_t value   = ink_atoi64("1.5T", &end);
82     REQUIRE(value != 1649267441664);
83     REQUIRE(*end != '\0');
84   }
85 
86   // testf "asdf" - error case
87   {
88     const char *end = nullptr;
89     int64_t value   = ink_atoi64("asdf", &end);
90     REQUIRE(value == 0);
91     REQUIRE(*end != '\0');
92   }
93 }