]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/strtol: add test case for parsing hex numbers 21582/head
authorJan Fajerski <jfajerski@suse.com>
Sat, 21 Apr 2018 09:27:17 +0000 (11:27 +0200)
committerJan Fajerski <jfajerski@suse.com>
Sat, 21 Apr 2018 09:27:17 +0000 (11:27 +0200)
Signed-off-by: Jan Fajerski <jfajerski@suse.com>
src/test/strtol.cc

index 69d1a70871e0a3d458e8e7d8ab1b1de52ec6416a..673bf2977f416826a6b9cf46a29836646c2dd99c 100644 (file)
 
 #include "gtest/gtest.h"
 
-static void test_strict_strtoll(const char *str, long long expected)
+static void test_strict_strtoll(const char *str, long long expected, int base)
 {
   std::string err;
-  long long val = strict_strtoll(str, 10, &err);
+  long long val = strict_strtoll(str, base, &err);
   if (!err.empty()) {
     ASSERT_EQ(err, "");
   }
@@ -74,11 +74,14 @@ static void test_strict_strtof(const char *str, float expected)
 }
 
 TEST(StrToL, Simple1) {
-  test_strict_strtoll("123", 123);
-  test_strict_strtoll("0", 0);
-  test_strict_strtoll("-123", -123);
-  test_strict_strtoll("8796093022208", 8796093022208LL);
-  test_strict_strtoll("-8796093022208", -8796093022208LL);
+  test_strict_strtoll("123", 123, 10);
+  test_strict_strtoll("0", 0, 10);
+  test_strict_strtoll("-123", -123, 10);
+  test_strict_strtoll("8796093022208", 8796093022208LL, 10);
+  test_strict_strtoll("-8796093022208", -8796093022208LL, 10);
+  test_strict_strtoll("123", 123, 0);
+  test_strict_strtoll("0x7b", 123, 0);
+  test_strict_strtoll("4d2", 1234, 16);
 
   test_strict_strtol("208", 208);
   test_strict_strtol("-4", -4);