mirror of
https://github.com/chylex/Nextcloud-Desktop.git
synced 2025-01-02 19:42:52 +01:00
Remove unused c_path
This commit is contained in:
parent
41798cef18
commit
5d0aa5f039
src
test/csync
@ -69,7 +69,6 @@ set(csync_SRCS
|
||||
vio/csync_vio.cpp
|
||||
|
||||
std/c_alloc.c
|
||||
std/c_path.c
|
||||
std/c_string.c
|
||||
std/c_time.c
|
||||
std/c_utf8.cpp
|
||||
|
@ -23,7 +23,6 @@
|
||||
|
||||
#include "c_macro.h"
|
||||
#include "c_alloc.h"
|
||||
#include "c_path.h"
|
||||
#include "c_string.h"
|
||||
#include "c_time.h"
|
||||
#include "c_private.h"
|
||||
|
@ -1,392 +0,0 @@
|
||||
/*
|
||||
* cynapses libc functions
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "c_private.h"
|
||||
#include "c_alloc.h"
|
||||
#include "c_path.h"
|
||||
#include "c_string.h"
|
||||
#include "c_utf8.h"
|
||||
|
||||
/*
|
||||
* dirname - parse directory component.
|
||||
*/
|
||||
char *c_dirname (const char *path) {
|
||||
char *newbuf = NULL;
|
||||
unsigned int len;
|
||||
|
||||
if (path == NULL || *path == '\0') {
|
||||
return c_strdup(".");
|
||||
}
|
||||
|
||||
len = strlen(path);
|
||||
|
||||
/* Remove trailing slashes */
|
||||
while(len > 0 && path[len - 1] == '/') --len;
|
||||
|
||||
/* We have only slashes */
|
||||
if (len == 0) {
|
||||
return c_strdup("/");
|
||||
}
|
||||
|
||||
/* goto next slash */
|
||||
while(len > 0 && path[len - 1] != '/') --len;
|
||||
|
||||
if (len == 0) {
|
||||
return c_strdup(".");
|
||||
} else if (len == 1) {
|
||||
return c_strdup("/");
|
||||
}
|
||||
|
||||
/* Remove slashes again */
|
||||
while(len > 0 && path[len - 1] == '/') --len;
|
||||
|
||||
newbuf = c_malloc(len + 1);
|
||||
|
||||
strncpy(newbuf, path, len);
|
||||
newbuf[len] = '\0';
|
||||
|
||||
return newbuf;
|
||||
}
|
||||
|
||||
char *c_basename (const char *path) {
|
||||
char *newbuf = NULL;
|
||||
const char *s;
|
||||
unsigned int len;
|
||||
|
||||
if (path == NULL || *path == '\0') {
|
||||
return c_strdup(".");
|
||||
}
|
||||
|
||||
len = strlen(path);
|
||||
/* Remove trailing slashes */
|
||||
while(len > 0 && path[len - 1] == '/') --len;
|
||||
|
||||
/* We have only slashes */
|
||||
if (len == 0) {
|
||||
return c_strdup("/");
|
||||
}
|
||||
|
||||
while(len > 0 && path[len - 1] != '/') --len;
|
||||
|
||||
if (len > 0) {
|
||||
s = path + len;
|
||||
len = strlen(s);
|
||||
|
||||
while(len > 0 && s[len - 1] == '/') --len;
|
||||
} else {
|
||||
return c_strdup(path);
|
||||
}
|
||||
|
||||
newbuf = c_malloc(len + 1);
|
||||
|
||||
strncpy(newbuf, s, len);
|
||||
newbuf[len] = '\0';
|
||||
|
||||
return newbuf;
|
||||
}
|
||||
|
||||
int c_parse_uri(const char *uri,
|
||||
char **scheme,
|
||||
char **user, char **passwd,
|
||||
char **host, unsigned int *port,
|
||||
char **path) {
|
||||
const char *p, *z;
|
||||
|
||||
if (uri == NULL || *uri == '\0') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
p = z = uri;
|
||||
|
||||
/* check for valid scheme; git+ssh, pop3 */
|
||||
while (isalpha((int) *p) || isdigit((int) *p) ||
|
||||
*p == '+' || *p == '-') {
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
p++;
|
||||
}
|
||||
|
||||
/* get scheme */
|
||||
if (*p == ':') {
|
||||
if (scheme != NULL) {
|
||||
*scheme = c_strndup(z, p - z);
|
||||
|
||||
if (*scheme == NULL) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
z = p;
|
||||
}
|
||||
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
p = z;
|
||||
|
||||
/* do we have a hostname */
|
||||
if (p[0] == '/' && p[1] == '/') {
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
z += 2;
|
||||
p = z;
|
||||
|
||||
/* check for user and passwd */
|
||||
while (*p && *p != '@' && *p != '/') {
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^ or ^
|
||||
* z = ^
|
||||
*/
|
||||
p++;
|
||||
}
|
||||
|
||||
/* check for user and password */
|
||||
if (*p == '@') {
|
||||
const char *q;
|
||||
|
||||
q = p;
|
||||
|
||||
/* check if we have a password */
|
||||
while (q > z && *q != ':') {
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
* q = ^
|
||||
*/
|
||||
q--;
|
||||
}
|
||||
|
||||
/* password found */
|
||||
if (*q == ':') {
|
||||
if (user != NULL) {
|
||||
*user = c_strndup(z, q - z);
|
||||
if (*user == NULL) {
|
||||
errno = ENOMEM;
|
||||
if (scheme != NULL) SAFE_FREE(*scheme);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (passwd != NULL) {
|
||||
*passwd = c_strndup(q + 1, p - (q + 1));
|
||||
if (*passwd == NULL) {
|
||||
if (scheme != NULL) SAFE_FREE(*scheme);
|
||||
if (user != NULL) SAFE_FREE(*user);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* user only */
|
||||
if (user != NULL) {
|
||||
*user = c_strndup(z, p - z);
|
||||
if( *user == NULL) {
|
||||
if (scheme != NULL) SAFE_FREE(*scheme);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p++;
|
||||
z = p;
|
||||
}
|
||||
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
p = z;
|
||||
|
||||
/* check for IPv6 address */
|
||||
if (*p == '[') {
|
||||
/*
|
||||
* uri = scheme://user:password@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
p++;
|
||||
|
||||
/* check if we have a valid IPv6 address */
|
||||
while (*p && (isxdigit((int) *p) || *p == '.' || *p == ':')) {
|
||||
/*
|
||||
* uri = scheme://user:password@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
p++;
|
||||
}
|
||||
|
||||
/* valid IPv6 address found */
|
||||
if (*p == ']') {
|
||||
/*
|
||||
* uri = scheme://user:password@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
z++;
|
||||
|
||||
if (host != NULL) {
|
||||
*host = c_strndup(z, p - z);
|
||||
if (*host == NULL) {
|
||||
if (scheme != NULL) SAFE_FREE(*scheme);
|
||||
if (user != NULL) SAFE_FREE(*user);
|
||||
if (passwd != NULL) SAFE_FREE(*passwd);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* uri = scheme://user:password@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
p++;
|
||||
} else {
|
||||
/* invalid IPv6 address, assume a hostname */
|
||||
p = z;
|
||||
|
||||
while (*p && *p != ':' && *p != '/') {
|
||||
p++;
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^ or ^
|
||||
* z = ^
|
||||
*/
|
||||
}
|
||||
|
||||
if (host != NULL) {
|
||||
*host = c_strndup(z, p - z);
|
||||
if (*host == NULL) {
|
||||
if (scheme != NULL) SAFE_FREE(*scheme);
|
||||
if (user != NULL) SAFE_FREE(*user);
|
||||
if (passwd != NULL) SAFE_FREE(*passwd);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* check for hostname */
|
||||
while (*p && *p != ':' && *p != '/') {
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^ ^
|
||||
* z = ^
|
||||
*/
|
||||
p++;
|
||||
}
|
||||
|
||||
if (host != NULL) {
|
||||
*host = c_strndup(z, p - z);
|
||||
if (*host == NULL) {
|
||||
if (scheme != NULL) SAFE_FREE(*scheme);
|
||||
if (user != NULL) SAFE_FREE(*user);
|
||||
if (passwd != NULL) SAFE_FREE(*passwd);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check for port */
|
||||
if (*p == ':') {
|
||||
char **e = NULL;
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
z = ++p;
|
||||
|
||||
/* get only the digits */
|
||||
while (isdigit((int) *p)) {
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
* z = ^
|
||||
*/
|
||||
e = (char **) &p;
|
||||
p++;
|
||||
}
|
||||
|
||||
if (port != NULL) {
|
||||
*port = strtoul(z, e, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* uri = scheme://user:password@host:port/path
|
||||
* p = ^
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
if (*p == '\0') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get the path with the leading slash */
|
||||
if (*p == '/') {
|
||||
if (path != NULL) {
|
||||
*path = c_strdup(p);
|
||||
if (*path == NULL) {
|
||||
if (scheme != NULL) SAFE_FREE(*scheme);
|
||||
if (user != NULL) SAFE_FREE(*user);
|
||||
if (passwd != NULL) SAFE_FREE(*passwd);
|
||||
if (host != NULL) SAFE_FREE(*host);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* cynapses libc functions
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file c_path.h
|
||||
*
|
||||
* @brief Interface of the cynapses libc path functions
|
||||
*
|
||||
* @defgroup cynPathInternals cynapses libc path functions
|
||||
* @ingroup cynLibraryAPI
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _C_PATH_H
|
||||
#define _C_PATH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "c_macro.h"
|
||||
#include "c_private.h"
|
||||
|
||||
/**
|
||||
* @brief Parse directory component.
|
||||
*
|
||||
* dirname breaks a null-terminated pathname string into a directory component.
|
||||
* In the usual case, c_dirname() returns the string up to, but not including,
|
||||
* the final '/'. Trailing '/' characters are not counted as part of the
|
||||
* pathname. The caller must free the memory.
|
||||
*
|
||||
* @param path The path to parse.
|
||||
*
|
||||
* @return The dirname of path or NULL if we can't allocate memory. If path
|
||||
* does not contain a slash, c_dirname() returns the string ".". If
|
||||
* path is the string "/", it returns the string "/". If path is
|
||||
* NULL or an empty string, "." is returned.
|
||||
*/
|
||||
char *c_dirname(const char *path);
|
||||
|
||||
/**
|
||||
* @brief basename - parse filename component.
|
||||
*
|
||||
* basename breaks a null-terminated pathname string into a filename component.
|
||||
* c_basename() returns the component following the final '/'. Trailing '/'
|
||||
* characters are not counted as part of the pathname.
|
||||
*
|
||||
* @param path The path to parse.
|
||||
*
|
||||
* @return The filename of path or NULL if we can't allocate memory. If path
|
||||
* is a the string "/", basename returns the string "/". If path is
|
||||
* NULL or an empty string, "." is returned.
|
||||
*/
|
||||
char *c_basename (const char *path);
|
||||
|
||||
/**
|
||||
* @brief parse a uri and split it into components.
|
||||
*
|
||||
* parse_uri parses an uri in the format
|
||||
*
|
||||
* [<scheme>:][//[<user>[:<password>]@]<host>[:<port>]]/[<path>]
|
||||
*
|
||||
* into its compoments. If you only want a special component,
|
||||
* pass NULL for all other components. All components will be allocated if they have
|
||||
* been found.
|
||||
*
|
||||
* @param uri The uri to parse.
|
||||
* @param scheme String for the scheme component
|
||||
* @param user String for the username component
|
||||
* @param passwd String for the password component
|
||||
* @param host String for the password component
|
||||
* @param port Integer for the port
|
||||
* @param path String for the path component with a leading slash.
|
||||
*
|
||||
* @return 0 on success, < 0 on error.
|
||||
*/
|
||||
int c_parse_uri(const char *uri, char **scheme, char **user, char **passwd,
|
||||
char **host, unsigned int *port, char **path);
|
||||
|
||||
/**
|
||||
* @brief Parts of a path.
|
||||
*
|
||||
* @param directory '\0' terminated path including the final '/'
|
||||
*
|
||||
* @param filename '\0' terminated string
|
||||
*
|
||||
* @param extension '\0' terminated string
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char * directory;
|
||||
char * filename;
|
||||
char * extension;
|
||||
} C_PATHINFO;
|
||||
|
||||
/**
|
||||
* }@
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _C_PATH_H */
|
@ -32,7 +32,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
#include "c_string.h"
|
||||
#include "c_path.h"
|
||||
#include "c_alloc.h"
|
||||
#include "c_macro.h"
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "c_private.h"
|
||||
#include "c_string.h"
|
||||
|
||||
#include "c_path.h"
|
||||
#include "c_time.h"
|
||||
#include "c_utf8.h"
|
||||
|
||||
|
@ -23,7 +23,6 @@ extern "C" int c_utimes(const char *, const struct timeval *);
|
||||
|
||||
#include "csync.h"
|
||||
#include "vio/csync_vio_local.h"
|
||||
#include "std/c_path.h"
|
||||
#include "std/c_string.h"
|
||||
#include "std/c_utf8.h"
|
||||
|
||||
|
@ -22,7 +22,6 @@ set(TEST_TARGET_LIBRARIES ${TORTURE_LIBRARY})
|
||||
# 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_path std_tests/check_std_c_path.c ${TEST_TARGET_LIBRARIES})
|
||||
add_cmocka_test(check_std_c_str std_tests/check_std_c_str.c ${TEST_TARGET_LIBRARIES})
|
||||
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "c_string.h"
|
||||
#include "c_path.h"
|
||||
#include "c_utf8.h"
|
||||
#include "common/filesystembase.h"
|
||||
#include "torture.h"
|
||||
|
@ -1,185 +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 <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "std/c_path.h"
|
||||
|
||||
#include "torture.h"
|
||||
|
||||
static void check_c_basename(void **state)
|
||||
{
|
||||
char *bname;
|
||||
|
||||
(void) state; /* unused */
|
||||
|
||||
bname = c_basename("/usr/lib");
|
||||
assert_string_equal(bname, "lib");
|
||||
free(bname);
|
||||
|
||||
bname = c_basename("/usr//");
|
||||
assert_string_equal(bname, "usr");
|
||||
free(bname);
|
||||
|
||||
bname = c_basename("usr");
|
||||
assert_string_equal(bname, "usr");
|
||||
free(bname);
|
||||
|
||||
bname = c_basename("///");
|
||||
assert_string_equal(bname, "/");
|
||||
free(bname);
|
||||
|
||||
bname = c_basename("/");
|
||||
assert_string_equal(bname, "/");
|
||||
free(bname);
|
||||
|
||||
bname = c_basename(".");
|
||||
assert_string_equal(bname, ".");
|
||||
free(bname);
|
||||
|
||||
bname = c_basename("..");
|
||||
assert_string_equal(bname, "..");
|
||||
free(bname);
|
||||
|
||||
bname = c_basename("");
|
||||
assert_string_equal(bname, ".");
|
||||
free(bname);
|
||||
|
||||
bname = c_basename(NULL);
|
||||
assert_string_equal(bname, ".");
|
||||
free(bname);
|
||||
}
|
||||
|
||||
static void check_c_basename_uri(void **state)
|
||||
{
|
||||
char *bname = NULL;
|
||||
|
||||
(void) state; /* unused */
|
||||
|
||||
bname = c_basename("smb://server/share/dir/");
|
||||
assert_string_equal(bname, "dir");
|
||||
free(bname);
|
||||
}
|
||||
|
||||
static void check_c_dirname(void **state)
|
||||
{
|
||||
char *dname;
|
||||
|
||||
(void) state; /* unused */
|
||||
|
||||
dname = c_dirname("/usr/lib");
|
||||
assert_string_equal(dname, "/usr");
|
||||
free(dname);
|
||||
|
||||
dname = c_dirname("/usr//");
|
||||
assert_string_equal(dname, "/");
|
||||
free(dname);
|
||||
|
||||
dname = c_dirname("usr");
|
||||
assert_string_equal(dname, ".");
|
||||
free(dname);
|
||||
|
||||
dname = c_dirname("/");
|
||||
assert_string_equal(dname, "/");
|
||||
free(dname);
|
||||
|
||||
dname = c_dirname("///");
|
||||
assert_string_equal(dname, "/");
|
||||
free(dname);
|
||||
|
||||
dname = c_dirname(".");
|
||||
assert_string_equal(dname, ".");
|
||||
free(dname);
|
||||
|
||||
dname = c_dirname("..");
|
||||
assert_string_equal(dname, ".");
|
||||
free(dname);
|
||||
|
||||
dname = c_dirname(NULL);
|
||||
assert_string_equal(dname, ".");
|
||||
free(dname);
|
||||
}
|
||||
|
||||
static void check_c_dirname_uri(void **state)
|
||||
{
|
||||
char *dname;
|
||||
|
||||
(void) state; /* unused */
|
||||
|
||||
dname = c_dirname("smb://server/share/dir");
|
||||
assert_string_equal(dname, "smb://server/share");
|
||||
free(dname);
|
||||
}
|
||||
|
||||
static void check_c_parse_uri(void **state)
|
||||
{
|
||||
const char *test_scheme = "git+ssh";
|
||||
const char *test_user = "gladiac";
|
||||
const char *test_passwd = "secret";
|
||||
const char *test_host = "git.csync.org";
|
||||
const char *test_path = "/srv/git/csync.git";
|
||||
|
||||
char *scheme = NULL;
|
||||
char *user = NULL;
|
||||
char *passwd = NULL;
|
||||
char *host = NULL;
|
||||
unsigned int port;
|
||||
char *path = NULL;
|
||||
char uri[1024] = {0};
|
||||
int rc;
|
||||
|
||||
(void) state; /* unused */
|
||||
|
||||
rc = snprintf(uri, sizeof(uri), "%s://%s:%s@%s:22%s",
|
||||
test_scheme, test_user, test_passwd, test_host, test_path);
|
||||
assert_true(rc);
|
||||
|
||||
rc = c_parse_uri(uri, &scheme, &user, &passwd, &host, &port, &path);
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
assert_string_equal(test_scheme, scheme);
|
||||
assert_string_equal(test_user, user);
|
||||
assert_string_equal(test_passwd, passwd);
|
||||
assert_string_equal(test_host, host);
|
||||
assert_int_equal(port, 22);
|
||||
assert_string_equal(test_path, path);
|
||||
|
||||
free(scheme);
|
||||
free(user);
|
||||
free(passwd);
|
||||
free(host);
|
||||
free(path);
|
||||
}
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(check_c_basename),
|
||||
cmocka_unit_test(check_c_basename_uri),
|
||||
cmocka_unit_test(check_c_dirname),
|
||||
cmocka_unit_test(check_c_dirname_uri),
|
||||
cmocka_unit_test(check_c_parse_uri),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user