| 1 | // |
|---|
| 2 | // Emit.c |
|---|
| 3 | // |
|---|
| 4 | // $Author$ |
|---|
| 5 | // $Date$ |
|---|
| 6 | // |
|---|
| 7 | // Copyright (C) 2003 why the lucky stiff |
|---|
| 8 | // |
|---|
| 9 | |
|---|
| 10 | #include <string.h> |
|---|
| 11 | #include "syck.h" |
|---|
| 12 | #include "CuTest.h" |
|---|
| 13 | |
|---|
| 14 | // |
|---|
| 15 | // 1. Test the buffering -- print 10 bytes at a time |
|---|
| 16 | // |
|---|
| 17 | void |
|---|
| 18 | TestSyckEmit_Output( SyckEmitter *e, const char *str, long len ) |
|---|
| 19 | { |
|---|
| 20 | // char *tmp = syck_strndup( str, len ); |
|---|
| 21 | // printf( "OUT: %s [%d]\n", tmp, len ); |
|---|
| 22 | // S_FREE( tmp ); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | void |
|---|
| 26 | TestSyckEmit( CuTest *tc ) |
|---|
| 27 | { |
|---|
| 28 | SyckEmitter *emitter; |
|---|
| 29 | |
|---|
| 30 | emitter = syck_new_emitter(); |
|---|
| 31 | emitter->bufsize = 10; |
|---|
| 32 | emitter->output_handler = TestSyckEmit_Output; |
|---|
| 33 | |
|---|
| 34 | syck_emitter_write( emitter, "Test [1]", 8 ); |
|---|
| 35 | syck_emitter_write( emitter, ".", 1 ); |
|---|
| 36 | syck_emitter_write( emitter, "Test [2]", 8 ); |
|---|
| 37 | syck_emitter_write( emitter, ".", 1 ); |
|---|
| 38 | syck_emitter_write( emitter, "Test [3]", 8 ); |
|---|
| 39 | syck_emitter_write( emitter, ".", 1 ); |
|---|
| 40 | syck_emitter_write( emitter, "Test [4]", 8 ); |
|---|
| 41 | syck_emitter_write( emitter, ".", 1 ); |
|---|
| 42 | syck_emitter_write( emitter, "END!", 4 ); |
|---|
| 43 | |
|---|
| 44 | syck_free_emitter( emitter ); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | /* |
|---|
| 48 | * Ensure that our base64 encoder can do some basic |
|---|
| 49 | * binary encoding. |
|---|
| 50 | */ |
|---|
| 51 | void TestBase64Encode( CuTest *tc ) |
|---|
| 52 | { |
|---|
| 53 | char gif[] = "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236iiiccc\243\243\243\204\204\204\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371!\376\016Made with GIMP\000,\000\000\000\000\f\000\f\000\000\005, \216\2010\236\343@\024\350i\020\304\321\212\010\034\317\200M$z\357\3770\205p\270\2601f\r\033\316\001\303\001\036\020' \202\n\001\000;"; |
|---|
| 54 | char *enc = syck_base64enc( gif, 185 ); |
|---|
| 55 | CuAssertStrEquals( tc, enc, "R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=\n" ); |
|---|
| 56 | S_FREE( enc ); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | CuSuite * |
|---|
| 60 | SyckGetSuite() |
|---|
| 61 | { |
|---|
| 62 | CuSuite *suite = CuSuiteNew(); |
|---|
| 63 | SUITE_ADD_TEST( suite, TestSyckEmit ); |
|---|
| 64 | SUITE_ADD_TEST( suite, TestBase64Encode ); |
|---|
| 65 | return suite; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | int main(void) |
|---|
| 69 | { |
|---|
| 70 | CuString *output = CuStringNew(); |
|---|
| 71 | CuSuite* suite = SyckGetSuite(); |
|---|
| 72 | int count; |
|---|
| 73 | |
|---|
| 74 | CuSuiteRun(suite); |
|---|
| 75 | CuSuiteSummary(suite, output); |
|---|
| 76 | CuSuiteDetails(suite, output); |
|---|
| 77 | |
|---|
| 78 | printf("%s\n", output->buffer); |
|---|
| 79 | count = suite->failCount; |
|---|
| 80 | |
|---|
| 81 | CuStringFree( output ); |
|---|
| 82 | CuSuiteFree( suite ); |
|---|
| 83 | |
|---|
| 84 | return count; |
|---|
| 85 | } |
|---|