added relative function

This commit is contained in:
Leonard Iklé committed 2018-09-02 17:41:32 +02:00
1 parent 58ebcdc2f7
commit 69b3bef06e
5 files changed
+357 -44

No files matched your search

+29 -4
View File
@@ -4,6 +4,33 @@
#include <stdlib.h>
#include <string.h>
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
int absolute_check()
{
const char *relative_paths[] = {"..", "test", "test/test", "../another_test",
"./simple", ".././simple"};
const char *absolute_paths[] = {"/", "/test", "/../test/", "/../another_test",
"/./simple", "/.././simple"};
int i;
cwk_path_set_style(CWK_STYLE_UNIX);
for (i = 0; i < ARRAY_SIZE(relative_paths); ++i) {
if (cwk_path_is_absolute(relative_paths[i])) {
return EXIT_FAILURE;
}
}
for (i = 0; i < ARRAY_SIZE(absolute_paths); ++i) {
if (!cwk_path_is_absolute(absolute_paths[i])) {
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
int absolute_too_far()
{
char buffer[FILENAME_MAX];
@@ -70,8 +97,7 @@ int absolute_relative_base()
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_absolute("hello/there", "test", buffer,
sizeof(buffer));
length = cwk_path_get_absolute("hello/there", "test", buffer, sizeof(buffer));
if (length != 17) {
return EXIT_FAILURE;
@@ -110,8 +136,7 @@ int absolute_simple()
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_absolute("/hello/there", "..", buffer,
sizeof(buffer));
length = cwk_path_get_absolute("/hello/there", "..", buffer, sizeof(buffer));
if (length != 6) {
return EXIT_FAILURE;
+131
View File
@@ -0,0 +1,131 @@
#include <cwalk.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
int relative_check()
{
const char *relative_paths[] = {"..", "test", "test/test", "../another_test",
"./simple", ".././simple"};
const char *absolute_paths[] = {"/", "/test", "/../test/", "/../another_test",
"/./simple", "/.././simple"};
int i;
cwk_path_set_style(CWK_STYLE_UNIX);
for (i = 0; i < ARRAY_SIZE(relative_paths); ++i) {
if (!cwk_path_is_relative(relative_paths[i])) {
return EXIT_FAILURE;
}
}
for (i = 0; i < ARRAY_SIZE(absolute_paths); ++i) {
if (cwk_path_is_relative(absolute_paths[i])) {
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
int relative_equal()
{
char result[FILENAME_MAX];
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_relative("/path/same", "/path/same",
result, sizeof(result));
if(length != 1) {
return EXIT_FAILURE;
}
if(strcmp(result, ".") != 0){
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int relative_long_target()
{
char result[FILENAME_MAX];
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_relative("/path/long/one", "/path/long/one/two",
result, sizeof(result));
if(length != 3) {
return EXIT_FAILURE;
}
if(strcmp(result, "two") != 0){
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int relative_long_base()
{
char result[FILENAME_MAX];
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_relative("/path/long/one/two", "/path/long/one",
result, sizeof(result));
if(length != 2) {
return EXIT_FAILURE;
}
if(strcmp(result, "..") != 0){
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int relative_relative()
{
char result[FILENAME_MAX];
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_relative("./this/is/path_one", "./this/is/path_two",
result, sizeof(result));
if(length != 11) {
return EXIT_FAILURE;
}
if(strcmp(result, "../path_two") != 0){
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int relative_simple()
{
char result[FILENAME_MAX];
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_relative("/this/is/path_one", "/this/is/path_two",
result, sizeof(result));
if(length != 11) {
return EXIT_FAILURE;
}
if(strcmp(result, "../path_two") != 0){
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}