// main.cpp // // Copyright (c) 2003 Philip Romanik, Amy Muntz // // Permission to use, copy, modify, distribute, and sell this software and // its documentation for any purpose is hereby granted without fee, provided // that (i) the above copyright notices and this permission notice appear in // all copies of the software and related documentation, and (ii) the names // of Philip Romanik and Amy Muntz may not be used in any advertising or // publicity relating to the software without the specific, prior written // permission of Philip Romanik and Amy Muntz. // // Use of this software and/or its documentation will be deemed to be // acceptance of these terms. // // THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, // EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY // WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. // // IN NO EVENT SHALL PHILIP ROMANIK OR AMY MUNTZ BE LIABLE FOR // ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, // OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, // WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF // LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE // OF THIS SOFTWARE. // // // Unit Test for apAlloc<> template class. #include "allocTmpl.h" #include "unitTest.h" // Ruler // 1 2 3 4 5 6 6 //345678901234567890123456789012345678901234567890123456789012345 UTFUNC(null) { setDescription ("Null alloc"); apAlloc data; VERIFY (data.size() == 0); VERIFY (data.data() == apAlloc::gNull().data()); VERIFY (data.isNull()); apAlloc data2 (2); VERIFY (!data2.isNull()); } UTFUNC(simple) { setDescription ("Simple test of accessors"); int i; apAlloc data (10); VERIFY (data.size() == 10); VERIFY (data.ref() == 1); const apAlloc data2 = data; for (i=0; i data2 (10, 2); apAlloc data4 (10, 4); apAlloc data8 (10, 8); apAlloc data3 (10, 1024); VERIFY ((reinterpret_cast((const int*)data2.data()) & 1) == 0); VERIFY ((reinterpret_cast((const int*)data4.data()) & 3) == 0); VERIFY ((reinterpret_cast((const int*)data8.data()) & 7) == 0); VERIFY ((reinterpret_cast((const int*)data3.data()) & 1023) == 0); } UTFUNC(set1) { setDescription ("Set/get memory with []"); int i; apAlloc data (10); for (i=0; i data2 = data; for (i=0; i data (10); int* p1 = data.data(); for (i=0; i data2 = data; const int* p2 = data2.data (); for (i=0; i data (10); for (i=0; i data2 = data; VERIFY(data2.data() == data.data()); for (i=0; i data (10, true); for (i=0; i data2 = data; VERIFY (data.ref() == 2); VERIFY (data.data() == data2.data()); // Explicitly duplicate the data data2.duplicate (); VERIFY (data.ref() == 1); VERIFY (data2.ref() == 1); VERIFY (data.data() != data2.data()); VERIFY (p1 == data.data()); for (i=0; i image (1); for (i=0; i<1000; i++) { image = apAlloc (1024*1024); VERIFY (image.ref() == 1); } } UTFUNC(exception) { setDescription ("Exceptions"); int i; apAlloc data (10); // This should generate 2 exceptions int caught = 0; int sum = 0; int sz = data.size(); for (i=-1; i