67#define TEST_EQUALITY_CONST( v1, v2 ) \
68 TEUCHOS_TEST_EQUALITY_CONST( v1, v2, out, success )
70#define TEST_EQUALITY( v1, v2 ) \
71 TEUCHOS_TEST_EQUALITY( v1, v2, out, success )
73#define TEST_ITER_EQUALITY( iter1, iter2 ) \
74 TEUCHOS_TEST_ITER_EQUALITY( iter1, iter2, out, success )
76#define TEST_ARRAY_ELE_EQUALITY( a, i, val ) \
77 TEUCHOS_TEST_ARRAY_ELE_EQUALITY( a, i, val, false, out, local_success )
79#define TEST_COMPARE( v1, comp, v2 ) \
80 TEUCHOS_TEST_COMPARE( v1, comp, v2, out, success )
82#define TEST_COMPARE_ARRAYS( a1, a2 ) \
84 const bool result = compareArrays(a1,#a1,a2,#a2,out); \
85 if (!result) success = false; \
88#define TEST_THROW( code, ExceptType ) \
89 TEUCHOS_TEST_THROW( code, ExceptType, out, success )
91#define TEST_NOTHROW( code ) \
92 TEUCHOS_TEST_NOTHROW( code, out, success )
105 using Teuchos::arrayView;
106 using Teuchos::arrayViewFromVector;
107 using Teuchos::outArg;
112 typedef typename ArrayView<T>::size_type size_type;
124 const size_type arbitrarySizeTypeValue = 0;
125 (void) arbitrarySizeTypeValue;
131 <<
"\n*** Testing "<<TypeNameTraits<ArrayView<T> >::name()<<
" of size = "<<n
137 out <<
"\nA) Initial setup testing ...\n\n";
141 out <<
"\nTesting basic null construction!\n\n";
148#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
156 ArrayView<const T> cav2(av2);
161#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
167#ifdef SHOW_INVALID_CONST_ASSIGN
174 const ArrayView<T> av = arrayViewFromVector(v);
178 const ArrayView<const T> cav = av;
181 out <<
"\nInitializing data for std::vector v through view av ...\n";
182 for(
int i = 0; i < n; ++i )
187 out <<
"\nTest that v[i] == i through ArrayView<const T> ...\n";
188 const ArrayView<const T> cav2 = cav;
189 bool local_success =
true;
190 for(
int i = 0; i < n; ++i ) {
193 if (local_success) out <<
"passed\n";
194 else success =
false;
198 out <<
"\nTest explicit copy to std::vector from non-const array view ...\n";
199 std::vector<T> v2 = Teuchos::createVector(av);
204 out <<
"\nTest explicit copy to std::vector from const array view ...\n";
205 std::vector<T> v2 = Teuchos::createVector(cav);
210 out <<
"\nTest shallow implicit conversion from ArrayView<T> to ArrayView<T> ...\n";
211 ArrayView<T> av2(av);
216 out <<
"\nTest shallow implicit conversion from ArrayView<const T> to ArrayView<const T> ...\n";
217 ArrayView<const T> cav2(cav);
222 out <<
"\nTest shallow implicit conversion from ArrayView<const T> to ArrayView<T> ...\n";
223 ArrayView<const T> cav2(av);
228 out <<
"\nTest shallow implicit conversion from std::vector<T> to ArrayView<T> ...\n";
229 std::vector<T> v2 = Teuchos::createVector(cav);
230 ArrayView<T> cav2(v2);
235 out <<
"\nTest shallow implicit conversion from const std::vector<T> to ArrayView<const T> ...\n";
236 const std::vector<T> v2 = Teuchos::createVector(cav);
237 ArrayView<const T> cav2(v2);
243#ifdef SHOW_INVALID_COPY_CONSTRUCTION
244 ArrayView<T> cav2(cav);
249 out <<
"\ntest assign(...) ...\n";
250 std::vector<T> v2(n);
251 ArrayView<T> av2(v2);
257 out <<
"\nB) Test element access ...\n";
265#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
273 out <<
"\nC) Test iterator access ...\n";
278 out <<
"\nTest non-const forward iterator access ...\n";
279 std::vector<T> v2(n);
280 ArrayView<T> av2(v2);
281 typedef typename ArrayView<T>::iterator iter_t;
282 iter_t iter = av2.begin();
283 for (
int i = 0; iter != av2.end(); ++i )
289 out <<
"\nTest const forward iterator access ... ";
290 bool local_success =
true;
291 typedef typename ArrayView<const T>::iterator iter_t;
292 const ArrayView<const T> cav2 = av.getConst();
293 iter_t iter = cav2.begin();
294 for (
int i = 0; i < n; ++i, ++iter ) {
297#ifdef SHOW_INVALID_CONST_ITER_MODIFICATION
301 iter = NullIteratorTraits<iter_t>::getNull();
302 if (local_success) out <<
"passed\n";
303 else success =
false;
307 out <<
"\nD) Test sub-views ...\n";
311 out <<
"\nTest full non-const subview ...\n";
312 const ArrayView<T> av2 = av(0,n);
317 out <<
"\nTest full shorthand non-const subview ...\n";
318 const ArrayView<T> av2 = av();
323 out <<
"\nTest full const subview ...\n";
324 const ArrayView<const T> cav2 = cav(0,n);
329 out <<
"\nTest full non-const to const subview ...\n";
330 const ArrayView<const T> cav2 = av(0,n);
335 out <<
"\nTest full short-hand const subview ...\n";
336 const ArrayView<const T> cav2 = cav();
341 out <<
"\nTest non-const initial range view ...\n";
342 std::vector<T> v2(n,as<T>(-1));
343 const ArrayView<T> av2(v2);
344 const ArrayView<T> av2_init = av2(0,n-1);
346 av2_init.assign( av(0,n-1) );
347 av2.back() = as<T>(n-1);
352 out <<
"\nTest non-const final range view ...\n";
353 std::vector<T> v2(n,as<T>(-1));
354 const ArrayView<T> av2(v2);
355 const ArrayView<T> av2_init = av2(1,n-1);
357 av2_init.assign( av(1,n-1) );
358 av2.front() = as<T>(0);
363 out <<
"\nTest non-const middle range view ...\n";
364 std::vector<T> v2(n,as<T>(-1));
365 const ArrayView<T> av2(v2);
366 const ArrayView<T> av2_init = av2(1,n-2);
368 av2_init.assign( av(1,n-2) );
369 av2.front() = as<T>(0);
370 av2.back() = as<T>(n-1);
385int main(
int argc,
char* argv[] )
404 CommandLineProcessor clp(
false);
407 clp.setOption(
"n", &n,
"Number of elements in the array" );
409 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
411 if ( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
412 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
418 result = testArrayView<int>(n,*out);
419 if (!result) success =
false;
421 result = testArrayView<float>(n,*out);
422 if (!result) success =
false;
424 result = testArrayView<double>(n,*out);
425 if (!result) success =
false;
427 result = testArrayView<std::complex<double> >(n,*out);
428 if (!result) success =
false;
434 *out <<
"\nEnd Result: TEST PASSED" << std::endl;
436 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
438 return ( success ? 0 : 1 );
#define TEST_EQUALITY_CONST(v1, v2)
#define TEST_EQUALITY(v1, v2)
bool testArrayView(const int n, Teuchos::FancyOStream &out)
#define TEST_NOTHROW(code)
#define TEST_ARRAY_ELE_EQUALITY(a, i, val)
#define TEST_THROW(code, ExceptType)
#define TEST_COMPARE_ARRAYS(a1, a2)
#define TEST_ITER_EQUALITY(iter1, iter2)
Basic command line parser for input from (argc,argv[])
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
Utilities to make writing tests easier.
Definition of Teuchos::as, for conversions between types.
Class that helps parse command line input arguments from (argc,argv[]) and set options.
Initialize, finalize, and query the global MPI session.
Base traits class for getting a properly initialized null pointer.
Null reference error exception class.
Smart reference counting pointer class for automatic garbage collection.
Range error exception class.
Default traits class that just returns typeid(T).name().
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
std::string Teuchos_Version()