Compile fixes.
[SquirrelJME.git] / nanocoat / tests / testAllocWeakRefRef.c
blob729f8076360f8eccefd71991868149ca78caa5ef
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"
15 /**
16 * Tests counting up a weak reference.
18 * @since 2024/07/08
20 SJME_TEST_DECLARE(testAllocWeakRefRef)
22 sjme_alloc_weak weak;
23 sjme_alloc_weak weakB;
24 void* p;
26 /* Allocate weak reference. */
27 p = NULL;
28 weak = NULL;
29 if (sjme_error_is(sjme_alloc_weakNew(test->pool, 512,
30 NULL, NULL, &p, &weak)))
31 return sjme_unit_fail(test, "Failed to allocate weak?");
33 /* Reference count should be one. */
34 sjme_unit_equalI(test, sjme_atomic_sjme_jint_get(&weak->count), 1,
35 "Reference count not one?");
37 /* Reference again. */
38 weakB = NULL;
39 if (sjme_error_is(sjme_alloc_weakRefE(p, &weakB,
40 NULL, NULL)))
41 return sjme_unit_fail(test, "Could not re-ref weak?");
43 /* These should be the same weak reference. */
44 sjme_unit_equalP(test, weak, weakB,
45 "Weak references not the same?");
47 /* Reference count should be two. */
48 sjme_unit_equalI(test, sjme_atomic_sjme_jint_get(&weak->count), 2,
49 "Reference count not two?");
51 /* Success! */
52 return SJME_TEST_RESULT_PASS;