mirror of https://github.com/vitalif/grive2
trying to read properties from entry XML
parent
826db0e064
commit
f80a5f0fb7
|
@ -43,7 +43,7 @@ file (GLOB LIBGRIVE_SRC
|
|||
src/xml/*.cc
|
||||
)
|
||||
|
||||
add_definitions( -DVERSION="${GRIVE_VERSION}" )
|
||||
add_definitions( -DVERSION="${GRIVE_VERSION}" -DTEST_DATA="${libgrive_SOURCE_DIR}/test/data/" )
|
||||
|
||||
add_library( grive SHARED ${LIBGRIVE_SRC} )
|
||||
|
||||
|
@ -75,6 +75,7 @@ IF ( CPPUNIT_FOUND )
|
|||
|
||||
# list of test source files here
|
||||
file(GLOB TEST_SRC
|
||||
test/drive/*.cc
|
||||
test/util/*.cc
|
||||
test/xml/*.cc
|
||||
)
|
||||
|
|
|
@ -115,13 +115,10 @@ Drive::FolderListIterator Drive::FindFolder( const std::string& href )
|
|||
void Drive::ConstructDirTree( http::Agent *http )
|
||||
{
|
||||
http::XmlResponse xml ;
|
||||
http::ResponseLog log( "dir-", &xml ) ;
|
||||
http::ResponseLog log( "dir-", ".xml", &xml ) ;
|
||||
|
||||
http->Get( root_url + "/-/folder?showroot=true&max-results=10", &log, m_http_hdr ) ;
|
||||
|
||||
std::ofstream abc( "abc.xml" ) ;
|
||||
abc << xml.Response()["feed"]["entry"] ;
|
||||
|
||||
http::JsonResponse jrsp ;
|
||||
http->Get( root_url + "/-/folder?alt=json", &jrsp, m_http_hdr ) ;
|
||||
Json resp = jrsp.Response() ;
|
||||
|
|
|
@ -48,6 +48,8 @@ Entry::Entry( const Json& entry )
|
|||
|
||||
Entry::Entry( const xml::Node& n )
|
||||
{
|
||||
m_title = n["title"].Value() ;
|
||||
m_etag = n["@gd:etag"].Value() ;
|
||||
}
|
||||
|
||||
Entry::Entry( const std::string& title, const std::string& href ) :
|
||||
|
|
|
@ -25,8 +25,11 @@
|
|||
|
||||
namespace gr { namespace http {
|
||||
|
||||
ResponseLog::ResponseLog( const std::string& prefix, Receivable *next ) :
|
||||
m_log( Filename(prefix).c_str() ),
|
||||
ResponseLog::ResponseLog(
|
||||
const std::string& prefix,
|
||||
const std::string& suffix,
|
||||
Receivable *next ) :
|
||||
m_log( Filename(prefix, suffix).c_str() ),
|
||||
m_next( next )
|
||||
{
|
||||
}
|
||||
|
@ -43,9 +46,9 @@ void ResponseLog::Clear()
|
|||
m_next->Clear() ;
|
||||
}
|
||||
|
||||
std::string ResponseLog::Filename( const std::string& prefix )
|
||||
std::string ResponseLog::Filename( const std::string& prefix, const std::string& suffix )
|
||||
{
|
||||
return prefix + DateTime::Now().Format( "%H%M%S" ) ;
|
||||
return prefix + DateTime::Now().Format( "%H%M%S" ) + suffix ;
|
||||
}
|
||||
|
||||
}} // end of namespace
|
||||
|
|
|
@ -29,13 +29,16 @@ namespace gr { namespace http {
|
|||
class ResponseLog : public Receivable
|
||||
{
|
||||
public :
|
||||
ResponseLog( const std::string& prefix, Receivable *next ) ;
|
||||
ResponseLog(
|
||||
const std::string& prefix,
|
||||
const std::string& suffix,
|
||||
Receivable *next ) ;
|
||||
|
||||
std::size_t OnData( void *data, std::size_t count ) ;
|
||||
void Clear() ;
|
||||
|
||||
private :
|
||||
static std::string Filename( const std::string& prefix ) ;
|
||||
static std::string Filename( const std::string& prefix, const std::string& suffix ) ;
|
||||
|
||||
private :
|
||||
std::ofstream m_log ;
|
||||
|
|
|
@ -133,6 +133,11 @@ public :
|
|||
return m_children.end() ;
|
||||
}
|
||||
|
||||
std::size_t Size() const
|
||||
{
|
||||
return m_children.size() ;
|
||||
}
|
||||
|
||||
std::pair<iterator, iterator> Attr()
|
||||
{
|
||||
return std::make_pair( m_attr.begin(), m_attr.end() ) ;
|
||||
|
@ -195,7 +200,10 @@ Node::iterator::iterator( ImplVec::iterator i ) : iterator_adaptor(i)
|
|||
|
||||
Node::iterator::reference Node::iterator::dereference() const
|
||||
{
|
||||
return Node( (*base_reference())->AddRef() ) ;
|
||||
Impl *p = *base_reference() ;
|
||||
assert( p != 0 ) ;
|
||||
|
||||
return Node( p->AddRef() ) ;
|
||||
}
|
||||
|
||||
Node::Node() : m_ptr( new Impl )
|
||||
|
@ -380,16 +388,25 @@ std::ostream& Node::PrintChar( std::ostream& os, char c )
|
|||
|
||||
Node::iterator Node::begin() const
|
||||
{
|
||||
assert( m_ptr != 0 ) ;
|
||||
return iterator( m_ptr->Begin() ) ;
|
||||
}
|
||||
|
||||
Node::iterator Node::end() const
|
||||
{
|
||||
assert( m_ptr != 0 ) ;
|
||||
return iterator( m_ptr->End() ) ;
|
||||
}
|
||||
|
||||
std::size_t Node::size() const
|
||||
{
|
||||
assert( m_ptr != 0 ) ;
|
||||
return m_ptr->Size() ;
|
||||
}
|
||||
|
||||
Node::Range Node::Attr() const
|
||||
{
|
||||
assert( m_ptr != 0 ) ;
|
||||
std::pair<Impl::iterator, Impl::iterator> is = m_ptr->Attr() ;
|
||||
|
||||
return std::make_pair( iterator(is.first), iterator(is.second) ) ;
|
||||
|
@ -397,6 +414,7 @@ Node::Range Node::Attr() const
|
|||
|
||||
Node::Range Node::Children( const std::string& name ) const
|
||||
{
|
||||
assert( m_ptr != 0 ) ;
|
||||
std::pair<Impl::iterator, Impl::iterator> is = m_ptr->Children( name ) ;
|
||||
|
||||
return std::make_pair( iterator(is.first), iterator(is.second) ) ;
|
||||
|
|
|
@ -70,6 +70,7 @@ public :
|
|||
|
||||
iterator begin() const ;
|
||||
iterator end() const ;
|
||||
std::size_t size() const ;
|
||||
|
||||
Range Attr() const ;
|
||||
Range Children( const std::string& name ) const ;
|
||||
|
|
|
@ -80,8 +80,13 @@ Node TreeBuilder::Parse( const std::string& xml )
|
|||
|
||||
Node TreeBuilder::Result() const
|
||||
{
|
||||
// the node on the stack should be the dummy node with only one child
|
||||
assert( m_impl->stack.size() == 1 ) ;
|
||||
return m_impl->stack.front() ;
|
||||
|
||||
if ( m_impl->stack.front().size() != 1 )
|
||||
throw std::runtime_error( "invalid node" ) ;
|
||||
|
||||
return *m_impl->stack.front().begin() ;
|
||||
}
|
||||
|
||||
void TreeBuilder::StartElement( void *pvthis, const char *name, const char **attr )
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
|
||||
#include "drive/EntryTest.hh"
|
||||
#include "util/DateTimeTest.hh"
|
||||
#include "util/FunctionTest.hh"
|
||||
#include "util/PathTest.hh"
|
||||
|
@ -30,6 +31,7 @@ int main( int argc, char **argv )
|
|||
using namespace grut ;
|
||||
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest( EntryTest::suite( ) ) ;
|
||||
runner.addTest( DateTimeTest::suite( ) ) ;
|
||||
runner.addTest( FunctionTest::suite( ) ) ;
|
||||
runner.addTest( PathTest::suite( ) ) ;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
grive: an GPL program to sync a local directory with Google Drive
|
||||
Copyright (C) 2012 Wan Wai Ho
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "EntryTest.hh"
|
||||
|
||||
#include "Assert.hh"
|
||||
|
||||
#include "drive/Entry.hh"
|
||||
#include "xml/Node.hh"
|
||||
#include "xml/TreeBuilder.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace grut {
|
||||
|
||||
using namespace gr ;
|
||||
|
||||
EntryTest::EntryTest( )
|
||||
{
|
||||
}
|
||||
|
||||
void EntryTest::TestXml( )
|
||||
{
|
||||
xml::Node root = xml::TreeBuilder::ParseFile( TEST_DATA "entry.xml" ) ;
|
||||
|
||||
xml::Node::Range entries = root.Children( "entry" ) ;
|
||||
CPPUNIT_ASSERT( entries.first != entries.second ) ;
|
||||
|
||||
Entry subject( *entries.first ) ;
|
||||
GRUT_ASSERT_EQUAL( "snes", subject.Title() ) ;
|
||||
GRUT_ASSERT_EQUAL( "\"WxYPGE8CDyt7ImBk\"", subject.ETag() ) ;
|
||||
}
|
||||
|
||||
} // end of namespace grut
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
grive: an GPL program to sync a local directory with Google Drive
|
||||
Copyright (C) 2012 Wan Wai Ho
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace grut {
|
||||
|
||||
class EntryTest : public CppUnit::TestFixture
|
||||
{
|
||||
public :
|
||||
EntryTest( ) ;
|
||||
|
||||
// declare suit function
|
||||
CPPUNIT_TEST_SUITE( EntryTest ) ;
|
||||
CPPUNIT_TEST( TestXml ) ;
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private :
|
||||
void TestXml( ) ;
|
||||
} ;
|
||||
|
||||
} // end of namespace
|
|
@ -57,7 +57,10 @@ void NodeTest::TestTree( )
|
|||
|
||||
void NodeTest::TestParseFile( )
|
||||
{
|
||||
Node n = TreeBuilder::Parse( "<entry><link href=\"q\"><href>abc</href></link><link></link></entry>" ) ;
|
||||
Node n ;
|
||||
n.AddNode( TreeBuilder::Parse( "<entry><link href=\"q\"><href>abc</href></link><link></link></entry>" ) ) ;
|
||||
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("entry"), n["entry"].Name() ) ;
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("link"), n["entry"]["link"].Name() ) ;
|
||||
CPPUNIT_ASSERT_EQUAL( std::string("q"), n["entry"]["link"]["@href"].Value() ) ;
|
||||
|
|
Loading…
Reference in New Issue