Skip to content

Commit

Permalink
Make XML comparison in the test work for SQL Server too
Browse files Browse the repository at this point in the history
Adding a new line to work around the problem with Oracle didn't allow
this test to pass with SQL Server which strips the newline if it is
present.

So don't modify the input, but do strip the trailing newline from output
if it's present in it to accommodate Oracle, but to allow SQL Server to
work too.
  • Loading branch information
vadz committed Sep 14, 2017
1 parent 11a8982 commit fabb8f0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/common-tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -4355,13 +4355,7 @@ TEST_CASE_METHOD(common_tests, "XML", "[core][xml]")

int id = 1;
xml_type xml;

// The extra new line is a special hack for Oracle: its getCLOBVal()
// seems to reformat the returned XML and, in particular, appends a new
// line to it if its last line doesn't contain one already. So if we didn't
// append it here the check for round trip below would fail because of the
// extra new line.
xml.value = make_long_xml_string() + "\n";
xml.value = make_long_xml_string();

sql << "insert into soci_test (id, x) values (:1, "
<< tc_.to_xml(":2")
Expand All @@ -4375,6 +4369,15 @@ TEST_CASE_METHOD(common_tests, "XML", "[core][xml]")
<< " from soci_test where id = :1",
into(xml2), use(id);

// The returned value doesn't need to be identical to the original one as
// string, only structurally equal as XML. In particular, extra whitespace
// can be added and this does happen with Oracle, for example, which adds
// an extra new line, so remove it if it's present.
if (!xml2.value.empty() && *xml2.value.rbegin() == '\n')
{
xml2.value.resize(xml2.value.length() - 1);
}

CHECK(xml.value == xml2.value);

sql << "update soci_test set x = null where id = :1", use(id);
Expand Down

0 comments on commit fabb8f0

Please sign in to comment.