Compile fixes.
[SquirrelJME.git] / nanocoat / tests / testStreamWriteSingle.c
blob2e122c9bfbe1ebaad7d6492373460ae479de6fc0
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 <string.h>
12 #include "mock.h"
13 #include "proto.h"
14 #include "test.h"
15 #include "unit.h"
16 #include "sjme/stream.h"
18 /**
19 * Tests writing a single byte to the output.
21 * @since 2024/01/09
23 SJME_TEST_DECLARE(testStreamWriteSingle)
25 sjme_stream_output stream;
26 sjme_jubyte value;
28 /* Clear output first. */
29 memset(&value, 0, sizeof(value));
31 /* Setup output stream. */
32 stream = NULL;
33 if (sjme_error_is(sjme_stream_outputOpenMemory(test->pool,
34 &stream, &value, 1)) || stream == NULL)
35 return sjme_unit_fail(test, "Could not open output stream.");
37 /* Write single value. */
38 if (sjme_error_is(sjme_stream_outputWriteSingle(stream,
39 123)))
40 return sjme_unit_fail(test, "Could not write output value.");
42 /* The write count should be the buffer size. */
43 sjme_unit_equalI(test,
44 1, stream->totalWritten,
45 "Number of written bytes incorrect?");
47 /* Was this value written? */
48 sjme_unit_equalI(test, 123, value,
49 "Value was not written?");
51 /* Close stream. */
52 if (sjme_error_is(sjme_closeable_close(
53 SJME_AS_CLOSEABLE(stream))))
54 return sjme_unit_fail(test, "Could not close output stream.");
56 /* Success! */
57 return SJME_TEST_RESULT_PASS;