Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2020-07-16 15:21:38 +0300
committerHannah von Reth <vonreth@kde.org>2020-07-20 14:37:01 +0300
commitbaa7cdbcd9404a3fbd7ad39579dae7d542019f6f (patch)
treec61672f429f4a7b5e733f69700b68c594eed4aaa /test
parenta4450fbbaff7d4cdd3a48a0039909da58e09b99a (diff)
Remove more legacy C code
Diffstat (limited to 'test')
-rw-r--r--test/csync/CMakeLists.txt7
-rw-r--r--test/csync/encoding_tests/check_encoding.cpp1
-rw-r--r--test/csync/std_tests/check_std_c_alloc.c89
-rw-r--r--test/csync/std_tests/check_std_c_str.c64
-rw-r--r--test/csync/vio_tests/check_vio_ext.cpp45
5 files changed, 13 insertions, 193 deletions
diff --git a/test/csync/CMakeLists.txt b/test/csync/CMakeLists.txt
index 7b62ffe04..4e673d8ce 100644
--- a/test/csync/CMakeLists.txt
+++ b/test/csync/CMakeLists.txt
@@ -16,19 +16,12 @@ set(TEST_TARGET_LIBRARIES torture Qt5::Core "${csync_NAME}")
# create tests
# std
-add_cmocka_test(check_std_c_alloc std_tests/check_std_c_alloc.c ${TEST_TARGET_LIBRARIES})
add_cmocka_test(check_std_c_jhash std_tests/check_std_c_jhash.c ${TEST_TARGET_LIBRARIES})
-add_cmocka_test(check_std_c_str std_tests/check_std_c_str.c ${TEST_TARGET_LIBRARIES})
-
# vio
add_cmocka_test(check_vio_ext vio_tests/check_vio_ext.cpp ${TEST_TARGET_LIBRARIES})
-if(NOT HAVE_ASPRINTF AND NOT HAVE___MINGW_ASPRINTF)
- target_sources(check_vio_ext PRIVATE ${PROJECT_SOURCE_DIR}/src/csync/std/asprintf.c)
-endif()
-
# encoding
add_cmocka_test(check_encoding_functions encoding_tests/check_encoding.cpp ${TEST_TARGET_LIBRARIES})
diff --git a/test/csync/encoding_tests/check_encoding.cpp b/test/csync/encoding_tests/check_encoding.cpp
index fcefa7ef3..ae0fb87fd 100644
--- a/test/csync/encoding_tests/check_encoding.cpp
+++ b/test/csync/encoding_tests/check_encoding.cpp
@@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
-#include "c_string.h"
#include "common/filesystembase.h"
#include "torture.h"
diff --git a/test/csync/std_tests/check_std_c_alloc.c b/test/csync/std_tests/check_std_c_alloc.c
deleted file mode 100644
index bcdf7e1cf..000000000
--- a/test/csync/std_tests/check_std_c_alloc.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * libcsync -- a library to sync a directory with another
- *
- * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
- *
- * 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 "torture.h"
-
-#include "std/c_alloc.h"
-
-struct test_s {
- int answer;
-};
-
-static void check_c_malloc(void **state)
-{
- struct test_s *p = NULL;
-
- (void) state; /* unused */
-
- p = c_malloc(sizeof(struct test_s));
- assert_non_null(p);
- assert_int_equal(p->answer, 0);
- p->answer = 42;
- assert_int_equal(p->answer, 42);
- free(p);
-}
-
-static void check_c_malloc_zero(void **state)
-{
- void *p;
-
- (void) state; /* unused */
-
- p = c_malloc((size_t) 0);
- assert_null(p);
-}
-
-static void check_c_strdup(void **state)
-{
- const char *str = "test";
- char *tdup = NULL;
-
- (void) state; /* unused */
-
- tdup = c_strdup(str);
- assert_string_equal(tdup, str);
-
- free(tdup);
-}
-
-static void check_c_strndup(void **state)
-{
- const char *str = "test";
- char *tdup = NULL;
-
- (void) state; /* unused */
-
- tdup = c_strndup(str, 3);
- assert_memory_equal(tdup, "tes", 3);
-
- free(tdup);
-}
-
-int torture_run_tests(void)
-{
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(check_c_malloc),
- cmocka_unit_test(check_c_malloc_zero),
- cmocka_unit_test(check_c_strdup),
- cmocka_unit_test(check_c_strndup),
- };
-
- return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
diff --git a/test/csync/std_tests/check_std_c_str.c b/test/csync/std_tests/check_std_c_str.c
deleted file mode 100644
index e815958c2..000000000
--- a/test/csync/std_tests/check_std_c_str.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * libcsync -- a library to sync a directory with another
- *
- * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
- *
- * 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 <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "torture.h"
-
-#include "std/c_string.h"
-
-static void check_c_streq_equal(void **state)
-{
- (void) state; /* unused */
-
- assert_true(c_streq("test", "test"));
-}
-
-static void check_c_streq_not_equal(void **state)
-{
- (void) state; /* unused */
-
- assert_false(c_streq("test", "test2"));
-}
-
-static void check_c_streq_null(void **state)
-{
- (void) state; /* unused */
-
- assert_false(c_streq(NULL, "test"));
- assert_false(c_streq("test", NULL));
- assert_false(c_streq(NULL, NULL));
-}
-
-
-
-int torture_run_tests(void)
-{
- const struct CMUnitTest tests[] = {
- cmocka_unit_test(check_c_streq_equal),
- cmocka_unit_test(check_c_streq_not_equal),
- cmocka_unit_test(check_c_streq_null),
- };
-
- return cmocka_run_group_tests(tests, NULL, NULL);
-}
-
diff --git a/test/csync/vio_tests/check_vio_ext.cpp b/test/csync/vio_tests/check_vio_ext.cpp
index 1b9bc3073..490ab81af 100644
--- a/test/csync/vio_tests/check_vio_ext.cpp
+++ b/test/csync/vio_tests/check_vio_ext.cpp
@@ -25,8 +25,6 @@
#include <stdio.h>
#include "csync.h"
-#include "std/c_alloc.h"
-#include "std/c_string.h"
#include "vio/csync_vio_local.h"
#include <QDir>
@@ -47,8 +45,8 @@ int oc_mkdir(const QString &path)
static mbchar_t wd_buffer[WD_BUFFER_SIZE];
typedef struct {
- char *result;
- char *ignored_dir;
+ QByteArray result;
+ QByteArray ignored_dir;
} statevar;
/* remove the complete test dir */
@@ -82,9 +80,7 @@ static int setup_testenv(void **state) {
assert_int_equal(rc, 0);
/* --- initialize csync */
- statevar *mystate = (statevar*)malloc( sizeof(statevar) );
- mystate->result = NULL;
-
+ statevar *mystate = new statevar;
*state = mystate;
return 0;
}
@@ -105,8 +101,7 @@ static int teardown(void **state) {
rc = wipe_testdir();
assert_int_equal(rc, 0);
- SAFE_FREE(((statevar*)*state)->result);
- SAFE_FREE(*state);
+ delete reinterpret_cast<statevar*>(*state);
return 0;
}
@@ -157,13 +152,11 @@ static void traverse_dir(void **state, const QString &dir, int *cnt)
csync_vio_handle_t *dh;
std::unique_ptr<csync_file_stat_t> dirent;
statevar *sv = (statevar*) *state;
- char *subdir;
- char *subdir_out;
+ QByteArray subdir;
+ QByteArray subdir_out;
int rc;
int is_dir;
- const char *format_str = "%s %s";
-
dh = csync_vio_local_opendir(dir);
assert_non_null(dh);
@@ -171,35 +164,26 @@ static void traverse_dir(void **state, const QString &dir, int *cnt)
while( (dirent = csync_vio_local_readdir(dh, vfs)) ) {
assert_non_null(dirent.get());
if (!dirent->original_path.isEmpty()) {
- sv->ignored_dir = c_strdup(dirent->original_path);
+ sv->ignored_dir = dirent->original_path;
continue;
}
assert_false(dirent->path.isEmpty());
- if( c_streq( dirent->path, "..") || c_streq( dirent->path, "." )) {
+ if( dirent->path == ".." || dirent->path == "." ) {
continue;
}
is_dir = (dirent->type == ItemTypeDirectory) ? 1:0;
- 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 ? "<DIR>":" ",
- subdir), -1 );
+ subdir = dir.toUtf8() + "/" + dirent->path;
+ subdir_out = (is_dir ? "<DIR> ":" ") + subdir;
if( is_dir ) {
- if( !sv->result ) {
- sv->result = c_strdup( subdir_out);
+ if( sv->result.isNull() ) {
+ sv->result = subdir_out;
} else {
- int newlen = 1+strlen(sv->result)+strlen(subdir_out);
- char *tmp = sv->result;
- sv->result = (char*)c_malloc(newlen);
- strcpy( sv->result, tmp);
- SAFE_FREE(tmp);
-
- strcat( sv->result, subdir_out );
+ sv->result += subdir_out;
}
} else {
*cnt = *cnt +1;
@@ -208,9 +192,6 @@ static void traverse_dir(void **state, const QString &dir, int *cnt)
if( is_dir ) {
traverse_dir( state, subdir, cnt);
}
-
- SAFE_FREE(subdir);
- SAFE_FREE(subdir_out);
}
rc = csync_vio_local_closedir(dh);