From 7af4cc23a867dff402504d289af10f2e5de83ddc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Tue, 10 Mar 2015 22:22:00 +0100 Subject: [PATCH] Add simple testing tool and build it on demand --- CMakeLists.txt | 7 +++++++ test_tool.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test_tool.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6146e81..c1595de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,3 +17,10 @@ set(libHPCS_SRCS add_library(HPCS SHARED ${libHPCS_SRCS}) +if (${BuildTestTool}) + set(libHPCS_test_SRCS + test_tool.c) + + add_executable(test_tool ${libHPCS_test_SRCS}) + target_link_libraries(test_tool HPCS) +endif() diff --git a/test_tool.c b/test_tool.c new file mode 100644 index 0000000..eebe9d9 --- /dev/null +++ b/test_tool.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include "libhpcs.h" + +int main(int argc, char** argv) +{ + struct HPCS_MeasuredData* mdata; + enum HPCS_RetCode hret; + size_t di; + + if (argc < 2) { + printf("No filename specified\n"); + return EXIT_FAILURE; + } + + mdata = hpcs_alloc(); + if (mdata == NULL) { + printf("Out of memory\n"); + return EXIT_FAILURE; + } + + hret = hpcs_read_file(argv[1], mdata); + if (hret != HPCS_OK) { + printf("Cannot parse file: %s\n", hpcs_error_to_string(hret)); + return EXIT_FAILURE; + } + + for (di = 0; di < mdata->data_count; di++) + printf("Time: %.17lg, Value: %.17lg\n", mdata->data[di].time, mdata->data[di].value); + + hpcs_free(mdata); + + return EXIT_SUCCESS; +} -- 2.43.5