From: JINMEI Tatuya Date: Tue, 4 Dec 2012 22:51:45 +0000 (-0800) Subject: [2442] added some test cases for txt-like rdata with multi-char-string X-Git-Tag: bind10-1.0.0-beta-release~39^2~3^2~1^2~2^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bdc1899a220d369cb7ca1b86fd9a2ddde44eeb9;p=thirdparty%2Fkea.git [2442] added some test cases for txt-like rdata with multi-char-string --- diff --git a/src/lib/dns/tests/rdata_txt_like_unittest.cc b/src/lib/dns/tests/rdata_txt_like_unittest.cc index b3c263013a..e4bb173861 100644 --- a/src/lib/dns/tests/rdata_txt_like_unittest.cc +++ b/src/lib/dns/tests/rdata_txt_like_unittest.cc @@ -25,6 +25,10 @@ #include +#include +#include +#include + using isc::UnitTestUtil; using namespace std; using namespace isc::dns; @@ -77,7 +81,6 @@ protected: const TXT_LIKE rdata_txt_like; const TXT_LIKE rdata_txt_like_empty; const TXT_LIKE rdata_txt_like_quoted; - ConstRdataPtr rdata_txt_like_fromwire; }; // The list of types we want to test. @@ -96,24 +99,21 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) { ss << "\"Test-String\\\"\"\n"; this->lexer.pushSource(ss); - // Rdata to compare, created from wire - this->rdata_txt_like_fromwire = + // commonly used Rdata to compare below, created from wire + ConstRdataPtr const rdata = this->rdataFactoryFromFile(RRTYPE(), RRClass("IN"), "rdata_txt_fromWire1"); // normal case is covered in toWireBuffer. - EXPECT_EQ(0, this->rdata_txt_like.compare(*this->rdata_txt_like_fromwire)); + EXPECT_EQ(0, this->rdata_txt_like.compare(*rdata)); EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, - this->loader_cb).compare( - *this->rdata_txt_like_fromwire)); + this->loader_cb).compare(*rdata)); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); // surrounding double-quotes shouldn't change the result. - EXPECT_EQ(0, this->rdata_txt_like_quoted.compare( - *this->rdata_txt_like_fromwire)); + EXPECT_EQ(0, this->rdata_txt_like_quoted.compare(*rdata)); EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, - this->loader_cb).compare( - *this->rdata_txt_like_fromwire)); + this->loader_cb).compare(*rdata)); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); // Null character-string. @@ -160,6 +160,43 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) { EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); } +TYPED_TEST(Rdata_TXT_LIKE_Test, createMultiStringsFromText) { + // Tests for "from text" variants construction with various forms of + // multi character-strings. + + std::vector texts; + texts.push_back("\"Test-String\" \"Test-String\""); // most common form + texts.push_back("\"Test-String\"\"Test-String\""); // no space between'em + texts.push_back("\"Test-String\" Test-String"); // no '"' for one + texts.push_back("\"Test-String\"Test-String"); // and no space either + texts.push_back("Test-String \"Test-String\""); // no '"' for the other + + std::stringstream ss; + for (std::vector::const_iterator it = texts.begin(); + it != texts.end(); ++it) { + ss << *it << "\n"; + } + this->lexer.pushSource(ss); + + // The corresponding Rdata built from wire to compare in the checks below. + ConstRdataPtr const rdata = + this->rdataFactoryFromFile(RRTYPE(), + RRClass("IN"), "rdata_txt_fromWire3.wire"); + + // Confirm we can construct the Rdata from the test text, both from + // std::string and with lexer, and that matches the from-wire data. + for (std::vector::const_iterator it = texts.begin(); + it != texts.end(); ++it) { + SCOPED_TRACE(*it); + EXPECT_EQ(0, TypeParam(*it).compare(*rdata)); + + EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, + this->loader_cb).compare(*rdata)); + EXPECT_EQ(MasterToken::END_OF_LINE, + this->lexer.getNextToken().getType()); + } +} + void makeLargest(vector& data) { uint8_t ch = 0;