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 general creation of a weak reference.
20 SJME_TEST_DECLARE(testAllocWeakRef
)
23 sjme_alloc_weak weakSecond
;
24 sjme_alloc_link
* link
;
27 /* Allocate weak reference. */
30 if (sjme_error_is(sjme_alloc_weakNew(test
->pool
, 512,
31 NULL
, NULL
, &p
, &weak
)))
32 return sjme_unit_fail(test
, "Failed to allocate weak?");
34 /* These should be set. */
35 sjme_unit_notEqualP(test
, p
, NULL
,
37 sjme_unit_notEqualP(test
, weak
, NULL
,
40 /* This should be marked valid. */
41 sjme_unit_equalI(test
,
42 sjme_atomic_sjme_jint_get(&weak
->valid
), SJME_ALLOC_WEAK_VALID
,
43 "Weak reference not marked valid?");
45 /* Get the block link. */
47 if (sjme_error_is(sjme_alloc_getLink(p
, &link
)))
48 return sjme_unit_fail(test
, "Could not get block link?");
50 /* Should be this pointer. */
51 sjme_unit_equalP(test
, weak
->pointer
, p
,
52 "Weak pointer not allocated pointer?");
53 sjme_unit_equalP(test
, weak
->link
, link
,
54 "Weak pointer not allocated link?");
55 sjme_unit_equalP(test
, link
->weak
, weak
,
56 "Link weak not allocated weak?");
58 /* These should not be set. */
59 sjme_unit_equalP(test
, weak
->enqueue
, NULL
,
61 sjme_unit_equalP(test
, weak
->enqueueData
, NULL
,
62 "Enqueue data was set?");
64 /* Reference count should be zero. */
65 sjme_unit_equalI(test
, sjme_atomic_sjme_jint_get(&weak
->count
), 0,
66 "Reference count not one?");
70 if (sjme_error_is(sjme_alloc_weakRef(p
, &weakSecond
)))
71 return sjme_unit_fail(test
, "Could not weak ref count up?");
73 /* Weak reference should be returned. */
74 sjme_unit_equalP(test
, weak
, weakSecond
,
75 "Different or un-passed weak pointer?");
77 /* Reference count should be one. */
78 sjme_unit_equalI(test
, sjme_atomic_sjme_jint_get(&weak
->count
), 1,
79 "Reference count not one?");
82 return SJME_TEST_RESULT_PASS
;