From: Francesco Chemolli Date: Mon, 26 May 2014 14:06:07 +0000 (+0200) Subject: Clarify Parser::Tokenizer::int64 documentation, add one test case. X-Git-Tag: SQUID_3_5_0_1~217^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e48aef3e0f88685754cfc498cbd330c649d35905;p=thirdparty%2Fsquid.git Clarify Parser::Tokenizer::int64 documentation, add one test case. --- diff --git a/src/parser/Tokenizer.h b/src/parser/Tokenizer.h index 84db031342..677d628255 100644 --- a/src/parser/Tokenizer.h +++ b/src/parser/Tokenizer.h @@ -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); diff --git a/src/parser/testTokenizer.cc b/src/parser/testTokenizer.cc index 5308c91de7..1499f52f48 100644 --- a/src/parser/testTokenizer.cc +++ b/src/parser/testTokenizer.cc @@ -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)); + } }