Commit 7286499d authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

Merge branch 'trac571'

parents c243f842 9d6d5822
......@@ -869,8 +869,11 @@ struct SectionFormatter {
void operator()(const T& entry) {
if (section_ == Message::SECTION_QUESTION) {
output_ += ";";
output_ += entry->toText();
output_ += "\n";
} else {
output_ += entry->toText();
}
output_ += entry->toText();
}
const Message::Section section_;
string& output_;
......
......@@ -70,9 +70,9 @@ class QuestionTest(unittest.TestCase):
def test_to_text(self):
self.assertEqual("foo.example.com. IN NS\n", self.test_question1.to_text())
self.assertEqual("foo.example.com. IN NS\n", str(self.test_question1))
self.assertEqual("bar.example.com. CH A\n", self.test_question2.to_text())
self.assertEqual("foo.example.com. IN NS", self.test_question1.to_text())
self.assertEqual("foo.example.com. IN NS", str(self.test_question1))
self.assertEqual("bar.example.com. CH A", self.test_question2.to_text())
def test_to_wire_buffer(self):
obuffer = bytes()
......
......@@ -40,10 +40,15 @@ Question::Question(InputBuffer& buffer) :
rrclass_ = RRClass(buffer);
}
string
Question::toText() const {
return (name_.toText() + " " + rrclass_.toText() + " " +
rrtype_.toText() + "\n");
std::string
Question::toText(bool newline) const {
std::string r(name_.toText() + " " + rrclass_.toText() + " " +
rrtype_.toText());
if (newline) {
r.append("\n");
}
return (r);
}
unsigned int
......
......@@ -173,9 +173,9 @@ public:
//@{
/// \brief Convert the Question to a string.
///
/// Unlike other similar methods of this library, this method terminates
/// the resulting string with a trailing newline character
/// (following the BIND9 convention).
/// When \c newline argument is \c true, this method terminates the
/// resulting string with a trailing newline character (following
/// the BIND9 convention).
///
/// This method simply calls the \c %toText() methods of the corresponding
/// \c Name, \c RRType and \c RRClass classes for this \c Question, and
......@@ -183,8 +183,12 @@ public:
/// In particular, if resource allocation fails, a corresponding standard
/// exception will be thrown.
///
/// \param newline Whether to add a trailing newline. If true, a
/// trailing newline is added. If false, no trailing newline is
/// added.
///
/// \return A string representation of the \c Question.
std::string toText() const;
std::string toText(bool newline = false) const;
/// \brief Render the Question in the wire format with name compression.
///
......
......@@ -86,8 +86,14 @@ TEST_F(QuestionTest, fromWire) {
}
TEST_F(QuestionTest, toText) {
EXPECT_EQ("foo.example.com. IN NS\n", test_question1.toText());
EXPECT_EQ("bar.example.com. CH A\n", test_question2.toText());
EXPECT_EQ("foo.example.com. IN NS", test_question1.toText());
EXPECT_EQ("bar.example.com. CH A", test_question2.toText());
EXPECT_EQ("foo.example.com. IN NS", test_question1.toText(false));
EXPECT_EQ("bar.example.com. CH A", test_question2.toText(false));
EXPECT_EQ("foo.example.com. IN NS\n", test_question1.toText(true));
EXPECT_EQ("bar.example.com. CH A\n", test_question2.toText(true));
}
TEST_F(QuestionTest, toWireBuffer) {
......
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