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