ReactOS 0.4.15-dev-7998-gdb93cb1
config_test.cpp
Go to the documentation of this file.
1#include <new>
2#include <vector>
3
5
6#if defined (_STLP_USE_NAMESPACES)
7using namespace std;
8#endif
9
10//
11// TestCase class
12//
13class ConfigTest : public CPPUNIT_NS::TestCase
14{
16#if !defined (STLPORT)
18#endif
22#if !defined (_STLP_USE_EXCEPTIONS)
24#endif
27
28 protected:
29 void placement_new_bug();
30 void endianess();
33};
34
36
38{
39#if defined (STLPORT)
40 int int_val = 1;
41 int *pint;
42 pint = new(&int_val) int();
43 CPPUNIT_ASSERT( pint == &int_val );
44# if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
45 CPPUNIT_ASSERT( int_val != 0 );
46# else
47 CPPUNIT_ASSERT( int_val == 0 );
48# endif
49#endif
50}
51
53{
54#if defined (STLPORT)
55 int val = 0x01020304;
56 char *ptr = (char*)(&val);
57# if defined (_STLP_BIG_ENDIAN)
58 //This test only work if sizeof(int) == 4, this is a known limitation
59 //that will be handle the day we find a compiler for which it is false.
60 CPPUNIT_ASSERT( *ptr == 0x01 ||
61 sizeof(int) > 4 && *ptr == 0x00 );
62# elif defined (_STLP_LITTLE_ENDIAN)
63 CPPUNIT_ASSERT( *ptr == 0x04 );
64# endif
65#endif
66}
67
69{
70#if defined (STLPORT)
71 vector<int> vect1(10, 0);
72 int* pvect1Front = &vect1.front();
73 vector<int> vect2(10, 0);
74 int* pvect2Front = &vect2.front();
75
76 swap(vect1, vect2);
77
78# if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
79 CPPUNIT_ASSERT( pvect1Front == &vect2.front() );
80 CPPUNIT_ASSERT( pvect2Front == &vect1.front() );
81# else
82 CPPUNIT_ASSERT( pvect1Front != &vect2.front() );
83 CPPUNIT_ASSERT( pvect2Front != &vect1.front() );
84# endif
85#endif
86}
87
89{
90#if defined (STLPORT) && defined (_STLP_USE_EXCEPTIONS)
91 try
92 {
93 /* We try to exhaust heap memory. However, we don't actually use the
94 largest possible size_t value bus slightly less in order to avoid
95 triggering any overflows due to the allocator adding some more for
96 its internal data structures. */
97 size_t const huge_amount = size_t(-1) - 1024;
98 void* pvoid = operator new (huge_amount);
99#if !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
100 // Allocation should have fail
101 CPPUNIT_ASSERT( pvoid != 0 );
102#endif
103 // Just in case it succeeds:
104 operator delete(pvoid);
105 }
106 catch (const bad_alloc&)
107 {
108#if defined (_STLP_NEW_DONT_THROW_BAD_ALLOC)
109 // Looks like your compiler new operator finally throw bad_alloc, you can fix
110 // configuration.
112#endif
113 }
114 catch (...)
115 {
116 //We shouldn't be there:
117 //Not bad_alloc exception thrown.
119 }
120#endif
121}
CPPUNIT_TEST(placement_new_bug)
CPPUNIT_TEST_SUITE_END()
void placement_new_bug()
Definition: config_test.cpp:37
void template_function_partial_ordering()
Definition: config_test.cpp:68
CPPUNIT_TEST(template_function_partial_ordering)
void endianess()
Definition: config_test.cpp:52
void new_throw_bad_alloc()
Definition: config_test.cpp:88
CPPUNIT_TEST(endianess)
CPPUNIT_TEST_SUITE(ConfigTest)
CPPUNIT_TEST(new_throw_bad_alloc)
#define CPPUNIT_FAIL
Definition: cppunit_mini.h:206
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
__kernel_size_t size_t
Definition: linux.h:237
GLuint GLfloat * val
Definition: glext.h:7180
static PVOID ptr
Definition: dispmode.c:27
Definition: features.h:417
#define swap(a, b)
Definition: qsort.c:63
reference front()
Definition: _vector.h:205