1 /* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
27 #include "eina_suite.h"
29 #include "eina_safety_checks.h"
31 #ifdef EINA_SAFETY_CHECKS
38 /* tests should not output on success, just uncomment this for debugging */
42 _eina_test_safety_print_cb(const Eina_Log_Domain *d, Eina_Log_Level level, const char *file, const char *fnc, int line, const char *fmt, void *data, va_list args __UNUSED__)
44 struct log_ctx *ctx = data;
48 va_copy(cp_args, args);
49 str = va_arg(cp_args, const char *);
52 ck_assert_int_eq(level, EINA_LOG_LEVEL_ERR);
53 ck_assert_str_eq(fmt, "%s");
54 ck_assert_str_eq(ctx->msg, str);
55 ck_assert_str_eq(ctx->fnc, fnc);
59 eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
69 START_TEST(eina_file_split_simple)
75 #ifdef EINA_SAFETY_CHECKS
77 fprintf(stderr, "you should have a safety check failure below:\n");
81 #define TEST_MAGIC_SAFETY(fn, _msg) \
86 eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx);
88 TEST_MAGIC_SAFETY("eina_file_split", "safety check failed: path == NULL");
89 ea = eina_file_split(NULL);
91 fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
94 eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
95 #undef TEST_MAGIC_SAFETY
99 ea = eina_file_split(strdup("\\this\\is\\a\\small\\test"));
101 ea = eina_file_split(strdup("/this/is/a/small/test"));
105 fail_if(eina_array_count(ea) != 5);
106 fail_if(strcmp(eina_array_data_get(ea, 0), "this"));
107 fail_if(strcmp(eina_array_data_get(ea, 1), "is"));
108 fail_if(strcmp(eina_array_data_get(ea, 2), "a"));
109 fail_if(strcmp(eina_array_data_get(ea, 3), "small"));
110 fail_if(strcmp(eina_array_data_get(ea, 4), "test"));
116 eina_file_split(strdup(
117 "this\\\\is\\\\\\a \\more\\complex\\\\\\case\\\\\\"));
119 ea = eina_file_split(strdup("this//is///a /more/complex///case///"));
123 fail_if(eina_array_count(ea) != 6);
124 fail_if(strcmp(eina_array_data_get(ea, 0), "this"));
125 fail_if(strcmp(eina_array_data_get(ea, 1), "is"));
126 fail_if(strcmp(eina_array_data_get(ea, 2), "a "));
127 fail_if(strcmp(eina_array_data_get(ea, 3), "more"));
128 fail_if(strcmp(eina_array_data_get(ea, 4), "complex"));
129 fail_if(strcmp(eina_array_data_get(ea, 5), "case"));
138 eina_test_file(TCase *tc)
140 tcase_add_test(tc, eina_file_split_simple);