Changeset 139

Show
Ignore:
Timestamp:
05/23/08 20:38:24 (8 months ago)
Author:
zork
Message:

added tests and fixed bugs for non-fkey loading

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dba/dba/xmlistream.cpp

    r138 r139  
    2626xmlNodePtr 
    2727XMLIStream::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 
     33xmlNodePtr 
     34XMLIStream::findNonTextNode(xmlNodePtr pNode) { 
     35  while(pNode != NULL && (xmlIsBlankNode(pNode) == 1)) 
     36    pNode = pNode->next; 
    3537  return pNode; 
    3638}; 
     
    6163        if (entry->getFKeyName() == NULL)  
    6264          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      { 
    6468        return entry; 
    6569      }; 
     
    7983void 
    8084XMLIStream::getChildren(Storeable* pParent, xmlNodePtr pNode) { 
    81   pNode = setNextNode(pNode); 
     85  pNode = findNonTextNode(pNode); 
    8286  //if (pNode) std::cerr << "getChildren at node " << pNode->name << std::endl; 
    8387  //ignore all nodes that are binded to pParent class members 
     
    103107      open(child,member->getTableName());  
    104108 
    105       xmlNodePtr node = setNextNode(pNode); 
     109      xmlNodePtr node = findNonTextNode(pNode); 
    106110      while (node != NULL) {  
    107111        mCurrentNode = node; 
     
    111115        if (node->children != NULL) 
    112116          getChildren(&child,node->children); 
    113    
     117 
    114118        childFilter->updateRef((char*)pParent + member->getMemberOffset()); 
    115119        childFilter->put(); 
  • trunk/dba/dba/xmlistream.h

    r138 r139  
    4040    void applyFilters(Storeable* pObject); 
    4141    xmlNodePtr setNextNode(xmlNodePtr pNode); 
     42    xmlNodePtr findNonTextNode(xmlNodePtr pNode); 
    4243    ColMemberEntry* findMember(Storeable* pObject, xmlNodePtr pNode); 
    4344    ColMemberEntry* findNullMember(Storeable* pObject); 
  • trunk/dba/test/testobject.cpp

    r48 r139  
    6868END_STORE_TABLE() 
    6969 
    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") 
     70BEGIN_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") 
    7373END_STORE_TABLE() 
    7474 
  • trunk/dba/test/testobject.h

    r138 r139  
    302302  Object that contains list of other storeable objects 
    303303*/ 
    304 class ObjWithList : public dba::Storeable { 
     304class 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 
     336class ObjWithList : public ObjWithListBase { 
    305337    DECLARE_STORE_TABLE(); 
    306338  public: 
    307339    ObjWithList() {}; 
    308340    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) {}; 
    335342}; 
    336343 
  • trunk/dba/test/xmltestcase.cpp

    r138 r139  
    1414#include "dba/fileutils.h" 
    1515#include "dba/int_filter.h" 
     16#include "dba/string_filter.h" 
     17#include "dba/stdlist.h" 
    1618 
    1719#include <fstream> 
     
    290292}; 
    291293 
     294class XMLObjWithOneUnnamedList : public ObjWithListBase { 
     295    DECLARE_STORE_TABLE(); 
     296  public: 
     297    XMLObjWithOneUnnamedList() {} 
     298    XMLObjWithOneUnnamedList(const char* pName, int pCount)  
     299      : ObjWithListBase(pName, pCount) {} 
     300}; 
     301 
     302BEGIN_STORE_TABLE(XMLObjWithOneUnnamedList,ObjWithListBase,"obj_with_list") 
     303  BIND_STR(ObjWithListBase::mName, dba::String, "name") 
     304  BIND_COL(ObjWithListBase::mList, dba::stdList<TestObject>, NULL) 
     305END_STORE_TABLE() 
     306 
     307void  
     308XMLTestCase::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 
     328void  
     329XMLTestCase::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 
    292355 
    293356} //namespace 
  • trunk/dba/test/xmltestcase.h

    r138 r139  
    3737      CPPUNIT_TEST(sublist_one_load); 
    3838      CPPUNIT_TEST(sublist_two_load); 
     39      CPPUNIT_TEST(sublist_one_store_nofk); 
     40      CPPUNIT_TEST(sublist_one_load_nofk); 
    3941    CPPUNIT_TEST_SUITE_END(); 
    4042  public: 
     
    5557    void sublist_one_load(); 
    5658    void sublist_two_load(); 
     59    void sublist_one_store_nofk(); 
     60    void sublist_one_load_nofk(); 
    5761  private: 
    5862    bool compareXML(const char* pFilename, const char* pData);