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 // -------------------------------------------------------------------------*/
21 static const sjme_jubyte testBytes
[NUM_BYTES
] =
23 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
24 12, 13, 14, 15, 16, 17,
28 * Tests reading more bytes than what is available.
32 SJME_TEST_DECLARE(testStreamOverRead
)
34 sjme_stream_input inputStream
;
37 sjme_jubyte buf
[READ_BYTES
];
40 if (sjme_error_is(sjme_stream_inputOpenMemory(test
->pool
,
41 &inputStream
, testBytes
, NUM_BYTES
)))
42 return sjme_unit_fail(test
, "Could not open input stream.");
44 /* Get available bytes. */
46 if (sjme_error_is(sjme_stream_inputAvailable(inputStream
,
47 &available
)) || available
< 0)
48 return sjme_unit_fail(test
, "Could not get available bytes?");
50 /* The number of available bytes should be the full size. */
51 sjme_unit_equalI(test
, available
, NUM_BYTES
,
52 "Available bytes incorrect?");
54 /* Read way too many bytes. */
55 memset(buf
, 0, sizeof(buf
));
57 if (sjme_error_is(sjme_stream_inputRead(inputStream
,
58 &readCount
, buf
, READ_BYTES
)))
59 return sjme_unit_fail(test
, "Failed to read bytes?");
61 /* Should be the bytes in the buffer, not the read attempt. */
62 sjme_unit_equalI(test
, readCount
, NUM_BYTES
,
63 "Read count incorrect?");
65 /* Test that the actual bytes are correct. */
66 sjme_unit_equalI(test
, 0, memcmp(buf
, testBytes
, readCount
),
67 "Read bytes are not correct?");
69 /* Close the stream. */
70 if (sjme_error_is(sjme_closeable_close(
71 SJME_AS_CLOSEABLE(inputStream
))))
72 return sjme_unit_fail(test
, "Could not close stream?");
75 return SJME_TEST_RESULT_PASS
;