summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2011-07-15 12:42:49 -0400
committerNat Goodspeed <nat@lindenlab.com>2011-07-15 12:42:49 -0400
commit7341e01ce2c833a190e6361bd97cf64bc1947efc (patch)
treeaae870d37e62b7af6078c5be0f12165c7f8905c1 /indra/llcommon/tests
parentc33cf379f25e9a1a3780a73805749616fa07de66 (diff)
Add test to verify Python-to-C++ LLSD notation sequence.
Verify that an LLSD::String containing newlines works; verify that newlines between items are accepted.
Diffstat (limited to 'indra/llcommon/tests')
-rw-r--r--indra/llcommon/tests/llsdserialize_test.cpp60
1 files changed, 58 insertions, 2 deletions
diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp
index aaf3740b07..0b9f1b53d2 100644
--- a/indra/llcommon/tests/llsdserialize_test.cpp
+++ b/indra/llcommon/tests/llsdserialize_test.cpp
@@ -1787,8 +1787,12 @@ namespace tut
" else:\n"
" assert False, 'Too many data items'\n";
- // Create a something.llsd file containing 'data' serialized to notation.
- // Avoid final newline because NamedTempFile implicitly adds one.
+ // Create a something.llsd file containing 'data' serialized to
+ // notation. It's important to separate with newlines because Python's
+ // llsd module doesn't support parsing from a file stream, only from a
+ // string, so we have to know how much of the file to read into a
+ // string. Avoid final newline because NamedTempFile implicitly adds
+ // one.
NamedTempFile file(".llsd",
(lambda::bind(LLSDSerialize::toNotation, cdata[0], lambda::_1),
lambda::_1 << '\n',
@@ -1805,4 +1809,56 @@ namespace tut
pydata <<
"verify(parse_each(open('" << file.getName() << "')))\n");
}
+
+ template<> template<>
+ void TestPythonCompatibleObject::test<4>()
+ {
+ set_test_name("verify sequence from Python");
+
+ // Create an empty data file. This is just a placeholder for our
+ // script to write into. Create it to establish a unique name that
+ // we know.
+ NamedTempFile file(".llsd", "");
+
+ python("write Python notation",
+ lambda::_1 <<
+ "from __future__ import with_statement\n"
+ "from llbase import llsd\n"
+ "DATA = [\n"
+ " 17,\n"
+ " 3.14,\n"
+ " '''\\\n"
+ "This string\n"
+ "has several\n"
+ "lines.''',\n"
+ "]\n"
+ // N.B. Using 'print' implicitly adds newlines.
+ "with open('" << file.getName() << "', 'w') as f:\n"
+ " for item in DATA:\n"
+ " print >>f, llsd.format_notation(item)\n");
+
+ std::ifstream inf(file.getName().c_str());
+ LLSD item;
+ // Notice that we're not doing anything special to parse out the
+ // newlines: LLSDSerialize::fromNotation ignores them. While it would
+ // seem they're not strictly necessary, going in this direction, we
+ // want to ensure that notation-separated-by-newlines works in both
+ // directions -- since in practice, a given file might be read by
+ // either language.
+ ensure_equals("Failed to read LLSD::Integer from Python",
+ LLSDSerialize::fromNotation(item, inf, LLSDSerialize::SIZE_UNLIMITED),
+ 1);
+ ensure_equals(item.asInteger(), 17);
+ ensure_equals("Failed to read LLSD::Real from Python",
+ LLSDSerialize::fromNotation(item, inf, LLSDSerialize::SIZE_UNLIMITED),
+ 1);
+ ensure_approximately_equals(item.asReal(), 3.14, 7); // 7 bits ~= 0.01
+ ensure_equals("Failed to read LLSD::String from Python",
+ LLSDSerialize::fromNotation(item, inf, LLSDSerialize::SIZE_UNLIMITED),
+ 1);
+ ensure_equals(item.asString(),
+ "This string\n"
+ "has several\n"
+ "lines.");
+ }
}