Adjust sourcize.c to use _snprintf if using MSVC.
[SquirrelJME.git] / nanocoat / tests / testCloseable.c
blobf8ce841922b83d4ce499923042bde01335fe8f22
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 "test.h"
11 #include "proto.h"
12 #include "mock.h"
13 #include "unit.h"
14 #include "testCloseable.h"
16 sjme_errorCode testCloseable_new(
17 sjme_attrInNotNull sjme_alloc_pool* inPool,
18 sjme_attrOutNotNull sjme_closeable* outCloseable,
19 sjme_attrInNotNull sjme_closeable_closeHandlerFunc handlerFunc,
20 sjme_attrInValue sjme_jboolean isRefCounted)
22 sjme_errorCode error;
23 sjme_closeable result;
25 if (inPool == NULL || outCloseable == NULL || handlerFunc == NULL)
26 return SJME_ERROR_NULL_ARGUMENTS;
28 /* Allocate. */
29 result = NULL;
30 if (sjme_error_is(error = sjme_closeable_alloc(
31 inPool, sizeof(*result),
32 handlerFunc, isRefCounted,
33 &result)) || result == NULL)
34 return sjme_error_default(error);
36 /* Success! */
37 *outCloseable = result;
38 return SJME_ERROR_NONE;
41 static sjme_errorCode testHandler(
42 sjme_attrInNotNull sjme_closeable closeable)
44 return SJME_ERROR_NONE;
47 /**
48 * Generic closeable test.
50 * @since 2024/09/28
52 SJME_TEST_DECLARE(testCloseable)
54 sjme_closeable closing;
56 /* Make closeable. */
57 if (sjme_error_is(test->error = testCloseable_new(test->pool,
58 &closing, testHandler,
59 SJME_JNI_FALSE)))
60 return sjme_unit_fail(test, "Could not make closeable?");
62 /* Success! */
63 return SJME_TEST_RESULT_PASS;