From b38f986767722242dccbac29117a4d23eea72773 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Fri, 17 Oct 2014 23:36:07 +0100 Subject: [PATCH] A pretty slim test of file loading and initial path apis --- elm_code/lib/Elm_Code.h | 24 ++++++++++++++++++++++++ elm_code/lib/elm_code.c | 28 ++++++++++++++++++++++++++++ elm_code/tests/elm_code_test_load.c | 11 ++++++++++- elm_code/tests/testfile.txt | 5 +++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 elm_code/tests/testfile.txt diff --git a/elm_code/lib/Elm_Code.h b/elm_code/lib/Elm_Code.h index 13f6369..f560bbc 100644 --- a/elm_code/lib/Elm_Code.h +++ b/elm_code/lib/Elm_Code.h @@ -3,6 +3,8 @@ #include +#include + #ifdef EAPI # undef EAPI #endif @@ -38,6 +40,20 @@ extern "C" { * @brief These routines are used for interacting with files using Elm Code. */ +typedef struct _Elm_Code_Line +{ + const char *content; + const char *modified; + +} Elm_Code_Line; + +typedef struct _Elm_Code_File +{ + Elm_Code_Line *lines; + Eina_File *file; + +} Elm_Code_File; + /** * @brief Init / shutdown functions. * @defgroup Init Init / Shutdown @@ -84,6 +100,14 @@ EAPI int elm_code_init(void); */ EAPI int elm_code_shutdown(void); +EAPI Elm_Code_File *elm_code_open(const char *path); + +EAPI void elm_code_close(Elm_Code_File *file); + +EAPI const char *elm_code_filename_get(Elm_Code_File *file); + +EAPI const char *elm_code_path_get(Elm_Code_File *file); + /** * @} */ diff --git a/elm_code/lib/elm_code.c b/elm_code/lib/elm_code.c index 0532ce6..44b251a 100644 --- a/elm_code/lib/elm_code.c +++ b/elm_code/lib/elm_code.c @@ -56,3 +56,31 @@ elm_code_shutdown(void) return _elm_code_init; } + +EAPI Elm_Code_File *elm_code_open(const char *path) +{ + Elm_Code_File *ret; + Eina_File *file; + + file = eina_file_open(path, EINA_FALSE); + ret = calloc(1, sizeof(ret)); + ret->file = file; + + return ret; +} + +EAPI void elm_code_close(Elm_Code_File *file) +{ + eina_file_close(file->file); + free(file); +} + +EAPI const char *elm_code_filename_get(Elm_Code_File *file) +{ + return basename(eina_file_filename_get(file->file)); +} + +EAPI const char *elm_code_path_get(Elm_Code_File *file) +{ + return eina_file_filename_get(file->file); +} \ No newline at end of file diff --git a/elm_code/tests/elm_code_test_load.c b/elm_code/tests/elm_code_test_load.c index 807e06e..926b2aa 100644 --- a/elm_code/tests/elm_code_test_load.c +++ b/elm_code/tests/elm_code_test_load.c @@ -6,7 +6,16 @@ START_TEST (elm_code_load) { - ck_assert(1); + char *path = "elm_code/tests/testfile.txt"; + char real[EINA_PATH_MAX]; + Elm_Code_File *file; + + file = elm_code_open(path); + realpath(path, real); + + ck_assert_str_eq(basename(path), elm_code_filename_get(file)); + ck_assert_str_eq(real, elm_code_path_get(file)); + elm_code_close(file); } END_TEST diff --git a/elm_code/tests/testfile.txt b/elm_code/tests/testfile.txt new file mode 100644 index 0000000..246d68e --- /dev/null +++ b/elm_code/tests/testfile.txt @@ -0,0 +1,5 @@ +line 1 +line2 + +another line +5