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 )
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";
204 out <<
"\nTest explicit copy to std::vector from const array view ...\n";
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";
230 ArrayView<T> cav2(v2);
235 out <<
"\nTest shallow implicit conversion from const std::vector<T> to ArrayView<const T> ...\n";
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[] )
407 clp.
setOption(
"n", &n,
"Number of elements in the array" );
412 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
419 if (!result) success =
false;
422 if (!result) success =
false;
425 if (!result) success =
false;
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.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
EParseCommandLineReturn
Return value for CommandLineProcessor::parse(). Note: These enums are all given non-negative values s...
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Parse a command line.
ArrayView< T > arrayViewFromVector(std::vector< T > &vec)
Construct a non-const view of an std::vector.
ArrayView< T > arrayView(T *p, typename ArrayView< T >::size_type size)
Construct a const or non-const view to const or non-const data.
std::vector< T > createVector(const Array< T > &a)
Copy conversion to an std::vector.
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.
Ptr< T > outArg(T &arg)
create a non-persisting (required or optional) output argument for a function call.
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.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
basic_FancyOStream< char > FancyOStream
basic_OSTab< char > OSTab
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
std::string Teuchos_Version()