Changeset 130

Show
Ignore:
Timestamp:
05/03/08 14:00:09 (8 months ago)
Author:
zork
Message:

stubs for input and output streams, test tools for xml write

Files:

Legend:

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

    r129 r130  
    1212#include "xmlarchive.h" 
    1313#include "fileutils.h" 
     14#include "xmlistream.h" 
     15#include "xmlostream.h" 
    1416 
    1517namespace dba { 
     
    4951IStream*  
    5052XMLArchive::getInputStream() { 
    51   //TODO  
     53  return new XMLIStream(mRootNode,mConvSpecs); 
    5254}; 
    5355 
    5456OStream*  
    5557XMLArchive::getOutputStream() { 
    56   //TODO 
     58  return new XMLOStream(mRootNode,mConvSpecs); 
     59}; 
     60 
     61XMLIStream  
     62XMLArchive::getIStream() { 
     63  XMLIStream ret(mRootNode,mConvSpecs); 
     64  return ret; 
     65}; 
     66 
     67XMLOStream  
     68XMLArchive::getOStream() { 
     69  XMLOStream ret(mRootNode,mConvSpecs); 
     70  return ret; 
    5771}; 
    5872 
  • trunk/dba/dba/xmlarchive.h

    r129 r130  
    1414 
    1515#include "archive.h" 
     16#include "xmlistream.h" 
     17#include "xmlostream.h" 
    1618#include "xmlerrorhandler.h" 
    1719#include <libxml/tree.h> 
    1820 
    1921namespace dba { 
    20  
    21 class OStream; 
    22 class IStream; 
    2322 
    2423/** 
     
    3029    virtual void open(const char* pOpenStr); 
    3130    virtual bool isOpen() const { return mRootNode != NULL; } 
     31    XMLOStream getOStream(); 
     32    XMLIStream getIStream(); 
    3233    virtual IStream* getInputStream(); 
    3334    virtual OStream* getOutputStream(); 
  • trunk/dba/dba/xmlistream.cpp

    r126 r130  
    1414namespace dba { 
    1515 
    16 XMLIStream::XMLIStream() 
    17  : IStream() 
     16XMLIStream::XMLIStream(xmlNodePtr pNode, const ConvSpec& pSpecs) 
     17  : IStream(), 
     18    ConvSpecContainer(pSpecs), 
     19    mCurrentNode(pNode) 
    1820{ 
    1921} 
    2022 
     23void  
     24XMLIStream::close() { 
     25  //nothing to do here 
     26}; 
     27 
     28void  
     29XMLIStream::destroy() { 
     30  mCurrentNode = NULL; 
     31}; 
     32 
     33bool  
     34XMLIStream::getNext(Storeable* pObject) { 
     35  //TODO 
     36}; 
     37 
     38bool  
     39XMLIStream::updateVars() { 
     40  //TODO 
     41}; 
     42 
     43void  
     44XMLIStream::setIdsCondition(const char* pFKeyName, id pRelationId, const std::vector<id>& pIds) { 
     45  //TODO 
     46}; 
    2147 
    2248XMLIStream::~XMLIStream() 
     
    2551 
    2652 
    27 } 
     53} //namespace 
  • trunk/dba/dba/xmlistream.h

    r126 r130  
    1414 
    1515#include "istream.h" 
     16#include "xmlerrorhandler.h" 
     17#include <libxml/tree.h> 
    1618 
    1719namespace dba { 
     
    2022Object input stream for XMLArchive 
    2123*/ 
    22 class XMLIStream  : public IStream
     24class XMLIStream  : public IStream, public XMLErrorHandler, public ConvSpecContainer
    2325  public: 
    24     XMLIStream(); 
    25     ~XMLIStream(); 
     26    XMLIStream(xmlNodePtr pNode, const ConvSpec& pSpecs); 
     27    virtual void close(); 
     28    virtual void destroy(); 
     29    virtual bool getNext(Storeable* pObject); 
     30    virtual bool updateVars(); 
     31    virtual bool isCollectionFilterSupported() const { return true; }; 
     32    virtual ~XMLIStream(); 
     33  private: 
     34    xmlNodePtr mCurrentNode; 
     35     
     36    virtual void setIdsCondition(const char* pFKeyName, id pRelationId, const std::vector<id>& pIds); 
    2637}; 
    2738 
  • trunk/dba/dba/xmlostream.cpp

    r126 r130  
    1414namespace dba { 
    1515 
    16 XMLOStream::XMLOStream() 
    17  : OStream() 
     16XMLOStream::XMLOStream(xmlNodePtr pNode, const ConvSpec& pSpecs) 
     17  : OStream(), 
     18    ConvSpecContainer(pSpecs) 
    1819{ 
    1920} 
    2021 
     22void  
     23XMLOStream::close() { 
     24  //TODO 
     25}; 
     26 
     27void  
     28XMLOStream::destroy() { 
     29  //TODO 
     30}; 
     31 
     32void  
     33XMLOStream::assignId(Storeable* pObject) throw (Exception) { 
     34  //TODO 
     35}; 
     36 
     37bool  
     38XMLOStream::erase(Storeable* pObject) { 
     39  //TODO 
     40}; 
     41 
     42bool  
     43XMLOStream::update(Storeable* pObject) { 
     44  //TODO 
     45}; 
     46 
     47bool  
     48XMLOStream::store(Storeable* pObject) { 
     49  //TODO 
     50}; 
     51 
     52std::vector<id>  
     53XMLOStream::loadRefData(const char* pTable, const char* pFkName, id pCollId, id pId) { 
     54  //TODO 
     55}; 
     56 
     57bool  
     58XMLOStream::deleteRefData(const std::vector<id>& pIds, const char* pTableName) { 
     59  //TODO 
     60}; 
    2161 
    2262XMLOStream::~XMLOStream() 
  • trunk/dba/dba/xmlostream.h

    r126 r130  
    1414 
    1515#include "ostream.h" 
     16#include "xmlerrorhandler.h" 
     17#include <libxml/tree.h> 
    1618 
    1719namespace dba { 
     
    2022Object output stream for XMLArchive 
    2123*/ 
    22 class XMLOStream  : public OStream
     24class XMLOStream  : public OStream, public XMLErrorHandler, public ConvSpecContainer
    2325  public: 
    24     XMLOStream(); 
    25     ~XMLOStream(); 
     26    XMLOStream(xmlNodePtr pNode, const ConvSpec& pSpecs); 
     27    virtual void close(); 
     28    virtual void destroy(); 
     29    virtual void begin() { throw APIException("begin() not supported for XML format"); } 
     30    virtual void commit() { throw APIException("commit() not supported for XML format"); } 
     31    virtual void rollback() { throw APIException("rollback() not supported for XML format"); } 
     32    virtual void assignId(Storeable* pObject) throw (Exception); 
     33    virtual bool erase(Storeable* pObject); 
     34    virtual bool update(Storeable* pObject); 
     35    virtual bool store(Storeable* pObject); 
     36    virtual bool isCollectionFilterSupported() const { return true; }; 
     37    virtual std::vector<id> loadRefData(const char* pTable, const char* pFkName, id pCollId, id pId); 
     38    virtual bool deleteRefData(const std::vector<id>& pIds, const char* pTableName); 
     39    virtual ~XMLOStream(); 
    2640}; 
    2741 
  • trunk/dba/test/main.cpp

    r129 r130  
    151151  //runner.addTest(new CppUnit::TestCaller<SQLite3SQLArchiveTestCase>("debug_test",&SQLite3SQLArchiveTestCase::transactions_rollback)); 
    152152  //runner.addTest(dba_tests::XMLTestCase::suite()); 
    153   runner.addTest(new CppUnit::TestCaller<dba_tests::XMLTestCase>("debug_test",&dba_tests::XMLTestCase::encodingChange)); 
     153  runner.addTest(new CppUnit::TestCaller<dba_tests::XMLTestCase>("debug_test",&dba_tests::XMLTestCase::simpleStore)); 
    154154  //runner.addTest(new CppUnit::TestCaller<OdbcPluginTestCase>("debug_test",&OdbcPluginTestCase::dbConnection)); 
    155155  //runner.addTest(new CppUnit::TestCaller<PostgresSQLArchiveTestCase>("debug_test",&PostgresSQLArchiveTestCase::sqlError)); 
  • trunk/dba/test/xmltestcase.cpp

    r129 r130  
    1111// 
    1212#include "xmltestcase.h" 
     13#include "testobject.h" 
    1314#include "dba/fileutils.h" 
    1415 
     
    2627 
    2728XMLTestCase::~XMLTestCase() { 
     29}; 
     30 
     31bool 
     32XMLTestCase::compareXML(const char* pFilename, const char* pData) { 
     33  ErrorContext c(this); 
     34  xmlDocPtr doc = xmlParseFile(pFilename); 
     35  if (doc == NULL) { 
     36    if (c.wasError()) 
     37      throw c.createException(); 
     38    else 
     39      throw dba::XMLException("Error reading test file"); 
     40  }; 
     41  int len; 
     42  xmlChar* buf; 
     43  xmlDocDumpFormatMemoryEnc(doc,&buf,&len,(const char*)doc->encoding,1); 
     44  bool ret = strcmp((const char*)buf,pData) == 0; 
     45  if (!ret) { 
     46    std::cerr << "file: " << std::endl << buf << std::endl; 
     47    std::cerr << "expected: " << std::endl << pData << std::endl; 
     48  }; 
     49  xmlFree(buf); 
     50  return ret; 
    2851}; 
    2952 
     
    5275}; 
    5376 
     77void 
     78XMLTestCase::simpleStore() { 
     79  const char* result =  
     80"<?xml version=\"1.0\" encoding=\"utf-8\">\n" 
     81"<dba>\n" 
     82"<test_objects id=\"1\" i_value=\"1\" f_value=\"1.1\" s_value=\"test\" d_value=\"2008-01-01Z00:00:00\"/>\n" 
     83"</dba>\n"; 
     84  { 
     85    dba::XMLArchive ar; 
     86    unlink("simplestore.xml"); 
     87    ar.open("simplestore.xml"); 
     88    TestObject obj1(1,1.1,"test",Utils::getDate(2008,1,1,0,0,0)); 
     89    dba::XMLOStream stream(ar.getOStream()); 
     90    stream.open(); 
     91    stream.put(&obj1); 
     92  } 
     93  CPPUNIT_ASSERT(compareXML("simplestore.xml",result)); 
     94}; 
     95 
    5496} //namespace 
  • trunk/dba/test/xmltestcase.h

    r129 r130  
    2424tests from XMLArchive 
    2525*/ 
    26 class XMLTestCase : public CppUnit::TestCase
     26class XMLTestCase : public CppUnit::TestCase, public dba::XMLErrorHandler
    2727    CPPUNIT_TEST_SUITE(XMLTestCase); 
    2828      CPPUNIT_TEST(empty); 
    2929      CPPUNIT_TEST(encodingChange); 
     30      CPPUNIT_TEST(simpleStore); 
    3031    CPPUNIT_TEST_SUITE_END(); 
    3132  public: 
     
    3738    void empty(); 
    3839    void encodingChange(); 
     40    void simpleStore(); 
    3941  private: 
     42    bool compareXML(const char* pFilename, const char* pData); 
    4043}; 
    4144