improve project structure
[epclust.git] / code / stage1 / test / TimeSeries / t.serialize.c
diff --git a/code/stage1/test/TimeSeries/t.serialize.c b/code/stage1/test/TimeSeries/t.serialize.c
new file mode 100644 (file)
index 0000000..6003c67
--- /dev/null
@@ -0,0 +1,47 @@
+#include "TimeSeries/serialize.h"
+#include "lut.h"
+#include <unistd.h>
+#include <stdio.h>
+
+static void checkFilesEqual(const char* fileName1, const char* fileName2)
+{
+       FILE* output = fopen(fileName1, "rb");
+       FILE* refOutput = fopen(fileName2, "rb");
+       while (!feof(output) && !feof(refOutput))
+               LUT_ASSERT(fgetc(output) == fgetc(refOutput));
+       LUT_ASSERT(feof(output) && feof(refOutput));
+       fclose(output);
+       fclose(refOutput);
+}
+
+void t_serialize1()
+{
+       const char* csvIfName = "../tdata/test/sample_byCols.csv";
+       const char* binaryIfName = "../tdata/test/sample_byCols.bin";
+       const char* tmpBinaryIfName = "../tdata/test/sample_byCols.tmp.bin";
+       
+       // serialize text file into a temporary binary file
+       serialize_byCols(csvIfName, tmpBinaryIfName, 0);
+
+       // compare binary result with reference
+       checkFilesEqual(tmpBinaryIfName, binaryIfName);
+
+       // remove temp file
+       unlink(tmpBinaryIfName);
+}
+
+void t_serialize2()
+{
+       const char* csvIfName = "../tdata/test/sample_byRows.csv";
+       const char* binaryIfName = "../tdata/test/sample_byRows.bin";
+       const char* tmpBinaryIfName = "../tdata/test/sample_byRows.tmp.bin";
+       
+       // serialize text file into a temporary binary file
+       serialize_byRows(csvIfName, tmpBinaryIfName, 0);
+
+       // compare binary result with reference
+       checkFilesEqual(tmpBinaryIfName, binaryIfName);
+
+       // remove temp file
+       unlink(tmpBinaryIfName);
+}