2013-05-15 17:19:46 +04:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# Test script for the ownCloud module of csync.
|
|
|
|
# This script requires a running ownCloud instance accessible via HTTP.
|
|
|
|
# It does quite some fancy tests and asserts the results.
|
|
|
|
#
|
|
|
|
# Copyright (C) by Olivier Goffart <ogoffart@woboq.com>
|
|
|
|
#
|
2014-02-24 14:08:58 +04:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library 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
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
#
|
2013-05-15 17:19:46 +04:00
|
|
|
|
|
|
|
use lib ".";
|
|
|
|
|
2014-08-28 20:06:47 +04:00
|
|
|
|
2013-05-15 17:19:46 +04:00
|
|
|
use File::Copy;
|
|
|
|
use ownCloud::Test;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2013-11-06 14:26:20 +04:00
|
|
|
print "Hello, this is t3, a tester for renaming directories\n";
|
2013-05-15 17:19:46 +04:00
|
|
|
|
|
|
|
initTesting();
|
|
|
|
|
2013-11-14 19:10:41 +04:00
|
|
|
printInfo( "Copy some files to the remote location\n" );
|
2013-05-15 17:19:46 +04:00
|
|
|
createRemoteDir( "remoteToLocal1" );
|
|
|
|
createRemoteDir( "remoteToLocal1/rtl1" );
|
|
|
|
createRemoteDir( "remoteToLocal1/rtl1/rtl11" );
|
|
|
|
createRemoteDir( "remoteToLocal1/rtl2" );
|
|
|
|
|
|
|
|
glob_put( 'toremote1/*', "remoteToLocal1/" );
|
|
|
|
glob_put( 'toremote1/rtl1/*', "remoteToLocal1/rtl1/" );
|
|
|
|
glob_put( 'testfiles/*', "remoteToLocal1/rtl1/rtl11/" );
|
|
|
|
glob_put( 'toremote1/rtl2/*', "remoteToLocal1/rtl2/" );
|
|
|
|
|
|
|
|
# call csync, sync local t1 to remote t1
|
|
|
|
csync();
|
|
|
|
|
|
|
|
# Check if the files from toremote1 are now in t1/remoteToLocal1
|
|
|
|
# they should have taken the way via the ownCloud.
|
2013-11-14 19:10:41 +04:00
|
|
|
printInfo( "Assert the local file copy\n" );
|
2013-11-04 17:55:17 +04:00
|
|
|
assertLocalDirs( localDir().'remoteToLocal1', 'toremote1' );
|
2013-05-15 17:19:46 +04:00
|
|
|
|
|
|
|
# Check if the synced files from ownCloud have the same timestamp as the local ones.
|
2013-11-14 19:10:41 +04:00
|
|
|
printInfo( "Now assert remote 'toremote1' with local " . localDir() );
|
2013-05-15 17:19:46 +04:00
|
|
|
assertLocalAndRemoteDir( 'remoteToLocal1', 0);
|
|
|
|
|
|
|
|
# Make a new directory, moves a sub directory into. Remove the parent directory.
|
|
|
|
# create a new file on the server in the directory that will be renamed
|
2013-11-14 19:10:41 +04:00
|
|
|
printInfo( "Create a new directory and move subdirs into." );
|
2013-11-06 19:14:21 +04:00
|
|
|
my $newfile_md5 = createLocalFile(localDir()."remoteToLocal1/rtl1/rtl11/newfile.dat", 123);
|
2013-05-15 17:19:46 +04:00
|
|
|
unlink( localDir() . 'remoteToLocal1/rtl1/rtl11/test.txt' );
|
|
|
|
mkdir( localDir() . 'newdir' );
|
2013-11-14 20:06:53 +04:00
|
|
|
move( localDir() . 'remoteToLocal1/rtl1', localDir() . 'newdir/rtl1' );
|
2013-05-15 17:19:46 +04:00
|
|
|
system( "rm -rf " . localDir() . 'remoteToLocal1' );
|
|
|
|
system( "echo \"my file\" >> /tmp/myfile.txt" );
|
|
|
|
put_to_dir( '/tmp/myfile.txt', 'remoteToLocal1/rtl1/rtl11' );
|
|
|
|
|
2014-06-03 14:20:40 +04:00
|
|
|
# Also add a file with symbols
|
|
|
|
my $symbolName = "a\%b#c\$d-e";
|
|
|
|
|
|
|
|
system( "echo \"my symbols\" >> /tmp/$symbolName" );
|
|
|
|
put_to_dir( "/tmp/$symbolName", 'remoteToLocal1/rtl1/rtl11' );
|
|
|
|
|
|
|
|
|
2013-11-15 12:36:06 +04:00
|
|
|
my $fileid = remoteFileId( 'remoteToLocal1/rtl1/', 'rtl11' );
|
|
|
|
my $fid2 = remoteFileId( 'remoteToLocal1/rtl1/', 'La ced' );
|
2013-11-15 14:46:07 +04:00
|
|
|
assert($fid2 eq "" or $fileid ne $fid2, "File IDs are equal" );
|
2013-11-15 12:36:06 +04:00
|
|
|
|
2013-05-15 17:19:46 +04:00
|
|
|
csync();
|
2013-11-15 12:36:06 +04:00
|
|
|
my $newFileId = remoteFileId( 'newdir/rtl1/', 'rtl11' );
|
|
|
|
my $newfid2 = remoteFileId( 'newdir/rtl1/', 'La ced' );
|
2013-11-15 14:46:07 +04:00
|
|
|
assert($newFileId eq "" or $newFileId ne $newfid2, "File IDs are equal" );
|
2013-11-15 12:36:06 +04:00
|
|
|
|
|
|
|
assert( $fileid eq $newFileId, "file ID mixup: 'newdir/rtl1/rtl11" );
|
|
|
|
assert( $fid2 eq $newfid2, "file ID mixup: 'newdir/La ced" );
|
|
|
|
|
2013-11-06 14:26:20 +04:00
|
|
|
assertLocalAndRemoteDir( 'newdir', 0);
|
2013-05-15 17:19:46 +04:00
|
|
|
|
2013-11-14 20:06:53 +04:00
|
|
|
assert( -e localDir().'newdir/rtl1/rtl11/newfile.dat' );
|
|
|
|
assert( -e localDir().'newdir/rtl1/rtl11/myfile.txt' );
|
|
|
|
assert( ! -e localDir().'newdir/rtl11/test.txt' );
|
2014-10-21 14:10:12 +04:00
|
|
|
# BUG! remoteToLocal1 is not deleted because changes were detected
|
|
|
|
# (even if the changed fileswere moved)
|
|
|
|
# assert( ! -e localDir().'remoteToLocal1' );
|
|
|
|
assert( ! -e localDir().'remoteToLocal1/rtl1' );
|
2013-05-15 17:19:46 +04:00
|
|
|
|
2013-11-14 19:10:41 +04:00
|
|
|
printInfo("Move file and create another one with the same name.");
|
2013-07-08 14:40:56 +04:00
|
|
|
move( localDir() . 'newdir/myfile.txt', localDir() . 'newdir/oldfile.txt' );
|
|
|
|
system( "echo \"super new\" >> " . localDir() . 'newdir/myfile.txt' );
|
|
|
|
|
2014-06-03 14:20:40 +04:00
|
|
|
#Move a file with symbols as well
|
|
|
|
move( localDir() . "newdir/$symbolName", localDir() . "newdir/$symbolName.new" );
|
|
|
|
|
2013-07-23 16:56:29 +04:00
|
|
|
#Add some files for the next test.
|
|
|
|
system( "echo \"un\" > " . localDir() . '1.txt' );
|
|
|
|
system( "echo \"deux\" > " . localDir() . '2.txt' );
|
2014-02-12 16:44:32 +04:00
|
|
|
system( "echo \"trois\" > " . localDir() . '3.txt' );
|
2013-12-05 18:34:39 +04:00
|
|
|
mkdir( localDir() . 'newdir2' );
|
2013-07-23 16:56:29 +04:00
|
|
|
|
|
|
|
csync();
|
2013-11-06 14:26:20 +04:00
|
|
|
assertLocalAndRemoteDir( 'newdir', 0);
|
2013-07-23 16:56:29 +04:00
|
|
|
|
2013-12-05 18:34:39 +04:00
|
|
|
|
|
|
|
printInfo("Rename a directory that was just changed");
|
|
|
|
# newdir was changed so it's etag is not yet saved in the database, but still it needs to be moved.
|
|
|
|
my $newdirId = remoteFileId( localDir(), 'newdir' );
|
|
|
|
my $newdir2Id = remoteFileId( localDir(), 'newdir2' );
|
|
|
|
move(localDir() . 'newdir' , localDir() . 'newdir3');
|
|
|
|
move(localDir() . 'newdir2' , localDir() . 'newdir4');
|
|
|
|
|
|
|
|
|
2013-11-06 14:26:20 +04:00
|
|
|
# FIXME: this test is currently failing
|
|
|
|
# see csync_update.c in _csyn_detect_update, the commen near the commented fs->inode != tmp->inode
|
|
|
|
# unlink( localDir() . '1.txt' );
|
|
|
|
# move( localDir() . '2.txt', localDir() . '1.txt' );
|
2013-12-05 18:34:39 +04:00
|
|
|
|
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( '', 0);
|
|
|
|
my $newdir3Id = remoteFileId( localDir(), 'newdir3' );
|
|
|
|
my $newdir4Id = remoteFileId( localDir(), 'newdir4' );
|
|
|
|
assert( $newdirId eq $newdir3Id, "newdir was not MOVE'd to newdir3?" );
|
|
|
|
assert( $newdir2Id eq $newdir4Id, "newdir2 was not MOVE'd to newdir4?" );
|
|
|
|
|
2014-02-12 16:44:32 +04:00
|
|
|
printInfo("Move a file and replace it by a new one");
|
|
|
|
|
|
|
|
|
|
|
|
move( localDir() . '1.txt', localDir() . '1_bis.txt' );
|
|
|
|
move( localDir() . '3.txt', localDir() . '3_bis.txt' );
|
|
|
|
system( "echo \"new file un\" > " . localDir() . '1.txt' );
|
|
|
|
system( "echo \"new file trois\" > " . localDir() . '3.txt' );
|
|
|
|
|
2014-11-11 18:27:06 +03:00
|
|
|
#also add special file with special character for next sync
|
|
|
|
#and file with special characters
|
|
|
|
createLocalFile(localDir(). 'hêllo%20th@re.txt' , 1208 );
|
|
|
|
|
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( '', 0);
|
|
|
|
|
|
|
|
printInfo("Move a file containing special character");
|
|
|
|
|
|
|
|
move(localDir(). 'hêllo%20th@re.txt', localDir(). 'hêllo%20th@re.doc');
|
2014-02-12 16:44:32 +04:00
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( '', 0);
|
|
|
|
|
2013-07-08 14:40:56 +04:00
|
|
|
|
2013-05-15 17:19:46 +04:00
|
|
|
cleanup();
|
|
|
|
|
|
|
|
# --
|