2014-10-26 15:47:27 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2016-06-02 17:19:08 -07:00
|
|
|
# include "elementary_config.h"
|
2014-10-26 15:47:27 -07:00
|
|
|
#endif
|
|
|
|
|
2017-12-31 08:08:31 -08:00
|
|
|
#include <libgen.h>
|
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
#define ELM_INTERNAL_API_ARGESFSDFEFC
|
|
|
|
|
|
|
|
#include "elm_suite.h"
|
|
|
|
#include "Elementary.h"
|
2014-10-26 15:47:27 -07:00
|
|
|
|
|
|
|
START_TEST (elm_code_file_load)
|
|
|
|
{
|
2016-06-02 17:19:08 -07:00
|
|
|
char *path = TESTS_SRC_DIR "/testfile.txt";
|
2014-10-26 15:47:27 -07:00
|
|
|
char real[EINA_PATH_MAX];
|
|
|
|
Elm_Code_File *file;
|
2014-11-16 15:52:41 -08:00
|
|
|
Elm_Code *code;
|
2014-10-26 15:47:27 -07:00
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_init(1, NULL);
|
2014-11-16 15:52:41 -08:00
|
|
|
code = elm_code_create();
|
|
|
|
file = elm_code_file_open(code, path);
|
2018-01-22 14:58:29 -08:00
|
|
|
ck_assert_ptr_ne(realpath(path, real), NULL);
|
2014-10-26 15:47:27 -07:00
|
|
|
|
2017-12-31 07:28:23 -08:00
|
|
|
ck_assert_str_eq(ecore_file_file_get(path), elm_code_file_filename_get(file));
|
2014-10-26 15:47:27 -07:00
|
|
|
ck_assert_str_eq(real, elm_code_file_path_get(file));
|
|
|
|
elm_code_file_close(file);
|
2014-11-16 15:52:41 -08:00
|
|
|
elm_code_free(code);
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_shutdown();
|
2014-10-26 15:47:27 -07:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST (elm_code_file_load_lines)
|
|
|
|
{
|
2016-06-02 17:19:08 -07:00
|
|
|
char *path = TESTS_SRC_DIR "/testfile.txt";
|
2014-10-26 15:47:27 -07:00
|
|
|
Elm_Code_File *file;
|
2014-11-16 15:52:41 -08:00
|
|
|
Elm_Code *code;
|
2014-10-26 15:47:27 -07:00
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_init(1, NULL);
|
2014-11-16 15:52:41 -08:00
|
|
|
code = elm_code_create();
|
|
|
|
file = elm_code_file_open(code, path);
|
2014-10-26 15:47:27 -07:00
|
|
|
|
|
|
|
ck_assert_uint_eq(4, elm_code_file_lines_get(file));
|
|
|
|
elm_code_file_close(file);
|
2014-11-16 15:52:41 -08:00
|
|
|
elm_code_free(code);
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_shutdown();
|
2014-10-26 15:47:27 -07:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST (elm_code_file_load_blank_lines)
|
|
|
|
{
|
2016-06-02 17:19:08 -07:00
|
|
|
char *path = TESTS_SRC_DIR "/testfile-withblanks.txt";
|
2014-10-26 15:47:27 -07:00
|
|
|
Elm_Code_File *file;
|
2014-11-16 15:52:41 -08:00
|
|
|
Elm_Code *code;
|
2014-10-26 15:47:27 -07:00
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_init(1, NULL);
|
2014-11-16 15:52:41 -08:00
|
|
|
code = elm_code_create();
|
|
|
|
file = elm_code_file_open(code, path);
|
2014-10-26 15:47:27 -07:00
|
|
|
|
|
|
|
ck_assert_uint_eq(8, elm_code_file_lines_get(file));
|
|
|
|
elm_code_file_close(file);
|
2014-11-16 15:52:41 -08:00
|
|
|
elm_code_free(code);
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_shutdown();
|
2014-10-26 15:47:27 -07:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2015-03-27 14:45:43 -07:00
|
|
|
START_TEST (elm_code_file_load_windows)
|
|
|
|
{
|
2016-06-02 17:19:08 -07:00
|
|
|
char *path = TESTS_SRC_DIR "/testfile-windows.txt";
|
2015-03-27 14:45:43 -07:00
|
|
|
Elm_Code_File *file;
|
|
|
|
Elm_Code *code;
|
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_init(1, NULL);
|
2015-03-27 14:45:43 -07:00
|
|
|
code = elm_code_create();
|
|
|
|
file = elm_code_file_open(code, path);
|
|
|
|
|
|
|
|
ck_assert_uint_eq(4, elm_code_file_lines_get(file));
|
|
|
|
elm_code_file_close(file);
|
|
|
|
elm_code_free(code);
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_shutdown();
|
2015-03-27 14:45:43 -07:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-11-19 14:39:00 -08:00
|
|
|
static void _assert_line_content_eq(const char *content, Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
length = strlen(content);
|
|
|
|
ck_assert_int_eq(length, line->length);
|
|
|
|
|
|
|
|
for (c = 0; c < length; c++)
|
|
|
|
ck_assert_uint_eq(content[c], line->content[c]);
|
|
|
|
}
|
|
|
|
|
2014-10-26 15:47:27 -07:00
|
|
|
START_TEST (elm_code_file_load_content)
|
|
|
|
{
|
2016-06-02 17:19:08 -07:00
|
|
|
char *path = TESTS_SRC_DIR "/testfile.txt";
|
2014-10-26 15:47:27 -07:00
|
|
|
Elm_Code_File *file;
|
2014-11-16 15:52:41 -08:00
|
|
|
Elm_Code *code;
|
2014-10-26 15:47:27 -07:00
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_init(1, NULL);
|
2014-11-16 15:52:41 -08:00
|
|
|
code = elm_code_create();
|
|
|
|
file = elm_code_file_open(code, path);
|
2014-10-26 15:47:27 -07:00
|
|
|
|
2014-11-19 14:39:00 -08:00
|
|
|
_assert_line_content_eq("line2", elm_code_file_line_get(file, 2));
|
|
|
|
_assert_line_content_eq("another line", elm_code_file_line_get(file, 4));
|
2014-10-26 15:47:27 -07:00
|
|
|
elm_code_file_close(file);
|
2014-11-16 15:52:41 -08:00
|
|
|
elm_code_free(code);
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_shutdown();
|
2014-10-26 15:47:27 -07:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2015-03-15 16:07:31 -07:00
|
|
|
START_TEST (elm_code_file_line_ending_unix)
|
|
|
|
{
|
2016-06-02 17:19:08 -07:00
|
|
|
char *path = TESTS_SRC_DIR "/testfile.txt";
|
2015-03-15 16:07:31 -07:00
|
|
|
Elm_Code_File *file;
|
|
|
|
Elm_Code *code;
|
2015-03-21 06:58:30 -07:00
|
|
|
short len;
|
2015-03-15 16:07:31 -07:00
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_init(1, NULL);
|
2015-03-15 16:07:31 -07:00
|
|
|
code = elm_code_create();
|
|
|
|
file = elm_code_file_open(code, path);
|
|
|
|
|
|
|
|
ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_UNIX, elm_code_file_line_ending_get(file));
|
2015-03-21 06:58:30 -07:00
|
|
|
ck_assert_str_eq("\n", elm_code_file_line_ending_chars_get(file, &len));
|
|
|
|
ck_assert_int_eq(1, len);
|
2015-03-15 16:07:31 -07:00
|
|
|
|
|
|
|
elm_code_file_close(file);
|
|
|
|
elm_code_free(code);
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_shutdown();
|
2015-03-15 16:07:31 -07:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST (elm_code_file_line_ending_windows)
|
|
|
|
{
|
2016-06-02 17:19:08 -07:00
|
|
|
char *path = TESTS_SRC_DIR "/testfile-windows.txt";
|
2015-03-15 16:07:31 -07:00
|
|
|
Elm_Code_File *file;
|
|
|
|
Elm_Code *code;
|
2015-03-21 06:58:30 -07:00
|
|
|
short len;
|
2015-03-15 16:07:31 -07:00
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_init(1, NULL);
|
2015-03-15 16:07:31 -07:00
|
|
|
code = elm_code_create();
|
|
|
|
file = elm_code_file_open(code, path);
|
|
|
|
|
|
|
|
ck_assert_int_eq(ELM_CODE_FILE_LINE_ENDING_WINDOWS, elm_code_file_line_ending_get(file));
|
2015-03-21 06:58:30 -07:00
|
|
|
ck_assert_str_eq("\r\n", elm_code_file_line_ending_chars_get(file, &len));
|
|
|
|
ck_assert_int_eq(2, len);
|
2015-03-15 16:07:31 -07:00
|
|
|
|
|
|
|
elm_code_file_close(file);
|
|
|
|
elm_code_free(code);
|
2016-06-02 17:19:08 -07:00
|
|
|
elm_shutdown();
|
2015-03-15 16:07:31 -07:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-10-26 15:47:27 -07:00
|
|
|
void elm_code_file_test_load(TCase *tc)
|
|
|
|
{
|
|
|
|
tcase_add_test(tc, elm_code_file_load);
|
|
|
|
tcase_add_test(tc, elm_code_file_load_lines);
|
|
|
|
tcase_add_test(tc, elm_code_file_load_blank_lines);
|
2015-03-27 14:45:43 -07:00
|
|
|
tcase_add_test(tc, elm_code_file_load_windows);
|
2014-10-26 15:47:27 -07:00
|
|
|
tcase_add_test(tc, elm_code_file_load_content);
|
2015-03-15 16:07:31 -07:00
|
|
|
tcase_add_test(tc, elm_code_file_line_ending_unix);
|
|
|
|
tcase_add_test(tc, elm_code_file_line_ending_windows);
|
2014-10-26 15:47:27 -07:00
|
|
|
}
|