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 // -------------------------------------------------------------------------*/
11 #include "sjme/alloc.h"
12 #include "sjme/list.h"
16 /** We do not have a pointer to pointer type. */
17 SJME_LIST_DECLARE(sjme_jint
, 2);
20 static const sjme_jint testListElems
[5] = {1, 2, 3, 4, 5};
23 * Tests generic lists.
27 SJME_TEST_DECLARE(testList
)
29 sjme_list_sjme_jintPP
* ppList
;
30 sjme_list_sjme_jint
* varList
;
31 sjme_list_sjme_jint
* arrayList
;
32 sjme_alloc_link
* link
;
37 if (sjme_error_is(sjme_list_alloc(test
->pool
, 10, &ppList
,
38 sjme_jint
, 2)) || ppList
== NULL
)
39 sjme_unit_fail(test
, "Could not allocate list.");
41 /* Get the allocation link. */
43 if (sjme_error_is(sjme_alloc_getLink(ppList
, &link
)))
44 sjme_unit_fail(test
, "Could not obtain link.");
46 /* Was the size set? */
47 sjme_unit_equalI(test
, ppList
->length
, 10,
49 sjme_unit_equalI(test
, ppList
->elementSize
, sizeof(sjme_jint
**),
50 "Wrong element size?");
52 /* Check that the link is the correct size. */
53 sjme_unit_equalI(test
, link
->allocSize
,
54 SJME_SIZEOF_LIST(sjme_jint
, 2, 10),
55 "List allocation size incorrect?");
57 /* Test variadic load of list. */
59 if (sjme_error_is(sjme_list_newV(test
->pool
, sjme_jint
, 0, 5, &varList
,
62 sjme_unit_fail(test
, "Could not build variadic list?");
64 /* Test resultant list values. */
65 sjme_unit_equalI(test
, varList
->length
, 5,
67 sjme_unit_equalI(test
, varList
->elementSize
, sizeof(sjme_jint
),
68 "Element size invalid?");
69 for (i
= 0; i
< 5; i
++)
70 sjme_unit_equalI(test
, varList
->elements
[i
], i
+ 1,
71 "Variadic element %d not set correctly?", i
);
73 /* Test array load of list. */
75 if (sjme_error_is(sjme_list_newA(test
->pool
, sjme_jint
, 0, 5, &arrayList
,
76 testListElems
)) || arrayList
== NULL
)
77 sjme_unit_fail(test
, "Could not build array list?");
79 /* Test resultant list values. */
80 sjme_unit_equalI(test
, arrayList
->length
, 5,
82 sjme_unit_equalI(test
, arrayList
->elementSize
, sizeof(sjme_jint
),
83 "Element size invalid?");
84 for (i
= 0; i
< 5; i
++)
85 sjme_unit_equalI(test
, arrayList
->elements
[i
], i
+ 1,
86 "Array element %d not set correctly?", i
);
89 return SJME_TEST_RESULT_PASS
;