Collect all of the various spread out 3rd party licenses to a single file.
[SquirrelJME.git] / nanocoat / tests / testList.c
blob5afeb57d5902341ea1f0e4cda8bbc7422f1b4979
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 "proto.h"
11 #include "sjme/alloc.h"
12 #include "sjme/list.h"
13 #include "test.h"
14 #include "unit.h"
16 /** We do not have a pointer to pointer type. */
17 SJME_LIST_DECLARE(sjme_jint, 2);
19 /** List elements. */
20 static const sjme_jint testListElems[5] = {1, 2, 3, 4, 5};
22 /**
23 * Tests generic lists.
25 * @since 2023/12/17
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;
33 sjme_jint i;
35 /* Allocate list. */
36 ppList = NULL;
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. */
42 link = NULL;
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,
48 "List wrong size?");
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. */
58 varList = NULL;
59 if (sjme_error_is(sjme_list_newV(test->pool, sjme_jint, 0, 5, &varList,
60 1, 2, 3, 4, 5)) ||
61 varList == NULL)
62 sjme_unit_fail(test, "Could not build variadic list?");
64 /* Test resultant list values. */
65 sjme_unit_equalI(test, varList->length, 5,
66 "Length invalid?");
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. */
74 arrayList = NULL;
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,
81 "Length invalid?");
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);
88 /* Success! */
89 return SJME_TEST_RESULT_PASS;