13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Memory Pool Library 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * -------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Memory pool set class. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "dePoolSet.h" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string.h> 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 283c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_DECLARE_POOL_SET(deTestSet, deInt16); 293c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDE_IMPLEMENT_POOL_SET(deTestSet, deInt16, deInt16Hash, deInt16Equal); 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid dePoolSet_selfTest (void) 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deMemPool* pool = deMemPool_createRoot(DE_NULL, 0); 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deTestSet* set = deTestSet_create(pool); 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int i; 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry /* Test exists() on empty set. */ 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(deTestSet_getNumElements(set) == 0); 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (i = 0; i < 15000; i++) 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(!deTestSet_exists(set, (deInt16)i)); 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry /* Test insert(). */ 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (i = 0; i < 5000; i++) 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deTestSet_insert(set, (deInt16)i); 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(deTestSet_getNumElements(set) == 5000); 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (i = 0; i < 25000; i++) 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deBool inserted = deInBounds32(i, 0, 5000); 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deBool found = deTestSet_exists(set, (deInt16)i); 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(found == inserted); 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry /* Test delete(). */ 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (i = 0; i < 1000; i++) 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deTestSet_delete(set, (deInt16)i); 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(deTestSet_getNumElements(set) == 4000); 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (i = 0; i < 25000; i++) 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deBool inserted = deInBounds32(i, 1000, 5000); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deBool found = deTestSet_exists(set, (deInt16)i); 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(found == inserted); 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry /* Test insert() after delete(). */ 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (i = 10000; i < 12000; i++) 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deTestSet_insert(set, (deInt16)i); 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(deTestSet_getNumElements(set) == 6000); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (i = 0; i < 25000; i++) 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deBool inserted = (deInBounds32(i, 1000, 5000) || deInBounds32(i, 10000, 12000)); 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deBool found = deTestSet_exists(set, (deInt16)i); 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(found == inserted); 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry /* Test iterator. */ 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deTestSetIter iter; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numFound = 0; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (deTestSetIter_init(set, &iter); deTestSetIter_hasItem(&iter); deTestSetIter_next(&iter)) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deInt16 key = deTestSetIter_getKey(&iter); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(deInBounds32(key, 1000, 5000) || deInBounds32(key, 10000, 12000)); 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(deTestSet_exists(set, key)); 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry numFound++; 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_TEST_ASSERT(numFound == deTestSet_getNumElements(set)); 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deMemPool_destroy(pool); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 97