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 testData
[NUM_BYTES
] =
23 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
28 * Tests that streams work.
32 SJME_TEST_DECLARE(testStream
)
34 sjme_stream_input inputStream
;
35 sjme_jint readCount
, cycles
;
36 sjme_jubyte buf
[READ_BUF
];
39 /* Setup input stream. */
41 if (SJME_IS_ERROR(sjme_stream_inputOpenMemory(test
->pool
,
42 &inputStream
, testData
, NUM_BYTES
)) ||
44 return sjme_unitFail(test
, "Could not open input stream.");
48 for (cycles
= 0;; cycles
++)
50 /* Clear read buffer. */
51 memset(buf
, 0, sizeof(buf
));
53 /* Read in more data. */
55 if (SJME_IS_ERROR(sjme_stream_inputRead(inputStream
,
56 &readCount
, buf
, READ_BUF
)))
57 sjme_unitFail(test
, "Failed read?");
63 /* Should have read said bytes. */
64 sjme_unitEqualI(test
, READ_BUF
, readCount
,
65 "Did not read correct number of bytes?");
67 /* Values in buffer should match. */
68 for (i
= 0; i
< READ_BUF
; i
++)
69 sjme_unitEqualI(test
, valAt
++, buf
[i
],
70 "Incorrectly read value?");
73 /* There should have been this many cycles. */
74 sjme_unitEqualI(test
, cycles
, NUM_BYTES
/ READ_BUF
,
75 "Incorrect number of read cycles?");
78 return SJME_TEST_RESULT_PASS
;