diff options
author | Andy Williams <andy@andywilliams.me> | 2016-12-27 21:12:49 +0000 |
---|---|---|
committer | Andy Williams <andy@andywilliams.me> | 2016-12-27 21:12:49 +0000 |
commit | 5cf5e4bb3c62d63a61b4070a8fa27fec67414fb5 (patch) | |
tree | 378f08c726e8a672ff3b6a84471e539288810095 | |
parent | 34abcd33c99d23d05fe19b341911167a6ee2e86b (diff) | |
download | efl-5cf5e4bb3c62d63a61b4070a8fa27fec67414fb5.tar.gz |
elm_code: Fix filename/path for non-file based instances
And add tests appropriately
-rw-r--r-- | src/lib/elementary/elm_code_file.c | 6 | ||||
-rw-r--r-- | src/lib/elementary/elm_code_file.h | 10 | ||||
-rw-r--r-- | src/tests/elementary/elm_code_test_basic.c | 22 |
3 files changed, 38 insertions, 0 deletions
diff --git a/src/lib/elementary/elm_code_file.c b/src/lib/elementary/elm_code_file.c index a87a7d034e..8e015de6f0 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 3c3d4bd339..e7f2cabb12 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 9805a7508b..5f6827b95e 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); } |