2012-05-24 20:55:28 +04:00
|
|
|
/*
|
|
|
|
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 "ResourceTest.hh"
|
|
|
|
|
|
|
|
#include "Assert.hh"
|
|
|
|
|
2015-06-27 23:18:03 +03:00
|
|
|
#include "base/Resource.hh"
|
2012-06-10 19:11:32 +04:00
|
|
|
|
2016-09-28 10:16:57 +03:00
|
|
|
#include "drive2/Entry2.hh"
|
2016-01-01 02:27:21 +03:00
|
|
|
#include "json/Val.hh"
|
2012-05-24 20:55:28 +04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace grut {
|
|
|
|
|
|
|
|
using namespace gr ;
|
2016-09-28 10:16:57 +03:00
|
|
|
using namespace gr::v2 ;
|
2012-05-24 20:55:28 +04:00
|
|
|
|
|
|
|
ResourceTest::ResourceTest( )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-10 19:11:32 +04:00
|
|
|
void ResourceTest::TestRootPath()
|
2012-05-24 20:55:28 +04:00
|
|
|
{
|
2016-01-06 12:55:02 +03:00
|
|
|
std::string rootFolder = "/home/usr/grive/grive";
|
|
|
|
Resource root( rootFolder ) ;
|
2012-06-10 19:11:32 +04:00
|
|
|
CPPUNIT_ASSERT( root.IsRoot() ) ;
|
2012-07-29 21:17:10 +04:00
|
|
|
GRUT_ASSERT_EQUAL( root.Path(), fs::path( rootFolder ) ) ;
|
2012-06-10 19:11:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResourceTest::TestNormal( )
|
|
|
|
{
|
|
|
|
Resource root( TEST_DATA, "folder" ) ;
|
|
|
|
Resource subject( "entry.xml", "file" ) ;
|
2012-06-10 11:37:56 +04:00
|
|
|
root.AddChild( &subject ) ;
|
2012-05-24 20:55:28 +04:00
|
|
|
|
2016-01-06 12:55:02 +03:00
|
|
|
GRUT_ASSERT_EQUAL( subject.IsRoot(), false ) ;
|
2012-06-10 19:11:32 +04:00
|
|
|
GRUT_ASSERT_EQUAL( subject.Path(), fs::path( TEST_DATA ) / "entry.xml" ) ;
|
|
|
|
|
2016-01-01 02:27:21 +03:00
|
|
|
Val st;
|
2016-01-06 12:55:02 +03:00
|
|
|
st.Add( "srv_time", Val( DateTime( "2012-05-09T16:13:22.401Z" ).Sec() ) );
|
2016-01-02 15:04:28 +03:00
|
|
|
subject.FromLocal( st ) ;
|
2012-06-10 19:11:32 +04:00
|
|
|
GRUT_ASSERT_EQUAL( subject.MD5(), "c0742c0a32b2c909b6f176d17a6992d0" ) ;
|
|
|
|
GRUT_ASSERT_EQUAL( subject.StateStr(), "local_new" ) ;
|
|
|
|
|
2016-09-28 10:16:57 +03:00
|
|
|
Val entry;
|
|
|
|
entry.Set( "modifiedDate", Val( std::string( "2012-05-09T16:13:22.401Z" ) ) );
|
|
|
|
entry.Set( "md5Checksum", Val( std::string( "DIFFERENT" ) ) );
|
2012-06-10 19:11:32 +04:00
|
|
|
|
2016-09-28 10:16:57 +03:00
|
|
|
Entry2 remote( entry ) ;
|
2016-01-06 12:55:02 +03:00
|
|
|
GRUT_ASSERT_EQUAL( "different", remote.MD5() ) ;
|
2016-01-01 22:04:39 +03:00
|
|
|
subject.FromRemote( remote ) ;
|
2012-07-29 21:17:10 +04:00
|
|
|
GRUT_ASSERT_EQUAL( "local_changed", subject.StateStr() ) ;
|
2012-05-24 20:55:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end of namespace grut
|