44 : m_filename(filename)
65 ifstream file(m_filename.c_str());
67 unsigned char buf[512];
68 memset(buf, 0,
sizeof(buf));
69 size_t amountRead = 0;
71 file.read((
char *)buf,
sizeof(buf));
72 amountRead = file.gcount();
77 float bestMatch = 0.0;
78 string bestFormat =
"Unknown";
79 FileLoaderImplVector::const_iterator it = m_fileLoaders.begin();
80 for (; it != m_fileLoaders.end(); ++it) {
82 string format = (*it)->DetectFileType(buf, amountRead, match);
83 if (match > bestMatch) {
90 if (bestMatch == 0.0 && !file.is_open())
91 return "Not accessible";
103 <<
" is not an AddressDataBus.\n";
113 messages <<
"Error: File format '" <<
114 fileFormat <<
"' not yet implemented. TODO\n";
127 static void Test_FileLoader_Constructor()
129 FileLoader fileLoader(
"test/FileLoader_ELF_MIPS");
131 fileLoader.GetFilename(),
"test/FileLoader_ELF_MIPS");
134 static void Test_FileLoader_Constructor_NonExistingFile()
138 fileLoader.GetFilename(),
"test/Nonexisting");
141 static void Test_FileLoader_DetectFileFormat_NonexistingFile()
146 fileLoader.DetectFileFormat(loaderImpl),
"Not accessible");
149 static void Test_FileLoader_DetectFileFormat_NonsenseFile()
151 FileLoader fileLoader(
"test/FileLoader_NonsenseFile");
154 fileLoader.DetectFileFormat(loaderImpl),
"Unknown");
157 static void Test_FileLoader_DetectFileFormat_ELF32()
159 FileLoader fileLoader(
"test/FileLoader_ELF_MIPS");
162 fileLoader.DetectFileFormat(loaderImpl),
"ELF32");
165 static void Test_FileLoader_DetectFileFormat_ELF64()
167 FileLoader fileLoader(
"test/FileLoader_ELF_SH5");
170 fileLoader.DetectFileFormat(loaderImpl),
"ELF64");
173 static void Test_FileLoader_DetectFileFormat_aout_88K()
175 FileLoader fileLoader(
"test/FileLoader_A.OUT_M88K");
178 fileLoader.DetectFileFormat(loaderImpl),
"a.out_M88K_fromBeginning");
181 static void Test_FileLoader_DetectFileFormat_bout_i960()
183 FileLoader fileLoader(
"test/FileLoader_B.OUT_i960");
186 fileLoader.DetectFileFormat(loaderImpl),
"b.out_i960_little");
190 string machineName,
string fileName)
196 machine->SetVariableValue(
"name",
"\"machine\"");
198 machine->LookupPath(
"machine.mainbus0.cpu0");
202 stringstream messages;
204 " machine " + machineName, fileLoader.Load(component, messages));
209 static void Test_FileLoader_Load_ELF32()
212 SetupTestMachineAndLoad(
"testmips",
"test/FileLoader_ELF_MIPS");
216 machine->LookupPath(
"machine.mainbus0.cpu0");
219 uint32_t word = 0x12345678;
226 machine->LookupPath(
"machine.mainbus0.ram0");
229 uint32_t word2 = 0x12345678;
235 static void Test_FileLoader_Load_aout()
238 SetupTestMachineAndLoad(
"testm88k",
"test/FileLoader_A.OUT_M88K");
242 machine->LookupPath(
"machine.mainbus0.cpu0");
245 uint32_t word = 0x12345678;
252 machine->LookupPath(
"machine.mainbus0.ram0");
255 uint32_t word2 = 0xfdecba98;
263 UNITTEST(Test_FileLoader_Constructor);
264 UNITTEST(Test_FileLoader_Constructor_NonExistingFile);
266 UNITTEST(Test_FileLoader_DetectFileFormat_NonexistingFile);
267 UNITTEST(Test_FileLoader_DetectFileFormat_NonsenseFile);
268 UNITTEST(Test_FileLoader_DetectFileFormat_ELF32);
269 UNITTEST(Test_FileLoader_DetectFileFormat_ELF64);
270 UNITTEST(Test_FileLoader_DetectFileFormat_aout_88K);
271 UNITTEST(Test_FileLoader_DetectFileFormat_bout_i960);
273 UNITTEST(Test_FileLoader_Load_ELF32);
274 UNITTEST(Test_FileLoader_Load_aout);