From 95cbd82a3bb8d063712a215e5768e28ee9d327f6 Mon Sep 17 00:00:00 2001 From: Markus Blatt <mblatt@dune-project.org> Date: Mon, 10 Nov 2008 12:47:36 +0000 Subject: [PATCH] Check tr1 and deprecated interface speparately. [[Imported from SVN: r5355]] --- common/test/.gitignore | 3 +- common/test/Makefile.am | 4 +- common/test/deprtuplestest.cc | 256 ++++++++++++++++++++++++++++++++++ common/test/tuplestest.cc | 81 +++++------ 4 files changed, 302 insertions(+), 42 deletions(-) create mode 100644 common/test/deprtuplestest.cc diff --git a/common/test/.gitignore b/common/test/.gitignore index f6766cb2f..dcb181aa3 100644 --- a/common/test/.gitignore +++ b/common/test/.gitignore @@ -42,4 +42,5 @@ testfassign4 smallobject conversiontest nullptr-test -bitsetvectortest +blockbitfieldtest +deprecatedtuplestest diff --git a/common/test/Makefile.am b/common/test/Makefile.am index 05f15889a..e6163ab80 100644 --- a/common/test/Makefile.am +++ b/common/test/Makefile.am @@ -10,7 +10,7 @@ TESTPROGS = parsetest test-stack arraylisttest smartpointertest \ testfassign4 \ testfassign_fail1 testfassign_fail2 testfassign_fail3 \ testfassign_fail4 testfassign_fail5 testfassign_fail6 \ - conversiontest bitsetvectortest + conversiontest bitsetvectortest deprecatedtuplestest # which tests to run COMPILE_XFAIL=$(DUNE_COMMON_ROOT)/bin/xfail-compile-tests @@ -65,6 +65,8 @@ smartpointertest_SOURCES = smartpointertest.cc tuplestest_SOURCES = tuplestest.cc +deprecatedtuplestest_SOURCES = deprtuplestest.cc + streamtest_SOURCES = streamtest.cc # mention headers so that they are distributed too diff --git a/common/test/deprtuplestest.cc b/common/test/deprtuplestest.cc new file mode 100644 index 000000000..48ad939a4 --- /dev/null +++ b/common/test/deprtuplestest.cc @@ -0,0 +1,256 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: +// $Id$ +#include "config.h" + +#include <dune/common/tuples.hh> +#include <dune/common/helpertemplates.hh> +#include <string> +#include <iostream> +#include <vector> +#include <cassert> +#include <cstdlib> + +using namespace Dune; + +template<int i, int j> +struct Same +{ + enum { value = false}; +}; + +template<int i> +struct Same<i,i> +{ + enum { value = true}; +}; + +template<class T> +void test(T& tuple) +{ + float f; + f = Element<0>::get(tuple); + int i; + i = Element<1>::get(tuple); + double d; + d = Element<2>::get(tuple); + char c; + c = Element<3>::get(tuple); + std::string s; + s = Element<4>::get(tuple); + typename ElementType<4,T>::Type s2 = Element<4>::get(tuple); +} + +int iteratorTupleTest() +{ + std::vector<int> v; + + v.push_back(0); + v.push_back(1); + v.push_back(2); + + typedef std::vector<int>::iterator iterator; + typedef std::vector<int>::const_iterator const_iterator; + typedef Tuple<iterator,const_iterator, const_iterator> Tuple; + + + Tuple tuple_(v.begin(), v.begin(), v.end()); + dune_static_assert(Size<Tuple>::value==3, "The tuple size should be 3!");; + + int ret=0; + + if(Element<0>::get(tuple_)!= v.begin()) { + std::cerr<<"Iterator tuple construction failed!"<<std::endl; + ret++; + } + assert(Element<0>::get(tuple_) == v.begin()); + assert(Element<1>::get(tuple_) == Element<0>::get(tuple_)); + if(Element<2>::get(tuple_)!= v.end()) { + std::cerr<<"Iterator tuple construction failed!"<<std::endl; + ret++; + } + + assert(Element<2>::get(tuple_) == v.end()); + assert(Element<0>::get(tuple_) != v.end()); + assert(Element<1>::get(tuple_)!= Element<2>::get(tuple_)); + return ret; +} + +int lessTest() +{ + Tuple<int,float,double> t1(1,2.0,3.0); + Tuple<int,int,int> t2(1,2,1); + + int ret=0; + + if ((t1<t2) != false) ret++; + std::cout << "[" << t1 << "] < [" << t2 << "] = " << (t1<t2) << std::endl; + if ((t2<t1) != true) ret++; + std::cout << "[" << t2 << "] < [" << t1 << "] = " << (t2<t1) << std::endl; + + // This would result in a compiler error + // Tuple<int,int> t3(1,2); + // std::cout << "[" << t3 << "] < [" << t1 << "] = " << (t3<t1) << std::endl; + + return ret; +} + +int copyTest() +{ + Tuple<float,int,double,char,std::string> tuple_, tuple1(3.0,1,3.3,'c',std::string("hallo")), tuple2(tuple1); + + std::cout<<tuple1<<std::endl; + std::cout<<tuple2<<std::endl; + tuple_=tuple1; + std::cout<<tuple_<<std::endl; + + if(tuple_!=tuple1) + return 1; + if(tuple2!=tuple1) + return 1; + + return 0; +} + +int referenceTest() +{ + int k=5; + int& kr(k); + kr=20; + int i=50; + double d=-3.3; + long j=-666; + Tuple<int,double,long> t1(100, 5.0, 10); + Tuple<int,int,int> t2(1,5,9); + std::cout << "i="<<i<<" d="<<d<<" j="<<j<<std::endl; + + Tuple<int&,double&,long&> tr(i,d,j); + + Element<0>::get(tr)=3; + assert(Element<0>::get(tr)==3); + + std::cout <<"tr="<< tr<<std::endl; + + Tuple<int> i1(5); + Tuple<int&> ir(i); + ir=i1; + + t1=t2; + + std::cout <<"tr="<< tr<<std::endl; + std::cout <<"t1="<< t1<<std::endl; + tr=t1; + + if(tr!=t1) + return 1; + else + std::cout<<"t1="<<t1<< " tr="<<tr<<std::endl; + + + return 0; +} + +int pointerTest() +{ + int k=5, k1=6; + int i=50; + double d=-3.3, d1=7.8; + long j=-666, j1=-300; + Tuple<int*,double*,long*> t1(&k, &d, &j); + Tuple<int*,double*,long*> t2(&k1,&d1,&j1); + std::cout << "i="<<i<<" d="<<d<<" j="<<j<<std::endl; + + Tuple<int*,double*,long*> tr(&i,&d,&j); + + *Element<0>::get(tr)=3; + assert(*Element<0>::get(tr)==3); + + std::cout <<"tr="<< tr<<std::endl; + + Tuple<int> i1(5); + Tuple<int*> ir(&i); + + t2=t1; + + std::cout <<"tr="<< tr<<std::endl; + std::cout <<"t1="<< t1<<std::endl; + tr=t1; + + if(tr!=t1) + return 1; + else + std::cout<<"t1="<<t1<< " tr="<<tr<<std::endl; + + + return 0; +} + +int constPointerTest() +{ + int k=5, k1=88; + int i=50; + double d=-3.3, d1=6.8; + long j=-666, j1=-500; + Tuple<const int*, const double*, const long*> t1(&k, &d, &j); + Tuple<int*, double*, long*> t2(&k1,&d1,&j1); + std::cout << "i="<<i<<" d="<<d<<" j="<<j<<std::endl; + + Tuple<const int*, const double*, const long*> tr(&i,&d,&j); + + std::cout << *Element<0>::get(tr)<<std::endl; + + std::cout <<"tr="<< tr<<std::endl; + + Tuple<int> i1(5); + Tuple<const int*> ir(&i); + + t1=t2; + + std::cout <<"tr="<< tr<<std::endl; + std::cout <<"t1="<< t1<<std::endl; + tr=t1; + + if(tr!=t1) + return 1; + else + std::cout<<"t1="<<t1<< " tr="<<tr<<std::endl; + + + return 0; +} + +int tuple_tr1_test() +{ + int ret=0; + + tuple<int,double> t(1,3.14); + int sz = tuple_size<tuple<int, double, char> >::value; + if(sz!=3) ++ret; + + // contruct a tuple + + t= make_tuple(5, 10.9); + + + // get the second element + tuple_element<1,tuple<int,double> >::type d=get<1>(t); + + get<0>(t)=16; + + std::cout<<t<<std::endl; + + return ret; +} + + +int main(int argc, char** argv) +{ + Tuple<float,int,double,char,std::string> tuple_; + + test(tuple_); + test(static_cast<Tuple<float,int,double,char,std::string>& >(tuple_)); + test(static_cast<const Tuple<float,int,double,char,std::string>&>(tuple_)); + exit(copyTest()+iteratorTupleTest()+referenceTest()+lessTest() + +pointerTest()+constPointerTest()+tuple_tr1_test()); + +} diff --git a/common/test/tuplestest.cc b/common/test/tuplestest.cc index f188e54e9..a7d2c0e6b 100644 --- a/common/test/tuplestest.cc +++ b/common/test/tuplestest.cc @@ -29,15 +29,16 @@ template<class T> void test(T& tuple) { float f; - f = Element<0>::get(tuple); + f = get<0>(tuple); int i; - i = Element<1>::get(tuple); + i = get<1>(tuple); double d; - d = Element<2>::get(tuple); + d = get<2>(tuple); char c; - c = Element<3>::get(tuple); + c = get<3>(tuple); std::string s; - s = Element<4>::get(tuple); + s = get<4>(tuple); + typename tuple_element<4,T>::type s2 = get<4>(tuple); } int iteratorTupleTest() @@ -50,35 +51,35 @@ int iteratorTupleTest() typedef std::vector<int>::iterator iterator; typedef std::vector<int>::const_iterator const_iterator; - typedef Tuple<iterator,const_iterator, const_iterator> Tuple; + typedef tuple<iterator,const_iterator, const_iterator> Tuple; Tuple tuple_(v.begin(), v.begin(), v.end()); - dune_static_assert(Size<Tuple>::value==3, "The tuple size should be 3!");; + dune_static_assert(tuple_size<Tuple>::value==3, "The tuple size should be 3!");; int ret=0; - if(Element<0>::get(tuple_)!= v.begin()) { + if(get<0>(tuple_)!= v.begin()) { std::cerr<<"Iterator tuple construction failed!"<<std::endl; ret++; } - assert(Element<0>::get(tuple_) == v.begin()); - assert(Element<1>::get(tuple_) == Element<0>::get(tuple_)); - if(Element<2>::get(tuple_)!= v.end()) { + assert(get<1>(tuple_) == v.begin()); + assert(get<1>(tuple_) == get<0>(tuple_)); + if(get<2>(tuple_)!= v.end()) { std::cerr<<"Iterator tuple construction failed!"<<std::endl; ret++; } - assert(Element<2>::get(tuple_) == v.end()); - assert(Element<0>::get(tuple_) != v.end()); - assert(Element<1>::get(tuple_)!= Element<2>::get(tuple_)); + assert(get<2>(tuple_) == v.end()); + assert(get<0>(tuple_) != v.end()); + assert(get<1>(tuple_)!= Element<2>::get(tuple_)); return ret; } int lessTest() { - Tuple<int,float,double> t1(1,2.0,3.0); - Tuple<int,int,int> t2(1,2,1); + tuple<int,float,double> t1(1,2.0,3.0); + tuple<int,int,int> t2(1,2,1); int ret=0; @@ -96,7 +97,7 @@ int lessTest() int copyTest() { - Tuple<float,int,double,char,std::string> tuple_, tuple1(3.0,1,3.3,'c',std::string("hallo")), tuple2(tuple1); + tuple<float,int,double,char,std::string> tuple_, tuple1(3.0,1,3.3,'c',std::string("hallo")), tuple2(tuple1); std::cout<<tuple1<<std::endl; std::cout<<tuple2<<std::endl; @@ -119,19 +120,19 @@ int referenceTest() int i=50; double d=-3.3; long j=-666; - Tuple<int,double,long> t1(100, 5.0, 10); - Tuple<int,int,int> t2(1,5,9); + tuple<int,double,long> t1(100, 5.0, 10); + tuple<int,int,int> t2(1,5,9); std::cout << "i="<<i<<" d="<<d<<" j="<<j<<std::endl; - Tuple<int&,double&,long&> tr(i,d,j); + tuple<int&,double&,long&> tr(i,d,j); - Element<0>::get(tr)=3; - assert(Element<0>::get(tr)==3); + get<0>(tr)=3; + assert(get<0>(tr)==3); std::cout <<"tr="<< tr<<std::endl; - Tuple<int> i1(5); - Tuple<int&> ir(i); + tuple<int> i1(5); + tuple<int&> ir(i); ir=i1; t1=t2; @@ -155,19 +156,19 @@ int pointerTest() int i=50; double d=-3.3, d1=7.8; long j=-666, j1=-300; - Tuple<int*,double*,long*> t1(&k, &d, &j); - Tuple<int*,double*,long*> t2(&k1,&d1,&j1); + tuple<int*,double*,long*> t1(&k, &d, &j); + tuple<int*,double*,long*> t2(&k1,&d1,&j1); std::cout << "i="<<i<<" d="<<d<<" j="<<j<<std::endl; - Tuple<int*,double*,long*> tr(&i,&d,&j); + tuple<int*,double*,long*> tr(&i,&d,&j); - *Element<0>::get(tr)=3; - assert(*Element<0>::get(tr)==3); + *get<0>(tr)=3; + assert(*get<0>(tr)==3); std::cout <<"tr="<< tr<<std::endl; - Tuple<int> i1(5); - Tuple<int*> ir(&i); + tuple<int> i1(5); + tuple<int*> ir(&i); t2=t1; @@ -190,18 +191,18 @@ int constPointerTest() int i=50; double d=-3.3, d1=6.8; long j=-666, j1=-500; - Tuple<const int*, const double*, const long*> t1(&k, &d, &j); - Tuple<int*, double*, long*> t2(&k1,&d1,&j1); + tuple<const int*, const double*, const long*> t1(&k, &d, &j); + tuple<int*, double*, long*> t2(&k1,&d1,&j1); std::cout << "i="<<i<<" d="<<d<<" j="<<j<<std::endl; - Tuple<const int*, const double*, const long*> tr(&i,&d,&j); + tuple<const int*, const double*, const long*> tr(&i,&d,&j); - std::cout << *Element<0>::get(tr)<<std::endl; + std::cout << *get<0>(tr)<<std::endl; std::cout <<"tr="<< tr<<std::endl; - Tuple<int> i1(5); - Tuple<const int*> ir(&i); + tuple<int> i1(5); + tuple<const int*> ir(&i); t1=t2; @@ -244,11 +245,11 @@ int tuple_tr1_test() int main(int argc, char** argv) { - Tuple<float,int,double,char,std::string> tuple_; + tuple<float,int,double,char,std::string> tuple_; test(tuple_); - test(static_cast<Tuple<float,int,double,char,std::string>& >(tuple_)); - test(static_cast<const Tuple<float,int,double,char,std::string>&>(tuple_)); + test(static_cast<tuple<float,int,double,char,std::string>& >(tuple_)); + test(static_cast<const tuple<float,int,double,char,std::string>&>(tuple_)); exit(copyTest()+iteratorTupleTest()+referenceTest()+lessTest() +pointerTest()+constPointerTest()+tuple_tr1_test()); -- GitLab