Added empty stream/buffer tests, fixed null buffer parsing in wchar_t mode
git-svn-id: http://pugixml.googlecode.com/svn/trunk@397 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
parent
78057035d2
commit
464d0f4ff9
@ -922,10 +922,17 @@ namespace
|
||||
{
|
||||
const char_t* data = static_cast<const char_t*>(contents);
|
||||
|
||||
out_buffer = is_mutable ? const_cast<char_t*>(data) : static_cast<char_t*>(global_allocate(size > 0 ? size : 1));
|
||||
out_length = size / sizeof(char_t);
|
||||
if (is_mutable)
|
||||
{
|
||||
out_buffer = const_cast<char_t*>(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
out_buffer = static_cast<char_t*>(global_allocate(size > 0 ? size : 1));
|
||||
if (!out_buffer) return false;
|
||||
}
|
||||
|
||||
if (!out_buffer) return false;
|
||||
out_length = size / sizeof(char_t);
|
||||
|
||||
impl::convert_wchar_endian_swap(out_buffer, data, out_length);
|
||||
|
||||
|
||||
@ -71,6 +71,15 @@ TEST(document_load_stream_error)
|
||||
CHECK(doc.load(iss).status == status_out_of_memory);
|
||||
}
|
||||
|
||||
TEST(document_load_stream_empty)
|
||||
{
|
||||
std::istringstream iss;
|
||||
|
||||
pugi::xml_document doc;
|
||||
doc.load(iss); // parse result depends on STL implementation
|
||||
CHECK(!doc.first_child());
|
||||
}
|
||||
|
||||
TEST(document_load_stream_wide)
|
||||
{
|
||||
pugi::xml_document doc;
|
||||
@ -571,3 +580,38 @@ TEST(document_convert_invalid_utf16)
|
||||
CHECK(test_parse_fail("\x00<\xde\x24", 4, encoding_utf16_be));
|
||||
CHECK(test_parse_fail("<\x00\x24\xde", 4, encoding_utf16_le));
|
||||
}
|
||||
|
||||
TEST(document_load_buffer_empty)
|
||||
{
|
||||
encoding_t encodings[] =
|
||||
{
|
||||
encoding_auto,
|
||||
encoding_utf8,
|
||||
encoding_utf16_le,
|
||||
encoding_utf16_be,
|
||||
encoding_utf16,
|
||||
encoding_utf32_le,
|
||||
encoding_utf32_be,
|
||||
encoding_utf32,
|
||||
encoding_wchar
|
||||
};
|
||||
|
||||
char buffer[1];
|
||||
|
||||
for (unsigned int i = 0; i < sizeof(encodings) / sizeof(encodings[0]); ++i)
|
||||
{
|
||||
encoding_t encoding = encodings[i];
|
||||
|
||||
xml_document doc;
|
||||
CHECK(doc.load_buffer(buffer, 0, parse_default, encoding) && !doc.first_child());
|
||||
CHECK(doc.load_buffer(0, 0, parse_default, encoding) && !doc.first_child());
|
||||
|
||||
CHECK(doc.load_buffer_inplace(buffer, 0, parse_default, encoding) && !doc.first_child());
|
||||
CHECK(doc.load_buffer_inplace(0, 0, parse_default, encoding) && !doc.first_child());
|
||||
|
||||
void* own_buffer = pugi::get_memory_allocation_function()(1);
|
||||
|
||||
CHECK(doc.load_buffer_inplace_own(own_buffer, 0, parse_default, encoding) && !doc.first_child());
|
||||
CHECK(doc.load_buffer_inplace_own(0, 0, parse_default, encoding) && !doc.first_child());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user