2015-07-01 15:53:47 +03:00
|
|
|
/*
|
|
|
|
* libcsync -- a library to sync a directory with another
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015-2013 by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2020-09-01 18:49:17 +03:00
|
|
|
#include <cstring>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <cstdio>
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2018-07-26 10:53:40 +03:00
|
|
|
#include "csync.h"
|
2018-07-25 17:00:16 +03:00
|
|
|
#include "vio/csync_vio_local.h"
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2020-11-27 13:13:54 +03:00
|
|
|
#include <QDir>
|
2015-07-03 12:46:45 +03:00
|
|
|
|
2020-11-27 13:13:54 +03:00
|
|
|
static const auto CSYNC_TEST_DIR = []{ return QStringLiteral("%1/csync_test").arg(QDir::tempPath());}();
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2017-09-07 12:02:05 +03:00
|
|
|
#include "torture.h"
|
|
|
|
|
2020-11-27 13:13:54 +03:00
|
|
|
namespace {
|
|
|
|
int oc_mkdir(const QString &path)
|
|
|
|
{
|
|
|
|
return QDir(path).mkpath(path) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-07-01 15:53:47 +03:00
|
|
|
#define WD_BUFFER_SIZE 255
|
|
|
|
|
|
|
|
static mbchar_t wd_buffer[WD_BUFFER_SIZE];
|
|
|
|
|
2022-09-30 20:56:31 +03:00
|
|
|
using statevar = struct {
|
2020-07-16 15:21:38 +03:00
|
|
|
QByteArray result;
|
|
|
|
QByteArray ignored_dir;
|
2022-09-30 20:56:31 +03:00
|
|
|
};
|
2015-07-01 15:53:47 +03:00
|
|
|
|
|
|
|
/* remove the complete test dir */
|
|
|
|
static int wipe_testdir()
|
|
|
|
{
|
2020-11-27 13:13:54 +03:00
|
|
|
QDir tmp(CSYNC_TEST_DIR);
|
|
|
|
if (tmp.exists())
|
|
|
|
{
|
|
|
|
return tmp.removeRecursively() ? 0 : 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2015-07-01 15:53:47 +03:00
|
|
|
}
|
|
|
|
|
2017-08-21 21:05:00 +03:00
|
|
|
static int setup_testenv(void **state) {
|
2020-12-10 21:52:58 +03:00
|
|
|
int rc = 0;
|
2015-07-01 15:53:47 +03:00
|
|
|
|
|
|
|
rc = wipe_testdir();
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2020-11-27 13:13:54 +03:00
|
|
|
auto dir = CSYNC_TEST_DIR;
|
|
|
|
rc = oc_mkdir(dir);
|
2015-07-01 15:53:47 +03:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
|
|
|
assert_non_null(_tgetcwd(wd_buffer, WD_BUFFER_SIZE));
|
|
|
|
|
2020-11-27 13:13:54 +03:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
rc = _tchdir(dir.toStdWString().data());
|
|
|
|
#else
|
|
|
|
rc = _tchdir(dir.toLocal8Bit().constData());
|
|
|
|
#endif
|
2015-07-01 15:53:47 +03:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
|
|
|
/* --- initialize csync */
|
2020-12-10 21:52:58 +03:00
|
|
|
auto mystate = new statevar;
|
2015-07-01 15:53:47 +03:00
|
|
|
*state = mystate;
|
2017-08-21 21:05:00 +03:00
|
|
|
return 0;
|
2015-07-01 15:53:47 +03:00
|
|
|
}
|
|
|
|
|
2015-07-03 12:46:45 +03:00
|
|
|
static void output( const char *text )
|
|
|
|
{
|
2020-11-27 13:13:54 +03:00
|
|
|
printf("%s\n", text);
|
2015-07-03 12:46:45 +03:00
|
|
|
}
|
|
|
|
|
2017-08-21 21:05:00 +03:00
|
|
|
static int teardown(void **state) {
|
2020-12-10 21:52:58 +03:00
|
|
|
int rc = -1;
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2015-07-03 12:46:45 +03:00
|
|
|
output("================== Tearing down!\n");
|
2015-07-01 15:53:47 +03:00
|
|
|
|
|
|
|
rc = _tchdir(wd_buffer);
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
|
|
|
rc = wipe_testdir();
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2020-07-16 15:21:38 +03:00
|
|
|
delete reinterpret_cast<statevar*>(*state);
|
2017-08-21 21:05:00 +03:00
|
|
|
return 0;
|
2015-07-01 15:53:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function takes a relative path, prepends it with the CSYNC_TEST_DIR
|
|
|
|
* and creates each sub directory.
|
|
|
|
*/
|
|
|
|
static void create_dirs( const char *path )
|
|
|
|
{
|
2020-12-10 21:52:58 +03:00
|
|
|
int rc = -1;
|
2020-07-27 11:44:51 +03:00
|
|
|
auto _mypath = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, QString::fromUtf8(path)).toUtf8();
|
2020-11-27 13:13:54 +03:00
|
|
|
char *mypath = _mypath.data();
|
|
|
|
|
|
|
|
char *p = mypath + CSYNC_TEST_DIR.size() + 1; /* start behind the offset */
|
2015-07-01 15:53:47 +03:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
assert_non_null(path);
|
|
|
|
|
|
|
|
while( *(p+i) ) {
|
|
|
|
if( *(p+i) == '/' ) {
|
|
|
|
p[i] = '\0';
|
|
|
|
|
2020-11-27 13:13:54 +03:00
|
|
|
auto mb_dir = QString::fromUtf8(mypath);
|
|
|
|
rc = oc_mkdir(mb_dir);
|
|
|
|
if(rc)
|
|
|
|
{
|
|
|
|
rc = errno;
|
|
|
|
}
|
2015-07-01 15:53:47 +03:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
p[i] = '/';
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function uses the vio_opendir, vio_readdir and vio_closedir functions
|
|
|
|
* to traverse a file tree that was created before by the create_dir function.
|
|
|
|
*
|
|
|
|
* It appends a listing to the result member of the incoming struct in *state
|
|
|
|
* that can be compared later to what was expected in the calling functions.
|
2015-07-27 14:28:21 +03:00
|
|
|
*
|
|
|
|
* The int parameter cnt contains the number of seen files (not dirs) in the
|
|
|
|
* whole tree.
|
2015-07-01 15:53:47 +03:00
|
|
|
*
|
|
|
|
*/
|
2020-11-27 13:13:54 +03:00
|
|
|
static void traverse_dir(void **state, const QString &dir, int *cnt)
|
2015-07-01 15:53:47 +03:00
|
|
|
{
|
2020-12-10 21:52:58 +03:00
|
|
|
csync_vio_handle_t *dh = nullptr;
|
2017-09-05 17:12:32 +03:00
|
|
|
std::unique_ptr<csync_file_stat_t> dirent;
|
2020-12-10 21:52:58 +03:00
|
|
|
auto sv = (statevar*) *state;
|
2020-07-16 15:21:38 +03:00
|
|
|
QByteArray subdir;
|
|
|
|
QByteArray subdir_out;
|
2020-12-10 21:52:58 +03:00
|
|
|
int rc = -1;
|
|
|
|
int is_dir = 0;
|
2020-11-27 13:13:54 +03:00
|
|
|
|
2018-07-25 17:00:16 +03:00
|
|
|
dh = csync_vio_local_opendir(dir);
|
2015-07-01 15:53:47 +03:00
|
|
|
assert_non_null(dh);
|
|
|
|
|
2018-11-07 14:36:29 +03:00
|
|
|
OCC::Vfs *vfs = nullptr;
|
|
|
|
while( (dirent = csync_vio_local_readdir(dh, vfs)) ) {
|
2017-09-05 17:12:32 +03:00
|
|
|
assert_non_null(dirent.get());
|
|
|
|
if (!dirent->original_path.isEmpty()) {
|
2020-07-16 15:21:38 +03:00
|
|
|
sv->ignored_dir = dirent->original_path;
|
2015-08-04 23:13:38 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2017-09-05 17:12:32 +03:00
|
|
|
assert_false(dirent->path.isEmpty());
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2020-07-16 15:21:38 +03:00
|
|
|
if( dirent->path == ".." || dirent->path == "." ) {
|
2015-07-01 15:53:47 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:08:53 +03:00
|
|
|
is_dir = (dirent->type == ItemTypeDirectory) ? 1:0;
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2020-07-16 15:21:38 +03:00
|
|
|
subdir = dir.toUtf8() + "/" + dirent->path;
|
|
|
|
subdir_out = (is_dir ? "<DIR> ":" ") + subdir;
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2015-07-27 14:28:21 +03:00
|
|
|
if( is_dir ) {
|
2020-07-16 15:21:38 +03:00
|
|
|
if( sv->result.isNull() ) {
|
|
|
|
sv->result = subdir_out;
|
2015-07-27 14:28:21 +03:00
|
|
|
} else {
|
2020-07-16 15:21:38 +03:00
|
|
|
sv->result += subdir_out;
|
2015-07-27 14:28:21 +03:00
|
|
|
}
|
2015-07-01 15:53:47 +03:00
|
|
|
} else {
|
2015-07-27 14:28:21 +03:00
|
|
|
*cnt = *cnt +1;
|
2015-07-01 15:53:47 +03:00
|
|
|
}
|
2020-07-27 11:44:51 +03:00
|
|
|
output(subdir_out.constData());
|
2015-07-03 12:46:45 +03:00
|
|
|
if( is_dir ) {
|
2020-07-27 11:44:51 +03:00
|
|
|
traverse_dir(state, QString::fromUtf8(subdir), cnt);
|
2015-07-03 12:46:45 +03:00
|
|
|
}
|
2015-07-01 15:53:47 +03:00
|
|
|
}
|
|
|
|
|
2018-07-25 17:00:16 +03:00
|
|
|
rc = csync_vio_local_closedir(dh);
|
2015-07-01 15:53:47 +03:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-03 12:46:45 +03:00
|
|
|
static void create_file( const char *path, const char *name, const char *content)
|
|
|
|
{
|
2020-07-27 11:44:51 +03:00
|
|
|
QFile file(QStringLiteral("%1/%2%3").arg(CSYNC_TEST_DIR, QString::fromUtf8(path), QString::fromUtf8(name)));
|
|
|
|
assert_int_equal(1, file.open(QIODevice::WriteOnly | QIODevice::NewOnly));
|
|
|
|
file.write(content);
|
2015-07-03 12:46:45 +03:00
|
|
|
}
|
|
|
|
|
2015-07-01 15:53:47 +03:00
|
|
|
static void check_readdir_shorttree(void **state)
|
|
|
|
{
|
2020-12-10 21:52:58 +03:00
|
|
|
auto sv = (statevar*) *state;
|
2015-07-01 15:53:47 +03:00
|
|
|
|
|
|
|
const char *t1 = "alibaba/und/die/vierzig/räuber/";
|
|
|
|
create_dirs( t1 );
|
2015-07-27 14:28:21 +03:00
|
|
|
int files_cnt = 0;
|
|
|
|
|
|
|
|
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
|
2015-07-01 15:53:47 +03:00
|
|
|
|
2020-07-27 11:44:51 +03:00
|
|
|
assert_string_equal(sv->result.constData(),
|
|
|
|
QString::fromUtf8("<DIR> %1/alibaba"
|
|
|
|
"<DIR> %1/alibaba/und"
|
|
|
|
"<DIR> %1/alibaba/und/die"
|
|
|
|
"<DIR> %1/alibaba/und/die/vierzig"
|
|
|
|
"<DIR> %1/alibaba/und/die/vierzig/räuber")
|
|
|
|
.arg(CSYNC_TEST_DIR)
|
|
|
|
.toUtf8()
|
|
|
|
.constData());
|
2015-07-27 14:28:21 +03:00
|
|
|
assert_int_equal(files_cnt, 0);
|
2015-07-01 15:53:47 +03:00
|
|
|
}
|
|
|
|
|
2015-07-03 12:46:45 +03:00
|
|
|
static void check_readdir_with_content(void **state)
|
|
|
|
{
|
2020-12-10 21:52:58 +03:00
|
|
|
auto sv = (statevar*) *state;
|
2015-07-27 14:28:21 +03:00
|
|
|
int files_cnt = 0;
|
2015-07-03 12:46:45 +03:00
|
|
|
|
|
|
|
const char *t1 = "warum/nur/40/Räuber/";
|
|
|
|
create_dirs( t1 );
|
|
|
|
|
|
|
|
create_file( t1, "Räuber Max.txt", "Der Max ist ein schlimmer finger");
|
|
|
|
create_file( t1, "пя́тница.txt", "Am Freitag tanzt der Ürk");
|
|
|
|
|
|
|
|
|
2015-07-27 14:28:21 +03:00
|
|
|
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
|
2015-07-03 12:46:45 +03:00
|
|
|
|
2020-07-27 11:44:51 +03:00
|
|
|
assert_string_equal(sv->result.constData(),
|
|
|
|
QString::fromUtf8("<DIR> %1/warum"
|
|
|
|
"<DIR> %1/warum/nur"
|
|
|
|
"<DIR> %1/warum/nur/40"
|
|
|
|
"<DIR> %1/warum/nur/40/Räuber")
|
|
|
|
.arg(CSYNC_TEST_DIR)
|
|
|
|
.toUtf8()
|
|
|
|
.constData());
|
2020-11-27 13:13:54 +03:00
|
|
|
/* " %1/warum/nur/40/Räuber/Räuber Max.txt"
|
|
|
|
" %1/warum/nur/40/Räuber/пя́тница.txt"; */
|
2015-07-27 14:28:21 +03:00
|
|
|
assert_int_equal(files_cnt, 2); /* Two files in the sub dir */
|
2015-07-03 12:46:45 +03:00
|
|
|
}
|
|
|
|
|
2015-07-01 15:53:47 +03:00
|
|
|
static void check_readdir_longtree(void **state)
|
|
|
|
{
|
2020-12-10 21:52:58 +03:00
|
|
|
auto sv = (statevar*) *state;
|
2015-07-01 15:53:47 +03:00
|
|
|
|
|
|
|
/* Strange things here: Compilers only support strings with length of 4k max.
|
|
|
|
* The expected result string is longer, so it needs to be split up in r1, r2 and r3
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* create the test tree */
|
|
|
|
const char *t1 = "vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM/";
|
|
|
|
create_dirs( t1 );
|
|
|
|
|
2020-11-27 13:13:54 +03:00
|
|
|
const auto r1 = QString::fromUtf8(
|
|
|
|
"<DIR> %1/vierzig"
|
|
|
|
"<DIR> %1/vierzig/mann"
|
|
|
|
"<DIR> %1/vierzig/mann/auf"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum").arg(CSYNC_TEST_DIR);
|
|
|
|
|
|
|
|
|
|
|
|
const auto r2 = QString::fromUtf8(
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH").arg(CSYNC_TEST_DIR);
|
|
|
|
|
|
|
|
|
|
|
|
const auto r3 = QString::fromUtf8(
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln"
|
|
|
|
"<DIR> %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM").arg(CSYNC_TEST_DIR);
|
2015-07-01 15:53:47 +03:00
|
|
|
|
|
|
|
/* assemble the result string ... */
|
2020-11-27 13:13:54 +03:00
|
|
|
const auto result = (r1 + r2 + r3).toUtf8();
|
2015-07-27 14:28:21 +03:00
|
|
|
int files_cnt = 0;
|
|
|
|
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
|
|
|
|
assert_int_equal(files_cnt, 0);
|
2015-07-01 15:53:47 +03:00
|
|
|
/* and compare. */
|
2020-07-27 11:44:51 +03:00
|
|
|
assert_string_equal(sv->result.constData(), result.constData());
|
2015-07-01 15:53:47 +03:00
|
|
|
}
|
|
|
|
|
2015-08-04 23:13:38 +03:00
|
|
|
// https://github.com/owncloud/client/issues/3128 https://github.com/owncloud/client/issues/2777
|
|
|
|
static void check_readdir_bigunicode(void **state)
|
|
|
|
{
|
2020-12-10 21:52:58 +03:00
|
|
|
auto sv = (statevar*) *state;
|
2015-08-04 23:13:38 +03:00
|
|
|
// 1: ? ASCII: 239 - EF
|
|
|
|
// 2: ? ASCII: 187 - BB
|
|
|
|
// 3: ? ASCII: 191 - BF
|
|
|
|
// 4: ASCII: 32 - 20
|
|
|
|
|
2020-07-27 11:44:51 +03:00
|
|
|
QString p = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, QStringLiteral("goodone/"));
|
2020-11-27 13:13:54 +03:00
|
|
|
int rc = oc_mkdir(p);
|
2015-08-04 23:13:38 +03:00
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
2020-07-27 11:44:51 +03:00
|
|
|
p = QStringLiteral("%1/goodone/ugly\xEF\xBB\xBF\x32.txt").arg(CSYNC_TEST_DIR); // file with encoding error
|
2020-11-27 13:13:54 +03:00
|
|
|
|
|
|
|
rc = oc_mkdir(p);
|
2015-08-04 23:13:38 +03:00
|
|
|
|
|
|
|
assert_int_equal(rc, 0);
|
|
|
|
|
|
|
|
int files_cnt = 0;
|
|
|
|
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
|
2020-07-27 11:44:51 +03:00
|
|
|
const auto expected_result = QStringLiteral("<DIR> %1/goodone"
|
|
|
|
"<DIR> %1/goodone/ugly\xEF\xBB\xBF\x32.txt")
|
|
|
|
.arg(CSYNC_TEST_DIR);
|
|
|
|
assert_string_equal(sv->result.constData(), expected_result.toUtf8().constData());
|
2015-08-05 12:09:27 +03:00
|
|
|
|
2015-08-04 23:13:38 +03:00
|
|
|
assert_int_equal(files_cnt, 0);
|
|
|
|
}
|
|
|
|
|
2015-07-01 15:53:47 +03:00
|
|
|
int torture_run_tests(void)
|
|
|
|
{
|
2017-08-21 21:05:00 +03:00
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(check_readdir_shorttree, setup_testenv, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_readdir_with_content, setup_testenv, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_readdir_longtree, setup_testenv, teardown),
|
|
|
|
cmocka_unit_test_setup_teardown(check_readdir_bigunicode, setup_testenv, teardown),
|
2015-07-01 15:53:47 +03:00
|
|
|
};
|
|
|
|
|
2020-12-10 21:52:58 +03:00
|
|
|
return cmocka_run_group_tests(tests, nullptr, nullptr);
|
2015-07-01 15:53:47 +03:00
|
|
|
}
|