|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <new> |
|
18 #include <vector> |
|
19 |
|
20 #include "cppunit/cppunit_proxy.h" |
|
21 |
|
22 #if defined (_STLP_USE_NAMESPACES) |
|
23 using namespace std; |
|
24 #endif |
|
25 |
|
26 // |
|
27 // TestCase class |
|
28 // |
|
29 class ConfigTest : public CPPUNIT_NS::TestCase |
|
30 { |
|
31 CPPUNIT_TEST_SUITE(ConfigTest); |
|
32 #if !defined (STLPORT) |
|
33 CPPUNIT_IGNORE; |
|
34 #endif |
|
35 CPPUNIT_TEST(placement_new_bug); |
|
36 CPPUNIT_TEST(endianess); |
|
37 CPPUNIT_TEST(template_function_partial_ordering); |
|
38 CPPUNIT_TEST_SUITE_END(); |
|
39 |
|
40 protected: |
|
41 void placement_new_bug(); |
|
42 void endianess(); |
|
43 void template_function_partial_ordering(); |
|
44 }; |
|
45 |
|
46 CPPUNIT_TEST_SUITE_REGISTRATION(ConfigTest); |
|
47 |
|
48 void ConfigTest::placement_new_bug() |
|
49 { |
|
50 #if defined (STLPORT) |
|
51 int int_val = 1; |
|
52 int *pint; |
|
53 pint = new(&int_val) int(); |
|
54 CPPUNIT_ASSERT( pint == &int_val ); |
|
55 # if defined (_STLP_DEF_CONST_PLCT_NEW_BUG) |
|
56 CPPUNIT_ASSERT( int_val != 0 ); |
|
57 # else |
|
58 CPPUNIT_ASSERT( int_val == 0 ); |
|
59 # endif |
|
60 #endif |
|
61 } |
|
62 |
|
63 void ConfigTest::endianess() |
|
64 { |
|
65 #if defined (STLPORT) |
|
66 int val = 0x01020304; |
|
67 char *ptr = (char*)(&val); |
|
68 # if defined (_STLP_BIG_ENDIAN) |
|
69 //This test only work if sizeof(int) == 4, this is a known limitation |
|
70 //that will be handle the day we find a compiler for which it is false. |
|
71 CPPUNIT_ASSERT( *ptr == 0x01 || |
|
72 sizeof(int) > 4 && *ptr == 0x00 ); |
|
73 # elif defined (_STLP_LITTLE_ENDIAN) |
|
74 CPPUNIT_ASSERT( *ptr == 0x04 ); |
|
75 # endif |
|
76 #endif |
|
77 } |
|
78 |
|
79 void ConfigTest::template_function_partial_ordering() |
|
80 { |
|
81 #if defined (STLPORT) |
|
82 vector<int> vect1(10, 0); |
|
83 int* pvect1Front = &vect1.front(); |
|
84 vector<int> vect2(10, 0); |
|
85 int* pvect2Front = &vect2.front(); |
|
86 |
|
87 swap(vect1, vect2); |
|
88 |
|
89 # if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) |
|
90 CPPUNIT_ASSERT( pvect1Front == &vect2.front() ); |
|
91 CPPUNIT_ASSERT( pvect2Front == &vect1.front() ); |
|
92 # else |
|
93 CPPUNIT_ASSERT( pvect1Front != &vect2.front() ); |
|
94 CPPUNIT_ASSERT( pvect2Front != &vect1.front() ); |
|
95 # endif |
|
96 #endif |
|
97 } |