Library: Fixed loading of 'resource'

This commit is contained in:
Daniel Marjamäki 2013-11-23 18:16:40 +01:00
parent 514218da31
commit 4fe6951b4c
2 changed files with 27 additions and 2 deletions

View File

@ -75,8 +75,11 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
return false;
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
if (strcmp(node->Name(),"memory")==0) {
while (!ismemory(++allocid));
if (strcmp(node->Name(),"memory")==0 || strcmp(node->Name(),"resource")==0) {
if (strcmp(node->Name(), "memory")==0)
while (!ismemory(++allocid));
else
while (!isresource(++allocid));
for (const tinyxml2::XMLElement *memorynode = node->FirstChildElement(); memorynode; memorynode = memorynode->NextSiblingElement()) {
if (strcmp(memorynode->Name(),"alloc")==0) {
_alloc[memorynode->GetText()] = allocid;

View File

@ -30,6 +30,7 @@ private:
TEST_CASE(function);
TEST_CASE(function_arg);
TEST_CASE(memory);
TEST_CASE(resource);
}
void empty() {
@ -111,6 +112,27 @@ private:
ASSERT(Library::ismemory(library.alloc("CreateX")));
ASSERT_EQUALS(library.alloc("CreateX"), library.dealloc("DeleteX"));
}
void resource() {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <resource>\n"
" <alloc>CreateX</alloc>\n"
" <dealloc>DeleteX</dealloc>\n"
" </resource>\n"
"</def>";
tinyxml2::XMLDocument doc;
doc.Parse(xmldata, sizeof(xmldata));
Library library;
library.load(doc);
ASSERT(library.use.empty());
ASSERT(library.leakignore.empty());
ASSERT(library.argumentChecks.empty());
ASSERT(Library::isresource(library.alloc("CreateX")));
ASSERT_EQUALS(library.alloc("CreateX"), library.dealloc("DeleteX"));
}
};
REGISTER_TEST(TestLibrary)