Changeset 139
- Timestamp:
- 05/23/08 20:38:24 (8 months ago)
- Files:
-
- trunk/dba/dba/xmlistream.cpp (modified) (5 diffs)
- trunk/dba/dba/xmlistream.h (modified) (1 diff)
- trunk/dba/test/testobject.cpp (modified) (1 diff)
- trunk/dba/test/testobject.h (modified) (1 diff)
- trunk/dba/test/xmltestcase.cpp (modified) (2 diffs)
- trunk/dba/test/xmltestcase.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dba/dba/xmlistream.cpp
r138 r139 26 26 xmlNodePtr 27 27 XMLIStream::setNextNode(xmlNodePtr pNode) { 28 do { 29 if (pNode) 30 pNode = pNode->next; 31 else 32 return NULL; 33 34 } while(xmlIsBlankNode(pNode) == 1); 28 if (pNode) 29 pNode = pNode->next; 30 return findNonTextNode(pNode); 31 }; 32 33 xmlNodePtr 34 XMLIStream::findNonTextNode(xmlNodePtr pNode) { 35 while(pNode != NULL && (xmlIsBlankNode(pNode) == 1)) 36 pNode = pNode->next; 35 37 return pNode; 36 38 }; … … 61 63 if (entry->getFKeyName() == NULL) 62 64 return entry; 63 } else if (!strcmp(entry->getFKeyName(),(const char*)pNode->name)) { 65 } else if (entry->getFKeyName() != NULL 66 && !strcmp(entry->getFKeyName(),(const char*)pNode->name)) 67 { 64 68 return entry; 65 69 }; … … 79 83 void 80 84 XMLIStream::getChildren(Storeable* pParent, xmlNodePtr pNode) { 81 pNode = setNextNode(pNode);85 pNode = findNonTextNode(pNode); 82 86 //if (pNode) std::cerr << "getChildren at node " << pNode->name << std::endl; 83 87 //ignore all nodes that are binded to pParent class members … … 103 107 open(child,member->getTableName()); 104 108 105 xmlNodePtr node = setNextNode(pNode);109 xmlNodePtr node = findNonTextNode(pNode); 106 110 while (node != NULL) { 107 111 mCurrentNode = node; … … 111 115 if (node->children != NULL) 112 116 getChildren(&child,node->children); 113 117 114 118 childFilter->updateRef((char*)pParent + member->getMemberOffset()); 115 119 childFilter->put(); trunk/dba/dba/xmlistream.h
r138 r139 40 40 void applyFilters(Storeable* pObject); 41 41 xmlNodePtr setNextNode(xmlNodePtr pNode); 42 xmlNodePtr findNonTextNode(xmlNodePtr pNode); 42 43 ColMemberEntry* findMember(Storeable* pObject, xmlNodePtr pNode); 43 44 ColMemberEntry* findNullMember(Storeable* pObject); trunk/dba/test/testobject.cpp
r48 r139 68 68 END_STORE_TABLE() 69 69 70 BEGIN_STORE_TABLE(ObjWithList, dba::Storeable,"obj_with_list")71 BIND_STR(ObjWithList ::mName, dba::String, "name")72 BIND_COL(ObjWithList ::mList, dba::stdList<TestObject>, "fk_owner")70 BEGIN_STORE_TABLE(ObjWithList,ObjWithListBase,"obj_with_list") 71 BIND_STR(ObjWithListBase::mName, dba::String, "name") 72 BIND_COL(ObjWithListBase::mList, dba::stdList<TestObject>, "fk_owner") 73 73 END_STORE_TABLE() 74 74 trunk/dba/test/testobject.h
r138 r139 302 302 Object that contains list of other storeable objects 303 303 */ 304 class ObjWithList : public dba::Storeable { 304 class ObjWithListBase : public dba::Storeable { 305 public: 306 ObjWithListBase() {}; 307 ObjWithListBase(const std::string& pName, int pChildrenCount) 308 : mName(pName) 309 { 310 for (int i=0; i < pChildrenCount; i++) { 311 mList.push_back(TestObject(i,i,"test_object",Utils::getDate(2008,1,i+1,0,0,0))); 312 }; 313 }; 314 bool operator==(const ObjWithListBase& pObj) const { 315 if (mName != pObj.mName) { 316 std::cerr << "Name mismatch. (mine:[" << mName << "], pObj:[" << pObj.mName << "])" << std::endl; 317 return false; 318 }; 319 if (mList.size() != pObj.mList.size()) { 320 std::cerr << "lists have different size (mine: " << mList.size() << ", pObj:" << pObj.mList.size() << ")" << std::endl; 321 return false; 322 }; 323 for(std::list<TestObject>::const_iterator it = mList.begin(); it != mList.end(); it++) { 324 std::list<TestObject>::const_iterator ot = std::find(pObj.mList.begin(), pObj.mList.end(), *it); 325 if (ot == pObj.mList.end()) { 326 std::cerr << "subobject " << it->i << " not found" << std::endl; 327 return false; 328 }; 329 }; 330 return true; 331 }; 332 std::string mName; 333 std::list<TestObject> mList; 334 }; 335 336 class ObjWithList : public ObjWithListBase { 305 337 DECLARE_STORE_TABLE(); 306 338 public: 307 339 ObjWithList() {}; 308 340 ObjWithList(const std::string& pName, int pChildrenCount) 309 : mName(pName) 310 { 311 for (int i=0; i < pChildrenCount; i++) { 312 mList.push_back(TestObject(i,i,"test_object",Utils::getDate(2008,1,i+1,0,0,0))); 313 }; 314 }; 315 bool operator==(const ObjWithList& pObj) const { 316 if (mName != pObj.mName) { 317 std::cerr << "Name mismatch. (mine:[" << mName << "], pObj:[" << pObj.mName << "])" << std::endl; 318 return false; 319 }; 320 if (mList.size() != pObj.mList.size()) { 321 std::cerr << "lists have different size (mine: " << mList.size() << ", pObj:" << pObj.mList.size() << ")" << std::endl; 322 return false; 323 }; 324 for(std::list<TestObject>::const_iterator it = mList.begin(); it != mList.end(); it++) { 325 std::list<TestObject>::const_iterator ot = std::find(pObj.mList.begin(), pObj.mList.end(), *it); 326 if (ot == pObj.mList.end()) { 327 std::cerr << "subobject " << it->i << " not found" << std::endl; 328 return false; 329 }; 330 }; 331 return true; 332 }; 333 std::string mName; 334 std::list<TestObject> mList; 341 : ObjWithListBase(pName, pChildrenCount) {}; 335 342 }; 336 343 trunk/dba/test/xmltestcase.cpp
r138 r139 14 14 #include "dba/fileutils.h" 15 15 #include "dba/int_filter.h" 16 #include "dba/string_filter.h" 17 #include "dba/stdlist.h" 16 18 17 19 #include <fstream> … … 290 292 }; 291 293 294 class XMLObjWithOneUnnamedList : public ObjWithListBase { 295 DECLARE_STORE_TABLE(); 296 public: 297 XMLObjWithOneUnnamedList() {} 298 XMLObjWithOneUnnamedList(const char* pName, int pCount) 299 : ObjWithListBase(pName, pCount) {} 300 }; 301 302 BEGIN_STORE_TABLE(XMLObjWithOneUnnamedList,ObjWithListBase,"obj_with_list") 303 BIND_STR(ObjWithListBase::mName, dba::String, "name") 304 BIND_COL(ObjWithListBase::mList, dba::stdList<TestObject>, NULL) 305 END_STORE_TABLE() 306 307 void 308 XMLTestCase::sublist_one_store_nofk() { 309 const char* result = 310 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 311 "<dba>\n" 312 " <obj_with_list name=\"sub\">\n" 313 " <test_objects i_value=\"0\" f_value=\"0\" s_value=\"test_object\" d_value=\"2008-01-01Z00:00:00\"/>\n" 314 " </obj_with_list>\n" 315 "</dba>\n"; 316 { 317 dba::XMLArchive ar; 318 unlink("sublist_one_nofk.xml"); 319 ar.open("sublist_one_nofk.xml"); 320 XMLObjWithOneUnnamedList obj1("sub",1); 321 dba::XMLOStream stream(ar.getOStream()); 322 stream.open(); 323 stream.put(&obj1); 324 } 325 CPPUNIT_ASSERT(compareXML("sublist_one_nofk.xml",result)); 326 }; 327 328 void 329 XMLTestCase::sublist_one_load_nofk() { 330 const char* data = 331 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 332 "<dba>\n" 333 " <obj_with_list name=\"sub\">\n" 334 " <test_objects i_value=\"0\" f_value=\"0\" s_value=\"test_object\" d_value=\"2008-01-01Z00:00:00\"/>\n" 335 " </obj_with_list>\n" 336 "</dba>\n"; 337 { 338 std::ofstream file("sublist_one_load_nofk.xml"); 339 file << data; 340 }; 341 { 342 dba::XMLArchive ar; 343 ar.open("sublist_one_load_nofk.xml"); 344 XMLObjWithOneUnnamedList obj1; 345 dba::XMLIStream stream(ar.getIStream()); 346 347 stream.get(&obj1); 348 349 XMLObjWithOneUnnamedList expected("sub",1); 350 351 CPPUNIT_ASSERT(obj1 == expected); 352 }; 353 }; 354 292 355 293 356 } //namespace trunk/dba/test/xmltestcase.h
r138 r139 37 37 CPPUNIT_TEST(sublist_one_load); 38 38 CPPUNIT_TEST(sublist_two_load); 39 CPPUNIT_TEST(sublist_one_store_nofk); 40 CPPUNIT_TEST(sublist_one_load_nofk); 39 41 CPPUNIT_TEST_SUITE_END(); 40 42 public: … … 55 57 void sublist_one_load(); 56 58 void sublist_two_load(); 59 void sublist_one_store_nofk(); 60 void sublist_one_load_nofk(); 57 61 private: 58 62 bool compareXML(const char* pFilename, const char* pData);
