Make all NanoCoat types closeable; Make unrefing closeable the default.
[SquirrelJME.git] / nanocoat / tests / testStreamEmpty.c
blob57d02415318a802e943124d7696028501b2dbed4
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
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 // -------------------------------------------------------------------------*/
10 #include "mock.h"
11 #include "proto.h"
12 #include "test.h"
13 #include "unit.h"
15 /** Empty buffer. */
16 static const sjme_jubyte emptyBuffer[1] =
18 'x'
21 /**
22 * Tests reading of an empty stream.
24 * @since 2023/12/31
26 SJME_TEST_DECLARE(testStreamEmpty)
28 sjme_stream_input inputStream;
29 sjme_jint result;
31 /* Open stream. */
32 if (sjme_error_is(sjme_stream_inputOpenMemory(test->pool,
33 &inputStream, emptyBuffer, 0)))
34 return sjme_unit_fail(test, "Could not open input stream.");
36 /* Try to read a single byte, it should indicate EOS. */
37 result = 999;
38 if (sjme_error_is(sjme_stream_inputReadSingle(inputStream,
39 &result)))
40 return sjme_unit_fail(test, "Could not read single byte.");
42 /* Should be EOF. */
43 sjme_unit_equalI(test, -1, result,
44 "Incorrect read byte?");
46 /* Close the stream. */
47 if (sjme_error_is(sjme_closeable_close(
48 SJME_AS_CLOSEABLE(inputStream))))
49 return sjme_unit_fail(test, "Could not close stream?");
51 /* Success! */
52 return SJME_TEST_RESULT_PASS;