]> Devoid-pointer.net GitWeb - libHPCS.git/commitdiff
Add simple testing tool and build it on demand
authorMichal Malý <madcatxster@devoid-pointer.net>
Tue, 10 Mar 2015 21:22:00 +0000 (22:22 +0100)
committerMichal Malý <madcatxster@devoid-pointer.net>
Tue, 10 Mar 2015 21:22:00 +0000 (22:22 +0100)
CMakeLists.txt
test_tool.c [new file with mode: 0644]

index 6146e81dcd19001c75dc8eea7028ffdf48395af2..c1595de8190727e959d467a62feb4a1683734b72 100644 (file)
@@ -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 (file)
index 0000000..eebe9d9
--- /dev/null
@@ -0,0 +1,35 @@
+#include <float.h>
+#include <stdio.h>
+#include <stdlib.h>
+#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;
+}