Compile fixes.
[SquirrelJME.git] / nanocoat / tests / testTraverseClear.c
blob9161e364197e6ac8173a1a2e5d9da9a0f46edb9c
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 <string.h>
12 #include "test.h"
13 #include "proto.h"
14 #include "mock.h"
15 #include "unit.h"
17 #include "sjme/traverse.h"
18 #include "testTraverse.h"
20 /**
21 * Tests clearing a traversal tree.
23 * @since 2024/09/02
25 SJME_TEST_DECLARE(testTraverseClear)
27 sjme_traverse_test_data traverse;
28 test_data value;
30 /* Setup traverse. */
31 traverse = NULL;
32 if (sjme_error_is(test->error = sjme_traverse_new(test->pool,
33 &traverse, MAX_ELEMENTS, test_data, 0)) || traverse == NULL)
34 return sjme_unit_fail(test, "Could not create traverse?");
36 /* Store first value. */
37 memset(&value, 0, sizeof(value));
38 value.a = 1;
39 value.b = 10;
40 if (sjme_error_is(test->error = sjme_traverse_put(traverse,
41 &value, 0, 1, test_data, 0)))
42 return sjme_unit_fail(test, "Could not put in first value?");
44 /* Store second value. */
45 memset(&value, 0, sizeof(value));
46 value.a = 2;
47 value.b = 20;
48 if (sjme_error_is(test->error = sjme_traverse_put(traverse,
49 &value, 1, 1, test_data, 0)))
50 return sjme_unit_fail(test, "Could not put in second value?");
52 /* Clear it. */
53 if (sjme_error_is(test->error = sjme_traverse_clear(
54 SJME_AS_TRAVERSE(traverse))))
55 return sjme_unit_fail(test, "Could not clear traversal tree?");
57 /* There should be no root node. */
58 sjme_unit_equalP(test, NULL, traverse->root,
59 "There was a root node on a cleared tree?");
61 /* There should be storage, however. */
62 sjme_unit_notEqualP(test, NULL, traverse->storage,
63 "Storage is missing?");
64 sjme_unit_equalP(test, traverse->start, traverse->next,
65 "Next storage node not at start?");
67 /* Destroy traverse. */
68 if (sjme_error_is(test->error = sjme_traverse_destroy(
69 SJME_AS_TRAVERSE(traverse))))
70 return sjme_unit_fail(test, "Could not destroy traverse?");
72 /* Success! */
73 return SJME_TEST_RESULT_PASS;