1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef UNIT_TEST_COMMON_H 19 #define UNIT_TEST_COMMON_H 20 21 //Note: the Oscl includes must be minimal here, since we use 22 //this framework to test Oscl. 23 #include "osclconfig.h" 24 #include "oscl_types.h"//to get basic types 25 #include "osclconfig_memory.h" //to get placement "new" 26 27 /** A basic allocator that does not rely on other modules. 28 * 29 */ 30 class unit_test_allocator 31 { 32 public: allocate(const uint32 size)33 static OsclAny* allocate(const uint32 size) 34 { 35 return malloc(size); 36 } 37 deallocate(OsclAny * p)38 static void deallocate(OsclAny *p) 39 { 40 free(p); 41 } 42 }; 43 44 /** 45 * Using this as a base class will allow using new/delete with the 46 * basic allocator defined above. This is used to avoid invoking 47 * the Oscl global new/delete overload, which relies on Oscl memory manager. 48 */ 49 50 class UnitTest_HeapBase 51 { 52 public: 53 new(size_t aSize)54 static void* operator new(size_t aSize) 55 { 56 return unit_test_allocator::allocate(aSize); 57 } 58 59 static void* operator new[](size_t aSize) 60 { 61 return unit_test_allocator::allocate(aSize); 62 } 63 new(size_t,void * aPtr)64 static void* operator new(size_t , void* aPtr) 65 { 66 return aPtr; 67 } 68 delete(void * aPtr)69 static void operator delete(void* aPtr) 70 { 71 unit_test_allocator::deallocate(aPtr); 72 } 73 74 static void operator delete[](void* aPtr) 75 { 76 unit_test_allocator::deallocate(aPtr); 77 } 78 UnitTest_HeapBase()79 UnitTest_HeapBase() {} ~UnitTest_HeapBase()80 virtual ~UnitTest_HeapBase() {} 81 82 83 }; 84 85 #include "unit_test_vector.h" 86 #include "unit_test_local_string.h" 87 88 #define _STRING UnitTest_String 89 #define _APPEND(string,value) string+=(value) 90 #define _VECTOR(var,allocator) UnitTest_Vector<var,allocator> 91 92 93 #endif //UNIT_TEST_COMMON_H 94 95