]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Clarify Parser::Tokenizer::int64 documentation, add one test case.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 26 May 2014 14:06:07 +0000 (16:06 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 26 May 2014 14:06:07 +0000 (16:06 +0200)
src/parser/Tokenizer.h
src/parser/testTokenizer.cc

index 84db031342158e8abeb1df995bd61863eb0a1ffe..677d6282559fc3df0a55089f2f2cebbd2d889949 100644 (file)
@@ -74,9 +74,8 @@ public:
     * or guesstimated; consumes the parsed characters.
     *
     * \param result output value. Not touched if parseing is unsuccessful
-    * \param base specify base to do the parsing in. Admitted values are
-    *   8, 10, 16 and 0, the latter specifying to use C syntax for guessing
-    *   the base
+    * \param base specify base to do the parsing in, with the same restrictions
+    *   as strtoll. Defaults to 0 (meaning guess)
     * \return true if the parsing was successful
     */
    bool int64 (int64_t &result, int base = 0);
index 5308c91de783e1bce63a0103e4bb8108ca8605b5..1499f52f4814084943f22d48e4241569b4c41c3c 100644 (file)
@@ -106,10 +106,9 @@ testTokenizer::testCharacterSet()
 void
 testTokenizer::testTokenizerInt64()
 {
-    int64_t rv;
-
     // successful parse in base 10
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf("1234"));
         const int64_t benchmark = 1234;
         CPPUNIT_ASSERT(t.int64(rv, 10));
@@ -118,6 +117,7 @@ testTokenizer::testTokenizerInt64()
 
     // successful parse, autodetect base
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf("1234"));
         const int64_t benchmark = 1234;
         CPPUNIT_ASSERT(t.int64(rv));
@@ -126,6 +126,7 @@ testTokenizer::testTokenizerInt64()
 
     // successful parse, autodetect base
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf("01234"));
         const int64_t benchmark = 01234;
         CPPUNIT_ASSERT(t.int64(rv));
@@ -134,6 +135,7 @@ testTokenizer::testTokenizerInt64()
 
     // successful parse, autodetect base
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf("0x12f4"));
         const int64_t benchmark = 0x12f4;
         CPPUNIT_ASSERT(t.int64(rv));
@@ -142,18 +144,21 @@ testTokenizer::testTokenizerInt64()
 
     // API mismatch: don't eat leading space
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf(" 1234"));
         CPPUNIT_ASSERT(!t.int64(rv));
     }
 
     // API mismatch: don't eat multiple leading spaces
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf("  1234"));
         CPPUNIT_ASSERT(!t.int64(rv));
     }
 
     // trailing spaces
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf("1234  foo"));
         const int64_t benchmark = 1234;
         CPPUNIT_ASSERT(t.int64(rv));
@@ -163,6 +168,7 @@ testTokenizer::testTokenizerInt64()
 
     // trailing nonspaces
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf("1234foo"));
         const int64_t benchmark = 1234;
         CPPUNIT_ASSERT(t.int64(rv));
@@ -172,10 +178,18 @@ testTokenizer::testTokenizerInt64()
 
     // trailing nonspaces
     {
+        int64_t rv;
         Parser::Tokenizer t(SBuf("0x1234foo"));
         const int64_t benchmark = 0x1234f;
         CPPUNIT_ASSERT(t.int64(rv));
         CPPUNIT_ASSERT_EQUAL(benchmark,rv);
         CPPUNIT_ASSERT_EQUAL(SBuf("oo"), t.buf());
     }
+
+    // overflow
+    {
+        int64_t rv;
+        Parser::Tokenizer t(SBuf("1029397752385698678762234"));
+        CPPUNIT_ASSERT(!t.int64(rv));
+    }
 }