os/ossrv/stdcpp/tsrc/Boost_test/multi_array/src/access.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright 2002 The Trustees of Indiana University.
     2 
     3 // Use, modification and distribution is subject to the Boost Software 
     4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
     5 // http://www.boost.org/LICENSE_1_0.txt)
     6 
     7 //  Boost.MultiArray Library
     8 //  Authors: Ronald Garcia
     9 //           Jeremy Siek
    10 //           Andrew Lumsdaine
    11 //  See http://www.boost.org/libs/multi_array for documentation.
    12 
    13 // 
    14 // access.cpp - operator[] and operator() tests with various arrays
    15 //    The tests assume that they are working on an Array of shape 2x3x4
    16 //
    17 /*
    18  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    19 */
    20 
    21 #include "generative_tests.hpp"
    22 #include "boost/static_assert.hpp"
    23 
    24 template <typename Array>
    25 void access(Array& A, const mutable_array_tag&) {
    26   assign(A);
    27   access(A,const_array_tag());
    28 
    29   const Array& CA = A;
    30   access(CA,const_array_tag());
    31 }
    32 
    33 template <typename Array>
    34 void access(Array& A, const const_array_tag&) {
    35   const unsigned int ndims = 3;
    36   BOOST_STATIC_ASSERT((Array::dimensionality == ndims));
    37   typedef typename Array::index index;
    38   const index idx0 = A.index_bases()[0];
    39   const index idx1 = A.index_bases()[1];
    40   const index idx2 = A.index_bases()[2];
    41 
    42   // operator[]
    43   int cnum = 0;
    44   const Array& CA = A;
    45   for (index i = idx0; i != idx0+2; ++i)
    46     for (index j = idx1; j != idx1+3; ++j)
    47       for (index k = idx2; k != idx2+4; ++k) {
    48         BOOST_CHECK(A[i][j][k] == cnum++);
    49         BOOST_CHECK(CA[i][j][k] == A[i][j][k]);
    50       }
    51 
    52   // operator()
    53   for (index i2 = idx0; i2 != idx0+2; ++i2)
    54     for (index j2 = idx1; j2 != idx1+3; ++j2)
    55       for (index k2 = idx2; k2 != idx2+4; ++k2) {
    56         boost::array<index,ndims> indices;
    57         indices[0] = i2; indices[1] = j2; indices[2] = k2;
    58         BOOST_CHECK(A(indices) == A[i2][j2][k2]);
    59          BOOST_CHECK(CA(indices) == A(indices));
    60       }
    61   ++tests_run;
    62 }
    63 
    64 int test_main(int,char*[]) {
    65 #ifdef __SYMBIAN32__
    66 if(boost::minimal_test::errors_counter() != 0)
    67    assert_failed = true;
    68    	testResultXml("access");
    69 	close_log_file();
    70 #endif
    71   return run_generative_tests();
    72 }