Previous 15994 Revisions Next

r2643 Saturday 17th May, 2008 at 01:31:52 UTC by Nathan Woods
[Imgtool/Messtest] Added a test case, cleanups and fixed two memory leaks
[src/mess/tests]imgtool_rsdos.xml
[src/mess/tools/imgtool]stream.c
[src/mess/tools/messtest]testimgt.c

src/mess/tools/messtest/testimgt.c
r2642r2643
181181   const char *filename;
182182   const char *fork;
183183   filter_getinfoproc filter;
184   imgtool_stream *stream;
184   imgtool_stream *stream = NULL;
185185   mess_pile pile;
186186
187   if (!state->partition)
187   if (state->partition == NULL)
188188   {
189189      state->failed = 1;
190190      report_message(MSG_FAILURE, "Partition not loaded");
191      return;
191      goto done;
192192   }
193193
194194   get_file_params(node, &filename, &fork, &filter);
195   if (!filename)
196      return;
195   if (filename == NULL)
196      goto done;
197197
198198   pile_init(&pile);
199199   messtest_get_data(node, &pile);
200200
201201   stream = stream_open_mem(NULL, 0);
202   if (!stream)
202   if (stream == NULL)
203203   {
204204      state->failed = 1;
205205      error_outofmemory();
206      return;
206      goto done;
207207   }
208208
209209   stream_write(stream, pile_getptr(&pile), pile_size(&pile));
r2642r2643
215215   {
216216      state->failed = 1;
217217      report_imgtoolerr(err);
218      return;
218      goto done;
219219   }
220220
221221   if (VERBOSE_FILECHAIN)
r2642r2643
225225      if (err == IMGTOOLERR_SUCCESS)
226226         report_message(MSG_INFO, "Filechain '%s': %s", filename, buf);
227227   }
228
229done:
230   if (stream != NULL)
231      stream_close(stream);
228232}
229233
230234
r2642r2643
235239   const char *filename;
236240   const char *fork;
237241   filter_getinfoproc filter;
238   imgtool_stream *stream;
242   imgtool_stream *stream = NULL;
239243   UINT64 stream_sz;
240244   const void *stream_ptr;
241245   mess_pile pile;
r2642r2643
244248   {
245249      state->failed = 1;
246250      report_message(MSG_FAILURE, "Partition not loaded");
247      return;
251      goto done;
248252   }
249253
250254   get_file_params(node, &filename, &fork, &filter);
251255   if (!filename)
252      return;
256      goto done;
253257
254258   stream = stream_open_mem(NULL, 0);
255259   if (!stream)
256260   {
257261      state->failed = 1;
258262      error_outofmemory();
259      return;
263      goto done;
260264   }
261265
262266   err = imgtool_partition_read_file(state->partition, filename, fork, stream, filter);
r2642r2643
264268   {
265269      state->failed = 1;
266270      report_imgtoolerr(err);
267      return;
271      goto done;
268272   }
269273
270274   pile_init(&pile);
r2642r2643
276280   if ((pile_size(&pile) != stream_sz) || (memcmp(stream_ptr, pile_getptr(&pile), pile_size(&pile))))
277281   {
278282      report_message(MSG_FAILURE, "Failed file verification");
279      return;
283      goto done;
280284   }
281285
282286   pile_delete(&pile);
287
288done:
289   if (stream != NULL)
290      stream_close(stream);
283291}
284292
285293
src/mess/tools/imgtool/stream.c
r2642r2643
231231
232232void stream_close(imgtool_stream *s)
233233{
234   assert(s);
234   assert(s != NULL);
235235
236236   switch(s->imgtype)
237237   {
238238      case IMG_FILE:
239         core_fclose(s->u.file);
239         if (s->u.file != NULL)
240         {
241            core_fclose(s->u.file);
242            s->u.file = NULL;
243         }
240244         break;
241245
242246      case IMG_MEM:
243         free(s->u.buffer);
247         if (s->u.buffer != NULL)
248         {
249            free(s->u.buffer);
250            s->u.buffer = NULL;
251         }
244252         break;
245253
246254      default:
src/mess/tests/imgtool_rsdos.xml
r2642r2643
119119   <checkfile name="FOO.BAS" filter="cocobas">'10 GOTO10&#13;&#10;'</checkfile>
120120</imgtooltest>
121121
122<imgtooltest name="coco_rs_006">
123  <!-- NOTE: should be using &eoln; here; this test assumes that the host is CRLF -->
124  <createimage driver="coco_jvc_rsdos"/>
125  <putfile name="FOO.BAS" filter="cocobas">'10 GOTO10&#13;&#10;'</putfile>
126  <checkfile name="FOO.BAS">0xFF000E2607000A81A53130000000</checkfile>
127</imgtooltest>
128
122129</tests>

Previous 15994 Revisions Next


© 1998-2018 The MESS Team