第一次提交
This commit is contained in:
43
tests/test_iris_format.cpp
Normal file
43
tests/test_iris_format.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iris_format/iris_deffine.h>
|
||||
FILE *fp = nullptr;
|
||||
void openfile(std::string Filepath,const char *mode) {
|
||||
fp= fopen(Filepath.c_str(), mode);
|
||||
}
|
||||
void write_data(const uint8_t *data, size_t length) {
|
||||
if (fp != nullptr) {
|
||||
fwrite(data, 1, length, fp);
|
||||
}
|
||||
}
|
||||
void closefile() {
|
||||
if (fp != nullptr) {
|
||||
fclose(fp);
|
||||
fp = nullptr;
|
||||
}
|
||||
}
|
||||
int64_t read_data(uint8_t **buffer, size_t size) {
|
||||
if (fp == nullptr) {
|
||||
return -1; // File not open
|
||||
}
|
||||
if (*buffer != nullptr) {
|
||||
delete[] *buffer; // Free previously allocated buffer
|
||||
}
|
||||
*buffer = new uint8_t[size];
|
||||
return fread(*buffer, 1, size, fp);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MyfileControl_Struct *file_control = new MyfileControl_Struct;
|
||||
file_control->open_file = openfile;
|
||||
file_control->Write_data = write_data;
|
||||
file_control->close_file = closefile;
|
||||
file_control->Read_data = read_data;
|
||||
Set_File_Functions(file_control);
|
||||
IRIS_DATA_example();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user