os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/config_test.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 #include <new>
     2 #include <vector>
     3 
     4 #include "cppunit/cppunit_proxy.h"
     5 
     6 #if defined (_STLP_USE_NAMESPACES)
     7 using namespace std;
     8 #endif
     9 
    10 //
    11 // TestCase class
    12 //
    13 class ConfigTest : public CPPUNIT_NS::TestCase
    14 {
    15   CPPUNIT_TEST_SUITE(ConfigTest);
    16 #if !defined (STLPORT)
    17   CPPUNIT_IGNORE;
    18 #endif
    19   CPPUNIT_TEST(placement_new_bug);
    20   CPPUNIT_TEST(endianess);
    21   CPPUNIT_TEST(template_function_partial_ordering);
    22   CPPUNIT_TEST_SUITE_END();
    23 
    24   protected:
    25     void placement_new_bug();
    26     void endianess();
    27     void template_function_partial_ordering();
    28 };
    29 
    30 CPPUNIT_TEST_SUITE_REGISTRATION(ConfigTest);
    31 
    32 void ConfigTest::placement_new_bug()
    33 {
    34 #if defined (STLPORT)
    35   int int_val = 1;
    36   int *pint;
    37   pint = new(&int_val) int();
    38   CPPUNIT_ASSERT( pint == &int_val );
    39 #  if defined (_STLP_DEF_CONST_PLCT_NEW_BUG)
    40   CPPUNIT_ASSERT( int_val != 0 );
    41 #  else
    42   CPPUNIT_ASSERT( int_val == 0 );
    43 #  endif
    44 #endif
    45 }
    46 
    47 void ConfigTest::endianess()
    48 {
    49 #if defined (STLPORT)
    50   int val = 0x01020304;
    51   char *ptr = (char*)(&val);
    52 #  if defined (_STLP_BIG_ENDIAN)
    53   //This test only work if sizeof(int) == 4, this is a known limitation
    54   //that will be handle the day we find a compiler for which it is false.
    55   CPPUNIT_ASSERT( *ptr == 0x01 ||
    56                   sizeof(int) > 4 && *ptr == 0x00 );
    57 #  elif defined (_STLP_LITTLE_ENDIAN)
    58   CPPUNIT_ASSERT( *ptr == 0x04 );
    59 #  endif
    60 #endif
    61 }
    62 
    63 void ConfigTest::template_function_partial_ordering()
    64 {
    65 #if defined (STLPORT)
    66   vector<int> vect1(10, 0);
    67   int* pvect1Front = &vect1.front();
    68   vector<int> vect2(10, 0);
    69   int* pvect2Front = &vect2.front();
    70 
    71   swap(vect1, vect2);
    72 
    73 #  if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
    74   CPPUNIT_ASSERT( pvect1Front == &vect2.front() );
    75   CPPUNIT_ASSERT( pvect2Front == &vect1.front() );
    76 #  else
    77   CPPUNIT_ASSERT( pvect1Front != &vect2.front() );
    78   CPPUNIT_ASSERT( pvect2Front != &vect1.front() );
    79 #  endif
    80 #endif
    81 }