mirror of
https://github.com/likle/cwalk.git
synced 2026-10-28 09:44:01 +00:00
added some tests
This commit is contained in:
1 parent
92a27a4840
commit
df85322bcc
5 files changed
+219
-17
No files matched your search
@@ -83,6 +83,7 @@ create_test(DEFAULT intersection same_roots)
|
||||
create_test(DEFAULT intersection one_root_only)
|
||||
create_test(DEFAULT intersection relative_base)
|
||||
create_test(DEFAULT intersection relative_other)
|
||||
create_test(DEFAULT intersection skipped_end)
|
||||
create_test(DEFAULT join simple)
|
||||
create_test(DEFAULT join navigate_back)
|
||||
create_test(DEFAULT join empty)
|
||||
@@ -107,12 +108,19 @@ create_test(DEFAULT relative relative)
|
||||
create_test(DEFAULT relative long_base)
|
||||
create_test(DEFAULT relative long_target)
|
||||
create_test(DEFAULT relative equal)
|
||||
create_test(DEFAULT relative base_skipped_end)
|
||||
create_test(DEFAULT relative target_skipped_end)
|
||||
create_test(DEFAULT relative base_div_skipped_end)
|
||||
create_test(DEFAULT relative target_div_skipped_end)
|
||||
create_test(DEFAULT relative different_roots)
|
||||
create_test(DEFAULT relative check)
|
||||
create_test(DEFAULT segment first)
|
||||
create_test(DEFAULT segment last)
|
||||
create_test(DEFAULT segment next)
|
||||
create_test(DEFAULT segment next_too_far)
|
||||
create_test(DEFAULT segment previous_absolute)
|
||||
create_test(DEFAULT segment previous_relative)
|
||||
create_test(DEFAULT segment previous_too_far)
|
||||
create_test(DEFAULT segment type)
|
||||
create_test(DEFAULT segment back_with_root)
|
||||
create_test(DEFAULT windows change_style)
|
||||
@@ -121,6 +129,8 @@ create_test(DEFAULT windows get_unc_root)
|
||||
create_test(DEFAULT windows get_root_separator)
|
||||
create_test(DEFAULT windows get_root_relative)
|
||||
create_test(DEFAULT windows intersection_case)
|
||||
create_test(DEFAULT windows root_backslash)
|
||||
create_test(DEFAULT windows root_empty)
|
||||
create_test_list(DEFAULT "${TEST_DIRECTORY}/tests.h")
|
||||
|
||||
add_executable(${TEST_TARGET}
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
#include <cwalk.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int intersection_skipped_end()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
if (cwk_path_get_intersection("/test/foo/har/../", "/test/foo/ho") != 9) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int intersection_relative_other()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
+112
-17
@@ -1,7 +1,7 @@
|
||||
#include <cwalk.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
@@ -30,6 +30,101 @@ int relative_check()
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_different_roots()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
length = cwk_path_get_relative("C:/path/same", "D:/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_target_div_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/not_same/ho/..", result,
|
||||
sizeof(result));
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../not_same") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_base_div_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/not_same/ho/..", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 7) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, "../same") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_target_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/same/ho/..", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_base_skipped_end()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
size_t length;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same/ho/..", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int relative_equal()
|
||||
{
|
||||
char result[FILENAME_MAX];
|
||||
@@ -37,13 +132,13 @@ int relative_equal()
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
length = cwk_path_get_relative("/path/same", "/path/same",
|
||||
result, sizeof(result));
|
||||
if(length != 1) {
|
||||
length = cwk_path_get_relative("/path/same", "/path/same", result,
|
||||
sizeof(result));
|
||||
if (length != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(strcmp(result, ".") != 0){
|
||||
if (strcmp(result, ".") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -57,13 +152,13 @@ int relative_long_target()
|
||||
|
||||
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) {
|
||||
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){
|
||||
if (strcmp(result, "two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -77,13 +172,13 @@ int relative_long_base()
|
||||
|
||||
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) {
|
||||
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){
|
||||
if (strcmp(result, "..") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -99,11 +194,11 @@ int relative_relative()
|
||||
|
||||
length = cwk_path_get_relative("./this/is/path_one", "./this/is/path_two",
|
||||
result, sizeof(result));
|
||||
if(length != 11) {
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(strcmp(result, "../path_two") != 0){
|
||||
if (strcmp(result, "../path_two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -119,11 +214,11 @@ int relative_simple()
|
||||
|
||||
length = cwk_path_get_relative("/this/is/path_one", "/this/is/path_two",
|
||||
result, sizeof(result));
|
||||
if(length != 11) {
|
||||
if (length != 11) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(strcmp(result, "../path_two") != 0){
|
||||
if (strcmp(result, "../path_two") != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,38 @@ int segment_type()
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int segment_previous_too_far()
|
||||
{
|
||||
const char *path;
|
||||
struct cwk_segment segment;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
path = "/now/hello_world/abc/";
|
||||
|
||||
if (!cwk_path_get_last_segment(path, &segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_get_previous_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int segment_previous_relative()
|
||||
{
|
||||
const char *path;
|
||||
@@ -166,6 +198,34 @@ int segment_previous_absolute()
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int segment_next_too_far()
|
||||
{
|
||||
const char *path;
|
||||
struct cwk_segment segment;
|
||||
|
||||
cwk_path_set_style(CWK_STYLE_UNIX);
|
||||
|
||||
path = "/hello_world/abc/";
|
||||
|
||||
if (!cwk_path_get_first_segment(path, &segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!cwk_path_get_next_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_get_next_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cwk_path_get_next_segment(&segment)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int segment_next()
|
||||
{
|
||||
const char *path;
|
||||
|
||||
@@ -3,6 +3,32 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int windows_root_empty()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_get_root("", &size);
|
||||
if (size != 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_root_backslash()
|
||||
{
|
||||
size_t size;
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
cwk_path_get_root("\\no_network_path\\hello", &size);
|
||||
if (size != 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int windows_intersection_case()
|
||||
{
|
||||
cwk_path_set_style(CWK_STYLE_WINDOWS);
|
||||
|
||||
Reference in new issue
Block a user