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 // -------------------------------------------------------------------------*/
16 * Tests counting up a weak reference.
20 SJME_TEST_DECLARE(testAllocWeakRefRef
)
23 sjme_alloc_weak weakB
;
26 /* Allocate weak reference. */
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. */
39 if (sjme_error_is(sjme_alloc_weakRefE(p
, &weakB
,
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?");
52 return SJME_TEST_RESULT_PASS
;