diff --git a/src/csync/CMakeLists.txt b/src/csync/CMakeLists.txt index 2d50c2988..7f0740a72 100644 --- a/src/csync/CMakeLists.txt +++ b/src/csync/CMakeLists.txt @@ -36,8 +36,7 @@ set(csync_SRCS std/c_alloc.c std/c_string.c - std/c_time.c - std/c_utf8.cpp + std/c_time.cpp ) diff --git a/src/csync/csync_exclude.cpp b/src/csync/csync_exclude.cpp index 902dffc76..2b9c549c2 100644 --- a/src/csync/csync_exclude.cpp +++ b/src/csync/csync_exclude.cpp @@ -26,7 +26,6 @@ #include "c_lib.h" #include "c_private.h" -#include "c_utf8.h" #include "csync_exclude.h" diff --git a/src/csync/std/c_lib.h b/src/csync/std/c_lib.h index e277f4e95..f6092a953 100644 --- a/src/csync/std/c_lib.h +++ b/src/csync/std/c_lib.h @@ -24,5 +24,4 @@ #include "c_macro.h" #include "c_alloc.h" #include "c_string.h" -#include "c_time.h" #include "c_private.h" diff --git a/src/csync/std/c_time.c b/src/csync/std/c_time.cpp similarity index 85% rename from src/csync/std/c_time.c rename to src/csync/std/c_time.cpp index 28528fdc6..616255313 100644 --- a/src/csync/std/c_time.c +++ b/src/csync/std/c_time.cpp @@ -23,13 +23,12 @@ #include "c_string.h" #include "c_time.h" -#include "c_utf8.h" + +#include #ifdef HAVE_UTIMES -int c_utimes(const char *uri, const struct timeval *times) { - mbchar_t *wuri = c_utf8_path_to_locale(uri); - int ret = utimes(wuri, times); - c_free_locale_string(wuri); +int c_utimes(const QString &uri, const struct timeval *times) { + int ret = utimes(QFile::encodeName(uri).constData(), times); return ret; } #else // HAVE_UTIMES @@ -50,12 +49,12 @@ static void UnixTimevalToFileTime(struct timeval t, LPFILETIME pft) pft->dwHighDateTime = ll >> 32; } -int c_utimes(const char *uri, const struct timeval *times) { +int c_utimes(const QString &uri, const struct timeval *times) { FILETIME LastAccessTime; FILETIME LastModificationTime; HANDLE hFile; - mbchar_t *wuri = c_utf8_path_to_locale( uri ); + auto wuri = uri.toStdWString(); if(times) { UnixTimevalToFileTime(times[0], &LastAccessTime); @@ -66,7 +65,7 @@ int c_utimes(const char *uri, const struct timeval *times) { GetSystemTimeAsFileTime(&LastModificationTime); } - hFile=CreateFileW(wuri, FILE_WRITE_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, + hFile=CreateFileW(wuri.data(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL+FILE_FLAG_BACKUP_SEMANTICS, NULL); if(hFile==INVALID_HANDLE_VALUE) { switch(GetLastError()) { @@ -94,12 +93,10 @@ int c_utimes(const char *uri, const struct timeval *times) { //can this happen? errno=ENOENT; CloseHandle(hFile); - c_free_locale_string(wuri); return -1; } CloseHandle(hFile); - c_free_locale_string(wuri); return 0; } diff --git a/src/csync/std/c_time.h b/src/csync/std/c_time.h index 3792198f8..55a6aa6bc 100644 --- a/src/csync/std/c_time.h +++ b/src/csync/std/c_time.h @@ -21,11 +21,9 @@ #ifndef _C_TIME_H #define _C_TIME_H -#include "ocsynclib.h" +#include -#ifdef __cplusplus -extern "C" { -#endif +#include "ocsynclib.h" #ifdef _WIN32 #include @@ -33,10 +31,7 @@ extern "C" { #include #endif -OCSYNC_EXPORT int c_utimes(const char *uri, const struct timeval *times); +OCSYNC_EXPORT int c_utimes(const QString &uri, const struct timeval *times); -#ifdef __cplusplus -} -#endif #endif /* _C_TIME_H */ diff --git a/src/csync/std/c_utf8.cpp b/src/csync/std/c_utf8.cpp deleted file mode 100644 index 93e678304..000000000 --- a/src/csync/std/c_utf8.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider - * Copyright (c) 2012-2013 by Klaas Freitag - * - * 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 "config_csync.h" -#include "c_utf8.h" - -#ifdef _WIN32 -#include -#include -#include -#include -#include -#include -#include -#else -#include -#include -#endif - -#include "c_alloc.h" -#include "c_string.h" -#include "common/filesystembase.h" -#include "common/utility.h" - -/* Convert a locale String to UTF8 */ -QByteArray c_utf8_from_locale(const mbchar_t *wstr) -{ - if (!wstr) { - return QByteArray(); - } - -#ifdef _WIN32 - QByteArray dst; - int size_needed; - size_t len; - len = wcslen(wstr); - /* Call once to get the required size. */ - size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, OCC::Utility::convertSizeToInt(len), nullptr, 0, nullptr, nullptr); - if (size_needed > 0) { - dst.resize(size_needed); - WideCharToMultiByte(CP_UTF8, 0, wstr, OCC::Utility::convertSizeToInt(len), dst.data(), size_needed, nullptr, nullptr); - } - return dst; -#else - auto codec = QTextCodec::codecForLocale(); -#ifndef __APPLE__ - if (codec->mibEnum() == 106) { // UTF-8 - // Optimisation for UTF-8: no need to convert to QString. - // We still need to do it for mac because of normalization - return QByteArray(wstr); - } -#endif - QTextDecoder dec(codec); - QString s = dec.toUnicode(wstr, qstrlen(wstr)); - if (s.isEmpty() || dec.hasFailure()) { - /* Conversion error: since we can't report error from this function, just return the original - string. We take care of invalid utf-8 in SyncEngine::treewalkFile */ - return QByteArray(wstr); - } -#ifdef __APPLE__ - s = s.normalized(QString::NormalizationForm_C); -#endif - return std::move(s).toUtf8(); -#endif -} - -extern "C" { - -/* Convert a an UTF8 string to locale */ -mbchar_t* c_utf8_string_to_locale(const char *str) -{ - if (!str) { - return nullptr; - } -#ifdef _WIN32 - mbchar_t *dst = nullptr; - size_t len; - int size_needed; - - len = strlen(str); - size_needed = MultiByteToWideChar(CP_UTF8, 0, str, OCC::Utility::convertSizeToInt(len), nullptr, 0); - if (size_needed > 0) { - int size_char = (size_needed + 1) * sizeof(mbchar_t); - dst = (mbchar_t*)c_malloc(size_char); - memset((void*)dst, 0, size_char); - MultiByteToWideChar(CP_UTF8, 0, str, -1, dst, size_needed); - } - return dst; -#else - return c_strdup(QFile::encodeName(QString::fromUtf8(str))); -#endif -} - - mbchar_t* c_utf8_path_to_locale(const char *str) - { - if(!str) { - return nullptr; - } else { - #ifdef _WIN32 - size_t strLength = strlen(str); - QByteArray unc_str = OCC::FileSystem::pathtoUNC(QByteArray::fromRawData(str, OCC::Utility::convertSizeToInt(strLength))); - mbchar_t *dst = c_utf8_string_to_locale(unc_str); - return dst; - #else - return c_utf8_string_to_locale(str); - #endif - } - } - -} diff --git a/src/csync/std/c_utf8.h b/src/csync/std/c_utf8.h deleted file mode 100644 index 2bbe1d4bd..000000000 --- a/src/csync/std/c_utf8.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider - * Copyright (c) 2012-2013 by Klaas Freitag - * - * 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 - */ - -/** - * @file c_string.h - * - * @brief Interface of the cynapses string implementations - * - * @defgroup cynStringInternals cynapses libc string functions - * @ingroup cynLibraryAPI - * - * @{ - */ -#ifndef _C_UTF8_H -#define _C_UTF8_H - -#include "c_private.h" -#include "c_macro.h" - -#ifdef __cplusplus -#include - -/** - * @brief Convert a platform locale string to utf8. - * - * This function is part of the multi platform abstraction of basic file - * operations to handle various platform encoding correctly. - * - * Instead of using the standard file operations the multi platform aliases - * defined in c_private.h have to be used instead. - * - * To convert path names returned by these functions to the internally used - * utf8 format this function has to be used. - * - * @param str The multibyte encoded string to convert - * - * @return The converted string or a null QByteArray on error. - * - * @see c_free_locale_string() - * @see c_utf8_to_locale() - * - */ - QByteArray c_utf8_from_locale(const mbchar_t *str); - -extern "C" { - -#endif // __cplusplus - -/** - * @brief Convert a utf8 encoded string to platform specific locale. - * - * This function is part of the multi platform abstraction of basic file - * operations to handle various platform encoding correctly. - * - * Instead of using the standard file operations the multi platform aliases - * defined in c_private.h have to be used instead. - * - * To convert strings as input for the cross platform functions from the - * internally used utf8 format, this function has to be used. - * The returned string has to be freed by c_free_locale_string(). On some - * platforms this method allocates memory and on others not but it has never - * sto be cared about. - * - * If the string to convert is a path, consider using c_utf8_path_to_locale(). - * - * @param str The utf8 string to convert. - * - * @return The malloced converted multibyte string or \c nullptr on error. - * - * @see c_free_locale_string() - * @see c_utf8_from_locale() - * - */ -mbchar_t* c_utf8_string_to_locale(const char *wstr); - -/** - * @brief c_utf8_path_to_locale converts a unixoid path to the locale aware format - * - * On windows, it converts to UNC and multibyte. - * On Mac, it converts to the correct utf8 using iconv. - * On Linux, it returns utf8 - * - * @param str The path to convert - * - * @return a pointer to the converted string. Caller has to free it using the - * function c_free_locale_string. - */ -mbchar_t* c_utf8_path_to_locale(const char *str); - -/** - * @brief Free buffer malloced by c_utf8_to_locale(). - * - * This function is part of the multi platform abstraction of basic file - * operations to handle various platform encoding correctly. - * - * Instead of using the standard file operations the multi platform aliases - * defined in c_private.h have to be used instead. - * - * This function frees the memory that was allocated by a previous call to - * c_utf8_to_locale(). - * - * @param buf The buffer to free. - * - * @see c_utf8_from_locale(), c_utf8_to_locale() - * - */ -#define c_free_locale_string(x) SAFE_FREE(x) - - -/** - * }@ - */ - -#ifdef __cplusplus -} -#endif - -#endif /* _C_UTF8_H */ diff --git a/src/csync/vio/csync_vio_local.h b/src/csync/vio/csync_vio_local.h index 769d1d020..04bd057ea 100644 --- a/src/csync/vio/csync_vio_local.h +++ b/src/csync/vio/csync_vio_local.h @@ -21,6 +21,8 @@ #ifndef _CSYNC_VIO_LOCAL_H #define _CSYNC_VIO_LOCAL_H +#include + struct csync_vio_handle_t; namespace OCC { class Vfs; @@ -30,6 +32,6 @@ csync_vio_handle_t OCSYNC_EXPORT *csync_vio_local_opendir(const QString &name); int OCSYNC_EXPORT csync_vio_local_closedir(csync_vio_handle_t *dhandle); std::unique_ptr OCSYNC_EXPORT csync_vio_local_readdir(csync_vio_handle_t *dhandle, OCC::Vfs *vfs); -int OCSYNC_EXPORT csync_vio_local_stat(const char *uri, csync_file_stat_t *buf); +int OCSYNC_EXPORT csync_vio_local_stat(const QString &uri, csync_file_stat_t *buf); #endif /* _CSYNC_VIO_LOCAL_H */ diff --git a/src/csync/vio/csync_vio_local_unix.cpp b/src/csync/vio/csync_vio_local_unix.cpp index 5b58b01cb..fae033b9d 100644 --- a/src/csync/vio/csync_vio_local_unix.cpp +++ b/src/csync/vio/csync_vio_local_unix.cpp @@ -31,7 +31,6 @@ #include "c_private.h" #include "c_lib.h" #include "c_string.h" -#include "c_utf8.h" #include "csync_util.h" #include "vio/csync_vio_local.h" @@ -86,7 +85,7 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h } while (qstrcmp(dirent->d_name, ".") == 0 || qstrcmp(dirent->d_name, "..") == 0); file_stat = std::make_unique(); - file_stat->path = c_utf8_from_locale(dirent->d_name); + file_stat->path = QFile::decodeName(dirent->d_name).toUtf8(); QByteArray fullPath = handle->path % '/' % QByteArray() % const_cast(dirent->d_name); if (file_stat->path.isNull()) { file_stat->original_path = fullPath; @@ -133,13 +132,9 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h } -int csync_vio_local_stat(const char *uri, csync_file_stat_t *buf) +int csync_vio_local_stat(const QString &uri, csync_file_stat_t *buf) { - mbchar_t *wuri = c_utf8_path_to_locale(uri); - *buf = csync_file_stat_t(); - int rc = _csync_vio_local_stat_mb(wuri, buf); - c_free_locale_string(wuri); - return rc; + return _csync_vio_local_stat_mb(QFile::encodeName(uri).constData(), buf); } static int _csync_vio_local_stat_mb(const mbchar_t *wuri, csync_file_stat_t *buf) diff --git a/src/csync/vio/csync_vio_local_win.cpp b/src/csync/vio/csync_vio_local_win.cpp index 8f0114767..354aea0f3 100644 --- a/src/csync/vio/csync_vio_local_win.cpp +++ b/src/csync/vio/csync_vio_local_win.cpp @@ -31,7 +31,6 @@ #include "c_private.h" #include "c_lib.h" -#include "c_utf8.h" #include "csync_util.h" #include "vio/csync_vio_local.h" #include "common/filesystembase.h" @@ -137,12 +136,12 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h return nullptr; } } - auto path = c_utf8_from_locale(handle->ffd.cFileName); + auto path = QString::fromWCharArray(handle->ffd.cFileName); if (path == "." || path == "..") return csync_vio_local_readdir(handle, vfs); file_stat = std::make_unique(); - file_stat->path = path; + file_stat->path = path.toUtf8(); if (vfs && vfs->statTypeVirtualFile(file_stat.get(), &handle->ffd)) { // all good @@ -177,7 +176,7 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h std::wstring fullPath; fullPath.reserve(handle->path.size() + std::wcslen(handle->ffd.cFileName)); - fullPath += reinterpret_cast(handle->path.utf16()); // path always ends with '\', by construction + fullPath += handle->path.toStdWString(); // path always ends with '\', by construction fullPath += handle->ffd.cFileName; if (_csync_vio_local_stat_mb(fullPath.data(), file_stat.get()) < 0) { @@ -189,11 +188,10 @@ std::unique_ptr csync_vio_local_readdir(csync_vio_handle_t *h } -int csync_vio_local_stat(const char *uri, csync_file_stat_t *buf) +int csync_vio_local_stat(const QString &uri, csync_file_stat_t *buf) { - mbchar_t *wuri = c_utf8_path_to_locale(uri); - int rc = _csync_vio_local_stat_mb(wuri, buf); - c_free_locale_string(wuri); + const std::wstring wuri = uri.toStdWString(); + int rc = _csync_vio_local_stat_mb(wuri.data(), buf); return rc; } diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 8bedc656a..8c2ebc155 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -558,7 +558,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo( if (!base.isDirectory()) { csync_file_stat_t buf; - if (csync_vio_local_stat((_discoveryData->_localDir + originalPathAdjusted).toUtf8(), &buf)) { + if (csync_vio_local_stat(_discoveryData->_localDir + originalPathAdjusted, &buf)) { qCInfo(lcDisco) << "Local file does not exist anymore." << originalPathAdjusted; return; } diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index fcf0cc0d7..eb6b498f0 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -21,13 +21,10 @@ #include #include -// We use some internals of csync: -extern "C" int c_utimes(const char *, const struct timeval *); - #include "csync.h" #include "vio/csync_vio_local.h" #include "std/c_string.h" -#include "std/c_utf8.h" +#include "std/c_time.h" namespace OCC { @@ -68,7 +65,7 @@ time_t FileSystem::getModTime(const QString &filename) { csync_file_stat_t stat; qint64 result = -1; - if (csync_vio_local_stat(filename.toUtf8().data(), &stat) != -1 + if (csync_vio_local_stat(filename, &stat) != -1 && (stat.modtime != 0)) { result = stat.modtime; } else { @@ -84,7 +81,7 @@ bool FileSystem::setModTime(const QString &filename, time_t modTime) struct timeval times[2]; times[0].tv_sec = times[1].tv_sec = modTime; times[0].tv_usec = times[1].tv_usec = 0; - int rc = c_utimes(filename.toUtf8().data(), times); + int rc = c_utimes(filename, times); if (rc != 0) { qCWarning(lcFileSystem) << "Error setting mtime for" << filename << "failed: rc" << rc << ", errno:" << errno; @@ -121,7 +118,7 @@ static qint64 getSizeWithCsync(const QString &filename) { qint64 result = 0; csync_file_stat_t stat; - if (csync_vio_local_stat(filename.toUtf8().data(), &stat) != -1) { + if (csync_vio_local_stat(filename, &stat) != -1) { result = stat.size; } else { qCWarning(lcFileSystem) << "Could not get size for" << filename << "with csync"; @@ -192,7 +189,7 @@ bool FileSystem::removeRecursively(const QString &path, const std::function #include "c_string.h" -#include "c_utf8.h" #include "common/filesystembase.h" #include "torture.h" @@ -29,87 +28,6 @@ #include "torture.h" -static void check_iconv_to_native_normalization(void **state) -{ - mbchar_t *out = nullptr; - const char *in= "\x48\xc3\xa4"; // UTF8 -#ifdef __APPLE__ - const char *exp_out = "\x48\x61\xcc\x88"; // UTF-8-MAC -#else - const char *exp_out = "\x48\xc3\xa4"; // UTF8 -#endif - - out = c_utf8_path_to_locale(in); - assert_string_equal(out, exp_out); - - c_free_locale_string(out); - assert_null(out); - - (void) state; /* unused */ -} - -static void check_iconv_from_native_normalization(void **state) -{ -#ifdef _WIN32 - const mbchar_t *in = L"\x48\xc3\xa4"; // UTF-8 -#else -#ifdef __APPLE__ - const mbchar_t *in = "\x48\x61\xcc\x88"; // UTF-8-MAC -#else - const mbchar_t *in = "\x48\xc3\xa4"; // UTF-8 -#endif -#endif - const char *exp_out = "\x48\xc3\xa4"; // UTF-8 - - QByteArray out = c_utf8_from_locale(in); - assert_string_equal(out, exp_out); - - (void) state; /* unused */ -} - -static void check_iconv_ascii(void **state) -{ -#ifdef _WIN32 - const mbchar_t *in = L"abc/ABC\\123"; // UTF-8 -#else -#ifdef __APPLE__ - const mbchar_t *in = "abc/ABC\\123"; // UTF-8-MAC -#else - const mbchar_t *in = "abc/ABC\\123"; // UTF-8 -#endif -#endif - const char *exp_out = "abc/ABC\\123"; - - QByteArray out = c_utf8_from_locale(in); - assert_string_equal(out, exp_out); - - (void) state; /* unused */ -} - -#define TESTSTRING "#cA\\#fߧ4" -#define LTESTSTRING L"#cA\\#fߧ4" - -static void check_to_multibyte(void **state) -{ - int rc = -1; - - mbchar_t *mb_string = c_utf8_path_to_locale(TESTSTRING); - mbchar_t *mb_null = c_utf8_path_to_locale(nullptr); - - (void) state; - -#ifdef _WIN32 - assert_int_equal(wcscmp(LTESTSTRING, mb_string), 0); -#else - assert_string_equal(mb_string, TESTSTRING); -#endif - assert_false(mb_null); - assert_int_equal(rc, -1); - - c_free_locale_string(mb_string); - c_free_locale_string(mb_null); -} - static void check_long_win_path(void **state) { (void) state; /* unused */ @@ -171,10 +89,6 @@ int torture_run_tests(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(check_long_win_path), - cmocka_unit_test(check_to_multibyte), - cmocka_unit_test(check_iconv_ascii), - cmocka_unit_test(check_iconv_to_native_normalization), - cmocka_unit_test(check_iconv_from_native_normalization), }; diff --git a/test/csync/vio_tests/check_vio_ext.cpp b/test/csync/vio_tests/check_vio_ext.cpp index 1f541adc0..32b173e7f 100644 --- a/test/csync/vio_tests/check_vio_ext.cpp +++ b/test/csync/vio_tests/check_vio_ext.cpp @@ -25,78 +25,65 @@ #include #include "csync.h" -#include "std/c_utf8.h" #include "std/c_alloc.h" #include "std/c_string.h" #include "vio/csync_vio_local.h" -#ifdef _WIN32 -#include +#include -#define CSYNC_TEST_DIR "C:/tmp/csync_test" -#else -#define CSYNC_TEST_DIR "/tmp/csync_test" -#endif -#define MKDIR_MASK (S_IRWXU |S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) +static const auto CSYNC_TEST_DIR = []{ return QStringLiteral("%1/csync_test").arg(QDir::tempPath());}(); #include "torture.h" +namespace { +int oc_mkdir(const QString &path) +{ + return QDir(path).mkpath(path) ? 0 : -1; +} + +} #define WD_BUFFER_SIZE 255 static mbchar_t wd_buffer[WD_BUFFER_SIZE]; -struct statevar { +typedef struct { char *result; char *ignored_dir; -}; +} statevar; /* remove the complete test dir */ static int wipe_testdir() { - int rc = 0; - -#ifdef _WIN32 - /* The windows system call to rd bails out if the dir is not existing - * Check first. - */ - WIN32_FIND_DATA FindFileData; - - mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR); - HANDLE handle = FindFirstFile(dir, &FindFileData); - c_free_locale_string(dir); - int found = handle != INVALID_HANDLE_VALUE; - - if(found) { - FindClose(handle); - rc = system("rd /s /q C:\\tmp\\csync_test"); - } -#else - rc = system("rm -rf /tmp/csync_test/"); -#endif - return rc; + QDir tmp(CSYNC_TEST_DIR); + if (tmp.exists()) + { + return tmp.removeRecursively() ? 0 : 1; + } + return 0; } static int setup_testenv(void **state) { - int rc = 0; + int rc; rc = wipe_testdir(); assert_int_equal(rc, 0); - mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR); - - rc = _tmkdir(dir, MKDIR_MASK); + auto dir = CSYNC_TEST_DIR; + rc = oc_mkdir(dir); assert_int_equal(rc, 0); assert_non_null(_tgetcwd(wd_buffer, WD_BUFFER_SIZE)); - rc = _tchdir(dir); +#ifdef Q_OS_WIN + rc = _tchdir(dir.toStdWString().data()); +#else + rc = _tchdir(dir.toLocal8Bit().constData()); +#endif assert_int_equal(rc, 0); - c_free_locale_string(dir); - /* --- initialize csync */ - auto *mystate = (statevar*)malloc( sizeof(statevar) ); - mystate->result = nullptr; + statevar *mystate = (statevar*)malloc( sizeof(statevar) ); + mystate->result = NULL; *state = mystate; return 0; @@ -104,18 +91,11 @@ static int setup_testenv(void **state) { static void output( const char *text ) { - mbchar_t *wtext = c_utf8_string_to_locale(text); - - #ifdef _WIN32 - wprintf(L"OOOO %ls (%ld)\n", wtext, strlen(text)); - #else - printf("%s\n", wtext); - #endif - c_free_locale_string(wtext); + printf("%s\n", text); } static int teardown(void **state) { - int rc = 0; + int rc; output("================== Tearing down!\n"); @@ -135,14 +115,11 @@ static int teardown(void **state) { */ static void create_dirs( const char *path ) { - int rc = 0; - char *mypath = (char*)c_malloc( 2+strlen(CSYNC_TEST_DIR)+strlen(path)); - *mypath = '\0'; - strcat(mypath, CSYNC_TEST_DIR); - strcat(mypath, "/"); - strcat(mypath, path); + int rc; + auto _mypath = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, path).toUtf8(); + char *mypath = _mypath.data(); - char *p = mypath+strlen(CSYNC_TEST_DIR)+1; /* start behind the offset */ + char *p = mypath + CSYNC_TEST_DIR.size() + 1; /* start behind the offset */ int i = 0; assert_non_null(path); @@ -151,17 +128,17 @@ static void create_dirs( const char *path ) if( *(p+i) == '/' ) { p[i] = '\0'; - mbchar_t *mb_dir = c_utf8_path_to_locale(mypath); - /* wprintf(L"OOOO %ls (%ld)\n", mb_dir, strlen(mypath)); */ - rc = _tmkdir(mb_dir, MKDIR_MASK); - c_free_locale_string(mb_dir); - + auto mb_dir = QString::fromUtf8(mypath); + rc = oc_mkdir(mb_dir); + if(rc) + { + rc = errno; + } assert_int_equal(rc, 0); p[i] = '/'; } i++; } - SAFE_FREE(mypath); } /* @@ -175,23 +152,17 @@ static void create_dirs( const char *path ) * whole tree. * */ -static void traverse_dir(void **state, const char *dir, int *cnt) +static void traverse_dir(void **state, const QString &dir, int *cnt) { - csync_vio_handle_t *dh = nullptr; + csync_vio_handle_t *dh; std::unique_ptr dirent; - auto *sv = (statevar*) *state; - char *subdir = nullptr; - char *subdir_out = nullptr; - int rc = 0; - int is_dir = 0; + statevar *sv = (statevar*) *state; + char *subdir; + char *subdir_out; + int rc; + int is_dir; - /* Format: Smuggle in the C: for unix platforms as its urgently needed - * on Windows and the test can be nicely cross platform this way. */ -#ifdef _WIN32 const char *format_str = "%s %s"; -#else - const char *format_str = "%s C:%s"; -#endif dh = csync_vio_local_opendir(dir); assert_non_null(dh); @@ -212,7 +183,7 @@ static void traverse_dir(void **state, const char *dir, int *cnt) is_dir = (dirent->type == ItemTypeDirectory) ? 1:0; - assert_int_not_equal( asprintf( &subdir, "%s/%s", dir, dirent->path.constData() ), -1 ); + assert_int_not_equal( asprintf( &subdir, "%s/%s", dir.toUtf8().constData(), dirent->path.constData() ), -1 ); assert_int_not_equal( asprintf( &subdir_out, format_str, is_dir ? "":" ", @@ -222,7 +193,7 @@ static void traverse_dir(void **state, const char *dir, int *cnt) if( !sv->result ) { sv->result = c_strdup( subdir_out); } else { - const auto newlen = 1 + strlen(sv->result)+strlen(subdir_out); + int newlen = 1+strlen(sv->result)+strlen(subdir_out); char *tmp = sv->result; sv->result = (char*)c_malloc(newlen); strcpy( sv->result, tmp); @@ -249,54 +220,14 @@ static void traverse_dir(void **state, const char *dir, int *cnt) static void create_file( const char *path, const char *name, const char *content) { -#ifdef _WIN32 - - char *filepath = c_malloc( 2+strlen(CSYNC_TEST_DIR)+strlen(path) + strlen(name) ); - *filepath = '\0'; - strcpy(filepath, CSYNC_TEST_DIR); - strcat(filepath, "/"); - strcat(filepath, path); - strcat(filepath, name); - - DWORD dwWritten; // number of bytes written to file - HANDLE hFile; - - mbchar_t *w_fname = c_utf8_path_to_locale(filepath); - - hFile=CreateFile(w_fname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); - - assert_int_equal( 0, hFile==INVALID_HANDLE_VALUE ); - - int len = strlen(content); - mbchar_t *dst = nullptr; - - dst = c_utf8_string_to_locale(content); - WriteFile(hFile, dst, len * sizeof(mbchar_t), &dwWritten, 0); - - CloseHandle(hFile); - SAFE_FREE(dst); - c_free_locale_string(w_fname); -#else - char *filepath = (char*)c_malloc( 1+strlen(path) + strlen(name) ); - *filepath = '\0'; - - strcpy(filepath, path); - strcat(filepath, name); - - FILE *sink = nullptr; - sink = fopen(filepath,"w"); - - fprintf (sink, "we got: %s",content); - fclose(sink); - SAFE_FREE(filepath); -#endif - + QFile file(QStringLiteral("%1/%2%3").arg(CSYNC_TEST_DIR, path, name)); + assert_int_equal(1, file.open(QIODevice::WriteOnly | QIODevice::NewOnly)); + file.write(content); } static void check_readdir_shorttree(void **state) { - auto *sv = (statevar*) *state; + statevar *sv = (statevar*) *state; const char *t1 = "alibaba/und/die/vierzig/räuber/"; create_dirs( t1 ); @@ -305,17 +236,17 @@ static void check_readdir_shorttree(void **state) traverse_dir(state, CSYNC_TEST_DIR, &files_cnt); assert_string_equal( sv->result, - " C:/tmp/csync_test/alibaba" - " C:/tmp/csync_test/alibaba/und" - " C:/tmp/csync_test/alibaba/und/die" - " C:/tmp/csync_test/alibaba/und/die/vierzig" - " C:/tmp/csync_test/alibaba/und/die/vierzig/räuber" ); + QString::fromUtf8(" %1/alibaba" + " %1/alibaba/und" + " %1/alibaba/und/die" + " %1/alibaba/und/die/vierzig" + " %1/alibaba/und/die/vierzig/räuber").arg(CSYNC_TEST_DIR).toUtf8().constData() ); assert_int_equal(files_cnt, 0); } static void check_readdir_with_content(void **state) { - auto *sv = (statevar*) *state; + statevar *sv = (statevar*) *state; int files_cnt = 0; const char *t1 = "warum/nur/40/Räuber/"; @@ -328,18 +259,18 @@ static void check_readdir_with_content(void **state) traverse_dir(state, CSYNC_TEST_DIR, &files_cnt); assert_string_equal( sv->result, - " C:/tmp/csync_test/warum" - " C:/tmp/csync_test/warum/nur" - " C:/tmp/csync_test/warum/nur/40" - " C:/tmp/csync_test/warum/nur/40/Räuber"); - /* " C:/tmp/csync_test/warum/nur/40/Räuber/Räuber Max.txt" - " C:/tmp/csync_test/warum/nur/40/Räuber/пя́тница.txt"); */ + QString::fromUtf8(" %1/warum" + " %1/warum/nur" + " %1/warum/nur/40" + " %1/warum/nur/40/Räuber").arg(CSYNC_TEST_DIR).toUtf8().constData()); + /* " %1/warum/nur/40/Räuber/Räuber Max.txt" + " %1/warum/nur/40/Räuber/пя́тница.txt"; */ assert_int_equal(files_cnt, 2); /* Two files in the sub dir */ } static void check_readdir_longtree(void **state) { - auto *sv = (statevar*) *state; + statevar *sv = (statevar*) *state; /* 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 @@ -349,100 +280,90 @@ static void check_readdir_longtree(void **state) 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 ); - const char *r1 = -" C:/tmp/csync_test/vierzig" -" C:/tmp/csync_test/vierzig/mann" -" C:/tmp/csync_test/vierzig/mann/auf" -" C:/tmp/csync_test/vierzig/mann/auf/des" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum"; + const auto r1 = QString::fromUtf8( +" %1/vierzig" +" %1/vierzig/mann" +" %1/vierzig/mann/auf" +" %1/vierzig/mann/auf/des" +" %1/vierzig/mann/auf/des/toten" +" %1/vierzig/mann/auf/des/toten/Mann" +" %1/vierzig/mann/auf/des/toten/Mann/kiste" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum").arg(CSYNC_TEST_DIR); - const char *r2 = -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS" -" C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE" -" C:/tmp/csync_test/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"; + const auto r2 = QString::fromUtf8( +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN" +" %1/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS" +" %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" +" %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 char *r3 = -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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" -" C:/tmp/csync_test/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"; + const auto r3 = QString::fromUtf8( +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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" +" %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); /* assemble the result string ... */ - const auto overall_len = 1 + strlen(r1) + strlen(r2) + strlen(r3); + const auto result = (r1 + r2 + r3).toUtf8(); int files_cnt = 0; - char *result = (char*)c_malloc(overall_len); - *result = '\0'; - - strcat(result, r1); - strcat(result, r2); - strcat(result, r3); - traverse_dir(state, CSYNC_TEST_DIR, &files_cnt); assert_int_equal(files_cnt, 0); /* and compare. */ assert_string_equal( sv->result, result); - SAFE_FREE(result); + } // https://github.com/owncloud/client/issues/3128 https://github.com/owncloud/client/issues/2777 static void check_readdir_bigunicode(void **state) { - auto *sv = (statevar*) *state; + statevar *sv = (statevar*) *state; // 1: ? ASCII: 239 - EF // 2: ? ASCII: 187 - BB // 3: ? ASCII: 191 - BF // 4: ASCII: 32 - 20 - char *p = nullptr; - asprintf( &p, "%s/%s", CSYNC_TEST_DIR, "goodone/" ); - int rc = _tmkdir(p, MKDIR_MASK); + QString p = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, "goodone/" ); + int rc = oc_mkdir(p); assert_int_equal(rc, 0); - SAFE_FREE(p); - const char *t1 = "goodone/ugly\xEF\xBB\xBF\x32" ".txt"; // file with encoding error - asprintf( &p, "%s/%s", CSYNC_TEST_DIR, t1 ); - rc = _tmkdir(p, MKDIR_MASK); - SAFE_FREE(p); + p = QStringLiteral("%1/%2").arg(CSYNC_TEST_DIR, "goodone/ugly\xEF\xBB\xBF\x32" ".txt" ); // file with encoding error + + rc = oc_mkdir(p); assert_int_equal(rc, 0); int files_cnt = 0; traverse_dir(state, CSYNC_TEST_DIR, &files_cnt); - const char *expected_result = " C:/tmp/csync_test/goodone" - " C:/tmp/csync_test/goodone/ugly\xEF\xBB\xBF\x32" ".txt" + const auto expected_result = QString::fromUtf8(" %1/goodone" + " %1/goodone/ugly\xEF\xBB\xBF\x32" ".txt").arg(CSYNC_TEST_DIR) ; - assert_string_equal( sv->result, expected_result); + assert_string_equal( sv->result, expected_result.toUtf8().constData()); assert_int_equal(files_cnt, 0); } @@ -456,5 +377,5 @@ int torture_run_tests(void) cmocka_unit_test_setup_teardown(check_readdir_bigunicode, setup_testenv, teardown), }; - return cmocka_run_group_tests(tests, nullptr, nullptr); + return cmocka_run_group_tests(tests, NULL, NULL); }