20 -1, -1, -1, -1, -1, 0, 0, 0,
26 66, 66, 66, 66, 66, 66, 66, 66
29 static float f1 = 3.1415926f;
30 static float f2 = 42.23f;
33 std::ofstream file(name, std::ios_base::out | std::ios_base::binary);
35 file.write(reinterpret_cast<char*>(&
f1),
sizeof(
f1));
36 file.write(reinterpret_cast<char*>(&
f2),
sizeof(
f2));
39 static int test(
const char* name) {
41 if (file.
open(name) != 0) {
42 std::cout <<
"Error opening file " << name << std::endl;
46 if (file.
readU8() != 255) {
47 std::cout <<
"Error reading U8!" << std::endl;
52 std::cout <<
"Error reading U16!" << std::endl;
56 if (file.
readU32() != 707406378) {
57 std::cout <<
"Error reading U32!" << std::endl;
61 if (file.
readU64() != 1099511627775) {
62 std::cout <<
"Error reading U64!" << std::endl;
66 if (file.
read8() != -1) {
67 std::cout <<
"Error reading 8!" << std::endl;
71 if (file.
read16() != -420) {
72 std::cout <<
"Error reading 16!" << std::endl;
76 if (file.
read32() != -666) {
77 std::cout <<
"Error reading 32!" << std::endl;
81 if (file.
read64() != 4774451407313060418) {
82 std::cout <<
"Error reading 64!" << std::endl;
86 std::cout <<
"This test will fail on big-endian machines!" << std::endl;
89 std::cout <<
"Error reading float1!" << std::endl;
94 std::cout <<
"Error reading float2!" << std::endl;
98 if (file.
tell() != 38) {
99 std::cout <<
"Error, file position wrong!" << std::endl;
107 char tmpFile[] =
"/tmp/openraider_unit_test_0";
109 while ((f = fopen(tmpFile,
"r")) != NULL) {
Binary file reading utilities.
static void error(char *msg)
static int test(const char *name)
virtual float readFloat()
virtual uint16_t readU16()
virtual uint32_t readU32()
static void fillFile(const char *name)
static const char testData[]
virtual uint64_t readU64()
int open(std::string f="")