From: JINMEI Tatuya Date: Tue, 4 Dec 2012 17:22:44 +0000 (-0800) Subject: [2382] added one suggested test: a case where RDATA is followed by comment X-Git-Tag: bind10-1.0.0-beta-release~44^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09d70952ca89ef967f8652046ed6fe869625b42e;p=thirdparty%2Fkea.git [2382] added one suggested test: a case where RDATA is followed by comment --- diff --git a/src/lib/dns/tests/rdata_unittest.cc b/src/lib/dns/tests/rdata_unittest.cc index bb39d05fe0..7f0dd6580d 100644 --- a/src/lib/dns/tests/rdata_unittest.cc +++ b/src/lib/dns/tests/rdata_unittest.cc @@ -132,6 +132,7 @@ TEST_F(RdataTest, createRdataWithLexer) { stringstream ss; const string src_name = "stream-" + boost::lexical_cast(&ss); ss << aaaa_rdata.toText() << "\n"; // valid case + ss << aaaa_rdata.toText() << "; comment, should be ignored\n"; ss << aaaa_rdata.toText() << " extra-token\n"; // extra token ss << aaaa_rdata.toText() << " extra token\n"; // 2 extra tokens ss << ")\n"; // causing lexer error in parsing the RDATA text @@ -146,54 +147,71 @@ TEST_F(RdataTest, createRdataWithLexer) { boost::bind(&CreateRdataCallback::callback, &callback, CreateRdataCallback::WARN, _1, _2, _3)); + size_t line = 0; + // Valid case. + ++line; ConstRdataPtr rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, MasterLoader::MANY_ERRORS, callbacks); EXPECT_EQ(0, aaaa_rdata.compare(*rdata)); EXPECT_FALSE(callback.isCalled()); + // Similar to the previous case, but RDATA is followed by a comment. + // It should cause any confusion. + ++line; + callback.clear(); + rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, + MasterLoader::MANY_ERRORS, callbacks); + EXPECT_EQ(0, aaaa_rdata.compare(*rdata)); + EXPECT_FALSE(callback.isCalled()); + // Broken RDATA text: extra token. createRdata() returns NULL, error // callback is called. + ++line; callback.clear(); EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, MasterLoader::MANY_ERRORS, callbacks)); - callback.check(src_name, 2, CreateRdataCallback::ERROR, + callback.check(src_name, line, CreateRdataCallback::ERROR, "createRdata from text failed near 'extra-token': " "extra input text"); // Similar to the previous case, but only the first extra token triggers // callback. + ++line; callback.clear(); EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, MasterLoader::MANY_ERRORS, callbacks)); - callback.check(src_name, 3, CreateRdataCallback::ERROR, + callback.check(src_name, line, CreateRdataCallback::ERROR, "createRdata from text failed near 'extra': " "extra input text"); // Lexer error will happen, corresponding error callback will be triggered. + ++line; callback.clear(); EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, MasterLoader::MANY_ERRORS, callbacks)); - callback.check(src_name, 4, CreateRdataCallback::ERROR, + callback.check(src_name, line, CreateRdataCallback::ERROR, "createRdata from text failed: unbalanced parentheses"); // Semantics level error will happen, corresponding error callback will be // triggered. + ++line; callback.clear(); EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, MasterLoader::MANY_ERRORS, callbacks)); - callback.check(src_name, 5, CreateRdataCallback::ERROR, + callback.check(src_name, line, CreateRdataCallback::ERROR, "createRdata from text failed: Failed to convert " "'192.0.2.1' to IN/AAAA RDATA"); // Input is valid and parse will succeed, but with a warning that the // file is not ended with a newline. + ++line; callback.clear(); rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, MasterLoader::MANY_ERRORS, callbacks); EXPECT_EQ(0, aaaa_rdata.compare(*rdata)); - callback.check(src_name, 6, CreateRdataCallback::WARN, + callback.check(src_name, line, CreateRdataCallback::WARN, "file does not end with newline"); }