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;
118 <<
"\n*** Testing "<<TypeNameTraits<ArrayView<T> >::name()<<
" of size = "<<n
124 out <<
"\nA) Initial setup testing ...\n\n";
128 out <<
"\nTesting basic null construction!\n\n";
134 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
142 ArrayView<const T> cav2(av2);
146 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
152 #ifdef SHOW_INVALID_CONST_ASSIGN
163 const ArrayView<const T> cav = av;
166 out <<
"\nInitializing data for std::vector v through view av ...\n";
167 for(
int i = 0; i <
n; ++i )
172 out <<
"\nTest that v[i] == i through ArrayView<const T> ...\n";
173 const ArrayView<const T> cav2 = cav;
174 bool local_success =
true;
175 for(
int i = 0; i <
n; ++i ) {
178 if (local_success) out <<
"passed\n";
179 else success =
false;
183 out <<
"\nTest explicit copy to std::vector from non-const array view ...\n";
184 std::vector<T> v2 = Teuchos::createVector(av);
189 out <<
"\nTest explicit copy to std::vector from const array view ...\n";
190 std::vector<T> v2 = Teuchos::createVector(cav);
195 out <<
"\nTest shallow implicit conversion from ArrayView<T> to ArrayView<T> ...\n";
196 ArrayView<T> av2(av);
201 out <<
"\nTest shallow implicit conversion from ArrayView<const T> to ArrayView<const T> ...\n";
202 ArrayView<const T> cav2(cav);
207 out <<
"\nTest shallow implicit conversion from ArrayView<const T> to ArrayView<T> ...\n";
208 ArrayView<const T> cav2(av);
213 out <<
"\nTest shallow implicit conversion from std::vector<T> to ArrayView<T> ...\n";
214 std::vector<T> v2 = Teuchos::createVector(cav);
215 ArrayView<T> cav2(v2);
220 out <<
"\nTest shallow implicit conversion from const std::vector<T> to ArrayView<const T> ...\n";
221 const std::vector<T> v2 = Teuchos::createVector(cav);
222 ArrayView<const T> cav2(v2);
228 #ifdef SHOW_INVALID_COPY_CONSTRUCTION
229 ArrayView<T> cav2(cav);
234 out <<
"\ntest assign(...) ...\n";
235 std::vector<T> v2(n);
236 ArrayView<T> av2(v2);
242 out <<
"\nB) Test element access ...\n";
250 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
255 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
258 out <<
"\nC) Test iterator access ...\n";
263 out <<
"\nTest non-const forward iterator access ...\n";
264 std::vector<T> v2(n);
265 ArrayView<T> av2(v2);
266 typedef typename ArrayView<T>::iterator iter_t;
267 iter_t iter = av2.begin();
268 for (
int i = 0; iter != av2.end(); ++i )
274 out <<
"\nTest const forward iterator access ... ";
275 bool local_success =
true;
276 typedef typename ArrayView<const T>::iterator iter_t;
277 const ArrayView<const T> cav2 = av.getConst();
278 iter_t iter = cav2.begin();
279 for (
int i = 0; i <
n; ++i, ++iter ) {
282 #ifdef SHOW_INVALID_CONST_ITER_MODIFICATION
286 iter = NullIteratorTraits<iter_t>::getNull();
287 if (local_success) out <<
"passed\n";
288 else success =
false;
292 out <<
"\nD) Test sub-views ...\n";
296 out <<
"\nTest full non-const subview ...\n";
297 const ArrayView<T> av2 = av(0,n);
302 out <<
"\nTest full shorthand non-const subview ...\n";
303 const ArrayView<T> av2 = av();
308 out <<
"\nTest full const subview ...\n";
309 const ArrayView<const T> cav2 = cav(0,n);
314 out <<
"\nTest full non-const to const subview ...\n";
315 const ArrayView<const T> cav2 = av(0,n);
320 out <<
"\nTest full short-hand const subview ...\n";
321 const ArrayView<const T> cav2 = cav();
326 out <<
"\nTest non-const initial range view ...\n";
327 std::vector<T> v2(n,as<T>(-1));
328 const ArrayView<T> av2(v2);
329 const ArrayView<T> av2_init = av2(0,n-1);
331 av2_init.assign( av(0,n-1) );
332 av2.back() = as<T>(n-1);
337 out <<
"\nTest non-const final range view ...\n";
338 std::vector<T> v2(n,as<T>(-1));
339 const ArrayView<T> av2(v2);
340 const ArrayView<T> av2_init = av2(1,n-1);
342 av2_init.assign( av(1,n-1) );
343 av2.front() = as<T>(0);
348 out <<
"\nTest non-const middle range view ...\n";
349 std::vector<T> v2(n,as<T>(-1));
350 const ArrayView<T> av2(v2);
351 const ArrayView<T> av2_init = av2(1,n-2);
353 av2_init.assign( av(1,n-2) );
354 av2.front() = as<T>(0);
355 av2.back() = as<T>(n-1);
370 int main(
int argc,
char* argv[] )
389 CommandLineProcessor clp(
false);
392 clp.setOption(
"n", &n,
"Number of elements in the array" );
394 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
396 if ( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
397 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
403 result = testArrayView<int>(
n,*out);
404 if (!result) success =
false;
406 result = testArrayView<float>(
n,*out);
407 if (!result) success =
false;
409 result = testArrayView<double>(
n,*out);
410 if (!result) success =
false;
412 result = testArrayView<std::complex<double> >(
n,*out);
413 if (!result) success =
false;
419 *out <<
"\nEnd Result: TEST PASSED" << std::endl;
421 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
423 return ( success ? 0 : 1 );
#define TEST_NOTHROW(code)
Null reference error exception class.
#define TEST_EQUALITY_CONST(v1, v2)
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
ArrayView< T > arrayViewFromVector(std::vector< T > &vec)
Construct a non-const view of an std::vector.
#define TEST_ITER_EQUALITY(iter1, iter2)
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
Initialize, finalize, and query the global MPI session.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
#define TEST_COMPARE_ARRAYS(a1, a2)
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
std::string Teuchos_Version()
Base traits class for getting a properly initialized null pointer.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
int main(int argc, char *argv[])
bool testArrayView(const int n, Teuchos::FancyOStream &out)
Utilities to make writing tests easier.
Default traits class that just returns typeid(T).name().
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
#define TEST_THROW(code, ExceptType)
Smart reference counting pointer class for automatic garbage collection.
#define TEST_ARRAY_ELE_EQUALITY(a, i, val)
#define TEST_EQUALITY(v1, v2)
Range error exception class.
RCP< basic_FancyOStream< CharT, Traits > > tab(const RCP< basic_FancyOStream< CharT, Traits > > &out, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Create a tab for an RCP-wrapped basic_FancyOStream object to cause the indentation of all output auto...
Definition of Teuchos::as, for conversions between types.
Class that helps parse command line input arguments from (argc,argv[]) and set options.