Changeset 130
- Timestamp:
- 05/03/08 14:00:09 (8 months ago)
- Files:
-
- trunk/dba/dba/xmlarchive.cpp (modified) (2 diffs)
- trunk/dba/dba/xmlarchive.h (modified) (2 diffs)
- trunk/dba/dba/xmlistream.cpp (modified) (2 diffs)
- trunk/dba/dba/xmlistream.h (modified) (2 diffs)
- trunk/dba/dba/xmlostream.cpp (modified) (1 diff)
- trunk/dba/dba/xmlostream.h (modified) (2 diffs)
- trunk/dba/test/main.cpp (modified) (1 diff)
- trunk/dba/test/xmltestcase.cpp (modified) (3 diffs)
- trunk/dba/test/xmltestcase.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dba/dba/xmlarchive.cpp
r129 r130 12 12 #include "xmlarchive.h" 13 13 #include "fileutils.h" 14 #include "xmlistream.h" 15 #include "xmlostream.h" 14 16 15 17 namespace dba { … … 49 51 IStream* 50 52 XMLArchive::getInputStream() { 51 //TODO53 return new XMLIStream(mRootNode,mConvSpecs); 52 54 }; 53 55 54 56 OStream* 55 57 XMLArchive::getOutputStream() { 56 //TODO 58 return new XMLOStream(mRootNode,mConvSpecs); 59 }; 60 61 XMLIStream 62 XMLArchive::getIStream() { 63 XMLIStream ret(mRootNode,mConvSpecs); 64 return ret; 65 }; 66 67 XMLOStream 68 XMLArchive::getOStream() { 69 XMLOStream ret(mRootNode,mConvSpecs); 70 return ret; 57 71 }; 58 72 trunk/dba/dba/xmlarchive.h
r129 r130 14 14 15 15 #include "archive.h" 16 #include "xmlistream.h" 17 #include "xmlostream.h" 16 18 #include "xmlerrorhandler.h" 17 19 #include <libxml/tree.h> 18 20 19 21 namespace dba { 20 21 class OStream;22 class IStream;23 22 24 23 /** … … 30 29 virtual void open(const char* pOpenStr); 31 30 virtual bool isOpen() const { return mRootNode != NULL; } 31 XMLOStream getOStream(); 32 XMLIStream getIStream(); 32 33 virtual IStream* getInputStream(); 33 34 virtual OStream* getOutputStream(); trunk/dba/dba/xmlistream.cpp
r126 r130 14 14 namespace dba { 15 15 16 XMLIStream::XMLIStream() 17 : IStream() 16 XMLIStream::XMLIStream(xmlNodePtr pNode, const ConvSpec& pSpecs) 17 : IStream(), 18 ConvSpecContainer(pSpecs), 19 mCurrentNode(pNode) 18 20 { 19 21 } 20 22 23 void 24 XMLIStream::close() { 25 //nothing to do here 26 }; 27 28 void 29 XMLIStream::destroy() { 30 mCurrentNode = NULL; 31 }; 32 33 bool 34 XMLIStream::getNext(Storeable* pObject) { 35 //TODO 36 }; 37 38 bool 39 XMLIStream::updateVars() { 40 //TODO 41 }; 42 43 void 44 XMLIStream::setIdsCondition(const char* pFKeyName, id pRelationId, const std::vector<id>& pIds) { 45 //TODO 46 }; 21 47 22 48 XMLIStream::~XMLIStream() … … 25 51 26 52 27 } 53 } //namespace trunk/dba/dba/xmlistream.h
r126 r130 14 14 15 15 #include "istream.h" 16 #include "xmlerrorhandler.h" 17 #include <libxml/tree.h> 16 18 17 19 namespace dba { … … 20 22 Object input stream for XMLArchive 21 23 */ 22 class XMLIStream : public IStream {24 class XMLIStream : public IStream, public XMLErrorHandler, public ConvSpecContainer { 23 25 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); 26 37 }; 27 38 trunk/dba/dba/xmlostream.cpp
r126 r130 14 14 namespace dba { 15 15 16 XMLOStream::XMLOStream() 17 : OStream() 16 XMLOStream::XMLOStream(xmlNodePtr pNode, const ConvSpec& pSpecs) 17 : OStream(), 18 ConvSpecContainer(pSpecs) 18 19 { 19 20 } 20 21 22 void 23 XMLOStream::close() { 24 //TODO 25 }; 26 27 void 28 XMLOStream::destroy() { 29 //TODO 30 }; 31 32 void 33 XMLOStream::assignId(Storeable* pObject) throw (Exception) { 34 //TODO 35 }; 36 37 bool 38 XMLOStream::erase(Storeable* pObject) { 39 //TODO 40 }; 41 42 bool 43 XMLOStream::update(Storeable* pObject) { 44 //TODO 45 }; 46 47 bool 48 XMLOStream::store(Storeable* pObject) { 49 //TODO 50 }; 51 52 std::vector<id> 53 XMLOStream::loadRefData(const char* pTable, const char* pFkName, id pCollId, id pId) { 54 //TODO 55 }; 56 57 bool 58 XMLOStream::deleteRefData(const std::vector<id>& pIds, const char* pTableName) { 59 //TODO 60 }; 21 61 22 62 XMLOStream::~XMLOStream() trunk/dba/dba/xmlostream.h
r126 r130 14 14 15 15 #include "ostream.h" 16 #include "xmlerrorhandler.h" 17 #include <libxml/tree.h> 16 18 17 19 namespace dba { … … 20 22 Object output stream for XMLArchive 21 23 */ 22 class XMLOStream : public OStream {24 class XMLOStream : public OStream, public XMLErrorHandler, public ConvSpecContainer { 23 25 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(); 26 40 }; 27 41 trunk/dba/test/main.cpp
r129 r130 151 151 //runner.addTest(new CppUnit::TestCaller<SQLite3SQLArchiveTestCase>("debug_test",&SQLite3SQLArchiveTestCase::transactions_rollback)); 152 152 //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)); 154 154 //runner.addTest(new CppUnit::TestCaller<OdbcPluginTestCase>("debug_test",&OdbcPluginTestCase::dbConnection)); 155 155 //runner.addTest(new CppUnit::TestCaller<PostgresSQLArchiveTestCase>("debug_test",&PostgresSQLArchiveTestCase::sqlError)); trunk/dba/test/xmltestcase.cpp
r129 r130 11 11 // 12 12 #include "xmltestcase.h" 13 #include "testobject.h" 13 14 #include "dba/fileutils.h" 14 15 … … 26 27 27 28 XMLTestCase::~XMLTestCase() { 29 }; 30 31 bool 32 XMLTestCase::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; 28 51 }; 29 52 … … 52 75 }; 53 76 77 void 78 XMLTestCase::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 54 96 } //namespace trunk/dba/test/xmltestcase.h
r129 r130 24 24 tests from XMLArchive 25 25 */ 26 class XMLTestCase : public CppUnit::TestCase {26 class XMLTestCase : public CppUnit::TestCase, public dba::XMLErrorHandler { 27 27 CPPUNIT_TEST_SUITE(XMLTestCase); 28 28 CPPUNIT_TEST(empty); 29 29 CPPUNIT_TEST(encodingChange); 30 CPPUNIT_TEST(simpleStore); 30 31 CPPUNIT_TEST_SUITE_END(); 31 32 public: … … 37 38 void empty(); 38 39 void encodingChange(); 40 void simpleStore(); 39 41 private: 42 bool compareXML(const char* pFilename, const char* pData); 40 43 }; 41 44
