/[jscoverage]/trunk/tests/streams.c
ViewVC logotype

Diff of /trunk/tests/streams.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 229 by siliconforks, Sat May 31 21:21:59 2008 UTC revision 230 by siliconforks, Fri Oct 3 02:29:48 2008 UTC
# Line 21  Line 21 
21  #include <string.h>  #include <string.h>
22    
23  #include "stream.h"  #include "stream.h"
24    #include "util.h"
25    
26  int main(void) {  int main(void) {
27    Stream * stream;    Stream * stream;
# Line 32  Line 33 
33    assert(memcmp(stream->data, "abc", 3) == 0);    assert(memcmp(stream->data, "abc", 3) == 0);
34    Stream_delete(stream);    Stream_delete(stream);
35    
36      /* test writing chars to stream */
37      stream = Stream_new(2);
38      Stream_write_char(stream, 'a');
39      Stream_write_char(stream, 'b');
40      Stream_write_char(stream, 'c');
41      assert(stream->length == 3);
42      assert(memcmp(stream->data, "abc", 3) == 0);
43      Stream_reset(stream);
44      Stream_write_char(stream, 'x');
45      Stream_write_char(stream, 'y');
46      assert(stream->length == 2);
47      assert(memcmp(stream->data, "xy", 2) == 0);
48      Stream_delete(stream);
49    
50      /* test writing file to stream */
51      stream = Stream_new(0);
52      FILE * f = xfopen("Makefile", "r");
53      fseek(f, 0, SEEK_END);
54      long file_length = ftell(f);
55      fseek(f, 0, SEEK_SET);
56      uint8_t * file_contents = xmalloc(file_length);
57      fread(file_contents, 1, file_length, f);
58      fseek(f, 0, SEEK_SET);
59      Stream_write_file_contents(stream, f);
60      fclose(f);
61      assert(stream->length == file_length);
62      assert(memcmp(stream->data, file_contents, file_length) == 0);
63      free(file_contents);
64      Stream_delete(stream);
65    
66    stream = Stream_new(0);    stream = Stream_new(0);
67    Stream_printf(stream, "%s %d\n", "abc", 123);    Stream_printf(stream, "%s %d\n", "abc", 123);
68    assert(stream->length == 8);    assert(stream->length == 8);

Legend:
Removed from v.229  
changed lines
  Added in v.230

  ViewVC Help
Powered by ViewVC 1.1.24