ajwillia-ms pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=5cf5e4bb3c62d63a61b4070a8fa27fec67414fb5
commit 5cf5e4bb3c62d63a61b4070a8fa27fec67414fb5 Author: Andy Williams <[email protected]> Date: Tue Dec 27 21:12:49 2016 +0000 elm_code: Fix filename/path for non-file based instances And add tests appropriately --- src/lib/elementary/elm_code_file.c | 6 ++++++ src/lib/elementary/elm_code_file.h | 10 ++++++++++ src/tests/elementary/elm_code_test_basic.c | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/lib/elementary/elm_code_file.c b/src/lib/elementary/elm_code_file.c index a87a7d0..8e015de 100644 --- a/src/lib/elementary/elm_code_file.c +++ b/src/lib/elementary/elm_code_file.c @@ -72,11 +72,17 @@ static void _elm_code_file_line_insert_data(Elm_Code_File *file, const char *con EAPI const char *elm_code_file_filename_get(Elm_Code_File *file) { + if (!file->file) + return NULL; + return basename((char *)eina_file_filename_get(file->file)); } EAPI const char *elm_code_file_path_get(Elm_Code_File *file) { + if (!file->file) + return NULL; + return eina_file_filename_get(file->file); } diff --git a/src/lib/elementary/elm_code_file.h b/src/lib/elementary/elm_code_file.h index 3c3d4bd..e7f2cab 100644 --- a/src/lib/elementary/elm_code_file.h +++ b/src/lib/elementary/elm_code_file.h @@ -46,8 +46,18 @@ EAPI void elm_code_file_free(Elm_Code_File *file); EAPI void elm_code_file_close(Elm_Code_File *file); +/** + * Get the filename for the file specified. + * + * @return the filename or NULL if it is an in-memory file + */ EAPI const char *elm_code_file_filename_get(Elm_Code_File *file); +/** + * Get the file path for the file specified. + * + * @return the file's path or NULL if it is an in-memory file + */ EAPI const char *elm_code_file_path_get(Elm_Code_File *file); EAPI Elm_Code_File_Line_Ending elm_code_file_line_ending_get(Elm_Code_File *file); diff --git a/src/tests/elementary/elm_code_test_basic.c b/src/tests/elementary/elm_code_test_basic.c index 9805a75..5f6827b 100644 --- a/src/tests/elementary/elm_code_test_basic.c +++ b/src/tests/elementary/elm_code_test_basic.c @@ -4,25 +4,47 @@ #define ELM_INTERNAL_API_ARGESFSDFEFC +#include <stdlib.h> + #include "elm_suite.h" #include "Elementary.h" START_TEST (elm_code_create_test) { + Elm_Code *code; + + elm_init(1, NULL); + code = elm_code_create(); + + ck_assert(!!code); + ck_assert(elm_code_file_path_get(code->file) == NULL); + elm_code_free(code); + elm_shutdown(); +} +END_TEST + +START_TEST (elm_code_open_test) +{ char *path = TESTS_SRC_DIR "/testfile.txt"; + char realpath1[PATH_MAX], realpath2[PATH_MAX]; Elm_Code *code; elm_init(1, NULL); code = elm_code_create(); elm_code_file_open(code, path); + realpath(path, realpath1); + realpath(elm_code_file_path_get(code->file), realpath2); ck_assert(!!code); + ck_assert_str_eq(realpath1, realpath2); elm_code_free(code); elm_shutdown(); } END_TEST + void elm_code_test_basic(TCase *tc) { tcase_add_test(tc, elm_code_create_test); + tcase_add_test(tc, elm_code_open_test); } --
