complete first draft of package
[epclust.git] / old_C_code / stage1 / test / TimeSeries / t.serialize.c
CommitLineData
ab4a34ef
BA
1#include "TimeSeries/serialize.h"
2#include "lut.h"
3#include <unistd.h>
4#include <stdio.h>
5
6static void checkFilesEqual(const char* fileName1, const char* fileName2)
7{
8 FILE* output = fopen(fileName1, "rb");
9 FILE* refOutput = fopen(fileName2, "rb");
10 while (!feof(output) && !feof(refOutput))
11 LUT_ASSERT(fgetc(output) == fgetc(refOutput));
12 LUT_ASSERT(feof(output) && feof(refOutput));
13 fclose(output);
14 fclose(refOutput);
15}
16
17void t_serialize1()
18{
4b7107ce
BA
19 const char* csvIfName = "../tdata/test/sample_byCols.csv";
20 const char* binaryIfName = "../tdata/test/sample_byCols.bin";
21 const char* tmpBinaryIfName = "../tdata/test/sample_byCols.tmp.bin";
ab4a34ef
BA
22
23 // serialize text file into a temporary binary file
24 serialize_byCols(csvIfName, tmpBinaryIfName, 0);
25
26 // compare binary result with reference
27 checkFilesEqual(tmpBinaryIfName, binaryIfName);
28
29 // remove temp file
30 unlink(tmpBinaryIfName);
31}
32
33void t_serialize2()
34{
4b7107ce
BA
35 const char* csvIfName = "../tdata/test/sample_byRows.csv";
36 const char* binaryIfName = "../tdata/test/sample_byRows.bin";
37 const char* tmpBinaryIfName = "../tdata/test/sample_byRows.tmp.bin";
ab4a34ef
BA
38
39 // serialize text file into a temporary binary file
40 serialize_byRows(csvIfName, tmpBinaryIfName, 0);
41
42 // compare binary result with reference
43 checkFilesEqual(tmpBinaryIfName, binaryIfName);
44
45 // remove temp file
46 unlink(tmpBinaryIfName);
47}