Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// dynarray.cons
|
||||
|
||||
// template <class Alloc>
|
||||
// dynarray(size_type c, const Alloc& alloc);
|
||||
// template <class Alloc>
|
||||
// dynarray(size_type c, const T& v, const Alloc& alloc);
|
||||
// template <class Alloc>
|
||||
// dynarray(const dynarray& d, const Alloc& alloc);
|
||||
// template <class Alloc>
|
||||
// dynarray(initializer_list<T>, const Alloc& alloc);
|
||||
|
||||
// ~dynarray();
|
||||
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
#include <experimental/dynarray>
|
||||
#include <cassert>
|
||||
|
||||
#include <algorithm>
|
||||
#include <complex>
|
||||
#include <string>
|
||||
#include "test_allocator.h"
|
||||
|
||||
using std::experimental::dynarray;
|
||||
|
||||
template <class T, class Allocator>
|
||||
void check_allocator ( const dynarray<T> &dyn, const Allocator &alloc ) {
|
||||
for ( int i = 0; i < dyn.size (); ++i )
|
||||
assert ( dyn[i].get_allocator() == alloc );
|
||||
}
|
||||
|
||||
template <class T, class Allocator>
|
||||
void test ( const std::initializer_list<T> &vals, const Allocator &alloc ) {
|
||||
typedef dynarray<T> dynA;
|
||||
|
||||
dynA d1 ( vals, alloc );
|
||||
assert ( d1.size () == vals.size() );
|
||||
assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ()));
|
||||
check_allocator ( d1, alloc );
|
||||
}
|
||||
|
||||
|
||||
template <class T, class Allocator>
|
||||
void test ( const T &val, const Allocator &alloc1, const Allocator &alloc2 ) {
|
||||
typedef dynarray<T> dynA;
|
||||
|
||||
dynA d1 ( 4, alloc1 );
|
||||
assert ( d1.size () == 4 );
|
||||
assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } ));
|
||||
check_allocator ( d1, alloc1 );
|
||||
|
||||
dynA d2 ( 7, val, alloc1 );
|
||||
assert ( d2.size () == 7 );
|
||||
assert ( std::all_of ( d2.begin (), d2.end (), [&val]( const T &item ){ return item == val; } ));
|
||||
check_allocator ( d2, alloc1 );
|
||||
|
||||
dynA d3 ( d2, alloc2 );
|
||||
assert ( d3.size () == 7 );
|
||||
assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } ));
|
||||
check_allocator ( d3, alloc2 );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// This test is waiting on the resolution of LWG issue #2235
|
||||
// typedef test_allocator<char> Alloc;
|
||||
// typedef std::basic_string<char, std::char_traits<char>, Alloc> nstr;
|
||||
//
|
||||
// test ( nstr("fourteen"), Alloc(3), Alloc(4) );
|
||||
// test ( { nstr("1"), nstr("1"), nstr("2"), nstr("3"), nstr("5"), nstr("8")}, Alloc(6));
|
||||
}
|
||||
#else
|
||||
int main() {}
|
||||
#endif
|
@@ -0,0 +1,95 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// dynarray.cons
|
||||
|
||||
// explicit dynarray(size_type c);
|
||||
// dynarray(size_type c, const T& v);
|
||||
// dynarray(initializer_list<T>);
|
||||
// dynarray(const dynarray& d);
|
||||
|
||||
// ~dynarray();
|
||||
|
||||
|
||||
#include <__config>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
#include <experimental/dynarray>
|
||||
#include <cassert>
|
||||
|
||||
#include <algorithm>
|
||||
#include <complex>
|
||||
#include <string>
|
||||
|
||||
using std::experimental::dynarray;
|
||||
|
||||
template <class T>
|
||||
void test ( const std::initializer_list<T> &vals ) {
|
||||
typedef dynarray<T> dynA;
|
||||
|
||||
dynA d1 ( vals );
|
||||
assert ( d1.size () == vals.size() );
|
||||
assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ()));
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
void test ( const T &val ) {
|
||||
typedef dynarray<T> dynA;
|
||||
|
||||
dynA d1 ( 4 );
|
||||
assert ( d1.size () == 4 );
|
||||
assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } ));
|
||||
|
||||
dynA d2 ( 7, val );
|
||||
assert ( d2.size () == 7 );
|
||||
assert ( std::all_of ( d2.begin (), d2.end (), [&val]( const T &item ){ return item == val; } ));
|
||||
|
||||
dynA d3 ( d2 );
|
||||
assert ( d3.size () == 7 );
|
||||
assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } ));
|
||||
}
|
||||
|
||||
void test_bad_length () {
|
||||
try { dynarray<int> ( std::numeric_limits<size_t>::max() / sizeof ( int ) + 1 ); }
|
||||
catch ( std::bad_array_length & ) { return ; }
|
||||
assert ( false );
|
||||
}
|
||||
|
||||
void test_bad_alloc () {
|
||||
try { dynarray<int> ( std::numeric_limits<size_t>::max() / sizeof ( int ) - 1 ); }
|
||||
catch ( std::bad_alloc & ) { return ; }
|
||||
assert ( false );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// test<int> ( 14 ); // ints don't get default initialized
|
||||
test<long> ( 0 );
|
||||
test<double> ( 14.0 );
|
||||
test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
|
||||
test<std::string> ( "fourteen" );
|
||||
|
||||
test ( { 1, 1, 2, 3, 5, 8 } );
|
||||
test ( { 1., 1., 2., 3., 5., 8. } );
|
||||
test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"),
|
||||
std::string("5"), std::string("8")} );
|
||||
|
||||
// Make sure we don't pick up the Allocator version here
|
||||
dynarray<long> d1 ( 20, 3 );
|
||||
assert ( d1.size() == 20 );
|
||||
assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return item == 3L; } ));
|
||||
|
||||
test_bad_length ();
|
||||
test_bad_alloc ();
|
||||
}
|
||||
#else
|
||||
int main() {}
|
||||
#endif
|
Reference in New Issue
Block a user