os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_algobase.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_algobase.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,98 @@
     1.4 +/***********************************************************************************
     1.5 +  test_algobase.cpp
     1.6 +
     1.7 + * Copyright (c) 1997
     1.8 + * Mark of the Unicorn, Inc.
     1.9 + *
    1.10 + * Permission to use, copy, modify, distribute and sell this software
    1.11 + * and its documentation for any purpose is hereby granted without fee,
    1.12 + * provided that the above copyright notice appear in all copies and
    1.13 + * that both that copyright notice and this permission notice appear
    1.14 + * in supporting documentation.  Mark of the Unicorn makes no
    1.15 + * representations about the suitability of this software for any
    1.16 + * purpose.  It is provided "as is" without express or implied warranty.
    1.17 +
    1.18 +***********************************************************************************/
    1.19 +
    1.20 +# include "Prefix.h"
    1.21 +# if defined (EH_NEW_HEADERS)
    1.22 +# ifdef __SUNPRO_CC
    1.23 +# include <stdio.h>
    1.24 +# endif
    1.25 +#include <algorithm>
    1.26 +# else
    1.27 +#include <algo.h>
    1.28 +# endif
    1.29 +#include "Tests.h"
    1.30 +#include "LeakCheck.h"
    1.31 +#include "TestClass.h"
    1.32 +
    1.33 +// EH_USE_STD
    1.34 +
    1.35 +enum { kBufferSize = 100 };
    1.36 +
    1.37 +struct test_uninitialized_copy
    1.38 +{
    1.39 +    test_uninitialized_copy()
    1.40 +        : stuff( new TestClass[kBufferSize] ), end_of_stuff(stuff + kBufferSize) {
    1.41 +        gTestController.SetCurrentTestName("uninitialized_copy()");
    1.42 +        }
    1.43 +
    1.44 +    ~test_uninitialized_copy() { delete[] stuff; }
    1.45 +
    1.46 +    void operator()( TestClass* buffer ) const
    1.47 +    {
    1.48 +        EH_STD::uninitialized_copy((TestClass*)stuff, (TestClass*)end_of_stuff, buffer );
    1.49 +        EH_ASSERT( EH_STD::equal( (TestClass*)stuff, (TestClass*)end_of_stuff, buffer ) );
    1.50 +        stl_destroy( buffer, buffer+kBufferSize );
    1.51 +    }
    1.52 +
    1.53 +private:
    1.54 +    TestClass * stuff;
    1.55 +    TestClass * end_of_stuff;
    1.56 +};
    1.57 +
    1.58 +struct test_uninitialized_fill
    1.59 +{
    1.60 +    test_uninitialized_fill() {
    1.61 +        gTestController.SetCurrentTestName("uninitialized_fill()");
    1.62 +    }
    1.63 +
    1.64 +    void operator()( TestClass* buffer ) const
    1.65 +    {
    1.66 +        TestClass* buf_end = buffer + kBufferSize;
    1.67 +        EH_STD::uninitialized_fill( buffer, buf_end, testValue );
    1.68 +        for ( EH_CSTD::size_t i = 0; i < kBufferSize; i++ )
    1.69 +            EH_ASSERT( buffer[i] == testValue );
    1.70 +        stl_destroy( buffer, buf_end );
    1.71 +    }
    1.72 +private:
    1.73 +    TestClass testValue;
    1.74 +};
    1.75 +
    1.76 +struct test_uninitialized_fill_n
    1.77 +{
    1.78 +    test_uninitialized_fill_n() {
    1.79 +        gTestController.SetCurrentTestName("uninitialized_fill_n()");
    1.80 +    }
    1.81 +    void operator()( TestClass* buffer ) const
    1.82 +    {
    1.83 +        TestClass* end = buffer + kBufferSize;
    1.84 +        EH_STD::uninitialized_fill_n( buffer, (EH_CSTD::size_t)kBufferSize, testValue );
    1.85 +        for ( EH_CSTD::size_t i = 0; i < kBufferSize; i++ )
    1.86 +            EH_ASSERT( buffer[i] == testValue );
    1.87 +        stl_destroy( buffer, end );
    1.88 +    }
    1.89 +private:
    1.90 +    TestClass testValue;
    1.91 +};
    1.92 +
    1.93 +void test_algobase()
    1.94 +{
    1.95 +  // force alignment
    1.96 +  double arr[ sizeof(TestClass) * kBufferSize ];
    1.97 +  TestClass* c = (TestClass*)arr;
    1.98 +  WeakCheck( c, test_uninitialized_copy() );
    1.99 +  WeakCheck( c, test_uninitialized_fill() );
   1.100 +  WeakCheck( c, test_uninitialized_fill_n() );
   1.101 +}