1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
16 #include "sjme/stream.h"
22 #define TOTAL_BYTES (CHUNK_SIZE * NUM_CHUNKS)
24 static sjme_errorCode
finishStreamWriteBlockBA(
25 sjme_attrInNotNull sjme_stream_output stream
,
26 sjme_attrInNotNull sjme_stream_resultByteArray
* result
,
27 sjme_attrInNullable sjme_pointer data
)
33 test
= (sjme_test
*)result
->whatever
;
35 sjme_unit_equalP(test
, data
, test
,
36 "Test data was not passed?");
38 /* Each chunk should match! */
39 for (i
= 0; i
< NUM_CHUNKS
; i
++)
40 sjme_unit_equalI(test
,
41 0, memcmp(test
->global
, &result
->array
[(CHUNK_SIZE
* i
)],
43 "Chunk %d did not match?", i
);
46 return SJME_ERROR_NONE
;
50 * Tests writing to a block of memory.
54 SJME_TEST_DECLARE(testStreamWriteBlockBA
)
56 sjme_stream_output stream
;
58 sjme_jubyte chunk
[CHUNK_SIZE
];
63 /* Initialize input chunk data. */
64 for (i
= 0; i
< CHUNK_SIZE
; i
++)
69 if (sjme_error_is(sjme_stream_outputOpenByteArray(test
->pool
,
70 &stream
, 2, finishStreamWriteBlockBA
,
71 test
)) || stream
== NULL
)
72 return sjme_unit_fail(test
, "Could not open output stream.");
74 /* Write the buffer sequence for each chunk. */
75 for (i
= 0; i
< NUM_CHUNKS
; i
++)
76 if (sjme_error_is(sjme_stream_outputWrite(stream
,
77 &chunk
, sizeof(chunk
))))
78 return sjme_unit_fail(test
, "Could not write chunk %d?", i
);
81 if (sjme_error_is(sjme_closeable_close(
82 SJME_AS_CLOSEABLE(stream
))))
83 return sjme_unit_fail(test
, "Could not close output stream.");
86 return SJME_TEST_RESULT_PASS
;