Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenconfig_test.cpp
Go to the documentation of this file.
00001 #include <new> 00002 #include <vector> 00003 00004 #include "cppunit/cppunit_proxy.h" 00005 00006 #if defined (_STLP_USE_NAMESPACES) 00007 using namespace std; 00008 #endif 00009 00010 // 00011 // TestCase class 00012 // 00013 class ConfigTest : public CPPUNIT_NS::TestCase 00014 { 00015 CPPUNIT_TEST_SUITE(ConfigTest); 00016 #if !defined (STLPORT) 00017 CPPUNIT_IGNORE; 00018 #endif 00019 CPPUNIT_TEST(placement_new_bug); 00020 CPPUNIT_TEST(endianess); 00021 CPPUNIT_TEST(template_function_partial_ordering); 00022 #if !defined (_STLP_USE_EXCEPTIONS) 00023 CPPUNIT_IGNORE; 00024 #endif 00025 CPPUNIT_TEST(new_throw_bad_alloc); 00026 CPPUNIT_TEST_SUITE_END(); 00027 00028 protected: 00029 void placement_new_bug(); 00030 void endianess(); 00031 void template_function_partial_ordering(); 00032 void new_throw_bad_alloc(); 00033 }; 00034 00035 CPPUNIT_TEST_SUITE_REGISTRATION(ConfigTest); 00036 00037 void ConfigTest::placement_new_bug() 00038 { 00039 #if defined (STLPORT) 00040 int int_val = 1; 00041 int *pint; 00042 pint = new(&int_val) int(); 00043 CPPUNIT_ASSERT( pint == &int_val ); 00044 # if defined (_STLP_DEF_CONST_PLCT_NEW_BUG) 00045 CPPUNIT_ASSERT( int_val != 0 ); 00046 # else 00047 CPPUNIT_ASSERT( int_val == 0 ); 00048 # endif 00049 #endif 00050 } 00051 00052 void ConfigTest::endianess() 00053 { 00054 #if defined (STLPORT) 00055 int val = 0x01020304; 00056 char *ptr = (char*)(&val); 00057 # if defined (_STLP_BIG_ENDIAN) 00058 //This test only work if sizeof(int) == 4, this is a known limitation 00059 //that will be handle the day we find a compiler for which it is false. 00060 CPPUNIT_ASSERT( *ptr == 0x01 || 00061 sizeof(int) > 4 && *ptr == 0x00 ); 00062 # elif defined (_STLP_LITTLE_ENDIAN) 00063 CPPUNIT_ASSERT( *ptr == 0x04 ); 00064 # endif 00065 #endif 00066 } 00067 00068 void ConfigTest::template_function_partial_ordering() 00069 { 00070 #if defined (STLPORT) 00071 vector<int> vect1(10, 0); 00072 int* pvect1Front = &vect1.front(); 00073 vector<int> vect2(10, 0); 00074 int* pvect2Front = &vect2.front(); 00075 00076 swap(vect1, vect2); 00077 00078 # if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) 00079 CPPUNIT_ASSERT( pvect1Front == &vect2.front() ); 00080 CPPUNIT_ASSERT( pvect2Front == &vect1.front() ); 00081 # else 00082 CPPUNIT_ASSERT( pvect1Front != &vect2.front() ); 00083 CPPUNIT_ASSERT( pvect2Front != &vect1.front() ); 00084 # endif 00085 #endif 00086 } 00087 00088 void ConfigTest::new_throw_bad_alloc() 00089 { 00090 #if defined (STLPORT) && defined (_STLP_USE_EXCEPTIONS) 00091 try 00092 { 00093 /* We try to exhaust heap memory. However, we don't actually use the 00094 largest possible size_t value bus slightly less in order to avoid 00095 triggering any overflows due to the allocator adding some more for 00096 its internal data structures. */ 00097 size_t const huge_amount = size_t(-1) - 1024; 00098 void* pvoid = operator new (huge_amount); 00099 #if !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC) 00100 // Allocation should have fail 00101 CPPUNIT_ASSERT( pvoid != 0 ); 00102 #endif 00103 // Just in case it succeeds: 00104 operator delete(pvoid); 00105 } 00106 catch (const bad_alloc&) 00107 { 00108 #if defined (_STLP_NEW_DONT_THROW_BAD_ALLOC) 00109 // Looks like your compiler new operator finally throw bad_alloc, you can fix 00110 // configuration. 00111 CPPUNIT_FAIL; 00112 #endif 00113 } 00114 catch (...) 00115 { 00116 //We shouldn't be there: 00117 //Not bad_alloc exception thrown. 00118 CPPUNIT_FAIL; 00119 } 00120 #endif 00121 } Generated on Fri May 25 2012 04:33:47 for ReactOS by
1.7.6.1
|