os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/test_algobase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/***********************************************************************************
sl@0
     2
  test_algobase.cpp
sl@0
     3
sl@0
     4
 * Copyright (c) 1997
sl@0
     5
 * Mark of the Unicorn, Inc.
sl@0
     6
 *
sl@0
     7
 * Permission to use, copy, modify, distribute and sell this software
sl@0
     8
 * and its documentation for any purpose is hereby granted without fee,
sl@0
     9
 * provided that the above copyright notice appear in all copies and
sl@0
    10
 * that both that copyright notice and this permission notice appear
sl@0
    11
 * in supporting documentation.  Mark of the Unicorn makes no
sl@0
    12
 * representations about the suitability of this software for any
sl@0
    13
 * purpose.  It is provided "as is" without express or implied warranty.
sl@0
    14
sl@0
    15
***********************************************************************************/
sl@0
    16
sl@0
    17
# include "Prefix.h"
sl@0
    18
# if defined (EH_NEW_HEADERS)
sl@0
    19
# ifdef __SUNPRO_CC
sl@0
    20
# include <stdio.h>
sl@0
    21
# endif
sl@0
    22
#include <algorithm>
sl@0
    23
# else
sl@0
    24
#include <algo.h>
sl@0
    25
# endif
sl@0
    26
#include "Tests.h"
sl@0
    27
#include "LeakCheck.h"
sl@0
    28
#include "TestClass.h"
sl@0
    29
sl@0
    30
// EH_USE_STD
sl@0
    31
sl@0
    32
enum { kBufferSize = 100 };
sl@0
    33
sl@0
    34
struct test_uninitialized_copy
sl@0
    35
{
sl@0
    36
    test_uninitialized_copy()
sl@0
    37
        : stuff( new TestClass[kBufferSize] ), end_of_stuff(stuff + kBufferSize) {
sl@0
    38
        gTestController.SetCurrentTestName("uninitialized_copy()");
sl@0
    39
        }
sl@0
    40
sl@0
    41
    ~test_uninitialized_copy() { delete[] stuff; }
sl@0
    42
sl@0
    43
    void operator()( TestClass* buffer ) const
sl@0
    44
    {
sl@0
    45
        EH_STD::uninitialized_copy((TestClass*)stuff, (TestClass*)end_of_stuff, buffer );
sl@0
    46
        EH_ASSERT( EH_STD::equal( (TestClass*)stuff, (TestClass*)end_of_stuff, buffer ) );
sl@0
    47
        stl_destroy( buffer, buffer+kBufferSize );
sl@0
    48
    }
sl@0
    49
sl@0
    50
private:
sl@0
    51
    TestClass * stuff;
sl@0
    52
    TestClass * end_of_stuff;
sl@0
    53
};
sl@0
    54
sl@0
    55
struct test_uninitialized_fill
sl@0
    56
{
sl@0
    57
    test_uninitialized_fill() {
sl@0
    58
        gTestController.SetCurrentTestName("uninitialized_fill()");
sl@0
    59
    }
sl@0
    60
sl@0
    61
    void operator()( TestClass* buffer ) const
sl@0
    62
    {
sl@0
    63
        TestClass* buf_end = buffer + kBufferSize;
sl@0
    64
        EH_STD::uninitialized_fill( buffer, buf_end, testValue );
sl@0
    65
        for ( EH_CSTD::size_t i = 0; i < kBufferSize; i++ )
sl@0
    66
            EH_ASSERT( buffer[i] == testValue );
sl@0
    67
        stl_destroy( buffer, buf_end );
sl@0
    68
    }
sl@0
    69
private:
sl@0
    70
    TestClass testValue;
sl@0
    71
};
sl@0
    72
sl@0
    73
struct test_uninitialized_fill_n
sl@0
    74
{
sl@0
    75
    test_uninitialized_fill_n() {
sl@0
    76
        gTestController.SetCurrentTestName("uninitialized_fill_n()");
sl@0
    77
    }
sl@0
    78
    void operator()( TestClass* buffer ) const
sl@0
    79
    {
sl@0
    80
        TestClass* end = buffer + kBufferSize;
sl@0
    81
        EH_STD::uninitialized_fill_n( buffer, (EH_CSTD::size_t)kBufferSize, testValue );
sl@0
    82
        for ( EH_CSTD::size_t i = 0; i < kBufferSize; i++ )
sl@0
    83
            EH_ASSERT( buffer[i] == testValue );
sl@0
    84
        stl_destroy( buffer, end );
sl@0
    85
    }
sl@0
    86
private:
sl@0
    87
    TestClass testValue;
sl@0
    88
};
sl@0
    89
sl@0
    90
void test_algobase()
sl@0
    91
{
sl@0
    92
  // force alignment
sl@0
    93
  double arr[ sizeof(TestClass) * kBufferSize ];
sl@0
    94
  TestClass* c = (TestClass*)arr;
sl@0
    95
  WeakCheck( c, test_uninitialized_copy() );
sl@0
    96
  WeakCheck( c, test_uninitialized_fill() );
sl@0
    97
  WeakCheck( c, test_uninitialized_fill_n() );
sl@0
    98
}