Compile fixes.
[SquirrelJME.git] / nanocoat / tests / testTraversePutLeafToNode.c
blob66c9f4f54f29466babb852e82499aa83c02f4c08
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 trying to put a node after a leaf.
23 * @since 2024/09/01
25 SJME_TEST_DECLARE(testTraversePutLeafToNode)
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 /* Put value at high enough depth. */
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, 3, 2, test_data, 0)))
42 return sjme_unit_fail(test, "Could not put in value?");
44 /* There should be a one facing node to a one facing leaf. */
45 sjme_unit_notEqualP(test, NULL, traverse->root->node.one,
46 "There is no one node?");
47 sjme_unit_notEqualP(test,
48 (void*)SJME_TRAVERSE_LEAF_KEY,
49 (void*)traverse->root->node.one->leaf.key,
50 "One facing is not a node?");
51 sjme_unit_equalP(test,
52 (void*)SJME_TRAVERSE_LEAF_KEY,
53 (void*)traverse->root->node.one->node.one->leaf.key,
54 "One+one facing is not a leaf?");
56 /* Put putting in a value higher up. */
57 memset(&value, 0, sizeof(value));
58 value.a = 2;
59 value.b = 20;
60 test->error = sjme_traverse_put(traverse,
61 &value, 1, 1, test_data, 0);
62 sjme_unit_equalI(test, test->error, SJME_ERROR_TREE_COLLISION,
63 "Adding entry did not indicate collision?");
65 /* Should be untouched. */
66 sjme_unit_notEqualP(test, NULL, traverse->root->node.one,
67 "There is no one node?");
68 sjme_unit_notEqualP(test,
69 (void*)SJME_TRAVERSE_LEAF_KEY,
70 (void*)traverse->root->node.one->leaf.key,
71 "One facing is not a node?");
72 sjme_unit_equalP(test,
73 (void*)SJME_TRAVERSE_LEAF_KEY,
74 (void*)traverse->root->node.one->node.one->leaf.key,
75 "One+one facing is not a leaf?");
77 /* Destroy traverse. */
78 if (sjme_error_is(test->error = sjme_traverse_destroy(
79 SJME_AS_TRAVERSE(traverse))))
80 return sjme_unit_fail(test, "Could not destroy traverse?");
82 /* Success! */
83 return SJME_TEST_RESULT_PASS;