1e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
2e5c31af7Sopenharmony_ci * drawElements Memory Pool Library
3e5c31af7Sopenharmony_ci * --------------------------------
4e5c31af7Sopenharmony_ci *
5e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
10e5c31af7Sopenharmony_ci *
11e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
17e5c31af7Sopenharmony_ci * limitations under the License.
18e5c31af7Sopenharmony_ci *
19e5c31af7Sopenharmony_ci *//*!
20e5c31af7Sopenharmony_ci * \file
21e5c31af7Sopenharmony_ci * \brief Memory pool hash-array class.
22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/
23e5c31af7Sopenharmony_ci
24e5c31af7Sopenharmony_ci#include "dePoolHashArray.h"
25e5c31af7Sopenharmony_ci
26e5c31af7Sopenharmony_ci#include <string.h>
27e5c31af7Sopenharmony_ci
28e5c31af7Sopenharmony_ciDE_DECLARE_POOL_HASH_ARRAY(deTestHashArray, deInt16, int, deInt16Array, deIntArray);
29e5c31af7Sopenharmony_ciDE_IMPLEMENT_POOL_HASH_ARRAY(deTestHashArray, deInt16, int, deInt16Array, deIntArray, deInt16Hash, deInt16Equal);
30e5c31af7Sopenharmony_ci
31e5c31af7Sopenharmony_civoid dePoolHashArray_selfTest (void)
32e5c31af7Sopenharmony_ci{
33e5c31af7Sopenharmony_ci	deMemPool*			pool		= deMemPool_createRoot(DE_NULL, 0);
34e5c31af7Sopenharmony_ci	deTestHashArray*	hashArray	= deTestHashArray_create(pool);
35e5c31af7Sopenharmony_ci	deInt16Array*		keyArray	= deInt16Array_create(pool);
36e5c31af7Sopenharmony_ci	deIntArray*			valueArray	= deIntArray_create(pool);
37e5c31af7Sopenharmony_ci	int					iter;
38e5c31af7Sopenharmony_ci
39e5c31af7Sopenharmony_ci	for (iter = 0; iter < 3; iter++)
40e5c31af7Sopenharmony_ci	{
41e5c31af7Sopenharmony_ci		int i;
42e5c31af7Sopenharmony_ci
43e5c31af7Sopenharmony_ci		/* Insert a bunch of values. */
44e5c31af7Sopenharmony_ci		DE_TEST_ASSERT(deTestHashArray_getNumElements(hashArray) == 0);
45e5c31af7Sopenharmony_ci		for (i = 0; i < 20; i++)
46e5c31af7Sopenharmony_ci		{
47e5c31af7Sopenharmony_ci			deTestHashArray_insert(hashArray, (deInt16)(-i^0x5), 2*i+5);
48e5c31af7Sopenharmony_ci		}
49e5c31af7Sopenharmony_ci		DE_TEST_ASSERT(deTestHashArray_getNumElements(hashArray) == 20);
50e5c31af7Sopenharmony_ci
51e5c31af7Sopenharmony_ci		deTestHashArray_copyToArray(hashArray, keyArray, DE_NULL);
52e5c31af7Sopenharmony_ci		deTestHashArray_copyToArray(hashArray, DE_NULL, valueArray);
53e5c31af7Sopenharmony_ci		DE_TEST_ASSERT(deInt16Array_getNumElements(keyArray) == 20);
54e5c31af7Sopenharmony_ci		DE_TEST_ASSERT(deIntArray_getNumElements(valueArray) == 20);
55e5c31af7Sopenharmony_ci
56e5c31af7Sopenharmony_ci		for (i = 0; i < 20; i++)
57e5c31af7Sopenharmony_ci		{
58e5c31af7Sopenharmony_ci			DE_TEST_ASSERT(deInt16Array_get(keyArray, i) == (deInt16)(-i^0x5));
59e5c31af7Sopenharmony_ci			DE_TEST_ASSERT(deIntArray_get(valueArray, i) == 2*i+5);
60e5c31af7Sopenharmony_ci		}
61e5c31af7Sopenharmony_ci
62e5c31af7Sopenharmony_ci		deTestHashArray_reset(hashArray);
63e5c31af7Sopenharmony_ci		DE_TEST_ASSERT(deTestHashArray_getNumElements(hashArray) == 0);
64e5c31af7Sopenharmony_ci
65e5c31af7Sopenharmony_ci		deTestHashArray_copyToArray(hashArray, keyArray, DE_NULL);
66e5c31af7Sopenharmony_ci		deTestHashArray_copyToArray(hashArray, DE_NULL, valueArray);
67e5c31af7Sopenharmony_ci
68e5c31af7Sopenharmony_ci		DE_TEST_ASSERT(deInt16Array_getNumElements(keyArray) == 0);
69e5c31af7Sopenharmony_ci		DE_TEST_ASSERT(deIntArray_getNumElements(valueArray) == 0);
70e5c31af7Sopenharmony_ci	}
71e5c31af7Sopenharmony_ci
72e5c31af7Sopenharmony_ci	deMemPool_destroy(pool);
73e5c31af7Sopenharmony_ci}
74