Commit c16b3ab5 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[master] applied the proposed fix of #906 to fix failure in MessageTest::toText

parent 434719dc
...@@ -683,11 +683,12 @@ TEST_F(MessageTest, toWireWithoutRcode) { ...@@ -683,11 +683,12 @@ TEST_F(MessageTest, toWireWithoutRcode) {
TEST_F(MessageTest, toText) { TEST_F(MessageTest, toText) {
// Check toText() output for a typical DNS response with records in // Check toText() output for a typical DNS response with records in
// all sections // all sections
ifstream ifs;
unittests::openTestData("message_toText1.txt", ifs);
factoryFromFile(message_parse, "message_toText1.wire"); factoryFromFile(message_parse, "message_toText1.wire");
{ {
SCOPED_TRACE("Message toText test (basic case)"); SCOPED_TRACE("Message toText test (basic case)");
ifstream ifs;
unittests::openTestData("message_toText1.txt", ifs);
unittests::matchTextData(ifs, message_parse.toText()); unittests::matchTextData(ifs, message_parse.toText());
} }
...@@ -695,12 +696,12 @@ TEST_F(MessageTest, toText) { ...@@ -695,12 +696,12 @@ TEST_F(MessageTest, toText) {
// from the dig output (other than replacing tabs with a space): adding // from the dig output (other than replacing tabs with a space): adding
// a newline after the "OPT PSEUDOSECTION". This is an intentional change // a newline after the "OPT PSEUDOSECTION". This is an intentional change
// in our version for better readability. // in our version for better readability.
ifs.close();
message_parse.clear(Message::PARSE); message_parse.clear(Message::PARSE);
unittests::openTestData("message_toText2.txt", ifs);
factoryFromFile(message_parse, "message_toText2.wire"); factoryFromFile(message_parse, "message_toText2.wire");
{ {
SCOPED_TRACE("Message toText test with EDNS"); SCOPED_TRACE("Message toText test with EDNS");
ifstream ifs;
unittests::openTestData("message_toText2.txt", ifs);
unittests::matchTextData(ifs, message_parse.toText()); unittests::matchTextData(ifs, message_parse.toText());
} }
...@@ -708,12 +709,12 @@ TEST_F(MessageTest, toText) { ...@@ -708,12 +709,12 @@ TEST_F(MessageTest, toText) {
// from the dig output (other than replacing tabs with a space): removing // from the dig output (other than replacing tabs with a space): removing
// a redundant white space at the end of TSIG RDATA. We'd rather consider // a redundant white space at the end of TSIG RDATA. We'd rather consider
// it a dig's defect than a feature. // it a dig's defect than a feature.
ifs.close();
message_parse.clear(Message::PARSE); message_parse.clear(Message::PARSE);
unittests::openTestData("message_toText3.txt", ifs);
factoryFromFile(message_parse, "message_toText3.wire"); factoryFromFile(message_parse, "message_toText3.wire");
{ {
SCOPED_TRACE("Message toText test with TSIG"); SCOPED_TRACE("Message toText test with TSIG");
ifstream ifs;
unittests::openTestData("message_toText3.txt", ifs);
unittests::matchTextData(ifs, message_parse.toText()); unittests::matchTextData(ifs, message_parse.toText());
} }
} }
......
...@@ -34,6 +34,14 @@ void addTestDataPath(const std::string& path); ...@@ -34,6 +34,14 @@ void addTestDataPath(const std::string& path);
/// addTestDataPath(). On success, ifs will be ready for reading the data /// addTestDataPath(). On success, ifs will be ready for reading the data
/// stored in 'datafile'. If the data file cannot be open with any of the /// stored in 'datafile'. If the data file cannot be open with any of the
/// registered paths, a runtime_error exception will be thrown. /// registered paths, a runtime_error exception will be thrown.
///
/// \note Care should be taken if you want to reuse the same single \c ifs
/// for multiple input data. Some standard C++ library implementations retain
/// the failure bit if the first stream reaches the end of the first file,
/// and make the second call to \c ifstream::open() fail. The safest way
/// is to use a different \c ifstream object for a new call to this function;
/// alternatively make sure you explicitly clear the error bit by calling
/// \c ifstream::clear() on \c ifs.
void openTestData(const char* const datafile, std::ifstream& ifs); void openTestData(const char* const datafile, std::ifstream& ifs);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment