elm_code: Fix filename/path for non-file based instances

And add tests appropriately
This commit is contained in:
Andy Williams 2016-12-27 21:12:49 +00:00
parent 34abcd33c9
commit 5cf5e4bb3c
3 changed files with 38 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}