1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #pragma once
- #include <cxxtest/TestSuite.h>
- #include "chunkfile_c.h"
- #include <string>
- #include <iostream>
- std::string get_temp_dir()
- {
- static bool temp_dir_created = false;
- std::string temp_dir = "temp_chunkfiletest/" ;
- if (!temp_dir_created)
- {
- std::cout << "create_temp_dir" << endl;
- mkdir(temp_dir.c_str(),16877);
- temp_dir_created = true;
-
- }
- return temp_dir;
- }
- class TestChunkFileC : public CxxTest::TestSuite
- {
- public:
- void testDummy()
- {
- TS_ASSERT_EQUALS(3,3);
-
- }
-
- void testSaveData()
- {
- int data[] = {3,4,5,6,7,4,5,6};
- size_t data_size = sizeof(data)/sizeof(int);
- std::string dir = get_temp_dir();
- std::string file_path = dir + "data_file.dat";
- std::string format("my_funny_file_format");
- int major = 42;
- int minor = 69;
- ChunkFileW writer = Open_ChunkFileWriter(file_path.c_str(), format.c_str(), major, minor);
- TS_ASSERT(writer);
- if (!writer)
- return;
- ChunkFileWriter_Write("gaga", sizeof(int), data_size, (char*)data, writer);
- ChunkFileWriter_Close(writer);
- ChunkFileR reader = Open_ChunkFileReader(file_path.c_str(), format.c_str(), major, minor);
- TS_ASSERT(reader);
- if (!reader)
- return;
- size_t n_elements;
- size_t element_size = sizeof(int);
- int* loaded_data = NULL;
- ChunkFileError err = ChunkFileReader_Read("gaga",
- element_size,
- &n_elements,
- (char**) &loaded_data,
- reader);
- ChunkFileReader_Close(reader);
- TS_ASSERT_EQUALS(err, ChunkFile_OK);
- TS_ASSERT_EQUALS(n_elements, data_size);
- TS_ASSERT(loaded_data);
- if (!loaded_data)
- return;
- for (int i=0; i<n_elements; ++i) {
- TS_ASSERT_EQUALS(loaded_data[i], data[i]);
- }
-
-
- }
- };
|