genericopenlibs/cppstdlib/stl/test/unit/rawriter_test.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     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 <algorithm>
       
    18 #include <iterator>
       
    19 #include <memory>
       
    20 
       
    21 #include "cppunit/cppunit_proxy.h"
       
    22 
       
    23 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
       
    24 using namespace std;
       
    25 #endif
       
    26 
       
    27 class X
       
    28 {
       
    29   public:
       
    30     X(int i_ = 0) : i(i_) {}
       
    31     ~X() {}
       
    32     operator int() const { return i; }
       
    33 
       
    34   private:
       
    35     int i;
       
    36 };
       
    37 
       
    38 
       
    39 //
       
    40 // TestCase class
       
    41 //
       
    42 class RawriterTest : public CPPUNIT_NS::TestCase
       
    43 {
       
    44   CPPUNIT_TEST_SUITE(RawriterTest);
       
    45   CPPUNIT_TEST(rawiter1);
       
    46   CPPUNIT_TEST_SUITE_END();
       
    47 
       
    48 protected:
       
    49   void rawiter1();
       
    50 };
       
    51 
       
    52 CPPUNIT_TEST_SUITE_REGISTRATION(RawriterTest);
       
    53 
       
    54 //
       
    55 // tests implementation
       
    56 //
       
    57 void RawriterTest::rawiter1()
       
    58 {
       
    59   allocator<X> a;
       
    60   typedef X* x_pointer;
       
    61   x_pointer save_p, p;
       
    62   p = a.allocate(5);
       
    63   save_p=p;
       
    64   raw_storage_iterator<X*, X> r(p);
       
    65   int i;
       
    66   for(i = 0; i < 5; i++)
       
    67     *r++ = X(i);
       
    68 
       
    69   CPPUNIT_ASSERT(*p++ == 0);
       
    70   CPPUNIT_ASSERT(*p++ == 1);
       
    71   CPPUNIT_ASSERT(*p++ == 2);
       
    72   CPPUNIT_ASSERT(*p++ == 3);
       
    73   CPPUNIT_ASSERT(*p++ == 4);
       
    74 
       
    75 //#if defined (STLPORT) || defined (__GNUC__)
       
    76   a.deallocate(save_p, 5);
       
    77 /*
       
    78 #else
       
    79   a.deallocate(save_p);
       
    80 #endif
       
    81 */
       
    82 
       
    83   CPPUNIT_ASSERT(true);
       
    84 }