diff options
Diffstat (limited to 'test/unit')
200 files changed, 0 insertions, 24709 deletions
diff --git a/test/unit/_template.cpp b/test/unit/_template.cpp deleted file mode 100644 index a2a86d6..0000000 --- a/test/unit/_template.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class Test : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(Test); - CPPUNIT_TEST(test); - CPPUNIT_TEST_SUITE_END(); - -protected: - void test(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(Test); - -// -// tests implementation -// -void Test::test() -{ - CPPUNIT_ASSERT(true); -} diff --git a/test/unit/accum_test.cpp b/test/unit/accum_test.cpp deleted file mode 100644 index bb58561..0000000 --- a/test/unit/accum_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include <vector> -#include <numeric> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class AccumTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(AccumTest); - CPPUNIT_TEST(accum1); - CPPUNIT_TEST(accum2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void accum1(); - void accum2(); - static int mult(int initial_, int element_); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(AccumTest); - -// -// tests implementation -// -void AccumTest::accum1() -{ - vector<int> v(5); - for(int i = 0; (size_t)i < v.size(); ++i) - v[i] = i + 1; - int sum = accumulate(v.begin(), v.end(), 0); - CPPUNIT_ASSERT(sum==15); -} -void AccumTest::accum2() -{ - vector<int> v(5); - for(int i = 0; (size_t)i < v.size(); ++i) - v[i] = i + 1; - int prod = accumulate(v.begin(), v.end(), 1, mult); - CPPUNIT_ASSERT(prod==120); -} -int AccumTest::mult(int initial_, int element_) -{ - return initial_ * element_; -} diff --git a/test/unit/adj_test.cpp b/test/unit/adj_test.cpp deleted file mode 100644 index 588838c..0000000 --- a/test/unit/adj_test.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include <vector> -#include <numeric> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class AdjTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(AdjTest); - CPPUNIT_TEST(adjfind0); - CPPUNIT_TEST(adjfind1); - CPPUNIT_TEST(adjfind2); - CPPUNIT_TEST(adjdiff0); - CPPUNIT_TEST(adjdiff1); - CPPUNIT_TEST(adjdiff2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void adjfind0(); - void adjfind1(); - void adjfind2(); - void adjdiff0(); - void adjdiff1(); - void adjdiff2(); - static int equal_length(const char* v1_, const char* v2_); - static int mult(int a_, int b_); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(AdjTest); - -// -// tests implementation -// -void AdjTest::adjfind0() -{ - int numbers1 [5] = { 1, 2, 4, 8, 16 }; - int numbers2 [5] = { 5, 3, 2, 1, 1 }; - - int* location = adjacent_find((int*)numbers1, (int*)numbers1 + 5); - CPPUNIT_ASSERT(location == numbers1 + 5); // no adj so loc should be _last - - location = adjacent_find((int*)numbers2, (int*)numbers2 + 5); - CPPUNIT_ASSERT(location != numbers2 + 5); // adj location off should be 3 (first 1) - CPPUNIT_ASSERT((location - numbers2)==3); -} -void AdjTest::adjfind1() -{ - typedef vector<int> IntVector; - IntVector v(10); - for (int i = 0; (size_t)i < v.size(); ++i) - v[i] = i; - IntVector::iterator location; - location = adjacent_find(v.begin(), v.end()); - CPPUNIT_ASSERT(location == v.end()); - v[6] = 7; - location = adjacent_find(v.begin(), v.end()); - CPPUNIT_ASSERT(location != v.end()); -} -void AdjTest::adjfind2() -{ - typedef vector <const char*> CStrVector; - - const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" }; - - const int nameCount = sizeof(names)/sizeof(names[0]); - CStrVector v(nameCount); - for(int i = 0; i < nameCount; i++) - v[i] = names[i]; - CStrVector::iterator location; - location = adjacent_find(v.begin(), v.end(), equal_length); - - CPPUNIT_ASSERT(location != v.end()); -} -int AdjTest::equal_length(const char* v1_, const char* v2_) -{ - return ::strlen(v1_) == ::strlen(v2_); -} -void AdjTest::adjdiff0() -{ - int numbers[5] = { 1, 2, 4, 8, 16 }; - int difference[5]; - adjacent_difference(numbers, numbers + 5, (int*)difference); - CPPUNIT_ASSERT(difference[0]==1); - CPPUNIT_ASSERT(difference[1]==1); - CPPUNIT_ASSERT(difference[2]==2); - CPPUNIT_ASSERT(difference[3]==4); - CPPUNIT_ASSERT(difference[4]==8); -} -void AdjTest::adjdiff1() -{ - vector <int> v(10); - for(int i = 0; (size_t)i < v.size(); ++i) - v[i] = i * i; - vector<int> result(v.size()); - adjacent_difference(v.begin(), v.end(), result.begin()); - CPPUNIT_ASSERT(result[0]==0) - CPPUNIT_ASSERT(result[1]==1) - CPPUNIT_ASSERT(result[2]==3) - CPPUNIT_ASSERT(result[3]==5) - CPPUNIT_ASSERT(result[4]==7) - CPPUNIT_ASSERT(result[5]==9) - CPPUNIT_ASSERT(result[6]==11) - CPPUNIT_ASSERT(result[7]==13) - CPPUNIT_ASSERT(result[8]==15) - CPPUNIT_ASSERT(result[9]==17) -} -void AdjTest::adjdiff2() -{ - vector <int> v(10); - for (int i = 0; (size_t)i < v.size(); ++i) - v[i] = i + 1; - vector <int> result(v.size()); - adjacent_difference(v.begin(), v.end(), result.begin(), mult); - CPPUNIT_ASSERT(result[0]==1) - CPPUNIT_ASSERT(result[1]==2) - CPPUNIT_ASSERT(result[2]==6) - CPPUNIT_ASSERT(result[3]==12) - CPPUNIT_ASSERT(result[4]==20) - CPPUNIT_ASSERT(result[5]==30) - CPPUNIT_ASSERT(result[6]==42) - CPPUNIT_ASSERT(result[7]==56) - CPPUNIT_ASSERT(result[8]==72) - CPPUNIT_ASSERT(result[9]==90) -} -int AdjTest::mult(int a_, int b_) -{ - return a_ * b_; -} diff --git a/test/unit/advance_test.cpp b/test/unit/advance_test.cpp deleted file mode 100644 index bd7a168..0000000 --- a/test/unit/advance_test.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class AdvanceTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(AdvanceTest); - CPPUNIT_TEST(adv); - CPPUNIT_TEST_SUITE_END(); - -protected: - void adv(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(AdvanceTest); - -// -// tests implementation -// -void AdvanceTest::adv() -{ - typedef vector <int> IntVector; - IntVector v(10); - for (int i = 0; (size_t)i < v.size(); ++i) - v[i] = i; - IntVector::iterator location = v.begin(); - CPPUNIT_ASSERT(*location==0); - advance(location, 5); - CPPUNIT_ASSERT(*location==5); -} diff --git a/test/unit/alg_test.cpp b/test/unit/alg_test.cpp deleted file mode 100644 index da4977a..0000000 --- a/test/unit/alg_test.cpp +++ /dev/null @@ -1,364 +0,0 @@ -#include <list> -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <slist> -#endif -#include <deque> -#include <vector> -#include <algorithm> -#include <functional> -#include <map> -#include <string> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class AlgTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(AlgTest); - CPPUNIT_TEST(min_max); - CPPUNIT_TEST(count_test); - CPPUNIT_TEST(sort_test); - CPPUNIT_TEST(search_n_test); - CPPUNIT_TEST(find_first_of_test); - CPPUNIT_TEST(find_first_of_nsc_test); - CPPUNIT_TEST_SUITE_END(); - -protected: - void min_max(); - void count_test(); - void sort_test(); - void search_n_test(); - void find_first_of_test(); - void find_first_of_nsc_test(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(AlgTest); - -// -// tests implementation -// -void AlgTest::min_max() -{ - int i = min(4, 7); - CPPUNIT_ASSERT( i == 4 ); - char c = max('a', 'z'); - CPPUNIT_ASSERT( c == 'z' ); - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - c = min('a', 'z', greater<char>()); - CPPUNIT_ASSERT( c == 'z' ); - i = max(4, 7, greater<int>()); - CPPUNIT_ASSERT( i == 4 ); -#endif -} - -void AlgTest::count_test() -{ - { - int i[] = { 1, 4, 2, 8, 2, 2 }; - int n = count(i, i + 6, 2); - CPPUNIT_ASSERT(n==3); -#if defined (STLPORT) && !defined (_STLP_NO_ANACHRONISMS) - n = 0; - count(i, i + 6, 2, n); - CPPUNIT_ASSERT(n==3); -#endif - } - { - vector<int> i; - i.push_back(1); - i.push_back(4); - i.push_back(2); - i.push_back(8); - i.push_back(2); - i.push_back(2); - int n = count(i.begin(), i.end(), 2); - CPPUNIT_ASSERT(n==3); -#if defined (STLPORT) && !defined (_STLP_NO_ANACHRONISMS) - n = 0; - count(i.begin(), i.end(), 2, n); - CPPUNIT_ASSERT(n==3); -#endif - } -} - -void AlgTest::sort_test() -{ - { - vector<int> years; - years.push_back(1962); - years.push_back(1992); - years.push_back(2001); - years.push_back(1999); - sort(years.begin(), years.end()); - CPPUNIT_ASSERT(years[0]==1962); - CPPUNIT_ASSERT(years[1]==1992); - CPPUNIT_ASSERT(years[2]==1999); - CPPUNIT_ASSERT(years[3]==2001); - } - { - deque<int> years; - years.push_back(1962); - years.push_back(1992); - years.push_back(2001); - years.push_back(1999); - sort(years.begin(), years.end()); // <-- changed! - CPPUNIT_ASSERT(years[0]==1962); - CPPUNIT_ASSERT(years[1]==1992); - CPPUNIT_ASSERT(years[2]==1999); - CPPUNIT_ASSERT(years[3]==2001); - } -} - -#define ARRAY_SIZE(arr) sizeof(arr) / sizeof(arr[0]) - -void AlgTest::search_n_test() -{ - int ints[] = {0, 1, 2, 3, 3, 4, 4, 4, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5}; - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - //search_n - //Forward iterator - { - slist<int> slint(ints, ints + ARRAY_SIZE(ints)); - slist<int>::iterator slit = search_n(slint.begin(), slint.end(), 2, 2); - CPPUNIT_ASSERT( slit != slint.end() ); - CPPUNIT_ASSERT( *(slit++) == 2 ); - CPPUNIT_ASSERT( *slit == 2 ); - } -#endif - - //Bidirectionnal iterator - { - list<int> lint(ints, ints + ARRAY_SIZE(ints)); - list<int>::iterator lit = search_n(lint.begin(), lint.end(), 3, 3); - CPPUNIT_ASSERT( lit != lint.end() ); - CPPUNIT_ASSERT( *(lit++) == 3 ); - CPPUNIT_ASSERT( *(lit++) == 3 ); - CPPUNIT_ASSERT( *lit == 3 ); - } - - //Random access iterator - { - deque<int> dint(ints, ints + ARRAY_SIZE(ints)); - deque<int>::iterator dit = search_n(dint.begin(), dint.end(), 4, 4); - CPPUNIT_ASSERT( dit != dint.end() ); - CPPUNIT_ASSERT( *(dit++) == 4 ); - CPPUNIT_ASSERT( *(dit++) == 4 ); - CPPUNIT_ASSERT( *(dit++) == 4 ); - CPPUNIT_ASSERT( *dit == 4 ); - } - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - //search_n with predicate - //Forward iterator - { - slist<int> slint(ints, ints + ARRAY_SIZE(ints)); - slist<int>::iterator slit = search_n(slint.begin(), slint.end(), 2, 1, greater<int>()); - CPPUNIT_ASSERT( slit != slint.end() ); - CPPUNIT_ASSERT( *(slit++) > 1 ); - CPPUNIT_ASSERT( *slit > 2 ); - } -#endif - - //Bidirectionnal iterator - { - list<int> lint(ints, ints + ARRAY_SIZE(ints)); - list<int>::iterator lit = search_n(lint.begin(), lint.end(), 3, 2, greater<int>()); - CPPUNIT_ASSERT( lit != lint.end() ); - CPPUNIT_ASSERT( *(lit++) > 2 ); - CPPUNIT_ASSERT( *(lit++) > 2 ); - CPPUNIT_ASSERT( *lit > 2 ); - } - - //Random access iterator - { - deque<int> dint(ints, ints + ARRAY_SIZE(ints)); - deque<int>::iterator dit = search_n(dint.begin(), dint.end(), 4, 3, greater<int>()); - CPPUNIT_ASSERT( dit != dint.end() ); - CPPUNIT_ASSERT( *(dit++) > 3 ); - CPPUNIT_ASSERT( *(dit++) > 3 ); - CPPUNIT_ASSERT( *(dit++) > 3 ); - CPPUNIT_ASSERT( *dit > 3 ); - } - - // test for bug reported by Jim Xochellis - { - int array[] = {0, 0, 1, 0, 1, 1}; - int* array_end = array + sizeof(array) / sizeof(*array); - CPPUNIT_ASSERT(search_n(array, array_end, 3, 1) == array_end); - } - - // test for bug with counter == 1, reported by Timmie Smith - { - int array[] = {0, 1, 2, 3, 4, 5}; - int* array_end = array + sizeof(array) / sizeof(*array); - CPPUNIT_ASSERT( search_n(array, array_end, 1, 1, equal_to<int>() ) == &array[1] ); - } -} - -struct MyIntComparable { - MyIntComparable(int val) : _val(val) {} - bool operator == (const MyIntComparable& other) const - { return _val == other._val; } - -private: - int _val; -}; - -void AlgTest::find_first_of_test() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - slist<int> intsl; - intsl.push_front(1); - intsl.push_front(2); - - { - vector<int> intv; - intv.push_back(0); - intv.push_back(1); - intv.push_back(2); - intv.push_back(3); - - vector<int>::iterator first; - first = find_first_of(intv.begin(), intv.end(), intsl.begin(), intsl.end()); - CPPUNIT_ASSERT( first != intv.end() ); - CPPUNIT_ASSERT( *first == 1 ); - } - { - vector<int> intv; - intv.push_back(3); - intv.push_back(2); - intv.push_back(1); - intv.push_back(0); - - vector<int>::iterator first; - first = find_first_of(intv.begin(), intv.end(), intsl.begin(), intsl.end()); - CPPUNIT_ASSERT( first != intv.end() ); - CPPUNIT_ASSERT( *first == 2 ); - } -#endif - - list<int> intl; - intl.push_front(1); - intl.push_front(2); - - { - vector<int> intv; - intv.push_back(0); - intv.push_back(1); - intv.push_back(2); - intv.push_back(3); - - vector<int>::iterator first; - first = find_first_of(intv.begin(), intv.end(), intl.begin(), intl.end()); - CPPUNIT_ASSERT( first != intv.end() ); - CPPUNIT_ASSERT( *first == 1 ); - } - { - vector<int> intv; - intv.push_back(3); - intv.push_back(2); - intv.push_back(1); - intv.push_back(0); - - vector<int>::iterator first; - first = find_first_of(intv.begin(), intv.end(), intl.begin(), intl.end()); - CPPUNIT_ASSERT( first != intv.end() ); - CPPUNIT_ASSERT( *first == 2 ); - } - { - char chars[] = {1, 2}; - - vector<int> intv; - intv.push_back(0); - intv.push_back(1); - intv.push_back(2); - intv.push_back(3); - - vector<int>::iterator first; - first = find_first_of(intv.begin(), intv.end(), chars, chars + sizeof(chars)); - CPPUNIT_ASSERT( first != intv.end() ); - CPPUNIT_ASSERT( *first == 1 ); - } - { - unsigned char chars[] = {1, 2, 255}; - - vector<int> intv; - intv.push_back(-10); - intv.push_back(1029); - intv.push_back(255); - intv.push_back(4); - - vector<int>::iterator first; - first = find_first_of(intv.begin(), intv.end(), chars, chars + sizeof(chars)); - CPPUNIT_ASSERT( first != intv.end() ); - CPPUNIT_ASSERT( *first == 255 ); - } - { - signed char chars[] = {93, 2, -101, 13}; - - vector<int> intv; - intv.push_back(-10); - intv.push_back(1029); - intv.push_back(-2035); - intv.push_back(-101); - intv.push_back(4); - - vector<int>::iterator first; - first = find_first_of(intv.begin(), intv.end(), chars, chars + sizeof(chars)); - CPPUNIT_ASSERT( first != intv.end() ); - CPPUNIT_ASSERT( *first == -101 ); - } - { - char chars[] = {1, 2}; - - vector<MyIntComparable> intv; - intv.push_back(0); - intv.push_back(1); - intv.push_back(2); - intv.push_back(3); - - vector<MyIntComparable>::iterator first; - first = find_first_of(intv.begin(), intv.end(), chars, chars + sizeof(chars)); - CPPUNIT_ASSERT( first != intv.end() ); - CPPUNIT_ASSERT( *first == 1 ); - } -} - -typedef pair<int, string> Pair; - -struct ValueFinder : - public binary_function<const Pair&, const string&, bool> -{ - bool operator () ( const Pair &p, const string& value ) const - { return p.second == value; } -}; - -void AlgTest::find_first_of_nsc_test() -{ - // Non-symmetrical comparator - - map<int, string> m; - vector<string> values; - - m[1] = "one"; - m[4] = "four"; - m[10] = "ten"; - m[20] = "twenty"; - - values.push_back( "four" ); - values.push_back( "ten" ); - - map<int, string>::iterator i = find_first_of(m.begin(), m.end(), values.begin(), values.end(), ValueFinder()); - - CPPUNIT_ASSERT( i != m.end() ); - CPPUNIT_ASSERT( i->first == 4 || i->first == 10 ); - CPPUNIT_ASSERT( i->second == "four" || i->second == "ten" ); -} diff --git a/test/unit/algorithm_header_test.cpp b/test/unit/algorithm_header_test.cpp deleted file mode 100644 index 8c3577f..0000000 --- a/test/unit/algorithm_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <algorithm> diff --git a/test/unit/allocator_test.cpp b/test/unit/allocator_test.cpp deleted file mode 100644 index 2760cd1..0000000 --- a/test/unit/allocator_test.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include <memory> -#include <vector> - -#include <cstdio> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class AllocatorTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(AllocatorTest); - CPPUNIT_TEST(zero_allocation); -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - CPPUNIT_TEST(bad_alloc_test); -#endif -#if defined (STLPORT) && defined (_STLP_THREADS) && defined (_STLP_USE_PERTHREAD_ALLOC) - CPPUNIT_TEST(per_thread_alloc); -#endif - CPPUNIT_TEST_SUITE_END(); - -protected: - void zero_allocation(); - void bad_alloc_test(); - void per_thread_alloc(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(AllocatorTest); - -// -// tests implementation -// -void AllocatorTest::zero_allocation() -{ - typedef allocator<char> CharAllocator; - CharAllocator charAllocator; - - char* buf = charAllocator.allocate(0); - charAllocator.deallocate(buf, 0); - - charAllocator.deallocate(0, 0); -} - -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - -struct BigStruct -{ - char _data[4096]; -}; - -void AllocatorTest::bad_alloc_test() -{ - typedef allocator<BigStruct> BigStructAllocType; - BigStructAllocType bigStructAlloc; - - try { - //Lets try to allocate almost 4096 Go (on most of the platforms) of memory: - BigStructAllocType::pointer pbigStruct = bigStructAlloc.allocate(1024 * 1024 * 1024); - - //Allocation failed but no exception thrown - CPPUNIT_ASSERT( pbigStruct != 0 ); - - // Just it case it succeeds: - bigStructAlloc.deallocate(pbigStruct, 1024 * 1024 * 1024); - } - catch (bad_alloc const&) { - } - catch (...) { - //We shouldn't be there: - //Not bad_alloc exception thrown. - CPPUNIT_FAIL; - } -} -#endif - -#if defined (STLPORT) && defined (_STLP_THREADS) && defined (_STLP_USE_PERTHREAD_ALLOC) -# include <pthread.h> - -class SharedDatas -{ -public: - typedef vector<int, per_thread_allocator<int> > thread_vector; - - SharedDatas(size_t nbElems) : threadVectors(nbElems, (thread_vector*)0) { - pthread_mutex_init(&mutex, 0); - pthread_cond_init(&condition, 0); - } - - ~SharedDatas() { - for (size_t i = 0; i < threadVectors.size(); ++i) { - delete threadVectors[i]; - } - } - - size_t initThreadVector() { - size_t ret; - - pthread_mutex_lock(&mutex); - - for (size_t i = 0; i < threadVectors.size(); ++i) { - if (threadVectors[i] == 0) { - threadVectors[i] = new thread_vector(); - ret = i; - break; - } - } - - if (ret != threadVectors.size() - 1) { - //We wait for other thread(s) to call this method too: - printf("Thread %d wait\n", ret); - pthread_cond_wait(&condition, &mutex); - } - else { - //We are the last thread calling this method, we signal this - //to the other thread(s) that might be waiting: - printf("Thread %d signal\n", ret); - pthread_cond_signal(&condition); - } - - pthread_mutex_unlock(&mutex); - - return ret; - } - - thread_vector& getThreadVector(size_t index) { - //We return other thread thread_vector instance: - return *threadVectors[(index + 1 == threadVectors.size()) ? 0 : index + 1]; - } - -private: - pthread_mutex_t mutex; - pthread_cond_t condition; - vector<thread_vector*> threadVectors; -}; - -void* f(void* pdatas) { - SharedDatas *psharedDatas = (SharedDatas*)pdatas; - - int threadIndex = psharedDatas->initThreadVector(); - - for (int i = 0; i < 100; ++i) { - psharedDatas->getThreadVector(threadIndex).push_back(i); - } - - return 0; -} - -void AllocatorTest::per_thread_alloc() -{ - const size_t nth = 2; - SharedDatas datas(nth); - pthread_t t[nth]; - - size_t i; - for (i = 0; i < nth; ++i) { - pthread_create(&t[i], 0, f, &datas); - } - - for (i = 0; i < nth; ++i ) { - pthread_join(t[i], 0); - } -} -#endif diff --git a/test/unit/assert_header_test.c b/test/unit/assert_header_test.c deleted file mode 100644 index a478877..0000000 --- a/test/unit/assert_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <assert.h> diff --git a/test/unit/bcompos_test.cpp b/test/unit/bcompos_test.cpp deleted file mode 100644 index d117fab..0000000 --- a/test/unit/bcompos_test.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include <algorithm> -#include "unary.h" - -#include "cppunit/cppunit_proxy.h" - -#if defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class BcomposTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(BcomposTest); -#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(bcompos1); - CPPUNIT_TEST(bcompos2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void bcompos1(); - void bcompos2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(BcomposTest); - -// -// tests implementation -// -void BcomposTest::bcompos1() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - int array [6] = { -2, -1, 0, 1, 2, 3 }; - - binary_compose<logical_and<bool>, odd, positive> - b = binary_compose<logical_and<bool>, odd, positive>(logical_and<bool>(), odd(), positive()); - - int* p = find_if((int*)array, (int*)array + 6, b); - CPPUNIT_ASSERT(p != array + 6); -#endif -} - -void BcomposTest::bcompos2() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - int array [6] = { -2, -1 , 0, 1, 2, 3 }; - - int* p = find_if((int*)array, (int*)array + 6, - compose2(logical_and<bool>(), odd(), positive())); - CPPUNIT_ASSERT(p != array + 6); -#endif -} diff --git a/test/unit/bind_test.cpp b/test/unit/bind_test.cpp deleted file mode 100644 index 8773baa..0000000 --- a/test/unit/bind_test.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class BindTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(BindTest); - CPPUNIT_TEST(bind1st1); - CPPUNIT_TEST(bind2nd1); - CPPUNIT_TEST(bind2nd2); -#if !defined (STLPORT) || \ - defined (_STLP_NO_EXTENSIONS) || !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(bind2nd3); - CPPUNIT_TEST(bind_memfn); - CPPUNIT_TEST_SUITE_END(); - -protected: - void bind1st1(); - void bind2nd1(); - void bind2nd2(); - void bind2nd3(); - void bind_memfn(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(BindTest); - -class pre_increment : public binary_function<int, int, int> { -public: - int operator()(int incr, int& val) const - { return val += incr; } -}; - -class post_increment : public binary_function<int, int, int> { -public: - int operator()(int& val, int incr) const - { return val += incr; } -}; - - -// -// tests implementation -// -void BindTest::bind1st1() -{ - int array [3] = { 1, 2, 3 }; - int* p = remove_if((int*)array, (int*)array + 3, bind1st(less<int>(), 2)); - - CPPUNIT_ASSERT(p == &array[2]); - CPPUNIT_ASSERT(array[0] == 1); - CPPUNIT_ASSERT(array[1] == 2); - - for_each((int*)array, (int*)array + 3, bind1st(pre_increment(), 1)); - CPPUNIT_ASSERT(array[0] == 2); - CPPUNIT_ASSERT(array[1] == 3); - CPPUNIT_ASSERT(array[2] == 4); - - for_each((int*)array, (int*)array + 3, bind2nd(post_increment(), 1)); - CPPUNIT_ASSERT(array[0] == 3); - CPPUNIT_ASSERT(array[1] == 4); - CPPUNIT_ASSERT(array[2] == 5); -} - -void BindTest::bind2nd1() -{ - int array [3] = { 1, 2, 3 }; - replace_if(array, array + 3, binder2nd<greater<int> >(greater<int>(), 2), 4); - - CPPUNIT_ASSERT(array[0]==1); - CPPUNIT_ASSERT(array[1]==2); - CPPUNIT_ASSERT(array[2]==4); -} -void BindTest::bind2nd2() -{ - int array [3] = { 1, 2, 3 }; - replace_if(array, array + 3, bind2nd(greater<int>(), 2), 4); - CPPUNIT_ASSERT(array[0]==1); - CPPUNIT_ASSERT(array[1]==2); - CPPUNIT_ASSERT(array[2]==4); -} - -int test_func1 (const int ¶m1, const int ¶m2) { - return param1 + param2; -} - -int test_func2 (int ¶m1, int param2) { - param1 += param2; - return param1 + param2; -} - -void BindTest::bind2nd3() -{ -#if defined (STLPORT) && \ - !defined (_STLP_NO_EXTENSIONS) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - int array[3] = { 1, 2, 3 }; - transform(array, array + 3, array, bind2nd(ptr_fun(test_func1), 1)); - transform(array, array + 3, array, bind1st(ptr_fun(test_func1), -1)); - CPPUNIT_ASSERT(array[0] == 1); - CPPUNIT_ASSERT(array[1] == 2); - CPPUNIT_ASSERT(array[2] == 3); - - transform(array, array + 3, array, bind2nd(ptr_fun(test_func2), 10)); - CPPUNIT_ASSERT(array[0] == 21); - CPPUNIT_ASSERT(array[1] == 22); - CPPUNIT_ASSERT(array[2] == 23); -#endif -} - -class A -{ - public: - A() : m_n( 0 ) - {} - - void f( int n ) const { -#if defined (STLPORT) - _STLP_MUTABLE(A, m_n) = n; -#else - m_n = n; -#endif - } - - int v() const - { return m_n; } - - private: - mutable int m_n; -}; - -void BindTest::bind_memfn() -{ -#if defined (STLPORT) && \ - !defined (_STLP_NO_EXTENSIONS) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - A array[3]; - - for_each( array, array + 3, bind2nd( mem_fun_ref(&A::f), 12 ) ); - - CPPUNIT_CHECK( array[0].v() == 12 ); -#endif -} diff --git a/test/unit/binsert_test.cpp b/test/unit/binsert_test.cpp deleted file mode 100644 index e085a5c..0000000 --- a/test/unit/binsert_test.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class BinsertTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(BinsertTest); - CPPUNIT_TEST(binsert1); - CPPUNIT_TEST(binsert2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void binsert1(); - void binsert2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(BinsertTest); - -// -// tests implementation -// -void BinsertTest::binsert1() -{ - const char* array [] = { "laurie", "jennifer", "leisa" }; - vector<const char*> names; - back_insert_iterator<vector<const char*> > bit(names); - bit = copy(array, array + 3, bit); - - CPPUNIT_ASSERT(!strcmp(names[0],array[0])); - CPPUNIT_ASSERT(!strcmp(names[1],array[1])); - CPPUNIT_ASSERT(!strcmp(names[2],array[2])); - - copy(array, array + 3, bit); - CPPUNIT_ASSERT(!strcmp(names[3],array[0])); - CPPUNIT_ASSERT(!strcmp(names[4],array[1])); - CPPUNIT_ASSERT(!strcmp(names[5],array[2])); -} -void BinsertTest::binsert2() -{ - const char* array [] = { "laurie", "jennifer", "leisa" }; - vector<const char*> names; - copy(array, array + 3, back_inserter(names)); - CPPUNIT_ASSERT(!strcmp(names[0],array[0])); - CPPUNIT_ASSERT(!strcmp(names[1],array[1])); - CPPUNIT_ASSERT(!strcmp(names[2],array[2])); -} diff --git a/test/unit/bitset_header_test.cpp b/test/unit/bitset_header_test.cpp deleted file mode 100644 index dbd5cc2..0000000 --- a/test/unit/bitset_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <bitset> diff --git a/test/unit/bitset_test.cpp b/test/unit/bitset_test.cpp deleted file mode 100644 index 141f646..0000000 --- a/test/unit/bitset_test.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include <bitset> -#include <algorithm> -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <sstream> -#endif - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class BitsetTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(BitsetTest); - CPPUNIT_TEST(bitset1); -#if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(iostream); - CPPUNIT_TEST_SUITE_END(); - -protected: - void bitset1(); - void iostream(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(BitsetTest); - -// -// tests implementation -// -void BitsetTest::bitset1() -{ - bitset<13U> b1(0xFFFF); - bitset<13U> b2(0x1111); - CPPUNIT_ASSERT(b1.size() == 13); - CPPUNIT_ASSERT(b1 == 0x1FFF); - CPPUNIT_ASSERT(b2.size() == 13); - CPPUNIT_ASSERT(b2 == 0x1111); - -#if !defined (STLPORT) || !defined (_STLP_NON_TYPE_TMPL_PARAM_BUG) - b1 = b1 ^ (b2 << 2); - CPPUNIT_ASSERT(b1 == 0x1BBB); - - CPPUNIT_ASSERT(b1.count() == 10); - CPPUNIT_ASSERT(b2.count() == 4); - -# if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - size_t __pos = b2._Find_first(); - CPPUNIT_ASSERT( __pos == 0 ); - __pos = b2._Find_next(__pos); - CPPUNIT_ASSERT( __pos == 4 ); - __pos = b2._Find_next(__pos); - CPPUNIT_ASSERT( __pos == 8 ); - __pos = b2._Find_next(__pos); - CPPUNIT_ASSERT( __pos == 12 ); - __pos = b2._Find_next(__pos); - CPPUNIT_ASSERT( __pos == 13 ); -# endif -#endif - -#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS) - string representation = b2.to_string<char, char_traits<char>, allocator<char> >(); - CPPUNIT_ASSERT( representation == "1000100010001" ); -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) - wstring wrepresentation = b2.to_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >(); - CPPUNIT_ASSERT( wrepresentation == L"1000100010001" ); -# endif -#else - CPPUNIT_ASSERT( b2.to_string() == "1000100010001" ); -#endif -} - -void BitsetTest::iostream() -{ -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) - { - stringstream sstr; - bitset<13U> b(0x1111); - sstr << b; - CPPUNIT_ASSERT( sstr.str() == "1000100010001" ); - - bitset<13U> b1; - sstr >> b1; - CPPUNIT_ASSERT( b1.test(0) ); - CPPUNIT_ASSERT( b1.test(4) ); - CPPUNIT_ASSERT( b1.test(8) ); - CPPUNIT_ASSERT( b1.test(12) ); - } -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) - { - wstringstream sstr; - bitset<13U> b(0x1111); - sstr << b; - CPPUNIT_ASSERT( sstr.str() == L"1000100010001" ); - - bitset<13U> b1; - sstr >> b1; - CPPUNIT_ASSERT( b1.test(0) ); - CPPUNIT_ASSERT( b1.test(4) ); - CPPUNIT_ASSERT( b1.test(8) ); - CPPUNIT_ASSERT( b1.test(12) ); - } -# endif -#endif -} diff --git a/test/unit/bnegate_test.cpp b/test/unit/bnegate_test.cpp deleted file mode 100644 index 888b036..0000000 --- a/test/unit/bnegate_test.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class BnegateTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(BnegateTest); - CPPUNIT_TEST(bnegate1); - CPPUNIT_TEST(bnegate2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void bnegate1(); - void bnegate2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(BnegateTest); - -// -// tests implementation -// -void BnegateTest::bnegate1() -{ - int array [4] = { 4, 9, 7, 1 }; - - sort(array, array + 4, binary_negate<greater<int> >(greater<int>())); - CPPUNIT_ASSERT(array[0]==1); - CPPUNIT_ASSERT(array[1]==4); - CPPUNIT_ASSERT(array[2]==7); - CPPUNIT_ASSERT(array[3]==9); -} -void BnegateTest::bnegate2() -{ - int array [4] = { 4, 9, 7, 1 }; - sort(array, array + 4, not2(greater<int>())); - CPPUNIT_ASSERT(array[0]==1); - CPPUNIT_ASSERT(array[1]==4); - CPPUNIT_ASSERT(array[2]==7); - CPPUNIT_ASSERT(array[3]==9); -} diff --git a/test/unit/boost_check.cpp b/test/unit/boost_check.cpp deleted file mode 100644 index 4bf7b95..0000000 --- a/test/unit/boost_check.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef WITHOUT_STLPORT -#include <stl/config/user_config.h> - -#ifdef _STLP_USE_BOOST_SUPPORT - -#include <boost/config.hpp> - -#endif // _STLP_USE_BOOST_SUPPORT - -#else - -#if 0 // Problem 1: -/* ******************************* -../../../stlport/functional:63: error: 'boost::mem_fn' has not been declared -../../../stlport/functional:64: error: 'boost::bind' has not been declared -../../../stlport/functional:67: error: '::_1' has not been declared -../../../stlport/functional:68: error: '::_2' has not been declared -../../../stlport/functional:69: error: '::_3' has not been declared -../../../stlport/functional:70: error: '::_4' has not been declared -../../../stlport/functional:71: error: '::_5' has not been declared -../../../stlport/functional:72: error: '::_6' has not been declared -../../../stlport/functional:73: error: '::_7' has not been declared -../../../stlport/functional:74: error: '::_8' has not been declared -../../../stlport/functional:75: error: '::_9' has not been declared - ******************************* */ - -#include <boost/bind.hpp> - -#endif // Problem 1 - -#if 0 // Problem 2 - -#include <boost/function.hpp> - -#endif // Problem 2 - -#if 0 // Problem 3 - -#include <boost/function/function_base.hpp> - -#endif // Problem 3 - -#if 0 // Problem 4 - -#include <boost/function/function1.hpp> - -#endif // Problem 4 - -#endif diff --git a/test/unit/bound_test.cpp b/test/unit/bound_test.cpp deleted file mode 100644 index f7cc6e2..0000000 --- a/test/unit/bound_test.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class BoundTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(BoundTest); - CPPUNIT_TEST(lwrbnd1); - CPPUNIT_TEST(lwrbnd2); - CPPUNIT_TEST(uprbnd1); - CPPUNIT_TEST(uprbnd2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void lwrbnd1(); - void lwrbnd2(); - void uprbnd1(); - void uprbnd2(); - - static bool char_str_less(const char* a_, const char* b_) - { - return strcmp(a_, b_) < 0 ? 1 : 0; - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(BoundTest); - -// -// tests implementation -// -void BoundTest::uprbnd1() -{ - int arr[20]; - for(int i = 0; i < 20; i++) - { - arr[i] = i/4; - } - int location = upper_bound((int*)arr, (int*)arr + 20, 3) - arr; - CPPUNIT_ASSERT(location==16); -} - -void BoundTest::uprbnd2() -{ - char const* str [] = { "a", "a", "b", "b", "q", "w", "z" }; - - const unsigned strCt = sizeof(str)/sizeof(str[0]); - - int location = (upper_bound((char const**)str, (char const**)str + strCt, (const char *)"d", char_str_less) - str); - CPPUNIT_ASSERT(location==4); -} -void BoundTest::lwrbnd1() -{ - vector <int> v1(20); - for (int i = 0; (size_t)i < v1.size(); ++i) - { - v1[i] = i/4; - } - // 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 - vector<int>::iterator location = lower_bound(v1.begin(), v1.end(), 3); - - CPPUNIT_ASSERT((location - v1.begin())==12); -} - -void BoundTest::lwrbnd2() -{ - char const* str [] = { "a", "a", "b", "b", "q", "w", "z" }; - - const unsigned strCt = sizeof(str)/sizeof(str[0]); - char const** location = lower_bound((char const**)str, (char const**)str + strCt, (const char *)"d", char_str_less); - - CPPUNIT_ASSERT((location - str) == 4); -} diff --git a/test/unit/bsearch_test.cpp b/test/unit/bsearch_test.cpp deleted file mode 100644 index 27dcc02..0000000 --- a/test/unit/bsearch_test.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class BsearchTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(BsearchTest); - CPPUNIT_TEST(bsearch1); - CPPUNIT_TEST(bsearch2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void bsearch1(); - void bsearch2(); - static bool str_compare(const char* a_, const char* b_); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(BsearchTest); - -// -// tests implementation -// -void BsearchTest::bsearch1() -{ - int vector[100]; - for(int i = 0; i < 100; i++) - vector[i] = i; - CPPUNIT_ASSERT(binary_search(vector, vector + 100, 42)); -} - -void BsearchTest::bsearch2() -{ - char const* labels[] = { "aa", "dd", "ff", "jj", "ss", "zz" }; - const unsigned count = sizeof(labels) / sizeof(labels[0]); - // DEC C++ generates incorrect template instatiation code - // for "ff" so must cast - CPPUNIT_ASSERT(binary_search(labels, labels + count, (const char *)"ff", str_compare)); -} -bool BsearchTest::str_compare(const char* a_, const char* b_) -{ - return strcmp(a_, b_) < 0 ? 1 : 0; -} diff --git a/test/unit/bvector_test.cpp b/test/unit/bvector_test.cpp deleted file mode 100644 index b0c4912..0000000 --- a/test/unit/bvector_test.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include <vector> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class BvectorTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(BvectorTest); -#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(bvec1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void bvec1(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(BvectorTest); - -// -// tests implementation -// -void BvectorTest::bvec1() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - bool ii[3]= {1,0,1}; - bit_vector b(3); - - CPPUNIT_ASSERT(b[0]==0); - CPPUNIT_ASSERT(b[1]==0); - CPPUNIT_ASSERT(b[2]==0); - - b[0] = b[2] = 1; - - CPPUNIT_ASSERT(b[0]==1); - CPPUNIT_ASSERT(b[1]==0); - CPPUNIT_ASSERT(b[2]==1); - - b.insert(b.begin(),(bool*)ii, ii+2); - - CPPUNIT_ASSERT(b[0]==1); - CPPUNIT_ASSERT(b[1]==0); - CPPUNIT_ASSERT(b[2]==1); - CPPUNIT_ASSERT(b[3]==0); - CPPUNIT_ASSERT(b[4]==1); - - bit_vector bb = b; - if (bb != b) - exit(1); - - b[0] |= 0; - b[1] |= 0; - b[2] |= 1; - b[3] |= 1; - CPPUNIT_ASSERT(!((b[0] != 1) || (b[1] != 0) || (b[2] != 1) || (b[3] != 1))); - - - bb[0] &= 0; - bb[1] &= 0; - bb[2] &= 1; - bb[3] &= 1; - CPPUNIT_ASSERT(!((bb[0] != 0) || (bb[1] != 0) || (bb[2] != 1) || (bb[3] != 0))); -#endif -} diff --git a/test/unit/c_limits_header_test.c b/test/unit/c_limits_header_test.c deleted file mode 100644 index 04b2bf2..0000000 --- a/test/unit/c_limits_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <limits.h> diff --git a/test/unit/c_locale_header_test.c b/test/unit/c_locale_header_test.c deleted file mode 100644 index 8dbec46..0000000 --- a/test/unit/c_locale_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <locale.h> diff --git a/test/unit/cassert_header_test.cpp b/test/unit/cassert_header_test.cpp deleted file mode 100644 index bafdf32..0000000 --- a/test/unit/cassert_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cassert> diff --git a/test/unit/cctype_header_test.cpp b/test/unit/cctype_header_test.cpp deleted file mode 100644 index 8a67339..0000000 --- a/test/unit/cctype_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cctype> diff --git a/test/unit/cerrno_header_test.cpp b/test/unit/cerrno_header_test.cpp deleted file mode 100644 index c0e1d5a..0000000 --- a/test/unit/cerrno_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cerrno> diff --git a/test/unit/cfloat_header_test.cpp b/test/unit/cfloat_header_test.cpp deleted file mode 100644 index 4579c73..0000000 --- a/test/unit/cfloat_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cfloat> diff --git a/test/unit/ciso646_header_test.cpp b/test/unit/ciso646_header_test.cpp deleted file mode 100644 index 4b7b257..0000000 --- a/test/unit/ciso646_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <ciso646> diff --git a/test/unit/climits_header_test.cpp b/test/unit/climits_header_test.cpp deleted file mode 100644 index cf71b9f..0000000 --- a/test/unit/climits_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <climits> diff --git a/test/unit/clocale_header_test.cpp b/test/unit/clocale_header_test.cpp deleted file mode 100644 index 5d3b36a..0000000 --- a/test/unit/clocale_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <clocale> diff --git a/test/unit/cmath_header_test.cpp b/test/unit/cmath_header_test.cpp deleted file mode 100644 index 5c9b7cb..0000000 --- a/test/unit/cmath_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cmath> diff --git a/test/unit/cmath_test.cpp b/test/unit/cmath_test.cpp deleted file mode 100644 index 07185e9..0000000 --- a/test/unit/cmath_test.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#define _STLP_DO_IMPORT_CSTD_FUNCTIONS - -#include <limits> -#include <cmath> -//We also test math functions imported from stdlib.h or -//defined in cstdlib -#include <cstdlib> - -#include "math_aux.h" -#include "cppunit/cppunit_proxy.h" - -//This test purpose is to check the right import of math.h C symbols -//into the std namespace so we do not use the using namespace std -//specification - -// -// TestCase class -// -class CMathTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(CMathTest); -#if defined (STLPORT) && !defined (_STLP_USE_NAMESPACES) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(import_checks); - CPPUNIT_TEST_SUITE_END(); - - protected: - void import_checks(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(CMathTest); - -// -// tests implementation -// -void CMathTest::import_checks() -{ -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) - int int_val = -1; - long long_val = -1l; - float float_val = -1.0f; - double double_val = -1.0; -# if !defined (_STLP_NO_LONG_DOUBLE) - long double long_double_val = -1.0l; -# endif - - CPPUNIT_CHECK( are_equals(std::abs(int_val), -int_val) ); - CPPUNIT_CHECK( are_equals(std::abs(long_val), -long_val) ); - CPPUNIT_CHECK( are_equals(std::labs(long_val), -long_val) ); - CPPUNIT_CHECK( are_equals(std::abs(float_val), -float_val) ); - CPPUNIT_CHECK( are_equals(std::abs(double_val), -double_val) ); -# if !defined (_STLP_NO_LONG_DOUBLE) - CPPUNIT_CHECK( are_equals(std::abs(long_double_val), -long_double_val) ); -# endif - - CPPUNIT_CHECK( are_equals(std::fabs(float_val), -float_val) ); - CPPUNIT_CHECK( are_equals(std::fabs(double_val), -double_val) ); -# if !defined (_STLP_NO_LONG_DOUBLE) - CPPUNIT_CHECK( are_equals(std::fabs(long_double_val), -long_double_val) ); -# endif - - std::div_t div_res = std::div(3, 2); - CPPUNIT_CHECK( div_res.quot == 1 ); - CPPUNIT_CHECK( div_res.rem == 1 ); - std::ldiv_t ldiv_res = std::ldiv(3l, 2l); - CPPUNIT_CHECK( ldiv_res.quot == 1l ); - CPPUNIT_CHECK( ldiv_res.rem == 1l ); - ldiv_res = std::div(3l, 2l); - CPPUNIT_CHECK( ldiv_res.quot == 1l ); - CPPUNIT_CHECK( ldiv_res.rem == 1l ); - - std::srand(2); - int rand_val = std::rand(); - CPPUNIT_CHECK( rand_val >= 0 && rand_val <= RAND_MAX ); - - CPPUNIT_CHECK( are_equals(std::floor(1.5), 1.0) ); - CPPUNIT_CHECK( are_equals(std::ceil(1.5), 2.0) ); - CPPUNIT_CHECK( are_equals(std::fmod(1.5, 1.0), 0.5) ); - CPPUNIT_CHECK( are_equals(std::sqrt(4.0), 2.0) ); - CPPUNIT_CHECK( are_equals(std::pow(2.0, 2), 4.0) ); - /* - * Uncomment the following to check that it generates an ambiguous call - * as there is no Standard pow(int, int) function only pow(double, int), - * pow(float, int) and some others... - * If it do not generate a compile time error it should at least give - * the good result. - */ - //CPPUNIT_CHECK( are_equals(std::pow(10, -2), 0.01) ); - CPPUNIT_CHECK( are_equals(std::pow(10.0, -2), 0.01) ); - CPPUNIT_CHECK( are_equals(std::exp(0.0), 1.0) ); - CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0)), 1.0) ); - CPPUNIT_CHECK( are_equals(std::log10(100.0), 2.0) ); -# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) - CPPUNIT_CHECK( are_equals(std::modf(100.5, &double_val), 0.5) ); - CPPUNIT_CHECK( are_equals(double_val, 100.0) ); -# endif - double_val = std::frexp(8.0, &int_val); - CPPUNIT_CHECK( are_equals(double_val * std::pow(2.0, int_val), 8.0) ); - CPPUNIT_CHECK( are_equals(std::ldexp(1.0, 2), 4.0) ); - CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0)), 1.0) ); - CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0)), 1.0) ); - CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0)), 1.0) ); - CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0, 1.0)), 1.0) ); - CPPUNIT_CHECK( are_equals(std::cosh(0.0), 1.0) ); - CPPUNIT_CHECK( are_equals(std::sinh(0.0), 0.0) ); -# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) - CPPUNIT_CHECK( are_equals(std::tanh(0.0), 0.0) ); -# endif - - CPPUNIT_CHECK( are_equals(std::floor(1.5f), 1.0f) ); - CPPUNIT_CHECK( are_equals(std::ceil(1.5f), 2.0f) ); - CPPUNIT_CHECK( are_equals(std::fmod(1.5f, 1.0f), 0.5f) ); - CPPUNIT_CHECK( are_equals(std::sqrt(4.0f), 2.0f) ); - CPPUNIT_CHECK( are_equals(std::pow(2.0f, 2), 4.0f) ); - CPPUNIT_CHECK( are_equals(std::exp(0.0f), 1.0f) ); - CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0f)), 1.0f) ); - CPPUNIT_CHECK( are_equals(std::log10(100.0f), 2.0f) ); -# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) - CPPUNIT_CHECK( are_equals(std::modf(100.5f, &float_val), 0.5f) ); - CPPUNIT_CHECK( are_equals(float_val, 100.0f) ); -# endif - float_val = std::frexp(8.0f, &int_val); - CPPUNIT_CHECK( are_equals(float_val * std::pow(2.0f, int_val), 8.0f) ); - CPPUNIT_CHECK( are_equals(std::ldexp(1.0f, 2), 4.0f) ); - CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0f)), 1.0f) ); - CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0f)), 1.0f) ); - CPPUNIT_CHECK( are_equals(std::tan(std::atan(1.0f)), 1.0f) ); - CPPUNIT_CHECK( are_equals(std::tan(std::atan2(1.0f, 1.0f)), 1.0f) ); - CPPUNIT_CHECK( are_equals(std::cosh(0.0f), 1.0f) ); - CPPUNIT_CHECK( are_equals(std::sinh(0.0f), 0.0f) ); -# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) - CPPUNIT_CHECK( are_equals(std::tanh(0.0f), 0.0f) ); -# endif - -# if !defined (_STLP_NO_LONG_DOUBLE) - CPPUNIT_CHECK( are_equals(std::floor(1.5l), 1.0l) ); - CPPUNIT_CHECK( are_equals(std::ceil(1.5l), 2.0l) ); - CPPUNIT_CHECK( are_equals(std::fmod(1.5l, 1.0l), 0.5l) ); - CPPUNIT_CHECK( are_equals(std::sqrt(4.0l), 2.0l) ); - CPPUNIT_CHECK( are_equals(std::pow(2.0l, 2), 4.0l) ); - CPPUNIT_CHECK( are_equals(std::exp(0.0l), 1.0l) ); - CPPUNIT_CHECK( are_equals(std::log(std::exp(1.0l)), 1.0l) ); - CPPUNIT_CHECK( are_equals(std::log10(100.0l), 2.0l) ); -# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_WIN64) - CPPUNIT_CHECK( are_equals(std::modf(100.5l, &long_double_val), 0.5l) ); - CPPUNIT_CHECK( are_equals(long_double_val, 100.0l) ); -# endif - long_double_val = std::frexp(8.0l, &int_val); - CPPUNIT_CHECK( are_equals(long_double_val * std::pow(2.0l, int_val), 8.0l) ); - CPPUNIT_CHECK( are_equals(std::ldexp(1.0l, 2), 4.0l) ); - CPPUNIT_CHECK( are_equals(std::cos(std::acos(1.0l)), 1.0l) ); - CPPUNIT_CHECK( are_equals(std::sin(std::asin(1.0l)), 1.0l) ); - CPPUNIT_CHECK( are_equals(std::tan(0.0l), 0.0l) ); - CPPUNIT_CHECK( are_equals(std::atan(0.0l), 0.0l) ); - CPPUNIT_CHECK( are_equals(std::atan2(0.0l, 1.0l), 0.0l) ); - CPPUNIT_CHECK( are_equals(std::cosh(0.0l), 1.0l) ); - CPPUNIT_CHECK( are_equals(std::sinh(0.0l), 0.0l) ); -# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) - CPPUNIT_CHECK( are_equals(std::tanh(0.0l), 0.0l) ); -# endif -# endif - - CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0))), 2.0) ); - CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0f))), 2.0f) ); -# if !defined (_STLP_NO_LONG_DOUBLE) - CPPUNIT_CHECK( are_equals(std::sqrt(std::sqrt(std::sqrt(256.0l))), 2.0l) ); -# endif -#endif -} diff --git a/test/unit/codecvt_test.cpp b/test/unit/codecvt_test.cpp deleted file mode 100644 index c33fe15..0000000 --- a/test/unit/codecvt_test.cpp +++ /dev/null @@ -1,654 +0,0 @@ -#include <string> - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <fstream> -# include <locale> -# include <stdexcept> -# include <cstdio> // for WEOF - -# include "cppunit/cppunit_proxy.h" - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -// -// TestCase class -// -class CodecvtTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(CodecvtTest); -#if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(variable_encoding); - CPPUNIT_STOP_IGNORE; -#if defined (STLPORT) && (defined (_STLP_NO_WCHAR_T) || !defined (_STLP_USE_EXCEPTIONS)) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(in_out_test); - CPPUNIT_TEST(length_test); - CPPUNIT_TEST(imbue_while_reading); - CPPUNIT_TEST(special_encodings); - CPPUNIT_TEST_SUITE_END(); - -protected: - void variable_encoding(); - void in_out_test(); - void length_test(); - void imbue_while_reading(); - void special_encodings(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(CodecvtTest); - -#if defined (STLPORT) -# define __NO_THROW _STLP_NOTHROW -#else -# define __NO_THROW throw() -#endif - - -/* Codecvt facet eating some characters from the external buffer. - * Transform '01' in 'a' - */ -struct eater_codecvt : public codecvt<char, char, mbstate_t> { - typedef codecvt<char,char,mbstate_t> base; - - explicit eater_codecvt(size_t refs = 0) : base(refs) {} - - // primitive conversion - virtual base::result - do_in(mbstate_t& mb, - const char* ebegin, const char* eend, const char*& ecur, - char* ibegin, char* iend, char*& icur) const __NO_THROW { - char *state = (char*)&mb; - ecur = ebegin; - icur = ibegin; - - while (ecur != eend) { - if (icur == iend) - return partial; - if (*ecur == '0' || *state == 1) { - if (*state != 1) { - ++ecur; - } - if (ecur == eend) { - *state = 1; - return ok; - } - - if (*ecur == '1') { - *icur = 'a'; - } - else { - *(icur++) = '0'; - if (icur == iend) { - if (*state != 1) { - --ecur; - } - return partial; - } - *icur = *ecur; - } - } - else { - *icur = *ecur; - } - - *state = 0; - ++icur; - ++ecur; - } - - return ok; - } - - // claim it's not a null-conversion - virtual bool do_always_noconv() const __NO_THROW - { return false; } - - // claim it doesn't have a fixed-length encoding - virtual int do_encoding() const __NO_THROW - { return 0; } - - // implemented for consistency with do_in overload - virtual int do_length(mbstate_t &state, - const char *efrom, const char *eend, size_t m) const { - char *ibegin = new char[m]; - const char *ecur = efrom; - char *icur = ibegin; - mbstate_t tmp = state; - do_in(tmp, efrom, eend, ecur, ibegin, ibegin + m, icur); - delete[] ibegin; - return ecur - efrom; - } - - virtual int do_max_length() const __NO_THROW - { return 2; } - -#ifdef __DMC__ - static locale::id id; -#endif -}; - -#ifdef __DMC__ -locale::id eater_codecvt::id; - -locale::id& _GetFacetId(const eater_codecvt*) -{ return eater_codecvt::id; } -#endif - -/* Codecvt facet generating more characters than the ones read from the - * external buffer, transform '01' in 'abc' - * This kind of facet do not allow systematical positionning in the external - * buffer (tellg -> -1), when you just read a 'a' you are at an undefined - * external buffer position. - */ -struct generator_codecvt : public codecvt<char, char, mbstate_t> { - typedef codecvt<char,char,mbstate_t> base; - - explicit generator_codecvt(size_t refs = 0) : base(refs) {} - - // primitive conversion - virtual base::result - do_in(mbstate_t& mb, - const char* ebegin, const char* eend, const char*& ecur, - char* ibegin, char* iend, char*& icur) const __NO_THROW { - //Access the mbstate information in a portable way: - char *state = (char*)&mb; - ecur = ebegin; - icur = ibegin; - - if (icur == iend) return ok; - - if (*state == 2) { - *(icur++) = 'b'; - if (icur == iend) { - *state = 3; - return ok; - } - *(icur++) = 'c'; - *state = 0; - } - else if (*state == 3) { - *(icur++) = 'c'; - *state = 0; - } - - while (ecur != eend) { - if (icur == iend) - return ok; - if (*ecur == '0' || *state == 1) { - if (*state != 1) { - ++ecur; - } - if (ecur == eend) { - *state = 1; - return partial; - } - - if (*ecur == '1') { - *(icur++) = 'a'; - if (icur == iend) { - *state = 2; - return ok; - } - *(icur++) = 'b'; - if (icur == iend) { - *state = 3; - return ok; - } - *icur = 'c'; - } - else { - *(icur++) = '0'; - if (icur == iend) { - if (*state != 1) { - --ecur; - } - return ok; - } - *icur = *ecur; - } - } - else { - *icur = *ecur; - } - - *state = 0; - ++icur; - ++ecur; - } - - return ok; - } - - // claim it's not a null-conversion - virtual bool do_always_noconv() const __NO_THROW - { return false; } - - // claim it doesn't have a fixed-length encoding - virtual int do_encoding() const __NO_THROW - { return 0; } - - // implemented for consistency with do_in overload - virtual int do_length(mbstate_t &mb, - const char *efrom, const char *eend, size_t m) const { - const char *state = (const char*)&mb; - int offset = 0; - if (*state == 2) - offset = 2; - else if (*state == 3) - offset = 1; - - char *ibegin = new char[m + offset]; - const char *ecur = efrom; - char *icur = ibegin; - mbstate_t tmpState = mb; - do_in(tmpState, efrom, eend, ecur, ibegin, ibegin + m + offset, icur); - /* - char *state = (char*)&tmpState; - if (*state != 0) { - if (*state == 1) - --ecur; - else if (*state == 2 || *state == 3) { - //Undefined position, we return -1: - ecur = efrom - 1; - } - } - else { - if (*((char*)&mb) != 0) { - //We take into account the character that hasn't been counted yet in - //the previous decoding step: - ecur++; - } - } - */ - delete[] ibegin; - return (int)min((size_t)(ecur - efrom), m); - } - - virtual int do_max_length() const __NO_THROW - { return 0; } -#ifdef __DMC__ - static locale::id id; -#endif -}; - -#ifdef __DMC__ -locale::id generator_codecvt::id; - -locale::id& _GetFacetId(const generator_codecvt*) -{ return generator_codecvt::id; } -#endif - -// -// tests implementation -// -void CodecvtTest::variable_encoding() -{ -#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) - //We first generate the file used for test: - const char* fileName = "test_file.txt"; - { - ofstream ostr(fileName); - //Maybe we simply do not have write access to repository - CPPUNIT_ASSERT( ostr.good() ); - for (int i = 0; i < 2048; ++i) { - ostr << "0123456789"; - } - CPPUNIT_ASSERT( ostr.good() ); - } - - { - ifstream istr(fileName); - CPPUNIT_ASSERT( istr.good() ); - CPPUNIT_ASSERT( !istr.eof() ); - - eater_codecvt codec(1); - locale loc(locale::classic(), &codec); - - istr.imbue(loc); - CPPUNIT_ASSERT( istr.good() ); - CPPUNIT_ASSERT( (int)istr.tellg() == 0 ); - - int theoricalPos = 0; - do { - int c = istr.get(); - if (char_traits<char>::eq_int_type(c, char_traits<char>::eof())) { - break; - } - ++theoricalPos; - if (c == 'a') { - ++theoricalPos; - } - - CPPUNIT_ASSERT( (int)istr.tellg() == theoricalPos ); - } - while (!istr.eof()); - - CPPUNIT_ASSERT( istr.eof() ); - } - -# if 0 - /* This test is broken, not sure if it is really possible to get a position in - * a locale having a codecvt such as generator_codecvt. Maybe generator_codecvt - * is not a valid theorical example of codecvt implementation. */ - { - ifstream istr(fileName); - CPPUNIT_ASSERT( istr.good() ); - CPPUNIT_ASSERT( !istr.eof() ); - - generator_codecvt codec(1); - locale loc(locale::classic(), &codec); - - istr.imbue(loc); - CPPUNIT_ASSERT( istr.good() ); - CPPUNIT_ASSERT( (int)istr.tellg() == 0 ); - - int theoricalPos = 0; - int theoricalTellg; - do { - char c = istr.get(); - if (c == char_traits<char>::eof()) { - break; - } - switch (c) { - case 'a': - case 'b': - theoricalTellg = -1; - break; - case 'c': - ++theoricalPos; - default: - ++theoricalPos; - theoricalTellg = theoricalPos; - break; - } - - if ((int)istr.tellg() != theoricalTellg) { - CPPUNIT_ASSERT( (int)istr.tellg() == theoricalTellg ); - } - } - while (!istr.eof()); - - CPPUNIT_ASSERT( istr.eof() ); - } -# endif -#endif -} - -void CodecvtTest::in_out_test() -{ -#if !defined (STLPORT) || !(defined (_STLP_NO_WCHAR_T) || !defined (_STLP_USE_EXCEPTIONS)) - try { - locale loc(""); - - typedef codecvt<wchar_t, char, mbstate_t> cdecvt_type; - if (has_facet<cdecvt_type>(loc)) { - cdecvt_type const& cdect = use_facet<cdecvt_type>(loc); - { - cdecvt_type::state_type state; - memset(&state, 0, sizeof(cdecvt_type::state_type)); - string from("abcdef"); - const char* next_from; - wchar_t to[1]; - wchar_t *next_to; - cdecvt_type::result res = cdect.in(state, from.data(), from.data() + from.size(), next_from, - to, to + sizeof(to) / sizeof(wchar_t), next_to); - CPPUNIT_ASSERT( res == cdecvt_type::ok ); - CPPUNIT_ASSERT( next_from == from.data() + 1 ); - CPPUNIT_ASSERT( next_to == &to[0] + 1 ); - CPPUNIT_ASSERT( to[0] == L'a'); - } - { - cdecvt_type::state_type state; - memset(&state, 0, sizeof(cdecvt_type::state_type)); - wstring from(L"abcdef"); - const wchar_t* next_from; - char to[1]; - char *next_to; - cdecvt_type::result res = cdect.out(state, from.data(), from.data() + from.size(), next_from, - to, to + sizeof(to) / sizeof(char), next_to); - CPPUNIT_ASSERT( res == cdecvt_type::ok ); - CPPUNIT_ASSERT( next_from == from.data() + 1 ); - CPPUNIT_ASSERT( next_to == &to[0] + 1 ); - CPPUNIT_ASSERT( to[0] == 'a'); - } - } - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -#endif -} - -void CodecvtTest::length_test() -{ -#if !defined (STLPORT) || !(defined (_STLP_NO_WCHAR_T) || !defined (_STLP_USE_EXCEPTIONS)) - try { - locale loc(""); - - typedef codecvt<wchar_t, char, mbstate_t> cdecvt_type; - if (has_facet<cdecvt_type>(loc)) { - cdecvt_type const& cdect = use_facet<cdecvt_type>(loc); - { - cdecvt_type::state_type state; - memset(&state, 0, sizeof(cdecvt_type::state_type)); - string from("abcdef"); - int res = cdect.length(state, from.data(), from.data() + from.size(), from.size()); - CPPUNIT_ASSERT( (size_t)res == from.size() ); - } - } - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -#endif -} - -#if !defined (STLPORT) || !(defined (_STLP_NO_WCHAR_T) || !defined (_STLP_USE_EXCEPTIONS)) -typedef std::codecvt<wchar_t, char, mbstate_t> my_codecvt_base; - -class my_codecvt : public my_codecvt_base { -public: - explicit my_codecvt(size_t r = 0) - : my_codecvt_base(r) {} - -protected: - virtual result do_in(state_type& /*state*/, const extern_type* first1, - const extern_type* last1, const extern_type*& next1, - intern_type* first2, intern_type* last2, - intern_type*& next2) const { - for ( next1 = first1, next2 = first2; next1 < last1; next1 += 2 ) { - if ( (last1 - next1) < 2 || (last2 - next2) < 1 ) - return partial; - *next2++ = (intern_type)((*(next1 + 1) << 8) | (*next1 & 255)); - } - return ok; - } - virtual bool do_always_noconv() const __NO_THROW - { return false; } - virtual int do_max_length() const __NO_THROW - { return 2; } - virtual int do_encoding() const __NO_THROW - { return 2; } -}; -#endif - -void CodecvtTest::imbue_while_reading() -{ -#if !defined (STLPORT) || !(defined (_STLP_NO_WCHAR_T) || !defined (_STLP_USE_EXCEPTIONS)) - { - wofstream ofs( "test.txt" ); - const wchar_t buf[] = L" "; - for ( int i = 0; i < 4098; ++i ) { - ofs << buf[0]; - } - } - - wifstream ifs("test.txt"); // a file containing 4098 wchars - - ifs.imbue( locale(locale(), new my_codecvt) ); - ifs.get(); - ifs.seekg(0); - ifs.imbue( locale() ); - ifs.ignore(4096); - int ch = ifs.get(); - CPPUNIT_CHECK( ch != (int)WEOF ); -#endif -} - -void CodecvtTest::special_encodings() -{ -#if !defined (STLPORT) || (!defined (_STLP_NO_WCHAR_T) && defined (_STLP_USE_EXCEPTIONS)) - { - locale loc(locale::classic(), new codecvt_byname<wchar_t, char, mbstate_t>("C")); - codecvt<wchar_t, char, mbstate_t> const& cvt = use_facet<codecvt<wchar_t, char, mbstate_t> >(loc); - mbstate_t state; - memset(&state, 0, sizeof(mbstate_t)); - char c = '0'; - const char *from_next; - wchar_t wc; - wchar_t *to_next; - CPPUNIT_ASSERT( cvt.in(state, &c, &c + 1, from_next, &wc, &wc, to_next) == codecvt_base::ok ); - CPPUNIT_ASSERT( to_next == &wc ); - CPPUNIT_ASSERT( cvt.in(state, &c, &c + 1, from_next, &wc, &wc + 1, to_next) == codecvt_base::ok ); - CPPUNIT_ASSERT( wc == L'0' ); - CPPUNIT_ASSERT( to_next == &wc + 1 ); - } - try - { - wstring cp936_wstr; - const string cp936_str = "\xd6\xd0\xb9\xfa\xc9\xe7\xbb\xe1\xbf\xc6\xd1\xa7\xd4\xba\xb7\xa2\xb2\xbc\x32\x30\x30\x38\xc4\xea\xa1\xb6\xbe\xad\xbc\xc3\xc0\xb6\xc6\xa4\xca\xe9\xa1\xb7\xd6\xb8\xb3\xf6\xa3\xac\x32\x30\x30\x37\xc4\xea\xd6\xd0\xb9\xfa\xbe\xad\xbc\xc3\xd4\xf6\xb3\xa4\xd3\xc9\xc6\xab\xbf\xec\xd7\xaa\xcf\xf2\xb9\xfd\xc8\xc8\xb5\xc4\xc7\xf7\xca\xc6\xc3\xf7\xcf\xd4\xd4\xa4\xbc\xc6\xc8\xab\xc4\xea\x47\x44\x50\xd4\xf6\xcb\xd9\xbd\xab\xb4\xef\x31\x31\x2e\x36\x25\xa1\xa3"; - locale loc(locale::classic(), ".936", locale::ctype); - codecvt<wchar_t, char, mbstate_t> const& cvt = use_facet<codecvt<wchar_t, char, mbstate_t> >(loc); - mbstate_t state; - memset(&state, 0, sizeof(mbstate_t)); - - codecvt_base::result res; - - { - wchar_t wbuf[4096]; - // Check we will have enough room for the generated wide string generated from the whole char buffer: - int len = cvt.length(state, cp936_str.data(), cp936_str.data() + cp936_str.size(), sizeof(wbuf) / sizeof(wchar_t)); - CPPUNIT_ASSERT( cp936_str.size() == (size_t)len ); - - const char *from_next; - wchar_t *to_next; - res = cvt.in(state, cp936_str.data(), cp936_str.data() + cp936_str.size(), from_next, - wbuf, wbuf + sizeof(wbuf) / sizeof(wchar_t), to_next); - CPPUNIT_ASSERT( res == codecvt_base::ok ); - CPPUNIT_ASSERT( from_next == cp936_str.data() + cp936_str.size() ); - cp936_wstr.assign(wbuf, to_next); - } - - { - const wchar_t *from_next; - char buf[4096]; - char *to_next; - res = cvt.out(state, cp936_wstr.data(), cp936_wstr.data() + cp936_wstr.size(), from_next, - buf, buf + sizeof(buf), to_next); - CPPUNIT_ASSERT( res == codecvt_base::ok ); - CPPUNIT_CHECK( string(buf, to_next) == cp936_str ); - } - } - catch (const runtime_error&) - { - CPPUNIT_MESSAGE("Not enough platform localization support to check 936 code page encoding."); - } - try - { - const string utf8_str = "\xe4\xb8\xad\xe5\x9b\xbd\xe7\xa4\xbe\xe4\xbc\x9a\xe7\xa7\x91\xe5\xad\xa6\xe9\x99\xa2\xe5\x8f\x91\xe5\xb8\x83\x32\x30\x30\x38\xe5\xb9\xb4\xe3\x80\x8a\xe7\xbb\x8f\xe6\xb5\x8e\xe8\x93\x9d\xe7\x9a\xae\xe4\xb9\xa6\xe3\x80\x8b\xe6\x8c\x87\xe5\x87\xba\xef\xbc\x8c\x32\x30\x30\x37\xe5\xb9\xb4\xe4\xb8\xad\xe5\x9b\xbd\xe7\xbb\x8f\xe6\xb5\x8e\xe5\xa2\x9e\xe9\x95\xbf\xe7\x94\xb1\xe5\x81\x8f\xe5\xbf\xab\xe8\xbd\xac\xe5\x90\x91\xe8\xbf\x87\xe7\x83\xad\xe7\x9a\x84\xe8\xb6\x8b\xe5\x8a\xbf\xe6\x98\x8e\xe6\x98\xbe\xe9\xa2\x84\xe8\xae\xa1\xe5\x85\xa8\xe5\xb9\xb4\x47\x44\x50\xe5\xa2\x9e\xe9\x80\x9f\xe5\xb0\x86\xe8\xbe\xbe\x31\x31\x2e\x36\x25\xe3\x80\x82"; - wstring utf8_wstr; - locale loc(locale::classic(), new codecvt_byname<wchar_t, char, mbstate_t>(".utf8")); - codecvt<wchar_t, char, mbstate_t> const& cvt = use_facet<codecvt<wchar_t, char, mbstate_t> >(loc); - mbstate_t state; - memset(&state, 0, sizeof(mbstate_t)); - - codecvt_base::result res; - - { - wchar_t wbuf[4096]; - // Check we will have enough room for the wide string generated from the whole char buffer: - int len = cvt.length(state, utf8_str.data(), utf8_str.data() + utf8_str.size(), sizeof(wbuf) / sizeof(wchar_t)); - CPPUNIT_ASSERT( utf8_str.size() == (size_t)len ); - - const char *from_next; - wchar_t *to_next; - res = cvt.in(state, utf8_str.data(), utf8_str.data() + utf8_str.size(), from_next, - wbuf, wbuf + sizeof(wbuf) / sizeof(wchar_t), to_next); - CPPUNIT_ASSERT( res == codecvt_base::ok ); - CPPUNIT_ASSERT( from_next == utf8_str.data() + utf8_str.size() ); - utf8_wstr.assign(wbuf, to_next); - - // Try to read one char after the other: - wchar_t wc; - const char* from = utf8_str.data(); - const char* from_end = from + utf8_str.size(); - from_next = utf8_str.data(); - size_t length = 1; - size_t windex = 0; - while (from + length <= from_end) { - res = cvt.in(state, from, from + length, from_next, - &wc, &wc + 1, to_next); - switch (res) { - case codecvt_base::ok: - // reset length: - from = from_next; - length = 1; - CPPUNIT_ASSERT( wc == utf8_wstr[windex++] ); - wc = 0; - break; - case codecvt_base::partial: - if (from_next == from) - // from_next hasn't move so we have to pass more chars - ++length; - else - // char between from and from_next has been eaten, we simply restart - // conversion from from_next: - from = from_next; - continue; - case codecvt_base::error: - case codecvt_base::noconv: - CPPUNIT_FAIL; - //break; - } - } - CPPUNIT_ASSERT( windex == utf8_wstr.size() ); - } - - { - const wchar_t *from_next; - char buf[4096]; - char *to_next; - res = cvt.out(state, utf8_wstr.data(), utf8_wstr.data() + utf8_wstr.size(), from_next, - buf, buf + sizeof(buf), to_next); - CPPUNIT_ASSERT( res == codecvt_base::ok ); - CPPUNIT_CHECK( string(buf, to_next) == utf8_str ); - } - - { - // Check that an obviously wrong UTF8 encoded string is correctly detected: - const string bad_utf8_str("\xdf\xdf\xdf\xdf\xdf"); - wchar_t wc; - const char *from_next; - wchar_t *to_next; - res = cvt.in(state, bad_utf8_str.data(), bad_utf8_str.data() + bad_utf8_str.size(), from_next, - &wc, &wc + 1, to_next); - CPPUNIT_ASSERT( res == codecvt_base::error ); - } - } - catch (const runtime_error&) - { - CPPUNIT_MESSAGE("Not enough platform localization support to check UTF8 encoding."); - } -#endif -} - -#endif diff --git a/test/unit/collate_facets_test.cpp b/test/unit/collate_facets_test.cpp deleted file mode 100644 index b6a1b14..0000000 --- a/test/unit/collate_facets_test.cpp +++ /dev/null @@ -1,279 +0,0 @@ -#include "locale_test.h" - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <locale> -# include <stdexcept> -# include <algorithm> -# include <vector> - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -// -// tests implementation -// -void LocaleTest::collate_facet() -{ - { - CPPUNIT_ASSERT( has_facet<collate<char> >(locale::classic()) ); - collate<char> const& col = use_facet<collate<char> >(locale::classic()); - - char const str1[] = "abcdef1"; - char const str2[] = "abcdef2"; - const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1; - const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1; - - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 ); - CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 ); - - //Smallest string should be before largest one: - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 ); - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 ); - } - -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { - locale loc("fr_FR"); - { - CPPUNIT_ASSERT( has_facet<collate<char> >(loc) ); - collate<char> const& col = use_facet<collate<char> >(loc); - - char const str1[] = "abcdef1"; - char const str2[] = "abcdef2"; - const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1; - const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1; - - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 ); - CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 ); - - //Smallest string should be before largest one: - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 ); - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 ); - } - { - CPPUNIT_ASSERT( has_facet<collate<char> >(loc) ); - collate<char> const& col = use_facet<collate<char> >(loc); - - string strs[] = {"abdd", "abçd", "abbd", "abcd"}; - - string transformed[4]; - for (size_t i = 0; i < 4; ++i) { - transformed[i] = col.transform(strs[i].data(), strs[i].data() + strs[i].size()); - } - - sort(strs, strs + 4, loc); - CPPUNIT_ASSERT( strs[0] == "abbd" ); - CPPUNIT_ASSERT( strs[1] == "abcd" ); - CPPUNIT_ASSERT( strs[2] == "abçd" ); - CPPUNIT_ASSERT( strs[3] == "abdd" ); - - sort(transformed, transformed + 4); - - CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + strs[0].size()) == transformed[0] ); - CPPUNIT_ASSERT( col.transform(strs[1].data(), strs[1].data() + strs[1].size()) == transformed[1] ); - CPPUNIT_ASSERT( col.transform(strs[2].data(), strs[2].data() + strs[2].size()) == transformed[2] ); - CPPUNIT_ASSERT( col.transform(strs[3].data(), strs[3].data() + strs[3].size()) == transformed[3] ); - - // Check empty string result in empty key. - CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data()).empty() ); - - // Check that only characters that matter are taken into accout to build the key. - CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + 2) == col.transform(strs[1].data(), strs[1].data() + 2) ); - } -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) - { - CPPUNIT_ASSERT( has_facet<collate<wchar_t> >(loc) ); - collate<wchar_t> const& col = use_facet<collate<wchar_t> >(loc); - - wchar_t const str1[] = L"abcdef1"; - wchar_t const str2[] = L"abcdef2"; - const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1; - const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1; - - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 ); - CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 ); - - //Smallest string should be before largest one: - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 ); - CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 ); - } - { - size_t i; - CPPUNIT_ASSERT( has_facet<collate<wchar_t> >(loc) ); - collate<wchar_t> const& col = use_facet<collate<wchar_t> >(loc); - - // Here we would like to use L"abçd" but it looks like all compilers - // do not support storage of unicode characters in exe resulting in - // compilation error. We avoid this test for the moment. - wstring strs[] = {L"abdd", L"abcd", L"abbd", L"abcd"}; - - wstring transformed[4]; - for (i = 0; i < 4; ++i) { - transformed[i] = col.transform(strs[i].data(), strs[i].data() + strs[i].size()); - } - - sort(strs, strs + 4, loc); - CPPUNIT_ASSERT( strs[0] == L"abbd" ); - CPPUNIT_ASSERT( strs[1] == L"abcd" ); - CPPUNIT_ASSERT( strs[2] == L"abcd" ); - CPPUNIT_ASSERT( strs[3] == L"abdd" ); - - sort(transformed, transformed + 4); - - CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + strs[0].size()) == transformed[0] ); - CPPUNIT_ASSERT( col.transform(strs[1].data(), strs[1].data() + strs[1].size()) == transformed[1] ); - CPPUNIT_ASSERT( col.transform(strs[2].data(), strs[2].data() + strs[2].size()) == transformed[2] ); - CPPUNIT_ASSERT( col.transform(strs[3].data(), strs[3].data() + strs[3].size()) == transformed[3] ); - - CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data()).empty() ); - - CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + 2) == col.transform(strs[1].data(), strs[1].data() + 2) ); - } -# endif - } - catch (runtime_error const&) { - CPPUNIT_MESSAGE("No french locale to check collate facet"); - } -# endif -} - -void LocaleTest::collate_by_name() -{ - /* - * Check of the 22.1.1.2.7 standard point. Construction of a locale - * instance from a null pointer or an unknown name should result in - * a runtime_error exception. - */ -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new collate_byname<char>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new collate_byname<char>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - string veryLongFacetName("LC_COLLATE="); - veryLongFacetName.append(512, '?'); - locale loc(locale::classic(), new collate_byname<char>(veryLongFacetName.c_str())); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), "C", locale::collate); - } - catch (runtime_error const& e) { - CPPUNIT_MESSAGE( e.what() ); - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - // On platform without real localization support we should rely on the "C" facet. - locale loc(locale::classic(), "", locale::collate); - } - catch (runtime_error const& e) { - CPPUNIT_MESSAGE( e.what() ); - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new collate_byname<char>("C")); - - //We check that the C locale gives a lexicographical comparison: - collate<char> const& cfacet_byname = use_facet<collate<char> >(loc); - collate<char> const& cfacet = use_facet<collate<char> >(locale::classic()); - - char const str1[] = "abcdef1"; - char const str2[] = "abcdef2"; - const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1; - const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1; - - CPPUNIT_ASSERT( cfacet_byname.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == - cfacet.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) ); - CPPUNIT_ASSERT( cfacet_byname.compare(str1, str1 + size1, str2, str2 + size2) == - cfacet.compare(str1, str1 + size1, str2, str2 + size2) ); - - //Smallest string should be before largest one: - CPPUNIT_ASSERT( cfacet_byname.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == - cfacet.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) ); - CPPUNIT_ASSERT( cfacet_byname.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == - cfacet.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) ); - - // We cannot play with 'ç' char here because doing so would make test result - // dependant on char being consider as signed or not... - string strs[] = {"abdd", /* "abçd",*/ "abbd", "abcd"}; - - vector<string> v1(strs, strs + sizeof(strs) / sizeof(strs[0])); - sort(v1.begin(), v1.end(), loc); - vector<string> v2(strs, strs + sizeof(strs) / sizeof(strs[0])); - sort(v2.begin(), v2.end(), locale::classic()); - CPPUNIT_ASSERT( v1 == v2 ); - - CPPUNIT_ASSERT( (cfacet_byname.transform(v1[0].data(), v1[0].data() + v1[0].size()).compare(cfacet_byname.transform(v1[1].data(), v1[1].data() + v1[1].size())) == - v1[0].compare(v1[1])) ); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new collate_byname<wchar_t>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new collate_byname<wchar_t>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif -# endif -} - -#endif diff --git a/test/unit/complete_digits.h b/test/unit/complete_digits.h deleted file mode 100644 index 0a3d933..0000000 --- a/test/unit/complete_digits.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef STLP_DIGITS_H -#define STLP_DIGITS_H - -#include <string> - -inline void -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -complete_digits(std::string &digits) -#else -complete_digits(string &digits) -#endif -{ - while (digits.size() < 2) - { - digits.insert(digits.begin(), '0'); - } -} - -#endif diff --git a/test/unit/complex_header_test.cpp b/test/unit/complex_header_test.cpp deleted file mode 100644 index 367f3d0..0000000 --- a/test/unit/complex_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <complex> diff --git a/test/unit/config_test.cpp b/test/unit/config_test.cpp deleted file mode 100644 index 92846ba..0000000 --- a/test/unit/config_test.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include <new> -#include <vector> - -#include "cppunit/cppunit_proxy.h" - -#if defined (_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class ConfigTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ConfigTest); -#if !defined (STLPORT) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(placement_new_bug); - CPPUNIT_TEST(endianess); - CPPUNIT_TEST(template_function_partial_ordering); -#if !defined (_STLP_USE_EXCEPTIONS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(new_throw_bad_alloc); - CPPUNIT_TEST_SUITE_END(); - - protected: - void placement_new_bug(); - void endianess(); - void template_function_partial_ordering(); - void new_throw_bad_alloc(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ConfigTest); - -void ConfigTest::placement_new_bug() -{ -#if defined (STLPORT) - int int_val = 1; - int *pint; - pint = new(&int_val) int(); - CPPUNIT_ASSERT( pint == &int_val ); -# if defined (_STLP_DEF_CONST_PLCT_NEW_BUG) - CPPUNIT_ASSERT( int_val != 0 ); -# else - CPPUNIT_ASSERT( int_val == 0 ); -# endif -#endif -} - -void ConfigTest::endianess() -{ -#if defined (STLPORT) - int val = 0x01020304; - char *ptr = (char*)(&val); -# if defined (_STLP_BIG_ENDIAN) - //This test only work if sizeof(int) == 4, this is a known limitation - //that will be handle the day we find a compiler for which it is false. - CPPUNIT_ASSERT( *ptr == 0x01 || - sizeof(int) > 4 && *ptr == 0x00 ); -# elif defined (_STLP_LITTLE_ENDIAN) - CPPUNIT_ASSERT( *ptr == 0x04 ); -# endif -#endif -} - -void ConfigTest::template_function_partial_ordering() -{ -#if defined (STLPORT) - vector<int> vect1(10, 0); - int* pvect1Front = &vect1.front(); - vector<int> vect2(10, 0); - int* pvect2Front = &vect2.front(); - - swap(vect1, vect2); - -# if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) - CPPUNIT_ASSERT( pvect1Front == &vect2.front() ); - CPPUNIT_ASSERT( pvect2Front == &vect1.front() ); -# else - CPPUNIT_ASSERT( pvect1Front != &vect2.front() ); - CPPUNIT_ASSERT( pvect2Front != &vect1.front() ); -# endif -#endif -} - -void ConfigTest::new_throw_bad_alloc() -{ -#if defined (STLPORT) && defined (_STLP_USE_EXCEPTIONS) - try - { - /* We try to exhaust heap memory. However, we don't actually use the - largest possible size_t value bus slightly less in order to avoid - triggering any overflows due to the allocator adding some more for - its internal data structures. */ - size_t const huge_amount = size_t(-1) - 1024; - void* pvoid = operator new (huge_amount); -#if !defined (_STLP_NEW_DONT_THROW_BAD_ALLOC) - // Allocation should have fail - CPPUNIT_ASSERT( pvoid != 0 ); -#endif - // Just in case it succeeds: - operator delete(pvoid); - } - catch (const bad_alloc&) - { -#if defined (_STLP_NEW_DONT_THROW_BAD_ALLOC) - // Looks like your compiler new operator finally throw bad_alloc, you can fix - // configuration. - CPPUNIT_FAIL; -#endif - } - catch (...) - { - //We shouldn't be there: - //Not bad_alloc exception thrown. - CPPUNIT_FAIL; - } -#endif -} diff --git a/test/unit/copy_test.cpp b/test/unit/copy_test.cpp deleted file mode 100644 index 852e687..0000000 --- a/test/unit/copy_test.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include <algorithm> -#include <cstring> -#include <vector> -#include <iterator> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class CopyTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(CopyTest); - CPPUNIT_TEST(copy_array); - CPPUNIT_TEST(copy_volatile); - CPPUNIT_TEST(copy_vector); - CPPUNIT_TEST(copy_insert); - CPPUNIT_TEST(copy_back); - CPPUNIT_TEST(copy_back_array); - CPPUNIT_TEST_SUITE_END(); - -protected: - void copy_array(); - void copy_volatile(); - void copy_vector(); - void copy_insert(); - void copy_back(); - void copy_back_array(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(CopyTest); - -// -// tests implementation -// -void CopyTest::copy_array() -{ - char string[23] = "A string to be copied."; - char result[23]; - copy(string, string + 23, result); - CPPUNIT_ASSERT(!strncmp(string, result, 23)); -} - -void CopyTest::copy_volatile() -{ - { - int a[] = {0, 1, 2, 3, 4, 5}; - const size_t size = sizeof(a) / sizeof(a[0]); - volatile int va[size]; - copy(a, a + size, va); - for (size_t i = 0; i != size; ++i) { - CPPUNIT_ASSERT( a[i] == va[i] ); - } - } - - { - const int a[] = {0, 1, 2, 3, 4, 5}; - const size_t size = sizeof(a) / sizeof(a[0]); - volatile int va[size]; - copy(a, a + size, va); - for (size_t i = 0; i != size; ++i) { - CPPUNIT_ASSERT( a[i] == va[i] ); - } - } - - // Following code can be activated to check that it doesn't compiled -#if 0 - { - int a[] = {0, 1, 2, 3, 4, 5}; - const size_t size = sizeof(a) / sizeof(a[0]); - const volatile int va[size] = {5, 4, 3, 2, 1, 0}; - copy(a, a + size, va); - for (size_t i = 0; i != size; ++i) { - CPPUNIT_ASSERT( a[i] == va[i] ); - } - } -#endif -} - -void CopyTest::copy_vector() -{ - vector<int> v1(10); - for (int i = 0; (size_t)i < v1.size(); ++i) - v1[i] = i; - - vector<int> v2(v1.size()); - copy(v1.begin(), v1.end(), v2.begin()); - - CPPUNIT_ASSERT( v2 == v1 ); -} - -void CopyTest::copy_insert() { - vector<int> v1(10); - for (int loc = 0; (size_t)loc < v1.size(); ++loc) - v1[loc] = loc; - vector<int> v2; - insert_iterator<vector<int> > i(v2, v2.begin()); - copy(v1.begin(), v1.end(), i); - - CPPUNIT_ASSERT( v2 == v1 ); -} - -void CopyTest::copy_back() -{ - vector<int> v1(10); - for (int i = 0; (size_t)i < v1.size(); ++i) - v1[i] = i; - vector<int> v2(v1.size()); - copy_backward(v1.begin(), v1.end(), v2.end()); - - CPPUNIT_ASSERT( v2 == v1 ); -} - -void CopyTest::copy_back_array() -{ - int numbers[5] = { 1, 2, 3, 4, 5 }; - - int result[5]; - copy_backward(numbers, numbers + 5, (int*)result + 5); - CPPUNIT_ASSERT(result[0]==numbers[0]); - CPPUNIT_ASSERT(result[1]==numbers[1]); - CPPUNIT_ASSERT(result[2]==numbers[2]); - CPPUNIT_ASSERT(result[3]==numbers[3]); - CPPUNIT_ASSERT(result[4]==numbers[4]); -} diff --git a/test/unit/count_test.cpp b/test/unit/count_test.cpp deleted file mode 100644 index edf96e0..0000000 --- a/test/unit/count_test.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include <algorithm> -#include <vector> -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class CountTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(CountTest); - CPPUNIT_TEST(count0); - CPPUNIT_TEST(count1); - CPPUNIT_TEST(countif1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void count0(); - void count1(); - void countif1(); - static int odd(int a_); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(CountTest); - -// -// tests implementation -// -void CountTest::count0() -{ - int numbers[10] = { 1, 2, 4, 1, 2, 4, 1, 2, 4, 1 }; - - int result = count(numbers, numbers + 10, 1); - CPPUNIT_ASSERT(result==4); -#if defined (STLPORT) && !defined (_STLP_NO_ANACHRONISMS) - result = 0; - count(numbers, numbers + 10, 1, result); - CPPUNIT_ASSERT(result==4); -#endif -} -void CountTest::count1() -{ - vector <int> numbers(100); - for(int i = 0; i < 100; i++) - numbers[i] = i % 3; - int elements = count(numbers.begin(), numbers.end(), 2); - CPPUNIT_ASSERT(elements==33); -#if defined (STLPORT) && !defined (_STLP_NO_ANACHRONISMS) - elements = 0; - count(numbers.begin(), numbers.end(), 2, elements); - CPPUNIT_ASSERT(elements==33); -#endif -} -void CountTest::countif1() -{ - vector <int> numbers(100); - for(int i = 0; i < 100; i++) - numbers[i] = i % 3; - int elements = count_if(numbers.begin(), numbers.end(), odd); - CPPUNIT_ASSERT(elements==33); -#if defined (STLPORT) && !defined (_STLP_NO_ANACHRONISMS) - elements = 0; - count_if(numbers.begin(), numbers.end(), odd, elements); - CPPUNIT_ASSERT(elements==33); -#endif -} -int CountTest::odd(int a_) -{ - return a_ % 2; -} diff --git a/test/unit/cppunit/cppunit_mini.h b/test/unit/cppunit/cppunit_mini.h deleted file mode 100644 index 98b4a7a..0000000 --- a/test/unit/cppunit/cppunit_mini.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2003, 2004 - * Zdenek Nemec - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use or copy this software for any purpose is hereby granted - * without fee, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is granted, - * provided the above notices are retained, and a notice that the code was - * modified is included with the above copyright notice. - * - */ - -/* $Id$ */ - -#ifndef _CPPUNITMPFR_H_ -#define _CPPUNITMPFR_H_ - -#if 0 -# define CPPUNIT_NS CppUnitMini -#else -# define CPPUNIT_NS -#endif - -#include <string.h> - -#if 0 -namespace CPPUNIT_NS -{ -#endif - class Reporter { - public: - virtual ~Reporter() {} - virtual void error(const char * /*macroName*/, const char * /*in_macro*/, const char * /*in_file*/, int /*in_line*/) {} - virtual void message( const char * /*msg*/ ) {} - virtual void progress( const char * /*in_className*/, const char * /*in_testName*/, bool /*ignored*/, bool /* explicit */) {} - virtual void end() {} - virtual void printSummary() {} - }; - - class TestFixture { - public: - virtual ~TestFixture() {} - - //! \brief Set up context before running a test. - virtual void setUp() {} - - //! Clean up after the test run. - virtual void tearDown() {} - }; - - class TestCase : public TestFixture { - public: - TestCase() { registerTestCase(this); } - - void setUp() { m_failed = false; } - static int run(Reporter *in_reporter = 0, const char *in_testName = "", bool invert = false); - int numErrors() { return m_numErrors; } - static void registerTestCase(TestCase *in_testCase); - - virtual void myRun(const char * /*in_name*/, bool /*invert*/ = false) {} - - virtual void error(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) { - m_failed = true; - if (m_reporter) { - m_reporter->error(in_macroName, in_macro, in_file, in_line); - } - } - - static void message(const char *msg) { - if (m_reporter) { - m_reporter->message(msg); - } - } - - bool equalDoubles(double in_expected, double in_real, double in_maxErr) { - double diff = in_expected - in_real; - if (diff < 0.) { - diff = -diff; - } - return diff < in_maxErr; - } - - virtual void progress(const char *in_className, const char *in_functionName, bool ignored, bool explicitTest) { - ++m_numTests; - if (m_reporter) { - m_reporter->progress(in_className, in_functionName, ignored, explicitTest); - } - } - - bool shouldRunThis(const char *in_desiredTest, const char *in_className, const char *in_functionName, - bool invert, bool explicit_test, bool &do_progress) { - if ((in_desiredTest) && (in_desiredTest[0] != '\0')) { - do_progress = false; - const char *ptr = strstr(in_desiredTest, "::"); - if (ptr) { - bool match = (strncmp(in_desiredTest, in_className, strlen(in_className)) == 0) && - (strncmp(ptr + 2, in_functionName, strlen(in_functionName)) == 0); - // Invert shall not make explicit test run: - return invert ? (match ? !match : !explicit_test) - : match; - } - bool match = (strcmp(in_desiredTest, in_className) == 0); - do_progress = match; - return !explicit_test && (match == !invert); - } - do_progress = true; - return !explicit_test; - } - - void tearDown() { - if (m_failed) - ++m_numErrors; - m_reporter->end(); - } - - protected: - static int m_numErrors; - static int m_numTests; - - private: - static TestCase *m_root; - TestCase *m_next; - bool m_failed; - - static Reporter *m_reporter; - }; -#if 0 -} -#endif - -#if !defined (CPPUNIT_MINI_HIDE_UNUSED_VARIABLE) -# if defined (_MSC_VER) -# define CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(v) (v); -# else -# define CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(v) -# endif -#endif - -#define CPPUNIT_TEST_SUITE(X) \ - typedef CPPUNIT_NS::TestCase Base; \ - virtual void myRun(const char *in_name, bool invert = false) { \ - const char *className = #X; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(className) \ - bool ignoring = false; CPPUNIT_MINI_HIDE_UNUSED_VARIABLE(ignoring) - -#if defined CPPUNIT_MINI_USE_EXCEPTIONS -# define CPPUNIT_TEST_BASE(X, Y) \ - { \ - bool do_progress; \ - bool shouldRun = shouldRunThis(in_name, className, #X, invert, Y, do_progress); \ - if (shouldRun || do_progress) { \ - setUp(); \ - progress(className, #X, ignoring || !shouldRun, !ignoring && Y); \ - if (shouldRun && !ignoring) { \ - try { \ - X(); \ - } \ - catch(...) { \ - Base::error("Test Failed: An Exception was thrown.", #X, __FILE__, __LINE__); \ - } \ - } \ - tearDown(); \ - } \ - } -#else -# define CPPUNIT_TEST_BASE(X, Y) \ - { \ - bool do_progress; \ - bool shouldRun = shouldRunThis(in_name, className, #X, invert, Y, do_progress); \ - if (shouldRun || do_progress) { \ - setUp(); \ - progress(className, #X, ignoring || !shouldRun, !ignoring && Y); \ - if (shouldRun && !ignoring) \ - X(); \ - tearDown(); \ - } \ - } -#endif - -#define CPPUNIT_TEST(X) CPPUNIT_TEST_BASE(X, false) -#define CPPUNIT_EXPLICIT_TEST(X) CPPUNIT_TEST_BASE(X, true) - -#define CPPUNIT_IGNORE \ - ignoring = true - -#define CPPUNIT_STOP_IGNORE \ - ignoring = false - -#define CPPUNIT_TEST_SUITE_END() } - -#define CPPUNIT_TEST_SUITE_REGISTRATION(X) static X local - -#define CPPUNIT_CHECK(X) \ - if (!(X)) { \ - Base::error("CPPUNIT_CHECK", #X, __FILE__, __LINE__); \ - } - -#define CPPUNIT_ASSERT(X) \ - if (!(X)) { \ - Base::error("CPPUNIT_ASSERT", #X, __FILE__, __LINE__); \ - return; \ - } - -#define CPPUNIT_FAIL { \ - Base::error("CPPUNIT_FAIL", "", __FILE__, __LINE__); \ - return; \ - } - -#define CPPUNIT_ASSERT_EQUAL(X, Y) \ - if ((X) != (Y)) { \ - Base::error("CPPUNIT_ASSERT_EQUAL", #X","#Y, __FILE__, __LINE__); \ - return; \ - } - -#define CPPUNIT_ASSERT_DOUBLES_EQUAL(X, Y, Z) \ - if (!equalDoubles((X), (Y), (Z))) { \ - Base::error("CPPUNIT_ASSERT_DOUBLES_EQUAL", #X","#Y","#Z, __FILE__, __LINE__); \ - return; \ - } - -#define CPPUNIT_MESSAGE(m) CPPUNIT_NS::TestCase::message(m) - -#endif diff --git a/test/unit/cppunit/cppunit_proxy.h b/test/unit/cppunit/cppunit_proxy.h deleted file mode 100644 index 41cdc2a..0000000 --- a/test/unit/cppunit/cppunit_proxy.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2003, 2004 - * Zdenek Nemec - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use or copy this software for any purpose is hereby granted - * without fee, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is granted, - * provided the above notices are retained, and a notice that the code was - * modified is included with the above copyright notice. - * - */ - -/* $Id$ */ - -#ifndef _CPPUNITPROXYINTERFACE_H_ -#define _CPPUNITPROXYINTERFACE_H_ - -/* - * STLport specific - */ -#if !defined (CPPUNIT_MINI_USE_EXCEPTIONS) && \ - (!defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)) -# define CPPUNIT_MINI_USE_EXCEPTIONS -#endif - -#include "cppunit_mini.h" - -#endif diff --git a/test/unit/cppunit/cppunit_timer.h b/test/unit/cppunit/cppunit_timer.h deleted file mode 100644 index 61f9076..0000000 --- a/test/unit/cppunit/cppunit_timer.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2006 - * Francois Dumont - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use or copy this software for any purpose is hereby granted - * without fee, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is granted, - * provided the above notices are retained, and a notice that the code was - * modified is included with the above copyright notice. - * - */ - -#ifndef CPPUNIT_TIMER_H -#define CPPUNIT_TIMER_H - -#if defined (_WIN32) -# define CPPUNIT_WIN32_TIMER -# include <windows.h> -#endif - -class Timer { -public: - Timer() { -#if defined (CPPUNIT_WIN32_TIMER) - m_start.LowPart = m_restart.LowPart = m_stop.LowPart = 0; - m_start.HighPart = m_restart.HighPart = m_stop.HighPart = 0; - QueryPerformanceFrequency(&m_frequency); -#endif - } - - void start() { -#if defined (CPPUNIT_WIN32_TIMER) - QueryPerformanceCounter(&m_start); -#endif - } - - void restart() { -#if defined (CPPUNIT_WIN32_TIMER) - QueryPerformanceCounter(&m_restart); - if (m_start.HighPart == 0 && m_start.LowPart == 0) { - m_start = m_restart; - } -#endif - } - - void stop() { -#if defined (CPPUNIT_WIN32_TIMER) - LARGE_INTEGER stop; - QueryPerformanceCounter(&stop); - if ((m_stop.HighPart != 0 || m_stop.LowPart != 0) && - m_restart.HighPart != 0 && m_restart.LowPart != 0) { - m_stop.HighPart += (stop.HighPart - m_restart.HighPart); - if (stop.LowPart < m_restart.LowPart) { - if (m_restart.LowPart - stop.LowPart > m_stop.LowPart) { - m_stop.HighPart -= 1; - } - m_stop.LowPart -= m_restart.LowPart - stop.LowPart; - } - else { - if (stop.LowPart - m_restart.LowPart > 0xFFFFFFFF - m_stop.LowPart) { - m_stop.HighPart += 1; - } - m_stop.LowPart += stop.LowPart - m_restart.LowPart; - } - } - else { - m_stop = stop; - } -#endif - } - - double elapsedMilliseconds() const { -#if defined (CPPUNIT_WIN32_TIMER) - LARGE_INTEGER elapsed; - elapsed.HighPart = m_stop.HighPart - m_start.HighPart; - elapsed.LowPart = m_stop.LowPart - m_start.LowPart; - return (double)elapsed.QuadPart / (double)m_frequency.QuadPart * 1000; -#else - return 0; -#endif - } - - static bool supported() { -#if defined (CPPUNIT_WIN32_TIMER) - return true; -#else - return false; -#endif - } - -private: -#if defined (CPPUNIT_WIN32_TIMER) - LARGE_INTEGER m_frequency; - LARGE_INTEGER m_start, m_stop, m_restart; -#endif -}; - -#endif diff --git a/test/unit/cppunit/file_reporter.h b/test/unit/cppunit/file_reporter.h deleted file mode 100644 index 2c7633b..0000000 --- a/test/unit/cppunit/file_reporter.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2003, 2004 - * Zdenek Nemec - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use or copy this software for any purpose is hereby granted - * without fee, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is granted, - * provided the above notices are retained, and a notice that the code was - * modified is included with the above copyright notice. - * - */ - -/* $Id$ */ - -#ifndef _CPPUNITMINIFILEREPORTERINTERFACE_H_ -#define _CPPUNITMINIFILEREPORTERINTERFACE_H_ - -#include <stdio.h> - -#include "cppunit_timer.h" - -// -// CppUnit mini file(stream) reporter -// -class FileReporter : public CPPUNIT_NS::Reporter { -private: - FileReporter(const FileReporter&); - FileReporter& operator=(const FileReporter&); -public: - // reporting to stderr - explicit FileReporter(bool doMonitor = false): - m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(false), - m_failed(false), m_doMonitor(doMonitor) - { _file = stderr; } - - // reporting to the file with the given name - explicit FileReporter(const char* file, bool doMonitor = false): - m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(true), - m_failed(false), m_doMonitor(doMonitor) - { -#ifndef _STLP_USE_SAFE_STRING_FUNCTIONS - _file = fopen(file, "w"); -#else - fopen_s(&_file, file, "w"); -#endif - } - - // reporting to the given file - explicit FileReporter(FILE* stream, bool doMonitor = false): - m_numErrors(0), m_numIgnored(0), m_numExplicit(0), m_numTests(0), _myStream(false), - m_failed(false), m_doMonitor(doMonitor) - { _file = stream; } - - virtual ~FileReporter() { - if (_myStream) - fclose(_file); - else - fflush(_file); - } - - virtual void error(const char *in_macroName, const char *in_macro, const char *in_file, int in_line) { - // Error might be called several times between 2 progress calls, we shouldn't however consider - // that a test failed twice so we simply keep the info that test failed, number of failed tests - // is computed later in end method. - m_failed = true; - fprintf(_file, "\n\n%s(%d) : %s(%s);", in_file, in_line, in_macroName, in_macro); - } - - virtual void message( const char *msg ) - { fprintf(_file, "\n\t%s", msg ); } - - virtual void progress(const char *in_className, const char *in_shortTestName, bool ignored, bool explicitTest) { - if (m_doMonitor) { - m_globalTimer.restart(); - m_testTimer.start(); - } - ++m_numTests; - m_failed = false; - if (ignored) - ++m_numIgnored; - fprintf(_file, "%s::%s", in_className, in_shortTestName); - if (ignored) { - const char *ignoredReason; - if (explicitTest) { - ++m_numExplicit; - ignoredReason = " EXPLICIT"; - } - else - ignoredReason = " IGNORED"; - - fprintf(_file, "%s", ignoredReason); - } - } - - virtual void end() { - if (m_doMonitor) { - m_globalTimer.stop(); - m_testTimer.stop(); - fprintf(_file, " %f msec", m_testTimer.elapsedMilliseconds()); - } - if (m_failed) { - ++m_numErrors; - } - fprintf(_file, "\n"); - } - - virtual void printSummary() { - if (m_numErrors > 0) { - fprintf(_file, "\nThere were errors! %d of %d tests", m_numErrors, m_numTests); - } - else { - fprintf(_file, "\nOK %d tests", m_numTests); - } - - if (m_numIgnored > 0) { - fprintf(_file, ", %d ignored", m_numIgnored); - } - - if (m_numExplicit > 0) { - fprintf(_file, " (%d explicit)", m_numExplicit); - } - - if (m_doMonitor) { - fprintf(_file, " %f msec", m_globalTimer.elapsedMilliseconds()); - } - - fprintf(_file, "\n\n"); - } -private: - int m_numErrors; - int m_numIgnored; - int m_numExplicit; - int m_numTests; - // flag whether we own '_file' and are thus responsible for releasing it in the destructor - bool _myStream; - bool m_failed; - bool m_doMonitor; - Timer m_globalTimer, m_testTimer; - FILE* _file; -}; - -#endif /*_CPPUNITMINIFILEREPORTERINTERFACE_H_*/ diff --git a/test/unit/cppunit/test_main.cpp b/test/unit/cppunit/test_main.cpp deleted file mode 100644 index 8519d4f..0000000 --- a/test/unit/cppunit/test_main.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2003, 2004 - * Zdenek Nemec - * - * This material is provided "as is", with absolutely no warranty expressed - * or implied. Any use is at your own risk. - * - * Permission to use or copy this software for any purpose is hereby granted - * without fee, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is granted, - * provided the above notices are retained, and a notice that the code was - * modified is included with the above copyright notice. - * - */ - -#include "cppunit_proxy.h" -#include "file_reporter.h" -#include "cppunit_timer.h" - -#include "stdio.h" - -#if 0 -namespace CPPUNIT_NS -{ -#endif - int TestCase::m_numErrors = 0; - int TestCase::m_numTests = 0; - - TestCase *TestCase::m_root = 0; - Reporter *TestCase::m_reporter = 0; - - void TestCase::registerTestCase(TestCase *in_testCase) { - in_testCase->m_next = m_root; - m_root = in_testCase; - } - - int TestCase::run(Reporter *in_reporter, const char *in_testName, bool invert) { - TestCase::m_reporter = in_reporter; - - m_numErrors = 0; - m_numTests = 0; - - TestCase *tmp = m_root; - while (tmp != 0) { - tmp->myRun(in_testName, invert); - tmp = tmp->m_next; - } - return m_numErrors; - } -#if 0 -} -#endif - -static void usage(const char* name) -{ - printf("Usage : %s [-t=<class>[::<test>]] [-x=<class>[::<test>]] [-f=<file>]%s\n", - name, Timer::supported() ? " [-m]": ""); - printf("\t[-t=<class>[::<test>]] : test class or class::test to execute;\n"); - printf("\t[-x=<class>[::<test>]] : test class or class::test to exclude from execution;\n"); - printf("\t[-f=<file>] : output file"); - if (Timer::supported()) - printf(";\n\t[-m] : monitor test execution, display time duration for each test\n"); - else - printf("\n"); -} - -int main(int argc, char** argv) { - - // CppUnit(mini) test launcher - // command line option syntax: - // test [OPTIONS] - // where OPTIONS are - // -t=CLASS[::TEST] run the test class CLASS or member test CLASS::TEST - // -x=CLASS[::TEST] run all except the test class CLASS or member test CLASS::TEST - // -f=FILE save output in file FILE instead of stdout - // -m monitor test(s) execution - const char *fileName = 0; - const char *testName = ""; - const char *xtestName = ""; - bool doMonitoring = false; - - for (int i = 1; i < argc; ++i) { - if (argv[i][0] == '-') { - if (!strncmp(argv[i], "-t=", 3)) { - testName = argv[i]+3; - continue; - } - else if (!strncmp(argv[i], "-f=", 3)) { - fileName = argv[i]+3; - continue; - } - else if (!strncmp(argv[i], "-x=", 3)) { - xtestName = argv[i]+3; - continue; - } - else if (Timer::supported() && !strncmp(argv[i], "-m", 2)) { - doMonitoring = true; - continue; - } - } - - // invalid option, we display normal usage. - usage(argv[0]); - return 1; - } - - CPPUNIT_NS::Reporter* reporter; - if (fileName != 0) - reporter = new FileReporter(fileName, doMonitoring); - else - reporter = new FileReporter(stdout, doMonitoring); - - int num_errors; - if (xtestName[0] != 0) { - num_errors = CPPUNIT_NS::TestCase::run(reporter, xtestName, true); - } else { - num_errors = CPPUNIT_NS::TestCase::run(reporter, testName); - } - - reporter->printSummary(); - delete reporter; - - return num_errors; -} - -// See doc/README.intel for explanation about this code -#if defined (STLPORT) && defined (__ICL) && (__ICL >= 900) && \ - (_STLP_MSVC_LIB < 1300) && defined (_STLP_USE_DYNAMIC_LIB) -# include <exception> - -# undef std -namespace std -{ - void _STLP_CALL unexpected() { - unexpected_handler hdl; - set_unexpected(hdl = set_unexpected((unexpected_handler)0)); - hdl(); - } -} -#endif diff --git a/test/unit/csetjmp_header_test.cpp b/test/unit/csetjmp_header_test.cpp deleted file mode 100644 index b817862..0000000 --- a/test/unit/csetjmp_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <csetjmp> diff --git a/test/unit/csignal_header_test.cpp b/test/unit/csignal_header_test.cpp deleted file mode 100644 index 9a9c6e0..0000000 --- a/test/unit/csignal_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <csignal> diff --git a/test/unit/cstdarg_header_test.cpp b/test/unit/cstdarg_header_test.cpp deleted file mode 100644 index 06cf0a5..0000000 --- a/test/unit/cstdarg_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cstdarg> diff --git a/test/unit/cstddef_header_test.cpp b/test/unit/cstddef_header_test.cpp deleted file mode 100644 index 201d3f6..0000000 --- a/test/unit/cstddef_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cstddef> diff --git a/test/unit/cstdio_header_test.cpp b/test/unit/cstdio_header_test.cpp deleted file mode 100644 index e38a5e9..0000000 --- a/test/unit/cstdio_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cstdio> diff --git a/test/unit/cstdlib_header_test.cpp b/test/unit/cstdlib_header_test.cpp deleted file mode 100644 index f356079..0000000 --- a/test/unit/cstdlib_header_test.cpp +++ /dev/null @@ -1,13 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cstdlib> - -//Just an additionnal compilation test for Borland that used to fail here. -#if defined (__BORLANDC__) -# include <process.h> -#endif diff --git a/test/unit/cstring_header_test.cpp b/test/unit/cstring_header_test.cpp deleted file mode 100644 index dd5d2cf..0000000 --- a/test/unit/cstring_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cstring> diff --git a/test/unit/cstring_test.cpp b/test/unit/cstring_test.cpp deleted file mode 100644 index b51da07..0000000 --- a/test/unit/cstring_test.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#define _STLP_DO_IMPORT_CSTD_FUNCTIONS - -#include <cstring> - -#include "cppunit/cppunit_proxy.h" - -//This test purpose is to check the right import of math.h C symbols -//into the std namespace so we do not use the using namespace std -//specification - -// -// TestCase class -// -class CStringTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(CStringTest); -#if defined (STLPORT) && !defined (_STLP_USE_NAMESPACES) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(import_checks); - CPPUNIT_TEST_SUITE_END(); - - protected: - void import_checks(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(CStringTest); - -#if defined (_MSC_VER) && (_MSC_VER >= 1400) -//For deprecated symbols like strcat, strtok... -# pragma warning (disable : 4996) -#endif - -// -// tests implementation -// -void CStringTest::import_checks() -{ -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) - std::size_t bar = 0; - CPPUNIT_CHECK( bar == 0 ); - - CPPUNIT_CHECK( std::memchr("foo", 'o', 3) != NULL ); - CPPUNIT_CHECK( std::memcmp("foo1", "foo2", 3) == 0 ); - char buf1[1], buf2[1]; - CPPUNIT_CHECK( std::memcpy(buf1, buf2, 0) != NULL ); - CPPUNIT_CHECK( std::memmove(buf1, buf2, 0) != NULL ); - CPPUNIT_CHECK( std::memset(buf1, 0, 1) != NULL ); - char buf[16]; buf[0] = 0; - const char* foo = "foo"; -# if !defined(_WIN32_WCE) - CPPUNIT_CHECK( std::strcoll("foo", "foo") == 0 ); - CPPUNIT_CHECK( std::strerror(0) != NULL ); -# endif - CPPUNIT_CHECK( std::strcat((char*)buf, foo) == (char*)buf ); // buf <- foo - CPPUNIT_CHECK( std::strchr(foo, 'o') != NULL ); - CPPUNIT_CHECK( std::strcmp("foo1", "foo2") < 0 ); - CPPUNIT_CHECK( std::strcpy((char*)buf, foo) == (char*)buf ); // buf <- foo - CPPUNIT_CHECK( std::strcspn("foo", "o") == 1 ); - CPPUNIT_CHECK( std::strlen("foo") == 3 ); - CPPUNIT_CHECK( std::strncat((char*)buf, foo, 2) == (char*)buf ); // buf <- foofo - CPPUNIT_CHECK( std::strncmp("foo1", "foo2", 3) == 0 ); - CPPUNIT_CHECK( std::strncpy((char*)buf, foo, 3) == (char*)buf ); // buf <- foo - CPPUNIT_CHECK( std::strpbrk(foo, "abcdo") == foo + 1 ); - const char* foofoo = "foofoo"; - CPPUNIT_CHECK( std::strrchr(foofoo, 'f') == foofoo + 3 ); - CPPUNIT_CHECK( std::strspn(foofoo, "aofz") == 6 ); - CPPUNIT_CHECK( std::strstr(foo, "") == foo ); - char foofoobuf[] = "foofoo"; - CPPUNIT_CHECK( std::strtok(foofoobuf, "z") != NULL ); -# if !defined(_WIN32_WCE) - CPPUNIT_CHECK( std::strxfrm((char*)buf, foo, 3) != 0 ); -# endif -#endif -} diff --git a/test/unit/ctime_header_test.cpp b/test/unit/ctime_header_test.cpp deleted file mode 100644 index 4e71c18..0000000 --- a/test/unit/ctime_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <ctime> diff --git a/test/unit/ctype_facets_test.cpp b/test/unit/ctype_facets_test.cpp deleted file mode 100644 index 9609e21..0000000 --- a/test/unit/ctype_facets_test.cpp +++ /dev/null @@ -1,520 +0,0 @@ -#include "locale_test.h" - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <locale> -# include <stdexcept> - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -static const char* tested_locales[] = { -//name, -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - // We need exception support to check support of the following localizations. - "fr_FR", - "ru_RU.koi8r", - "en_GB", - "en_US", -# endif - "", - "C" -}; - -// -// tests implementation -// -void LocaleTest::_ctype_facet( const locale& loc) -{ - CPPUNIT_ASSERT( has_facet<ctype<char> >(loc) ); - ctype<char> const& ct = use_facet<ctype<char> >(loc); - //is - { - CPPUNIT_ASSERT( ct.is(ctype_base::digit, '0') ); - CPPUNIT_ASSERT( ct.is(ctype_base::upper, 'A') ); - CPPUNIT_ASSERT( ct.is(ctype_base::lower, 'a') ); - CPPUNIT_ASSERT( ct.is(ctype_base::alpha, 'A') ); - CPPUNIT_ASSERT( ct.is(ctype_base::space, ' ') ); - CPPUNIT_ASSERT( !ct.is(ctype_base::space, '2') ); - CPPUNIT_ASSERT( ct.is(ctype_base::punct, '.') ); - CPPUNIT_ASSERT( ct.is(ctype_base::xdigit, 'a') ); - } - - //is range - { - char values[] = "0Aa ."; - ctype_base::mask res[sizeof(values)]; - ct.is(values, values + sizeof(values), res); - // '0' - CPPUNIT_ASSERT( (res[0] & ctype_base::print) != 0 ); - CPPUNIT_ASSERT( (res[0] & ctype_base::digit) != 0 ); - CPPUNIT_ASSERT( (res[0] & ctype_base::xdigit) != 0 ); - // 'A' - CPPUNIT_ASSERT( (res[1] & ctype_base::print) != 0 ); - CPPUNIT_ASSERT( (res[1] & ctype_base::alpha) != 0 ); - CPPUNIT_ASSERT( (res[1] & ctype_base::xdigit) != 0 ); - CPPUNIT_ASSERT( (res[1] & ctype_base::upper) != 0 ); - // 'a' - CPPUNIT_ASSERT( (res[2] & ctype_base::print) != 0 ); - CPPUNIT_ASSERT( (res[2] & ctype_base::alpha) != 0 ); - CPPUNIT_ASSERT( (res[2] & ctype_base::xdigit) != 0 ); - CPPUNIT_ASSERT( (res[2] & ctype_base::lower) != 0 ); - CPPUNIT_ASSERT( (res[2] & ctype_base::space) == 0 ); - // ' ' - CPPUNIT_ASSERT( (res[3] & ctype_base::print) != 0 ); - CPPUNIT_ASSERT( (res[3] & ctype_base::space) != 0 ); - CPPUNIT_ASSERT( (res[3] & ctype_base::digit) == 0 ); - // '.' - CPPUNIT_ASSERT( (res[4] & ctype_base::print) != 0 ); - CPPUNIT_ASSERT( (res[4] & ctype_base::punct) != 0 ); - CPPUNIT_ASSERT( (res[4] & ctype_base::digit) == 0 ); - } - - //scan_is - { - char range[] = "abAc123 ."; - const char *rbeg = range; - const char *rend = range + sizeof(range); - - const char *res; - res = ct.scan_is((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend); - CPPUNIT_ASSERT( res != rend ); - CPPUNIT_ASSERT( *res == 'a' ); - - res = ct.scan_is(ctype_base::upper, rbeg, rend); - CPPUNIT_ASSERT( res != rend ); - CPPUNIT_ASSERT( *res == 'A' ); - - res = ct.scan_is(ctype_base::punct, rbeg, rend); - CPPUNIT_ASSERT( res != rend ); - CPPUNIT_ASSERT( *res == '.' ); - } - - //scan_not - { - char range[] = "abAc123 ."; - const char *rbeg = range; - const char *rend = range + sizeof(range); - - const char *res; - res = ct.scan_not((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend); - CPPUNIT_ASSERT( res != rend ); - CPPUNIT_ASSERT( *res == '1' ); - - res = ct.scan_not(ctype_base::alpha, rbeg, rend); - CPPUNIT_ASSERT( res != rend ); - CPPUNIT_ASSERT( *res == '1' ); - - res = ct.scan_not(ctype_base::punct, rbeg, rend); - CPPUNIT_ASSERT( res != rend ); - CPPUNIT_ASSERT( *res == 'a' ); - } - - //toupper - { - CPPUNIT_ASSERT( ct.toupper('a') == 'A' ); - CPPUNIT_ASSERT( ct.toupper('A') == 'A' ); - CPPUNIT_ASSERT( ct.toupper('1') == '1' ); - } - - //toupper range - { - char range[] = "abAc1"; - char expected_range[] = "ABAC1"; - ct.toupper(range, range + sizeof(range)); - CPPUNIT_ASSERT( equal(range, range + sizeof(range), expected_range) ); - } - - //tolower - { - CPPUNIT_ASSERT( ct.tolower('A') == 'a' ); - CPPUNIT_ASSERT( ct.tolower('a') == 'a' ); - CPPUNIT_ASSERT( ct.tolower('1') == '1' ); - } - - //tolower range - { - char range[] = "ABaC1"; - char expected_range[] = "abac1"; - ct.tolower(range, range + sizeof(range)); - CPPUNIT_ASSERT( equal(range, range + sizeof(range), expected_range) ); - } - - //widen - { - CPPUNIT_ASSERT( ct.widen('a') == 'a' ); - } - - //widen range - { - char range[] = "ABaC1"; - char res[sizeof(range)]; - ct.widen(range, range + sizeof(range), res); - CPPUNIT_ASSERT( equal(range, range + sizeof(range), res) ); - } - - //narrow - { - CPPUNIT_ASSERT( ct.narrow('a', 'b') == 'a' ); - } - - //narrow range - { - char range[] = "ABaC1"; - char res[sizeof(range)]; - ct.narrow(range, range + sizeof(range), 'b', res); - CPPUNIT_ASSERT( equal(range, range + sizeof(range), res) ); - } -} - -void LocaleTest::_ctype_facet_w( const locale& loc ) -{ -# ifndef _STLP_NO_WCHAR_T - CPPUNIT_ASSERT( has_facet<ctype<wchar_t> >(loc) ); - ctype<wchar_t> const& wct = use_facet<ctype<wchar_t> >(loc); - //is - { - CPPUNIT_CHECK( wct.is(ctype_base::digit, L'0') ); - CPPUNIT_CHECK( wct.is(ctype_base::upper, L'A') ); - CPPUNIT_CHECK( wct.is(ctype_base::lower, L'a') ); - CPPUNIT_CHECK( wct.is(ctype_base::alpha, L'A') ); - CPPUNIT_CHECK( wct.is(ctype_base::space, L' ') ); - CPPUNIT_CHECK( !wct.is(ctype_base::space, L'2') ); - CPPUNIT_CHECK( wct.is(ctype_base::punct, L'.') ); - CPPUNIT_CHECK( wct.is(ctype_base::xdigit, L'a') ); - } - - //is range - { - wchar_t values[] = L"0Aa ."; - ctype_base::mask res[sizeof(values) / sizeof(wchar_t)]; - wct.is(values, values + (sizeof(values) / sizeof(wchar_t)), res); - // '0' - CPPUNIT_CHECK( (res[0] & ctype_base::print) != 0 ); - CPPUNIT_CHECK( (res[0] & ctype_base::digit) != 0 ); - CPPUNIT_CHECK( (res[0] & ctype_base::xdigit) != 0 ); - // 'A' - CPPUNIT_CHECK( (res[1] & ctype_base::print) != 0 ); - CPPUNIT_CHECK( (res[1] & ctype_base::alpha) != 0 ); - CPPUNIT_CHECK( (res[1] & ctype_base::xdigit) != 0 ); - CPPUNIT_CHECK( (res[1] & ctype_base::upper) != 0 ); - // 'a' - CPPUNIT_CHECK( (res[2] & ctype_base::print) != 0 ); - CPPUNIT_CHECK( (res[2] & ctype_base::alpha) != 0 ); - CPPUNIT_CHECK( (res[2] & ctype_base::xdigit) != 0 ); - CPPUNIT_CHECK( (res[2] & ctype_base::lower) != 0 ); - CPPUNIT_CHECK( (res[2] & ctype_base::space) == 0 ); - // ' ' - CPPUNIT_CHECK( (res[3] & ctype_base::print) != 0 ); - CPPUNIT_CHECK( (res[3] & ctype_base::space) != 0 ); - CPPUNIT_CHECK( (res[3] & ctype_base::digit) == 0 ); - // '.' - CPPUNIT_CHECK( (res[4] & ctype_base::print) != 0 ); - CPPUNIT_CHECK( (res[4] & ctype_base::punct) != 0 ); - CPPUNIT_CHECK( (res[4] & ctype_base::digit) == 0 ); - } - - //scan_is - { - wchar_t range[] = L"abAc123 ."; - const wchar_t *rbeg = range; - const wchar_t *rend = range + (sizeof(range) / sizeof(wchar_t)); - - const wchar_t *res; - res = wct.scan_is((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend); - CPPUNIT_CHECK( res != rend ); - CPPUNIT_CHECK( *res == L'a' ); - - res = wct.scan_is(ctype_base::upper, rbeg, rend); - CPPUNIT_CHECK( res != rend ); - CPPUNIT_CHECK( *res == L'A' ); - - res = wct.scan_is(ctype_base::punct, rbeg, rend); - CPPUNIT_CHECK( res != rend ); - CPPUNIT_CHECK( *res == L'.' ); - } - - //scan_not - { - wchar_t range[] = L"abAc123 ."; - const wchar_t *rbeg = range; - const wchar_t *rend = range + (sizeof(range) / sizeof(wchar_t)); - - const wchar_t *res; - res = wct.scan_not((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend); - CPPUNIT_CHECK( res != rend ); - CPPUNIT_CHECK( *res == L'1' ); - - res = wct.scan_not(ctype_base::alpha, rbeg, rend); - CPPUNIT_CHECK( res != rend ); - CPPUNIT_CHECK( *res == L'1' ); - - res = wct.scan_not(ctype_base::punct, rbeg, rend); - CPPUNIT_CHECK( res != rend ); - CPPUNIT_CHECK( *res == L'a' ); - } - - //toupper - { - CPPUNIT_CHECK( wct.toupper(L'a') == L'A' ); - CPPUNIT_CHECK( wct.toupper(L'A') == L'A' ); - CPPUNIT_CHECK( wct.toupper(L'1') == L'1' ); - } - - //toupper range - { - wchar_t range[] = L"abAc1"; - wchar_t expected_range[] = L"ABAC1"; - wct.toupper(range, range + sizeof(range) / sizeof(wchar_t)); - CPPUNIT_CHECK( equal(range, range + sizeof(range) / sizeof(wchar_t), expected_range) ); - } - - //tolower - { - CPPUNIT_CHECK( wct.tolower(L'A') == L'a' ); - CPPUNIT_CHECK( wct.tolower(L'a') == L'a' ); - CPPUNIT_CHECK( wct.tolower(L'1') == L'1' ); - } - - //tolower range - { - wchar_t range[] = L"ABaC1"; - wchar_t expected_range[] = L"abac1"; - wct.tolower(range, range + sizeof(range) / sizeof(wchar_t)); - CPPUNIT_CHECK( equal(range, range + sizeof(range) / sizeof(wchar_t), expected_range) ); - } - - //widen - { - CPPUNIT_CHECK( wct.widen('a') == L'a' ); - } - - //widen range - { - char range[] = "ABaC1"; - wchar_t res[sizeof(range)]; - wchar_t expected_res[] = L"ABaC1"; - wct.widen(range, range + sizeof(range), res); - CPPUNIT_CHECK( equal(expected_res, expected_res + sizeof(range), res) ); - } - - //narrow - { - CPPUNIT_CHECK( wct.narrow(L'a', 'b') == L'a' ); - } - - //narrow range - { - wchar_t range[] = L"ABaC1"; - char res[sizeof(range) / sizeof(wchar_t)]; - char expected_res[] = "ABaC1"; - wct.narrow(range, range + sizeof(range) / sizeof(wchar_t), 'b', res); - CPPUNIT_CHECK( equal(expected_res, expected_res + sizeof(range) / sizeof(wchar_t), res) ); - } -# endif -} - - -typedef void (LocaleTest::*_Test) (const locale&); -static void test_supported_locale(LocaleTest& inst, _Test __test) { - size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]); - for (size_t i = 0; i < n; ++i) { - locale loc; -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try -# endif - { - locale tmp(tested_locales[i]); - loc = tmp; - } -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - catch (runtime_error const&) { - //This locale is not supported. - continue; - } -# endif - - CPPUNIT_MESSAGE( loc.name().c_str() ); - (inst.*__test)(loc); - - { - locale tmp(locale::classic(), tested_locales[i], locale::ctype); - loc = tmp; - } - (inst.*__test)(loc); - - { - locale tmp(locale::classic(), new ctype_byname<char>(tested_locales[i])); -#ifndef _STLP_NO_WCHAR_T - locale tmp0(tmp, new ctype_byname<wchar_t>(tested_locales[i])); - tmp = tmp0; -#endif - loc = tmp; - } - (inst.*__test)(loc); - } -} - -void LocaleTest::ctype_facet() -{ - test_supported_locale(*this, &LocaleTest::_ctype_facet); -#ifndef _STLP_NO_WCHAR_T - test_supported_locale(*this, &LocaleTest::_ctype_facet_w); -#endif -} - -void LocaleTest::ctype_by_name() -{ - /* - * Check of the 22.1.1.2.7 standard point. Construction of a locale - * instance from a null pointer or an unknown name should result in - * a runtime_error exception. - */ -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -# if defined (STLPORT) || (!defined(__GNUC__) && (!defined (_MSC_VER) || (_MSC_VER > 1400))) - // libstdc++ call freelocate on bad locale - try { - locale loc(locale::classic(), new ctype_byname<char>(static_cast<char const*>(0))); - CPPUNIT_ASSERT( false ); - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_ASSERT( false ); - } -# endif - - try { - locale loc(locale::classic(), new ctype_byname<char>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - -# if defined(STLPORT) || !defined(__GNUC__) - try { - locale loc(locale::classic(), new codecvt_byname<char, char, mbstate_t>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new codecvt_byname<char, char, mbstate_t>("yasli_language")); - //STLport implementation do not care about name pass to this facet. -# if !defined (STLPORT) - CPPUNIT_FAIL; -# endif - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new ctype_byname<char>("fr_FR")); - CPPUNIT_ASSERT( has_facet<ctype<char> >(loc) ); - ctype<char> const& ct = use_facet<ctype<char> >(loc); - CPPUNIT_ASSERT( ct.is(ctype_base::mask(ctype_base::print | ctype_base::lower | ctype_base::alpha), 'ç') ); - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new ctype_byname<char>("C")); - ctype<char> const& cfacet_byname = use_facet<ctype<char> >(loc); - ctype<char> const& cfacet = use_facet<ctype<char> >(locale::classic()); - - for (char c = 0;; ++c) { - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::space, c) == cfacet.is(ctype_base::space, c)); - if (cfacet_byname.is(ctype_base::print, c) != cfacet.is(ctype_base::print, c)) - { - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::print, c) == cfacet.is(ctype_base::print, c)); - } - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::cntrl, c) == cfacet.is(ctype_base::cntrl, c)); - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::upper, c) == cfacet.is(ctype_base::upper, c)); - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::lower, c) == cfacet.is(ctype_base::lower, c)); - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::alpha, c) == cfacet.is(ctype_base::alpha, c)); - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::digit, c) == cfacet.is(ctype_base::digit, c)); - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::punct, c) == cfacet.is(ctype_base::punct, c)); - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::xdigit, c) == cfacet.is(ctype_base::xdigit, c)); - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::alnum, c) == cfacet.is(ctype_base::alnum, c)); - CPPUNIT_CHECK(cfacet_byname.is(ctype_base::graph, c) == cfacet.is(ctype_base::graph, c)); - if (c == 127) break; - } - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) -# if defined(STLPORT) || !defined(__GNUC__) - try { - locale loc(locale::classic(), new ctype_byname<wchar_t>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new ctype_byname<wchar_t>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - -# if defined(STLPORT) || !defined(__GNUC__) - try { - locale loc(locale::classic(), new codecvt_byname<wchar_t, char, mbstate_t>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new codecvt_byname<wchar_t, char, mbstate_t>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } -# endif -# endif -} - -#endif diff --git a/test/unit/ctype_header_test.c b/test/unit/ctype_header_test.c deleted file mode 100644 index 8bd9fa6..0000000 --- a/test/unit/ctype_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <ctype.h> diff --git a/test/unit/cwchar_header_test.cpp b/test/unit/cwchar_header_test.cpp deleted file mode 100644 index 7a63390..0000000 --- a/test/unit/cwchar_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cwchar> diff --git a/test/unit/cwctype_header_test.cpp b/test/unit/cwctype_header_test.cpp deleted file mode 100644 index 0746b83..0000000 --- a/test/unit/cwctype_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <cwctype> diff --git a/test/unit/deque_header_test.cpp b/test/unit/deque_header_test.cpp deleted file mode 100644 index c945948..0000000 --- a/test/unit/deque_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <deque> diff --git a/test/unit/deque_test.cpp b/test/unit/deque_test.cpp deleted file mode 100644 index 6be7e01..0000000 --- a/test/unit/deque_test.cpp +++ /dev/null @@ -1,330 +0,0 @@ -//Has to be first for StackAllocator swap overload to be taken -//into account (at least using GCC 4.0.1) -#include "stack_allocator.h" - -#include <deque> -#include <algorithm> -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -# include <stdexcept> -#endif - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class DequeTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(DequeTest); - CPPUNIT_TEST(deque1); - CPPUNIT_TEST(at); - CPPUNIT_TEST(insert); - CPPUNIT_TEST(erase); - CPPUNIT_TEST(auto_ref); - CPPUNIT_TEST(allocator_with_state); -#if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(optimizations_check); - CPPUNIT_TEST_SUITE_END(); - -protected: - void deque1(); - void insert(); - void erase(); - void at(); - void auto_ref(); - void allocator_with_state(); - void optimizations_check(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(DequeTest); - -// -// tests implementation -// -void DequeTest::deque1() -{ - deque<int> d; - d.push_back(4); - d.push_back(9); - d.push_back(16); - d.push_front(1); - - CPPUNIT_ASSERT( d[0] == 1 ); - CPPUNIT_ASSERT( d[1] == 4 ); - CPPUNIT_ASSERT( d[2] == 9 ); - CPPUNIT_ASSERT( d[3] == 16 ); - - d.pop_front(); - d[2] = 25; - - CPPUNIT_ASSERT( d[0] == 4 ); - CPPUNIT_ASSERT( d[1] == 9 ); - CPPUNIT_ASSERT( d[2] == 25 ); - - //Some compile time tests: - deque<int>::iterator dit = d.begin(); - deque<int>::const_iterator cdit(d.begin()); - CPPUNIT_ASSERT( (dit - cdit) == 0 ); - CPPUNIT_ASSERT( (cdit - dit) == 0 ); - CPPUNIT_ASSERT( (dit - dit) == 0 ); - CPPUNIT_ASSERT( (cdit - cdit) == 0 ); - CPPUNIT_ASSERT(!((dit < cdit) || (dit > cdit) || (dit != cdit) || !(dit <= cdit) || !(dit >= cdit))); -} - -void DequeTest::insert() -{ - deque<int> d; - d.push_back(0); - d.push_back(1); - d.push_back(2); - CPPUNIT_ASSERT( d.size() == 3 ); - - deque<int>::iterator dit; - - //Insertion before begin: - dit = d.insert(d.begin(), 3); - CPPUNIT_ASSERT( dit != d.end() ); - CPPUNIT_CHECK( *dit == 3 ); - CPPUNIT_ASSERT( d.size() == 4 ); - CPPUNIT_ASSERT( d[0] == 3 ); - - //Insertion after begin: - dit = d.insert(d.begin() + 1, 4); - CPPUNIT_ASSERT( dit != d.end() ); - CPPUNIT_CHECK( *dit == 4 ); - CPPUNIT_ASSERT( d.size() == 5 ); - CPPUNIT_ASSERT( d[1] == 4 ); - - //Insertion at end: - dit = d.insert(d.end(), 5); - CPPUNIT_ASSERT( dit != d.end() ); - CPPUNIT_CHECK( *dit == 5 ); - CPPUNIT_ASSERT( d.size() == 6 ); - CPPUNIT_ASSERT( d[5] == 5 ); - - //Insertion before last element: - dit = d.insert(d.end() - 1, 6); - CPPUNIT_ASSERT( dit != d.end() ); - CPPUNIT_CHECK( *dit == 6 ); - CPPUNIT_ASSERT( d.size() == 7 ); - CPPUNIT_ASSERT( d[5] == 6 ); - - //Insertion of several elements before begin - d.insert(d.begin(), 2, 7); - CPPUNIT_ASSERT( d.size() == 9 ); - CPPUNIT_ASSERT( d[0] == 7 ); - CPPUNIT_ASSERT( d[1] == 7 ); - - //Insertion of several elements after begin - //There is more elements to insert than elements before insertion position - d.insert(d.begin() + 1, 2, 8); - CPPUNIT_ASSERT( d.size() == 11 ); - CPPUNIT_ASSERT( d[1] == 8 ); - CPPUNIT_ASSERT( d[2] == 8 ); - - //There is less elements to insert than elements before insertion position - d.insert(d.begin() + 3, 2, 9); - CPPUNIT_ASSERT( d.size() == 13 ); - CPPUNIT_ASSERT( d[3] == 9 ); - CPPUNIT_ASSERT( d[4] == 9 ); - - //Insertion of several elements at end: - d.insert(d.end(), 2, 10); - CPPUNIT_ASSERT( d.size() == 15 ); - CPPUNIT_ASSERT( d[14] == 10 ); - CPPUNIT_ASSERT( d[13] == 10 ); - - //Insertion of several elements before last: - //There is more elements to insert than elements after insertion position - d.insert(d.end() - 1, 2, 11); - CPPUNIT_ASSERT( d.size() == 17 ); - CPPUNIT_ASSERT( d[15] == 11 ); - CPPUNIT_ASSERT( d[14] == 11 ); - - //There is less elements to insert than elements after insertion position - d.insert(d.end() - 3, 2, 12); - CPPUNIT_ASSERT( d.size() == 19 ); - CPPUNIT_ASSERT( d[15] == 12 ); - CPPUNIT_ASSERT( d[14] == 12 ); -} - -void DequeTest::at() { - deque<int> d; - deque<int> const& cd = d; - - d.push_back(10); - CPPUNIT_ASSERT( d.at(0) == 10 ); - d.at(0) = 20; - CPPUNIT_ASSERT( cd.at(0) == 20 ); - -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - for (;;) { - try { - d.at(1) = 20; - CPPUNIT_ASSERT(false); - } - catch (out_of_range const&) { - return; - } - catch (...) { - CPPUNIT_ASSERT(false); - } - } -#endif -} - -void DequeTest::auto_ref() -{ - int i; - deque<int> ref; - for (i = 0; i < 5; ++i) { - ref.push_back(i); - } - - deque<deque<int> > d_d_int(1, ref); - d_d_int.push_back(d_d_int[0]); - d_d_int.push_back(ref); - d_d_int.push_back(d_d_int[0]); - d_d_int.push_back(d_d_int[0]); - d_d_int.push_back(ref); - - for (i = 0; i < 5; ++i) { - CPPUNIT_ASSERT( d_d_int[i] == ref ); - } -} - -void DequeTest::allocator_with_state() -{ - char buf1[1024]; - StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1)); - - char buf2[1024]; - StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2)); - - { - typedef deque<int, StackAllocator<int> > DequeInt; - DequeInt dint1(10, 0, stack1); - DequeInt dint1Cpy(dint1); - - DequeInt dint2(10, 1, stack2); - DequeInt dint2Cpy(dint2); - - dint1.swap(dint2); - - CPPUNIT_ASSERT( dint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( dint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( dint1 == dint2Cpy ); - CPPUNIT_ASSERT( dint2 == dint1Cpy ); - CPPUNIT_ASSERT( dint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( dint2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); -} - -struct Point { - int x, y; -}; - -struct PointEx : public Point { - PointEx() : builtFromBase(false) {} - PointEx(const Point&) : builtFromBase(true) {} - - bool builtFromBase; -}; - -#if defined (STLPORT) -# if defined (_STLP_USE_NAMESPACES) -namespace std { -# endif - _STLP_TEMPLATE_NULL - struct __type_traits<PointEx> { - typedef __false_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; -# if defined (_STLP_USE_NAMESPACES) -} -# endif -#endif - -//This test check that deque implementation do not over optimize -//operation as PointEx copy constructor is trivial -void DequeTest::optimizations_check() -{ -#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) - deque<Point> d1(1); - CPPUNIT_ASSERT( d1.size() == 1 ); - - deque<PointEx> d2(d1.begin(), d1.end()); - CPPUNIT_ASSERT( d2.size() == 1 ); - CPPUNIT_ASSERT( d2[0].builtFromBase == true ); - - d2.insert(d2.end(), d1.begin(), d1.end()); - CPPUNIT_ASSERT( d2.size() == 2 ); - CPPUNIT_ASSERT( d2[1].builtFromBase == true ); -#endif -} - -void DequeTest::erase() -{ - deque<int> dint; - dint.push_back(3); - dint.push_front(2); - dint.push_back(4); - dint.push_front(1); - dint.push_back(5); - dint.push_front(0); - dint.push_back(6); - - deque<int>::iterator it(dint.begin() + 1); - CPPUNIT_ASSERT( *it == 1 ); - - dint.erase(dint.begin()); - CPPUNIT_ASSERT( *it == 1 ); - - it = dint.end() - 2; - CPPUNIT_ASSERT( *it == 5 ); - - dint.erase(dint.end() - 1); - CPPUNIT_ASSERT( *it == 5 ); - - dint.push_back(6); - dint.push_front(0); - - it = dint.begin() + 2; - CPPUNIT_ASSERT( *it == 2 ); - - dint.erase(dint.begin(), dint.begin() + 2); - CPPUNIT_ASSERT( *it == 2 ); - - it = dint.end() - 3; - CPPUNIT_ASSERT( *it == 4 ); - - dint.erase(dint.end() - 2, dint.end()); - CPPUNIT_ASSERT( *it == 4 ); -} - -#if (!defined (STLPORT) || \ - (!defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION))) && \ - (!defined (_MSC_VER) || (_MSC_VER > 1400)) && \ - (!defined(__GNUC__) || (__GNUC__ < 4) || (__GNUC_MINOR__ < 3)) -/* Simple compilation test: Check that nested types like iterator - * can be access even if type used to instanciate container is not - * yet completely defined. - */ -class IncompleteClass -{ - deque<IncompleteClass> instances; - typedef deque<IncompleteClass>::size_type size; -}; -#endif diff --git a/test/unit/divides_test.cpp b/test/unit/divides_test.cpp deleted file mode 100644 index 73e35cd..0000000 --- a/test/unit/divides_test.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include <numeric> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class DivideTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(DivideTest); - CPPUNIT_TEST(div); - CPPUNIT_TEST_SUITE_END(); - -protected: - void div(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(DivideTest); - -// -// tests implementation -// -void DivideTest::div() -{ - int input [3] = { 2, 3, 4 }; - int result = accumulate(input, input + 3, 48, divides<int>()); - CPPUNIT_ASSERT(result==2); -} diff --git a/test/unit/epilog_test.cpp b/test/unit/epilog_test.cpp deleted file mode 100644 index 07e28f3..0000000 --- a/test/unit/epilog_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include <time.h> -#include <string> - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) - -struct some_struct { - std::string s; // if std not properly redefined, error will be here -}; - -#endif diff --git a/test/unit/equal_test.cpp b/test/unit/equal_test.cpp deleted file mode 100644 index 91c0ae2..0000000 --- a/test/unit/equal_test.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class EqualTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(EqualTest); - CPPUNIT_TEST(equal_range0); - CPPUNIT_TEST(equal_range1); - CPPUNIT_TEST(equal_range2); - CPPUNIT_TEST(equal0); - CPPUNIT_TEST(equal1); - CPPUNIT_TEST(equal2); - CPPUNIT_TEST(equalto); - CPPUNIT_TEST_SUITE_END(); - -protected: - void equal_range0(); - void equal_range1(); - void equal_range2(); - void equal0(); - void equal1(); - void equal2(); - void equalto(); - static bool values_squared(int a_, int b_); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(EqualTest); - -// -// tests implementation -// -void EqualTest::equal_range0() -{ - int numbers[10] = { 0, 0, 1, 1, 2, 2, 2, 2, 3, 3 }; - pair<int*, int*> range = equal_range((int*)numbers, (int*)numbers + 10, 2); - CPPUNIT_ASSERT( (range.first - numbers) == 4 ); - CPPUNIT_ASSERT( (range.second - numbers) == 8 ); -} - -void EqualTest::equal_range1() -{ - typedef vector <int> IntVec; - IntVec v(10); - for (int i = 0; (size_t)i < v.size(); ++i) - v[i] = i / 3; - - pair<IntVec::iterator, IntVec::iterator> range = equal_range(v.begin(), v.end(), 2); - CPPUNIT_ASSERT( (range.first - v.begin()) == 6 ); - CPPUNIT_ASSERT( (range.second - v.begin()) == 9 ); - for (; range.first != range.second; ++range.first) - CPPUNIT_ASSERT( *range.first == 2 ); - - range = equal_range(v.begin(), v.end(), 4); - CPPUNIT_ASSERT( range.first == range.second ); - CPPUNIT_ASSERT( range.first == v.end() ); -} - -struct Test { -#if defined (__DMC__) - Test(); -#endif - - Test(int val) : value(val) {} - int value; - - bool operator == (int i) const - { return value == i; } -}; - -bool operator < (const Test& v1, int v2) -{ return v1.value < v2; } - -bool operator < (int v1, const Test& v2) -{ return v1 < v2.value; } - -#if defined (_MSC_VER) && !defined (STLPORT) -bool operator < (const Test& v1, const Test& v2) -{ return v1.value < v2.value; } -#endif - -void EqualTest::equal_range2() -{ - char chars[] = "aabbccddggghhklllmqqqqssyyzz"; - - const unsigned count = sizeof(chars) - 1; - pair<char*, char*> range = equal_range((char*)chars, (char*)chars + count, 'q', less<char>()); - CPPUNIT_ASSERT( (range.first - chars) == 18 ); - CPPUNIT_ASSERT( (range.second - chars) == 22 ); - for (; range.first != range.second; ++range.first) - CPPUNIT_ASSERT( *range.first == 'q' ); - - range = equal_range((char*)chars, (char*)chars + count, 'm', less<char>()); - CPPUNIT_ASSERT( (range.second - range.first) == 1 ); - CPPUNIT_ASSERT( *range.first == 'm' ); - - vector<Test> tv; - vector<Test>::iterator it; - pair<vector<Test>::iterator, vector<Test>::iterator> p; - - for (int i = 0; i < 10; ++i) { - tv.push_back(i); - } - - it = upper_bound(tv.begin(), tv.end(), 5); - CPPUNIT_ASSERT( it != tv.end() ); - CPPUNIT_ASSERT( *it == 6 ); - - it = lower_bound(tv.begin(), tv.end(), 5); - CPPUNIT_ASSERT( it != tv.end() ); - CPPUNIT_ASSERT( *it == 5 ); - - p = equal_range(tv.begin(), tv.end(), 5); - CPPUNIT_ASSERT( p.first != p.second ); - CPPUNIT_ASSERT( p.first != tv.end() ); - CPPUNIT_ASSERT( p.second != tv.end() ); - CPPUNIT_ASSERT( *p.first == 5 ); - CPPUNIT_ASSERT( *p.second == 6 ); -} - -void EqualTest::equal0() -{ - int numbers1[5] = { 1, 2, 3, 4, 5 }; - int numbers2[5] = { 1, 2, 4, 8, 16 }; - int numbers3[2] = { 1, 2 }; - - CPPUNIT_ASSERT( !equal(numbers1, numbers1 + 5, numbers2) ); - CPPUNIT_ASSERT( equal(numbers3, numbers3 + 2, numbers1) ); -} - -void EqualTest::equal1() -{ - vector <int> v1(10); - for (int i = 0; (size_t)i < v1.size(); ++i) - v1[i] = i; - vector <int> v2(10); - CPPUNIT_ASSERT( !equal(v1.begin(), v1.end(), v2.begin()) ); - - copy(v1.begin(), v1.end(), v2.begin()); - CPPUNIT_ASSERT( equal(v1.begin(), v1.end(), v2.begin()) ) -} - -void EqualTest::equal2() -{ - vector <int> v1(10); - vector <int> v2(10); - for (int i = 0; (size_t)i < v1.size(); ++i) { - v1[i] = i; - v2[i] = i * i; - } - CPPUNIT_ASSERT( equal(v1.begin(), v1.end(), v2.begin(), values_squared) ); -} - -void EqualTest::equalto() -{ - int input1 [4] = { 1, 7, 2, 2 }; - int input2 [4] = { 1, 6, 2, 3 }; - - int output [4]; - transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, equal_to<int>()); - CPPUNIT_ASSERT( output[0] == 1 ); - CPPUNIT_ASSERT( output[1] == 0 ); - CPPUNIT_ASSERT( output[2] == 1 ); - CPPUNIT_ASSERT( output[3] == 0 ); -} - -bool EqualTest::values_squared(int a_, int b_) -{ - return (a_ * a_ == b_); -} diff --git a/test/unit/errno_header_test.c b/test/unit/errno_header_test.c deleted file mode 100644 index 0a0accb..0000000 --- a/test/unit/errno_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <errno.h> diff --git a/test/unit/exception_header_test.cpp b/test/unit/exception_header_test.cpp deleted file mode 100644 index d784ab9..0000000 --- a/test/unit/exception_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <exception> diff --git a/test/unit/exception_test.cpp b/test/unit/exception_test.cpp deleted file mode 100644 index 1879945..0000000 --- a/test/unit/exception_test.cpp +++ /dev/null @@ -1,193 +0,0 @@ -#include <exception> -#include <stdexcept> -#include <string> - -#include "cppunit/cppunit_proxy.h" - -#if defined (STLPORT) && defined (_STLP_USE_NAMESPACES) -/* - * This test case purpose is to check that the exception handling - * functions are correctly imported to the STLport namespace only - * if they have a right behavior. - * Otherwise they are not imported to report the problem as a compile - * time error. - */ - -// -// TestCase class -// -class ExceptionTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ExceptionTest); -#if defined (STLPORT) && !defined (_STLP_USE_EXCEPTIONS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(what); -#if defined (STLPORT) && defined (_STLP_NO_UNEXPECTED_EXCEPT_SUPPORT) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(unexpected_except); -#if defined (STLPORT) && defined (_STLP_USE_EXCEPTIONS) - CPPUNIT_STOP_IGNORE; -#endif -#if defined (STLPORT) && defined (_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(uncaught_except); -#if defined (STLPORT) && defined (_STLP_USE_EXCEPTIONS) - CPPUNIT_STOP_IGNORE; -#endif - CPPUNIT_TEST(exception_emission); - CPPUNIT_TEST_SUITE_END(); - -protected: - void what(); - void unexpected_except(); - void uncaught_except(); - void exception_emission(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ExceptionTest); - -#if !defined (STLPORT) || !defined (_STLP_NO_UNEXPECTED_EXCEPT_SUPPORT) -bool g_unexpected_called = false; -void unexpected_hdl() { - g_unexpected_called = true; - throw std::bad_exception(); -} - -struct special_except {}; -void throw_func() { - throw special_except(); -} - -void throw_except_func() throw(std::exception) { - throw_func(); -} -#endif - -void ExceptionTest::what() -{ - try { - throw std::runtime_error( std::string( "message" ) ); - } - catch ( std::runtime_error& err ) { - CPPUNIT_CHECK( strcmp( err.what(), "message" ) == 0 ); - } -} - -void ExceptionTest::unexpected_except() -{ -#if !defined (STLPORT) || !defined (_STLP_NO_UNEXPECTED_EXCEPT_SUPPORT) - std::unexpected_handler hdl = &unexpected_hdl; - std::set_unexpected(hdl); - - try { - throw_except_func(); - } - catch (std::bad_exception const&) { - CPPUNIT_ASSERT( true ); - } - catch (special_except) { - CPPUNIT_ASSERT( false ); - } - CPPUNIT_ASSERT( g_unexpected_called ); -#endif -} - -#if !defined (STLPORT) || !defined (_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT) -struct UncaughtClassTest -{ - UncaughtClassTest(int &res) : _res(res) - {} - - ~UncaughtClassTest() { - _res = std::uncaught_exception()?1:0; - } - - int &_res; -}; -#endif - -void ExceptionTest::uncaught_except() -{ -#if !defined (STLPORT) || !defined (_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT) - int uncaught_result = -1; - { - UncaughtClassTest test_inst(uncaught_result); - CPPUNIT_ASSERT( uncaught_result == -1 ); - } - CPPUNIT_ASSERT( uncaught_result == 0 ); - - { - try { - uncaught_result = -1; - UncaughtClassTest test_inst(uncaught_result); - throw "exception"; - } - catch (...) { - } - } - CPPUNIT_ASSERT( uncaught_result == 1 ); -#endif -} - -void ExceptionTest::exception_emission() -{ -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - std::string foo = "foo"; - try { - throw std::runtime_error(foo); - } - catch (std::runtime_error const& e) { - CPPUNIT_ASSERT( foo == e.what() ); - std::runtime_error clone(""); - clone = e; - CPPUNIT_ASSERT(foo == clone.what() ); - } - catch (...) { - CPPUNIT_ASSERT( false ); - } - - try { - throw std::runtime_error(foo); - } - catch (std::runtime_error e) { - CPPUNIT_ASSERT( foo == e.what() ); - std::runtime_error clone(""); - clone = e; - CPPUNIT_ASSERT(foo == clone.what() ); - } - catch (...) { - CPPUNIT_ASSERT( false ); - } - - std::string msg(512, 'a'); - try { - throw std::runtime_error(msg); - } - catch (std::runtime_error const& e) { - CPPUNIT_ASSERT(msg == e.what() ); - std::runtime_error clone(""); - clone = e; - CPPUNIT_ASSERT(msg == clone.what() ); - } - catch (...) { - CPPUNIT_ASSERT( false ); - } - - try { - throw std::runtime_error(msg); - } - catch (std::runtime_error e) { - CPPUNIT_ASSERT(msg == e.what() ); - std::runtime_error clone(""); - clone = e; - CPPUNIT_ASSERT(msg == clone.what() ); - } - catch (...) { - CPPUNIT_ASSERT( false ); - } -#endif -} -#endif diff --git a/test/unit/fadapter.h b/test/unit/fadapter.h deleted file mode 100644 index b1cceaf..0000000 --- a/test/unit/fadapter.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef _fadapter_h_ -#define _fadapter_h_ - -#include <functional> - -// used as adaptor's return/argument type, -// to allow binders/composers usage -struct __void_tag {}; - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -using std::unary_function; -#endif - -template <class Result> -class pointer_to_void_function { -protected: - Result (*ptr)(); -public: - explicit pointer_to_void_function(Result (*x)()) : ptr(x) {} - Result operator()() const { return ptr(); } - Result operator()(__void_tag) const { return ptr(); } -}; - -// to feed composers -template <class Arg1> -struct projectvoid : public unary_function<Arg1,__void_tag> { - __void_tag operator()(const Arg1& x) const { return __void_tag(); } -}; - -#if !defined (_STLP_MEMBER_POINTER_PARAM_BUG) - -template <class Result> -pointer_to_void_function<Result> ptr_fun(Result (*x)()) { - return pointer_to_void_function<Result>(x); -} - -// alternate name -template <class Result> -pointer_to_void_function<Result> ptr_gen(Result (*x)()) { - return pointer_to_void_function<Result>(x); -} - -#endif /* !defined (_STLP_MEMBER_POINTER_PARAM_BUG) */ - -template <class Arg> -class pointer_to_unary_procedure /* :public unary_function<Arg, __void_tag> */ { -protected: - typedef void (*fun_type)(Arg); - fun_type ptr; -public: - typedef Arg argument_type; - pointer_to_unary_procedure() {} - pointer_to_unary_procedure(fun_type x) : ptr(x) {} - void operator() (Arg x) const { ptr(x); } -}; - -template <class Arg> -inline pointer_to_unary_procedure<Arg> ptr_proc(void (*x)(Arg)) { - return pointer_to_unary_procedure<Arg>(x); -} - -template <class Arg1, class Arg2> -class pointer_to_binary_procedure /* : public unary_function<Arg1, Arg2, __void_tag> */ { -protected: - typedef void (*fun_type)(Arg1, Arg2); - fun_type ptr; -public: - typedef Arg1 first_argument_type; - typedef Arg2 second_argument_type; - pointer_to_binary_procedure() {} - pointer_to_binary_procedure(fun_type x) : ptr(x) {} - void operator() (Arg1 x, Arg2 y) const { ptr(x, y); } -}; - -template <class Arg1, class Arg2> -inline pointer_to_binary_procedure<Arg1, Arg2> ptr_proc(void (*x)(Arg1, Arg2)) { - return pointer_to_binary_procedure<Arg1, Arg2>(x); -} - -#endif diff --git a/test/unit/fib.h b/test/unit/fib.h deleted file mode 100644 index 9c74038..0000000 --- a/test/unit/fib.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _fib_h -#define _fib_h -class Fibonacci -{ - public: - Fibonacci() : v1(0), v2(1) {} - inline int operator()(); - private: - int v1; - int v2; -}; - -inline int -Fibonacci::operator()() -{ - int r = v1 + v2; - v1 = v2; - v2 = r; - return v1; -} -#endif // _fib_h diff --git a/test/unit/fill_test.cpp b/test/unit/fill_test.cpp deleted file mode 100644 index 22d3fe9..0000000 --- a/test/unit/fill_test.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class FillTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(FillTest); - CPPUNIT_TEST(fill1); - CPPUNIT_TEST(filln1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void fill1(); - void filln1(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(FillTest); - -// -// tests implementation -// -void FillTest::fill1() -{ - vector <int> v(10); - fill(v.begin(), v.end(), 42); - - CPPUNIT_ASSERT(v[0]==42); - CPPUNIT_ASSERT(v[1]==42); - CPPUNIT_ASSERT(v[2]==42); - CPPUNIT_ASSERT(v[3]==42); - CPPUNIT_ASSERT(v[4]==42); - CPPUNIT_ASSERT(v[5]==42); - CPPUNIT_ASSERT(v[6]==42); - CPPUNIT_ASSERT(v[7]==42); - CPPUNIT_ASSERT(v[8]==42); - CPPUNIT_ASSERT(v[9]==42); -} -void FillTest::filln1() -{ - vector <int> v(10); - fill_n(v.begin(), v.size(), 42); - - CPPUNIT_ASSERT(v[0]==42); - CPPUNIT_ASSERT(v[1]==42); - CPPUNIT_ASSERT(v[2]==42); - CPPUNIT_ASSERT(v[3]==42); - CPPUNIT_ASSERT(v[4]==42); - CPPUNIT_ASSERT(v[5]==42); - CPPUNIT_ASSERT(v[6]==42); - CPPUNIT_ASSERT(v[7]==42); - CPPUNIT_ASSERT(v[8]==42); - CPPUNIT_ASSERT(v[9]==42); -} diff --git a/test/unit/find_test.cpp b/test/unit/find_test.cpp deleted file mode 100644 index d910f33..0000000 --- a/test/unit/find_test.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class FindTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(FindTest); - CPPUNIT_TEST(find0); - CPPUNIT_TEST(find1); - CPPUNIT_TEST(findif0); - CPPUNIT_TEST(findif1); - CPPUNIT_TEST(find_char); - CPPUNIT_TEST_SUITE_END(); - -protected: - void find0(); - void find1(); - void findif0(); - void findif1(); - void find_char(); - static bool odd(int a_); - static bool div_3(int a_); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(FindTest); - -// -// tests implementation -// -void FindTest::find0() -{ - int numbers[10] = { 0, 1, 4, 9, 16, 25, 36, 49, 64 }; - - int *location = find((int*)numbers, (int*)numbers + 10, 25); - - CPPUNIT_ASSERT((location - numbers)==5); - - int *out_range = find((int*)numbers, (int*)numbers + 10, 128); - - CPPUNIT_ASSERT( out_range == (int *)(numbers + 10) ); -} - -struct Key -{ - int data; - - /* This operator should rather be global and commutative - but implementing it this way show that STLport used to - ask too much from the user code. */ - bool operator == (int d) const - { - return data == d; - } -}; - -void FindTest::find1() -{ - int years[] = { 1942, 1952, 1962, 1972, 1982, 1992 }; - - const unsigned yearCount = sizeof(years) / sizeof(years[0]); - int* location = find((int*)years, (int*)years + yearCount, 1972); - - CPPUNIT_ASSERT((location - years)==3); -} - -void FindTest::findif0() -{ - { - int numbers[6] = { 2, 4, 8, 15, 32, 64 }; - int *location = find_if((int*)numbers, (int*)numbers + 6, odd); - - CPPUNIT_ASSERT((location - numbers)==3); - - int numbers_even[6] = { 2, 4, 8, 16, 32, 64 }; - - int *out_range = find_if((int*)numbers_even, (int*)numbers_even + 6, odd); - - CPPUNIT_ASSERT( out_range == (int *)(numbers_even + 6) ); - } - - { - Key keys[10] = { {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} }; - Key const* k = find(keys + 0, keys + 10, 5); - CPPUNIT_ASSERT( k == keys + 10 ); - } -} - -void FindTest::findif1() -{ - typedef vector <int> IntVec; - IntVec v(10); - for(int i = 0; (size_t)i < v.size(); ++i) - v[i] =(i + 1) *(i + 1); - IntVec::iterator iter; - iter = find_if(v.begin(), v.end(), div_3); - CPPUNIT_ASSERT((iter - v.begin())==2); -} - -bool FindTest::odd(int a_) -{ - return (a_ % 2) != 0; -} - -bool FindTest::div_3(int a_) -{ - return a_ % 3 ? 0 : 1; -} - -void FindTest::find_char() -{ - char str[] = "abcdefghij"; - char *pstr = (char*)str; - const char* cpstr = (const char*)str; - size_t str_size = sizeof(str) / sizeof(char); - - char *d = find(pstr, pstr + str_size, 'd'); - CPPUNIT_ASSERT( *d == 'd' ); - - const char *e = find(cpstr, cpstr + str_size, 'e'); - CPPUNIT_ASSERT( *e == 'e' ); - - char *last = find(pstr, pstr + str_size, 'x'); - CPPUNIT_ASSERT( last == pstr + str_size ); - - const char *clast = find(cpstr, cpstr + str_size, 'x'); - CPPUNIT_ASSERT( clast == cpstr + str_size ); -} diff --git a/test/unit/finsert_test.cpp b/test/unit/finsert_test.cpp deleted file mode 100644 index e45289e..0000000 --- a/test/unit/finsert_test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include <vector> -#include <algorithm> -#include <deque> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class FinsertTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(FinsertTest); - CPPUNIT_TEST(finsert1); - CPPUNIT_TEST(finsert2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void finsert1(); - void finsert2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(FinsertTest); - -// -// tests implementation -// -void FinsertTest::finsert1() -{ - char const* array [] = { "laurie", "jennifer", "leisa" }; - deque<char const*> names; - front_insert_iterator<deque<char const*> > fit(names); - fit = copy(array, array + 3, front_insert_iterator<deque <char const*> >(names)); - - CPPUNIT_ASSERT(names[0]==array[2]); - CPPUNIT_ASSERT(names[1]==array[1]); - CPPUNIT_ASSERT(names[2]==array[0]); - - copy(array, array + 3, fit); - CPPUNIT_ASSERT(names[3]==array[2]); - CPPUNIT_ASSERT(names[4]==array[1]); - CPPUNIT_ASSERT(names[5]==array[0]); -} - -void FinsertTest::finsert2() -{ - char const* array [] = { "laurie", "jennifer", "leisa" }; - - deque<char const*> names; - copy(array, array + 3, front_inserter(names)); - - CPPUNIT_ASSERT(names[0]==array[2]); - CPPUNIT_ASSERT(names[1]==array[1]); - CPPUNIT_ASSERT(names[2]==array[0]); -} diff --git a/test/unit/float_header_test.c b/test/unit/float_header_test.c deleted file mode 100644 index bb3f28d..0000000 --- a/test/unit/float_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <float.h> diff --git a/test/unit/foreach_test.cpp b/test/unit/foreach_test.cpp deleted file mode 100644 index 76fd514..0000000 --- a/test/unit/foreach_test.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include <vector> -#include <algorithm> -#include "fadapter.h" - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class ForeachTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ForeachTest); - CPPUNIT_TEST(foreach0); - CPPUNIT_TEST(foreach1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void foreach0(); - void foreach1(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ForeachTest); - -// -// tests implementation -// -static void increase(int& a_) -{ - a_ += 1; -} -void ForeachTest::foreach0() -{ - int numbers[10] = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 }; - - for_each(numbers, numbers + 10, ptr_fun(increase)); - - CPPUNIT_ASSERT(numbers[0]==2); - CPPUNIT_ASSERT(numbers[1]==2); - CPPUNIT_ASSERT(numbers[2]==3); - CPPUNIT_ASSERT(numbers[3]==4); - CPPUNIT_ASSERT(numbers[4]==6); - CPPUNIT_ASSERT(numbers[5]==9); - CPPUNIT_ASSERT(numbers[6]==14); - CPPUNIT_ASSERT(numbers[7]==22); - CPPUNIT_ASSERT(numbers[8]==35); - CPPUNIT_ASSERT(numbers[9]==56); -} -static void sqr(int& a_) -{ - a_ = a_ * a_; -} -void ForeachTest::foreach1() -{ - vector<int> v1(10); - for (int i = 0; (size_t)i < v1.size(); ++i) - v1[i] = i; - for_each(v1.begin(), v1.end(), ptr_fun(sqr) ); - - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==4); - CPPUNIT_ASSERT(v1[3]==9); - CPPUNIT_ASSERT(v1[4]==16); - CPPUNIT_ASSERT(v1[5]==25); - CPPUNIT_ASSERT(v1[6]==36); - CPPUNIT_ASSERT(v1[7]==49); - CPPUNIT_ASSERT(v1[8]==64); - CPPUNIT_ASSERT(v1[9]==81); -} diff --git a/test/unit/fstream_header_test.cpp b/test/unit/fstream_header_test.cpp deleted file mode 100644 index 7fbe268..0000000 --- a/test/unit/fstream_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <fstream> -#endif diff --git a/test/unit/fstream_test.cpp b/test/unit/fstream_test.cpp deleted file mode 100644 index bba41a2..0000000 --- a/test/unit/fstream_test.cpp +++ /dev/null @@ -1,915 +0,0 @@ -#include <string> -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <fstream> -# include <iostream> -# include <iomanip> -# include <sstream> -# include <vector> -# include <stdexcept> - -#include <stdio.h> - -# include "full_streambuf.h" -# include "cppunit/cppunit_proxy.h" - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -//The macro value gives approximately the generated file -//size in Go -//#define CHECK_BIG_FILE 4 - -# if (!defined(STLPORT) && (defined (__GNUC__) && (__GNUC__ > 3))) || \ - (defined (STLPORT) && !defined (_STLP_NO_CUSTOM_IO) && !defined (_STLP_NO_MEMBER_TEMPLATES) && \ - !((defined (_STLP_MSVC) && (_STLP_MSVC < 1300)) || \ - (defined (__GNUC__) && (__GNUC__ < 3)) || \ - (defined (__SUNPRO_CC)) || \ - (defined (__DMC__) && defined (_DLL)))) -# define DO_CUSTOM_FACET_TEST -# endif - -// -// TestCase class -// -class FstreamTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(FstreamTest); - CPPUNIT_TEST(output); - CPPUNIT_TEST(input); - CPPUNIT_TEST(input_char); - CPPUNIT_TEST(io); - CPPUNIT_TEST(err); - CPPUNIT_TEST(tellg); - CPPUNIT_TEST(tellp); - CPPUNIT_TEST(seek); - CPPUNIT_TEST(buf); - CPPUNIT_TEST(rdbuf); - CPPUNIT_TEST(streambuf_output); - CPPUNIT_TEST(win32_file_format); - CPPUNIT_TEST(null_stream); -# if defined (STLPORT) && (defined (_STLP_NO_WCHAR_T) || !defined (_STLP_USE_EXCEPTIONS)) - CPPUNIT_IGNORE; -# endif - CPPUNIT_TEST(null_buf); -# if !defined (STLPORT) || !defined (_STLP_WIN32) - CPPUNIT_TEST(offset); -# endif -# if defined (CHECK_BIG_FILE) - CPPUNIT_TEST(big_file); -# endif -# if !defined (DO_CUSTOM_FACET_TEST) - CPPUNIT_IGNORE; -# endif - CPPUNIT_TEST(custom_facet); - CPPUNIT_TEST_SUITE_END(); - - protected: - void output(); - void input(); - void input_char(); - void io(); - void err(); - void tellg(); - void tellp(); - void seek(); - void buf(); - void rdbuf(); - void streambuf_output(); - void win32_file_format(); - void null_stream(); - void null_buf(); -# if !defined (STLPORT) || !defined (_STLP_WIN32) - void offset(); -# endif - void custom_facet(); -# if defined (CHECK_BIG_FILE) - void big_file(); -# endif -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(FstreamTest); - -// -// tests implementation -// -void FstreamTest::output() -{ - ofstream f( "test_file.txt" ); - - f << 1 << '\n' << 2.0 << '\n' << "abcd\n" << "ghk lm\n" << "abcd ef"; - CPPUNIT_ASSERT (f.good()); - // CPPUNIT_ASSERT( s.str() == "1\n2\nabcd\nghk lm\nabcd ef" ); -} - -void FstreamTest::input() -{ - { - ifstream f( "test_file.txt" ); - int i = 0; - f >> i; - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( i == 1 ); - double d = 0.0; - f >> d; - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( d == 2.0 ); - string str; - f >> str; - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( str == "abcd" ); - char c; - f.get(c); // extract newline, that not extracted by operator >> - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( c == '\n' ); - getline( f, str ); - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( str == "ghk lm" ); - getline( f, str ); - CPPUNIT_ASSERT( f.eof() ); - CPPUNIT_ASSERT( str == "abcd ef" ); - } -#if defined (STLPORT) && !defined (_STLP_USE_WIN32_IO) - { - ifstream in("/tmp"); - if (in.good()) { - string s; - getline(in, s); - CPPUNIT_ASSERT( in.fail() ); - } - } -#endif -} - -void FstreamTest::input_char() -{ - char buf[16] = { 0, '1', '2', '3' }; - ifstream s( "test_file.txt" ); - s >> buf; - - CPPUNIT_ASSERT( buf[0] == '1' ); - CPPUNIT_ASSERT( buf[1] == 0 ); - CPPUNIT_ASSERT( buf[2] == '2' ); -} - -void FstreamTest::io() -{ - basic_fstream<char,char_traits<char> > f( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc ); - - CPPUNIT_ASSERT( f.is_open() ); - - f << 1 << '\n' << 2.0 << '\n' << "abcd\n" << "ghk lm\n" << "abcd ef"; - - // f.flush(); - f.seekg( 0, ios_base::beg ); - - int i = 0; - f >> i; - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( i == 1 ); - double d = 0.0; - f >> d; - CPPUNIT_ASSERT( d == 2.0 ); - string s; - f >> s; - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( s == "abcd" ); - char c; - f.get(c); // extract newline, that not extracted by operator >> - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( c == '\n' ); - getline( f, s ); - CPPUNIT_ASSERT( f.good() ); - CPPUNIT_ASSERT( s == "ghk lm" ); - getline( f, s ); - CPPUNIT_ASSERT( !f.fail() ); - CPPUNIT_ASSERT( s == "abcd ef" ); - CPPUNIT_ASSERT( f.eof() ); -} - -void FstreamTest::err() -{ - basic_fstream<char,char_traits<char> > f( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc ); - - CPPUNIT_ASSERT( f.is_open() ); - - int i = 9; - f << i; - CPPUNIT_ASSERT( f.good() ); - i = 0; - f.seekg( 0, ios_base::beg ); - f >> i; - CPPUNIT_ASSERT( !f.fail() ); - CPPUNIT_ASSERT( i == 9 ); - f >> i; - CPPUNIT_ASSERT( f.fail() ); - CPPUNIT_ASSERT( f.eof() ); - CPPUNIT_ASSERT( i == 9 ); -} - -void FstreamTest::tellg() -{ - { - // bogus ios_base::binary is for Wins - ofstream of("test_file.txt", ios_base::out | ios_base::binary | ios_base::trunc); - CPPUNIT_ASSERT( of.is_open() ); - - for (int i = 0; i < 50; ++i) { - of << "line " << setiosflags(ios_base::right) << setfill('0') << setw(2) << i << "\n"; - CPPUNIT_ASSERT( !of.fail() ); - } - of.close(); - } - - { - // bogus ios_base::binary is for Wins - ifstream is("test_file.txt", ios_base::in | ios_base::binary); - CPPUNIT_ASSERT( is.is_open() ); - char buf[64]; - - // CPPUNIT_ASSERT( is.tellg() == 0 ); - streampos p = 0; - for (int i = 0; i < 50; ++i) { - is.read(buf, 0); - CPPUNIT_ASSERT( is.gcount() == 0 ); - CPPUNIT_ASSERT( is.tellg() == p ); - is.read( buf, 8 ); - CPPUNIT_ASSERT( !is.fail() ); - CPPUNIT_ASSERT( is.gcount() == 8 ); - p += 8; - } - } - - { - // bogus ios_base::binary is for Wins - ifstream is("test_file.txt", ios_base::in | ios_base::binary); - CPPUNIT_ASSERT( is.is_open() ); - - streampos p = 0; - for (int i = 0; i < 50; ++i) { - CPPUNIT_ASSERT( !is.fail() ); - is.tellg(); - CPPUNIT_ASSERT( is.tellg() == p ); - p += 8; - is.seekg( p, ios_base::beg ); - CPPUNIT_ASSERT( !is.fail() ); - } - } - - { - // bogus ios_base::binary is for Wins - ifstream is("test_file.txt", ios_base::in | ios_base::binary); - CPPUNIT_ASSERT( is.is_open() ); - - streampos p = 0; - for (int i = 0; i < 50; ++i) { - CPPUNIT_ASSERT( is.tellg() == p ); - p += 8; - is.seekg( 8, ios_base::cur ); - CPPUNIT_ASSERT( !is.fail() ); - } - } -} - -void FstreamTest::tellp() -{ - { - ofstream o( "test_file.txt" ); - - o << "123456"; - - CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(6) ); - CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(6) ); - } - { - ofstream o( "test_file.txt" ); - - o << "123456789"; - - CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(9) ); - CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(9) ); - } - /* According to the standard - ofstream o( "test_file.txt", ios_base::app | ios_base::out ) - should give the same effect as fopen( "test_file.txt", "a" ). - Problem is fopen( "test_file.txt", "a" ) has a bit different behaviour - on different platforms, and this difference is not covered by specification. - After fopen( "test_file.txt", "a" ) in this context ftell( f ) == 9 for - Linux and Mac OS X (I expect the same for others POSIX-like platforms too); - on Windows (independently from version?) ftell( f ) == 0, i.e. write pointer not - shifted to EOF (but shifted to EOF just before write, as described in the specs). - - It isn't specifications violation, neither for Linux and Mac OS X nor for Windows. - - The code below is intended to demonstrate ambiguity (dependance from fopen implementation). - */ - { - #ifdef WIN32 - //In Windows, stlport and fopen use kernel32.CreateFile for open. - //File position is at BOF after open, unless we open with ios_base::ate - long expected_pos = 0; - #else - //On UNIX flavours, stlport and fopen use unix's open - //File position is at EOF after open - // - //3rd possible scenario, "other platforms" - _STLP_USE_STDIO_IO - //stlport uses fopen here. This case may fail this test, since the file position after - //fopen is implementation-dependent - long expected_pos = 9; - #endif - ofstream o( "test_file.txt", ios_base::app | ios_base::out ); - CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(expected_pos) ); - CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(expected_pos) ); - } - { // for reference, to test fopen/ftell behaviour in append mode: - #ifdef WIN32 - long expected_pos = 0; - #else - long expected_pos = 9; - #endif - FILE* f = fopen( "test_file.txt", "a" ); - CPPUNIT_CHECK( ftell( f ) == expected_pos ); - fclose( f ); - } - { - //In append mode, file is positioned at EOF just before a write. - // After a write, file is at EOF. This is implementation-independent. - ofstream o( "test_file.txt", ios_base::app | ios_base::out ); - o << "X"; - CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == ofstream::pos_type(10) ); - CPPUNIT_CHECK( o.tellp() == ofstream::pos_type(10) ); - } -} - -void FstreamTest::buf() -{ - fstream ss( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc ); - - ss << "1234567\n89\n"; - ss.seekg( 0, ios_base::beg ); - char buf[10]; - buf[7] = 'x'; - ss.get( buf, 10 ); - CPPUNIT_ASSERT( !ss.fail() ); - CPPUNIT_ASSERT( buf[0] == '1' ); - CPPUNIT_ASSERT( buf[1] == '2' ); - CPPUNIT_ASSERT( buf[2] == '3' ); - CPPUNIT_ASSERT( buf[3] == '4' ); - CPPUNIT_ASSERT( buf[4] == '5' ); - CPPUNIT_ASSERT( buf[5] == '6' ); - CPPUNIT_ASSERT( buf[6] == '7' ); // 27.6.1.3 paragraph 10, paragraph 7 - CPPUNIT_ASSERT( buf[7] == 0 ); // 27.6.1.3 paragraph 8 - char c; - ss.get(c); - CPPUNIT_ASSERT( !ss.fail() ); - CPPUNIT_ASSERT( c == '\n' ); // 27.6.1.3 paragraph 10, paragraph 7 - ss.get(c); - CPPUNIT_ASSERT( !ss.fail() ); - CPPUNIT_ASSERT( c == '8' ); -} - -void FstreamTest::seek() -{ - { - // Test in binary mode: - { - fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc ); - CPPUNIT_ASSERT( s ); - - s << "1234567890\n"; - CPPUNIT_ASSERT( s ); - } - - char b1[] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' }; - fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary ); - CPPUNIT_ASSERT( s ); - - int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) ); - CPPUNIT_CHECK( chars_read == 11 ); - CPPUNIT_CHECK( b1[9] == '0' ); - CPPUNIT_ASSERT( s.rdbuf()->pubseekoff( 0, ios_base::cur ) == fstream::pos_type(chars_read) ); - CPPUNIT_ASSERT( s.rdbuf()->pubseekoff( -chars_read, ios_base::cur ) == fstream::pos_type(0) ); - - char b2[10] = { 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y' }; - - CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 10 ) == 10 ); - CPPUNIT_CHECK( b2[9] == '0' ); - } - - { - // Test in text mode: - { - fstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc ); - CPPUNIT_ASSERT( s ); - - s << "1234567890\n"; - CPPUNIT_ASSERT( s ); - } - - char b1[] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' }; - fstream s( "test_file.txt", ios_base::in | ios_base::out ); - CPPUNIT_ASSERT( s ); - - int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) ); - CPPUNIT_CHECK( chars_read == 11 ); - CPPUNIT_CHECK( b1[9] == '0' ); - - fstream::pos_type pos = s.rdbuf()->pubseekoff(0, ios_base::cur); - // Depending on how '\n' is written in file, file position can be greater or equal to the number of chars_read read. - streamoff offset = pos; - CPPUNIT_ASSERT( offset >= chars_read ); - offset = s.rdbuf()->pubseekoff( -offset, ios_base::cur ); - CPPUNIT_ASSERT( offset == 0 ); - - char b2[10] = { 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y' }; - - CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 5 ) == 5 ); - CPPUNIT_CHECK( b2[4] == '5' ); - - pos = s.rdbuf()->pubseekoff(0, ios_base::cur); - CPPUNIT_ASSERT( pos == fstream::pos_type(5) ); - CPPUNIT_ASSERT( s.rdbuf()->pubseekoff(-5, ios_base::cur) == fstream::pos_type(0) ); - } - -#if !defined (STLPORT) || \ - (!defined (_STLP_NO_WCHAR_T) && defined (_STLP_USE_EXCEPTIONS)) - { - // Test with a wariable encoding: - locale loc; - try - { - locale tmp(locale::classic(), new codecvt_byname<wchar_t, char, mbstate_t>(".UTF8")); - loc = tmp; - } - catch (const runtime_error&) - { - // Localization no supported so no test: - return; - } - - { - wfstream s( "test_file.txt", ios_base::in | ios_base::out | ios_base::trunc ); - CPPUNIT_ASSERT( s ); - s.imbue(loc); - CPPUNIT_ASSERT( s ); - - s << L"1234567890\n"; - CPPUNIT_ASSERT( s ); - } - - wchar_t b1[] = { L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x', L'x' }; - wfstream s( "test_file.txt", ios_base::in | ios_base::out ); - CPPUNIT_ASSERT( s ); - s.imbue(loc); - CPPUNIT_ASSERT( s ); - - int chars_read = (int)s.rdbuf()->sgetn( b1, sizeof(b1) / sizeof(wchar_t) ); - CPPUNIT_CHECK( chars_read == 11 ); - CPPUNIT_CHECK( b1[9] == L'0' ); - - fstream::pos_type pos = s.rdbuf()->pubseekoff(0, ios_base::cur); - // Depending on how '\n' is written in file, file position can be greater or equal to the number of chars_read read. - streamoff off = pos; - CPPUNIT_ASSERT( off >= chars_read ); - off = s.rdbuf()->pubseekoff(-off, ios_base::cur); - CPPUNIT_ASSERT( off == -1 ); - off = s.rdbuf()->pubseekoff(0, ios_base::beg); - CPPUNIT_ASSERT( off == 0 ); - - wchar_t b2[10] = { L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y', L'y' }; - - CPPUNIT_ASSERT( s.rdbuf()->sgetn( b2, 5 ) == 5 ); - CPPUNIT_CHECK( b2[4] == L'5' ); - - pos = s.rdbuf()->pubseekoff(0, ios_base::cur); - CPPUNIT_ASSERT( pos == fstream::pos_type(5) ); - //CPPUNIT_ASSERT( s.rdbuf()->pubseekoff(-5, ios_base::cur) == fstream::pos_type(0) ); - } -#endif -} - -void FstreamTest::rdbuf() -{ - fstream ss( "test_file.txt", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc ); - - ss << "1234567\n89\n"; - ss.seekg( 0, ios_base::beg ); - - ostringstream os; - ss.get( *os.rdbuf(), '\n' ); - CPPUNIT_ASSERT( !ss.fail() ); - char c; - ss.get(c); - CPPUNIT_ASSERT( !ss.fail() ); - CPPUNIT_ASSERT( c == '\n' ); // 27.6.1.3 paragraph 12 - CPPUNIT_ASSERT( os.str() == "1234567" ); -} - -void FstreamTest::streambuf_output() -{ - { - ofstream ofstr("test_file.txt", ios_base::binary); - if (!ofstr) - //No test if we cannot create the file - return; - ofstr << "01234567890123456789"; - CPPUNIT_ASSERT( ofstr ); - } - - { - ifstream in("test_file.txt", ios_base::binary); - CPPUNIT_ASSERT( in ); - - full_streambuf full_buf(10); - ostream out(&full_buf); - CPPUNIT_ASSERT( out ); - - out << in.rdbuf(); - CPPUNIT_ASSERT( out ); - CPPUNIT_ASSERT( in ); - CPPUNIT_ASSERT( full_buf.str() == "0123456789" ); - - out << in.rdbuf(); - CPPUNIT_ASSERT( out.fail() ); - CPPUNIT_ASSERT( in ); - - ostringstream ostr; - ostr << in.rdbuf(); - CPPUNIT_ASSERT( ostr ); - CPPUNIT_ASSERT( in ); - CPPUNIT_ASSERT( ostr.str() == "0123456789" ); - } - -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - { - //If the output stream buffer throws: - ifstream in("test_file.txt", ios_base::binary); - CPPUNIT_ASSERT( in ); - - full_streambuf full_buf(10, true); - ostream out(&full_buf); - CPPUNIT_ASSERT( out ); - - out << in.rdbuf(); - CPPUNIT_ASSERT( out.bad() ); - CPPUNIT_ASSERT( in ); - //out is bad we have no guaranty on what has been extracted: - //CPPUNIT_ASSERT( full_buf.str() == "0123456789" ); - - out.clear(); - out << in.rdbuf(); - CPPUNIT_ASSERT( out.fail() && out.bad() ); - CPPUNIT_ASSERT( in ); - - ostringstream ostr; - ostr << in.rdbuf(); - CPPUNIT_ASSERT( ostr ); - CPPUNIT_ASSERT( in ); - CPPUNIT_ASSERT( ostr.str() == "0123456789" ); - } -# endif -} - -void FstreamTest::win32_file_format() -{ - const char* file_name = "win32_file_format.tmp"; - const size_t nb_lines = 2049; - { - ofstream out(file_name); - CPPUNIT_ASSERT( out.good() ); - out << 'a'; - for (size_t i = 0; i < nb_lines - 1; ++i) { - out << '\n'; - } - out << '\r'; - CPPUNIT_ASSERT( out.good() ); - } - { - ifstream in(file_name); - CPPUNIT_ASSERT( in.good() ); - string line, last_line; - size_t nb_read_lines = 0; - while (getline(in, line)) { - ++nb_read_lines; - last_line = line; - } - CPPUNIT_ASSERT( in.eof() ); - CPPUNIT_ASSERT( nb_read_lines == nb_lines ); - CPPUNIT_ASSERT( !last_line.empty() && (last_line[0] == '\r') ); - } -} - -#if defined (DO_CUSTOM_FACET_TEST) -struct my_state { - char dummy; -}; - -struct my_traits : public char_traits<char> { - typedef my_state state_type; - typedef fpos<state_type> pos_type; -}; - -#if !defined (STLPORT) -//STLport grant a default implementation, other Standard libs implementation -//do not necessarily do the same: -namespace std { - template <> - class codecvt<char, char, my_state> - : public locale::facet, public codecvt_base { - public: - typedef char intern_type; - typedef char extern_type; - typedef my_state state_type; - - explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} - result out(state_type&, - const intern_type* __from, - const intern_type*, - const intern_type*& __from_next, - extern_type* __to, - extern_type*, - extern_type*& __to_next) const - { __from_next = __from; __to_next = __to; return noconv; } - - result in (state_type&, - const extern_type* __from, - const extern_type*, - const extern_type*& __from_next, - intern_type* __to, - intern_type*, - intern_type*& __to_next) const - { __from_next = __from; __to_next = __to; return noconv; } - - result unshift(state_type&, - extern_type* __to, - extern_type*, - extern_type*& __to_next) const - { __to_next = __to; return noconv; } - - int encoding() const throw() - { return 1; } - - bool always_noconv() const throw() - { return true; } - - int length(const state_type&, - const extern_type* __from, - const extern_type* __end, - size_t __max) const - { return (int)min(static_cast<size_t>(__end - __from), __max); } - - int max_length() const throw() - { return 1; } - - static locale::id id; - }; - - locale::id codecvt<char, char, my_state>::id; -} -# else -# if defined (__BORLANDC__) && (__BORLANDC__ < 0x590) -template <> -locale::id codecvt<char, char, my_state>::id; -# endif -# endif -#endif - -void FstreamTest::custom_facet() -{ -#if defined (DO_CUSTOM_FACET_TEST) - const char* fileName = "test_file.txt"; - //File preparation: - { - ofstream ofstr(fileName, ios_base::binary); - ofstr << "0123456789"; - CPPUNIT_ASSERT( ofstr ); - } - - { - typedef basic_ifstream<char, my_traits> my_ifstream; - typedef basic_string<char, my_traits> my_string; - - my_ifstream ifstr(fileName); - CPPUNIT_ASSERT( ifstr ); - -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - ifstr.imbue(locale::classic()); - CPPUNIT_ASSERT( ifstr.fail() && !ifstr.bad() ); - ifstr.clear(); -# endif - typedef codecvt<char, char, my_state> my_codecvt; - locale my_loc(locale::classic(), new my_codecvt()); - // Check that my_codecvt has not replace default codecvt: - CPPUNIT_ASSERT( (has_facet<my_codecvt>(my_loc)) ); - CPPUNIT_ASSERT( (has_facet<codecvt<char, char, mbstate_t> >(my_loc)) ); -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) - CPPUNIT_ASSERT( (has_facet<codecvt<wchar_t, char, mbstate_t> >(my_loc)) ); -# endif - ifstr.imbue(my_loc); - CPPUNIT_ASSERT( ifstr.good() ); - /* - my_string res; - ifstr >> res; - CPPUNIT_ASSERT( !ifstr.fail() ); - CPPUNIT_ASSERT( !ifstr.bad() ); - CPPUNIT_ASSERT( ifstr.eof() ); - CPPUNIT_ASSERT( res == "0123456789" ); - */ - } -#endif -} - -# if defined (CHECK_BIG_FILE) -void FstreamTest::big_file() -{ - vector<pair<streamsize, streamoff> > file_pos; - - //Big file creation: - { - ofstream out("big_file.txt"); - CPPUNIT_ASSERT( out ); - - //We are going to generate a file with the following schema for the content: - //0(1019 times)0000 //1023 characters + 1 charater for \n (for some platforms it will be a 1 ko line) - //0(1019 times)0001 - //... - //0(1019 times)1234 - //... - - //Generation of the number of loop: - streamoff nb = 1; - for (int i = 0; i < 20; ++i) { - //This assertion check that the streamoff can at least represent the necessary integers values - //for this test: - CPPUNIT_ASSERT( (nb << 1) > nb ); - nb <<= 1; - } - CPPUNIT_ASSERT( nb * CHECK_BIG_FILE >= nb ); - nb *= CHECK_BIG_FILE; - - //Preparation of the ouput stream state: - out << setiosflags(ios_base::right) << setfill('*'); - for (streamoff index = 0; index < nb; ++index) { - if (index % 1024 == 0) { - file_pos.push_back(make_pair(out.tellp(), index)); - CPPUNIT_ASSERT( file_pos.back().first != streamsize(-1) ); - if (file_pos.size() > 1) { - CPPUNIT_ASSERT( file_pos[file_pos.size() - 1].first > file_pos[file_pos.size() - 2].first ); - } - } - out << setw(1023) << index << '\n'; - } - } - - { - ifstream in("big_file.txt"); - CPPUNIT_ASSERT( in ); - - string line; - vector<pair<streamsize, streamsize> >::const_iterator pit(file_pos.begin()), - pitEnd(file_pos.end()); - for (; pit != pitEnd; ++pit) { - in.seekg((*pit).first); - CPPUNIT_ASSERT( in ); - in >> line; - size_t lastStarPos = line.rfind('*'); - CPPUNIT_ASSERT( atoi(line.substr(lastStarPos + 1).c_str()) == (*pit).second ); - } - } - - /* - The following test has been used to check that STLport do not generate - an infinite loop when the file size is larger than the streamsize and - streamoff representation (32 bits or 64 bits). - { - ifstream in("big_file.txt"); - CPPUNIT_ASSERT( in ); - char tmp[4096]; - streamsize nb_reads = 0; - while ((!in.eof()) && in.good()){ - in.read(tmp, 4096); - nb_reads += in.gcount(); - } - } - */ -} -# endif - -void FstreamTest::null_stream() -{ -# if (defined (STLPORT) && defined (_STLP_USE_WIN32_IO)) || \ - (!defined (STLPORT) && (defined (WIN32) || defined (_WIN32))) - const char* nullStreamName = "NUL"; -# else - const char* nullStreamName = "/dev/null"; -# endif - { - ofstream nullStream(nullStreamName); - CPPUNIT_CHECK( nullStream ); - } - - { - ofstream nullStream(nullStreamName, ios_base::ate); - CPPUNIT_CHECK( nullStream ); - } - - { - ofstream nullStream(nullStreamName, ios_base::trunc); - CPPUNIT_CHECK( nullStream ); - } - - { - ofstream nullStream(nullStreamName, ios_base::app); - CPPUNIT_CHECK( nullStream ); - } - - { - ifstream nullStream(nullStreamName); - CPPUNIT_CHECK( nullStream ); - } - - { - ifstream nullStream(nullStreamName, ios_base::ate); - CPPUNIT_CHECK( nullStream ); - } - - { - fstream nullStream(nullStreamName); - CPPUNIT_CHECK( nullStream ); - } - - { - fstream nullStream(nullStreamName, ios_base::in | ios_base::out | ios_base::ate); - CPPUNIT_CHECK( nullStream ); - } - - { - fstream nullStream(nullStreamName, ios_base::in | ios_base::out | ios_base::trunc); - CPPUNIT_CHECK( nullStream ); - } -} - -void FstreamTest::null_buf() -{ - /* ********************************************************************************** - - testcase for bug #1830513: - in _istream.c - - template < class _CharT, class _Traits, class _Is_Delim> - streamsize _STLP_CALL __read_unbuffered(basic_istream<_CharT, _Traits>* __that, - basic_streambuf<_CharT, _Traits>* __buf, - streamsize _Num, _CharT* __s, - _Is_Delim __is_delim, - bool __extract_delim, bool __append_null, - bool __is_getline) - - can't accept _Num == 0; this is legal case, and may happen from - - template <class _CharT, class _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>::getline(_CharT* __s, streamsize __n, _CharT __delim) - - *********************************************************************************** */ - - fstream f( "test.txt", ios_base::in | ios_base::out | ios_base::trunc ); - // string line; - - for ( int i = 0; i < 0x200; ++i ) { - f.put( ' ' ); - } - - // const streambuf *b = f.rdbuf(); - - // string s; - char buf[1024]; - buf[0] = 'a'; - buf[1] = 'b'; - buf[2] = 'c'; - - // getline( f, s ); - // cerr << f.good() << endl; - f.seekg( 0, ios_base::beg ); - // f.seekg( 0, ios_base::end ); - // buf[0] = f.get(); - - // cerr << (void *)(b->_M_gptr()) << " " << (void *)(b->_M_egptr()) << endl; - // cerr << f.good() << endl; - // getline( f, s ); - f.getline( buf, 1 ); // <-- key line - CPPUNIT_CHECK( buf[0] == 0 ); - CPPUNIT_CHECK( f.fail() ); // due to delimiter not found while buffer was exhausted -} - -# if !defined (STLPORT) || !defined (_STLP_WIN32) -void FstreamTest::offset() -{ -# if (defined(_LARGEFILE_SOURCE) || defined(_LARGEFILE64_SOURCE)) && !defined(_STLP_USE_DEFAULT_FILE_OFFSET) - CPPUNIT_CHECK( sizeof(streamoff) == 8 ); -# else - CPPUNIT_CHECK( sizeof(streamoff) == sizeof(off_t) ); -# endif -} -# endif - -#endif diff --git a/test/unit/full_streambuf.h b/test/unit/full_streambuf.h deleted file mode 100644 index 34766ac..0000000 --- a/test/unit/full_streambuf.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _FULL_STREAM_H -#define _FULL_STREAM_H - -#include <streambuf> - -/* - * This full_streambuf purpose is to act like a full disk to check the right behavior - * of the STLport code in such a case. - */ - -class full_streambuf : public std::streambuf { -public: - typedef std::streambuf _Base; - - typedef _Base::int_type int_type; - typedef _Base::traits_type traits_type; - - full_streambuf(size_t nb_output, bool do_throw = false) - : _nb_output(nb_output), _do_throw(do_throw) - {} - - std::string const& str() const - { return _buf; } - -protected: - int_type overflow(int_type c) { - if (_nb_output == 0) { -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - if (_do_throw) { - throw "streambuf full"; - } -#endif - return traits_type::eof(); - } - --_nb_output; - _buf += traits_type::to_char_type(c); - return c; - } - -private: - size_t _nb_output; - bool _do_throw; - std::string _buf; -}; - -#endif //_FULL_STREAM_H diff --git a/test/unit/func_test.cpp b/test/unit/func_test.cpp deleted file mode 100644 index 91ad1ef..0000000 --- a/test/unit/func_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class FuncTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(FuncTest); - CPPUNIT_TEST(func1); - CPPUNIT_TEST(func2); - CPPUNIT_TEST(func3); - CPPUNIT_TEST_SUITE_END(); - -protected: - void func1(); - void func2(); - void func3(); - static bool bigger(int i_); - static bool bigger_than(int x_, int y_); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(FuncTest); - -// -// tests implementation -// -bool FuncTest::bigger(int i_) -{ - return i_ > 3; -} -bool FuncTest::bigger_than(int x_, int y_) -{ - return x_ > y_; -} -void FuncTest::func1() -{ - vector<int>v; - v.push_back(4); - v.push_back(1); - v.push_back(5); - int n = count_if(v.begin(), v.end(), bigger); - CPPUNIT_ASSERT( n == 2 ) -} - -void FuncTest::func2() -{ - vector<int> v; - v.push_back(4); - v.push_back(1); - v.push_back(5); - sort(v.begin(), v.end(), bigger_than); - - CPPUNIT_ASSERT( v[0] == 5 ); - CPPUNIT_ASSERT( v[1] == 4 ); - CPPUNIT_ASSERT( v[2] == 1 ); -} -void FuncTest::func3() -{ - vector<int> v; - v.push_back(4); - v.push_back(1); - v.push_back(5); - sort(v.begin(), v.end(), greater<int>()); - - CPPUNIT_ASSERT( v[0] == 5 ); - CPPUNIT_ASSERT( v[1] == 4 ); - CPPUNIT_ASSERT( v[2] == 1 ); -} diff --git a/test/unit/functional_header_test.cpp b/test/unit/functional_header_test.cpp deleted file mode 100644 index 47bce72..0000000 --- a/test/unit/functional_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <functional> diff --git a/test/unit/generator_test.cpp b/test/unit/generator_test.cpp deleted file mode 100644 index 70ac945..0000000 --- a/test/unit/generator_test.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include <vector> -#include <algorithm> -#include "fadapter.h" -#include "fib.h" - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class GeneratorTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(GeneratorTest); - CPPUNIT_TEST(gener1); - CPPUNIT_TEST(gener2); - CPPUNIT_TEST(genern1); - CPPUNIT_TEST(genern2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void gener1(); - void gener2(); - void genern1(); - void genern2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(GeneratorTest); - -// -// tests implementation -// - -static int cxxrand() { return rand();} - -void GeneratorTest::gener1() -{ - int numbers[10]; -#if defined(__MVS__) - generate(numbers, numbers + 10, ptr_gen(cxxrand)); -#else - generate(numbers, numbers + 10, cxxrand); -#endif - // any suggestions? -} -void GeneratorTest::gener2() -{ - vector <int> v1(10); - Fibonacci generator; - generate(v1.begin(), v1.end(), generator); - - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==2); - CPPUNIT_ASSERT(v1[3]==3); - CPPUNIT_ASSERT(v1[4]==5); - CPPUNIT_ASSERT(v1[5]==8); - CPPUNIT_ASSERT(v1[6]==13); - CPPUNIT_ASSERT(v1[7]==21); - CPPUNIT_ASSERT(v1[8]==34); - CPPUNIT_ASSERT(v1[9]==55); -} -void GeneratorTest::genern1() -{ -#if !defined (_STLP_MEMBER_POINTER_PARAM_BUG) - //*TY 07/18/98 - added conditional - // since ptr_gen() is not defined under this condition - // (see xfunction.h) - vector <int> v1(10); - generate_n(v1.begin(), v1.size(), ptr_gen(cxxrand)); -#endif //_STLP_MEMBER_POINTER_PARAM_BUG //*TY 07/18/98 - added -} -void GeneratorTest::genern2() -{ - vector <int> v1(10); - Fibonacci generator; - generate_n(v1.begin(), v1.size(), generator); - - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==2); - CPPUNIT_ASSERT(v1[3]==3); - CPPUNIT_ASSERT(v1[4]==5); - CPPUNIT_ASSERT(v1[5]==8); - CPPUNIT_ASSERT(v1[6]==13); - CPPUNIT_ASSERT(v1[7]==21); - CPPUNIT_ASSERT(v1[8]==34); - CPPUNIT_ASSERT(v1[9]==55); -} diff --git a/test/unit/greater_test.cpp b/test/unit/greater_test.cpp deleted file mode 100644 index a3b8585..0000000 --- a/test/unit/greater_test.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class GreaterTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(GreaterTest); - CPPUNIT_TEST(greatert); - CPPUNIT_TEST(greatereq); - CPPUNIT_TEST_SUITE_END(); - -protected: - void greatert(); - void greatereq(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(GreaterTest); - -// -// tests implementation -// -void GreaterTest::greatert() -{ - int array[4] = { 3, 1, 4, 2 }; - sort(array, array + 4, greater<int>() ); - - CPPUNIT_ASSERT(array[0]==4); - CPPUNIT_ASSERT(array[1]==3); - CPPUNIT_ASSERT(array[2]==2); - CPPUNIT_ASSERT(array[3]==1); -} -void GreaterTest::greatereq() -{ - int array [4] = { 3, 1, 4, 2 }; - sort(array, array + 4, greater_equal<int>()); - CPPUNIT_ASSERT(array[0]==4); - CPPUNIT_ASSERT(array[1]==3); - CPPUNIT_ASSERT(array[2]==2); - CPPUNIT_ASSERT(array[3]==1); -} diff --git a/test/unit/hash_test.cpp b/test/unit/hash_test.cpp deleted file mode 100644 index 4ea913e..0000000 --- a/test/unit/hash_test.cpp +++ /dev/null @@ -1,434 +0,0 @@ -//Has to be first for StackAllocator swap overload to be taken -//into account (at least using GCC 4.0.1) -#include "stack_allocator.h" - -#include <vector> -#include <algorithm> -#include <map> -#include <set> - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <hash_map> -# include <hash_set> -# include <rope> -#endif - -#include <string> - -#include "cppunit/cppunit_proxy.h" - -#if defined (__MVS__) -const char star = 92; -#else -const char star = 42; -#endif - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class HashTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(HashTest); -#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(hmap1); - CPPUNIT_TEST(hmmap1); - CPPUNIT_TEST(hmmap2); - CPPUNIT_TEST(hmset1); - CPPUNIT_TEST(hset2); - CPPUNIT_TEST(insert_erase); - CPPUNIT_TEST(allocator_with_state); - //CPPUNIT_TEST(equality); - CPPUNIT_TEST_SUITE_END(); - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - typedef hash_multiset<char, hash<char>, equal_to<char> > hmset; -#endif - -protected: - void hmap1(); - void hmmap1(); - void hmmap2(); - void hmset1(); - void hset2(); - void insert_erase(); - //void equality(); - void allocator_with_state(); - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - typedef hash_multimap<int, int> hashType; - typedef multimap<int, int> mapType; - - void check_keys( hashType& h, mapType& m ); -#endif -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(HashTest); - -// -// tests implementation -// -void HashTest::hmap1() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - typedef hash_map<char, crope, hash<char>, equal_to<char> > maptype; - maptype m; - // Store mappings between roman numerals and decimals. - m['l'] = "50"; - m['x'] = "20"; // Deliberate mistake. - m['v'] = "5"; - m['i'] = "1"; - CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"20") ); - m['x'] = "10"; // Correct mistake. - CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"10") ); - - CPPUNIT_ASSERT( !strcmp(m['z'].c_str(),"") ); - - CPPUNIT_ASSERT( m.count('z')==1 ); - pair<maptype::iterator, bool> p = m.insert(pair<const char, crope>('c', crope("100"))); - - CPPUNIT_ASSERT(p.second); - - p = m.insert(pair<const char, crope>('c', crope("100"))); - CPPUNIT_ASSERT(!p.second); - - //Some iterators compare check, really compile time checks - maptype::iterator ite(m.begin()); - maptype::const_iterator cite(m.begin()); - cite = m.begin(); - maptype const& cm = m; - cite = cm.begin(); - CPPUNIT_ASSERT( ite == cite ); - CPPUNIT_ASSERT( !(ite != cite) ); - CPPUNIT_ASSERT( cite == ite ); - CPPUNIT_ASSERT( !(cite != ite) ); -#endif -} - -void HashTest::hmmap1() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - typedef hash_multimap<char, int, hash<char>,equal_to<char> > mmap; - mmap m; - CPPUNIT_ASSERT(m.count('X')==0); - m.insert(pair<const char,int>('X', 10)); // Standard way. - CPPUNIT_ASSERT(m.count('X')==1); -// m.insert('X', 20); // Non-standard, but very convenient! - m.insert(pair<const char,int>('X', 20)); // jbuck: standard way - CPPUNIT_ASSERT(m.count('X')==2); -// m.insert('Y', 32); - m.insert(pair<const char,int>('Y', 32)); // jbuck: standard way - mmap::iterator i = m.find('X'); // Find first match. - - CPPUNIT_ASSERT((*i).first=='X'); - CPPUNIT_ASSERT((*i).second==10); - i++; - CPPUNIT_ASSERT((*i).first=='X'); - CPPUNIT_ASSERT((*i).second==20); - i++; - CPPUNIT_ASSERT((*i).first=='Y'); - CPPUNIT_ASSERT((*i).second==32); - i++; - CPPUNIT_ASSERT(i==m.end()); - - size_t count = m.erase('X'); - CPPUNIT_ASSERT(count==2); - - //Some iterators compare check, really compile time checks - mmap::iterator ite(m.begin()); - mmap::const_iterator cite(m.begin()); - CPPUNIT_ASSERT( ite == cite ); - CPPUNIT_ASSERT( !(ite != cite) ); - CPPUNIT_ASSERT( cite == ite ); - CPPUNIT_ASSERT( !(cite != ite) ); - - typedef hash_multimap<size_t, size_t> HMapType; - HMapType hmap; - - //We fill the map to implicitely start a rehash. - for (size_t counter = 0; counter < 3077; ++counter) - hmap.insert(HMapType::value_type(1, counter)); - - hmap.insert(HMapType::value_type(12325, 1)); - hmap.insert(HMapType::value_type(12325, 2)); - - CPPUNIT_ASSERT( hmap.count(12325) == 2 ); - - //At this point 23 goes to the same bucket as 12325, it used to reveal a bug. - hmap.insert(HMapType::value_type(23, 0)); - - CPPUNIT_ASSERT( hmap.count(12325) == 2 ); -#endif -} - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -// Short demonstrator that helps reproducing a bug in the hash-table implementation -// of STLPort 5.0.1/5.0.2. -// -// Problem: Fill a hash_multimap with entries of which many have the same key -// Internally, entries with the same key are kept as one block within the same bucket. -// Thus, when calling equal_range(key) the begin/end of that block is returned. -// However, this code shows that for key =3, that block is destroyed after inserting the 194th element. -// According to _hashtable.c we will have a rehash from size 193 to size 389 in that situation. -// After that rehash, equal_range only returns 2 elements with key = 3 whereas there are 65 in it. -// Reproduction: -// In the main()-method we fill a hash_multimap as well as a multi_map with the same <key, data> pairs -// After each insertion we call check_keys(...) to assure validity of these two containers. -// This works fine up to the 193th insertion. Insertion 194 generates the bug. -// -// check_keys() works as follows: -// (a) we check whether both containers contain the same number of elements. -// (b) Assuming that the multi_map works correctly, we iterate over all its elements and check -// whether we can find that key also in the hash_multimap. We collect all data for that specific -// key in in a set ("collection"). Notice that data is unique by construction in main(), thus the -// number of elements in the set must equal the number of entries in the hash_multimap and in the multimap -// (c) We check if we have seen as many data elements in collection as we have seen in the multimap. -// if so, we print "OK", otherwise we print a detailed key/data overview and assert. -// Caution: -// There are several configurations of the program that will NOT fail. (see comment in code below) -// E.g. it seems that whenever the keys are more or less sorted, the problem does not occur. -// Also, using numbers from 200 downto 1 or from 300 downto 1 cannot generate the problem, -// whereas using 400 downto 1 will fail. -// Finally, if we use key 1 (rather than key 3) we cannot generate a problem. - -void HashTest::check_keys( HashTest::hashType& h, HashTest::mapType& m ) -{ - set<int> collection; - - // (a) check sizes - CPPUNIT_CHECK( h.size() == m.size() ); - - // (b) iterate over multi_map - for ( mapType::iterator i = m.begin(); i != m.end(); ++i ) { - // look up that key in hash-table and keep all data in the set - pair<hashType::iterator,hashType::iterator> range = h.equal_range( i->first ); - for ( hashType::iterator j = range.first; j != range.second; ++j ) { - collection.insert( j->second ); - } - } - // (c) we should have seen as many elements as there are in the hash-table -#if 0 - if (collection.size() == h.size()) cout << " OK" << endl; - else { - // if not, please report - cout << " FAILED: " << endl; - int lastKey = -1; - // iterate over all elements in multi_map - for (mapType::iterator mIter = m.begin(); mIter != m.end(); mIter++) { - // new key? print a new status line - if (mIter->first != lastKey) { - cout << endl << "Key : " << mIter->first << endl; - lastKey = mIter->first; - - // print all hashed values for that key - cout << " data in hash: "; - pair<hashType::iterator,hashType::iterator> range = h.equal_range(mIter->first); - - for (hashType::iterator h = range.first; h != range.second; h++) { - assert (h->first == lastKey); - cerr << h->second << ", "; // print all data for that key in Hash-Table - } - cout << endl << " data in map: "; - } - // and print all member in multi-map until the next key occurs - cout << mIter->second << ", " ; // print all data for that key in Map - } - } -#endif - CPPUNIT_CHECK( collection.size() == h.size() ); -} - -#endif - -void HashTest::hmmap2() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - hashType h; - mapType m; - - // CAUTION the following configurations WORKS in our setting - // for (int id = 1; id != 400; id ++) and int key = (id %3 == 0 ? 3 : id) - // for (int id = 200; id != 1; id --) and int key = (id %3 == 0 ? 3 : id) - // for (int id = 300; id != 1; id --) and int key = (id %3 == 0 ? 3 : id) - // for (int id = 400; id != 1; id --) and int key = (id %3 == 0 ? 1 : id) - // for (int id = 4000; id != 1; id --) and int key = (id %3 == 0 ? 1 : id) - // - // whereas these will FAIL - // for (int id = 400; id != 1; id --) and int key = (id %3 == 0 ? 3 : id) - // for (int id = 4000; id != 1; id --) and int key = (id %3 == 0 ? 3 : id) - // - - for ( int id = 400; id != 1; id-- ) { - // generate many entries with key 3, fill up with unique keys. Data is unique (needed in check_keys()) - int key = (id % 3 == 0 ? 3 : id); - - // keep hash_multi_map and multimap in sync - h.insert(make_pair(key, id)); - m.insert(make_pair(key, id)); - - // check whether both contain the same elements - check_keys( h, m ); - } -#endif -} - -void HashTest::hmset1() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - hmset s; - CPPUNIT_ASSERT( s.count(star) == 0 ); - s.insert(star); - CPPUNIT_ASSERT( s.count(star) == 1 ); - s.insert(star); - CPPUNIT_ASSERT( s.count(star) == 2 ); - hmset::iterator i = s.find(char(40)); - CPPUNIT_ASSERT( i == s.end() ); - - i = s.find(star); - CPPUNIT_ASSERT( i != s.end() ) - CPPUNIT_ASSERT( *i == '*' ); - CPPUNIT_ASSERT( s.erase(star) == 2 ); -#endif -} -void HashTest::hset2() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - hash_set<int, hash<int>, equal_to<int> > s; - pair<hash_set<int, hash<int>, equal_to<int> >::iterator, bool> p = s.insert(42); - CPPUNIT_ASSERT( p.second ); - CPPUNIT_ASSERT( *(p.first) == 42 ); - - p = s.insert(42); - CPPUNIT_ASSERT( !p.second ); -#endif -} - -void HashTest::insert_erase() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - typedef hash_map<string, size_t, hash<string>, equal_to<string> > hmap; - typedef hmap::value_type val_type; - { - hmap values; -# if !defined (__BORLANDC__) || (__BORLANDC__ >= 0x564) - CPPUNIT_ASSERT( values.insert(val_type("foo", 0)).second ); - CPPUNIT_ASSERT( values.insert(val_type("bar", 0)).second ); - CPPUNIT_ASSERT( values.insert(val_type("abc", 0)).second ); -# else - CPPUNIT_ASSERT( values.insert(hmap::value_type("foo", 0)).second ); - CPPUNIT_ASSERT( values.insert(hmap::value_type("bar", 0)).second ); - CPPUNIT_ASSERT( values.insert(hmap::value_type("abc", 0)).second ); -# endif - - CPPUNIT_ASSERT( values.erase("foo") == 1 ); - CPPUNIT_ASSERT( values.erase("bar") == 1 ); - CPPUNIT_ASSERT( values.erase("abc") == 1 ); - } - - { - hmap values; -# if !defined (__BORLANDC__) || (__BORLANDC__ >= 0x564) - CPPUNIT_ASSERT( values.insert(val_type("foo", 0)).second ); - CPPUNIT_ASSERT( values.insert(val_type("bar", 0)).second ); - CPPUNIT_ASSERT( values.insert(val_type("abc", 0)).second ); -# else - CPPUNIT_ASSERT( values.insert(hmap::value_type("foo", 0)).second ); - CPPUNIT_ASSERT( values.insert(hmap::value_type("bar", 0)).second ); - CPPUNIT_ASSERT( values.insert(hmap::value_type("abc", 0)).second ); -# endif - - CPPUNIT_ASSERT( values.erase("abc") == 1 ); - CPPUNIT_ASSERT( values.erase("bar") == 1 ); - CPPUNIT_ASSERT( values.erase("foo") == 1 ); - } -#endif -} - -/* - * Here is the test showing why equality operator on hash containers - * has no meaning: - -struct equality_hash_func { - size_t operator () (size_t val) const { - return val % 10; - } -}; - -void HashTest::equality() -{ - hash_set<size_t, equality_hash_func, equal_to<size_t> > s1, s2; - - s1.insert(10); - s1.insert(20); - - s2.insert(20); - s2.insert(10); - - //s1 and s2 contains both 10 and 20: - CPPUNIT_ASSERT( s1 == s2 ); -} -*/ - -void HashTest::allocator_with_state() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - char buf1[2048]; - StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1)); - - char buf2[2048]; - StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2)); - - { - typedef hash_set<int, hash<int>, equal_to<int>, StackAllocator<int> > HashSetInt; - HashSetInt hint1(10, hash<int>(), equal_to<int>(), stack1); - - int i; - for (i = 0; i < 5; ++i) - hint1.insert(i); - HashSetInt hint1Cpy(hint1); - - HashSetInt hint2(10, hash<int>(), equal_to<int>(), stack2); - for (; i < 10; ++i) - hint2.insert(i); - HashSetInt hint2Cpy(hint2); - - hint1.swap(hint2); - - CPPUNIT_ASSERT( hint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( hint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( hint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( hint2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); -#endif -} - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && \ - (!defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)) -# if !defined (__DMC__) - -/* Simple compilation test: Check that nested types like iterator - * can be access even if type used to instanciate container is not - * yet completely defined. - */ -class IncompleteClass -{ - hash_set<IncompleteClass> hsinstances; - typedef hash_set<IncompleteClass>::iterator hsit; - hash_multiset<IncompleteClass> hsminstances; - typedef hash_multiset<IncompleteClass>::iterator hsmit; - - hash_map<IncompleteClass, IncompleteClass> hminstances; - typedef hash_map<IncompleteClass, IncompleteClass>::iterator hmit; - hash_multimap<IncompleteClass, IncompleteClass> hmminstances; - typedef hash_multimap<IncompleteClass, IncompleteClass>::iterator hmmit; -}; -# endif -#endif diff --git a/test/unit/heap_test.cpp b/test/unit/heap_test.cpp deleted file mode 100644 index 87eb75d..0000000 --- a/test/unit/heap_test.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class HeapTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(HeapTest); - CPPUNIT_TEST(mkheap0); - CPPUNIT_TEST(mkheap1); - CPPUNIT_TEST(pheap1); - CPPUNIT_TEST(pheap2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void mkheap0(); - void mkheap1(); - void pheap1(); - void pheap2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(HeapTest); - -// -// tests implementation -// -void HeapTest::mkheap0() -{ - int numbers[6] = { 5, 10, 4, 13, 11, 19 }; - - make_heap(numbers, numbers + 6); - CPPUNIT_ASSERT(numbers[0]==19) - pop_heap(numbers, numbers + 6); - CPPUNIT_ASSERT(numbers[0]==13) - pop_heap(numbers, numbers + 5); - CPPUNIT_ASSERT(numbers[0]==11) - pop_heap(numbers, numbers + 4); - CPPUNIT_ASSERT(numbers[0]==10) - pop_heap(numbers, numbers + 3); - CPPUNIT_ASSERT(numbers[0]==5) - pop_heap(numbers, numbers + 2); - CPPUNIT_ASSERT(numbers[0]==4) - pop_heap(numbers, numbers + 1); -} -void HeapTest::mkheap1() -{ - int numbers[6] = { 5, 10, 4, 13, 11, 19 }; - - make_heap(numbers, numbers + 6, greater<int>()); - - CPPUNIT_ASSERT(numbers[0]==4) - pop_heap(numbers, numbers + 6, greater<int>()); - CPPUNIT_ASSERT(numbers[0]==5) - pop_heap(numbers, numbers + 5, greater<int>()); - CPPUNIT_ASSERT(numbers[0]==10) - pop_heap(numbers, numbers + 4, greater<int>()); - CPPUNIT_ASSERT(numbers[0]==11) - pop_heap(numbers, numbers + 3, greater<int>()); - CPPUNIT_ASSERT(numbers[0]==13) - pop_heap(numbers, numbers + 2, greater<int>()); - CPPUNIT_ASSERT(numbers[0]==19) -} -void HeapTest::pheap1() -{ - vector<int> v; - - v.push_back(1); - v.push_back(20); - v.push_back(4); - make_heap(v.begin(), v.end()); - - v.push_back(7); - push_heap(v.begin(), v.end()); - - sort_heap(v.begin(), v.end()); - - CPPUNIT_ASSERT(v[0]==1); - CPPUNIT_ASSERT(v[1]==4); - CPPUNIT_ASSERT(v[2]==7); - CPPUNIT_ASSERT(v[3]==20); -} -void HeapTest::pheap2() -{ - vector<int> v; - - v.push_back(1); - v.push_back(20); - v.push_back(4); - make_heap(v.begin(), v.end(), greater<int>()); - - v.push_back(7); - push_heap(v.begin(), v.end(), greater<int>()); - - sort_heap(v.begin(), v.end(), greater<int>()); - - CPPUNIT_ASSERT(v[0]==20); - CPPUNIT_ASSERT(v[1]==7); - CPPUNIT_ASSERT(v[2]==4); - CPPUNIT_ASSERT(v[3]==1); -} diff --git a/test/unit/includes_test.cpp b/test/unit/includes_test.cpp deleted file mode 100644 index d641797..0000000 --- a/test/unit/includes_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include <cstring> -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class IncludesTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(IncludesTest); - CPPUNIT_TEST(incl0); - CPPUNIT_TEST(incl1); - CPPUNIT_TEST(incl2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void incl0(); - void incl1(); - void incl2(); - - static bool compare_strings(const char* s1_, const char* s2_) - { - return strcmp(s1_, s2_) < 0 ? 1 : 0; - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(IncludesTest); - -// -// tests implementation -// -void IncludesTest::incl0() -{ - int numbers1[5] = { 1, 2, 3, 4, 5 }; - //int numbers2[5] = { 1, 2, 4, 8, 16 }; - int numbers3[2] = { 4, 8 }; - bool r1=includes(numbers1, numbers1 + 5, numbers3, numbers3 + 2); - CPPUNIT_ASSERT(!r1); -} -void IncludesTest::incl1() -{ - vector<int> v1(10); - vector<int> v2(3); - int i; - for (i = 0; (size_t)i < v1.size(); ++i) { - v1[i] = i; - } - - bool r1=includes(v1.begin(), v1.end(), v2.begin(), v2.end()); - CPPUNIT_ASSERT(!r1); - - for (i = 0; (size_t)i < v2.size(); ++i) - v2[i] = i + 3; - - bool r2=includes(v1.begin(), v1.end(), v2.begin(), v2.end()); - CPPUNIT_ASSERT(r2); -} -void IncludesTest::incl2() -{ - char const* names[] = { "Todd", "Mike", "Graham", "Jack", "Brett"}; - - const unsigned nameSize = sizeof(names)/sizeof(names[0]); - vector <char const*> v1(nameSize); - for (int i = 0; (size_t)i < v1.size(); ++i) { - v1[i] = names[i]; - } - vector <char const*> v2(2); - - v2[0] = "foo"; - v2[1] = "bar"; - sort(v1.begin(), v1.end(), compare_strings); - sort(v2.begin(), v2.end(), compare_strings); - - bool r1 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings); - CPPUNIT_ASSERT(!r1); - - v2[0] = "Brett"; - v2[1] = "Todd"; - bool r2 = includes(v1.begin(), v1.end(), v2.begin(), v2.end(), compare_strings); - CPPUNIT_ASSERT(r2); -} diff --git a/test/unit/innerprod_test.cpp b/test/unit/innerprod_test.cpp deleted file mode 100644 index 3d77f5d..0000000 --- a/test/unit/innerprod_test.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include <vector> -#include <algorithm> -#include <numeric> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class InnerprodTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(InnerprodTest); - CPPUNIT_TEST(inprod0); - CPPUNIT_TEST(inprod1); - CPPUNIT_TEST(inprod2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void inprod0(); - void inprod1(); - void inprod2(); - - static size_t add(size_t a_, size_t b_) { - return a_ + b_; - } - - static size_t mult(size_t a_, size_t b_) { - return a_ * b_; - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(InnerprodTest); - -// -// tests implementation -// -void InnerprodTest::inprod0() -{ - int vector1[5] = { 1, 2, 3, 4, 5 }; - int vector2[5] = { 1, 2, 3, 4, 5 }; - - int result; - result = inner_product(vector1, vector1 + 5, vector2, 0); - CPPUNIT_ASSERT(result==55); -} -void InnerprodTest::inprod1() -{ - vector<size_t> v1(3); - vector<size_t> v2(v1.size()); - for (size_t i = 0; i < v1.size(); ++i) { - v1[i] = i + 1; - v2[i] = v1.size() - i; - } - size_t result = inner_product(v1.begin(), v1.end(), v2.begin(), (size_t)0); - CPPUNIT_ASSERT(result == 10); -} -void InnerprodTest::inprod2() -{ - vector<size_t> v1(3); - vector<size_t> v2(v1.size()); - for(size_t i = 0; i < v1.size(); ++i) { - v1[i] = i + 1; - v2[i] = v1.size() - i; - } - size_t result=inner_product(v1.begin(), v1.end(), v2.begin(), (size_t)1, mult, add); - - CPPUNIT_ASSERT(result == 64); -} diff --git a/test/unit/inplace_test.cpp b/test/unit/inplace_test.cpp deleted file mode 100644 index 2c9bd99..0000000 --- a/test/unit/inplace_test.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class InplaceTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(InplaceTest); - CPPUNIT_TEST(inplmrg1); - CPPUNIT_TEST(inplmrg2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void inplmrg1(); - void inplmrg2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(InplaceTest); - -// -// tests implementation -// -void InplaceTest::inplmrg1() -{ - int numbers[6] = { 1, 10, 42, 3, 16, 32 }; - inplace_merge(numbers, numbers + 3, numbers + 6); - - CPPUNIT_ASSERT(numbers[0]==1); - CPPUNIT_ASSERT(numbers[1]==3); - CPPUNIT_ASSERT(numbers[2]==10); - CPPUNIT_ASSERT(numbers[3]==16); - CPPUNIT_ASSERT(numbers[4]==32); - CPPUNIT_ASSERT(numbers[5]==42); -} -void InplaceTest::inplmrg2() -{ - vector<size_t> v1(10); - for(size_t i = 0; i < v1.size(); ++i) - v1[i] =(v1.size() - i - 1) % 5; - - inplace_merge(v1.begin(), v1.begin() + 5, v1.end(), greater<size_t>()); - - CPPUNIT_ASSERT(v1[0]==4); - CPPUNIT_ASSERT(v1[1]==4); - CPPUNIT_ASSERT(v1[2]==3); - CPPUNIT_ASSERT(v1[3]==3); - CPPUNIT_ASSERT(v1[4]==2); - CPPUNIT_ASSERT(v1[5]==2); - CPPUNIT_ASSERT(v1[6]==1); - CPPUNIT_ASSERT(v1[7]==1); - CPPUNIT_ASSERT(v1[8]==0); - CPPUNIT_ASSERT(v1[9]==0); -} diff --git a/test/unit/insert_test.cpp b/test/unit/insert_test.cpp deleted file mode 100644 index e0ec1a2..0000000 --- a/test/unit/insert_test.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include <deque> -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class InsertTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(InsertTest); - CPPUNIT_TEST(insert1); - CPPUNIT_TEST(insert2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void insert1(); - void insert2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(InsertTest); - -// -// tests implementation -// -void InsertTest::insert1() -{ - char const* array1 [] = { "laurie", "jennifer", "leisa" }; - char const* array2 [] = { "amanda", "saskia", "carrie" }; - - deque<char const*> names(array1, array1 + 3); - deque<char const*>::iterator i = names.begin() + 2; - - insert_iterator<deque <char const*> > itd(names, i); - itd = copy(array2, array2 + 3, insert_iterator<deque <char const*> >(names, i)); - - CPPUNIT_ASSERT( !strcmp(names[0], "laurie") ); - CPPUNIT_ASSERT( !strcmp(names[1], "jennifer") ); - CPPUNIT_ASSERT( !strcmp(names[2], "amanda") ); - CPPUNIT_ASSERT( !strcmp(names[3], "saskia") ); - CPPUNIT_ASSERT( !strcmp(names[4], "carrie") ); - CPPUNIT_ASSERT( !strcmp(names[5], "leisa") ); - - copy(array1, array1 + 3, itd); - CPPUNIT_ASSERT( !strcmp(names[5], "laurie") ); - CPPUNIT_ASSERT( !strcmp(names[6], "jennifer") ); - CPPUNIT_ASSERT( !strcmp(names[7], "leisa") ); - CPPUNIT_ASSERT( !strcmp(names[8], "leisa") ); -} -void InsertTest::insert2() -{ - char const* array1 [] = { "laurie", "jennifer", "leisa" }; - char const* array2 [] = { "amanda", "saskia", "carrie" }; - - deque<char const*> names(array1, array1 + 3); - deque<char const*>::iterator i = names.begin() + 2; - copy(array2, array2 + 3, inserter(names, i)); - - CPPUNIT_ASSERT( !strcmp(names[0], "laurie") ); - CPPUNIT_ASSERT( !strcmp(names[1], "jennifer") ); - CPPUNIT_ASSERT( !strcmp(names[2], "amanda") ); - CPPUNIT_ASSERT( !strcmp(names[3], "saskia") ); - CPPUNIT_ASSERT( !strcmp(names[4], "carrie") ); - CPPUNIT_ASSERT( !strcmp(names[5], "leisa") ); -} diff --git a/test/unit/ioiter_test.cpp b/test/unit/ioiter_test.cpp deleted file mode 100644 index 6f0aeb9..0000000 --- a/test/unit/ioiter_test.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include <string> -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -#include <sstream> -#include <vector> -#include <iterator> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -class IoiterTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(IoiterTest); - CPPUNIT_TEST(ioiter_test); - CPPUNIT_TEST(assign_test); - CPPUNIT_TEST(assign2_test); - CPPUNIT_TEST_SUITE_END(); - -protected: - void ioiter_test(); - void assign_test(); - void assign2_test(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(IoiterTest); - -void IoiterTest::ioiter_test() -{ - - char c; - const char *pc; - const char *strorg = "abcd"; - string tmp; - - string objStr(strorg); - - istringstream objIStrStrm1(objStr); - istringstream objIStrStrm2(objStr); - istringstream objIStrStrm3(objStr); - - pc = strorg; - string::size_type sz = strlen(strorg); - string::size_type i; - for ( i = 0; i < sz; ++i ) { - c = *pc++; - tmp += c; - } - CPPUNIT_ASSERT( tmp == "abcd" ); - - istreambuf_iterator<char, char_traits<char> > objIStrmbIt1( objIStrStrm1.rdbuf() ); - istreambuf_iterator<char, char_traits<char> > end; - - tmp.clear(); - - for ( i = 0; i < sz /* objIStrmbIt1 != end */; ++i ) { - c = *objIStrmbIt1++; - tmp += c; - } - CPPUNIT_ASSERT( tmp == "abcd" ); - - tmp.clear(); - - istreambuf_iterator<char, char_traits<char> > objIStrmbIt2( objIStrStrm2.rdbuf() ); - for ( i = 0; i < sz; ++i ) { - c = *objIStrmbIt2; - tmp += c; - objIStrmbIt2++; - } - CPPUNIT_ASSERT( tmp == "abcd" ); - - tmp.clear(); - - istreambuf_iterator<char, char_traits<char> > objIStrmbIt3( objIStrStrm3.rdbuf() ); - - while ( objIStrmbIt3 != end ) { - c = *objIStrmbIt3++; - tmp += c; - } - CPPUNIT_ASSERT( tmp == "abcd" ); -} - -void IoiterTest::assign_test() -{ - stringstream s( "1234567890" ); - vector<char> v; - - v.assign( istreambuf_iterator<char>(s), istreambuf_iterator<char>() ); - CPPUNIT_CHECK( v.size() == 10 ); - if ( v.size() == 10 ) { - CPPUNIT_CHECK( v[0] == '1' ); - CPPUNIT_CHECK( v[9] == '0' ); - } -} - -void IoiterTest::assign2_test() -{ - stringstream s( "1234567890" ); - vector<char> v; - - v.assign( istreambuf_iterator<char>(s.rdbuf()), istreambuf_iterator<char>() ); - CPPUNIT_CHECK( v.size() == 10 ); - if ( v.size() == 10 ) { - CPPUNIT_CHECK( v[0] == '1' ); - CPPUNIT_CHECK( v[9] == '0' ); - } -} - -#endif diff --git a/test/unit/iomanip_header_test.cpp b/test/unit/iomanip_header_test.cpp deleted file mode 100644 index fa0ab0f..0000000 --- a/test/unit/iomanip_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <iomanip> -#endif diff --git a/test/unit/ios_header_test.cpp b/test/unit/ios_header_test.cpp deleted file mode 100644 index c239643..0000000 --- a/test/unit/ios_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <ios> -#endif diff --git a/test/unit/iosfwd_header_test.cpp b/test/unit/iosfwd_header_test.cpp deleted file mode 100644 index 8c3adcc..0000000 --- a/test/unit/iosfwd_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#ifndef _STLP_NO_IOSTREAMS -# include <iosfwd> -#endif diff --git a/test/unit/iostream_header_test.cpp b/test/unit/iostream_header_test.cpp deleted file mode 100644 index 51e6df6..0000000 --- a/test/unit/iostream_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <iostream> -#endif diff --git a/test/unit/iostream_test.cpp b/test/unit/iostream_test.cpp deleted file mode 100644 index a4db5d8..0000000 --- a/test/unit/iostream_test.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include <string> - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <sstream> -//# include <locale> -# include <iostream> -//# include <stdexcept> - -# include "cppunit/cppunit_proxy.h" - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -// -// TestCase class -// -class IOStreamTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(IOStreamTest); - CPPUNIT_TEST(manipulators); - CPPUNIT_TEST(in_avail); -//#if defined (STLPORT) && defined (_STLP_NO_WCHAR_T) - //CPPUNIT_IGNORE; -//#endif - //CPPUNIT_TEST(wimbue); - CPPUNIT_TEST_SUITE_END(); - -private: - void manipulators(); - void in_avail(); - //void wimbue(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(IOStreamTest); - -// -// tests implementation -// -void IOStreamTest::manipulators() -{ - { - istringstream istr; - istr.str("bar"); - - istr >> ws; - CPPUNIT_ASSERT( istr.good() ); - - string foo; - istr >> foo; - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( foo == "bar" ); - - istr >> ws; - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( !istr.fail() ); - istr.clear(); - } - - { - istringstream istr; - istr.str(" bar "); - - istr >> ws; - CPPUNIT_ASSERT( istr.good() ); - - string foo; - istr >> foo; - CPPUNIT_ASSERT( !istr.eof() ); - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( foo == "bar" ); - - istr >> ws; - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( !istr.fail() ); - istr.clear(); - } -} - - -void IOStreamTest::in_avail() -{ - CPPUNIT_CHECK( cin.rdbuf()->in_avail() == 0 ); - CPPUNIT_CHECK( cout.rdbuf()->in_avail() == -1 ); - CPPUNIT_CHECK( clog.rdbuf()->in_avail() == -1 ); - CPPUNIT_CHECK( cerr.rdbuf()->in_avail() == -1 ); - -#if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) - CPPUNIT_CHECK( wcin.rdbuf()->in_avail() == 0 ); - CPPUNIT_CHECK( wcout.rdbuf()->in_avail() == 0 ); - CPPUNIT_CHECK( wclog.rdbuf()->in_avail() == 0 ); - CPPUNIT_CHECK( wcerr.rdbuf()->in_avail() == 0 ); -#endif -} - -//void IOStreamTest::wimbue() -//{ -//#if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) -// locale loc; -// try { -// locale tmp(".866"); -// loc = tmp; -// } -// catch (const runtime_error&) { -// return; -// } -// -// wcout.imbue(loc); -// wcout << L"Hello world" << endl; -// wcout.imbue(loc); -// wcout << L"Hello world" << endl; -//#endif -//} - -#endif diff --git a/test/unit/iota.h b/test/unit/iota.h deleted file mode 100644 index 1cffefb..0000000 --- a/test/unit/iota.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef IOTA_H -#define IOTA_H - -#include <numeric> - -//iota definition used in unit test -template <typename _It, typename _Tp> -void __iota(_It __first, _It __last, _Tp __val) { -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - iota(__first, __last, __val); -#else - while (__first != __last) { - *__first++ = __val++; - } -#endif -} - -#endif diff --git a/test/unit/iota_test.cpp b/test/unit/iota_test.cpp deleted file mode 100644 index 24339b2..0000000 --- a/test/unit/iota_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include <vector> -#include <numeric> - -#include "cppunit/cppunit_proxy.h" - -#if defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class IotaTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(IotaTest); -#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(iota1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void iota1(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(IotaTest); - -// -// tests implementation -// -void IotaTest::iota1() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - int numbers[10]; - iota(numbers, numbers + 10, 42); - CPPUNIT_ASSERT(numbers[0]==42); - CPPUNIT_ASSERT(numbers[1]==43); - CPPUNIT_ASSERT(numbers[2]==44); - CPPUNIT_ASSERT(numbers[3]==45); - CPPUNIT_ASSERT(numbers[4]==46); - CPPUNIT_ASSERT(numbers[5]==47); - CPPUNIT_ASSERT(numbers[6]==48); - CPPUNIT_ASSERT(numbers[7]==49); - CPPUNIT_ASSERT(numbers[8]==50); - CPPUNIT_ASSERT(numbers[9]==51); -#endif -} diff --git a/test/unit/iso646_header_test.c b/test/unit/iso646_header_test.c deleted file mode 100644 index 41d7432..0000000 --- a/test/unit/iso646_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <iso646.h> diff --git a/test/unit/istmit_test.cpp b/test/unit/istmit_test.cpp deleted file mode 100644 index c1e2d17..0000000 --- a/test/unit/istmit_test.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include <algorithm> -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <sstream> -# include <functional> -# include <iterator> -# include <vector> -# include <string> -#endif - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class IStreamIteratorTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(IStreamIteratorTest); -#if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(istmit1); -#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(copy_n_test); - CPPUNIT_TEST_SUITE_END(); - -protected: - void istmit1(); - void copy_n_test(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(IStreamIteratorTest); - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# if !defined (STLPORT) || !defined (_STLP_LIMITED_DEFAULT_TEMPLATES) -typedef istream_iterator<char> istream_char_ite; -typedef istream_iterator<int> istream_int_ite; -typedef istream_iterator<string> istream_string_ite; -# else -typedef istream_iterator<char, ptrdiff_t> istream_char_ite; -typedef istream_iterator<int, ptrdiff_t> istream_int_ite; -typedef istream_iterator<string, ptrdiff_t> istream_string_ite; -# endif -#endif - -// -// tests implementation -// -void IStreamIteratorTest::istmit1() -{ -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) - const char* buff = "MyString"; - istringstream istr(buff); - - char buffer[100]; - size_t i = 0; - istr.unsetf(ios::skipws); // Disable white-space skipping. - istream_char_ite s(istr), meos; - while (!(s == meos) && - //*TY 01/10/1999 - added end of stream check - // NOTE operator!= should not be used here ifndef _STLP_FUNCTION_TMPL_PARTIAL_ORDER - (*s != '\n') && - (i < sizeof(buffer) / sizeof(buffer[0]))) { //*TY 07/28/98 - added index check - buffer[i++] = *s++; - } - buffer[i] = '\0'; // Null terminate buffer. - - CPPUNIT_ASSERT(!strcmp(buffer, buff)); - - { - istringstream empty_istr; - CPPUNIT_ASSERT( istream_char_ite(empty_istr) == istream_char_ite() ); - } -#endif -} - -void IStreamIteratorTest::copy_n_test() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && !defined (_STLP_USE_NO_IOSTREAMS) - //This test check that no character is lost while reading the istream - //through a istream_iterator. - { - istringstream istr("aabbcd"); - string chars; - istream_char_ite ite = copy_n(copy_n(istream_char_ite(istr), - 2, back_inserter(chars)).first, - 2, back_inserter(chars)).first; - CPPUNIT_ASSERT( chars == "aabb" ); - copy_n(ite, 2, back_inserter(chars)); - CPPUNIT_ASSERT( chars == "aabbcd" ); - } - - { - istringstream istr("11 22 AA BB 33 44 CC DD"); - vector<int> ints; - vector<string> strings; - - copy_n(istream_int_ite(istr), 2, back_inserter(ints)); - CPPUNIT_ASSERT( ints.size() == 2 ); - CPPUNIT_ASSERT( ints[0] == 11 ); - CPPUNIT_ASSERT( ints[1] == 22 ); - ints.clear(); - istr.clear(); - copy_n(istream_string_ite(istr), 2, back_inserter(strings)); - CPPUNIT_ASSERT( strings.size() == 2 ); - CPPUNIT_ASSERT( strings[0] == "AA" ); - CPPUNIT_ASSERT( strings[1] == "BB" ); - strings.clear(); - istr.clear(); - /* The following code cannot work, '33' is extracted as a string - * in the previous copy_n call, this value is returned in the pair - * returned by copy_n but is lost as this istream_iterator is not used. - * copy_n and istream_iterator can only be combined safely if: - * - you always extract the same type of istream_iterator and you always reuse - * the istream_iterator returned by copy_n (see previous test with "aabbcd") - * - you extract different type of object and no object is convertible to an other - * as in this current test when you extract int and string (when you extract ints - * again it fails as int can be converted to strings. - * - copy_n(istream_int_ite(istr), 2, back_inserter(ints)); - CPPUNIT_ASSERT( ints.size() == 2 ); - CPPUNIT_ASSERT( ints[0] == 33 ); - CPPUNIT_ASSERT( ints[1] == 44 ); - istr.clear(); - copy_n(istream_string_ite(istr), 2, back_inserter(strings)); - CPPUNIT_ASSERT( strings.size() == 2 ); - CPPUNIT_ASSERT( strings[0] == "CC" ); - CPPUNIT_ASSERT( strings[1] == "DD" ); - */ - } - - { - istringstream is("1 2 3 4 5 6 7 8 9 10"); - vector<int> ints; - istream_iterator<int> itr(is); - itr = copy_n(itr, 0, back_inserter(ints)).first; - CPPUNIT_ASSERT( ints.empty() ); - itr = copy_n(itr, -1, back_inserter(ints)).first; - CPPUNIT_ASSERT( ints.empty() ); - itr = copy_n(itr, 2, back_inserter(ints)).first; - CPPUNIT_ASSERT( ints.size() == 2 ); - CPPUNIT_ASSERT( ints[0] == 1 ); - CPPUNIT_ASSERT( ints[1] == 2 ); - itr = copy_n(itr, 2, back_inserter(ints)).first; - CPPUNIT_ASSERT( ints.size() == 4 ); - CPPUNIT_ASSERT( ints[2] == 3 ); - CPPUNIT_ASSERT( ints[3] == 4 ); - itr = copy_n(itr, 2, back_inserter(ints)).first; - CPPUNIT_ASSERT( ints.size() == 6 ); - CPPUNIT_ASSERT( ints[4] == 5 ); - CPPUNIT_ASSERT( ints[5] == 6 ); - } -#endif -} diff --git a/test/unit/istream_header_test.cpp b/test/unit/istream_header_test.cpp deleted file mode 100644 index 7c83854..0000000 --- a/test/unit/istream_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <istream> -#endif diff --git a/test/unit/iter_test.cpp b/test/unit/iter_test.cpp deleted file mode 100644 index 52e4348..0000000 --- a/test/unit/iter_test.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include <vector> -#include <list> -#include <algorithm> -#include <numeric> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class IterTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(IterTest); - CPPUNIT_TEST(iter1); - CPPUNIT_TEST(iter3); - CPPUNIT_TEST(iter4); - CPPUNIT_TEST(iterswp0); - CPPUNIT_TEST(iterswp1); - CPPUNIT_TEST(iterswp2); - CPPUNIT_TEST(iterswp3); - CPPUNIT_TEST_SUITE_END(); - -protected: - void iter1(); - void iter3(); - void iter4(); - void iterswp0(); - void iterswp1(); - void iterswp2(); - void iterswp3(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(IterTest); - -// -// tests implementation -// -void IterTest::iter1() -{ - vector<const char*> v; // Vector of character strings. - v.push_back("zippy"); // First element. - v.push_back("motorboy"); // Second element. - typedef vector<const char*> vec; - unsigned counter = 0; - for (vec::iterator i = v.begin(); i != v.end(); ++i, ++counter) { - switch (counter) { - case 0: - CPPUNIT_ASSERT(!strcmp(*i, "zippy")); - break; - case 1: - CPPUNIT_ASSERT(!strcmp(*i, "motorboy")); - break; - default: - CPPUNIT_FAIL; - } - } -} -void IterTest::iter3() -{ - typedef vector<const char*> Vec; - Vec v; // Vector of character strings. - v.push_back("zippy"); // First element. - v.push_back("motorboy"); // Second element. - Vec::reverse_iterator it; - unsigned counter = 0; - for (it = v.rbegin(); it != v.rend(); ++it, ++counter) { - switch (counter) { - case 1: - CPPUNIT_ASSERT(!strcmp(*it, "zippy")); - break; - case 0: - CPPUNIT_ASSERT(!strcmp(*it, "motorboy")); - break; - default: - CPPUNIT_FAIL; - } - } -} -void IterTest::iter4() -{ - vector<int> v; // Empty vector of integers. - v.push_back(1); - v.push_back(2); - v.push_back(3); - // Position immediately after last item. - vector<int>::iterator i = v.end(); - // Move back one and then access. - CPPUNIT_ASSERT((*--i)==3); - i -= 2; // Jump back two items. - CPPUNIT_ASSERT((*i)==1); -} -void IterTest::iterswp0() -{ - int numbers[6] = { 0, 1, 2, 3, 4, 5 }; - - iter_swap(numbers, numbers + 3); - - CPPUNIT_ASSERT(numbers[0]==3); - CPPUNIT_ASSERT(numbers[1]==1); - CPPUNIT_ASSERT(numbers[2]==2); - CPPUNIT_ASSERT(numbers[3]==0); - CPPUNIT_ASSERT(numbers[4]==4); - CPPUNIT_ASSERT(numbers[5]==5); - -} -void IterTest::iterswp1() -{ - vector<int> v1(6); - __iota(v1.begin(), v1.end(), 0); - iter_swap( v1.begin(), v1.begin() + 3 ); - - CPPUNIT_ASSERT(v1[0]==3); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==2); - CPPUNIT_ASSERT(v1[3]==0); - CPPUNIT_ASSERT(v1[4]==4); - CPPUNIT_ASSERT(v1[5]==5); -} -void IterTest::iterswp2() -{ - vector<bool> boolVector; - - boolVector.push_back( true ); - boolVector.push_back( false ); - - vector<bool>::iterator i1 = boolVector.begin(); - vector<bool>::iterator i2 = boolVector.begin(); - ++i2; - - bool v0 = *i1; - bool v1 = *i2; - - iter_swap( i1, i2 ); - - CPPUNIT_ASSERT(( *i1 == v1 && *i2 == v0 )); -} - - -void IterTest::iterswp3() -{ - vector<int> vvref(10, 10); - vector<int> lvref(10, 20); - - vector<vector<int> > vvints(4, vvref); - list<vector<int> > lvints(4, lvref); - - iter_swap(vvints.begin(), lvints.begin()); - CPPUNIT_CHECK( vvints.front() == lvref ); - CPPUNIT_CHECK( lvints.front() == vvref ); - - //const vector<vector<int> > &cvvints = vvints; - //iter_swap(cvvints.begin(), lvints.begin()); - //iter_swap(lvints.begin(), cvvints.begin()); - -#if defined (STLPORT) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - int *pvvint = &vvints.front().front(); - int *plvint = &lvints.front().front(); - - iter_swap(vvints.begin(), lvints.begin()); - //Check that elements have been swaped: - CPPUNIT_CHECK( pvvint == &lvints.front().front() ); - CPPUNIT_CHECK( plvint == &vvints.front().front() ); -#endif -} diff --git a/test/unit/iterator_header_test.cpp b/test/unit/iterator_header_test.cpp deleted file mode 100644 index cb7ed29..0000000 --- a/test/unit/iterator_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <iterator> diff --git a/test/unit/less_test.cpp b/test/unit/less_test.cpp deleted file mode 100644 index a87eae8..0000000 --- a/test/unit/less_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class LessTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(LessTest); - CPPUNIT_TEST(lesst); - CPPUNIT_TEST(lesseqt); - CPPUNIT_TEST_SUITE_END(); - -protected: - void lesst(); - void lesseqt(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(LessTest); - -// -// tests implementation -// -void LessTest::lesst() -{ - int array [4] = { 3, 1, 4, 2 }; - sort(array, array + 4, less<int>()); - - CPPUNIT_ASSERT(array[0]==1); - CPPUNIT_ASSERT(array[1]==2); - CPPUNIT_ASSERT(array[2]==3); - CPPUNIT_ASSERT(array[3]==4); -} -void LessTest::lesseqt() -{ - int array [4] = { 3, 1, 4, 2 }; - sort(array, array + 4, less_equal<int>()); - - CPPUNIT_ASSERT(array[0]==1); - CPPUNIT_ASSERT(array[1]==2); - CPPUNIT_ASSERT(array[2]==3); - CPPUNIT_ASSERT(array[3]==4); -} diff --git a/test/unit/lexcmp_test.cpp b/test/unit/lexcmp_test.cpp deleted file mode 100644 index f913f41..0000000 --- a/test/unit/lexcmp_test.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class LexcmpTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(LexcmpTest); - CPPUNIT_TEST(lexcmp1); - CPPUNIT_TEST(lexcmp2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void lexcmp1(); - void lexcmp2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(LexcmpTest); - -// -// tests implementation -// -void LexcmpTest::lexcmp1() -{ - const unsigned size = 6; - char n1[size] = "shoe"; - char n2[size] = "shine"; - - bool before = lexicographical_compare(n1, n1 + size, n2, n2 + size); - CPPUNIT_ASSERT(!before); -} -void LexcmpTest::lexcmp2() -{ - const unsigned size = 6; - char n1[size] = "shoe"; - char n2[size] = "shine"; - - bool before = lexicographical_compare(n1, n1 + size, n2, n2 + size, greater<char>()); - CPPUNIT_ASSERT(before); -} diff --git a/test/unit/limits_header_test.cpp b/test/unit/limits_header_test.cpp deleted file mode 100644 index 5954a04..0000000 --- a/test/unit/limits_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <limits> diff --git a/test/unit/limits_test.cpp b/test/unit/limits_test.cpp deleted file mode 100644 index d8102ee..0000000 --- a/test/unit/limits_test.cpp +++ /dev/null @@ -1,317 +0,0 @@ -/* boost limits_test.cpp test your <limits> file for important - * - * Copyright Jens Maurer 2000 - * Permission to use, copy, modify, sell, and distribute this software - * is hereby granted without fee provided that the above copyright notice - * appears in all copies and that both that copyright notice and this - * permission notice appear in supporting documentation, - * - * Jens Maurer makes no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - */ - -#include <limits> -//#include <sstream> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class LimitTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(LimitTest); -# if defined (__BORLANDC__) - /* Ignore FPU exceptions, set FPU precision to 64 bits */ - unsigned int _float_control_word = _control87(0, 0); - _control87(PC_64|MCW_EM|IC_AFFINE, MCW_PC|MCW_EM|MCW_IC); -# endif - CPPUNIT_TEST(test); - CPPUNIT_TEST(qnan_test); -# if defined (__BORLANDC__) - /* Reset floating point control word */ - _clear87(); - _control87(_float_control_word, MCW_PC|MCW_EM|MCW_IC); -# endif - CPPUNIT_TEST_SUITE_END(); - -protected: - void test(); - void qnan_test(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(LimitTest); - -#if defined (STLPORT) && defined (_STLP_STATIC_CONST_INIT_BUG) -# define CHECK_COND(X) if (!(X)) { CPPUNIT_MESSAGE(#X); return false; } -#else -//This version force to have external linkage on static constant which might -//reveal that _STLP_NO_STATIC_CONST_DEFINITION should be commented. -bool check_cond(const bool& cond) { return cond; } -# define CHECK_COND(X) if (!check_cond(X)) { CPPUNIT_MESSAGE(#X); return false; } -#endif - -bool valid_sign_info(bool, bool) -{ return true; } - -template <class _Tp> -bool valid_sign_info(bool limit_is_signed, const _Tp &) { - return (limit_is_signed && _Tp(-1) < 0) || - (!limit_is_signed && _Tp(-1) > 0); -} - -template <class _Tp> -bool test_integral_limits_base(const _Tp &, bool unknown_sign = true, bool is_signed = true) { - typedef numeric_limits<_Tp> lim; - - CHECK_COND(lim::is_specialized); - CHECK_COND(lim::is_exact); - CHECK_COND(lim::is_integer); - CHECK_COND(!lim::is_iec559); - CHECK_COND(lim::min() < lim::max()); - CHECK_COND((unknown_sign && ((lim::is_signed && (lim::min() != 0)) || (!lim::is_signed && (lim::min() == 0)))) || - (!unknown_sign && ((lim::is_signed && is_signed) || (!lim::is_signed && !is_signed)))); - - if (unknown_sign) { - CHECK_COND(valid_sign_info(lim::is_signed, _Tp())); - } - return true; -} - -template <class _Tp> -bool test_integral_limits(const _Tp &val, bool unknown_sign = true, bool is_signed = true) { - if (!test_integral_limits_base(val, unknown_sign, is_signed)) - return false; - - typedef numeric_limits<_Tp> lim; - - CHECK_COND(lim::is_modulo); - - if (lim::is_bounded || - (!lim::is_bounded && !lim::is_signed)) { - _Tp tmp = lim::min(); - CHECK_COND( --tmp > lim::min() ); - } - - if (lim::is_bounded) { - _Tp tmp = lim::max(); - CHECK_COND( ++tmp < lim::max() ); - } - - return true; -} - -template <class _Tp> -bool test_signed_integral_limits(const _Tp &__val) { - return test_integral_limits(__val, false, true); -} -template <class _Tp> -bool test_unsigned_integral_limits(const _Tp &__val) { - return test_integral_limits(__val, false, false); -} - -template <class _Tp> -bool test_float_values(_Tp lhs, _Tp rhs) -{ return lhs == rhs; } - -template <class _Tp> -bool test_float_limits(const _Tp &) { - typedef numeric_limits<_Tp> lim; - CHECK_COND(lim::is_specialized); - CHECK_COND(!lim::is_modulo); - CHECK_COND(!lim::is_integer); - CHECK_COND(lim::is_signed); - - CHECK_COND(lim::max() > 1000); - CHECK_COND(lim::min() > 0); - CHECK_COND(lim::min() < 0.001); - CHECK_COND(lim::epsilon() > 0); - - if (lim::is_iec559) { - CHECK_COND(lim::has_infinity); - CHECK_COND(lim::has_quiet_NaN); - CHECK_COND(lim::has_signaling_NaN); - CHECK_COND(lim::has_denorm == denorm_present); - } - - if (lim::has_denorm == denorm_absent) { - CHECK_COND(lim::denorm_min() == lim::min()); - _Tp tmp = lim::min(); - tmp /= 2; - if (tmp > 0 && tmp < lim::min()) { - // has_denorm could be denorm_present - CPPUNIT_MESSAGE("It looks like your compiler/platform supports denormalized floating point representation."); - } - } - else if (lim::has_denorm == denorm_present) { - CHECK_COND(lim::denorm_min() > 0); - CHECK_COND(lim::denorm_min() < lim::min()); - - _Tp tmp = lim::min(); - while (tmp != 0) { - _Tp old_tmp = tmp; - tmp /= 2; - CHECK_COND(tmp < old_tmp); - CHECK_COND(tmp >= lim::denorm_min() || tmp == (_Tp)0); - //ostringstream str; - //str << "denorm_min = " << lim::denorm_min() << ", tmp = " << tmp; - //CPPUNIT_MESSAGE(str.str().c_str()); - } - } - - if (lim::has_infinity) { - const _Tp infinity = lim::infinity(); - /* Make sure those values are not 0 or similar nonsense. - * Infinity must compare as if larger than the maximum representable value. */ - - _Tp val = lim::max(); - val *= 2; - - /* We use test_float_values because without it some compilers (gcc) perform weird - * optimization on the test giving unexpected result. */ - CHECK_COND(test_float_values(val, infinity)); - - /* - ostringstream str; - str << "lim::max() = " << lim::max() << ", val = " << val << ", infinity = " << infinity; - CPPUNIT_MESSAGE( str.str().c_str() ); - str.str(string()); - str << "sizeof(_Tp) = " << sizeof(_Tp); - CPPUNIT_MESSAGE( str.str().c_str() ); - if (sizeof(_Tp) == 4) { - str.str(string()); - str << "val in hexa: " << showbase << hex << *((const unsigned int*)&val); - str << ", infinity in hexa: " << showbase << hex << *((const unsigned int*)&infinity); - } -#if defined (_STLP_LONG_LONG) - else if (sizeof(_Tp) == sizeof(_STLP_LONG_LONG)) { - str.str(string()); - str << "val in hexa: " << showbase << hex << *((const unsigned _STLP_LONG_LONG*)&val); - str << ", infinity in hexa: " << showbase << hex << *((const unsigned _STLP_LONG_LONG*)&infinity); - } -#endif - else { - str.str(string()); - str << "val: "; - for (int i = 0; i != sizeof(_Tp) / sizeof(unsigned short); ++i) { - if (i != 0) str << ' '; - str << showbase << hex << setw(4) << setfill('0') << *((const unsigned short*)&val + i); - } - str << ", infinity: "; - for (int i = 0; i != sizeof(_Tp) / sizeof(unsigned short); ++i) { - if (i != 0) str << ' '; - str << showbase << hex << setw(4) << setfill('0') << *((const unsigned short*)&infinity + i); - } - } - CPPUNIT_MESSAGE( str.str().c_str() ); - str.str(string()); - str << dec; - str << "lim::digits = " << lim::digits << ", lim::digits10 = " << lim::digits10 << endl; - str << "lim::min_exponent = " << lim::min_exponent << ", lim::min_exponent10 = " << lim::min_exponent10 << endl; - str << "lim::max_exponent = " << lim::max_exponent << ", lim::max_exponent10 = " << lim::max_exponent10 << endl; - CPPUNIT_MESSAGE( str.str().c_str() ); - */ - - CHECK_COND(infinity == infinity); - CHECK_COND(infinity > lim::max()); - CHECK_COND(-infinity < -lim::max()); - } - - return true; -} - -//float generate_nan(float f) { -// return 0.0f / f; -//} -template <class _Tp> -bool test_qnan(const _Tp &) { - typedef numeric_limits<_Tp> lim; - if (lim::has_quiet_NaN) { - const _Tp qnan = lim::quiet_NaN(); - - //if (sizeof(_Tp) == 4) { - // ostringstream str; - // str << "qnan " << qnan << ", in hexa: " << showbase << hex << *((unsigned int*)&qnan); - // CPPUNIT_MESSAGE( str.str().c_str() ); - // str.str(""); - // float val = generate_nan(0.0f); - // str << "val " << val << ", in hexa: " << showbase << hex << *((unsigned int*)&val); - // CPPUNIT_MESSAGE( str.str().c_str() ); - // str.str(""); - // val = -qnan; - // str << "-qnan " << val << ", in hexa: " << showbase << hex << *((unsigned int*)&val); - // CPPUNIT_MESSAGE( str.str().c_str() ); - //} - /* NaNs shall always compare "false" when compared for equality - * If one of these fail, your compiler may be optimizing incorrectly, - * or the STLport is incorrectly configured. - */ - CHECK_COND(! (qnan == 42)); - CHECK_COND(! (qnan == qnan)); - CHECK_COND(qnan != 42); - CHECK_COND(qnan != qnan); - - /* The following tests may cause arithmetic traps. - * CHECK_COND(! (qnan < 42)); - * CHECK_COND(! (qnan > 42)); - * CHECK_COND(! (qnan <= 42)); - * CHECK_COND(! (qnan >= 42)); - */ - } - return true; -} - - -class ArbitraryType -{}; - -void LimitTest::test() { - CPPUNIT_CHECK(test_integral_limits_base(bool())); - CPPUNIT_CHECK(test_integral_limits(char())); - typedef signed char signed_char; - CPPUNIT_CHECK(test_signed_integral_limits(signed_char())); - typedef unsigned char unsigned_char; - CPPUNIT_CHECK(test_unsigned_integral_limits(unsigned_char())); -# if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_WCHAR_T_IS_USHORT) - CPPUNIT_CHECK(test_integral_limits(wchar_t())); -# endif - CPPUNIT_CHECK(test_signed_integral_limits(short())); - typedef unsigned short unsigned_short; - CPPUNIT_CHECK(test_unsigned_integral_limits(unsigned_short())); - CPPUNIT_CHECK(test_signed_integral_limits(int())); - typedef unsigned int unsigned_int; - CPPUNIT_CHECK(test_unsigned_integral_limits(unsigned_int())); - CPPUNIT_CHECK(test_signed_integral_limits(long())); - typedef unsigned long unsigned_long; - CPPUNIT_CHECK(test_unsigned_integral_limits(unsigned_long())); -# if defined (_STLP_LONG_LONG) - typedef _STLP_LONG_LONG long_long; - CPPUNIT_CHECK(test_signed_integral_limits(long_long())); - typedef unsigned _STLP_LONG_LONG unsigned_long_long; - CPPUNIT_CHECK(test_unsigned_integral_limits(unsigned_long_long())); -#endif - - CPPUNIT_CHECK(test_float_limits(float())); - CPPUNIT_CHECK(test_float_limits(double())); -# if !defined ( _STLP_NO_LONG_DOUBLE ) - typedef long double long_double; - CPPUNIT_CHECK(test_float_limits(long_double())); -# endif - - CPPUNIT_ASSERT( !numeric_limits<ArbitraryType>::is_specialized ); -} - -void LimitTest::qnan_test() { - CPPUNIT_CHECK(test_qnan(float())); - CPPUNIT_CHECK(test_qnan(double())); -# if !defined ( _STLP_NO_LONG_DOUBLE ) - typedef long double long_double; - CPPUNIT_CHECK(test_qnan(long_double())); -# endif -} diff --git a/test/unit/list_header_test.cpp b/test/unit/list_header_test.cpp deleted file mode 100644 index 36cb6c4..0000000 --- a/test/unit/list_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <list> diff --git a/test/unit/list_test.cpp b/test/unit/list_test.cpp deleted file mode 100644 index 7345d40..0000000 --- a/test/unit/list_test.cpp +++ /dev/null @@ -1,468 +0,0 @@ -//Has to be first for StackAllocator swap overload to be taken -//into account (at least using GCC 4.0.1) -#include "stack_allocator.h" - -#include <list> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class ListTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ListTest); - CPPUNIT_TEST(list1); - CPPUNIT_TEST(list2); - CPPUNIT_TEST(list3); - CPPUNIT_TEST(list4); - CPPUNIT_TEST(erase); - CPPUNIT_TEST(resize); - CPPUNIT_TEST(push_back); - CPPUNIT_TEST(push_front); - CPPUNIT_TEST(allocator_with_state); - CPPUNIT_TEST(swap); - CPPUNIT_TEST(adl); - //CPPUNIT_TEST(const_list); - CPPUNIT_TEST_SUITE_END(); - -protected: - void list1(); - void list2(); - void list3(); - void list4(); - void erase(); - void resize(); - void push_back(); - void push_front(); - void allocator_with_state(); - void swap(); - void adl(); - //void const_list(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ListTest); - -// -// tests implementation -// -void ListTest::list1() -{ - int array1 [] = { 9, 16, 36 }; - int array2 [] = { 1, 4 }; - - list<int> l1(array1, array1 + 3); - list<int> l2(array2, array2 + 2); - list<int>::iterator i1 = l1.begin(); - list<int>::iterator i2 = l2.begin(); - list<int>::const_iterator ci(i1); - list<int>::const_iterator ci1(ci); - l1.splice(i1, l2); - i1 = l1.begin(); - CPPUNIT_ASSERT( *i1++ == 1 ); - CPPUNIT_ASSERT( *i1++ == 4 ); - CPPUNIT_ASSERT( *i1++ == 9 ); - CPPUNIT_ASSERT( *i1++ == 16 ); - CPPUNIT_ASSERT( *i1++ == 36 ); - -#if defined (STLPORT) && \ - (!defined (_STLP_DEBUG) || (_STLP_DEBUG_LEVEL != _STLP_STANDARD_DBG_LEVEL)) - CPPUNIT_ASSERT( i2 == l1.begin() ); -#endif - - //Default construct check (_STLP_DEF_CONST_PLCT_NEW_BUG) - list<int> l(2); - i1 = l.begin(); - CPPUNIT_ASSERT( *(i1++) == 0 ); - CPPUNIT_ASSERT( *i1 == 0 ); -#if 0 - //A small compilation time check to be activated from time to time, - //compilation should fail. - { - list<char>::iterator l_char_ite; - list<int>::iterator l_int_ite; - CPPUNIT_ASSERT( l_char_ite != l_int_ite ); - } -#endif -} - -void ListTest::list2() -{ - int array1 [] = { 1, 16 }; - int array2 [] = { 4, 9 }; - - list<int> l1(array1, array1 + 2); - list<int> l2(array2, array2 + 2); - list<int>::iterator i = l1.begin(); - i++; - l1.splice(i, l2, l2.begin(), l2.end()); - i = l1.begin(); - CPPUNIT_ASSERT(*i++==1); - CPPUNIT_ASSERT(*i++==4); - CPPUNIT_ASSERT(*i++==9); - CPPUNIT_ASSERT(*i++==16); -} - -void ListTest::list3() -{ - char array [] = { 'x', 'l', 'x', 't', 's', 's' }; - - list<char> str(array, array + 6); - list<char>::iterator i; - - str.reverse(); - i = str.begin(); - CPPUNIT_ASSERT(*i++=='s'); - CPPUNIT_ASSERT(*i++=='s'); - CPPUNIT_ASSERT(*i++=='t'); - CPPUNIT_ASSERT(*i++=='x'); - CPPUNIT_ASSERT(*i++=='l'); - CPPUNIT_ASSERT(*i++=='x'); - - str.remove('x'); - i = str.begin(); - CPPUNIT_ASSERT(*i++=='s'); - CPPUNIT_ASSERT(*i++=='s'); - CPPUNIT_ASSERT(*i++=='t'); - CPPUNIT_ASSERT(*i++=='l'); - - str.unique(); - i = str.begin(); - CPPUNIT_ASSERT(*i++=='s'); - CPPUNIT_ASSERT(*i++=='t'); - CPPUNIT_ASSERT(*i++=='l'); - - str.sort(); - i = str.begin(); - CPPUNIT_ASSERT(*i++=='l'); - CPPUNIT_ASSERT(*i++=='s'); - CPPUNIT_ASSERT(*i++=='t'); -} - -void ListTest::list4() -{ - int array1 [] = { 1, 3, 6, 7 }; - int array2 [] = { 2, 4 }; - - list<int> l1(array1, array1 + 4); - list<int> l2(array2, array2 + 2); - l1.merge(l2); - list<int>::iterator i = l1.begin(); - CPPUNIT_ASSERT(*i++==1); - CPPUNIT_ASSERT(*i++==2); - CPPUNIT_ASSERT(*i++==3); - CPPUNIT_ASSERT(*i++==4); - CPPUNIT_ASSERT(*i++==6); - CPPUNIT_ASSERT(*i++==7); - - //We use distance to avoid a simple call to an internal counter - CPPUNIT_ASSERT(distance(l1.begin(), l1.end()) == 6); - CPPUNIT_ASSERT(distance(l2.begin(), l2.end()) == 0); - - l1.swap(l2); - - CPPUNIT_ASSERT(distance(l1.begin(), l1.end()) == 0); - CPPUNIT_ASSERT(distance(l2.begin(), l2.end()) == 6); -} - -void ListTest::erase() -{ - list<int> l; - l.push_back( 1 ); - l.erase(l.begin()); - CPPUNIT_ASSERT( l.empty() ); - - int array[] = { 0, 1, 2, 3 }; - l.assign(array, array + 4); - list<int>::iterator lit; - lit = l.erase(l.begin()); - CPPUNIT_ASSERT( *lit == 1 ); - - lit = l.erase(l.begin(), --l.end()); - CPPUNIT_ASSERT( *lit == 3 ); - - l.clear(); - CPPUNIT_ASSERT( l.empty() ); -} - - -void ListTest::resize() -{ - { - list<int> l; - l.resize(5, 1); - - size_t i; - list<int>::iterator lit(l.begin()); - for (i = 0; i < 5; ++i) { - CPPUNIT_ASSERT( lit != l.end() ); - CPPUNIT_ASSERT( *(lit++) == 1 ); - } - CPPUNIT_ASSERT( lit == l.end() ); - - l.resize(3); - lit = l.begin(); - for (i = 0; i < 3; ++i) { - CPPUNIT_ASSERT( lit != l.end() ); - CPPUNIT_ASSERT( *(lit++) == 1 ); - } - CPPUNIT_ASSERT( lit == l.end() ); - } - - { - list<int> l; - l.resize(5); - - size_t i; - list<int>::iterator lit(l.begin()); - for (i = 0; i < 5; ++i) { - CPPUNIT_ASSERT( lit != l.end() ); - CPPUNIT_ASSERT( *(lit++) == 0 ); - } - CPPUNIT_ASSERT( lit == l.end() ); - } -} - -void ListTest::push_back() -{ - list<int> l; - l.push_back( 1 ); - l.push_back( 2 ); - l.push_back( 3 ); - - list<int>::reverse_iterator r = l.rbegin(); - - CPPUNIT_ASSERT( *r == 3 ); - l.push_back( 4 ); - /* - * Following lines are commented, because ones show standard contradiction - * (24.4.1 and 23.2.2.3); but present behaviour is valid, 24.4.1, paragraphs 1 and 2, - * 24.4.1.3.3 and 23.1 paragraph 9 (Table 66). The 24.4.1 is more common rule, - * so it has preference under 23.2.2.3, by my opinion. - * - * - ptr - */ - // CPPUNIT_ASSERT( *r == 3 ); - // ++r; - // CPPUNIT_ASSERT( *r == 2 ); -} - -void ListTest::push_front() -{ - list<int> l; - l.push_back( 1 ); - l.push_back( 2 ); - l.push_back( 3 ); - - list<int>::iterator i = l.begin(); - - CPPUNIT_ASSERT( *i == 1 ); - l.push_front( 0 ); - CPPUNIT_ASSERT( *i == 1 ); - ++i; - CPPUNIT_ASSERT( *i == 2 ); -} - -void ListTest::allocator_with_state() -{ - char buf1[1024]; - StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1)); - - char buf2[1024]; - StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2)); - - typedef list<int, StackAllocator<int> > ListInt; - { - //Swap with both list non empty - ListInt lint1(10, 0, stack1); - ListInt lint1Cpy(lint1); - - ListInt lint2(10, 1, stack2); - ListInt lint2Cpy(lint2); - - lint1.swap(lint2); - - CPPUNIT_ASSERT( lint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( lint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( lint1 == lint2Cpy ); - CPPUNIT_ASSERT( lint2 == lint1Cpy ); - CPPUNIT_ASSERT( lint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( lint2.get_allocator() == stack1 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - //Swap with empty calle list - ListInt lint1(10, 0, stack1); - ListInt lint1Cpy(lint1); - - ListInt lint2(stack2); - ListInt lint2Cpy(lint2); - - lint1.swap(lint2); - - CPPUNIT_ASSERT( lint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( lint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( lint1 == lint2Cpy ); - CPPUNIT_ASSERT( lint2 == lint1Cpy ); - CPPUNIT_ASSERT( lint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( lint2.get_allocator() == stack1 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - //Swap with empty caller list - ListInt lint1(stack1); - ListInt lint1Cpy(lint1); - - ListInt lint2(10, 0, stack2); - ListInt lint2Cpy(lint2); - - lint1.swap(lint2); - - CPPUNIT_ASSERT( lint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( lint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( lint1 == lint2Cpy ); - CPPUNIT_ASSERT( lint2 == lint1Cpy ); - CPPUNIT_ASSERT( lint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( lint2.get_allocator() == stack1 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - ListInt lint1(10, 0, stack1); - ListInt lint2(10, 1, stack2); - - lint1.splice(lint1.begin(), lint2); - CPPUNIT_ASSERT( lint1.size() == 20 ); - CPPUNIT_ASSERT( lint2.empty() ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - ListInt lint1(10, 0, stack1); - ListInt lint2(10, 1, stack2); - - lint1.splice(lint1.begin(), lint2, lint2.begin()); - CPPUNIT_ASSERT( lint1.size() == 11 ); - CPPUNIT_ASSERT( lint2.size() == 9 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - ListInt lint1(10, 0, stack1); - ListInt lint2(10, 1, stack2); - - ListInt::iterator lit(lint2.begin()); - advance(lit, 5); - lint1.splice(lint1.begin(), lint2, lint2.begin(), lit); - CPPUNIT_ASSERT( lint1.size() == 15 ); - CPPUNIT_ASSERT( lint2.size() == 5 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - ListInt lint1(10, 0, stack1); - ListInt lint2(10, 1, stack2); - - ListInt lintref(stack2); - lintref.insert(lintref.begin(), 10, 1); - lintref.insert(lintref.begin(), 10, 0); - - lint1.merge(lint2); - CPPUNIT_ASSERT( lint1.size() == 20 ); - CPPUNIT_ASSERT( lint1 == lintref ); - CPPUNIT_ASSERT( lint2.empty() ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - -#if defined (STLPORT) && !defined (_STLP_NO_MEMBER_TEMPLATES) && \ - (!defined (_MSC_VER) || (_MSC_VER >= 1300)) - { - //This is a compile time test. - //We check that sort implementation is correct when list is instanciated - //with an allocator that do not have a default constructor. - ListInt lint1(10, 0, stack1); - lint1.sort(); - lint1.sort(greater<int>()); - } -#endif -} - -/* -void ListTest::const_list() -{ - list<const int> cint_list; - cint_list.push_back(1); - cint_list.push_front(2); -} -*/ -void ListTest::swap() -{ - list<int> lst1; - list<int> lst2; - - lst1.push_back(1); - lst2.push_back(2); - - lst1.swap( lst2 ); - - CPPUNIT_CHECK( lst1.front() == 2 ); - CPPUNIT_CHECK( lst2.front() == 1 ); - CPPUNIT_CHECK( lst1.size() == 1 ); - CPPUNIT_CHECK( lst2.size() == 1 ); - - lst1.pop_front(); - lst2.pop_front(); - - CPPUNIT_CHECK( lst1.empty() ); - CPPUNIT_CHECK( lst2.empty() ); -} - -namespace foo { - class bar {}; - - template <class _It> - size_t distance(_It, _It); -} - -void ListTest::adl() -{ - list<foo::bar> lbar; - CPPUNIT_ASSERT( lbar.size() == 0); -} - -#if !defined (STLPORT) || \ - !defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) -/* Simple compilation test: Check that nested types like iterator - * can be access even if type used to instanciate container is not - * yet completely defined. - */ -class IncompleteClass -{ - list<IncompleteClass> instances; - typedef list<IncompleteClass>::iterator it; -}; -#endif diff --git a/test/unit/locale_header_test.cpp b/test/unit/locale_header_test.cpp deleted file mode 100644 index bb2dec1..0000000 --- a/test/unit/locale_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <locale> -#endif diff --git a/test/unit/locale_test.cpp b/test/unit/locale_test.cpp deleted file mode 100644 index 71d3da9..0000000 --- a/test/unit/locale_test.cpp +++ /dev/null @@ -1,337 +0,0 @@ -#include "locale_test.h" - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <sstream> -# include <locale> -# include <stdexcept> - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -static const char* tested_locales[] = { -//name, -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - "fr_FR", - "ru_RU.koi8r", - "en_GB", - "en_US", -# endif - "", - "C" -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(LocaleTest); - -// -// tests implementation -// -typedef void (LocaleTest::*_Test) (const locale&); -static void test_supported_locale(LocaleTest &inst, _Test __test) { - size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]); - for (size_t i = 0; i < n; ++i) { - locale loc; -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { -# endif - locale tmp(tested_locales[i]); - loc = tmp; -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - } - catch (runtime_error const&) { - //This locale is not supported. - continue; - } -# endif - CPPUNIT_MESSAGE( loc.name().c_str() ); - (inst.*__test)(loc); - } -} - -void LocaleTest::locale_by_name() { -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - /* - * Check of the 22.1.1.2.7 standard point. Construction of a locale - * instance from a null pointer or an unknown name should result in - * a runtime_error exception. - */ - try { - locale loc(static_cast<char const*>(0)); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc("yasli_language"); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - string very_large_locale_name(1024, '?'); - locale loc(very_large_locale_name.c_str()); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - -#if defined (STLPORT) || !defined (_MSC_VER) || (_MSC_VER > 1400) - try { - string very_large_locale_name("LC_CTYPE="); - very_large_locale_name.append(1024, '?'); - locale loc(very_large_locale_name.c_str()); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - string very_large_locale_name("LC_ALL="); - very_large_locale_name.append(1024, '?'); - locale loc(very_large_locale_name.c_str()); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } -#endif - - try { - locale loc("C"); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - // On platform without real localization support we should rely on the "C" locale facet. - locale loc(""); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - -# endif -} - -void LocaleTest::loc_has_facet() { - locale loc("C"); - typedef numpunct<char> implemented_facet; - CPPUNIT_ASSERT( has_facet<implemented_facet>(loc) ); - /* - typedef num_put<char, back_insert_iterator<string> > not_implemented_facet; - CPPUNIT_ASSERT( !has_facet<not_implemented_facet>(loc) ); - */ -} - -void LocaleTest::locale_init_problem() { -# if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) - test_supported_locale(*this, &LocaleTest::_locale_init_problem); -# endif -} - -/* - * Creation of a locale instance imply initialization of some STLport internal - * static objects first. We use a static instance of locale to check that this - * initialization is done correctly. - */ -static locale global_loc; -static locale other_loc(""); - -# if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) -void LocaleTest::_locale_init_problem( const locale& loc) -{ -# if !defined (__APPLE__) && !defined (__FreeBSD__) || \ - !defined(__GNUC__) || ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__> 3))) - typedef codecvt<char,char,mbstate_t> my_facet; -# else -// std::mbstate_t required for gcc 3.3.2 on FreeBSD... -// I am not sure what key here---FreeBSD or 3.3.2... -// - ptr 2005-04-04 - typedef codecvt<char,char,std::mbstate_t> my_facet; -# endif - - locale loc_ref(global_loc); - { - locale gloc( loc_ref, new my_facet() ); - CPPUNIT_ASSERT( has_facet<my_facet>( gloc ) ); - //The following code is just here to try to confuse the reference counting underlying mecanism: - locale::global( locale::classic() ); - locale::global( gloc ); - } - -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { -# endif - ostringstream os("test") ; - locale loc2( loc, new my_facet() ); - CPPUNIT_ASSERT( has_facet<my_facet>( loc2 ) ); - os.imbue( loc2 ); -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - } - catch ( runtime_error& ) { - CPPUNIT_FAIL; - } - catch ( ... ) { - CPPUNIT_FAIL; - } -# endif - -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { -# endif - ostringstream os2("test2"); -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - } - catch ( runtime_error& ) { - CPPUNIT_FAIL; - } - catch ( ... ) { - CPPUNIT_FAIL; - } -# endif -} -#endif - -void LocaleTest::default_locale() -{ - locale loc( "" ); -} - -class dummy_facet : public locale::facet { -public: - static locale::id id; -}; - -locale::id dummy_facet::id; - -void LocaleTest::combine() -{ -# if (!defined (STLPORT) || \ - (defined (_STLP_USE_EXCEPTIONS) && !defined (_STLP_NO_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))) - { - try { - locale loc(""); - if (!has_facet<messages<char> >(loc)) { - loc.combine<messages<char> >(loc); - CPPUNIT_FAIL; - } - } - catch (const runtime_error & /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - } - - try { - locale loc; - if (!has_facet<dummy_facet>(loc)) { - loc.combine<dummy_facet>(loc); - CPPUNIT_FAIL; - } - } - catch (const runtime_error & /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - } - } - - locale loc1(locale::classic()), loc2; - size_t loc1_index = 0; - for (size_t i = 0; _get_ref_monetary(i) != 0; ++i) { - try { - { - locale loc(_get_ref_monetary_name(_get_ref_monetary(i))); - if (loc1 == locale::classic()) - { - loc1 = loc; - loc1_index = i; - continue; - } - else - { - loc2 = loc; - } - } - - //We can start the test - ostringstream ostr; - ostr << "combining '" << loc2.name() << "' money facets with '" << loc1.name() << "'"; - CPPUNIT_MESSAGE( ostr.str().c_str() ); - - //We are going to combine money facets as all formats are different. - { - //We check that resulting locale has correctly acquire loc2 facets. - locale loc = loc1.combine<moneypunct<char, true> >(loc2); - loc = loc.combine<moneypunct<char, false> >(loc2); - loc = loc.combine<money_put<char> >(loc2); - loc = loc.combine<money_get<char> >(loc2); - - //Check loc has the correct facets: - _money_put_get2(loc2, loc, _get_ref_monetary(i)); - - //Check loc1 has not been impacted: - _money_put_get2(loc1, loc1, _get_ref_monetary(loc1_index)); - - //Check loc2 has not been impacted: - _money_put_get2(loc2, loc2, _get_ref_monetary(i)); - } - { - //We check that resulting locale has not wrongly acquire loc1 facets that hasn't been combine: - locale loc = loc2.combine<numpunct<char> >(loc1); - loc = loc.combine<time_put<char> >(loc1); - loc = loc.combine<time_get<char> >(loc1); - - //Check loc has the correct facets: - _money_put_get2(loc2, loc, _get_ref_monetary(i)); - - //Check loc1 has not been impacted: - _money_put_get2(loc1, loc1, _get_ref_monetary(loc1_index)); - - //Check loc2 has not been impacted: - _money_put_get2(loc2, loc2, _get_ref_monetary(i)); - } - - { - // Check auto combination do not result in weird reference counting behavior - // (might generate a crash). - loc1.combine<numpunct<char> >(loc1); - } - - loc1 = loc2; - loc1_index = i; - } - catch (runtime_error const&) { - //This locale is not supported. - continue; - } - } -# endif -} - -#endif diff --git a/test/unit/locale_test.h b/test/unit/locale_test.h deleted file mode 100644 index ab97ac4..0000000 --- a/test/unit/locale_test.h +++ /dev/null @@ -1,94 +0,0 @@ -#include <string> -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <iosfwd> - -# include "cppunit/cppunit_proxy.h" -# include <locale> - -struct ref_monetary; -struct ref_locale; - -# if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -# define STD std:: -# else -# define STD -# endif - -// -// TestCase class -// -class LocaleTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(LocaleTest); -# if defined (STLPORT) && !defined (_STLP_USE_EXCEPTIONS) - CPPUNIT_IGNORE; -# endif - CPPUNIT_TEST(locale_by_name); - CPPUNIT_TEST(moneypunct_by_name); - CPPUNIT_TEST(time_by_name); - CPPUNIT_TEST(numpunct_by_name); - CPPUNIT_TEST(ctype_by_name); - CPPUNIT_TEST(collate_by_name); - CPPUNIT_TEST(messages_by_name); - CPPUNIT_STOP_IGNORE; - CPPUNIT_TEST(loc_has_facet); - CPPUNIT_TEST(num_put_get); - CPPUNIT_TEST(money_put_get); - CPPUNIT_TEST(money_put_X_bug); - CPPUNIT_TEST(time_put_get); - CPPUNIT_TEST(collate_facet); - CPPUNIT_TEST(ctype_facet); -# if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES) - CPPUNIT_IGNORE; -# endif - CPPUNIT_TEST(locale_init_problem); - CPPUNIT_STOP_IGNORE; - CPPUNIT_TEST(default_locale); -# if !defined (STLPORT) - CPPUNIT_IGNORE; -# endif - CPPUNIT_STOP_IGNORE; -#if (defined (STLPORT) && \ - (!defined (_STLP_USE_EXCEPTIONS) || defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))) - CPPUNIT_IGNORE; -# endif - CPPUNIT_TEST(combine); - CPPUNIT_TEST_SUITE_END(); - -public: - void locale_by_name(); - void loc_has_facet(); - void num_put_get(); - void numpunct_by_name(); - void time_put_get(); - void time_by_name(); - void collate_facet(); - void collate_by_name(); - void ctype_facet(); - void ctype_by_name(); - void locale_init_problem(); - void money_put_get(); - void money_put_X_bug(); - void moneypunct_by_name(); - void default_locale(); - void combine(); - void messages_by_name(); -private: - void _loc_has_facet( const STD locale& ); - void _num_put_get( const STD locale&, const ref_locale* ); - void _time_put_get( const STD locale& ); - void _ctype_facet( const STD locale& ); - void _ctype_facet_w( const STD locale& ); - void _locale_init_problem( const STD locale& ); - - static const ref_monetary* _get_ref_monetary(size_t); - static const char* _get_ref_monetary_name(const ref_monetary*); - - void _money_put_get( const STD locale&, const ref_monetary* ); - void _money_put_get2( const STD locale& loc, const STD locale& streamLoc, const ref_monetary* ); - void _money_put_X_bug( const STD locale&, const ref_monetary* ); -}; - -# undef STD -#endif - diff --git a/test/unit/logic_test.cpp b/test/unit/logic_test.cpp deleted file mode 100644 index 69ceea1..0000000 --- a/test/unit/logic_test.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class LogicTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(LogicTest); - CPPUNIT_TEST(logicand); - CPPUNIT_TEST(logicnot); - CPPUNIT_TEST(logicor); - CPPUNIT_TEST_SUITE_END(); - -protected: - void logicand(); - void logicnot(); - void logicor(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(LogicTest); - -// -// tests implementation -// -void LogicTest::logicand() -{ - bool input1 [4] = { true, true, false, true }; - bool input2 [4] = { false, true, false, false }; - - bool output [4]; - transform((bool*)input1, (bool*)input1 + 4, (bool*)input2, (bool*)output, logical_and<bool>()); - - CPPUNIT_ASSERT(output[0]==false); - CPPUNIT_ASSERT(output[1]==true); - CPPUNIT_ASSERT(output[2]==false); - CPPUNIT_ASSERT(output[3]==false); -} -void LogicTest::logicnot() -{ - bool input [7] = { 1, 0, 0, 1, 1, 1, 1 }; - - int n = count_if(input, input + 7, logical_not<bool>()); - CPPUNIT_ASSERT( n == 2 ); -} -void LogicTest::logicor() -{ - bool input1 [4] = { true, true, false, true }; - bool input2 [4] = { false, true, false, false }; - - bool output [4]; - transform((bool*)input1, (bool*)input1 + 4, (bool*)input2, (bool*)output, logical_or<bool>()); - - CPPUNIT_ASSERT(output[0]==true); - CPPUNIT_ASSERT(output[1]==true); - CPPUNIT_ASSERT(output[2]==false); - CPPUNIT_ASSERT(output[3]==true); -} diff --git a/test/unit/macro_checks.cpp b/test/unit/macro_checks.cpp deleted file mode 100644 index 171a9fa..0000000 --- a/test/unit/macro_checks.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include <cstdio> -#include <cwchar> -#include <climits> - -#if !defined (CHAR_BIT) -# error Missing CHAR_BIT definition. -#endif - -#if (CHAR_BIT < 0) -# error Weird WCHAR_BIT value. -#endif - -#if !defined (CHAR_MAX) -# error Missing CHAR_MAX definition. -#endif - -#if !defined (CHAR_MIN) -# error Missing CHAR_MIN definition. -#endif - -#if !(CHAR_MIN < CHAR_MAX) -# error Weird CHAR_MIN or CHAR_MAX macro values. -#endif - -#if !defined (INT_MAX) -# error Missing INT_MAX definition. -#endif - -#if !defined (INT_MIN) -# error Missing INT_MIN definition. -#endif - -#if !(INT_MIN < INT_MAX) -# error Weird INT_MIN or INT_MAX macro values. -#endif - -#if !defined (LONG_MAX) -# error Missing LONG_MAX definition. -#endif - -#if !defined (LONG_MIN) -# error Missing LONG_MIN definition. -#endif - -#if !(LONG_MIN < LONG_MAX) -# error Weird LONG_MIN or LONG_MAX macro values. -#endif - -#if !defined (SCHAR_MAX) -# error Missing SCHAR_MAX definition. -#endif - -#if !defined (SCHAR_MIN) -# error Missing SCHAR_MIN definition. -#endif - -#if !(SCHAR_MIN < SCHAR_MAX) -# error Weird SCHAR_MIN or SCHAR_MAX macro values. -#endif - -#if !defined (SHRT_MAX) -# error Missing SHRT_MAX definition. -#endif - -#if !defined (SHRT_MIN) -# error Missing SHRT_MIN definition. -#endif - -#if !(SHRT_MIN < SHRT_MAX) -# error Weird SHRT_MIN or SHRT_MAX macro values. -#endif - -#if !defined (WCHAR_MIN) -# error Missing WCHAR_MIN definition. -#endif - -#if !defined (WCHAR_MAX) -# error Missing WCHAR_MAX definition. -#endif - -#if !(WCHAR_MIN < WCHAR_MAX) -# error Weird WCHAR_MIN or WCHAR_MAX macro value. -#endif - -#if !defined (UCHAR_MAX) -# error Missing UCHAR_MAX definition. -#endif - -#if (UCHAR_MAX < 0) -# error Weird UCHAR_MAX macro value. -#endif - -#if !defined (UINT_MAX) -# error Missing UINT_MAX definition. -#endif - -#if (UINT_MAX < 0) -# error Weird UINT_MAX macro value. -#endif - -#if !defined (ULONG_MAX) -# error Missing ULONG_MAX definition. -#endif - -#if (ULONG_MAX < 0) -# error Weird ULONG_MAX macro value. -#endif - -#if !defined (USHRT_MAX) -# error Missing USHRT_MAX definition. -#endif - -#if (USHRT_MAX < 0) -# error Weird USHRT_MAX macro value. -#endif diff --git a/test/unit/map_header_test.cpp b/test/unit/map_header_test.cpp deleted file mode 100644 index 84cf154..0000000 --- a/test/unit/map_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <map> diff --git a/test/unit/map_test.cpp b/test/unit/map_test.cpp deleted file mode 100644 index 46256a9..0000000 --- a/test/unit/map_test.cpp +++ /dev/null @@ -1,454 +0,0 @@ -//Has to be first for StackAllocator swap overload to be taken -//into account (at least using GCC 4.0.1) -#include "stack_allocator.h" - -#include <map> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class MapTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(MapTest); - CPPUNIT_TEST(map1); - CPPUNIT_TEST(mmap1); - CPPUNIT_TEST(mmap2); - CPPUNIT_TEST(iterators); - CPPUNIT_TEST(equal_range); - CPPUNIT_TEST(allocator_with_state); -#if !defined (STLPORT) || !defined (_STLP_USE_CONTAINERS_EXTENSION) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(template_methods); - CPPUNIT_TEST_SUITE_END(); - -protected: - void map1(); - void mmap1(); - void mmap2(); - void iterators(); - void equal_range(); - void allocator_with_state(); - void template_methods(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MapTest); - -// -// tests implementation -// -void MapTest::map1() -{ - typedef map<char, int, less<char> > maptype; - maptype m; - // Store mappings between roman numerals and decimals. - m['l'] = 50; - m['x'] = 20; // Deliberate mistake. - m['v'] = 5; - m['i'] = 1; -// cout << "m['x'] = " << m['x'] << endl; - CPPUNIT_ASSERT( m['x']== 20 ); - m['x'] = 10; // Correct mistake. - CPPUNIT_ASSERT( m['x']== 10 ); - CPPUNIT_ASSERT( m['z']== 0 ); - //cout << "m['z'] = " << m['z'] << endl; // Note default value is added. - CPPUNIT_ASSERT( m.count('z') == 1 ); - //cout << "m.count('z') = " << m.count('z') << endl; - pair<maptype::iterator, bool> p = m.insert(pair<const char, int>('c', 100)); - CPPUNIT_ASSERT( p.second ); - CPPUNIT_ASSERT( p.first != m.end() ); - CPPUNIT_ASSERT( (*p.first).first == 'c' ); - CPPUNIT_ASSERT( (*p.first).second == 100 ); - - p = m.insert(pair<const char, int>('c', 100)); - CPPUNIT_ASSERT( !p.second ); // already existing pair - CPPUNIT_ASSERT( p.first != m.end() ); - CPPUNIT_ASSERT( (*p.first).first == 'c' ); - CPPUNIT_ASSERT( (*p.first).second == 100 ); -} - -void MapTest::mmap1() -{ - typedef multimap<char, int, less<char> > mmap; - mmap m; - CPPUNIT_ASSERT(m.count('X')==0); - - m.insert(pair<const char, int>('X', 10)); // Standard way. - CPPUNIT_ASSERT(m.count('X')==1); - - m.insert(pair<const char, int>('X', 20)); // jbuck: standard way - CPPUNIT_ASSERT(m.count('X')==2); - - m.insert(pair<const char, int>('Y', 32)); // jbuck: standard way - mmap::iterator i = m.find('X'); // Find first match. -#ifndef _STLP_CONST -# define _STLP_CONST const -#endif - pair<_STLP_CONST char, int> p('X', 10); - CPPUNIT_ASSERT(*i == p); - CPPUNIT_ASSERT((*i).first == 'X'); - CPPUNIT_ASSERT((*i).second == 10); - i++; - CPPUNIT_ASSERT((*i).first == 'X'); - CPPUNIT_ASSERT((*i).second == 20); - i++; - CPPUNIT_ASSERT((*i).first == 'Y'); - CPPUNIT_ASSERT((*i).second == 32); - i++; - CPPUNIT_ASSERT(i == m.end()); - - size_t count = m.erase('X'); - CPPUNIT_ASSERT(count==2); -} -void MapTest::mmap2() -{ - typedef pair<const int, char> pair_type; - - pair_type p1(3, 'c'); - pair_type p2(6, 'f'); - pair_type p3(1, 'a'); - pair_type p4(2, 'b'); - pair_type p5(3, 'x'); - pair_type p6(6, 'f'); - - typedef multimap<int, char, less<int> > mmap; - - pair_type array [] = { - p1, - p2, - p3, - p4, - p5, - p6 - }; - - mmap m(array + 0, array + 6); - mmap::iterator i; - i = m.lower_bound(3); - CPPUNIT_ASSERT((*i).first==3); - CPPUNIT_ASSERT((*i).second=='c'); - - i = m.upper_bound(3); - CPPUNIT_ASSERT((*i).first==6); - CPPUNIT_ASSERT((*i).second=='f'); -} - - -void MapTest::iterators() -{ - typedef map<int, char, less<int> > int_map; - int_map imap; - { - int_map::iterator ite(imap.begin()); - int_map::const_iterator cite(imap.begin()); - CPPUNIT_ASSERT( ite == cite ); - CPPUNIT_ASSERT( !(ite != cite) ); - CPPUNIT_ASSERT( cite == ite ); - CPPUNIT_ASSERT( !(cite != ite) ); - } - - typedef multimap<int, char, less<int> > mmap; - typedef mmap::value_type pair_type; - - pair_type p1(3, 'c'); - pair_type p2(6, 'f'); - pair_type p3(1, 'a'); - pair_type p4(2, 'b'); - pair_type p5(3, 'x'); - pair_type p6(6, 'f'); - - pair_type array [] = { - p1, - p2, - p3, - p4, - p5, - p6 - }; - - mmap m(array+0, array + 6); - - { - mmap::iterator ite(m.begin()); - mmap::const_iterator cite(m.begin()); - //test compare between const_iterator and iterator - CPPUNIT_ASSERT( ite == cite ); - CPPUNIT_ASSERT( !(ite != cite) ); - CPPUNIT_ASSERT( cite == ite ); - CPPUNIT_ASSERT( !(cite != ite) ); - } - -#if 0 - /* - * A check that map and multimap iterators are NOT comparable - * the following code should generate a compile time error - */ - { - int_map::iterator mite(imap.begin()); - int_map::const_iterator mcite(imap.begin()); - mmap::iterator mmite(m.begin()); - mmap::const_iterator mmcite(m.begin()); - CPPUNIT_ASSERT( !(mite == mmite) ); - CPPUNIT_ASSERT( !(mcite == mmcite) ); - CPPUNIT_ASSERT( mite != mmite ); - CPPUNIT_ASSERT( mcite != mmcite ); - CPPUNIT_ASSERT( !(mite == mmcite) ); - CPPUNIT_ASSERT( !(mite == mmcite) ); - CPPUNIT_ASSERT( mite != mmcite ); - CPPUNIT_ASSERT( mite != mmcite ); - } - -#endif - - mmap::reverse_iterator ri = m.rbegin(); - CPPUNIT_ASSERT( ri != m.rend() ); - CPPUNIT_ASSERT( ri == m.rbegin() ); - CPPUNIT_ASSERT( (*ri).first == 6 ); - CPPUNIT_ASSERT( (*ri++).second == 'f' ); - CPPUNIT_ASSERT( (*ri).first == 6 ); - CPPUNIT_ASSERT( (*ri).second == 'f' ); - - mmap const& cm = m; - mmap::const_reverse_iterator rci = cm.rbegin(); - CPPUNIT_ASSERT( rci != cm.rend() ); - CPPUNIT_ASSERT( (*rci).first == 6 ); - CPPUNIT_ASSERT( (*rci++).second == 'f' ); - CPPUNIT_ASSERT( (*rci).first == 6 ); - CPPUNIT_ASSERT( (*rci).second == 'f' ); -} - -void MapTest::equal_range() -{ - typedef map<char, int, less<char> > maptype; - { - maptype m; - m['x'] = 10; - - pair<maptype::iterator, maptype::iterator> ret; - ret = m.equal_range('x'); - CPPUNIT_ASSERT( ret.first != ret.second ); - CPPUNIT_ASSERT( (*(ret.first)).first == 'x' ); - CPPUNIT_ASSERT( (*(ret.first)).second == 10 ); - CPPUNIT_ASSERT( ++(ret.first) == ret.second ); - } - { - { - maptype m; - - maptype::iterator i = m.lower_bound( 'x' ); - CPPUNIT_ASSERT( i == m.end() ); - - i = m.upper_bound( 'x' ); - CPPUNIT_ASSERT( i == m.end() ); - - pair<maptype::iterator, maptype::iterator> ret; - ret = m.equal_range('x'); - CPPUNIT_ASSERT( ret.first == ret.second ); - CPPUNIT_ASSERT( ret.first == m.end() ); - } - - { - const maptype m; - pair<maptype::const_iterator, maptype::const_iterator> ret; - ret = m.equal_range('x'); - CPPUNIT_ASSERT( ret.first == ret.second ); - CPPUNIT_ASSERT( ret.first == m.end() ); - } - } -} - -void MapTest::allocator_with_state() -{ - char buf1[1024]; - StackAllocator<pair<const int, int> > stack1(buf1, buf1 + sizeof(buf1)); - - char buf2[1024]; - StackAllocator<pair<const int, int> > stack2(buf2, buf2 + sizeof(buf2)); - - { - typedef map<int, int, less<int>, StackAllocator<pair<const int, int> > > MapInt; - less<int> intLess; - MapInt mint1(intLess, stack1); - int i; - for (i = 0; i < 5; ++i) - mint1.insert(MapInt::value_type(i, i)); - MapInt mint1Cpy(mint1); - - MapInt mint2(intLess, stack2); - for (; i < 10; ++i) - mint2.insert(MapInt::value_type(i, i)); - MapInt mint2Cpy(mint2); - - mint1.swap(mint2); - - CPPUNIT_ASSERT( mint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( mint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( mint1 == mint2Cpy ); - CPPUNIT_ASSERT( mint2 == mint1Cpy ); - CPPUNIT_ASSERT( mint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( mint2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); -} - -struct Key -{ - Key() : m_data(0) {} - explicit Key(int data) : m_data(data) {} - - int m_data; -}; - -struct KeyCmp -{ - bool operator () (Key lhs, Key rhs) const - { return lhs.m_data < rhs.m_data; } - - bool operator () (Key lhs, int rhs) const - { return lhs.m_data < rhs; } - - bool operator () (int lhs, Key rhs) const - { return lhs < rhs.m_data; } -}; - -struct KeyCmpPtr -{ - bool operator () (Key const volatile *lhs, Key const volatile *rhs) const - { return (*lhs).m_data < (*rhs).m_data; } - - bool operator () (Key const volatile *lhs, int rhs) const - { return (*lhs).m_data < rhs; } - - bool operator () (int lhs, Key const volatile *rhs) const - { return lhs < (*rhs).m_data; } -}; - -void MapTest::template_methods() -{ -#if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION) - { - typedef map<Key, int, KeyCmp> Container; - typedef Container::value_type value; - Container cont; - cont.insert(value(Key(1), 1)); - cont.insert(value(Key(2), 2)); - cont.insert(value(Key(3), 3)); - cont.insert(value(Key(4), 4)); - - CPPUNIT_ASSERT( cont.count(Key(1)) == 1 ); - CPPUNIT_ASSERT( cont.count(1) == 1 ); - CPPUNIT_ASSERT( cont.count(5) == 0 ); - - CPPUNIT_ASSERT( cont.find(2) != cont.end() ); - CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() ); - CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() ); - CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) ); - - Container const& ccont = cont; - CPPUNIT_ASSERT( ccont.find(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) ); - } - - { - typedef map<Key*, int, KeyCmpPtr> Container; - typedef Container::value_type value; - Container cont; - Key key1(1), key2(2), key3(3), key4(4); - cont.insert(value(&key1, 1)); - cont.insert(value(&key2, 2)); - cont.insert(value(&key3, 3)); - cont.insert(value(&key4, 4)); - - CPPUNIT_ASSERT( cont.count(1) == 1 ); - CPPUNIT_ASSERT( cont.count(5) == 0 ); - - CPPUNIT_ASSERT( cont.find(2) != cont.end() ); - CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() ); - CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() ); - CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) ); - - Container const& ccont = cont; - CPPUNIT_ASSERT( ccont.find(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) ); - } - { - typedef multimap<Key, int, KeyCmp> Container; - typedef Container::value_type value; - Container cont; - cont.insert(value(Key(1), 1)); - cont.insert(value(Key(2), 2)); - cont.insert(value(Key(3), 3)); - cont.insert(value(Key(4), 4)); - - CPPUNIT_ASSERT( cont.count(Key(1)) == 1 ); - CPPUNIT_ASSERT( cont.count(1) == 1 ); - CPPUNIT_ASSERT( cont.count(5) == 0 ); - - CPPUNIT_ASSERT( cont.find(2) != cont.end() ); - CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() ); - CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() ); - CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) ); - - Container const& ccont = cont; - CPPUNIT_ASSERT( ccont.find(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) ); - } - - { - typedef multimap<Key const volatile*, int, KeyCmpPtr> Container; - typedef Container::value_type value; - Container cont; - Key key1(1), key2(2), key3(3), key4(4); - cont.insert(value(&key1, 1)); - cont.insert(value(&key2, 2)); - cont.insert(value(&key3, 3)); - cont.insert(value(&key4, 4)); - - CPPUNIT_ASSERT( cont.count(1) == 1 ); - CPPUNIT_ASSERT( cont.count(5) == 0 ); - - CPPUNIT_ASSERT( cont.find(2) != cont.end() ); - CPPUNIT_ASSERT( cont.lower_bound(2) != cont.end() ); - CPPUNIT_ASSERT( cont.upper_bound(2) != cont.end() ); - CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) ); - - Container const& ccont = cont; - CPPUNIT_ASSERT( ccont.find(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.lower_bound(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.upper_bound(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) ); - } -#endif -} - -#if !defined (STLPORT) || \ - !defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) -# if !defined (__DMC__) -/* Simple compilation test: Check that nested types like iterator - * can be access even if type used to instanciate container is not - * yet completely defined. - */ -class IncompleteClass -{ - map<IncompleteClass, IncompleteClass> instances; - typedef map<IncompleteClass, IncompleteClass>::iterator it; - multimap<IncompleteClass, IncompleteClass> minstances; - typedef multimap<IncompleteClass, IncompleteClass>::iterator mit; -}; -# endif -#endif diff --git a/test/unit/math_aux.h b/test/unit/math_aux.h deleted file mode 100644 index c1291af..0000000 --- a/test/unit/math_aux.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __MATH_AUX_H -#define __MATH_AUX_H - -#include <limits> - -#undef __STD -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -# define __STD std:: -#else -# define __STD -#endif - -/* - * This function is not only used to compare floating point values with a tolerance, - * it also leads to ambiguity problems if the called functions do not have the - * right prototype. - */ -template <class _Tp> -bool are_equals(_Tp val, _Tp ref) { - if (val < ref) { - return (ref - val) <= __STD numeric_limits<_Tp>::epsilon(); - } - else { - return (val - ref) <= __STD numeric_limits<_Tp>::epsilon(); - } -} - -#undef __STD - -#endif // __MATH_AUX_H diff --git a/test/unit/math_header_test.c b/test/unit/math_header_test.c deleted file mode 100644 index 9557496..0000000 --- a/test/unit/math_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <math.h> diff --git a/test/unit/max_test.cpp b/test/unit/max_test.cpp deleted file mode 100644 index d8ab006..0000000 --- a/test/unit/max_test.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class MaxTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(MaxTest); - CPPUNIT_TEST(max1); - CPPUNIT_TEST(max2); - CPPUNIT_TEST(maxelem1); - CPPUNIT_TEST(maxelem2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void max1(); - void max2(); - void maxelem1(); - void maxelem2(); - - static bool str_compare(const char* a_, const char* b_) - { return strcmp(a_, b_) < 0 ? 1 : 0; } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MaxTest); - -// -// tests implementation -// -void MaxTest::max1() -{ - int r = max(42, 100); - CPPUNIT_ASSERT( r == 100 ); - - int t = max(++r, 0); - CPPUNIT_ASSERT( t == 101 ); -} -void MaxTest::max2() -{ - const char* r = max((const char*)"shoe", (const char*)"shine", str_compare); - CPPUNIT_ASSERT(!strcmp(r, "shoe")); -} -void MaxTest::maxelem1() -{ - int numbers[6] = { 4, 10, 56, 11, -42, 19 }; - - int* r = max_element((int*)numbers, (int*)numbers + 6); - CPPUNIT_ASSERT(*r==56); -} -void MaxTest::maxelem2() -{ - const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" }; - - const unsigned namesCt = sizeof(names) / sizeof(names[0]); - const char** r = max_element((const char**)names, (const char**)names + namesCt, str_compare); - CPPUNIT_ASSERT(!strcmp(*r, "Todd")); -} diff --git a/test/unit/memory_header_test.cpp b/test/unit/memory_header_test.cpp deleted file mode 100644 index afd9f05..0000000 --- a/test/unit/memory_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <memory> diff --git a/test/unit/memory_test.cpp b/test/unit/memory_test.cpp deleted file mode 100644 index a117109..0000000 --- a/test/unit/memory_test.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include <memory> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class MemoryTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(MemoryTest); -#if defined (_STLP_MSVC) && (_STLP_MSVC < 1310) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(auto_ptr_test); - CPPUNIT_TEST_SUITE_END(); - -protected: - void auto_ptr_test(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MemoryTest); - -#if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1310) -auto_ptr<int> CreateAutoPtr(int val) -{ return auto_ptr<int>(new int(val)); } - -bool CheckEquality(auto_ptr<int> pint, int val) -{ return *pint == val; } -#endif - -// -// tests implementation -// -void MemoryTest::auto_ptr_test() -{ -#if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1310) - { - auto_ptr<int> pint(new int(1)); - CPPUNIT_ASSERT( *pint == 1 ); - *pint = 2; - CPPUNIT_ASSERT( *pint == 2 ); - } - - { - auto_ptr<int> pint(CreateAutoPtr(3)); - CPPUNIT_ASSERT( *pint == 3 ); - CPPUNIT_ASSERT( CheckEquality(pint, 3) ); - } - - { - auto_ptr<const int> pint(new int(2)); - CPPUNIT_ASSERT( *pint == 2 ); - } - { - auto_ptr<volatile int> pint(new int(2)); - CPPUNIT_ASSERT( *pint == 2 ); - } - { - auto_ptr<const volatile int> pint(new int(2)); - CPPUNIT_ASSERT( *pint == 2 ); - } -#endif -} diff --git a/test/unit/merge_test.cpp b/test/unit/merge_test.cpp deleted file mode 100644 index 7435b8f..0000000 --- a/test/unit/merge_test.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> -#include <numeric> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class MergeTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(MergeTest); - CPPUNIT_TEST(merge0); - CPPUNIT_TEST(merge1); - CPPUNIT_TEST(merge2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void merge0(); - void merge1(); - void merge2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MergeTest); - -// -// tests implementation -// -void MergeTest::merge0() -{ - int numbers1[5] = { 1, 6, 13, 25, 101 }; - int numbers2[5] = {-5, 26, 36, 46, 99 }; - - int result[10]; - merge((int*)numbers1, (int*)numbers1 + 5, (int*)numbers2, (int*)numbers2 + 5, (int*)result); - - CPPUNIT_ASSERT(result[0]==-5); - CPPUNIT_ASSERT(result[1]==1); - CPPUNIT_ASSERT(result[2]==6); - CPPUNIT_ASSERT(result[3]==13); - CPPUNIT_ASSERT(result[4]==25); - CPPUNIT_ASSERT(result[5]==26); - CPPUNIT_ASSERT(result[6]==36); - CPPUNIT_ASSERT(result[7]==46); - CPPUNIT_ASSERT(result[8]==99); - CPPUNIT_ASSERT(result[9]==101); -} -void MergeTest::merge1() -{ - vector<int> v1(5); - vector<int> v2(v1.size()); - __iota(v1.begin(), v1.end(), 0); - __iota(v2.begin(), v2.end(), 3); - - vector <int> result(v1.size() + v2.size()); - merge(v1.begin(), v1.end(), v2.begin(), v2.end(), result.begin()); - - CPPUNIT_ASSERT(result[0]==0); - CPPUNIT_ASSERT(result[1]==1); - CPPUNIT_ASSERT(result[2]==2); - CPPUNIT_ASSERT(result[3]==3); - CPPUNIT_ASSERT(result[4]==3); - CPPUNIT_ASSERT(result[5]==4); - CPPUNIT_ASSERT(result[6]==4); - CPPUNIT_ASSERT(result[7]==5); - CPPUNIT_ASSERT(result[8]==6); - CPPUNIT_ASSERT(result[9]==7); - -} -void MergeTest::merge2() -{ - vector <int> v1(5); - vector <int> v2(v1.size()); - for (int i = 0; (size_t)i < v1.size(); ++i) { - v1[i] = 10 - i; - v2[i] = 7 - i; - } - vector<int> result(v1.size() + v2.size()); - merge(v1.begin(), v1.end(), v2.begin(), v2.end(), result.begin(), greater<int>() ); - - CPPUNIT_ASSERT(result[0]==10); - CPPUNIT_ASSERT(result[1]==9); - CPPUNIT_ASSERT(result[2]==8); - CPPUNIT_ASSERT(result[3]==7); - CPPUNIT_ASSERT(result[4]==7); - CPPUNIT_ASSERT(result[5]==6); - CPPUNIT_ASSERT(result[6]==6); - CPPUNIT_ASSERT(result[7]==5); - CPPUNIT_ASSERT(result[8]==4); - CPPUNIT_ASSERT(result[9]==3); -} diff --git a/test/unit/messages_facets_test.cpp b/test/unit/messages_facets_test.cpp deleted file mode 100644 index 610bbaa..0000000 --- a/test/unit/messages_facets_test.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "locale_test.h" - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <locale> -# include <stdexcept> - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -// -// tests implementation -// -void LocaleTest::messages_by_name() -{ - /* - * Check of the 22.1.1.2.7 standard point. Construction of a locale - * instance from a null pointer or an unknown name should result in - * a runtime_error exception. - */ -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new messages_byname<char>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new messages_byname<char>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - /* - try { - locale loc(locale::classic(), new messages_byname<char>("")); - CPPUNIT_FAIL; - } - catch (runtime_error const& e) { - CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - */ - -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new messages_byname<wchar_t>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new messages_byname<wchar_t>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif -# endif -} - -#endif diff --git a/test/unit/mfunptr_test.cpp b/test/unit/mfunptr_test.cpp deleted file mode 100644 index d29d598..0000000 --- a/test/unit/mfunptr_test.cpp +++ /dev/null @@ -1,230 +0,0 @@ -#include <functional> -#include <memory> -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class MemFunPtrTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(MemFunPtrTest); - CPPUNIT_TEST(mem_ptr_fun); -#if defined (STLPORT) && !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - //This test require partial template specialization feature to avoid the - //reference to reference problem. No workaround yet for limited compilers. - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(find); - CPPUNIT_TEST_SUITE_END(); - -protected: - // compile test not neccessary to run but... - void mem_ptr_fun(); - void find(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MemFunPtrTest); - -#if defined(_STLP_DONT_RETURN_VOID) && (defined(_STLP_NO_MEMBER_TEMPLATE_CLASSES) && defined(_STLP_NO_CLASS_PARTIAL_SPECIALIZATION)) -# define _STLP_DONT_TEST_RETURN_VOID -#endif -//else there is no workaround for the return void bug - -struct S1 { } s1; -struct S2 { } s2; - -int f1(S1&); -int f2(S1&, S2&); -int f1c(const S1&); -int f2c(const S1&, const S2&); - -void vf1(S1&); -void vf2(S1&, S2&); -void vf1c(const S1&); -void vf2c(const S1&, const S2&); - -class Class { -public: - int f0(); - int f1(const S1&); - - void vf0(); - void vf1(const S1&); - - int f0c() const; - int f1c(const S1&) const; - - void vf0c() const; - void vf1c(const S1&) const; -}; - -// -// tests implementation -// -void MemFunPtrTest::mem_ptr_fun() -{ - Class obj; - const Class& objc = obj; - - // ptr_fun - - ptr_fun(f1)(s1); - ptr_fun(f2)(s1, s2); - - ptr_fun(f1c)(s1); - ptr_fun(f2c)(s1, s2); - -#ifndef _STLP_DONT_TEST_RETURN_VOID - ptr_fun(vf1)(s1); - ptr_fun(vf2)(s1, s2); - - ptr_fun(vf1c)(s1); - ptr_fun(vf2c)(s1, s2); -#endif /* _STLP_DONT_TEST_RETURN_VOID */ - - // mem_fun - - mem_fun(&Class::f0)(&obj); - mem_fun(&Class::f1)(&obj, s1); - -#ifndef _STLP_DONT_TEST_RETURN_VOID - mem_fun(&Class::vf0)(&obj); - mem_fun(&Class::vf1)(&obj, s1); -#endif /* _STLP_DONT_TEST_RETURN_VOID */ - - // mem_fun (const) - - mem_fun(&Class::f0c)(&objc); - mem_fun(&Class::f1c)(&objc, s1); - -#ifndef _STLP_DONT_TEST_RETURN_VOID - mem_fun(&Class::vf0c)(&objc); - mem_fun(&Class::vf1c)(&objc, s1); -#endif /* _STLP_DONT_TEST_RETURN_VOID */ - - // mem_fun_ref - - mem_fun_ref(&Class::f0)(obj); - mem_fun_ref(&Class::f1)(obj, s1); - -#ifndef _STLP_DONT_TEST_RETURN_VOID - mem_fun_ref(&Class::vf0)(obj); - mem_fun_ref(&Class::vf1)(obj, s1); -#endif /* _STLP_DONT_TEST_RETURN_VOID */ - - // mem_fun_ref (const) - mem_fun_ref(&Class::f0c)(objc); - mem_fun_ref(&Class::f1c)(objc, s1); - -#ifndef _STLP_DONT_TEST_RETURN_VOID - mem_fun_ref(&Class::vf0c)(objc); - mem_fun_ref(&Class::vf1c)(objc, s1); -#endif /* _STLP_DONT_TEST_RETURN_VOID */ -} -int f1(S1&) -{return 1;} - -int f2(S1&, S2&) -{return 2;} - -int f1c(const S1&) -{return 1;} - -int f2c(const S1&, const S2&) -{return 2;} - -void vf1(S1&) -{} - -void vf2(S1&, S2&) -{} - -void vf1c(const S1&) -{} - -void vf2c(const S1&, const S2&) -{} - -int Class::f0() -{return 0;} - -int Class::f1(const S1&) -{return 1;} - -void Class::vf0() -{} - -void Class::vf1(const S1&) -{} - -int Class::f0c() const -{return 0;} - -int Class::f1c(const S1&) const -{return 1;} - -void Class::vf0c() const -{} - -void Class::vf1c(const S1&) const -{} - -struct V { - public: - V(int _v) : - v(_v) - { } - - bool f( int _v ) const { return (v == _v); } - - int v; -#if defined (__DMC__) - V(){} -#endif -}; - -void MemFunPtrTest::find() -{ -#if !defined (STLPORT) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - vector<V> v; - - v.push_back( V(1) ); - v.push_back( V(2) ); - v.push_back( V(3) ); - - // step-by-step complication of work for compiler: - - // step 1: - const_mem_fun1_ref_t<bool,V,int> pmf = mem_fun_ref( &V::f ); - binder2nd<const_mem_fun1_ref_t<bool,V,int> > b(pmf, 2); - vector<V>::iterator i = find_if( v.begin(), v.end(), b ); - CPPUNIT_ASSERT(i != v.end()); - CPPUNIT_ASSERT(i->v == 2); - - // step 2, just check that compiler understand what pass to bind2nd: - binder2nd<const_mem_fun1_ref_t<bool,V,int> > b2 = bind2nd( pmf, 2 ); - - // step 3, the same as step 1, but more intellect from compiler required: - binder2nd<const_mem_fun1_ref_t<bool,V,int> > b3 = bind2nd( mem_fun_ref( &V::f ), 2 ); - - vector<V>::iterator j = find_if( v.begin(), v.end(), b3 ); - CPPUNIT_ASSERT(j != v.end()); - CPPUNIT_ASSERT(j->v == 2); - - // step 4, more brief, more complex: - vector<V>::iterator k = find_if( v.begin(), v.end(), bind2nd( mem_fun_ref( &V::f ), 2 ) ); - CPPUNIT_ASSERT(k != v.end()); - CPPUNIT_ASSERT(k->v == 2); -#endif -} - -#ifdef _STLP_DONT_TEST_RETURN_VOID -# undef _STLP_DONT_TEST_RETURN_VOID -#endif diff --git a/test/unit/min_test.cpp b/test/unit/min_test.cpp deleted file mode 100644 index 2f45ade..0000000 --- a/test/unit/min_test.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class MinTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(MinTest); - CPPUNIT_TEST(min1); - CPPUNIT_TEST(min2); - CPPUNIT_TEST(minelem1); - CPPUNIT_TEST(minelem2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void min1(); - void min2(); - void minelem1(); - void minelem2(); - static bool str_compare(const char* a_, const char* b_) - { return strcmp(a_, b_) < 0 ? 1 : 0; } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MinTest); - -// -// tests implementation -// -void MinTest::min1() -{ - int r = min(42, 100); - CPPUNIT_ASSERT( r == 42 ); - - r = min(--r, r); - CPPUNIT_ASSERT( r == 41 ); -} -void MinTest::min2() -{ - const char* r = min((const char*)"shoe", (const char*)"shine", str_compare); - CPPUNIT_ASSERT(!strcmp(r, "shine")); -} -void MinTest::minelem1() -{ - int numbers[6] = { -10, 15, -100, 36, -242, 42 }; - int* r = min_element((int*)numbers, (int*)numbers + 6); - CPPUNIT_ASSERT(*r==-242); -} -void MinTest::minelem2() -{ - const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" }; - - const unsigned namesCt = sizeof(names) / sizeof(names[0]); - const char** r = min_element((const char**)names, (const char**)names + namesCt, str_compare); - CPPUNIT_ASSERT(!strcmp(*r, "Brett")); -} diff --git a/test/unit/mismatch_test.cpp b/test/unit/mismatch_test.cpp deleted file mode 100644 index 13f7cd0..0000000 --- a/test/unit/mismatch_test.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include <numeric> -#include <vector> -#include <algorithm> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class MismatchTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(MismatchTest); - CPPUNIT_TEST(mismatch0); - CPPUNIT_TEST(mismatch1); - CPPUNIT_TEST(mismatch2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void mismatch0(); - void mismatch1(); - void mismatch2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MismatchTest); - -// -// tests implementation -// -bool str_equal(const char* a_, const char* b_) -{ - return strcmp(a_, b_) == 0 ? 1 : 0; -} -void MismatchTest::mismatch0() -{ - int n1[5] = { 1, 2, 3, 4, 5 }; - int n2[5] = { 1, 2, 3, 4, 5 }; - int n3[5] = { 1, 2, 3, 2, 1 }; - - pair <int*, int*> result = mismatch((int*)n1, (int*)n1 + 5, (int*)n2); - CPPUNIT_ASSERT(result.first ==(n1 + 5) && result.second ==(n2 + 5)); - - result = mismatch((int*)n1, (int*)n1 + 5, (int*)n3); - CPPUNIT_ASSERT(!(result.first ==(n1 + 5) && result.second ==(n3 + 5))); - CPPUNIT_ASSERT((result.first - n1)==3); -} -void MismatchTest::mismatch1() -{ - typedef vector<int> IntVec; - IntVec v1(10); - __iota(v1.begin(), v1.end(), 0); - IntVec v2(v1); - - pair <IntVec::iterator, IntVec::iterator> result = mismatch(v1.begin(), v1.end(), v2.begin()); - - CPPUNIT_ASSERT(result.first == v1.end() && result.second == v2.end()); - - v2[v2.size()/2] = 42; - result = mismatch(v1.begin(), v1.end(), v2.begin()); - CPPUNIT_ASSERT(!(result.first == v1.end() && result.second == v2.end())); - CPPUNIT_ASSERT((result.first - v1.begin())==5); -} -void MismatchTest::mismatch2() -{ - const unsigned size = 5; - char const* n1[size] = { "Brett", "Graham", "Jack", "Mike", "Todd" }; - - char const* n2[size]; - copy(n1, n1 + 5, (char const**)n2); - pair <char const**, char const**> result = mismatch((char const**)n1, (char const**)n1 + size, (char const**)n2, str_equal); - - CPPUNIT_ASSERT(result.first == n1 + size && result.second == n2 + size); - - n2[2] = "QED"; - result = mismatch((char const**)n1, (char const**)n1 + size, (char const**)n2, str_equal); - CPPUNIT_ASSERT(!(result.first == n2 + size && result.second == n2 + size)); - CPPUNIT_ASSERT((result.first - n1)==2); -} diff --git a/test/unit/modulus_test.cpp b/test/unit/modulus_test.cpp deleted file mode 100644 index 2fab979..0000000 --- a/test/unit/modulus_test.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class ModulusTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ModulusTest); - CPPUNIT_TEST(modulus0); - CPPUNIT_TEST_SUITE_END(); - -protected: - void modulus0(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ModulusTest); - -// -// tests implementation -// -void ModulusTest::modulus0() -{ - int input1 [4] = { 6, 8, 10, 2 }; - int input2 [4] = { 4, 2, 11, 3 }; - - int output [4]; - - transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, modulus<int>()); - CPPUNIT_ASSERT(output[0]==2); - CPPUNIT_ASSERT(output[1]==0); - CPPUNIT_ASSERT(output[2]==10); - CPPUNIT_ASSERT(output[3]==2); -} diff --git a/test/unit/money_facets_test.cpp b/test/unit/money_facets_test.cpp deleted file mode 100644 index 5ace770..0000000 --- a/test/unit/money_facets_test.cpp +++ /dev/null @@ -1,655 +0,0 @@ -#include "locale_test.h" - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <locale> -# include <sstream> -# include <stdexcept> - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -struct ref_monetary { - const char *name; - const char *money_int_prefix; - const char *money_int_prefix_old; - const char *money_prefix; - const char *money_suffix; - const char *money_decimal_point; - const char *money_thousands_sep; -}; - -static const ref_monetary tested_locales[] = { -//{ name, money_int_prefix, money_int_prefix_old, money_prefix, money_suffix, money_decimal_point, money_thousands_sep}, -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - { "fr_FR", "EUR ", "FRF ", "", "", ",", -# if defined (WIN32) || defined (_WIN32) - "\xa0" }, -# else - " " }, -# endif - { "ru_RU.koi8r", "RUB ", "RUR ", "", "\xd2\xd5\xc2", ".", " " }, - { "en_GB", "GBP ", "", "\xa3", "", ".", "," }, - { "en_US", "USD ", "", "$", "", ".", "," }, -# endif - { "C", "", "", "", "", " ", " " }, -}; - - -const ref_monetary* LocaleTest::_get_ref_monetary(size_t i) -{ - if (i < sizeof(tested_locales) / sizeof(tested_locales[0])) { - return tested_locales + i; - } - return 0; -} - -const char* LocaleTest::_get_ref_monetary_name(const ref_monetary* _ref) -{ - return _ref->name; -} - -void LocaleTest::_money_put_get( const locale& loc, const ref_monetary* rl ) -{ - _money_put_get2(loc, loc, rl); -} - -void LocaleTest::_money_put_get2( const locale& loc, const locale& streamLoc, const ref_monetary* prl ) -{ - const ref_monetary &rl = *prl; - CPPUNIT_ASSERT( has_facet<money_put<char> >(loc) ); - money_put<char> const& fmp = use_facet<money_put<char> >(loc); - CPPUNIT_ASSERT( has_facet<money_get<char> >(loc) ); - money_get<char> const& fmg = use_facet<money_get<char> >(loc); - - ostringstream ostr; - ostr.imbue(streamLoc); - ostr << showbase; - - //Check a positive value (international format) - { - string str_res; - //money_put - { - CPPUNIT_ASSERT( (has_facet<moneypunct<char, true> >(loc)) ); - moneypunct<char, true> const& intl_fmp = use_facet<moneypunct<char, true> >(loc); - - ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, true, ostr, ' ', 123456); - - CPPUNIT_ASSERT( !res.failed() ); - str_res = ostr.str(); - //CPPUNIT_MESSAGE(str_res.c_str()); - - size_t fieldIndex = 0; - size_t index = 0; - - //On a positive value we skip the sign field if exists: - if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) { - ++fieldIndex; - } - // international currency abbreviation, if it is before value - - /* - * int_curr_symbol - * - * The international currency symbol. The operand is a four-character - * string, with the first three characters containing the alphabetic - * international currency symbol in accordance with those specified - * in the ISO 4217 specification. The fourth character is the character used - * to separate the international currency symbol from the monetary quantity. - * - * (http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html) - */ - string::size_type p = strlen( rl.money_int_prefix ); - if (p != 0) { - CPPUNIT_ASSERT( intl_fmp.pos_format().field[fieldIndex] == money_base::symbol ); - string::size_type p_old = strlen( rl.money_int_prefix_old ); - CPPUNIT_ASSERT( (str_res.substr(index, p) == rl.money_int_prefix) || - ((p_old != 0) && - (str_res.substr(index, p_old) == rl.money_int_prefix_old)) ); - if ( str_res.substr(index, p) == rl.money_int_prefix ) { - index += p; - } else { - index += p_old; - } - ++fieldIndex; - } - - // space after currency - if (intl_fmp.pos_format().field[fieldIndex] == money_base::space || - intl_fmp.pos_format().field[fieldIndex] == money_base::none) { - // iternational currency symobol has four chars, one of these chars - // is separator, so if format has space on this place, it should - // be skipped. - ++fieldIndex; - } - - // sign - if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) { - ++fieldIndex; - } - - // value - CPPUNIT_ASSERT( str_res[index++] == '1' ); - if (!intl_fmp.grouping().empty()) { - CPPUNIT_ASSERT( str_res[index++] == /* intl_fmp.thousands_sep() */ *rl.money_thousands_sep ); - } - CPPUNIT_ASSERT( str_res[index++] == '2' ); - CPPUNIT_ASSERT( str_res[index++] == '3' ); - CPPUNIT_ASSERT( str_res[index++] == '4' ); - if (intl_fmp.frac_digits() != 0) { - CPPUNIT_ASSERT( str_res[index++] == /* intl_fmp.decimal_point() */ *rl.money_decimal_point ); - } - CPPUNIT_ASSERT( str_res[index++] == '5' ); - CPPUNIT_ASSERT( str_res[index++] == '6' ); - ++fieldIndex; - - // sign - if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) { - ++fieldIndex; - } - - // space - if (intl_fmp.pos_format().field[fieldIndex] == money_base::space ) { - CPPUNIT_ASSERT( str_res[index++] == ' ' ); - ++fieldIndex; - } - - // sign - if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) { - ++fieldIndex; - } - - //as space cannot be last the only left format can be none: - while ( fieldIndex < 3 ) { - CPPUNIT_ASSERT( intl_fmp.pos_format().field[fieldIndex] == money_base::none ); - ++fieldIndex; - } - } - - //money_get - { - ios_base::iostate err = ios_base::goodbit; - string digits; - - istringstream istr(str_res); - ostr.str( "" ); - ostr.clear(); - fmg.get(istr, istreambuf_iterator<char, char_traits<char> >(), true, ostr, err, digits); - CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 ); - CPPUNIT_ASSERT( digits == "123456" ); - } - } - - ostr.str(""); - //Check a negative value (national format) - { - CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) ); - moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc); - string str_res; - //Check money_put - { - ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', -123456); - - CPPUNIT_ASSERT( !res.failed() ); - str_res = ostr.str(); - //CPPUNIT_MESSAGE(str_res.c_str()); - - size_t fieldIndex = 0; - size_t index = 0; - - if (dom_fmp.neg_format().field[fieldIndex] == money_base::sign) { - CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.negative_sign().size()) == dom_fmp.negative_sign() ); - index += dom_fmp.negative_sign().size(); - ++fieldIndex; - } - - string::size_type p = strlen( rl.money_prefix ); - if (p != 0) { - CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix ); - index += p; - ++fieldIndex; - } - if (dom_fmp.neg_format().field[fieldIndex] == money_base::space || - dom_fmp.neg_format().field[fieldIndex] == money_base::none) { - CPPUNIT_ASSERT( str_res[index++] == ' ' ); - ++fieldIndex; - } - - CPPUNIT_ASSERT( str_res[index++] == '1' ); - if (!dom_fmp.grouping().empty()) { - CPPUNIT_ASSERT( str_res[index++] == dom_fmp.thousands_sep() ); - } - CPPUNIT_ASSERT( str_res[index++] == '2' ); - CPPUNIT_ASSERT( str_res[index++] == '3' ); - CPPUNIT_ASSERT( str_res[index++] == '4' ); - if (dom_fmp.frac_digits() != 0) { - CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() ); - } - CPPUNIT_ASSERT( str_res[index++] == '5' ); - CPPUNIT_ASSERT( str_res[index++] == '6' ); - ++fieldIndex; - - //space cannot be last: - if ((fieldIndex < 3) && - dom_fmp.neg_format().field[fieldIndex] == money_base::space) { - CPPUNIT_ASSERT( str_res[index++] == ' ' ); - ++fieldIndex; - } - - if (fieldIndex == 3) { - //If none is last we should not add anything to the resulting string: - if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) { - CPPUNIT_ASSERT( index == str_res.size() ); - } else { - CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol ); - CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix ); - } - } - } - - //money_get - { - ios_base::iostate err = ios_base::goodbit; -# if defined (STLPORT) - _STLP_LONGEST_FLOAT_TYPE val; -# else - long double val; -# endif - - istringstream istr(str_res); - fmg.get(istr, istreambuf_iterator<char, char_traits<char> >(), false, ostr, err, val); - CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 ); - if (dom_fmp.negative_sign().empty()) { - //Without negative sign there is no way to guess the resulting amount sign ("C" locale): - CPPUNIT_ASSERT( val == 123456 ); - } - else { - CPPUNIT_ASSERT( val == -123456 ); - } - } - } -} - - -// Test for bug in case when number of digits in value less then number -// of digits in fraction. I.e. '9' should be printed as '0.09', -// if x.frac_digits() == 2. - -void LocaleTest::_money_put_X_bug( const locale& loc, const ref_monetary* prl ) -{ - const ref_monetary &rl = *prl; - CPPUNIT_ASSERT( has_facet<money_put<char> >(loc) ); - money_put<char> const& fmp = use_facet<money_put<char> >(loc); - - ostringstream ostr; - ostr.imbue(loc); - ostr << showbase; - - // ostr.str(""); - // Check value with one decimal digit: - { - CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) ); - moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc); - string str_res; - // Check money_put - { - ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', 9); - - CPPUNIT_ASSERT( !res.failed() ); - str_res = ostr.str(); - - size_t fieldIndex = 0; - size_t index = 0; - - if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) { - CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() ); - index += dom_fmp.positive_sign().size(); - ++fieldIndex; - } - - string::size_type p = strlen( rl.money_prefix ); - if (p != 0) { - CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix ); - index += p; - ++fieldIndex; - } - if (dom_fmp.neg_format().field[fieldIndex] == money_base::space || - dom_fmp.neg_format().field[fieldIndex] == money_base::none) { - CPPUNIT_ASSERT( str_res[index++] == ' ' ); - ++fieldIndex; - } - if (dom_fmp.frac_digits() != 0) { - CPPUNIT_ASSERT( str_res[index++] == '0' ); - CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() ); - for ( int fd = 1; fd < dom_fmp.frac_digits(); ++fd ) { - CPPUNIT_ASSERT( str_res[index++] == '0' ); - } - } - CPPUNIT_ASSERT( str_res[index++] == '9' ); - ++fieldIndex; - - //space cannot be last: - if ((fieldIndex < 3) && - dom_fmp.neg_format().field[fieldIndex] == money_base::space) { - CPPUNIT_ASSERT( str_res[index++] == ' ' ); - ++fieldIndex; - } - - if (fieldIndex == 3) { - //If none is last we should not add anything to the resulting string: - if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) { - CPPUNIT_ASSERT( index == str_res.size() ); - } else { - CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol ); - CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix ); - } - } - } - } - - ostr.str(""); - // Check value with two decimal digit: - { - CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) ); - moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc); - string str_res; - // Check money_put - { - ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', 90); - - CPPUNIT_ASSERT( !res.failed() ); - str_res = ostr.str(); - - size_t fieldIndex = 0; - size_t index = 0; - - if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) { - CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() ); - index += dom_fmp.positive_sign().size(); - ++fieldIndex; - } - - string::size_type p = strlen( rl.money_prefix ); - if (p != 0) { - CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix ); - index += p; - ++fieldIndex; - } - if (dom_fmp.neg_format().field[fieldIndex] == money_base::space || - dom_fmp.neg_format().field[fieldIndex] == money_base::none) { - CPPUNIT_ASSERT( str_res[index++] == ' ' ); - ++fieldIndex; - } - if (dom_fmp.frac_digits() != 0) { - CPPUNIT_ASSERT( str_res[index++] == '0' ); - CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() ); - for ( int fd = 1; fd < dom_fmp.frac_digits() - 1; ++fd ) { - CPPUNIT_ASSERT( str_res[index++] == '0' ); - } - } - CPPUNIT_ASSERT( str_res[index++] == '9' ); - if (dom_fmp.frac_digits() != 0) { - CPPUNIT_ASSERT( str_res[index++] == '0' ); - } - ++fieldIndex; - - //space cannot be last: - if ((fieldIndex < 3) && - dom_fmp.neg_format().field[fieldIndex] == money_base::space) { - CPPUNIT_ASSERT( str_res[index++] == ' ' ); - ++fieldIndex; - } - - if (fieldIndex == 3) { - //If none is last we should not add anything to the resulting string: - if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) { - CPPUNIT_ASSERT( index == str_res.size() ); - } else { - CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol ); - CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix ); - } - } - } - } -} - -typedef void (LocaleTest::*_Test) (const locale&, const ref_monetary*); -static void test_supported_locale(LocaleTest& inst, _Test __test) { - size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]); - for (size_t i = 0; i < n; ++i) { - locale loc; -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try -# endif - { - locale tmp(tested_locales[i].name); - loc = tmp; - } -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - catch (runtime_error const&) { - //This locale is not supported. - continue; - } -# endif - CPPUNIT_MESSAGE( loc.name().c_str() ); - (inst.*__test)(loc, tested_locales + i); - - { - locale tmp(locale::classic(), tested_locales[i].name, locale::monetary); - loc = tmp; - } - (inst.*__test)(loc, tested_locales + i); - - { - locale tmp0(locale::classic(), new moneypunct_byname<char, true>(tested_locales[i].name)); - locale tmp1(tmp0, new moneypunct_byname<char, false>(tested_locales[i].name)); - loc = tmp1; - } - (inst.*__test)(loc, tested_locales + i); - } -} - -void LocaleTest::money_put_get() -{ test_supported_locale(*this, &LocaleTest::_money_put_get); } - -void LocaleTest::money_put_X_bug() -{ test_supported_locale(*this, &LocaleTest::_money_put_X_bug); } - -void LocaleTest::moneypunct_by_name() -{ - /* - * Check of the 22.1.1.2.7 standard point. Construction of a locale - * instance from a null pointer or an unknown name should result in - * a runtime_error exception. - */ -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new moneypunct_byname<char, true>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new moneypunct_byname<char, true>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - string veryLongFacetName("LC_MONETARY="); - veryLongFacetName.append(512, '?'); - locale loc(locale::classic(), new moneypunct_byname<char, true>(veryLongFacetName.c_str())); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new moneypunct_byname<char, false>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new moneypunct_byname<char, false>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - string veryLongFacetName("LC_MONETARY="); - veryLongFacetName.append(512, '?'); - locale loc(locale::classic(), new moneypunct_byname<char, false>(veryLongFacetName.c_str())); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new moneypunct_byname<char, false>("C")); - moneypunct<char, false> const& cfacet_byname = use_facet<moneypunct<char, false> >(loc); - moneypunct<char, false> const& cfacet = use_facet<moneypunct<char, false> >(locale::classic()); - - money_base::pattern cp = cfacet.pos_format(); - money_base::pattern cp_bn = cfacet_byname.pos_format(); - CPPUNIT_CHECK( cp_bn.field[0] == cp.field[0] ); - CPPUNIT_CHECK( cp_bn.field[1] == cp.field[1] ); - CPPUNIT_CHECK( cp_bn.field[2] == cp.field[2] ); - CPPUNIT_CHECK( cp_bn.field[3] == cp.field[3] ); - - CPPUNIT_CHECK( cfacet_byname.frac_digits() == cfacet.frac_digits() ); - if (cfacet_byname.frac_digits() != 0) - CPPUNIT_CHECK( cfacet_byname.decimal_point() == cfacet.decimal_point() ); - CPPUNIT_CHECK( cfacet_byname.grouping() == cfacet.grouping() ); - if (!cfacet_byname.grouping().empty()) - CPPUNIT_CHECK( cfacet_byname.thousands_sep() == cfacet.thousands_sep() ); - CPPUNIT_CHECK( cfacet_byname.positive_sign() == cfacet.positive_sign() ); - CPPUNIT_CHECK( cfacet_byname.negative_sign() == cfacet.negative_sign() ); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new moneypunct_byname<char, true>("C")); - moneypunct<char, true> const& cfacet_byname = use_facet<moneypunct<char, true> >(loc); - moneypunct<char, true> const& cfacet = use_facet<moneypunct<char, true> >(locale::classic()); - - money_base::pattern cp = cfacet.pos_format(); - money_base::pattern cp_bn = cfacet_byname.pos_format(); - CPPUNIT_CHECK( cp_bn.field[0] == cp.field[0] ); - CPPUNIT_CHECK( cp_bn.field[1] == cp.field[1] ); - CPPUNIT_CHECK( cp_bn.field[2] == cp.field[2] ); - CPPUNIT_CHECK( cp_bn.field[3] == cp.field[3] ); - - CPPUNIT_CHECK( cfacet_byname.frac_digits() == cfacet.frac_digits() ); - if (cfacet_byname.frac_digits() != 0) - CPPUNIT_CHECK( cfacet_byname.decimal_point() == cfacet.decimal_point() ); - CPPUNIT_CHECK( cfacet_byname.grouping() == cfacet.grouping() ); - if (!cfacet_byname.grouping().empty()) - CPPUNIT_CHECK( cfacet_byname.thousands_sep() == cfacet.thousands_sep() ); - CPPUNIT_CHECK( cfacet_byname.positive_sign() == cfacet.positive_sign() ); - CPPUNIT_CHECK( cfacet_byname.negative_sign() == cfacet.negative_sign() ); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - // On platform without real localization support we should rely on the "C" locale facet. - locale loc(locale::classic(), new moneypunct_byname<char, false>("")); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new moneypunct_byname<wchar_t, true>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new moneypunct_byname<wchar_t, true>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new moneypunct_byname<wchar_t, false>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new moneypunct_byname<wchar_t, false>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif -# endif -} - -#endif diff --git a/test/unit/multiset_test.cpp b/test/unit/multiset_test.cpp deleted file mode 100644 index 3e30917..0000000 --- a/test/unit/multiset_test.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include <set> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class MultisetTest : public CPPUNIT_NS::TestCase -{ - typedef multiset<int, less<int> > mset; - - CPPUNIT_TEST_SUITE(MultisetTest); - CPPUNIT_TEST(mset1); - CPPUNIT_TEST(mset3); - CPPUNIT_TEST(mset5); - CPPUNIT_TEST_SUITE_END(); - -protected: - void mset1(); - void mset3(); - void mset5(); - - static bool less_than(int a_, int b_) - { - return a_ < b_; - } - - static bool greater_than(int a_, int b_) - { - return a_ > b_; - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(MultisetTest); - -// -// tests implementation -// -void MultisetTest::mset1() -{ - mset s; - CPPUNIT_ASSERT(s.count(42) == 0); - s.insert(42); - CPPUNIT_ASSERT(s.count(42) == 1); - s.insert(42); - CPPUNIT_ASSERT(s.count(42) == 2); - - mset::iterator i = s.find(40); - CPPUNIT_ASSERT(i == s.end()); - - i = s.find(42); - CPPUNIT_ASSERT(i != s.end()); - size_t count = s.erase(42); - CPPUNIT_ASSERT(count == 2); -} -void MultisetTest::mset3() -{ - int array [] = { 3, 6, 1, 2, 3, 2, 6, 7, 9 }; - - //Check iterator on a mutable set - mset s(array, array + 9); - mset::iterator i; - i = s.lower_bound(3); - CPPUNIT_ASSERT(*i == 3); - i = s.upper_bound(3); - CPPUNIT_ASSERT(*i == 6); - pair<mset::iterator, mset::iterator> p = s.equal_range(5); - CPPUNIT_ASSERT(*(p.first) == 6); - CPPUNIT_ASSERT(*(p.second) == 6); - - //Check const_iterator on a mutable multiset - mset::const_iterator ci; - ci = s.lower_bound(3); - CPPUNIT_ASSERT(*ci == 3); - ci = s.upper_bound(3); - CPPUNIT_ASSERT(*ci == 6); - pair<mset::const_iterator, mset::const_iterator> cp; -#ifdef _STLP_MEMBER_TEMPLATES - cp = s.equal_range(5); - CPPUNIT_ASSERT(*(cp.first) == 6); - CPPUNIT_ASSERT(*(cp.second) == 6); -#endif - - //Check const_iterator on a const multiset - mset const& crs = s; - ci = crs.lower_bound(3); - CPPUNIT_ASSERT(*ci == 3); - ci = crs.upper_bound(3); - CPPUNIT_ASSERT(*ci == 6); - cp = crs.equal_range(5); - CPPUNIT_ASSERT(*(cp.first) == 6); - CPPUNIT_ASSERT(*(cp.second) == 6); -} -void MultisetTest::mset5() -{ - int array [] = { 3, 6, 1, 9 }; - int j; - - typedef pointer_to_binary_function<int, int, bool> fn_type; - typedef multiset<int, fn_type, allocator<int> > fn_mset; - - fn_type f(less_than); - fn_mset s1(array+0, array + 4 , f ); - fn_mset::const_iterator i = s1.begin(); - for (j = 0; i != s1.end(); ++i, ++j) { - CPPUNIT_ASSERT(j != 0 || *i == 1); - CPPUNIT_ASSERT(j != 1 || *i == 3); - CPPUNIT_ASSERT(j != 2 || *i == 6); - CPPUNIT_ASSERT(j != 3 || *i == 9); - } - - fn_type g(greater_than); - fn_mset s2(array, array + 4, g); - i = s2.begin(); - for (j = 0; i != s2.end(); ++i, ++j) { - CPPUNIT_ASSERT(j != 0 || *i == 9); - CPPUNIT_ASSERT(j != 1 || *i == 6); - CPPUNIT_ASSERT(j != 2 || *i == 3); - CPPUNIT_ASSERT(j != 3 || *i == 1); - } - -} diff --git a/test/unit/mvctor_declaration_test.cpp b/test/unit/mvctor_declaration_test.cpp deleted file mode 100644 index cb6f8a3..0000000 --- a/test/unit/mvctor_declaration_test.cpp +++ /dev/null @@ -1,369 +0,0 @@ -#include <vector> -#include <algorithm> -#include <string> -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <rope> -#endif -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <slist> -#endif -#include <list> -#include <deque> -#include <set> -#include <map> -#if defined (STLPORT) -# include <unordered_set> -# include <unordered_map> -#endif -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <hash_set> -# include <hash_map> -#endif -#include <queue> -#include <stack> - -#include "mvctor_test.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# if defined (STLPORT) -using namespace std::tr1; -# endif -#endif - -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - -# if defined (__GNUC__) && defined (_STLP_USE_NAMESPACES) -// libstdc++ sometimes exposed its own __true_type in -// global namespace resulting in an ambiguity. -# define __true_type std::__true_type -# define __false_type std::__false_type -# endif - -static bool type_to_bool(__true_type) -{ return true; } -static bool type_to_bool(__false_type) -{ return false; } - -template <class _Tp> -static bool is_movable(const _Tp&) { - typedef typename __move_traits<_Tp>::implemented _MovableTp; - return type_to_bool(_MovableTp()); -} - -template <class _Tp> -static bool is_move_complete(const _Tp&) { - typedef __move_traits<_Tp> _TpMoveTraits; - typedef typename _TpMoveTraits::complete _TpMoveComplete; - return type_to_bool(_TpMoveComplete()); -} - -struct specially_allocated_struct { - bool operator < (const specially_allocated_struct&) const; -# if defined (__DMC__) // slist<_Tp,_Alloc>::remove error - bool operator==(const specially_allocated_struct&) const; -# endif -}; - -#if defined (__DMC__) -bool specially_allocated_struct::operator < (const specially_allocated_struct&) const -{ return false; } -#endif - -struct struct_with_specialized_less {}; - -# if defined (_STLP_USE_NAMESPACES) -namespace std { -# endif - _STLP_TEMPLATE_NULL - class allocator<specially_allocated_struct> { - //This allocator just represent what a STLport could do and in this - //case the STL containers implemented with it should still be movable - //but not completely as we cannot do any hypothesis on what is in this - //allocator. - public: - typedef specially_allocated_struct value_type; - typedef value_type * pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; -# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) - template <class _Tp1> struct rebind { - typedef allocator<_Tp1> other; - }; -# endif - allocator() _STLP_NOTHROW {} -# if defined (_STLP_MEMBER_TEMPLATES) - template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {} -# endif - allocator(const allocator&) _STLP_NOTHROW {} - ~allocator() _STLP_NOTHROW {} - pointer address(reference __x) const { return &__x; } - const_pointer address(const_reference __x) const { return &__x; } - pointer allocate(size_type, const void* = 0) { return 0; } - void deallocate(pointer, size_type) {} - size_type max_size() const _STLP_NOTHROW { return 0; } - void construct(pointer, const_reference) {} - void destroy(pointer) {} - }; - - _STLP_TEMPLATE_NULL - struct less<struct_with_specialized_less> { - bool operator() (struct_with_specialized_less const&, - struct_with_specialized_less const&) const; - }; - -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) -# if !defined (_STLP_NO_MOVE_SEMANTIC) -# if defined (__BORLANDC__) && (__BORLANDC__ >= 0x564) - _STLP_TEMPLATE_NULL - struct __move_traits<vector<specially_allocated_struct> > { - typedef __true_type implemented; - typedef __false_type complete; - }; - _STLP_TEMPLATE_NULL - struct __move_traits<deque<specially_allocated_struct> > { - typedef __true_type implemented; - typedef __false_type complete; - }; - _STLP_TEMPLATE_NULL - struct __move_traits<list<specially_allocated_struct> > { - typedef __true_type implemented; - typedef __false_type complete; - }; - _STLP_TEMPLATE_NULL - struct __move_traits<slist<specially_allocated_struct> > { - typedef __true_type implemented; - typedef __false_type complete; - }; - _STLP_TEMPLATE_NULL - struct __move_traits<less<struct_with_specialized_less> > { - typedef __true_type implemented; - typedef __false_type complete; - }; - _STLP_TEMPLATE_NULL - struct __move_traits<set<specially_allocated_struct> > { - typedef __true_type implemented; - typedef __false_type complete; - }; - _STLP_TEMPLATE_NULL - struct __move_traits<multiset<specially_allocated_struct> > { - typedef __true_type implemented; - typedef __false_type complete; - }; -# endif -# endif -# endif - -# if defined (_STLP_USE_NAMESPACES) -} -# endif -#endif - -void MoveConstructorTest::movable_declaration() -{ -#if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \ - !defined (_STLP_NO_MOVE_SEMANTIC) - //This test purpose is to check correct detection of the STL movable - //traits declaration - { - //string, wstring: - CPPUNIT_ASSERT( is_movable(string()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(string()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(string()) ); -# endif -# if defined (_STLP_HAS_WCHAR_T) - CPPUNIT_ASSERT( is_movable(wstring()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(wstring()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(wstring()) ); -# endif -# endif - } - -# if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - { - //crope, wrope: - CPPUNIT_ASSERT( is_movable(crope()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(crope()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(crope()) ); -# endif -# if defined (_STLP_HAS_WCHAR_T) - CPPUNIT_ASSERT( is_movable(wrope()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(wrope()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(wrope()) ); -# endif -# endif - } -# endif - - { - //vector: - CPPUNIT_ASSERT( is_movable(vector<char>()) ); - CPPUNIT_ASSERT( is_movable(vector<specially_allocated_struct>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(vector<char>()) ); - CPPUNIT_ASSERT( !is_move_complete(vector<specially_allocated_struct>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(vector<char>()) ); -# endif - } - - { - //deque: - CPPUNIT_ASSERT( is_movable(deque<char>()) ); - CPPUNIT_ASSERT( is_movable(deque<specially_allocated_struct>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(deque<char>()) ); - CPPUNIT_ASSERT( !is_move_complete(deque<specially_allocated_struct>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(deque<char>()) ); -# endif - } - - { - //list: - CPPUNIT_ASSERT( is_movable(list<char>()) ); - CPPUNIT_ASSERT( is_movable(list<specially_allocated_struct>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(list<char>()) ); - CPPUNIT_ASSERT( !is_move_complete(list<specially_allocated_struct>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(list<char>()) ); -# endif - } - -# if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - { - //slist: - CPPUNIT_ASSERT( is_movable(slist<char>()) ); - CPPUNIT_ASSERT( is_movable(slist<specially_allocated_struct>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(slist<char>()) ); - CPPUNIT_ASSERT( !is_move_complete(slist<specially_allocated_struct>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(slist<char>()) ); -# endif - } -# endif - - { - //queue: - CPPUNIT_ASSERT( is_movable(queue<char>()) ); - CPPUNIT_ASSERT( is_movable(queue<specially_allocated_struct>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(queue<char>()) ); - CPPUNIT_ASSERT( !is_move_complete(queue<specially_allocated_struct>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(queue<char>()) ); -# endif - } - - { - //stack: - CPPUNIT_ASSERT( is_movable(stack<char>()) ); - CPPUNIT_ASSERT( is_movable(stack<specially_allocated_struct>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(stack<char>()) ); - CPPUNIT_ASSERT( !is_move_complete(stack<specially_allocated_struct>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(stack<char>()) ); -# endif - } - -#endif -} - -void MoveConstructorTest::movable_declaration_assoc() -{ -#if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \ - !defined (_STLP_NO_MOVE_SEMANTIC) - { - //associative containers, set multiset, map, multimap: - - //For associative containers it is important that less is correctly recognize as - //the STLport less or a user specialized less: -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(less<char>()) ); -# endif - CPPUNIT_ASSERT( !is_move_complete(less<struct_with_specialized_less>()) ); - - //set - CPPUNIT_ASSERT( is_movable(set<char>()) ); - CPPUNIT_ASSERT( is_movable(set<specially_allocated_struct>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(set<char>()) ); - CPPUNIT_ASSERT( !is_move_complete(set<specially_allocated_struct>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(set<char>()) ); -# endif - - //multiset - CPPUNIT_ASSERT( is_movable(multiset<char>()) ); - CPPUNIT_ASSERT( is_movable(multiset<specially_allocated_struct>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(multiset<char>()) ); - CPPUNIT_ASSERT( !is_move_complete(multiset<specially_allocated_struct>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(multiset<char>()) ); -# endif - - //map - CPPUNIT_ASSERT( is_movable(map<char, char>()) ); - CPPUNIT_ASSERT( is_movable(map<specially_allocated_struct, char>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(map<char, char>()) ); - //Here even if allocator has been specialized for specially_allocated_struct - //this pecialization won't be used in default map instanciation as the default - //allocator is allocator<pair<specially_allocated_struct, char> > - CPPUNIT_ASSERT( is_move_complete(map<specially_allocated_struct, char>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(map<char, char>()) ); -# endif - - //multimap - CPPUNIT_ASSERT( is_movable(multimap<char, char>()) ); - CPPUNIT_ASSERT( is_movable(multimap<specially_allocated_struct, char>()) ); -# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( is_move_complete(multimap<char, char>()) ); - //Idem map remark - CPPUNIT_ASSERT( is_move_complete(multimap<specially_allocated_struct, char>()) ); -# else - CPPUNIT_ASSERT( !is_move_complete(multimap<char, char>()) ); -# endif - } -#endif -} - -void MoveConstructorTest::movable_declaration_hash() -{ -#if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \ - !defined (_STLP_NO_MOVE_SEMANTIC) - { - //hashed containers, unordered_set unordered_multiset, unordered_map, unordered_multimap, - // hash_set, hash_multiset, hash_map, hash_multimap: - - //We only check that they are movable, completness is not yet supported - CPPUNIT_ASSERT( is_movable(unordered_set<char>()) ); - CPPUNIT_ASSERT( is_movable(unordered_multiset<char>()) ); - CPPUNIT_ASSERT( is_movable(unordered_map<char, char>()) ); - CPPUNIT_ASSERT( is_movable(unordered_multimap<char, char>()) ); -# if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - CPPUNIT_ASSERT( is_movable(hash_set<char>()) ); - CPPUNIT_ASSERT( is_movable(hash_multiset<char>()) ); - CPPUNIT_ASSERT( is_movable(hash_map<char, char>()) ); - CPPUNIT_ASSERT( is_movable(hash_multimap<char, char>()) ); -# endif - } -#endif -} - diff --git a/test/unit/mvctor_test.cpp b/test/unit/mvctor_test.cpp deleted file mode 100644 index ddac32f..0000000 --- a/test/unit/mvctor_test.cpp +++ /dev/null @@ -1,816 +0,0 @@ -#include <vector> -#include <algorithm> -#include <string> -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <slist> -#endif -#include <list> -#include <deque> -#include <set> -#if defined (STLPORT) -# include <unordered_set> -#endif - -#include "mvctor_test.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# if defined (STLPORT) -using namespace std::tr1; -# endif -#endif - -CPPUNIT_TEST_SUITE_REGISTRATION(MoveConstructorTest); - -// -// tests implementation -// -void MoveConstructorTest::move_construct_test() -{ - //cout << "vector<vector<int>>"; - vector<int> const ref_vec(10, 0); - vector<vector<int> > v_v_ints(1, ref_vec); - -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - int *pint = &(v_v_ints.front().front()); -#endif - - size_t cur_capacity = v_v_ints.capacity(); - while (v_v_ints.capacity() <= cur_capacity) { - v_v_ints.push_back(ref_vec); - } - - //v_v_ints has been resized -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT((pint == &v_v_ints.front().front())); -#endif - - //cout << "vector<vector<int>>::erase"; - //We need at least 3 elements: - while (v_v_ints.size() < 3) { - v_v_ints.push_back(ref_vec); - } - - //We erase the 2nd -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - pint = &v_v_ints[2].front(); -#endif - v_v_ints.erase(v_v_ints.begin() + 1); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT((pint == &v_v_ints[1].front())); -#endif - - //cout << "vector<string>"; - string const ref_str("ref string, big enough to be a dynamic one"); - vector<string> vec_strs(1, ref_str); - -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - char const* pstr = vec_strs.front().c_str(); -#endif - cur_capacity = vec_strs.capacity(); - while (vec_strs.capacity() <= cur_capacity) { - vec_strs.push_back(ref_str); - } - - //vec_str has been resized -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT((pstr == vec_strs.front().c_str())); -#endif - - //cout << "vector<string>::erase"; - //We need at least 3 elements: - while (vec_strs.size() < 3) { - vec_strs.push_back(ref_str); - } - - //We erase the 2nd -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - pstr = vec_strs[2].c_str(); -#endif - vec_strs.erase(vec_strs.begin() + 1); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT((pstr == vec_strs[1].c_str())); -#endif - - //cout << "swap(vector<int>, vector<int>)"; - vector<int> elem1(10, 0), elem2(10, 0); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - int *p1 = &elem1.front(); - int *p2 = &elem2.front(); -#endif - swap(elem1, elem2); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT(((p1 == &elem2.front()) && (p2 == &elem1.front()))); -#endif - - { - vector<bool> bit_vec(5, true); - bit_vec.insert(bit_vec.end(), 5, false); - vector<vector<bool> > v_v_bits(1, bit_vec); - - /* - * This is a STLport specific test as we are using internal implementation - * details to check that the move has been correctly handled. For other - * STL implementation it is only a compile check. - */ -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) -# if defined (_STLP_DEBUG) - unsigned int *punit = v_v_bits.front().begin()._M_iterator._M_p; -# else - unsigned int *punit = v_v_bits.front().begin()._M_p; -# endif -#endif - - cur_capacity = v_v_bits.capacity(); - while (v_v_bits.capacity() <= cur_capacity) { - v_v_bits.push_back(bit_vec); - } - -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - //v_v_bits has been resized -# if defined (_STLP_DEBUG) - CPPUNIT_ASSERT( punit == v_v_bits.front().begin()._M_iterator._M_p ); -# else - CPPUNIT_ASSERT( punit == v_v_bits.front().begin()._M_p ); -# endif -#endif - } - - // zero: don't like this kind of tests - // because of template test function - // we should find another way to provide - // move constructor testing... - -/* - standard_test1(list<int>(10)); - - - standard_test1(slist<int>(10)); - - standard_test1(deque<int>(10)); -*/ - - /* - int int_values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - - set<int> int_set(int_values, int_values + sizeof(in_values) / sizeof(int)); - standard_test1(int_set); - - multiset<int> int_multiset(int_values, int_values + sizeof(in_values) / sizeof(int)); - standard_test1(int_multiset); - */ - - /* - CheckFullMoveSupport(string()); - CheckFullMoveSupport(vector<int>()); - CheckFullMoveSupport(deque<int>()); - CheckFullMoveSupport(list<int>()); - CheckFullMoveSupport(slist<int>()); - */ -} - -void MoveConstructorTest::deque_test() -{ - //Check the insert range method. - //To the front: - { -# if !defined (STLPORT) || !defined (_STLP_DEBUG) || !defined (_STLP_NO_MEMBER_TEMPLATES) - deque<vector<int> > vect_deque; - vector<int*> bufs; - vect_deque.assign(3, vector<int>(10)); - bufs.push_back(&vect_deque[0].front()); - bufs.push_back(&vect_deque[1].front()); - bufs.push_back(&vect_deque[2].front()); - - int nb_insert = 5; - //Initialize to 1 to generate a front insertion: - int pos = 1; - while (nb_insert--) { - vector<vector<int> > vect_vect(2, vector<int>(10)); - vect_deque.insert(vect_deque.begin() + pos, vect_vect.begin(), vect_vect.end()); - bufs.insert(bufs.begin() + pos, &vect_deque[pos].front()); - bufs.insert(bufs.begin() + pos + 1, &vect_deque[pos + 1].front()); - ++pos; - } - CPPUNIT_ASSERT( vect_deque.size() == 13 ); -# if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (int i = 0; i < 5; ++i) { - CPPUNIT_ASSERT( bufs[i] == &vect_deque[i].front() ); - CPPUNIT_ASSERT( bufs[11 - i] == &vect_deque[11 - i].front() ); - } -# endif -# endif - } - - //To the back - { -# if !defined (STLPORT) || !defined (_STLP_DEBUG) || !defined (_STLP_NO_MEMBER_TEMPLATES) - deque<vector<int> > vect_deque; - vector<int*> bufs; - vect_deque.assign(3, vector<int>(10)); - bufs.push_back(&vect_deque[0].front()); - bufs.push_back(&vect_deque[1].front()); - bufs.push_back(&vect_deque[2].front()); - - int nb_insert = 5; - //Initialize to 2 to generate a back insertion: - int pos = 2; - while (nb_insert--) { - vector<vector<int> > vect_vect(2, vector<int>(10)); - vect_deque.insert(vect_deque.begin() + pos, vect_vect.begin(), vect_vect.end()); - bufs.insert(bufs.begin() + pos, &vect_deque[pos].front()); - bufs.insert(bufs.begin() + pos + 1, &vect_deque[pos + 1].front()); - ++pos; - } - CPPUNIT_ASSERT( vect_deque.size() == 13 ); -# if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (int i = 0; i < 5; ++i) { - CPPUNIT_ASSERT( bufs[i + 1] == &vect_deque[i + 1].front() ); - CPPUNIT_ASSERT( bufs[12 - i] == &vect_deque[12 - i].front() ); - } -# endif -# endif - } - - //Check the different erase methods. - { - deque<vector<int> > vect_deque; - vect_deque.assign(20, vector<int>(10)); - deque<vector<int> >::iterator vdit(vect_deque.begin()), vditEnd(vect_deque.end()); - vector<int*> bufs; - for (; vdit != vditEnd; ++vdit) { - bufs.push_back(&vdit->front()); - } - - { - // This check, repeated after each operation, check the deque consistency: - deque<vector<int> >::iterator it = vect_deque.end() - 5; - int nb_incr = 0; - for (; it != vect_deque.end() && nb_incr <= 6; ++nb_incr, ++it) {} - CPPUNIT_ASSERT( nb_incr == 5 ); - } - - { - //erase in front: - vect_deque.erase(vect_deque.begin() + 2); - bufs.erase(bufs.begin() + 2); - CPPUNIT_ASSERT( vect_deque.size() == 19 ); - deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end()); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - deque<vector<int> >::iterator it = vect_deque.end() - 5; - int nb_incr = 0; - for (; it != vect_deque.end() && nb_incr <= 6; ++nb_incr, ++it) {} - CPPUNIT_ASSERT( nb_incr == 5 ); - } - - { - //erase in the back: - vect_deque.erase(vect_deque.end() - 2); - bufs.erase(bufs.end() - 2); - CPPUNIT_ASSERT( vect_deque.size() == 18 ); - deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end()); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - deque<vector<int> >::iterator it = vect_deque.end() - 5; - int nb_incr = 0; - for (; it != vect_deque.end() && nb_incr < 6; ++nb_incr, ++it) {} - CPPUNIT_ASSERT( nb_incr == 5 ); - } - - { - //range erase in front - vect_deque.erase(vect_deque.begin() + 3, vect_deque.begin() + 5); - bufs.erase(bufs.begin() + 3, bufs.begin() + 5); - CPPUNIT_ASSERT( vect_deque.size() == 16 ); - deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end()); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - deque<vector<int> >::iterator it = vect_deque.end() - 5; - int nb_incr = 0; - for (; it != vect_deque.end() && nb_incr <= 6; ++nb_incr, ++it) {} - CPPUNIT_ASSERT( nb_incr == 5 ); - } - - { - //range erase in back - vect_deque.erase(vect_deque.end() - 5, vect_deque.end() - 3); - bufs.erase(bufs.end() - 5, bufs.end() - 3); - CPPUNIT_ASSERT( vect_deque.size() == 14 ); - deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end()); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - } - - //Check the insert value(s) - { - deque<vector<int> > vect_deque; - vect_deque.assign(20, vector<int>(10)); - deque<vector<int> >::iterator vdit(vect_deque.begin()), vditEnd(vect_deque.end()); - vector<int*> bufs; - for (; vdit != vditEnd; ++vdit) { - bufs.push_back(&vdit->front()); - } - - { - //2 values in front: - vect_deque.insert(vect_deque.begin() + 2, 2, vector<int>(10)); - bufs.insert(bufs.begin() + 2, &vect_deque[2].front()); - bufs.insert(bufs.begin() + 3, &vect_deque[3].front()); - CPPUNIT_ASSERT( vect_deque.size() == 22 ); - deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end()); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - //2 values in back: - vect_deque.insert(vect_deque.end() - 2, 2, vector<int>(10)); - bufs.insert(bufs.end() - 2, &vect_deque[20].front()); - bufs.insert(bufs.end() - 2, &vect_deque[21].front()); - CPPUNIT_ASSERT( vect_deque.size() == 24 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - //1 value in front: - deque<vector<int> >::iterator ret; - ret = vect_deque.insert(vect_deque.begin() + 2, vector<int>(10)); - bufs.insert(bufs.begin() + 2, &vect_deque[2].front()); - CPPUNIT_ASSERT( vect_deque.size() == 25 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( &ret->front() == bufs[2] ); - deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - //1 value in back: - deque<vector<int> >::iterator ret; - ret = vect_deque.insert(vect_deque.end() - 2, vector<int>(10)); - bufs.insert(bufs.end() - 2, &vect_deque[23].front()); - CPPUNIT_ASSERT( vect_deque.size() == 26 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( &ret->front() == bufs[23] ); - deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - } -} - -void MoveConstructorTest::vector_test() -{ - //Check the insert range method. - //To the front: - { - vector<vector<int> > vect_vector; - vector<int*> bufs; - vect_vector.assign(3, vector<int>(10)); - bufs.push_back(&vect_vector[0].front()); - bufs.push_back(&vect_vector[1].front()); - bufs.push_back(&vect_vector[2].front()); - - int nb_insert = 5; - int pos = 1; - while (nb_insert--) { - vector<vector<int> > vect_vect(2, vector<int>(10)); - vect_vector.insert(vect_vector.begin() + pos, vect_vect.begin(), vect_vect.end()); - bufs.insert(bufs.begin() + pos, &vect_vector[pos].front()); - bufs.insert(bufs.begin() + pos + 1, &vect_vector[pos + 1].front()); - ++pos; - } - CPPUNIT_ASSERT( vect_vector.size() == 13 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (int i = 0; i < 5; ++i) { - CPPUNIT_ASSERT( bufs[i] == &vect_vector[i].front() ); - CPPUNIT_ASSERT( bufs[11 - i] == &vect_vector[11 - i].front() ); - } -#endif - } - - //To the back - { - vector<vector<int> > vect_vector; - vector<int*> bufs; - vect_vector.assign(3, vector<int>(10)); - bufs.push_back(&vect_vector[0].front()); - bufs.push_back(&vect_vector[1].front()); - bufs.push_back(&vect_vector[2].front()); - - int nb_insert = 5; - //Initialize to 2 to generate a back insertion: - int pos = 2; - while (nb_insert--) { - vector<vector<int> > vect_vect(2, vector<int>(10)); - vect_vector.insert(vect_vector.begin() + pos, vect_vect.begin(), vect_vect.end()); - bufs.insert(bufs.begin() + pos, &vect_vector[pos].front()); - bufs.insert(bufs.begin() + pos + 1, &vect_vector[pos + 1].front()); - ++pos; - } - CPPUNIT_ASSERT( vect_vector.size() == 13 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - for (int i = 0; i < 5; ++i) { - CPPUNIT_ASSERT( bufs[i + 1] == &vect_vector[i + 1].front() ); - CPPUNIT_ASSERT( bufs[12 - i] == &vect_vector[12 - i].front() ); - } -#endif - } - - //Check the different erase methods. - { - vector<vector<int> > vect_vector; - vect_vector.assign(20, vector<int>(10)); - vector<vector<int> >::iterator vdit(vect_vector.begin()), vditEnd(vect_vector.end()); - vector<int*> bufs; - for (; vdit != vditEnd; ++vdit) { - bufs.push_back(&vdit->front()); - } - - { - // This check, repeated after each operation, check the vector consistency: - vector<vector<int> >::iterator it = vect_vector.end() - 5; - int nb_incr = 0; - for (; it != vect_vector.end() && nb_incr <= 6; ++nb_incr, ++it) {} - CPPUNIT_ASSERT( nb_incr == 5 ); - } - - { - //erase in front: - vect_vector.erase(vect_vector.begin() + 2); - bufs.erase(bufs.begin() + 2); - CPPUNIT_ASSERT( vect_vector.size() == 19 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - vector<vector<int> >::iterator it = vect_vector.end() - 5; - int nb_incr = 0; - for (; it != vect_vector.end() && nb_incr <= 6; ++nb_incr, ++it) {} - CPPUNIT_ASSERT( nb_incr == 5 ); - } - - { - //erase in the back: - vect_vector.erase(vect_vector.end() - 2); - bufs.erase(bufs.end() - 2); - CPPUNIT_ASSERT( vect_vector.size() == 18 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - vector<vector<int> >::iterator it = vect_vector.end() - 5; - int nb_incr = 0; - for (; it != vect_vector.end() && nb_incr < 6; ++nb_incr, ++it) {} - CPPUNIT_ASSERT( nb_incr == 5 ); - } - - { - //range erase in front - vect_vector.erase(vect_vector.begin() + 3, vect_vector.begin() + 5); - bufs.erase(bufs.begin() + 3, bufs.begin() + 5); - CPPUNIT_ASSERT( vect_vector.size() == 16 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - vector<vector<int> >::iterator it = vect_vector.end() - 5; - int nb_incr = 0; - for (; it != vect_vector.end() && nb_incr <= 6; ++nb_incr, ++it) {} - CPPUNIT_ASSERT( nb_incr == 5 ); - } - - { - //range erase in back - vect_vector.erase(vect_vector.end() - 5, vect_vector.end() - 3); - bufs.erase(bufs.end() - 5, bufs.end() - 3); - CPPUNIT_ASSERT( vect_vector.size() == 14 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - } - - //Check the insert value(s) - { - vector<vector<int> > vect_vector; - vect_vector.assign(20, vector<int>(10)); - vector<vector<int> >::iterator vdit(vect_vector.begin()), vditEnd(vect_vector.end()); - vector<int*> bufs; - for (; vdit != vditEnd; ++vdit) { - bufs.push_back(&vdit->front()); - } - - { - //2 values in front: - vect_vector.insert(vect_vector.begin() + 2, 2, vector<int>(10)); - bufs.insert(bufs.begin() + 2, &vect_vector[2].front()); - bufs.insert(bufs.begin() + 3, &vect_vector[3].front()); - CPPUNIT_ASSERT( vect_vector.size() == 22 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - //2 values in back: - vect_vector.insert(vect_vector.end() - 2, 2, vector<int>(10)); - bufs.insert(bufs.end() - 2, &vect_vector[20].front()); - bufs.insert(bufs.end() - 2, &vect_vector[21].front()); - CPPUNIT_ASSERT( vect_vector.size() == 24 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - //1 value in front: -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - vector<vector<int> >::iterator ret = -#endif - vect_vector.insert(vect_vector.begin() + 2, vector<int>(10)); - bufs.insert(bufs.begin() + 2, &vect_vector[2].front()); - CPPUNIT_ASSERT( vect_vector.size() == 25 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( &ret->front() == bufs[2] ); - vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - - { - //1 value in back: -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - vector<vector<int> >::iterator ret = -#endif - vect_vector.insert(vect_vector.end() - 2, vector<int>(10)); - bufs.insert(bufs.end() - 2, &vect_vector[23].front()); - CPPUNIT_ASSERT( vect_vector.size() == 26 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( &ret->front() == bufs[23] ); - vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end()); - for (size_t i = 0; dit != ditEnd; ++dit, ++i) { - CPPUNIT_ASSERT( bufs[i] == &dit->front() ); - } -#endif - } - } - - //The following tests are checking move contructor implementations: - const string long_str("long enough string to force dynamic allocation"); - { - //vector move contructor: - vector<vector<string> > vect(10, vector<string>(10, long_str)); - vector<string> strs; - size_t index = 0; - for (;;) { - vector<vector<string> >::iterator it(vect.begin()); - advance(it, index % vect.size()); - strs.push_back(it->front()); - it->erase(it->begin()); - if (it->empty()) { - vect.erase(it); - if (vect.empty()) - break; - } - index += 3; - } - CPPUNIT_ASSERT( strs.size() == 10 * 10 ); - vector<string>::iterator it(strs.begin()), itEnd(strs.end()); - for (; it != itEnd; ++it) { - CPPUNIT_ASSERT( *it == long_str ); - } - } - - { - //deque move contructor: -# if !defined (__DMC__) - vector<deque<string> > vect(10, deque<string>(10, long_str)); -# else - deque<string> deq_str = deque<string>(10, long_str); - vector<deque<string> > vect(10, deq_str); -# endif - vector<string> strs; - size_t index = 0; - for (;;) { - vector<deque<string> >::iterator it(vect.begin()); - advance(it, index % vect.size()); - strs.push_back(it->front()); - it->pop_front(); - if (it->empty()) { - vect.erase(it); - if (vect.empty()) - break; - } - index += 3; - } - CPPUNIT_ASSERT( strs.size() == 10 * 10 ); - vector<string>::iterator it(strs.begin()), itEnd(strs.end()); - for (; it != itEnd; ++it) { - CPPUNIT_ASSERT( *it == long_str ); - } - } - - { - //list move contructor: - vector<list<string> > vect(10, list<string>(10, long_str)); - vector<string> strs; - size_t index = 0; - for (;;) { - vector<list<string> >::iterator it(vect.begin()); - advance(it, index % vect.size()); - strs.push_back(it->front()); - it->pop_front(); - if (it->empty()) { - vect.erase(it); - if (vect.empty()) - break; - } - index += 3; - } - CPPUNIT_ASSERT( strs.size() == 10 * 10 ); - vector<string>::iterator it(strs.begin()), itEnd(strs.end()); - for (; it != itEnd; ++it) { - CPPUNIT_ASSERT( *it == long_str ); - } - } - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - { - //slist move contructor: - vector<slist<string> > vect(10, slist<string>(10, long_str)); - vector<string> strs; - size_t index = 0; - while (true) { - vector<slist<string> >::iterator it(vect.begin()); - advance(it, index % vect.size()); - strs.push_back(it->front()); - it->pop_front(); - if (it->empty()) { - vect.erase(it); - if (vect.empty()) - break; - } - index += 3; - } - CPPUNIT_ASSERT( strs.size() == 10 * 10 ); - vector<string>::iterator it(strs.begin()), itEnd(strs.end()); - for (; it != itEnd; ++it) { - CPPUNIT_ASSERT( *it == long_str ); - } - } -#endif - - { - //binary tree move contructor: - multiset<string> ref; - for (size_t i = 0; i < 10; ++i) { - ref.insert(long_str); - } - vector<multiset<string> > vect(10, ref); - vector<string> strs; - size_t index = 0; - for (;;) { - vector<multiset<string> >::iterator it(vect.begin()); - advance(it, index % vect.size()); - strs.push_back(*it->begin()); - it->erase(it->begin()); - if (it->empty()) { - vect.erase(it); - if (vect.empty()) - break; - } - index += 3; - } - CPPUNIT_ASSERT( strs.size() == 10 * 10 ); - vector<string>::iterator it(strs.begin()), itEnd(strs.end()); - for (; it != itEnd; ++it) { - CPPUNIT_ASSERT( *it == long_str ); - } - } - -#if defined (STLPORT) -# if !defined (__DMC__) - { - //hash container move contructor: - unordered_multiset<string> ref; - for (size_t i = 0; i < 10; ++i) { - ref.insert(long_str); - } - vector<unordered_multiset<string> > vect(10, ref); - vector<string> strs; - size_t index = 0; - while (true) { - vector<unordered_multiset<string> >::iterator it(vect.begin()); - advance(it, index % vect.size()); - strs.push_back(*it->begin()); - it->erase(it->begin()); - if (it->empty()) { - vect.erase(it); - if (vect.empty()) - break; - } - index += 3; - } - CPPUNIT_ASSERT( strs.size() == 10 * 10 ); - vector<string>::iterator it(strs.begin()), itEnd(strs.end()); - for (; it != itEnd; ++it) { - CPPUNIT_ASSERT( *it == long_str ); - } - } -# endif -#endif -} - -#if defined (__BORLANDC__) -/* Specific Borland test case to show a really weird compiler behavior. - */ -class Standalone -{ -public: - //Uncomment following to pass the test - //Standalone() {} - ~Standalone() {} - - MovableStruct movableStruct; - vector<int> intVector; -}; - -void MoveConstructorTest::nb_destructor_calls() -{ - MovableStruct::reset(); - - try - { - Standalone standalone; - throw "some exception"; - MovableStruct movableStruct; - } - catch (const char*) - { - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 1 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 1 ); - } -} -#endif diff --git a/test/unit/mvctor_test.h b/test/unit/mvctor_test.h deleted file mode 100644 index 8314db6..0000000 --- a/test/unit/mvctor_test.h +++ /dev/null @@ -1,97 +0,0 @@ -#include <cstdio> //size_t and STLport macros - -#include "cppunit/cppunit_proxy.h" - -// -// TestCase class -// -class MoveConstructorTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(MoveConstructorTest); - CPPUNIT_TEST(move_construct_test); - CPPUNIT_TEST(deque_test); - CPPUNIT_TEST(vector_test); - CPPUNIT_TEST(move_traits); -#if !defined (STLPORT) || defined (_STLP_NO_MOVE_SEMANTIC) || \ - defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) || \ - (defined (__BORLANDC__) && (__BORLANDC__ < 0x564)) - CPPUNIT_IGNORE; -# endif - CPPUNIT_TEST(movable_declaration) - CPPUNIT_TEST(movable_declaration_assoc) - CPPUNIT_TEST(movable_declaration_hash) -#if defined (__BORLANDC__) - CPPUNIT_STOP_IGNORE; - CPPUNIT_TEST(nb_destructor_calls); -#endif - CPPUNIT_TEST_SUITE_END(); - -protected: - void move_construct_test(); - void deque_test(); - void vector_test(); - void move_traits(); - void movable_declaration(); - void movable_declaration_assoc(); - void movable_declaration_hash(); - void nb_destructor_calls(); - - /* - template <class _Container> - void standard_test1(_Container const& ref_cont) { - vector<_Container> vec_cont(1, ref_cont); - typedef typename _Container::value_type value_type; - value_type *pvalue = &(*vec_cont.front().begin()); - size_t cur_capacity= vec_cont.capacity(); - //force reallocation - while (cur_capacity == vec_cont.capacity()) { - vec_cont.push_back(ref_cont); - } - bool b=( (pvalue==(&(*vec_cont.front().begin()))) ); - CPPUNIT_ASSERT(b); - } - */ - -private: - void move_traits_vec(); - void move_traits_vec_complete(); - void move_traits_deq(); - void move_traits_deq_complete(); -}; - -struct MovableStruct { - MovableStruct() { ++nb_dft_construct_call; } - MovableStruct(MovableStruct const&) { ++nb_cpy_construct_call; } -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) -# if defined (_STLP_USE_NAMESPACES) - MovableStruct(std::__move_source<MovableStruct>) -# else - MovableStruct(__move_source<MovableStruct>) -# endif - { ++nb_mv_construct_call; } -#endif - ~MovableStruct() { ++nb_destruct_call; } - - MovableStruct& operator = (const MovableStruct&) { - ++nb_assignment_call; - return *this; - } - - static void reset() { - nb_dft_construct_call = nb_cpy_construct_call = nb_mv_construct_call = 0; - nb_assignment_call = 0; - nb_destruct_call = 0; - } - - static size_t nb_dft_construct_call; - static size_t nb_cpy_construct_call; - static size_t nb_mv_construct_call; - static size_t nb_assignment_call; - static size_t nb_destruct_call; - - //Dummy data just to control struct sizeof - //As node allocator implementation align memory blocks on 2 * sizeof(void*) - //we give MovableStruct the same size in order to have expected allocation - //and not more - void* dummy_data[2]; -}; diff --git a/test/unit/mvctor_traits_test.cpp b/test/unit/mvctor_traits_test.cpp deleted file mode 100644 index 7cea98f..0000000 --- a/test/unit/mvctor_traits_test.cpp +++ /dev/null @@ -1,460 +0,0 @@ -#include <vector> -#include <deque> - -#include "mvctor_test.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -size_t MovableStruct::nb_dft_construct_call = 0; -size_t MovableStruct::nb_cpy_construct_call = 0; -size_t MovableStruct::nb_mv_construct_call = 0; -size_t MovableStruct::nb_assignment_call = 0; -size_t MovableStruct::nb_destruct_call = 0; - -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) -# if defined (_STLP_USE_NAMESPACES) -namespace std { -# endif - _STLP_TEMPLATE_NULL - struct __move_traits<MovableStruct> { - typedef __true_type implemented; - typedef __false_type complete; - }; -# if defined (_STLP_USE_NAMESPACES) -} -# endif -#endif - -struct CompleteMovableStruct { - CompleteMovableStruct() { ++nb_dft_construct_call; } - CompleteMovableStruct(CompleteMovableStruct const&) { ++nb_cpy_construct_call; } -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CompleteMovableStruct(__move_source<CompleteMovableStruct>) { ++nb_mv_construct_call; } -#endif - ~CompleteMovableStruct() { ++nb_destruct_call; } - - CompleteMovableStruct& operator = (const CompleteMovableStruct&) { - ++nb_assignment_call; - return *this; - } - static void reset() { - nb_dft_construct_call = nb_cpy_construct_call = nb_mv_construct_call = 0; - nb_assignment_call = 0; - nb_destruct_call = 0; - } - - static size_t nb_dft_construct_call; - static size_t nb_cpy_construct_call; - static size_t nb_mv_construct_call; - static size_t nb_assignment_call; - static size_t nb_destruct_call; - - //See MovableStruct - void* dummy_data[2]; -}; - -size_t CompleteMovableStruct::nb_dft_construct_call = 0; -size_t CompleteMovableStruct::nb_cpy_construct_call = 0; -size_t CompleteMovableStruct::nb_mv_construct_call = 0; -size_t CompleteMovableStruct::nb_assignment_call = 0; -size_t CompleteMovableStruct::nb_destruct_call = 0; - -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) -# if defined (_STLP_USE_NAMESPACES) -namespace std { -# endif - _STLP_TEMPLATE_NULL - struct __move_traits<CompleteMovableStruct> { - typedef __true_type implemented; - typedef __true_type complete; - }; -# if defined (_STLP_USE_NAMESPACES) -} -# endif -#endif - -void MoveConstructorTest::move_traits() -{ - move_traits_vec(); - move_traits_vec_complete(); - move_traits_deq(); - move_traits_deq_complete(); -} - -void MoveConstructorTest::move_traits_vec() -{ - { - { - vector<MovableStruct> vect; - vect.push_back(MovableStruct()); - vect.push_back(MovableStruct()); - vect.push_back(MovableStruct()); - vect.push_back(MovableStruct()); - - // vect contains 4 elements - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 4 ); -#if defined (STLPORT) -# if !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 3 ); -# else - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 7 ); -# endif - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 7 ); -#elif !defined (_MSC_VER) - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 7 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 7 ); -#else - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 14 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 14 ); -#endif - CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 0 ); - - // Following test violate requirements to sequiences (23.1.1 Table 67) - /* - vect.insert(vect.begin() + 2, vect.begin(), vect.end()); - // vect contains 8 elements - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 4 ); - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 8 ); - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 7 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 11 ); - */ - - MovableStruct::reset(); - vector<MovableStruct> v2 = vect; - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 0 ); - - MovableStruct::reset(); - vect.insert(vect.begin() + 2, v2.begin(), v2.end() ); - - // vect contains 8 elements - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 0 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 4 ); -#else - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 8 ); -#endif - CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 4 ); - - MovableStruct::reset(); - vect.erase(vect.begin(), vect.begin() + 2 ); - - // vect contains 6 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 6 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 8 ); -#else - CPPUNIT_ASSERT_EQUAL( MovableStruct::nb_assignment_call, 6 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 ); -#endif - - MovableStruct::reset(); - vect.erase(vect.end() - 2, vect.end()); - - // vect contains 4 elements - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 ); - - MovableStruct::reset(); - vect.erase(vect.begin()); - - // vect contains 3 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 3 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 4 ); -#else - CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 3 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 1 ); -#endif - - MovableStruct::reset(); - } - //vect with 3 elements and v2 with 4 elements are now out of scope - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 3 + 4 ); - } -} - -void MoveConstructorTest::move_traits_vec_complete() -{ - { - { - vector<CompleteMovableStruct> vect; - vect.push_back(CompleteMovableStruct()); - vect.push_back(CompleteMovableStruct()); - vect.push_back(CompleteMovableStruct()); - vect.push_back(CompleteMovableStruct()); - - // vect contains 4 elements - CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 4 ); -#if defined (STLPORT) -# if !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 3 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 ); -# else - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 7 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 7 ); -# endif -#elif !defined (_MSC_VER) - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 7 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 7 ); -#else - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 14 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 14 ); -#endif - - // Following test violate requirements to sequiences (23.1.1 Table 67) - /* - vect.insert(vect.begin() + 2, vect.begin(), vect.end()); - - // vect contains 8 elements - CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 8 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 7 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 ); - */ - - CompleteMovableStruct::reset(); - vector<CompleteMovableStruct> v2 = vect; - - CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 0 ); - - CompleteMovableStruct::reset(); - vect.insert(vect.begin() + 2, v2.begin(), v2.end()); - - // vect contains 8 elements - CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 0 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 0 ); -#else - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 8 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 ); -#endif - - CompleteMovableStruct::reset(); - vect.erase(vect.begin(), vect.begin() + 2); - - // vect contains 6 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 6 ); -#else - CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 6 ); -#endif - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 2 ); - - CompleteMovableStruct::reset(); - vect.erase(vect.end() - 2, vect.end()); - - // vect contains 4 elements - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 2 ); - - CompleteMovableStruct::reset(); - vect.erase(vect.begin()); - - // vect contains 3 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 3 ); -#else - CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 3 ); -#endif - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 1 ); - - CompleteMovableStruct::reset(); - } - //vect with 3 elements and v2 with 4 elements are now out of scope - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 3 + 4 ); - } -} - -void MoveConstructorTest::move_traits_deq() -{ - { - MovableStruct::reset(); - { - deque<MovableStruct> deq; - deq.push_back(MovableStruct()); - deq.push_back(MovableStruct()); - deq.push_back(MovableStruct()); - deq.push_back(MovableStruct()); - - // deq contains 4 elements - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 4 ); - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 4 ); - - // Following test violate requirements to sequiences (23.1.1 Table 67) - /* - deq.insert(deq.begin() + 2, deq.begin(), deq.end()); - // deq contains 8 elements - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 4 ); - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 8 ); - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 7 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 11 ); - */ - - MovableStruct::reset(); - deque<MovableStruct> d2 = deq; - - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 0 ); - - MovableStruct::reset(); - deq.insert(deq.begin() + 2, d2.begin(), d2.end() ); - - // deq contains 8 elements - CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 0 ); - CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 2 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 ); -#else - CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 2 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 0 ); -#endif - - MovableStruct::reset(); - deq.erase(deq.begin() + 1, deq.begin() + 3 ); - - // deq contains 6 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 1 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 3 ); -#else - //Following check is highly deque implementation dependant so - //it might not always work... - CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 1 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 ); -#endif - - MovableStruct::reset(); - deq.erase(deq.end() - 3, deq.end() - 1); - - // deq contains 4 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 1 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 3 ); -#else - CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 1 ); - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 ); -#endif - - MovableStruct::reset(); - deq.erase(deq.begin()); - - // deq contains 3 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 ); -#else - CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 0 ); -#endif - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 1 ); - - MovableStruct::reset(); - } - //deq with 3 elements and d2 with 4 elements are now out of scope - CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 3 + 4 ); - } -} - -void MoveConstructorTest::move_traits_deq_complete() -{ - { - CompleteMovableStruct::reset(); - { - deque<CompleteMovableStruct> deq; - deq.push_back(CompleteMovableStruct()); - deq.push_back(CompleteMovableStruct()); - deq.push_back(CompleteMovableStruct()); - deq.push_back(CompleteMovableStruct()); - - // deq contains 4 elements - CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 ); - - // Following test violate requirements to sequiences (23.1.1 Table 67) - /* - deq.insert(deq.begin() + 2, deq.begin(), deq.end()); - - // deq contains 8 elements - CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 8 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 7 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 ); - */ - - CompleteMovableStruct::reset(); - deque<CompleteMovableStruct> d2 = deq; - - CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 0 ); - - CompleteMovableStruct::reset(); - deq.insert(deq.begin() + 2, d2.begin(), d2.end()); - - // deq contains 8 elements - CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 ); -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 2 ); -#else - CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 2 ); -#endif - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 0 ); - - CompleteMovableStruct::reset(); - deq.erase(deq.begin() + 1, deq.begin() + 3); - - // deq contains 6 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 1 ); -#else - CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 1 ); -#endif - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 2 ); - - CompleteMovableStruct::reset(); - deq.erase(deq.end() - 3, deq.end() - 1); - - // deq contains 4 elements -#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC) - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 1 ); -#else - CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 1 ); -#endif - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 2 ); - - CompleteMovableStruct::reset(); - deq.erase(deq.begin()); - - // deq contains 3 elements - CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 0 ); - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 1 ); - - CompleteMovableStruct::reset(); - } - //deq with 3 elements and v2 with 4 elements are now out of scope - CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 3 + 4 ); - } -} diff --git a/test/unit/neq_test.cpp b/test/unit/neq_test.cpp deleted file mode 100644 index 7769e42..0000000 --- a/test/unit/neq_test.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class NeqTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(NeqTest); - CPPUNIT_TEST(negate0); - CPPUNIT_TEST(nequal0); - CPPUNIT_TEST_SUITE_END(); - -protected: - void negate0(); - void nequal0(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(NeqTest); - -// -// tests implementation -// -void NeqTest::negate0() -{ - int input [3] = { 1, 2, 3 }; - - int output[3]; - transform((int*)input, (int*)input + 3, (int*)output, negate<int>()); - - CPPUNIT_ASSERT(output[0]==-1); - CPPUNIT_ASSERT(output[1]==-2); - CPPUNIT_ASSERT(output[2]==-3); -} -void NeqTest::nequal0() -{ - int input1 [4] = { 1, 7, 2, 2 }; - int input2 [4] = { 1, 6, 2, 3 }; - - int output [4]; - transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, not_equal_to<int>()); - - CPPUNIT_ASSERT(output[0]==0); - CPPUNIT_ASSERT(output[1]==1); - CPPUNIT_ASSERT(output[2]==0); - CPPUNIT_ASSERT(output[3]==1); -} diff --git a/test/unit/new_header_test.cpp b/test/unit/new_header_test.cpp deleted file mode 100644 index 1884299..0000000 --- a/test/unit/new_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <new> diff --git a/test/unit/nthelm_test.cpp b/test/unit/nthelm_test.cpp deleted file mode 100644 index 75c26d1..0000000 --- a/test/unit/nthelm_test.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class NthElemTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(NthElemTest); - CPPUNIT_TEST(nthelem0); - CPPUNIT_TEST(nthelem1); - CPPUNIT_TEST(nthelem2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void nthelem0(); - void nthelem1(); - void nthelem2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(NthElemTest); - -// -// tests implementation -// -void NthElemTest::nthelem0() -{ - int numbers[7] = { 5, 2, 4, 1, 0, 3 ,77}; - nth_element(numbers, numbers + 3, numbers + 6); - - CPPUNIT_ASSERT(numbers[0]==1); - CPPUNIT_ASSERT(numbers[1]==0); - CPPUNIT_ASSERT(numbers[2]==2); - CPPUNIT_ASSERT(numbers[3]==3); - CPPUNIT_ASSERT(numbers[4]==4); - CPPUNIT_ASSERT(numbers[5]==5); -} -void NthElemTest::nthelem1() -{ - //6 8 5 1 7 4 1 5 2 6 - //1 1 4 2 5 5 6 7 8 6 - int numbers[10] = { 6, 8, 5, 1, 7, 4, 1, 5, 2, 6 }; - - vector <int> v1(numbers, numbers+10); - nth_element(v1.begin(), v1.begin() + v1.size() / 2, v1.end()); - - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==4); - CPPUNIT_ASSERT(v1[3]==2); - CPPUNIT_ASSERT(v1[4]==5); - CPPUNIT_ASSERT(v1[5]==5); - CPPUNIT_ASSERT(v1[6]==6); - CPPUNIT_ASSERT(v1[7]==7); - CPPUNIT_ASSERT(v1[8]==8); - CPPUNIT_ASSERT(v1[9]==6); -} -void NthElemTest::nthelem2() -{ - //4 5 4 2 1 7 4 3 1 6 - //6 7 4 4 5 4 3 2 1 1 - - int numbers[10] = { 4, 5, 4, 2, 1, 7, 4, 3, 1, 6 }; - vector <int> v1(numbers, numbers+10); - nth_element(v1.begin(), v1.begin() + v1.size() / 2, v1.end(), greater<int>()); - - CPPUNIT_ASSERT(v1[0]==6); - CPPUNIT_ASSERT(v1[1]==7); - CPPUNIT_ASSERT(v1[2]==4); - CPPUNIT_ASSERT(v1[3]==4); - CPPUNIT_ASSERT(v1[4]==5); - CPPUNIT_ASSERT(v1[5]==4); - CPPUNIT_ASSERT(v1[6]==3); - CPPUNIT_ASSERT(v1[7]==2); - CPPUNIT_ASSERT(v1[8]==1); - CPPUNIT_ASSERT(v1[9]==1); -} diff --git a/test/unit/num_facets_test.cpp b/test/unit/num_facets_test.cpp deleted file mode 100644 index bc5195f..0000000 --- a/test/unit/num_facets_test.cpp +++ /dev/null @@ -1,297 +0,0 @@ -#include "locale_test.h" - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <locale> -# include <sstream> -# include <stdexcept> - -# include "complete_digits.h" - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -struct ref_locale { - const char *name; - const char *decimal_point; - const char *thousands_sep; -}; - -static const ref_locale tested_locales[] = { -//{ name, decimal_point, thousands_sepy_thousands_sep}, -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - { "fr_FR", ",", "\xa0"}, - { "ru_RU.koi8r", ",", "."}, - { "en_GB", ".", ","}, - { "en_US", ".", ","}, -# endif - { "C", ".", ","}, -}; - -// -// tests implementation -// -void LocaleTest::_num_put_get( const locale& loc, const ref_locale* prl ) { - const ref_locale& rl = *prl; - CPPUNIT_ASSERT( has_facet<numpunct<char> >(loc) ); - numpunct<char> const& npct = use_facet<numpunct<char> >(loc); - CPPUNIT_ASSERT( npct.decimal_point() == *rl.decimal_point ); - - float val = 1234.56f; - ostringstream fostr; - fostr.imbue(loc); - fostr << val; - - string ref = "1"; - if (!npct.grouping().empty()) { - ref += npct.thousands_sep(); - } - ref += "234"; - ref += npct.decimal_point(); - ref += "56"; - //cout << "In " << loc.name() << " 1234.56 is written: " << fostr.str() << endl; - CPPUNIT_ASSERT( fostr.str() == ref ); - - val = 12345678.9f; - ref = "1"; - ref += npct.decimal_point(); - ref += "23457e+"; - string digits = "7"; - complete_digits(digits); - ref += digits; - fostr.str(""); - fostr << val; - CPPUNIT_ASSERT( fostr.str() == ref ); - - val = 1000000000.0f; - fostr.str(""); - fostr << val; - digits = "9"; - complete_digits(digits); - CPPUNIT_ASSERT( fostr.str() == string("1e+") + digits ); - - val = 1234.0f; - ref = "1"; - if (!npct.grouping().empty()) { - ref += npct.thousands_sep(); - } - ref += "234"; - fostr.str(""); - fostr << val; - CPPUNIT_ASSERT( fostr.str() == ref ); - - val = 10000001.0f; - fostr.str(""); - fostr << val; - digits = "7"; - complete_digits(digits); - CPPUNIT_ASSERT( fostr.str() == string("1e+") + digits ); - - if (npct.grouping().size() == 1 && npct.grouping()[0] == 3) { - int ival = 1234567890; - fostr.str(""); - fostr << ival; - ref = "1"; - ref += npct.thousands_sep(); - ref += "234"; - ref += npct.thousands_sep(); - ref += "567"; - ref += npct.thousands_sep(); - ref += "890"; - CPPUNIT_ASSERT( fostr.str() == ref ); - } - -#if defined (__BORLANDC__) - num_put<char> const& nput = use_facet<num_put<char> >(loc); - typedef numeric_limits<double> limd; - fostr.setf(ios_base::uppercase | ios_base::showpos); - - if (limd::has_infinity) { - double infinity = limd::infinity(); - fostr.str(""); - nput.put(fostr, fostr, ' ', infinity); - CPPUNIT_ASSERT( fostr.str() == string("+Inf") ); - } - - if (limd::has_quiet_NaN) { - /* Ignore FPU exceptions */ - unsigned int _float_control_word = _control87(0, 0); - _control87(EM_INVALID|EM_INEXACT, MCW_EM); - double qnan = limd::quiet_NaN(); - /* Reset floating point control word */ - _clear87(); - _control87(_float_control_word, MCW_EM); - fostr.str(""); - nput.put(fostr, fostr, ' ', qnan); - CPPUNIT_ASSERT( fostr.str() == string("+NaN") ); - } -#endif -} - -typedef void (LocaleTest::*_Test) (const locale&, const ref_locale*); -static void test_supported_locale(LocaleTest& inst, _Test __test) { - size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]); - for (size_t i = 0; i < n; ++i) { - locale loc; -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try -# endif - { - locale tmp(tested_locales[i].name); - loc = tmp; - } -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - catch (runtime_error const&) { - //This locale is not supported. - continue; - } -# endif - CPPUNIT_MESSAGE( loc.name().c_str() ); - (inst.*__test)(loc, tested_locales + i); - - { - locale tmp(locale::classic(), tested_locales[i].name, locale::numeric); - loc = tmp; - } - (inst.*__test)(loc, tested_locales + i); - - { - locale tmp(locale::classic(), new numpunct_byname<char>(tested_locales[i].name)); - loc = tmp; - } - (inst.*__test)(loc, tested_locales + i); - } -} - -void LocaleTest::num_put_get() -{ test_supported_locale(*this, &LocaleTest::_num_put_get); } - -void LocaleTest::numpunct_by_name() -{ - /* - * Check of the 22.1.1.2.7 standard point. Construction of a locale - * instance from a null pointer or an unknown name should result in - * a runtime_error exception. - */ -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new numpunct_byname<char>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new numpunct_byname<char>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - string veryLongFacetName("LC_NUMERIC="); - veryLongFacetName.append(512, '?'); - locale loc(locale::classic(), new numpunct_byname<char>(veryLongFacetName.c_str())); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), "C", locale::numeric); - } - catch (runtime_error const& e) { - CPPUNIT_MESSAGE( e.what() ); - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - // On platform without real localization support we should rely on the "C" facet. - locale loc(locale::classic(), "", locale::numeric); - } - catch (runtime_error const& e) { - CPPUNIT_MESSAGE( e.what() ); - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new numpunct_byname<char>("C")); - numpunct<char> const& cfacet_byname = use_facet<numpunct<char> >(loc); - numpunct<char> const& cfacet = use_facet<numpunct<char> >(locale::classic()); - - CPPUNIT_CHECK( cfacet_byname.decimal_point() == cfacet.decimal_point() ); - CPPUNIT_CHECK( cfacet_byname.grouping() == cfacet.grouping() ); - if (!cfacet.grouping().empty()) - CPPUNIT_CHECK( cfacet_byname.thousands_sep() == cfacet.thousands_sep() ); -# if !defined (STLPORT) || !defined (__GLIBC__) - CPPUNIT_CHECK( cfacet_byname.truename() == cfacet.truename() ); - CPPUNIT_CHECK( cfacet_byname.falsename() == cfacet.falsename() ); -# endif - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - // On platform without real localization support we should rely on the "C" locale facet. - locale loc(locale::classic(), new numpunct_byname<char>("")); - } - catch (runtime_error const& e) { - CPPUNIT_MESSAGE( e.what() ); - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) -# if defined (STLPORT) || !defined (__GNUC__) - try { - locale loc(locale::classic(), new numpunct_byname<wchar_t>(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new numpunct_byname<wchar_t>("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif -# endif -} - -#endif diff --git a/test/unit/num_put_get_test.cpp b/test/unit/num_put_get_test.cpp deleted file mode 100644 index 13b250f..0000000 --- a/test/unit/num_put_get_test.cpp +++ /dev/null @@ -1,1266 +0,0 @@ -#include <limits> - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <iomanip> -# include <string> -# include <sstream> -# include <cstdio> -/* -# include <iostream> -# include <ieee754.h> -*/ - -# include "complete_digits.h" -# include "cppunit/cppunit_proxy.h" - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -// -// TestCase class -// -class NumPutGetTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(NumPutGetTest); -# if defined (__BORLANDC__) - /* Ignore FPU exceptions, set FPU precision to 64 bits */ - unsigned int _float_control_word = _control87(0, 0); - _control87(PC_64|MCW_EM|IC_AFFINE, MCW_PC|MCW_EM|MCW_IC); -# endif - CPPUNIT_TEST(num_put_float); - CPPUNIT_TEST(num_put_integer); - CPPUNIT_TEST(num_get_float); - CPPUNIT_TEST(num_get_integer); - CPPUNIT_TEST(inhex); - CPPUNIT_TEST(pointer); - CPPUNIT_TEST(fix_float_long); - CPPUNIT_TEST(custom_numpunct); -# if defined (__BORLANDC__) - /* Reset floating point control word */ - _clear87(); - _control87(_float_control_word, MCW_PC|MCW_EM|MCW_IC); -# endif - CPPUNIT_TEST_SUITE_END(); - -private: - void num_put_float(); - void num_put_integer(); - void num_get_float(); - void num_get_integer(); - void inhex(); - void pointer(); - void fix_float_long(); - void custom_numpunct(); - - static bool check_float(float val, float ref) - { - float epsilon = numeric_limits<float>::epsilon(); - return val <= ref + epsilon && val >= ref - epsilon; - } - - static bool check_double(double val, double ref) - { - double epsilon = numeric_limits<double>::epsilon(); - return val <= ref + epsilon && val >= ref - epsilon; - } - - static string reset_stream(ostringstream &ostr) - { - string tmp = ostr.str(); - ostr.str(""); - return tmp; - } - -#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) - template <class F> - void check_get_float( F v ) - { - F in_val_d = v; - typedef numeric_limits<F> limits; - { - stringstream str; - - str << "1E+" << limits::max_exponent10; - - str >> in_val_d; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d != limits::infinity() ); - } - { - stringstream str; - - str << "-1E+" << limits::max_exponent10; - - str >> in_val_d; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d != -limits::infinity() ); - } - { - stringstream str; - - str << "1E" << limits::min_exponent10; - - str >> in_val_d; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d != F(0.0) ); - } - { - stringstream str; - - str << "1E+" << (limits::max_exponent10 + 1); - - str >> in_val_d; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d == limits::infinity() ); - } - { - stringstream str; - - str << "-1E+" << (limits::max_exponent10 + 1); - - str >> in_val_d; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d == -limits::infinity() ); - } - { - stringstream str; - - str << "1E" << (limits::min_exponent10 - 1); - - str >> in_val_d; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d >= F(0.0) && in_val_d <= limits::min() ); - } -#if !defined (__MINGW32__) - { - stringstream str; - - str << limits::max(); - - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_CHECK( str.str() != "inf" ); - CPPUNIT_CHECK( str.str() != "-inf" ); - CPPUNIT_CHECK( str.str() != "nan" ); - CPPUNIT_CHECK( str.str() != "-nan" ); - //CPPUNIT_MESSAGE( str.str().c_str() ); - - //str.str(""); - //str << limits::max_exponent10; - //CPPUNIT_MESSAGE( str.str().c_str() ); - - str >> in_val_d; - - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d != limits::infinity() ); - } - { - stringstream str; - - str << fixed << limits::max(); - - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_CHECK( str.str() != "inf" ); - CPPUNIT_CHECK( str.str() != "-inf" ); - CPPUNIT_CHECK( str.str() != "nan" ); - CPPUNIT_CHECK( str.str() != "-nan" ); - //CPPUNIT_MESSAGE( str.str().c_str() ); - - //str.str(""); - //str << limits::max_exponent10; - //CPPUNIT_MESSAGE( str.str().c_str() ); - - str >> in_val_d; - - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d != limits::infinity() ); - } - { - stringstream str; - - str << scientific << setprecision(50) << limits::max(); - - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_CHECK( str.str() != "inf" ); - CPPUNIT_CHECK( str.str() != "-inf" ); - CPPUNIT_CHECK( str.str() != "nan" ); - CPPUNIT_CHECK( str.str() != "-nan" ); - //CPPUNIT_MESSAGE( str.str().c_str() ); - - //str.str(""); - //str << limits::max_exponent10; - //CPPUNIT_MESSAGE( str.str().c_str() ); - - str >> in_val_d; - - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_CHECK( in_val_d == in_val_d ); - CPPUNIT_CHECK( in_val_d != limits::infinity() ); - } -#endif - { - stringstream str; - - str << limits::infinity(); - - CPPUNIT_ASSERT( !str.fail() ); - CPPUNIT_ASSERT( !limits::has_infinity || str.str() == "inf" ); - } - { - stringstream str; - - str << -limits::infinity(); - - CPPUNIT_ASSERT( !str.fail() ); - CPPUNIT_ASSERT( !limits::has_infinity || str.str() == "-inf" ); - } - { - stringstream str; - - str << limits::quiet_NaN(); - - CPPUNIT_ASSERT( !str.fail() ); - CPPUNIT_ASSERT( !limits::has_quiet_NaN || str.str() == "nan" ); - } - { - stringstream str; - - str << -limits::quiet_NaN(); - - CPPUNIT_ASSERT( !str.fail() ); - CPPUNIT_ASSERT( !limits::has_quiet_NaN || str.str() == "-nan" ); - } - { - stringstream str; - - str << "0." << string(limits::max_exponent10, '0') << "1e" << (limits::max_exponent10 + 1); - CPPUNIT_ASSERT( !str.fail() ); - - str >> in_val_d; - CPPUNIT_ASSERT( !str.fail() ); - CPPUNIT_ASSERT( str.eof() ); - CPPUNIT_CHECK( in_val_d == 1 ); - } - { - stringstream str; - - str << "1" << string(-(limits::min_exponent10 - 1), '0') << "e" << (limits::min_exponent10 - 1); - CPPUNIT_ASSERT( !str.fail() ); - - str >> in_val_d; - CPPUNIT_ASSERT( !str.fail() ); - CPPUNIT_ASSERT( str.eof() ); - CPPUNIT_CHECK( in_val_d == 1 ); - } -# if defined (_STLPORT_VERSION) && (_STLPORT_VERSION >= 0x530) - // The following tests are showing that simply changing stream - // precision lead to different result. Do not seems to be a real - // problem, simply rounding approximation but additional study should - // be done after 5.2 release. - { - stringstream str; - str << setprecision(limits::digits10 + 2) << limits::max(); - - CPPUNIT_MESSAGE(str.str().c_str()); - CPPUNIT_ASSERT( !str.fail() ); - - F val; - str >> val; - - CPPUNIT_ASSERT( !str.fail() ); - CPPUNIT_ASSERT( limits::infinity() > val ); - } - { - stringstream str; - str << setprecision(limits::digits10 + 1) << limits::max(); - - CPPUNIT_MESSAGE(str.str().c_str()); - CPPUNIT_ASSERT( !str.fail() ); - - F val; - str >> val; - - CPPUNIT_ASSERT( !str.fail() ); - CPPUNIT_ASSERT( limits::infinity() > val ); - } -# endif - } -#else -# define __check_get_float( F ) \ - void check_get_float( F v ) \ - { \ - F in_val_d = v; \ - { \ - stringstream str; \ - \ - str << "1E+" << numeric_limits<F>::max_exponent10; \ - \ - str >> in_val_d; \ - CPPUNIT_ASSERT(!str.fail()); \ - CPPUNIT_ASSERT(str.eof()); \ - CPPUNIT_CHECK( in_val_d == in_val_d ); \ - CPPUNIT_CHECK( in_val_d != numeric_limits<F>::infinity() ); \ - } \ - { \ - stringstream str; \ - \ - str << "-1E+" << numeric_limits<F>::max_exponent10; \ - \ - str >> in_val_d; \ - CPPUNIT_ASSERT(!str.fail()); \ - CPPUNIT_ASSERT(str.eof()); \ - CPPUNIT_CHECK( in_val_d == in_val_d ); \ - CPPUNIT_CHECK( in_val_d != -numeric_limits<F>::infinity() ); \ - } \ - { \ - stringstream str; \ - \ - str << "1E" << numeric_limits<F>::min_exponent10; \ - \ - str >> in_val_d; \ - CPPUNIT_ASSERT(!str.fail()); \ - CPPUNIT_ASSERT(str.eof()); \ - CPPUNIT_CHECK( in_val_d == in_val_d ); \ - CPPUNIT_CHECK( in_val_d != F(0.0) ); \ - } \ - { \ - stringstream str; \ - \ - str << "1E+" << (numeric_limits<F>::max_exponent10 + 1); \ - \ - str >> in_val_d; \ - CPPUNIT_ASSERT(!str.fail()); \ - CPPUNIT_ASSERT(str.eof()); \ - CPPUNIT_CHECK( in_val_d == in_val_d ); \ - CPPUNIT_CHECK( in_val_d == numeric_limits<F>::infinity() ); \ - } \ - { \ - stringstream str; \ - \ - str << "-1E+" << (numeric_limits<F>::max_exponent10 + 1); \ - \ - str >> in_val_d; \ - CPPUNIT_ASSERT(!str.fail()); \ - CPPUNIT_ASSERT(str.eof()); \ - CPPUNIT_CHECK( in_val_d == in_val_d ); \ - CPPUNIT_CHECK( in_val_d == -numeric_limits<F>::infinity() ); \ - } \ - { \ - stringstream str; \ - \ - str << "1E" << (numeric_limits<F>::min_exponent10 - 1); \ - \ - str >> in_val_d; \ - CPPUNIT_ASSERT(!str.fail()); \ - CPPUNIT_ASSERT(str.eof()); \ - CPPUNIT_CHECK( in_val_d == in_val_d ); \ - CPPUNIT_CHECK( in_val_d >= F(0.0) && in_val_d <= numeric_limits<F>::min() ); \ - } \ - } - - __check_get_float( float ) - __check_get_float( double ) -# if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE) - __check_get_float( long double ) -# endif -# undef __check_get_float -#endif // _STLP_NO_MEMBER_TEMPLATES -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(NumPutGetTest); - -#if defined (_MSC_VER) -# pragma warning (disable : 4056) -# pragma warning (disable : 4756) -#endif - -// -// tests implementation -// -void NumPutGetTest::num_put_float() -{ - { - string output, digits; - - { - ostringstream ostr; - ostr << 1.23457e+17f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - digits = "17"; - complete_digits(digits); - CPPUNIT_CHECK(output == string("1.23457e+") + digits ); - } - - { - ostringstream ostr; - ostr << setprecision(200) << 1.23457e+17f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK( output.size() < 200 ); - } - - { - ostringstream ostr; - ostr << setprecision(200) << numeric_limits<float>::min(); - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK( output.size() < 200 ); - } - - { - ostringstream ostr; - ostr << fixed << 1.23457e+17f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output.size() == 25); - CPPUNIT_CHECK(output.substr(0, 5) == "12345"); - CPPUNIT_CHECK(output.substr(18) == ".000000"); - } - - { - ostringstream ostr; - ostr << fixed << showpos << 1.23457e+17f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output.size() == 26); - CPPUNIT_CHECK(output.substr(0, 6) == "+12345"); - CPPUNIT_CHECK(output.substr(19) == ".000000"); - } - - { - ostringstream ostr; - ostr << fixed << showpos << setprecision(100) << 1.23457e+17f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output.size() == 120); - CPPUNIT_CHECK(output.substr(0, 6) == "+12345"); - CPPUNIT_CHECK(output.substr(19) == ".0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ); - } - - { - ostringstream ostr; - ostr << scientific << setprecision(8) << 0.12345678f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - digits = "1"; - complete_digits(digits); - CPPUNIT_CHECK(output == string("1.23456780e-") + digits ); - } - - { - ostringstream ostr; - ostr << fixed << setprecision(8) << setw(30) << setfill('0') << 0.12345678f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output == "000000000000000000000.12345678"); - } - - { - ostringstream ostr; - ostr << fixed << showpos << setprecision(8) << setw(30) << setfill('0') << 0.12345678f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output == "0000000000000000000+0.12345678"); - } - - { - ostringstream ostr; - ostr << fixed << showpos << setprecision(8) << setw(30) << left << setfill('0') << 0.12345678f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output == "+0.123456780000000000000000000"); - } - - { - ostringstream ostr; - ostr << fixed << showpos << setprecision(8) << setw(30) << internal << setfill('0') << 0.12345678f; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output == "+00000000000000000000.12345678"); - } - - { - ostringstream ostr; - ostr << fixed << showpos << setprecision(100) << 1.234567e+17; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output.size() == 120); - CPPUNIT_CHECK(output.substr(0, 6) == "+12345"); - CPPUNIT_CHECK(output.substr(19) == ".0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ); - } - -#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE) - { - ostringstream ostr; - ostr << fixed << showpos << setprecision(100) << 1.234567e+17l; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK(output.size() == 120); - CPPUNIT_CHECK(output.substr(0, 6) == "+12345"); - CPPUNIT_CHECK(output.substr(19) == ".0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ); - } -#endif - - { - ostringstream ostr; - ostr << scientific << setprecision(50) << 0.0; - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - CPPUNIT_CHECK( output == "0.00000000000000000000000000000000000000000000000000e+00" ); - } - { - ostringstream ostr; - ostr << fixed << setprecision(100) << numeric_limits<float>::max(); - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - //CPPUNIT_MESSAGE( output.c_str() ); - } - - { - ostringstream ostr; - ostr << setprecision(100) << numeric_limits<double>::max(); - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - //CPPUNIT_MESSAGE( output.c_str() ); - } - -#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE) - { - ostringstream ostr; - ostr << setprecision(100) << numeric_limits<long double>::max(); - CPPUNIT_ASSERT(ostr.good()); - output = reset_stream(ostr); - //CPPUNIT_MESSAGE( output.c_str() ); - } -#endif - - //{ - // ostringstream ostr; - // ostr << setprecision(-numeric_limits<float>::min_exponent10 + numeric_limits<float>::digits10 + 9) << numeric_limits<float>::min(); - // CPPUNIT_ASSERT(ostr.good()); - // output = reset_stream(ostr); - // //CPPUNIT_MESSAGE( output.c_str() ); - //} - - //{ - // ostringstream ostr; - // ostr << setprecision(-numeric_limits<double>::min_exponent10 + numeric_limits<double>::digits10) << numeric_limits<double>::min(); - // CPPUNIT_ASSERT(ostr.good()); - // output = reset_stream(ostr); - // //CPPUNIT_MESSAGE( output.c_str() ); - //} - -//#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE) -// { -// ostringstream ostr; -// ostr << setprecision(-numeric_limits<long double>::min_exponent10 + numeric_limits<long double>::digits10) << numeric_limits<long double>::min(); -// CPPUNIT_ASSERT(ostr.good()); -// output = reset_stream(ostr); -// CPPUNIT_MESSAGE( output.c_str() ); -// } -//#endif - } - - { - ostringstream str; - - str.setf(ios::fixed, ios::floatfield); - str << 1.0e+5; - // cerr << str.str() << endl; - CPPUNIT_CHECK( str.str() == "100000.000000" ); - - reset_stream(str); - str.precision(0); - str << 1.0e+5; - CPPUNIT_CHECK( str.str() == "100000" ); - - reset_stream(str); - str.precision(4); - str << 1.0e+5; - CPPUNIT_CHECK( str.str() == "100000.0000" ); - - reset_stream(str); - str.precision(0); - str << 1.0e+83; - CPPUNIT_CHECK( str.str().size() == 84 ); - //printf("\nC result: %.0f\n", 1.0e+83); - //CPPUNIT_MESSAGE( str.str().c_str() ); - //CPPUNIT_CHECK( str.str() == "100000000000000000000000000000000000000000000000000000000000000000000000000000000000" ); - - // cerr.setf(ios::fixed, ios::floatfield); - // cerr << DBL_MAX << endl; - // cerr << 1.0e+37 << endl; - } -} - -#define CHECK_COMPLETE(type, val, base, showbase, showpos, casing, width, adjust, expected) \ -{ \ - type tmp = val; \ - ostringstream ostr; \ - ostr << base << showbase << showpos << casing << setw(width) << adjust << tmp; \ - CPPUNIT_CHECK( ostr.str() == expected ); \ -} - -#define CHECK(type, val, base, expected) \ - CHECK_COMPLETE(type, val, base, noshowbase, noshowpos, nouppercase, 0, right, expected) - -void NumPutGetTest::num_put_integer() -{ - //octal outputs - { - CHECK(short, 0, oct, "0") - CHECK(short, 1, oct, "1") - CHECK(short, 12345, oct, "30071") - if (sizeof(short) == 2) { - CHECK(short, -1, oct, "177777") - CHECK(short, -12345, oct, "147707") - } - - CHECK(unsigned short, 0, oct, "0") - CHECK(unsigned short, 12345, oct, "30071") - - CHECK(int, 0, oct, "0") - CHECK(int, 12345678, oct, "57060516") - if (sizeof(int) == 4) { - CHECK(int, -1, oct, "37777777777") - CHECK(int, -12345678, oct, "37720717262") - } - - CHECK(unsigned int, 0, oct, "0") - CHECK(unsigned int, 12345678, oct, "57060516") - - CHECK(long, 0, oct, "0") - CHECK(long, 12345678, oct, "57060516") - if (sizeof(long) == 4) { - CHECK(long, -1, oct, "37777777777") - CHECK(long, -12345678, oct, "37720717262") - } - - CHECK(unsigned long, 0, oct, "0") - CHECK(unsigned long, 12345678, oct, "57060516") - -#if defined (STLPORT) && defined (_STLP_LONG_LONG) - CHECK(_STLP_LONG_LONG, 0, oct, "0") - CHECK(_STLP_LONG_LONG, 12345678, oct, "57060516") - if (sizeof(_STLP_LONG_LONG) == 8) { - CHECK(_STLP_LONG_LONG, -1, oct, "1777777777777777777777") - CHECK(_STLP_LONG_LONG, -12345678, oct, "1777777777777720717262") - } - - CHECK(unsigned _STLP_LONG_LONG, 0, oct, "0") - CHECK(unsigned _STLP_LONG_LONG, 12345678, oct, "57060516") -#endif - - //Even with showbase, 0 value gives "0" (see printf documentation) - CHECK_COMPLETE(short, 0, oct, showbase, noshowpos, nouppercase, 0, right, "0") - CHECK_COMPLETE(short, 0, oct, showbase, showpos, nouppercase, 6, right, " 0") - - CHECK_COMPLETE(short, 1, oct, showbase, noshowpos, nouppercase, 6, right, " 01") - CHECK_COMPLETE(short, 1, oct, showbase, noshowpos, nouppercase, 6, left, "01 ") - CHECK_COMPLETE(short, 1, oct, showbase, showpos, nouppercase, 6, internal, " 01") - } - - //decimal outputs - { - CHECK(short, 0, dec, "0") - CHECK(short, -1, dec, "-1") - CHECK(short, 12345, dec, "12345") - CHECK(short, -12345, dec, "-12345") - - CHECK(unsigned short, 0, dec, "0") - CHECK(unsigned short, 12345, dec, "12345") - - CHECK(int, 0, dec, "0") - CHECK(int, -1, dec, "-1") - CHECK(int, 12345678, dec, "12345678") - CHECK(int, -12345678, dec, "-12345678") - - CHECK(unsigned int, 0, dec, "0") - CHECK(unsigned int, 12345678, dec, "12345678") - - CHECK(long, 0, dec, "0") - CHECK(long, -1, dec, "-1") - CHECK(long, 12345678, dec, "12345678") - CHECK(long, -12345678, dec, "-12345678") - - CHECK(unsigned long, 0, dec, "0") - CHECK(unsigned long, 12345678, dec, "12345678") -#if defined (STLPORT) && defined (_STLP_LONG_LONG) - CHECK(_STLP_LONG_LONG, 0, dec, "0") - CHECK(_STLP_LONG_LONG, -1, dec, "-1") - CHECK(_STLP_LONG_LONG, 12345678, dec, "12345678") - CHECK(_STLP_LONG_LONG, -12345678, dec, "-12345678") - - CHECK(unsigned _STLP_LONG_LONG, 0, dec, "0") - CHECK(unsigned _STLP_LONG_LONG, 12345678, dec, "12345678") -#endif - - CHECK_COMPLETE(short, 0, dec, showbase, showpos, nouppercase, 0, right, "+0") - CHECK_COMPLETE(short, 0, dec, showbase, showpos, nouppercase, 6, right, " +0") - CHECK_COMPLETE(short, 1, dec, showbase, showpos, nouppercase, 6, right, " +1") - CHECK_COMPLETE(short, 1, dec, showbase, showpos, nouppercase, 6, left, "+1 ") - CHECK_COMPLETE(short, 1, dec, showbase, showpos, nouppercase, 6, internal, "+ 1") - } - - //hexadecimal outputs - { - CHECK(short, 0, hex, "0") - CHECK(short, 12345, hex, "3039") - if (sizeof(short) == 2) { - CHECK(short, -1, hex, "ffff") - CHECK(short, -12345, hex, "cfc7") - } - - CHECK(unsigned short, 0, hex, "0") - CHECK(unsigned short, 12345, hex, "3039") - - CHECK(int, 0, hex, "0") - CHECK(int, 12345678, hex, "bc614e") - if (sizeof(int) == 4) { - CHECK(int, -1, hex, "ffffffff") - CHECK(int, -12345678, hex, "ff439eb2") - } - - CHECK(unsigned int, 0, hex, "0") - CHECK(unsigned int, 12345678, hex, "bc614e") - - CHECK(long, 0, hex, "0") - CHECK(long, 12345678, hex, "bc614e") - if (sizeof(long) == 4) { - CHECK(long, -1, hex, "ffffffff") - CHECK(long, -12345678, hex, "ff439eb2") - } - - CHECK(unsigned long, 0, hex, "0") - CHECK(unsigned long, 12345678, hex, "bc614e") -#if defined (STLPORT) && defined (_STLP_LONG_LONG) - CHECK(_STLP_LONG_LONG, 0, hex, "0") - CHECK(_STLP_LONG_LONG, 12345678, hex, "bc614e") - if (sizeof(_STLP_LONG_LONG) == 8) { - CHECK(_STLP_LONG_LONG, -1, hex, "ffffffffffffffff") - CHECK(_STLP_LONG_LONG, -12345678, hex, "ffffffffff439eb2") - } - - CHECK(unsigned _STLP_LONG_LONG, 0, hex, "0") - CHECK(unsigned _STLP_LONG_LONG, 12345678, hex, "bc614e") -#endif - - //Even with showbase, 0 value gives "0" output (see printf documentation) - CHECK_COMPLETE(short, 0, hex, showbase, showpos, nouppercase, 0, right, "0") - CHECK_COMPLETE(short, 0, hex, showbase, noshowpos, nouppercase, 6, right, " 0") - CHECK_COMPLETE(short, 0, hex, showbase, noshowpos, nouppercase, 6, internal, " 0") - - CHECK_COMPLETE(short, 1, hex, showbase, noshowpos, nouppercase, 6, right, " 0x1") - CHECK_COMPLETE(short, 1, hex, showbase, noshowpos, nouppercase, 6, left, "0x1 ") - CHECK_COMPLETE(short, 1, hex, showbase, noshowpos, nouppercase, 6, internal, "0x 1") - CHECK_COMPLETE(short, 1, hex, showbase, noshowpos, uppercase, 6, left, "0X1 ") - CHECK_COMPLETE(short, 1, hex, showbase, showpos, uppercase, 6, internal, "0X 1") - } -} - -void NumPutGetTest::num_get_float() -{ - float in_val; - - istringstream istr; - - istr.str("1.2345"); - istr >> in_val; - CPPUNIT_ASSERT(!istr.fail()); - CPPUNIT_ASSERT(istr.eof()); - CPPUNIT_ASSERT(check_float(in_val, 1.2345f)); - istr.clear(); - - istr.str("-1.2345"); - istr >> in_val; - CPPUNIT_ASSERT(!istr.fail()); - CPPUNIT_ASSERT(istr.eof()); - CPPUNIT_ASSERT(check_float(in_val, -1.2345f)); - istr.clear(); - - istr.str("+1.2345"); - istr >> in_val; - CPPUNIT_ASSERT(!istr.fail()); - CPPUNIT_ASSERT(check_float(in_val, 1.2345f)); - istr.clear(); - - istr.str("000000000000001.234500000000"); - istr >> in_val; - CPPUNIT_ASSERT(!istr.fail()); - CPPUNIT_ASSERT(istr.eof()); - CPPUNIT_ASSERT(check_float(in_val, 1.2345f)); - istr.clear(); - - istr.str("1.2345e+04"); - istr >> in_val; - CPPUNIT_ASSERT(!istr.fail()); - CPPUNIT_ASSERT(istr.eof()); - CPPUNIT_ASSERT(check_float(in_val, 12345.0f)); - istr.clear(); - - CPPUNIT_MESSAGE( "float" ); - check_get_float( 0.0F ); - CPPUNIT_MESSAGE( "double" ); - check_get_float( 0.0 ); -#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE) - CPPUNIT_MESSAGE( "long double" ); - check_get_float( 0.0L ); -#endif - { - stringstream str; - - str << "1e" << numeric_limits<double>::max_exponent10; - CPPUNIT_ASSERT(!str.fail()); - - float val; - str >> val; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_ASSERT( numeric_limits<double>::max_exponent10 <= numeric_limits<float>::max_exponent10 || - val == numeric_limits<float>::infinity() ); - } - { - stringstream str; - - str << "1e" << numeric_limits<double>::min_exponent10; - CPPUNIT_ASSERT(!str.fail()); - - float val; - str >> val; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_ASSERT( numeric_limits<double>::min_exponent10 >= numeric_limits<float>::min_exponent10 || - val == 0.0f ); - } -#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE) - { - stringstream str; - - str << "1e" << numeric_limits<long double>::max_exponent10; - CPPUNIT_ASSERT(!str.fail()); - - double val; - str >> val; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_ASSERT( numeric_limits<long double>::max_exponent10 <= numeric_limits<double>::max_exponent10 || - val == numeric_limits<double>::infinity() ); - } - { - stringstream str; - - str << "1e" << numeric_limits<long double>::min_exponent10; - CPPUNIT_ASSERT(!str.fail()); - - double val; - str >> val; - CPPUNIT_ASSERT(!str.fail()); - CPPUNIT_ASSERT(str.eof()); - CPPUNIT_ASSERT( numeric_limits<long double>::min_exponent10 >= numeric_limits<double>::min_exponent10 || - val == 0.0 ); - } - { - const char* p = "2.718281828459045235360287471352662497757247093e0"; - std::stringstream s; - s << p; - long double x; - s >> x; - CPPUNIT_ASSERT( x > 2.70l && x < 2.72l ); - } -#endif -} - -void NumPutGetTest::num_get_integer() -{ - //octal input - { - istringstream istr; - istr.str("30071"); - short val; - istr >> oct >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == 12345 ); - istr.clear(); - - if (sizeof(short) == 2) { - istr.str("177777"); - istr >> oct >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == -1 ); - istr.clear(); - } - } - - //decimal input - { - istringstream istr; - istr.str("10000"); - short val = -1; - istr >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == 10000 ); - istr.clear(); - - istr.str("+10000"); - val = -1; - istr >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == 10000 ); - istr.clear(); - - if (sizeof(short) == 2) { - val = -1; - istr.str("10000000"); - istr >> val; - CPPUNIT_ASSERT( istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == -1 ); - istr.clear(); - } - - val = -1; - istr.str("0x0"); - istr >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( !istr.eof() ); - CPPUNIT_ASSERT( val == 0 ); - istr.clear(); - - val = -1; - istr.str("000001"); - istr >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == 1 ); - istr.clear(); - } - - //hexadecimal input - { - istringstream istr; - istr.str("3039"); - short val = -1; - istr >> hex >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == 12345 ); - istr.clear(); - - istr.str("x3039"); - val = -1; - istr >> hex >> val; - CPPUNIT_ASSERT( istr.fail() ); - CPPUNIT_ASSERT( !istr.eof() ); - CPPUNIT_ASSERT( val == -1 ); - istr.clear(); - - istr.str("03039"); - val = -1; - istr >> hex >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == 12345 ); - istr.clear(); - - istr.str("0x3039"); - istr >> hex >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == 12345 ); - istr.clear(); - - if (sizeof(short) == 2) { - val = -1; - istr.str("cfc7"); - istr >> hex >> val; - CPPUNIT_ASSERT( !istr.fail() ); - CPPUNIT_ASSERT( istr.eof() ); - CPPUNIT_ASSERT( val == -12345 ); - istr.clear(); - } - } -} - -void NumPutGetTest::inhex() -{ - { - ostringstream s; - s << hex << 0; - CPPUNIT_CHECK( s.str() == "0" ); - } - { - ostringstream s; - s << hex << 0xff; - CPPUNIT_CHECK( s.str() == "ff" ); - } - { - ostringstream s; - s << hex << setw( 4 ) << 0xff; - CPPUNIT_CHECK( s.str() == " ff" ); - } - { - ostringstream s; - s << hex << setw( 4 ) << 0; - CPPUNIT_CHECK( s.str() == " 0" ); - } - { - ostringstream s; - s << hex << showbase << 0; - CPPUNIT_CHECK( s.str() == "0" ); - } - { - ostringstream s; - s << hex << showbase << 0xff; - CPPUNIT_CHECK( s.str() == "0xff" ); - } - { - ostringstream s; - s << hex << showbase << setw( 4 ) << 0xff; - CPPUNIT_CHECK( s.str() == "0xff" ); - } - { // special case for regression (partially duplicate CHECK_COMPLETE above): - ostringstream s; - s.setf( ios_base::internal, ios_base::adjustfield ); - s << hex << showbase << setw(8+2) << 0; - CPPUNIT_CHECK( s.str() == " 0" ); - } -} - -void NumPutGetTest::pointer() -{ - // Problem with printing pointer to null - - /* - * Really C's formatting not help here, due to: - * - * p The argument shall be a pointer to void. The value of - * the pointer is converted to a sequence of printable characters, - * in an implementation-defined manner. - */ - { - /* - char buf[128]; - void *p = (void *)0xff00; - sprintf( buf, "%p", p ); - // cerr << buf << endl; - // Hmmm, I see 0xff00 on box with 32-bits address; pointer like 'unsigned hex'? - if ( sizeof( p ) == 2 ) { - CPPUNIT_ASSERT( strcmp( buf, "0xff00" ) == 0 ); - } else if ( sizeof( p ) == 4 ) { - CPPUNIT_ASSERT( strcmp( buf, "0x0000ff00" ) == 0 ); - } else if ( sizeof( p ) == 8 ) { - CPPUNIT_ASSERT( strcmp( buf, "0x000000000000ff00" ) == 0 ); - } else { - CPPUNIT_CHECK( sizeof( p ) == 2 || sizeof( p ) == 4 || sizeof( p ) == 8 ); - } - */ - } - { - /* - char buf[128]; - void *p = 0; - */ - // sprintf( buf, "%p", p ); - /* Cool. "%p" print '(nil)'; "%#x" print '0' */ - // sprintf( buf, "%#x", (unsigned)p ); - // cerr << buf << endl; - } - { - ostringstream s; - void *p = (void *)0xff00; - s << p; - CPPUNIT_ASSERT( s.good() ); - if ( sizeof( p ) == 2 ) { - CPPUNIT_ASSERT( s.str() == "0xff00" ); - } else if ( sizeof( p ) == 4 ) { - CPPUNIT_ASSERT( s.str() == "0x0000ff00" ); // this pass - } else if ( sizeof( p ) == 8 ) { - CPPUNIT_ASSERT( s.str() == "0x000000000000ff00" ); - } else { - CPPUNIT_CHECK( sizeof( p ) == 2 || sizeof( p ) == 4 || sizeof( p ) == 8 ); - } - } - { - ostringstream s; - void *p = 0; - s << p; - CPPUNIT_ASSERT( s.good() ); - if ( sizeof( p ) == 2 ) { - CPPUNIT_ASSERT( s.str() == "0x0000" ); - } else if ( sizeof( p ) == 4 ) { - CPPUNIT_ASSERT( s.str() == "0x00000000" ); // but this will fail, if follow %p - } else if ( sizeof( p ) == 8 ) { - CPPUNIT_ASSERT( s.str() == "0x0000000000000000" ); - } else { - CPPUNIT_CHECK( sizeof( p ) == 2 || sizeof( p ) == 4 || sizeof( p ) == 8 ); - } - } -} - -void NumPutGetTest::fix_float_long() -{ - ostringstream str; - - str.setf(ios::fixed, ios::floatfield); - str << 1.0e+5; - CPPUNIT_CHECK( str.str() == "100000.000000" ); - - reset_stream(str); - str.precision(0); - str << 1.0e+5; - CPPUNIT_CHECK( str.str() == "100000" ); - - reset_stream(str); - str.precision(4); - str << 1.0e+5; - CPPUNIT_CHECK( str.str() == "100000.0000" ); - - reset_stream(str); - str.precision(0); - str << 1.0e+83; - { - istringstream istr( str.str() ); - double f; - istr >> f; - CPPUNIT_CHECK( !istr.fail() ); - if ( int(numeric_limits<double>::digits10) < 83 ) { - double delta = 1.0; - for ( int ee = 83 - int(numeric_limits<double>::digits10); ee > 0; --ee ) { - delta *= 10.0; - } - // we may loss some digits here, but not more than mantissa: - CPPUNIT_CHECK( (f > (1.0e+83 - delta)) && (f < (1.0e+83 + delta)) ); - } else { - CPPUNIT_CHECK( check_double(f, 1.0e+83) ); - } - } - -#if 0 // #ifndef _STLP_NO_LONG_DOUBLE - reset_stream(str); - str.precision(0); - str << 1.0e+83l; - { - istringstream istr( str.str() ); - long double f; - istr >> f; - CPPUNIT_CHECK( !istr.fail() ); - if ( int(numeric_limits<long double>::digits10) < 83 ) { - long double delta = 1.0l; - for ( int ee = 83 - int(numeric_limits<long double>::digits10); ee > 0; --ee ) { - delta *= 10.0l; - } - // we may loss some digits here, but not more than mantissa: - cerr << "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" << endl; - cerr << str.str() << endl; - cerr << delta << endl; - cerr << f << endl; - CPPUNIT_CHECK( (f > (1.0e+83l - delta)) && (f < (1.0e+83l + delta)) ); - } else { - CPPUNIT_CHECK( check_double(f, 1.0e+83l) ); - } - } -#endif - - reset_stream(str); - str.precision(0); - str << numeric_limits<double>::max(); - { - istringstream istr( str.str() ); - double f; - istr >> f; - CPPUNIT_CHECK( !istr.fail() ); - if ( int(numeric_limits<double>::digits10) < int(numeric_limits<double>::max_exponent10) ) { - double delta = 9.0; - for ( int ee = int(numeric_limits<double>::max_exponent10) - int(numeric_limits<double>::digits10); ee > 0; --ee ) { - delta *= 10.0; - } - // we may loss some digits here, but not more than mantissa: - CPPUNIT_CHECK( (f > (numeric_limits<double>::max() - delta)) ); - } - } - -#if 0 // #ifndef _STLP_NO_LONG_DOUBLE - reset_stream(str); - str.precision(0); - str << numeric_limits<long double>::max(); - { - istringstream istr( str.str() ); - long double f; - istr >> f; - CPPUNIT_CHECK( !istr.fail() ); - if ( int(numeric_limits<long double>::digits10) < int(numeric_limits<long double>::max_exponent10) ) { - long double delta = 1.0l; - for ( int ee = int(numeric_limits<long double>::max_exponent10) - int(numeric_limits<long double>::digits10); ee > 0; --ee ) { - delta *= 10.0l; - } - // we may loss some digits here, but not more than mantissa: - CPPUNIT_CHECK( (f > (numeric_limits<long double>::max() - delta)) ); - } - } -#endif -} - -class CommaSepNumPunct : public numpunct<char> { - char do_thousands_sep() const { return ','; } - string do_grouping() const { return string("\1\2\3") + (char)CHAR_MAX; } -}; - -#define CHECK2(val, expected) \ - os.str(""); os << fixed << setprecision(3) << showpos << val; \ - CPPUNIT_ASSERT( os.str() == expected ) - -void NumPutGetTest::custom_numpunct() -{ - ostringstream os; - locale loc(os.getloc(), new CommaSepNumPunct()); - os.imbue(loc); - - CHECK2(1, "+1"); - CHECK2(10, "+1,0"); - CHECK2(100, "+10,0"); - CHECK2(1000, "+1,00,0"); - - CHECK2(1.234, "+1.234"); - CHECK2(123.456, "+12,3.456"); - CHECK2(1234.567, "+1,23,4.567"); - CHECK2(12345.678, "+12,34,5.678"); - CHECK2(123456.789, "+123,45,6.789"); - CHECK2(1234567.891, "+1,234,56,7.891"); - CHECK2(123456789.123, "+123,456,78,9.123"); - //CHECK2(100000000000000000000000000000.0, "+100000000000000000000000,000,00,0.000"); - CHECK2(numeric_limits<double>::infinity(), "+inf"); - - CHECK2(-1.234, "-1.234"); - CHECK2(-123.456, "-12,3.456"); - CHECK2(-1234.567, "-1,23,4.567"); - CHECK2(-12345.678, "-12,34,5.678"); - CHECK2(-123456.789, "-123,45,6.789"); - CHECK2(-1234567.891, "-1,234,56,7.891"); - CHECK2(-123456789.123, "-123,456,78,9.123"); - //CHECK2(-100000000000000000000000000000.0, "-100000000000000000000000,000,00,0.000"); - CHECK2(-numeric_limits<double>::infinity(), "-inf"); -} - -#endif diff --git a/test/unit/numeric_header_test.cpp b/test/unit/numeric_header_test.cpp deleted file mode 100644 index 38d23dd..0000000 --- a/test/unit/numeric_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <numeric> diff --git a/test/unit/ostmit_test.cpp b/test/unit/ostmit_test.cpp deleted file mode 100644 index f94353e..0000000 --- a/test/unit/ostmit_test.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include <iterator> -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -#include <string> -#include <sstream> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class OstreamIteratorTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(OstreamIteratorTest); - CPPUNIT_TEST(ostmit0); - CPPUNIT_TEST_SUITE_END(); - -protected: - void ostmit0(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(OstreamIteratorTest); - -// -// tests implementation -// -void OstreamIteratorTest::ostmit0() -{ - // not necessary, tested in copy_test - int array [] = { 1, 5, 2, 4 }; - - const char* text = "hello"; - - ostringstream os; - - ostream_iterator<char> iter(os); - copy(text, text + 5, iter); - CPPUNIT_ASSERT(os.good()); - os << ' '; - CPPUNIT_ASSERT(os.good()); - - ostream_iterator<int> iter2(os); - copy(array, array + 4, iter2); - CPPUNIT_ASSERT(os.good()); - CPPUNIT_ASSERT(os.str() == "hello 1524"); -} - -#endif diff --git a/test/unit/ostream_header_test.cpp b/test/unit/ostream_header_test.cpp deleted file mode 100644 index 9c9ccb4..0000000 --- a/test/unit/ostream_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <ostream> -#endif diff --git a/test/unit/pair_test.cpp b/test/unit/pair_test.cpp deleted file mode 100644 index 6fc5172..0000000 --- a/test/unit/pair_test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include <utility> -#include <vector> -#include <algorithm> -#include <string> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -class PairTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(PairTest); - CPPUNIT_TEST(pair0); - CPPUNIT_TEST(init); - CPPUNIT_TEST_SUITE_END(); - - protected: - void pair0(); - void init(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(PairTest); - -void PairTest::pair0() -{ - pair<int, int> p = make_pair(1, 10); - - CPPUNIT_ASSERT(p.first==1); - CPPUNIT_ASSERT(p.second==10); -} - -void PairTest::init() -{ - pair<int, string> PAIR_ARRAY[] = { pair<int, string>(0, "0") }; - - int PAIR_ARRAY_SIZE = sizeof(PAIR_ARRAY) > 0 ? sizeof(PAIR_ARRAY) / sizeof(PAIR_ARRAY[0]) : 0; - - - for ( int i = 0; i < PAIR_ARRAY_SIZE; i++ ) { - CPPUNIT_CHECK( PAIR_ARRAY[i].first == 0 ); - CPPUNIT_CHECK( PAIR_ARRAY[i].second == "0" ); - PAIR_ARRAY[i].second = "1"; - } -} diff --git a/test/unit/partial_test.cpp b/test/unit/partial_test.cpp deleted file mode 100644 index b7650fd..0000000 --- a/test/unit/partial_test.cpp +++ /dev/null @@ -1,248 +0,0 @@ -#include <numeric> -#include <vector> -#include <algorithm> -#include <functional> - -#if defined (STLPORT) && defined (_STLP_DEBUG) && defined (_STLP_DEBUG_MODE_THROWS) -# define _STLP_DO_CHECK_BAD_PREDICATE -# include <stdexcept> -#endif - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class PartialTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(PartialTest); - CPPUNIT_TEST(parsrt0); - CPPUNIT_TEST(parsrt1); - CPPUNIT_TEST(parsrt2); - CPPUNIT_TEST(parsrtc0); - CPPUNIT_TEST(parsrtc1); - CPPUNIT_TEST(parsrtc2); -#if defined (_STLP_DO_CHECK_BAD_PREDICATE) - CPPUNIT_TEST(bad_predicate_detected); -#endif - CPPUNIT_TEST(partsum0); - CPPUNIT_TEST(partsum1); - CPPUNIT_TEST(partsum2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void parsrt0(); - void parsrt1(); - void parsrt2(); - void parsrtc0(); - void parsrtc1(); - void parsrtc2(); - void partsum0(); - void partsum1(); - void partsum2(); - void bad_predicate_detected(); - - static bool str_compare(const char* a_, const char* b_) - { - return strcmp(a_, b_) < 0 ? 1 : 0; - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(PartialTest); - -// -// tests implementation -// -void PartialTest::parsrt0() -{ - int numbers[6] = { 5, 2, 4, 3, 1, 6 }; - - partial_sort((int*)numbers, (int*)numbers + 3, (int*)numbers + 6); - - // 1 2 3 5 4 6 - CPPUNIT_ASSERT(numbers[0]==1); - CPPUNIT_ASSERT(numbers[1]==2); - CPPUNIT_ASSERT(numbers[2]==3); - CPPUNIT_ASSERT(numbers[3]==5); - CPPUNIT_ASSERT(numbers[4]==4); - CPPUNIT_ASSERT(numbers[5]==6); -} - -void PartialTest::parsrt1() -{ - // 8 8 5 3 7 6 5 3 2 4 - // 2 3 3 4 5 8 8 7 6 5 - int numbers[10] ={ 8, 8, 5, 3, 7, 6, 5, 3, 2, 4 }; - - vector <int> v1(numbers, numbers+10); - partial_sort(v1.begin(), v1.begin() + v1.size() / 2, v1.end()); - - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==3); - CPPUNIT_ASSERT(v1[2]==3); - CPPUNIT_ASSERT(v1[3]==4); - CPPUNIT_ASSERT(v1[4]==5); - CPPUNIT_ASSERT(v1[5]==8); - CPPUNIT_ASSERT(v1[6]==8); - CPPUNIT_ASSERT(v1[7]==7); - CPPUNIT_ASSERT(v1[8]==6); - CPPUNIT_ASSERT(v1[9]==5); -} - -void PartialTest::parsrt2() -{ - char const* names[] = { "aa", "ff", "dd", "ee", "cc", "bb" }; - - const unsigned nameSize = sizeof(names) / sizeof(names[0]); - vector <char const*> v1(nameSize); - for(size_t i = 0; i < v1.size(); i++) - v1[i] = names[i]; - - partial_sort(v1.begin(), v1.begin() + nameSize / 2, v1.end(), str_compare); - - // aa bb cc ff ee dd - CPPUNIT_ASSERT( strcmp(v1[0], "aa") == 0 ); - CPPUNIT_ASSERT( v1[0] == names[0] ); - CPPUNIT_ASSERT( strcmp(v1[1], "bb") == 0 ); - CPPUNIT_ASSERT( v1[1] == names[5] ); - CPPUNIT_ASSERT( strcmp(v1[2], "cc") == 0 ); - CPPUNIT_ASSERT( v1[2] == names[4] ); - CPPUNIT_ASSERT( strcmp(v1[3], "ff") == 0 ); - CPPUNIT_ASSERT( v1[3] == names[1] ); - CPPUNIT_ASSERT( strcmp(v1[4], "ee") == 0 ); - CPPUNIT_ASSERT( v1[4] == names[3] ); - CPPUNIT_ASSERT( strcmp(v1[5], "dd") == 0 ); - CPPUNIT_ASSERT( v1[5] == names[2] ); -} - -void PartialTest::parsrtc0() -{ - int numbers[6] = { 5, 2, 4, 3, 1, 6 }; - - int result[3]; - partial_sort_copy((int*)numbers, (int*)numbers + 6, (int*)result, (int*)result + 3); - //1 2 3 - CPPUNIT_ASSERT(result[0]==1); - CPPUNIT_ASSERT(result[1]==2); - CPPUNIT_ASSERT(result[2]==3); -} - -void PartialTest::parsrtc1() -{ - int numbers[10] ={ 3, 0, 4, 3, 2, 8, 2, 7, 7, 5 }; - - //3 0 4 3 2 8 2 7 7 5 - //0 2 2 3 3 - - vector <int> v1(numbers, numbers+10); - vector <int> result(5); - - partial_sort_copy(v1.begin(), v1.end(), result.begin(), result.end()); - CPPUNIT_ASSERT(result[0]==0); - CPPUNIT_ASSERT(result[1]==2); - CPPUNIT_ASSERT(result[2]==2); - CPPUNIT_ASSERT(result[3]==3); - CPPUNIT_ASSERT(result[4]==3); -} - -void PartialTest::parsrtc2() -{ - char const* names[] = { "aa", "ff", "dd", "ee", "cc", "bb" }; - - const unsigned nameSize = sizeof(names) / sizeof(names[0]); - vector <char const*> v1(nameSize); - for(size_t i = 0; i < v1.size(); i++) - v1[i] = names[i]; - vector <char const*> result(3); - partial_sort_copy(v1.begin(), v1.end(), result.begin(), result.end(), str_compare); - - // aa bb cc - CPPUNIT_ASSERT( strcmp( result[0], "aa" ) == 0 ); - CPPUNIT_ASSERT( result[0] == names[0] ); - CPPUNIT_ASSERT( strcmp( result[1], "bb" ) == 0 ); - CPPUNIT_ASSERT( result[1] == names[5] ); - CPPUNIT_ASSERT( strcmp( result[2], "cc" ) == 0 ); - CPPUNIT_ASSERT( result[2] == names[4] ); -} - -#if defined (_STLP_DO_CHECK_BAD_PREDICATE) -void PartialTest::bad_predicate_detected() -{ - int numbers[] = { 0, 0, 1, 0, 0, 1, 0, 0 }; - const size_t s = sizeof(numbers) / sizeof(numbers[0]); - - try { - partial_sort(numbers, numbers + s / 2, numbers + s, less_equal<int>()); - - //Here is means that no exception has been raised - CPPUNIT_ASSERT( false ); - } - catch (runtime_error const&) - { /*OK bad predicate has been detected.*/ } - - try { - vector<int> result(s); - partial_sort_copy(numbers, numbers + s, result.begin(), result.end(), less_equal<int>()); - - //Here is means that no exception has been raised - CPPUNIT_ASSERT( false ); - } - catch (runtime_error const&) - { /*OK bad predicate has been detected.*/ } -} -#endif - -void PartialTest::partsum0() -{ - int numbers[6] = { 1, 2, 3, 4, 5, 6 }; - - int result[6]; - partial_sum((int*)numbers, (int*)numbers + 6, (int*)result); - - // 1 3 6 10 15 21 - CPPUNIT_ASSERT(result[0]==1); - CPPUNIT_ASSERT(result[1]==3); - CPPUNIT_ASSERT(result[2]==6); - CPPUNIT_ASSERT(result[3]==10); - CPPUNIT_ASSERT(result[4]==15); - CPPUNIT_ASSERT(result[5]==21); -} - -void PartialTest::partsum1() -{ - vector <int> v1(10); - __iota(v1.begin(), v1.end(), 0); - vector <int> v2(v1.size()); - partial_sum(v1.begin(), v1.end(), v2.begin()); - - // 0 1 3 6 10 15 21 28 36 45 - CPPUNIT_ASSERT(v2[0]==0); - CPPUNIT_ASSERT(v2[1]==1); - CPPUNIT_ASSERT(v2[2]==3); - CPPUNIT_ASSERT(v2[3]==6); - CPPUNIT_ASSERT(v2[4]==10); - CPPUNIT_ASSERT(v2[5]==15); - CPPUNIT_ASSERT(v2[6]==21); - CPPUNIT_ASSERT(v2[7]==28); - CPPUNIT_ASSERT(v2[8]==36); - CPPUNIT_ASSERT(v2[9]==45); -} - -void PartialTest::partsum2() -{ - vector <int> v1(5); - __iota(v1.begin(), v1.end(), 1); - vector <int> v2(v1.size()); - partial_sum(v1.begin(), v1.end(), v2.begin(), multiplies<int>()); - // 1 2 6 24 120 - CPPUNIT_ASSERT(v2[0]==1); - CPPUNIT_ASSERT(v2[1]==2); - CPPUNIT_ASSERT(v2[2]==6); - CPPUNIT_ASSERT(v2[3]==24); - CPPUNIT_ASSERT(v2[4]==120); -} diff --git a/test/unit/partition_test.cpp b/test/unit/partition_test.cpp deleted file mode 100644 index cc5c91b..0000000 --- a/test/unit/partition_test.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include <algorithm> -#include <vector> -#include <cstdlib> -#include <iterator> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class PartitionTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(PartitionTest); - CPPUNIT_TEST(ptition0); - CPPUNIT_TEST(ptition1); - CPPUNIT_TEST(stblptn0); - CPPUNIT_TEST(stblptn1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void ptition0(); - void ptition1(); - void stblptn0(); - void stblptn1(); - - struct less_n { - less_n(int limit, size_t &nb_calls) - : _limit(limit), _nb_calls(nb_calls) {} - - bool operator() (int a_) const { - ++_nb_calls; - return a_ < _limit; - } - - int _limit; - size_t &_nb_calls; - - private: - //explicitely defined as private to avoid warnings: - less_n& operator = (less_n const&); - }; -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(PartitionTest); - -// -// tests implementation -// -void PartitionTest::stblptn0() -{ - int numbers[6] = { 10, 5, 11, 20, 6, -2 }; - - size_t nb_pred_calls = 0; - stable_partition((int*)numbers, (int*)numbers + 6, less_n(10, nb_pred_calls)); - // 5 6 -2 10 11 20 - CPPUNIT_ASSERT(numbers[0]==5); - CPPUNIT_ASSERT(numbers[1]==6); - CPPUNIT_ASSERT(numbers[2]==-2); - CPPUNIT_ASSERT(numbers[3]==10); - CPPUNIT_ASSERT(numbers[4]==11); - CPPUNIT_ASSERT(numbers[5]==20); - - //Complexity check: - CPPUNIT_ASSERT( nb_pred_calls == sizeof(numbers) / sizeof(numbers[0]) ); -} -void PartitionTest::stblptn1() -{ - //5 5 2 10 0 12 5 0 0 19 - //5 5 2 10 0 5 0 0 12 19 - int numbers[] = { 5, 5, 2, 10, 0, 12, 5, 0, 0, 19 }; - vector <int> v1(numbers, numbers+10); - - size_t nb_pred_calls = 0; - stable_partition(v1.begin(), v1.end(), less_n(11, nb_pred_calls)); - - CPPUNIT_ASSERT(v1[0]==5); - CPPUNIT_ASSERT(v1[1]==5); - CPPUNIT_ASSERT(v1[2]==2); - CPPUNIT_ASSERT(v1[3]==10); - CPPUNIT_ASSERT(v1[4]==0); - CPPUNIT_ASSERT(v1[5]==5); - CPPUNIT_ASSERT(v1[6]==0); - CPPUNIT_ASSERT(v1[7]==0); - CPPUNIT_ASSERT(v1[8]==12); - CPPUNIT_ASSERT(v1[9]==19); - CPPUNIT_ASSERT( nb_pred_calls == v1.size() ); -} -void PartitionTest::ptition0() -{ - int numbers[6] = { 6, 12, 3, 10, 1, 20 }; - size_t nb_pred_calls = 0; - // 6 1 3 10 12 20 - partition((int*)numbers, (int*)numbers + 6, less_n(10, nb_pred_calls)); - CPPUNIT_ASSERT(numbers[0]==6); - CPPUNIT_ASSERT(numbers[1]==1); - CPPUNIT_ASSERT(numbers[2]==3); - CPPUNIT_ASSERT(numbers[3]==10); - CPPUNIT_ASSERT(numbers[4]==12); - CPPUNIT_ASSERT(numbers[5]==20); - - CPPUNIT_ASSERT( nb_pred_calls == sizeof(numbers) / sizeof(numbers[0]) ); -} -void PartitionTest::ptition1() -{ - // 19 3 11 14 10 19 8 17 9 6 - // 6 3 9 8 10 19 14 17 11 19 - - int numbers[10] ={ 19, 3, 11, 14, 10, 19, 8, 17, 9, 6 }; - - vector <int> v1(numbers, numbers+10); - size_t nb_pred_calls = 0; - partition(v1.begin(), v1.end(), less_n(11, nb_pred_calls)); - - CPPUNIT_ASSERT(v1[0]==6); - CPPUNIT_ASSERT(v1[1]==3); - CPPUNIT_ASSERT(v1[2]==9); - CPPUNIT_ASSERT(v1[3]==8); - CPPUNIT_ASSERT(v1[4]==10); - CPPUNIT_ASSERT(v1[5]==19); - CPPUNIT_ASSERT(v1[6]==14); - CPPUNIT_ASSERT(v1[7]==17); - CPPUNIT_ASSERT(v1[8]==11); - CPPUNIT_ASSERT(v1[9]==19); - CPPUNIT_ASSERT( nb_pred_calls == v1.size() ); -} diff --git a/test/unit/perm_test.cpp b/test/unit/perm_test.cpp deleted file mode 100644 index 5be6ea0..0000000 --- a/test/unit/perm_test.cpp +++ /dev/null @@ -1,228 +0,0 @@ -#include <vector> -#include <algorithm> -#include <numeric> -#include <iterator> -#include <functional> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class PermTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(PermTest); - CPPUNIT_TEST(nextprm0); - CPPUNIT_TEST(nextprm1); - CPPUNIT_TEST(nextprm2); - CPPUNIT_TEST(prevprm0); - CPPUNIT_TEST(prevprm1); - CPPUNIT_TEST(prevprm2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void nextprm0(); - void nextprm1(); - void nextprm2(); - void prevprm0(); - void prevprm1(); - void prevprm2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(PermTest); - -// -// tests implementation -// -void PermTest::prevprm0() -{ - int v1[3] = { 0, 1, 2 }; - prev_permutation(v1, v1 + 3); - - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==0); -} -void PermTest::prevprm1() -{ - vector <int> v1(3); - __iota(v1.begin(), v1.end(), 0); - - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==0); - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==1); - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==0); - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==2); - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==2);// - CPPUNIT_ASSERT(v1[2]==1); - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==2); - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==0); - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==1); - prev_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==0); -} -void PermTest::prevprm2() -{ - vector <int> v1(3); - __iota(v1.begin(), v1.end(), 0); - - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==1); - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==2); - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==0); - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==1); - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==0); - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==2); - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==1); - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==2); - prev_permutation(v1.begin(), v1.end(), greater<int>()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==0); -} -void PermTest::nextprm0() -{ - int v1[3] = { 0, 1, 2 }; - next_permutation(v1, v1 + 3); - - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==1); -} -void PermTest::nextprm1() -{ - vector <int> v1(3); - __iota(v1.begin(), v1.end(), 0); - - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==1); - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==2); - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==0); - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==1); - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==2); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==0); - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==2); - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==1); - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==0); - CPPUNIT_ASSERT(v1[2]==2); - next_permutation(v1.begin(), v1.end()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==0); -} -void PermTest::nextprm2() -{ - vector <char> v1(3); - __iota(v1.begin(), v1.end(), 'A'); - - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='A'); - CPPUNIT_ASSERT(v1[1]=='C'); - CPPUNIT_ASSERT(v1[2]=='B'); - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='B'); - CPPUNIT_ASSERT(v1[1]=='A'); - CPPUNIT_ASSERT(v1[2]=='C'); - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='B'); - CPPUNIT_ASSERT(v1[1]=='C'); - CPPUNIT_ASSERT(v1[2]=='A'); - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='C'); - CPPUNIT_ASSERT(v1[1]=='A'); - CPPUNIT_ASSERT(v1[2]=='B'); - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='C'); - CPPUNIT_ASSERT(v1[1]=='B'); - CPPUNIT_ASSERT(v1[2]=='A'); - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='A'); - CPPUNIT_ASSERT(v1[1]=='B'); - CPPUNIT_ASSERT(v1[2]=='C'); - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='A'); - CPPUNIT_ASSERT(v1[1]=='C'); - CPPUNIT_ASSERT(v1[2]=='B'); - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='B'); - CPPUNIT_ASSERT(v1[1]=='A'); - CPPUNIT_ASSERT(v1[2]=='C'); - next_permutation(v1.begin(), v1.end(), less<char>()); - CPPUNIT_ASSERT(v1[0]=='B'); - CPPUNIT_ASSERT(v1[1]=='C'); - CPPUNIT_ASSERT(v1[2]=='A'); - -} diff --git a/test/unit/plusminus_test.cpp b/test/unit/plusminus_test.cpp deleted file mode 100644 index ee6f5c6..0000000 --- a/test/unit/plusminus_test.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include <numeric> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class PlusMinusTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(PlusMinusTest); - CPPUNIT_TEST(plus0); - CPPUNIT_TEST(minus0); - CPPUNIT_TEST_SUITE_END(); - -protected: - void plus0(); - void minus0(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(PlusMinusTest); - -// -// tests implementation -// -void PlusMinusTest::plus0() -{ - int input1 [4] = { 1, 6, 11, 8 }; - int input2 [4] = { 1, 5, 2, 3 }; - - int total = inner_product(input1, input1 + 4, input2, 0, plus<int>(), multiplies <int>()); - - CPPUNIT_ASSERT(total==77); -} -void PlusMinusTest::minus0() -{ - int input1 [4] = { 1, 5, 7, 8 }; - int input2 [4] = { 1, 4, 8, 3 }; - - int output [4]; - - transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, minus<int>()); - CPPUNIT_ASSERT(output[0]==0); - CPPUNIT_ASSERT(output[1]==1); - CPPUNIT_ASSERT(output[2]==-1); - CPPUNIT_ASSERT(output[3]==5); -} diff --git a/test/unit/ptr2_test.cpp b/test/unit/ptr2_test.cpp deleted file mode 100644 index 9a1155c..0000000 --- a/test/unit/ptr2_test.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class Ptr2Test : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(Ptr2Test); - CPPUNIT_TEST(ptrbin1); - CPPUNIT_TEST(ptrbin2); - CPPUNIT_TEST(ptrun1); - CPPUNIT_TEST(ptrun2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void ptrbin1(); - void ptrbin2(); - void ptrun1(); - void ptrun2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(Ptr2Test); - -// -// tests implementation -// -static int sum(int x_, int y_) -{ - return x_ + y_; -} -bool even(int n_) -{ - return(n_ % 2) == 0; -} -void Ptr2Test::ptrbin1() -{ - int input1 [4] = { 7, 2, 3, 5 }; - int input2 [4] = { 1, 5, 5, 8 }; - - int output [4]; - transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, pointer_to_binary_function<int, int, int>(sum)); - - CPPUNIT_ASSERT(output[0]==8); - CPPUNIT_ASSERT(output[1]==7); - CPPUNIT_ASSERT(output[2]==8); - CPPUNIT_ASSERT(output[3]==13); -} -void Ptr2Test::ptrbin2() -{ - int input1 [4] = { 7, 2, 3, 5 }; - int input2 [4] = { 1, 5, 5, 8 }; - - int output [4]; - transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, ptr_fun(sum)); - - CPPUNIT_ASSERT(output[0]==8); - CPPUNIT_ASSERT(output[1]==7); - CPPUNIT_ASSERT(output[2]==8); - CPPUNIT_ASSERT(output[3]==13); -} -void Ptr2Test::ptrun1() -{ - int array [3] = { 1, 2, 3 }; - - int* p = find_if((int*)array, (int*)array + 3, pointer_to_unary_function<int, bool>(even)); - CPPUNIT_ASSERT(p != array+3); - CPPUNIT_ASSERT(*p==2); -} -void Ptr2Test::ptrun2() -{ - int array [3] = { 1, 2, 3 }; - - int* p = find_if((int*)array, (int*)array + 3, ptr_fun(even)); - CPPUNIT_ASSERT(p != array+3); - CPPUNIT_ASSERT(*p==2); -} diff --git a/test/unit/ptrspec_test.cpp b/test/unit/ptrspec_test.cpp deleted file mode 100644 index 6d0fcf5..0000000 --- a/test/unit/ptrspec_test.cpp +++ /dev/null @@ -1,232 +0,0 @@ -#include <vector> -#include <list> -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <slist> -#endif -#include <deque> -#include <set> -#include <iterator> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class PtrSpecTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(PtrSpecTest); - CPPUNIT_TEST(ptr_specialization_test); - CPPUNIT_TEST(function_pointer); - CPPUNIT_TEST_SUITE_END(); - -protected: - /// this seems to be compile only test but... - void ptr_specialization_test(); - void function_pointer(); - - template <class _Tp> - struct unary_pred { - bool operator () (_Tp *__ptr) const { - return *__ptr == 0; - } - }; - - template <class _Tp> - struct binary_pred { - bool operator () (_Tp *__first, _Tp *__second) const { - return *__first < *__second; - } - }; -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(PtrSpecTest); - -#define TEST_INSTANCIATE_CONTAINER(cont) \ - template class cont<int*>; \ - template class cont<int const*>; \ - template class cont<int volatile*>; \ - template class cont<int const volatile*> - -#if !defined(_MSC_VER) || (_MSC_VER > 1200) // excluding MSVC 6.0 -TEST_INSTANCIATE_CONTAINER(vector); -TEST_INSTANCIATE_CONTAINER(list); -# if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -TEST_INSTANCIATE_CONTAINER(slist); -# endif -TEST_INSTANCIATE_CONTAINER(deque); -TEST_INSTANCIATE_CONTAINER(set); -TEST_INSTANCIATE_CONTAINER(multiset); -#endif - -//Function to test pointer to function support: -void FTypeInstance() {} - -//Class to test pointer to member method support: -class AClass { -public: - void func() {} -}; - -// -// tests implementation -// -void PtrSpecTest::ptr_specialization_test() -{ - int *int_array[] = {0, 0, 0}; - int const* cint_array[] = {0, 0, 0}; - - { - vector<void*> void_vect; - deque<void*> void_deque; - list<void*> void_list; -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - slist<void*> void_slist; -#endif - } - - { - typedef void (*FType)(); - vector<FType> func_vector; - func_vector.push_back(&FTypeInstance); - } - -#if !defined(__GNUC__) || (__GNUC__ > 2) - { - typedef void (AClass::*MFType)(); - vector<MFType> mem_func_vector; - mem_func_vector.push_back(&AClass::func); - } -#endif - - vector<int*> pint_vect; - vector<int*> pint_vect2; - vector<int const*> pcint_vect; - list<int*> pint_list; - list<int*> pint_list2; - list<int const*> pcint_list; -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - slist<int*> pint_slist; - slist<int*> pint_slist2; - slist<int const*> pcint_slist; -#endif - deque<int*> pint_deque; - deque<int*> pint_deque2; - deque<int const*> pcint_deque; - -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES) - vector<int*> pint_vect_from_list(pint_list.begin(), pint_list.end()); -#endif - pint_vect.insert(pint_vect.end(), pint_vect2.begin(), pint_vect2.end()); - pint_vect.insert(pint_vect.end(), int_array, int_array + 3); - pint_vect2.insert(pint_vect2.end(), int_array, int_array + 3); - pcint_vect.insert(pcint_vect.end(), int_array, int_array + 3); - pcint_vect.insert(pcint_vect.end(), cint_array, cint_array + 3); -#if !defined (STLPORT) || !defined(_STLP_DEBUG) || defined(_STLP_MEMBER_TEMPLATES) - pcint_vect.insert(pcint_vect.end(), pint_vect2.begin(), pint_vect2.end()); -#endif - pcint_vect.insert(pcint_vect.end(), int_array, int_array + 3); -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES) - pint_vect.insert(pint_vect.end(), pint_list.begin(), pint_list.end()); - pcint_vect.insert(pcint_vect.end(), pint_list.begin(), pint_list.end()); - pcint_vect.insert(pcint_vect.end(), pcint_list.begin(), pcint_list.end()); - pint_vect.assign(pint_list.begin(), pint_list.end()); - pcint_vect.assign(pint_list.begin(), pint_list.end()); -#endif - pint_vect.assign(int_array, int_array + 3); - pcint_vect.assign(int_array, int_array + 3); - pcint_vect.assign(cint_array, cint_array + 3); - copy(int_array, int_array + 3, back_inserter(pint_vect)); - -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES) - pint_list.sort(binary_pred<int>()); - pcint_list.sort(binary_pred<int const>()); - pint_list.unique(binary_pred<int>()); - pcint_list.unique(binary_pred<int const>()); - pint_list.merge(pint_list, binary_pred<int>()); - pcint_list.merge(pcint_list, binary_pred<int const>()); - pint_list.remove_if(unary_pred<int>()); - pcint_list.remove_if(unary_pred<int const>()); -#endif - - copy(int_array, int_array + 3, back_inserter(pint_list)); - copy(int_array, int_array + 3, back_inserter(pint_list2)); - pint_list.insert(pint_list.end(), pint_list2.begin(), pint_list2.end()); -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES) - pcint_list.insert(pcint_list.end(), pint_list.begin(), pint_list.end()); -#endif -#if !defined (STLPORT) || !defined(_STLP_DEBUG) || defined(_STLP_MEMBER_TEMPLATES) - pint_list.insert(pint_list.end(), pint_vect.begin(), pint_vect.end()); - pcint_list.insert(pcint_list.end(), pint_vect.begin(), pint_vect.end()); - pcint_list.insert(pcint_list.end(), pcint_vect.begin(), pcint_vect.end()); - list<int*> pint_list_from_vect(pint_vect.begin(), pint_vect.end()); - pint_list.assign(pint_vect.begin(), pint_vect.end()); - pcint_list.assign(pint_vect.begin(), pint_vect.end()); -#endif - pint_list.insert(pint_list.begin(), int_array, int_array + 3); - pint_list.insert(pint_list.end(), int_array, int_array + 3); - pcint_list.insert(pcint_list.end(), int_array, int_array + 3); - pcint_list.insert(pcint_list.end(), cint_array, cint_array + 3); - pint_list.assign(int_array, int_array + 3); - pcint_list.assign(int_array, int_array + 3); - pcint_list.assign(cint_array, cint_array + 3); - //pint_list.assign(pcint_vect.begin(), pcint_vect.end()); - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - copy(int_array, int_array + 3, front_inserter(pint_slist)); - copy(int_array, int_array + 3, front_inserter(pint_slist2)); - pint_slist.insert(pint_slist.end(), pint_slist2.begin(), pint_slist2.end()); -# if defined (_STLP_MEMBER_TEMPLATES) - pcint_slist.insert(pcint_slist.end(), pint_slist.begin(), pint_slist.end()); -# endif -# if !defined (_STLP_DEBUG) || defined (_STLP_MEMBER_TEMPLATES) - pint_slist.insert(pint_slist.end(), pint_vect.begin(), pint_vect.end()); - pcint_slist.insert(pcint_slist.end(), pint_vect.begin(), pint_vect.end()); - pcint_slist.insert(pcint_slist.end(), pcint_vect.begin(), pcint_vect.end()); - slist<int*> pint_slist_from_vect(pint_vect.begin(), pint_vect.end()); - pint_slist.assign(pint_vect.begin(), pint_vect.end()); - pcint_slist.assign(pint_vect.begin(), pint_vect.end()); -# endif - pint_slist.insert(pint_slist.end(), int_array, int_array + 3); - pcint_slist.insert(pcint_slist.end(), int_array, int_array + 3); - pcint_slist.insert(pcint_slist.end(), cint_array, cint_array + 3); - pint_slist.assign(int_array, int_array + 3); - pcint_slist.assign(int_array, int_array + 3); - pcint_slist.assign(cint_array, cint_array + 3); - //pint_slist.assign(pcint_vect.begin(), pcint_vect.end()); -#endif - - copy(int_array, int_array + 3, back_inserter(pint_deque)); - copy(int_array, int_array + 3, back_inserter(pint_deque2)); - pint_deque.insert(pint_deque.end(), pint_deque2.begin(), pint_deque2.end()); -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES) - pcint_deque.insert(pcint_deque.end(), pint_deque.begin(), pint_deque.end()); -#endif -#if !defined (STLPORT) || !defined(_STLP_DEBUG) || defined(_STLP_MEMBER_TEMPLATES) - pint_deque.insert(pint_deque.end(), pint_vect.begin(), pint_vect.end()); - pcint_deque.insert(pcint_deque.end(), pint_vect.begin(), pint_vect.end()); - pcint_deque.insert(pcint_deque.end(), pcint_vect.begin(), pcint_vect.end()); - deque<int*> pint_deque_from_vect(pint_vect.begin(), pint_vect.end()); - pint_deque.assign(pint_vect.begin(), pint_vect.end()); - pcint_deque.assign(pint_vect.begin(), pint_vect.end()); -#endif - pint_deque.insert(pint_deque.end(), int_array, int_array + 3); - pcint_deque.insert(pcint_deque.end(), int_array, int_array + 3); - pcint_deque.insert(pcint_deque.end(), cint_array, cint_array + 3); - pint_deque.assign(int_array, int_array + 3); - pcint_deque.assign(int_array, int_array + 3); - pcint_deque.assign(cint_array, cint_array + 3); -} - -typedef void (*Func)(int); -void f1(int) {} - -void PtrSpecTest::function_pointer() -{ - vector<Func> fs; - fs.push_back(&f1); - CPPUNIT_ASSERT( !fs.empty() ); -} diff --git a/test/unit/queue_header_test.cpp b/test/unit/queue_header_test.cpp deleted file mode 100644 index 4149c22..0000000 --- a/test/unit/queue_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <queue> diff --git a/test/unit/queue_test.cpp b/test/unit/queue_test.cpp deleted file mode 100644 index 2e6add3..0000000 --- a/test/unit/queue_test.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include <vector> -#include <algorithm> -#include <list> -#include <deque> -#include <queue> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class QueueTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(QueueTest); - CPPUNIT_TEST(pqueue1); - CPPUNIT_TEST(queue1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void pqueue1(); - void queue1(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(QueueTest); - -// -// tests implementation -// -void QueueTest::pqueue1() -{ - priority_queue<int, deque<int>, less<int> > q; - q.push(42); - q.push(101); - q.push(69); - - CPPUNIT_ASSERT( q.top()==101 ); - q.pop(); - CPPUNIT_ASSERT( q.top()==69 ); - q.pop(); - CPPUNIT_ASSERT( q.top()==42 ); - q.pop(); - - CPPUNIT_ASSERT(q.empty()); -} -void QueueTest::queue1() -{ - queue<int, list<int> > q; - q.push(42); - q.push(101); - q.push(69); - - CPPUNIT_ASSERT( q.front()==42 ); - q.pop(); - CPPUNIT_ASSERT( q.front()==101 ); - q.pop(); - CPPUNIT_ASSERT( q.front()==69 ); - q.pop(); - - CPPUNIT_ASSERT(q.empty()); -} diff --git a/test/unit/rawriter_test.cpp b/test/unit/rawriter_test.cpp deleted file mode 100644 index 0c8438a..0000000 --- a/test/unit/rawriter_test.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include <algorithm> -#include <iterator> -#include <memory> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -class X -{ - public: - X(int i_ = 0) : i(i_) {} - ~X() {} - operator int() const { return i; } - - private: - int i; -}; - - -// -// TestCase class -// -class RawriterTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(RawriterTest); - CPPUNIT_TEST(rawiter1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void rawiter1(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(RawriterTest); - -// -// tests implementation -// -void RawriterTest::rawiter1() -{ - allocator<X> a; - typedef X* x_pointer; - x_pointer save_p, p; - p = a.allocate(5); - save_p=p; - raw_storage_iterator<X*, X> r(p); - int i; - for(i = 0; i < 5; i++) - *r++ = X(i); - - CPPUNIT_ASSERT(*p++ == 0); - CPPUNIT_ASSERT(*p++ == 1); - CPPUNIT_ASSERT(*p++ == 2); - CPPUNIT_ASSERT(*p++ == 3); - CPPUNIT_ASSERT(*p++ == 4); - -//#if defined (STLPORT) || defined (__GNUC__) - a.deallocate(save_p, 5); -/* -#else - a.deallocate(save_p); -#endif -*/ -} diff --git a/test/unit/reference_wrapper_test.cpp b/test/unit/reference_wrapper_test.cpp deleted file mode 100644 index 4e3fb41..0000000 --- a/test/unit/reference_wrapper_test.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include <functional> - -#if !defined(_STLP_NO_EXTENSIONS) && defined(_STLP_USE_BOOST_SUPPORT) - -#include <typeinfo> -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -class RefWrapperTest : - public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(RefWrapperTest); - CPPUNIT_TEST(ref); - CPPUNIT_TEST(cref); - CPPUNIT_TEST_SUITE_END(); - - protected: - void ref(); - void cref(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(RefWrapperTest); - -void RefWrapperTest::ref() -{ - typedef std::tr1::reference_wrapper<int> rr_type; - - CPPUNIT_CHECK( (::boost::is_convertible<rr_type, int&>::value) ); - CPPUNIT_CHECK( (::boost::is_same<rr_type::type, int>::value) ); - - int i = 1; - int j = 2; - - rr_type r1 = std::tr1::ref(i); - - CPPUNIT_CHECK( r1.get() == 1 ); - - r1 = std::tr1::ref(j); - - CPPUNIT_CHECK( r1.get() == 2 ); - - i = 3; - - CPPUNIT_CHECK( r1.get() == 2 ); - - j = 4; - - CPPUNIT_CHECK( r1.get() == 4 ); - - r1.get() = 5; - - CPPUNIT_CHECK( j == 5 ); -} - -void RefWrapperTest::cref() -{ - typedef std::tr1::reference_wrapper<const int> crr_type; - - CPPUNIT_CHECK( (::boost::is_convertible<crr_type, const int&>::value) ); - CPPUNIT_CHECK( (::boost::is_same<crr_type::type, const int>::value) ); - - int i = 1; - int j = 2; - - crr_type r1 = std::tr1::cref(i); - - CPPUNIT_CHECK( r1.get() == 1 ); - - r1 = std::tr1::cref(j); - - CPPUNIT_CHECK( r1.get() == 2 ); - - i = 3; - - CPPUNIT_CHECK( r1.get() == 2 ); - - j = 4; - - CPPUNIT_CHECK( r1.get() == 4 ); -} - -#endif /* !_STLP_NO_EXTENSIONS && _STLP_USE_BOOST_SUPPORT */ diff --git a/test/unit/resolve_name.cpp b/test/unit/resolve_name.cpp deleted file mode 100644 index dc7c123..0000000 --- a/test/unit/resolve_name.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#define _STLP_DO_IMPORT_CSTD_FUNCTIONS -#include <cmath> - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) - -namespace NS1 { - -bool f() -{ - double d( 1.0 ); - - d = sqrt( d ); - d = ::sqrt( d ); - d = std::sqrt( d ); - return d == 1.0; -} - -} - -namespace { - -bool g() -{ - double d( 1.0 ); - - d = sqrt( d ); - d = ::sqrt( d ); - d = std::sqrt( d ); - return d == 1.0; -} - -} - -// VC6 consider call to sqrt ambiguous as soon as using namespace std has -// been invoked. -#if !defined (STLPORT) || !defined (_STLP_MSVC) || (_STLP_MSVC >= 1300) -using namespace std; -#endif - -bool h() -{ - double d( 1.0 ); - - d = sqrt( d ); - d = ::sqrt( d ); - d = std::sqrt( d ); - return d == 1.0; -} - -struct sq -{ - sq() {} - - double sqroot( double x ) { - using std::sqrt; - return sqrt(x); - } -}; - -#endif - - -#if 0 // Do nothing, this should be compiled only - -#include "cppunit/cppunit_proxy.h" - -class ResolveNameTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ResolveNameTest); - CPPUNIT_TEST(cstyle); - CPPUNIT_TEST_SUITE_END(); - -protected: - void cstyle(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ResolveNameTest); - -void ResolveNameTest::cstyle() -{ -} - -#endif diff --git a/test/unit/reviter_test.cpp b/test/unit/reviter_test.cpp deleted file mode 100644 index 15a3c34..0000000 --- a/test/unit/reviter_test.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include <vector> -#include <list> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class ReviterTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ReviterTest); - CPPUNIT_TEST(reviter1); - CPPUNIT_TEST(reviter2); - CPPUNIT_TEST(revbit1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void reviter1(); - void reviter2(); - void revbit1(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ReviterTest); - -// -// tests implementation -// -void ReviterTest::reviter1() -{ - int array [] = { 1, 5, 2, 3 }; - - vector<int> v(array, array + 4); - typedef vector<int>::reverse_iterator reviter; - reviter r(v.rend()); - r--; - - CPPUNIT_ASSERT(*r-- == 1); - CPPUNIT_ASSERT(*r-- == 5); - CPPUNIT_ASSERT(*r-- == 2); - CPPUNIT_ASSERT(*r == 3); - CPPUNIT_ASSERT(r==v.rbegin()); -} -void ReviterTest::reviter2() -{ - int array [] = { 1, 5, 2, 3 }; - - vector<int> v(array, array + 4); - vector<int>::reverse_iterator r; - r = v.rbegin(); - CPPUNIT_ASSERT(*r++ == 3); - CPPUNIT_ASSERT(*r++ == 2); - CPPUNIT_ASSERT(*r++ == 5); - CPPUNIT_ASSERT(*r++ == 1); - CPPUNIT_ASSERT(r==v.rend()); -} -void ReviterTest::revbit1() -{ - int array [] = { 1, 5, 2, 3 }; - - list<int> v(array, array + 4); - list<int>::reverse_iterator r(v.rbegin()); - CPPUNIT_ASSERT(*r++ == 3); - CPPUNIT_ASSERT(*r++ == 2); - CPPUNIT_ASSERT(*r++ == 5); - CPPUNIT_ASSERT(*r++ == 1); - CPPUNIT_ASSERT(r==v.rend()); -} diff --git a/test/unit/rm_cp_test.cpp b/test/unit/rm_cp_test.cpp deleted file mode 100644 index 3e3a4d6..0000000 --- a/test/unit/rm_cp_test.cpp +++ /dev/null @@ -1,245 +0,0 @@ -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class RmCpTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(RmCpTest); - CPPUNIT_TEST(remcopy1); - CPPUNIT_TEST(remcpif1); - CPPUNIT_TEST(remif1); - CPPUNIT_TEST(remove1); - CPPUNIT_TEST(repcpif1); - CPPUNIT_TEST(replace0); - CPPUNIT_TEST(replace1); - CPPUNIT_TEST(replcpy1); - CPPUNIT_TEST(replif1); - CPPUNIT_TEST(revcopy1); - CPPUNIT_TEST(reverse1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void remcopy1(); - void remcpif1(); - void remif1(); - void remove1(); - void repcpif1(); - void replace0(); - void replace1(); - void replcpy1(); - void replif1(); - void revcopy1(); - void reverse1(); - -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(RmCpTest); - -static bool odd(int a_) -{ - return (a_ % 2) != 0; -} -// -// tests implementation -// - -void RmCpTest::reverse1() -{ - int numbers[6] = { 0, 1, 2, 3, 4, 5 }; - - reverse(numbers, numbers + 6); - CPPUNIT_ASSERT(numbers[0]==5); - CPPUNIT_ASSERT(numbers[1]==4); - CPPUNIT_ASSERT(numbers[2]==3); - CPPUNIT_ASSERT(numbers[3]==2); - CPPUNIT_ASSERT(numbers[4]==1); - CPPUNIT_ASSERT(numbers[5]==0); -} - -void RmCpTest::revcopy1() -{ - int numbers[6] = { 0, 1, 2, 3, 4, 5 }; - - int result[6]; - reverse_copy((int*)numbers, (int*)numbers + 6, (int*)result); - // 5 4 3 2 1 0 - CPPUNIT_ASSERT(result[0]==5); - CPPUNIT_ASSERT(result[1]==4); - CPPUNIT_ASSERT(result[2]==3); - CPPUNIT_ASSERT(result[3]==2); - CPPUNIT_ASSERT(result[4]==1); - CPPUNIT_ASSERT(result[5]==0); -} - -void RmCpTest::replif1() -{ - vector <int> v1(10); - for (int i = 0; (size_t)i < v1.size(); ++i) - v1[i] = i % 5; - - replace_if(v1.begin(), v1.end(), odd, 42); - - // 0 42 2 42 4 0 42 2 42 4 - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==42); - CPPUNIT_ASSERT(v1[2]==2); - CPPUNIT_ASSERT(v1[3]==42); - CPPUNIT_ASSERT(v1[4]==4); - CPPUNIT_ASSERT(v1[5]==0); - CPPUNIT_ASSERT(v1[6]==42); - CPPUNIT_ASSERT(v1[7]==2); - CPPUNIT_ASSERT(v1[8]==42); - CPPUNIT_ASSERT(v1[9]==4); -} - -void RmCpTest::replcpy1() -{ - int numbers[6] = { 0, 1, 2, 0, 1, 2 }; - int result[6] = { 0, 0, 0, 0, 0, 0 }; - - replace_copy((int*)numbers, (int*)numbers + 6, (int*)result, 2, 42); - CPPUNIT_ASSERT(result[0]==0); - CPPUNIT_ASSERT(result[1]==1); - CPPUNIT_ASSERT(result[2]==42); - CPPUNIT_ASSERT(result[3]==0); - CPPUNIT_ASSERT(result[4]==1); - CPPUNIT_ASSERT(result[5]==42); -} - -void RmCpTest::replace0() -{ - int numbers[6] = { 0, 1, 2, 0, 1, 2 }; - - replace(numbers, numbers + 6, 2, 42); - - // 0 1 42 0 1 42 - CPPUNIT_ASSERT(numbers[0]==0); - CPPUNIT_ASSERT(numbers[1]==1); - CPPUNIT_ASSERT(numbers[2]==42); - CPPUNIT_ASSERT(numbers[3]==0); - CPPUNIT_ASSERT(numbers[4]==1); - CPPUNIT_ASSERT(numbers[5]==42); -} - -void RmCpTest::replace1() -{ - vector <int> v1(10); - for (int i = 0; (size_t)i < v1.size(); ++i) - v1[i] = i % 5; - replace(v1.begin(), v1.end(), 2, 42); - - // 0 1 2 3 4 0 1 2 3 4 - // 0 1 42 3 4 0 1 42 3 4 - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==42); - CPPUNIT_ASSERT(v1[3]==3); - CPPUNIT_ASSERT(v1[4]==4); - CPPUNIT_ASSERT(v1[5]==0); - CPPUNIT_ASSERT(v1[6]==1); - CPPUNIT_ASSERT(v1[7]==42); - CPPUNIT_ASSERT(v1[8]==3); - CPPUNIT_ASSERT(v1[9]==4); -} - -void RmCpTest::repcpif1() -{ - vector <int> v1(10); - for (int i = 0; (size_t)i < v1.size(); ++i) - v1[i] = i % 5; - vector <int> v2(v1.size()); - - // 0 1 2 3 4 0 1 2 3 4 - // 0 1 2 3 4 0 1 2 3 4 - // 0 42 2 42 4 0 42 2 42 4 - replace_copy_if(v1.begin(), v1.end(), v2.begin(), odd, 42); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==2); - CPPUNIT_ASSERT(v1[3]==3); - CPPUNIT_ASSERT(v1[4]==4); - CPPUNIT_ASSERT(v1[5]==0); - CPPUNIT_ASSERT(v1[6]==1); - CPPUNIT_ASSERT(v1[7]==2); - CPPUNIT_ASSERT(v1[8]==3); - CPPUNIT_ASSERT(v1[9]==4); - - CPPUNIT_ASSERT(v2[0]==0); - CPPUNIT_ASSERT(v2[1]==42); - CPPUNIT_ASSERT(v2[2]==2); - CPPUNIT_ASSERT(v2[3]==42); - CPPUNIT_ASSERT(v2[4]==4); - CPPUNIT_ASSERT(v2[5]==0); - CPPUNIT_ASSERT(v2[6]==42); - CPPUNIT_ASSERT(v2[7]==2); - CPPUNIT_ASSERT(v2[8]==42); - CPPUNIT_ASSERT(v2[9]==4); -} - -void RmCpTest::remove1() -{ - int numbers[6] = { 1, 2, 3, 1, 2, 3 }; - remove((int*)numbers, (int*)numbers + 6, 1); - - // 2 3 2 3 2 3 - CPPUNIT_ASSERT(numbers[0]==2); - CPPUNIT_ASSERT(numbers[1]==3); - CPPUNIT_ASSERT(numbers[2]==2); - CPPUNIT_ASSERT(numbers[3]==3); - CPPUNIT_ASSERT(numbers[4]==2); - CPPUNIT_ASSERT(numbers[5]==3); -} - -void RmCpTest::remif1() -{ - int numbers[6] = { 0, 0, 1, 1, 2, 2 }; - - remove_if((int*)numbers, (int*)numbers + 6, odd); - - // 0 0 2 2 2 2 - CPPUNIT_ASSERT(numbers[0]==0); - CPPUNIT_ASSERT(numbers[1]==0); - CPPUNIT_ASSERT(numbers[2]==2); - CPPUNIT_ASSERT(numbers[3]==2); - CPPUNIT_ASSERT(numbers[4]==2); - CPPUNIT_ASSERT(numbers[5]==2); -} - -void RmCpTest::remcopy1() -{ - int numbers[6] = { 1, 2, 3, 1, 2, 3 }; - int result[6] = { 0, 0, 0, 0, 0, 0 }; - - remove_copy((int*)numbers, (int*)numbers + 6, (int*)result, 2); - - CPPUNIT_ASSERT(result[0]==1); - CPPUNIT_ASSERT(result[1]==3); - CPPUNIT_ASSERT(result[2]==1); - CPPUNIT_ASSERT(result[3]==3); - CPPUNIT_ASSERT(result[4]==0); - CPPUNIT_ASSERT(result[5]==0); -} - -void RmCpTest::remcpif1() -{ - int numbers[6] = { 1, 2, 3, 1, 2, 3 }; - int result[6] = { 0, 0, 0, 0, 0, 0 }; - - remove_copy_if((int*)numbers, (int*)numbers + 6, (int*)result, odd); - - // 2 2 0 0 0 0 - CPPUNIT_ASSERT(result[0]==2); - CPPUNIT_ASSERT(result[1]==2); - CPPUNIT_ASSERT(result[2]==0); - CPPUNIT_ASSERT(result[3]==0); - CPPUNIT_ASSERT(result[4]==0); - CPPUNIT_ASSERT(result[5]==0); -} diff --git a/test/unit/rndshf_test.cpp b/test/unit/rndshf_test.cpp deleted file mode 100644 index ad57a53..0000000 --- a/test/unit/rndshf_test.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include <numeric> -#include <vector> -#include <algorithm> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class RndShuffleTest : public CPPUNIT_NS::TestCase -{ - class MyRandomGenerator - { - public: - unsigned long operator()(unsigned long n_) - { - return rand() % n_; - } - }; - CPPUNIT_TEST_SUITE(RndShuffleTest); - CPPUNIT_TEST(rndshuf0); - CPPUNIT_TEST(rndshuf2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void rndshuf0(); - void rndshuf2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(RndShuffleTest); - -// -// tests implementation -// -void RndShuffleTest::rndshuf0() -{ - int numbers[6] = { 1, 2, 3, 4, 5, 6 }; - - random_shuffle(numbers, numbers + 6); - - CPPUNIT_ASSERT(count(numbers, numbers+6, 1)==1); - CPPUNIT_ASSERT(count(numbers, numbers+6, 2)==1); - CPPUNIT_ASSERT(count(numbers, numbers+6, 3)==1); - CPPUNIT_ASSERT(count(numbers, numbers+6, 4)==1); - CPPUNIT_ASSERT(count(numbers, numbers+6, 5)==1); - CPPUNIT_ASSERT(count(numbers, numbers+6, 6)==1); -} -void RndShuffleTest::rndshuf2() -{ - vector <int> v1(10); - __iota(v1.begin(), v1.end(), 0); - - MyRandomGenerator r; - for(int i = 0; i < 3; i++) - { - random_shuffle(v1.begin(), v1.end(), r); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 0)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 1)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 2)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 3)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 4)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 5)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 6)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 7)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 8)==1); - CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 9)==1); - } -} diff --git a/test/unit/rope_test.cpp b/test/unit/rope_test.cpp deleted file mode 100644 index c12fec8..0000000 --- a/test/unit/rope_test.cpp +++ /dev/null @@ -1,189 +0,0 @@ -//Small header to get STLport numerous defines: -#include <utility> - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <rope> - -# if !defined (_STLP_USE_NO_IOSTREAMS) -# include <sstream> -# endif -#endif - -#include "cppunit/cppunit_proxy.h" - -// #include <stdlib.h> // for rand etc - -#if defined (_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class RopeTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(RopeTest); -#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) || defined (_STLP_USE_NO_IOSTREAMS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(io); -#if defined (_STLP_USE_NO_IOSTREAMS) - CPPUNIT_STOP_IGNORE; -#endif - CPPUNIT_TEST(find1); - CPPUNIT_TEST(find2); - CPPUNIT_TEST(construct_from_char); - CPPUNIT_TEST(bug_report); -#if !defined (_STLP_MEMBER_TEMPLATES) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(test_saved_rope_iterators); - CPPUNIT_TEST_SUITE_END(); - -protected: - void io(); - void find1(); - void find2(); - void construct_from_char(); - void bug_report(); - void test_saved_rope_iterators(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(RopeTest); - -// -// tests implementation -// -void RopeTest::io() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && !defined (_STLP_USE_NO_IOSTREAMS) - char const* cstr = "rope test string"; - crope rstr(cstr); - - { - ostringstream ostr; - ostr << rstr; - - CPPUNIT_ASSERT( ostr ); - CPPUNIT_ASSERT( ostr.str() == cstr ); - } -#endif -} - -void RopeTest::find1() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - crope r("Fuzzy Wuzzy was a bear"); - crope::size_type n = r.find( "hair" ); - CPPUNIT_ASSERT( n == crope::npos ); - - n = r.find("ear"); - - CPPUNIT_ASSERT( n == (r.size() - 3) ); -#endif -} - -void RopeTest::find2() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - crope r("Fuzzy Wuzzy was a bear"); - crope::size_type n = r.find( 'e' ); - CPPUNIT_ASSERT( n == (r.size() - 3) ); -#endif -} - -void RopeTest::construct_from_char() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - crope r('1'); - char const* s = r.c_str(); - CPPUNIT_ASSERT( '1' == s[0] && '\0' == s[1] ); -#endif -} - -// Test used for a bug report from Peter Hercek -void RopeTest::bug_report() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - //first create a rope bigger than crope::_S_copy_max = 23 - // so that any string addition is added to a new leaf - crope evilRope("12345678901234567890123_"); - //crope* pSevenCharRope( new TRope("1234567") ); - crope sevenCharRope0("12345678"); - crope sevenCharRope1("1234567"); - // add _Rope_RopeRep<c,a>::_S_alloc_granularity-1 = 7 characters - evilRope += "1234567"; // creates a new leaf - crope sevenCharRope2("1234567"); - // add one more character to the leaf - evilRope += '8'; // here is the write beyond the allocated memory - CPPUNIT_ASSERT( strcmp(sevenCharRope2.c_str(), "1234567") == 0 ); -#endif -} - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -const char str[] = "ilcpsklryvmcpjnbpbwllsrehfmxrkecwitrsglrexvtjmxypu\ -nbqfgxmuvgfajclfvenhyuhuorjosamibdnjdbeyhkbsomblto\ -uujdrbwcrrcgbflqpottpegrwvgajcrgwdlpgitydvhedtusip\ -pyvxsuvbvfenodqasajoyomgsqcpjlhbmdahyviuemkssdslde\ -besnnngpesdntrrvysuipywatpfoelthrowhfexlwdysvspwlk\ -fblfdf"; - -crope create_rope( int len ) -{ - int l = len/2; - crope result; - if(l <= 2) - { - static int j = 0; - for(int i = 0; i < len; ++i) - { - // char c = 'a' + rand() % ('z' - 'a'); - result.append(1, /* c */ str[j++] ); - j %= sizeof(str); - } - } - else - { - result = create_rope(len/2); - result.append(create_rope(len/2)); - } - return result; -} - -#endif - -void RopeTest::test_saved_rope_iterators() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && \ - defined (_STLP_MEMBER_TEMPLATES) - // - // Try and create a rope with a complex tree structure: - // - // srand(0); - crope r = create_rope(300); - string expected(r.begin(), r.end()); - CPPUNIT_ASSERT(expected.size() == r.size()); - CPPUNIT_ASSERT(equal(expected.begin(), expected.end(), r.begin())); - crope::const_iterator i(r.begin()), j(r.end()); - int pos = 0; - while(i != j) - { - crope::const_iterator k; - // This initial read triggers the bug: - CPPUNIT_ASSERT(*i); - k = i; - int newpos = pos; - // Now make sure that i is incremented into the next leaf: - while(i != j) - { - CPPUNIT_ASSERT(*i == expected[newpos]); - ++i; - ++newpos; - } - // Back up from stored value and continue: - i = k; - ++i; - ++pos; - } -#endif -} diff --git a/test/unit/rotate_test.cpp b/test/unit/rotate_test.cpp deleted file mode 100644 index 730bf28..0000000 --- a/test/unit/rotate_test.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include <numeric> -#include <vector> -#include <algorithm> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class RotateTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(RotateTest); - CPPUNIT_TEST(rotate0); - CPPUNIT_TEST(rotate1); - CPPUNIT_TEST(rotcopy0); - CPPUNIT_TEST(rotcopy1); - CPPUNIT_TEST_SUITE_END(); - -protected: - void rotate0(); - void rotate1(); - void rotcopy0(); - void rotcopy1(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(RotateTest); - -// -// tests implementation -// -void RotateTest::rotate0() -{ - int numbers[6] = { 0, 1, 2, 3, 4, 5 }; - // 3 4 5 0 1 2 - rotate((int*)numbers, numbers + 3, numbers + 6); - CPPUNIT_ASSERT(numbers[0]==3); - CPPUNIT_ASSERT(numbers[1]==4); - CPPUNIT_ASSERT(numbers[2]==5); - CPPUNIT_ASSERT(numbers[3]==0); - CPPUNIT_ASSERT(numbers[4]==1); - CPPUNIT_ASSERT(numbers[5]==2); -} -void RotateTest::rotate1() -{ - vector <int> v1(10); - __iota(v1.begin(), v1.end(), 0); - - rotate(v1.begin(), v1.begin()+1, v1.end()); - CPPUNIT_ASSERT(v1[0]==1); - CPPUNIT_ASSERT(v1[1]==2); - CPPUNIT_ASSERT(v1[2]==3); - CPPUNIT_ASSERT(v1[3]==4); - CPPUNIT_ASSERT(v1[4]==5); - CPPUNIT_ASSERT(v1[5]==6); - CPPUNIT_ASSERT(v1[6]==7); - CPPUNIT_ASSERT(v1[7]==8); - CPPUNIT_ASSERT(v1[8]==9); - CPPUNIT_ASSERT(v1[9]==0); - - rotate(v1.begin(), v1.begin()+2, v1.end()); - CPPUNIT_ASSERT(v1[0]==3); - CPPUNIT_ASSERT(v1[1]==4); - CPPUNIT_ASSERT(v1[2]==5); - CPPUNIT_ASSERT(v1[3]==6); - CPPUNIT_ASSERT(v1[4]==7); - CPPUNIT_ASSERT(v1[5]==8); - CPPUNIT_ASSERT(v1[6]==9); - CPPUNIT_ASSERT(v1[7]==0); - CPPUNIT_ASSERT(v1[8]==1); - CPPUNIT_ASSERT(v1[9]==2); - - rotate(v1.begin(), v1.begin()+7, v1.end()); - CPPUNIT_ASSERT(v1[0]==0); - CPPUNIT_ASSERT(v1[1]==1); - CPPUNIT_ASSERT(v1[2]==2); - CPPUNIT_ASSERT(v1[3]==3); - CPPUNIT_ASSERT(v1[4]==4); - CPPUNIT_ASSERT(v1[5]==5); - CPPUNIT_ASSERT(v1[6]==6); - CPPUNIT_ASSERT(v1[7]==7); - CPPUNIT_ASSERT(v1[8]==8); - CPPUNIT_ASSERT(v1[9]==9); - -} -void RotateTest::rotcopy0() -{ - int numbers[6] = { 0, 1, 2, 3, 4, 5 }; - - int result[6]; - rotate_copy((int*)numbers, (int*)numbers + 3, (int*)numbers + 6, (int*)result); - // 3 4 5 0 1 2 - CPPUNIT_ASSERT(result[0]==3); - CPPUNIT_ASSERT(result[1]==4); - CPPUNIT_ASSERT(result[2]==5); - CPPUNIT_ASSERT(result[3]==0); - CPPUNIT_ASSERT(result[4]==1); - CPPUNIT_ASSERT(result[5]==2); -} -void RotateTest::rotcopy1() -{ - vector <int> v1(10); - __iota(v1.begin(), v1.end(), 0); - vector <int> v2(v1.size()); - - rotate_copy(v1.begin(), v1.begin()+1, v1.end(), v2.begin()); - CPPUNIT_ASSERT(v2[0]==1); - CPPUNIT_ASSERT(v2[1]==2); - CPPUNIT_ASSERT(v2[2]==3); - CPPUNIT_ASSERT(v2[3]==4); - CPPUNIT_ASSERT(v2[4]==5); - CPPUNIT_ASSERT(v2[5]==6); - CPPUNIT_ASSERT(v2[6]==7); - CPPUNIT_ASSERT(v2[7]==8); - CPPUNIT_ASSERT(v2[8]==9); - CPPUNIT_ASSERT(v2[9]==0); - - rotate_copy(v1.begin(), v1.begin()+3, v1.end(), v2.begin()); - CPPUNIT_ASSERT(v2[0]==3); - CPPUNIT_ASSERT(v2[1]==4); - CPPUNIT_ASSERT(v2[2]==5); - CPPUNIT_ASSERT(v2[3]==6); - CPPUNIT_ASSERT(v2[4]==7); - CPPUNIT_ASSERT(v2[5]==8); - CPPUNIT_ASSERT(v2[6]==9); - CPPUNIT_ASSERT(v2[7]==0); - CPPUNIT_ASSERT(v2[8]==1); - CPPUNIT_ASSERT(v2[9]==2); -} diff --git a/test/unit/search_test.cpp b/test/unit/search_test.cpp deleted file mode 100644 index f7dd33d..0000000 --- a/test/unit/search_test.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include <vector> -#include <numeric> -#include <algorithm> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class SearchTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SearchTest); - CPPUNIT_TEST(search0); - CPPUNIT_TEST(search1); - CPPUNIT_TEST(search2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void search0(); - void search1(); - void search2(); - - static bool str_equal(const char* a_, const char* b_) - { - return strcmp(a_, b_) == 0 ? 1 : 0; - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SearchTest); - -// -// tests implementation -// -void SearchTest::search0() -{ - int v1[6] = { 1, 1, 2, 3, 5, 8 }; - int v2[6] = { 0, 1, 2, 3, 4, 5 }; - int v3[2] = { 3, 4 }; - - int* location; - location = search((int*)v1, (int*)v1 + 6, (int*)v3, (int*)v3 + 2); - CPPUNIT_ASSERT(location == v1 + 6); - - location = search((int*)v2, (int*)v2 + 6, (int*)v3, (int*)v3 + 2); - CPPUNIT_ASSERT(location != v2 + 6); - CPPUNIT_ASSERT(location - v2 == 3); -} -void SearchTest::search1() -{ - typedef vector <int> IntVec; - IntVec v1(10); - __iota(v1.begin(), v1.end(), 0); - IntVec v2(3); - __iota(v2.begin(), v2.end(), 50); - - IntVec::iterator location; - location = search(v1.begin(), v1.end(), v2.begin(), v2.end()); - - CPPUNIT_ASSERT(location == v1.end()); - - __iota(v2.begin(), v2.end(), 4); - - location = search(v1.begin(), v1.end(), v2.begin(), v2.end()); - - CPPUNIT_ASSERT(location != v1.end()); - CPPUNIT_ASSERT(location - v1.begin() == 4); -} -void SearchTest::search2() -{ - char const* grades[] = { "A", "B", "C", "D", "F" }; - char const* letters[] = { "Q", "E", "D" }; - const unsigned gradeCount = sizeof(grades) / sizeof(grades[0]); - const unsigned letterCount = sizeof(letters) / sizeof(letters[0]); - char const** location = search((char const**)grades, (char const**)grades + gradeCount, (char const**)letters, (char const**)letters + letterCount, str_equal); - - CPPUNIT_ASSERT(location == grades + gradeCount); - - copy((char const**)grades + 1, (char const**)grades + 1 + letterCount, (char const**)letters); - location = search((char const**)grades, (char const**)grades + gradeCount, (char const**)letters, (char const**)letters + letterCount, str_equal); - - CPPUNIT_ASSERT(location != grades + gradeCount); - CPPUNIT_ASSERT(location - grades == 1); - -} diff --git a/test/unit/set_header_test.cpp b/test/unit/set_header_test.cpp deleted file mode 100644 index 8335e13..0000000 --- a/test/unit/set_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <set> diff --git a/test/unit/set_test.cpp b/test/unit/set_test.cpp deleted file mode 100644 index 9070b2f..0000000 --- a/test/unit/set_test.cpp +++ /dev/null @@ -1,507 +0,0 @@ -//Has to be first for StackAllocator swap overload to be taken -//into account (at least using GCC 4.0.1) -#include "stack_allocator.h" - -#include <set> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class SetTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SetTest); - CPPUNIT_TEST(set1); - CPPUNIT_TEST(set2); - CPPUNIT_TEST(erase); - CPPUNIT_TEST(insert); - CPPUNIT_TEST(find); - CPPUNIT_TEST(bounds); - CPPUNIT_TEST(specialized_less); - CPPUNIT_TEST(implementation_check); - CPPUNIT_TEST(allocator_with_state); - CPPUNIT_TEST(reverse_iterator_test); -#if !defined (STLPORT) || !defined (_STLP_USE_CONTAINERS_EXTENSION) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(template_methods); - CPPUNIT_TEST_SUITE_END(); - -protected: - void set1(); - void set2(); - void erase(); - void insert(); - void find(); - void bounds(); - void specialized_less(); - void implementation_check(); - void allocator_with_state(); - void reverse_iterator_test(); - void template_methods(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SetTest); - - -// -// tests implementation -// -void SetTest::set1() -{ - set<int, less<int> > s; - CPPUNIT_ASSERT (s.count(42) == 0); - s.insert(42); - CPPUNIT_ASSERT (s.count(42) == 1); - s.insert(42); - CPPUNIT_ASSERT (s.count(42) == 1); - size_t count = s.erase(42); - CPPUNIT_ASSERT (count == 1); -} - -void SetTest::set2() -{ - typedef set<int, less<int> > int_set; - int_set s; - pair<int_set::iterator, bool> p = s.insert(42); - CPPUNIT_ASSERT (p.second == true); - p = s.insert(42); - CPPUNIT_ASSERT (p.second == false); - - int array1 [] = { 1, 3, 6, 7 }; - s.insert(array1, array1 + 4); - CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 5); - - int_set s2; - s2.swap(s); - CPPUNIT_ASSERT (distance(s2.begin(), s2.end()) == 5); - CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 0); - - int_set s3; - s3.swap(s); - s3.swap(s2); - CPPUNIT_ASSERT (distance(s.begin(), s.end()) == 0); - CPPUNIT_ASSERT (distance(s2.begin(), s2.end()) == 0); - CPPUNIT_ASSERT (distance(s3.begin(), s3.end()) == 5); -} - -void SetTest::erase() -{ - set<int, less<int> > s; - s.insert(1); - s.erase(s.begin()); - CPPUNIT_ASSERT( s.empty() ); - - size_t nb = s.erase(1); - CPPUNIT_ASSERT(nb == 0); -} - -void SetTest::insert() -{ - set<int> s; - set<int>::iterator i = s.insert( s.end(), 0 ); - CPPUNIT_ASSERT( *i == 0 ); -} - -void SetTest::find() -{ - set<int> s; - - CPPUNIT_ASSERT( s.find(0) == s.end() ); - - set<int> const& crs = s; - - CPPUNIT_ASSERT( crs.find(0) == crs.end() ); -} - -void SetTest::bounds() -{ - int array1 [] = { 1, 3, 6, 7 }; - set<int> s(array1, array1 + sizeof(array1) / sizeof(array1[0])); - set<int> const& crs = s; - - set<int>::iterator sit; - set<int>::const_iterator scit; - pair<set<int>::iterator, set<int>::iterator> pit; - pair<set<int>::const_iterator, set<int>::const_iterator> pcit; - - //Check iterator on mutable set - sit = s.lower_bound(2); - CPPUNIT_ASSERT( sit != s.end() ); - CPPUNIT_ASSERT( *sit == 3 ); - - sit = s.upper_bound(5); - CPPUNIT_ASSERT( sit != s.end() ); - CPPUNIT_ASSERT( *sit == 6 ); - - pit = s.equal_range(6); - CPPUNIT_ASSERT( pit.first != pit.second ); - CPPUNIT_ASSERT( pit.first != s.end() ); - CPPUNIT_ASSERT( *pit.first == 6 ); - CPPUNIT_ASSERT( pit.second != s.end() ); - CPPUNIT_ASSERT( *pit.second == 7 ); - - pit = s.equal_range(4); - CPPUNIT_ASSERT( pit.first == pit.second ); - CPPUNIT_ASSERT( pit.first != s.end() ); - CPPUNIT_ASSERT( *pit.first == 6 ); - CPPUNIT_ASSERT( pit.second != s.end() ); - CPPUNIT_ASSERT( *pit.second == 6 ); - - //Check const_iterator on mutable set - scit = s.lower_bound(2); - CPPUNIT_ASSERT( scit != s.end() ); - CPPUNIT_ASSERT( *scit == 3 ); - - scit = s.upper_bound(5); - CPPUNIT_ASSERT( scit != s.end() ); - CPPUNIT_ASSERT( *scit == 6 ); - -#ifdef _STLP_MEMBER_TEMPLATES - pcit = s.equal_range(6); - CPPUNIT_ASSERT( pcit.first != pcit.second ); - CPPUNIT_ASSERT( pcit.first != s.end() ); - CPPUNIT_ASSERT( *pcit.first == 6 ); - CPPUNIT_ASSERT( pcit.second != s.end() ); - CPPUNIT_ASSERT( *pcit.second == 7 ); -#endif - - //Check const_iterator on const set - scit = crs.lower_bound(2); - CPPUNIT_ASSERT( scit != crs.end() ); - CPPUNIT_ASSERT( *scit == 3 ); - - scit = crs.upper_bound(5); - CPPUNIT_ASSERT( scit != crs.end() ); - CPPUNIT_ASSERT( *scit == 6 ); - - pcit = crs.equal_range(6); - CPPUNIT_ASSERT( pcit.first != pcit.second ); - CPPUNIT_ASSERT( pcit.first != crs.end() ); - CPPUNIT_ASSERT( *pcit.first == 6 ); - CPPUNIT_ASSERT( pcit.second != crs.end() ); - CPPUNIT_ASSERT( *pcit.second == 7 ); -} - - -class SetTestClass { -public: - SetTestClass (int data) : _data(data) - {} - - int data() const { - return _data; - } - -private: - int _data; -}; - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -namespace std { -#endif -#if defined (STLPORT) - _STLP_TEMPLATE_NULL -#else - template <> -#endif - struct less<SetTestClass> { - bool operator () (SetTestClass const& lhs, SetTestClass const& rhs) const { - return lhs.data() < rhs.data(); - } - }; -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -} -#endif - -void SetTest::specialized_less() -{ - set<SetTestClass> s; - s.insert(SetTestClass(1)); - s.insert(SetTestClass(3)); - s.insert(SetTestClass(2)); - s.insert(SetTestClass(0)); - - set<SetTestClass>::iterator sit(s.begin()), sitEnd(s.end()); - int i = 0; - for (; sit != sitEnd; ++sit, ++i) { - CPPUNIT_ASSERT( sit->data() == i ); - } -} - -void SetTest::implementation_check() -{ - set<int> tree; - tree.insert(1); - set<int>::iterator it = tree.begin(); - int const& int_ref = *it++; - CPPUNIT_ASSERT( int_ref == 1 ); - - CPPUNIT_ASSERT( it == tree.end() ); - CPPUNIT_ASSERT( it != tree.begin() ); - - set<int>::const_iterator cit = tree.begin(); - int const& int_cref = *cit++; - CPPUNIT_ASSERT( int_cref == 1 ); -} - -void SetTest::reverse_iterator_test() -{ - set<int> tree; - tree.insert(1); - tree.insert(2); - - { - set<int>::reverse_iterator rit(tree.rbegin()); - CPPUNIT_ASSERT( *(rit++) == 2 ); - CPPUNIT_ASSERT( *(rit++) == 1 ); - CPPUNIT_ASSERT( rit == tree.rend() ); - } - - { - set<int> const& ctree = tree; - set<int>::const_reverse_iterator rit(ctree.rbegin()); - CPPUNIT_ASSERT( *(rit++) == 2 ); - CPPUNIT_ASSERT( *(rit++) == 1 ); - CPPUNIT_ASSERT( rit == ctree.rend() ); - } -} - -void SetTest::allocator_with_state() -{ - char buf1[1024]; - StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1)); - - char buf2[1024]; - StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2)); - - int i; - typedef set<int, less<int>, StackAllocator<int> > SetInt; - less<int> intLess; - - { - SetInt sint1(intLess, stack1); - for (i = 0; i < 5; ++i) - sint1.insert(i); - SetInt sint1Cpy(sint1); - - SetInt sint2(intLess, stack2); - for (; i < 10; ++i) - sint2.insert(i); - SetInt sint2Cpy(sint2); - - sint1.swap(sint2); - - CPPUNIT_ASSERT( sint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( sint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( sint1 == sint2Cpy ); - CPPUNIT_ASSERT( sint2 == sint1Cpy ); - CPPUNIT_ASSERT( sint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( sint2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - SetInt sint1(intLess, stack1); - SetInt sint1Cpy(sint1); - - SetInt sint2(intLess, stack2); - for (i = 0; i < 10; ++i) - sint2.insert(i); - SetInt sint2Cpy(sint2); - - sint1.swap(sint2); - - CPPUNIT_ASSERT( sint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( sint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( sint1 == sint2Cpy ); - CPPUNIT_ASSERT( sint2 == sint1Cpy ); - CPPUNIT_ASSERT( sint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( sint2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - SetInt sint1(intLess, stack1); - for (i = 0; i < 10; ++i) - sint1.insert(i); - SetInt sint1Cpy(sint1); - - SetInt sint2(intLess, stack2); - SetInt sint2Cpy(sint2); - - sint1.swap(sint2); - - CPPUNIT_ASSERT( sint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( sint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( sint1 == sint2Cpy ); - CPPUNIT_ASSERT( sint2 == sint1Cpy ); - CPPUNIT_ASSERT( sint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( sint2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); - stack1.reset(); stack2.reset(); -} - -struct Key -{ - Key() : m_data(0) {} - explicit Key(int data) : m_data(data) {} - - int m_data; -}; - -struct KeyCmp -{ - bool operator () (Key lhs, Key rhs) const - { return lhs.m_data < rhs.m_data; } - - bool operator () (Key lhs, int rhs) const - { return lhs.m_data < rhs; } - - bool operator () (int lhs, Key rhs) const - { return lhs < rhs.m_data; } -}; - -struct KeyCmpPtr -{ - bool operator () (Key const volatile *lhs, Key const volatile *rhs) const - { return (*lhs).m_data < (*rhs).m_data; } - - bool operator () (Key const volatile *lhs, int rhs) const - { return (*lhs).m_data < rhs; } - - bool operator () (int lhs, Key const volatile *rhs) const - { return lhs < (*rhs).m_data; } -}; - -void SetTest::template_methods() -{ -#if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION) - { - typedef set<Key, KeyCmp> KeySet; - KeySet keySet; - keySet.insert(Key(1)); - keySet.insert(Key(2)); - keySet.insert(Key(3)); - keySet.insert(Key(4)); - - CPPUNIT_ASSERT( keySet.count(Key(1)) == 1 ); - CPPUNIT_ASSERT( keySet.count(1) == 1 ); - CPPUNIT_ASSERT( keySet.count(5) == 0 ); - - CPPUNIT_ASSERT( keySet.find(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) ); - - KeySet const& ckeySet = keySet; - CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) ); - } - - { - typedef set<Key*, KeyCmpPtr> KeySet; - KeySet keySet; - Key key1(1), key2(2), key3(3), key4(4); - keySet.insert(&key1); - keySet.insert(&key2); - keySet.insert(&key3); - keySet.insert(&key4); - - CPPUNIT_ASSERT( keySet.count(1) == 1 ); - CPPUNIT_ASSERT( keySet.count(5) == 0 ); - - CPPUNIT_ASSERT( keySet.find(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) ); - - KeySet const& ckeySet = keySet; - CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) ); - } - { - typedef multiset<Key, KeyCmp> KeySet; - KeySet keySet; - keySet.insert(Key(1)); - keySet.insert(Key(2)); - keySet.insert(Key(3)); - keySet.insert(Key(4)); - - CPPUNIT_ASSERT( keySet.count(Key(1)) == 1 ); - CPPUNIT_ASSERT( keySet.count(1) == 1 ); - CPPUNIT_ASSERT( keySet.count(5) == 0 ); - - CPPUNIT_ASSERT( keySet.find(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) ); - - KeySet const& ckeySet = keySet; - CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) ); - } - - { - typedef multiset<Key const volatile*, KeyCmpPtr> KeySet; - KeySet keySet; - Key key1(1), key2(2), key3(3), key4(4); - keySet.insert(&key1); - keySet.insert(&key2); - keySet.insert(&key3); - keySet.insert(&key4); - - CPPUNIT_ASSERT( keySet.count(1) == 1 ); - CPPUNIT_ASSERT( keySet.count(5) == 0 ); - - CPPUNIT_ASSERT( keySet.find(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.lower_bound(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.upper_bound(2) != keySet.end() ); - CPPUNIT_ASSERT( keySet.equal_range(2) != make_pair(keySet.begin(), keySet.end()) ); - - KeySet const& ckeySet = keySet; - CPPUNIT_ASSERT( ckeySet.find(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.lower_bound(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.upper_bound(2) != ckeySet.end() ); - CPPUNIT_ASSERT( ckeySet.equal_range(2) != make_pair(ckeySet.begin(), ckeySet.end()) ); - } -#endif -} - -#if !defined (STLPORT) || \ - !defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) -# if !defined (__DMC__) -/* Simple compilation test: Check that nested types like iterator - * can be access even if type used to instanciate container is not - * yet completely defined. - */ -class IncompleteClass -{ - set<IncompleteClass> instances; - typedef set<IncompleteClass>::iterator it; - multiset<IncompleteClass> minstances; - typedef multiset<IncompleteClass>::iterator mit; -}; -# endif -#endif diff --git a/test/unit/setdiff_test.cpp b/test/unit/setdiff_test.cpp deleted file mode 100644 index 8fa2dda..0000000 --- a/test/unit/setdiff_test.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include <numeric> -#include <string> -#include <iterator> -#include <vector> -#include <algorithm> -#include <functional> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class SetDifferenceTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SetDifferenceTest); - CPPUNIT_TEST(setdiff0); - CPPUNIT_TEST(setdiff1); - CPPUNIT_TEST(setdiff2); - CPPUNIT_TEST(setsymd0); - CPPUNIT_TEST(setsymd1); - CPPUNIT_TEST(setsymd2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void setdiff0(); - void setdiff1(); - void setdiff2(); - void setsymd0(); - void setsymd1(); - void setsymd2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SetDifferenceTest); - -// -// tests implementation -// -void SetDifferenceTest::setsymd0() -{ - int v1[3] = { 13, 18, 23 }; - int v2[4] = { 10, 13, 17, 23 }; - int result[4] = { 0, 0, 0, 0 }; - - set_symmetric_difference((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result); - CPPUNIT_ASSERT(result[0]==10); - CPPUNIT_ASSERT(result[1]==17); - CPPUNIT_ASSERT(result[2]==18); - CPPUNIT_ASSERT(result[3]==0); -} - -void SetDifferenceTest::setsymd1() -{ - vector<int> v1(10); - __iota(v1.begin(), v1.end(), 0); - vector<int> v2(10); - __iota(v2.begin(), v2.end(), 7); - - vector<int> diff; - set_symmetric_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(diff)); - CPPUNIT_ASSERT( diff.size() == 14 ); - int int_res[] = {0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16}; - for (int i = 0; i < 14; ++i) { - CPPUNIT_ASSERT( diff[i] == int_res[i] ); - } -} - -void SetDifferenceTest::setsymd2() -{ - const char* word1 = "ABCDEFGHIJKLMNO"; - const char* word2 = "LMNOPQRSTUVWXYZ"; - - string diff; - set_symmetric_difference(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), - back_inserter(diff), less<char>()); - CPPUNIT_ASSERT( diff.size() == 22 ); - char char_res[] = "ABCDEFGHIJKPQRSTUVWXYZ"; - for (int i = 0; i < 22; ++i) { - CPPUNIT_ASSERT( diff[i] == char_res[i] ); - } -} - -void SetDifferenceTest::setdiff0() -{ - int v1[3] = { 13, 18, 23 }; - int v2[4] = { 10, 13, 17, 23 }; - int result[4] = { 0, 0, 0, 0 }; - //18 0 0 0 - //10 17 23 0 - - set_difference((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result); - CPPUNIT_ASSERT( result[0] == 18 ); - CPPUNIT_ASSERT( result[1] == 0 ); - CPPUNIT_ASSERT( result[2] == 0 ); - CPPUNIT_ASSERT( result[3] == 0 ); - - set_difference((int*)v2, (int*)v2 + 4, (int*)v1, (int*)v1 + 2, (int*)result); - CPPUNIT_ASSERT( result[0] == 10 ); - CPPUNIT_ASSERT( result[1] == 17 ); - CPPUNIT_ASSERT( result[2] == 23 ); - CPPUNIT_ASSERT( result[3] == 0 ); -} - -void SetDifferenceTest::setdiff1() -{ - vector<int> v1(10); - __iota(v1.begin(), v1.end(), 0); - vector<int> v2(10); - __iota(v2.begin(), v2.end(), 7); - - vector<int> diff; - set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(diff)); - CPPUNIT_ASSERT( diff.size() == 7 ); - for (int i = 0; i < 7; ++i) { - CPPUNIT_ASSERT( diff[i] == i ); - } -} - -void SetDifferenceTest::setdiff2() -{ - const char* word1 = "ABCDEFGHIJKLMNO"; - const char* word2 = "LMNOPQRSTUVWXYZ"; - - string diff; - set_difference(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), back_inserter(diff), less<char>()); - CPPUNIT_ASSERT( diff.size() == 11 ); - for (int i = 0; i < 11; ++i) { - CPPUNIT_ASSERT( diff[i] == ('A' + i) ); - } -} diff --git a/test/unit/setinter_test.cpp b/test/unit/setinter_test.cpp deleted file mode 100644 index ffcfd78..0000000 --- a/test/unit/setinter_test.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include <numeric> -#include <string> -#include <iterator> -#include <vector> -#include <algorithm> -#include <functional> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class SetIntersectionTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SetIntersectionTest); - CPPUNIT_TEST(setintr0); - CPPUNIT_TEST(setintr1); - CPPUNIT_TEST(setintr2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void setintr0(); - void setintr1(); - void setintr2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SetIntersectionTest); - -// -// tests implementation -// -void SetIntersectionTest::setintr0() -{ - int v1[3] = { 13, 18, 23 }; - int v2[4] = { 10, 13, 17, 23 }; - int result[4] = { 0, 0, 0, 0 }; - - set_intersection((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result); - - CPPUNIT_ASSERT(result[0]==13); - CPPUNIT_ASSERT(result[1]==23); - CPPUNIT_ASSERT(result[2]==0); - CPPUNIT_ASSERT(result[3]==0); -} - -void SetIntersectionTest::setintr1() -{ - vector <int> v1(10); - __iota(v1.begin(), v1.end(), 0); - vector <int> v2(10); - __iota(v2.begin(), v2.end(), 7); - - vector<int> inter; - set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(inter)); - CPPUNIT_ASSERT( inter.size() == 3 ); - CPPUNIT_ASSERT( inter[0] == 7 ); - CPPUNIT_ASSERT( inter[1] == 8 ); - CPPUNIT_ASSERT( inter[2] == 9 ); -} - -void SetIntersectionTest::setintr2() -{ - const char* word1 = "ABCDEFGHIJKLMNO"; - const char* word2 = "LMNOPQRSTUVWXYZ"; - - string inter; - set_intersection(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), - back_inserter(inter), less<char>()); - CPPUNIT_ASSERT( inter.size() == 4 ); - CPPUNIT_ASSERT( inter[0] == 'L' ); - CPPUNIT_ASSERT( inter[1] == 'M' ); - CPPUNIT_ASSERT( inter[2] == 'N' ); - CPPUNIT_ASSERT( inter[3] == 'O' ); -} diff --git a/test/unit/setjmp_header_test.c b/test/unit/setjmp_header_test.c deleted file mode 100644 index 9496289..0000000 --- a/test/unit/setjmp_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <setjmp.h> diff --git a/test/unit/setjmp_header_test2.cpp b/test/unit/setjmp_header_test2.cpp deleted file mode 100644 index 00e4e4a..0000000 --- a/test/unit/setjmp_header_test2.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ - -/* - * Sometimes, if native setjmp.h was included first, the setjmp functions - * situated in global namespace, not in vendor's std. This may confuse - * following csetjmp - */ -#include <setjmp.h> -#include <csetjmp> diff --git a/test/unit/setunion_test.cpp b/test/unit/setunion_test.cpp deleted file mode 100644 index 577953e..0000000 --- a/test/unit/setunion_test.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include <numeric> -#include <string> -#include <iterator> -#include <vector> -#include <algorithm> -#include <functional> - -#include "iota.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class SetUnionTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SetUnionTest); - CPPUNIT_TEST(setunon0); - CPPUNIT_TEST(setunon1); - CPPUNIT_TEST(setunon2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void setunon0(); - void setunon1(); - void setunon2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SetUnionTest); - -// -// tests implementation -// -void SetUnionTest::setunon0() -{ - int v1[3] = { 13, 18, 23 }; - int v2[4] = { 10, 13, 17, 23 }; - int result[7] = { 0, 0, 0, 0, 0, 0, 0 }; - - set_union((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result); - - CPPUNIT_ASSERT(result[0]==10); - CPPUNIT_ASSERT(result[1]==13); - CPPUNIT_ASSERT(result[2]==17); - CPPUNIT_ASSERT(result[3]==18); - CPPUNIT_ASSERT(result[4]==23); - CPPUNIT_ASSERT(result[5]==0); - CPPUNIT_ASSERT(result[6]==0); -} - -void SetUnionTest::setunon1() -{ - vector <int> v1(10); - __iota(v1.begin(), v1.end(), 0); - vector <int> v2(10); - __iota(v2.begin(), v2.end(), 7); - - vector<int> diff; - set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(diff)); - CPPUNIT_ASSERT( diff.size() == 17 ); - for (int i = 0; i < 17; ++i) { - CPPUNIT_ASSERT( diff[i] == i ); - } -} - -void SetUnionTest::setunon2() -{ - const char* word1 = "ABCDEFGHIJKLMNO"; - const char* word2 = "LMNOPQRSTUVWXYZ"; - - string diff; - set_union(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), - back_inserter(diff), less<char>()); - CPPUNIT_ASSERT( diff.size() == 26 ); - for (int i = 0; i < 26; ++i) { - CPPUNIT_ASSERT( diff[i] == ('A' + i) ); - } -} diff --git a/test/unit/shared_ptr_test.cpp b/test/unit/shared_ptr_test.cpp deleted file mode 100644 index a5393de..0000000 --- a/test/unit/shared_ptr_test.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include <memory> - -#if !defined(_STLP_NO_EXTENSIONS) && defined(_STLP_USE_BOOST_SUPPORT) - -// #include <typeinfo> -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -class SharedPtrTest : - public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SharedPtrTest); - CPPUNIT_TEST(shared_from_this); - CPPUNIT_TEST_SUITE_END(); - - protected: - void shared_from_this(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SharedPtrTest); - -struct X; - -struct X : - public std::tr1::enable_shared_from_this<X> -{ -}; - -void SharedPtrTest::shared_from_this() -{ - std::tr1::shared_ptr<X> p( new X ); - std::tr1::shared_ptr<X> q = p->shared_from_this(); - - CPPUNIT_CHECK( p == q ); - CPPUNIT_CHECK( !(p < q) && !(q < p) ); // p and q share ownership -} - -#endif /* !_STLP_NO_EXTENSIONS && _STLP_USE_BOOST_SUPPORT */ diff --git a/test/unit/signal_header_test.c b/test/unit/signal_header_test.c deleted file mode 100644 index e179eb2..0000000 --- a/test/unit/signal_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <signal.h> diff --git a/test/unit/slist_test.cpp b/test/unit/slist_test.cpp deleted file mode 100644 index 383ece2..0000000 --- a/test/unit/slist_test.cpp +++ /dev/null @@ -1,554 +0,0 @@ -//Has to be first for StackAllocator swap overload to be taken -//into account (at least using GCC 4.0.1) -#include "stack_allocator.h" - -#include <algorithm> -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) -# include <slist> -# if !defined (_STLP_USE_NO_IOSTREAMS) -# include <sstream> -# endif -# include <iterator> -# include <functional> -#endif - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -#if !defined (STLPORT) && defined(__GNUC__) -using namespace __gnu_cxx; -#endif - -// -// TestCase class -// -class SlistTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SlistTest); -#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) || defined (_STLP_USE_NO_IOSTREAMS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(slist1); -#if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS) - CPPUNIT_STOP_IGNORE; -#endif - CPPUNIT_TEST(erase); - CPPUNIT_TEST(insert); - CPPUNIT_TEST(splice); - CPPUNIT_TEST(allocator_with_state); - CPPUNIT_TEST_SUITE_END(); - -protected: - void slist1(); - void erase(); - void insert(); - void splice(); - void allocator_with_state(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SlistTest); - -// -// tests implementation -// -void SlistTest::slist1() -{ -#if defined (STLPORT) && !defined (_STLP_USE_NO_IOSTREAMS) && !defined (_STLP_NO_EXTENSIONS) -/* -original: xlxtss -reversed: sstxlx -removed: sstl -uniqued: stl -sorted: lst -*/ - - char array [] = { 'x', 'l', 'x', 't', 's', 's' }; - ostringstream os; - ostream_iterator<char> o(os,""); - slist<char> str(array+0, array + 6); - slist<char>::iterator i; - //Check const_iterator construction from iterator - slist<char>::const_iterator ci(i); - slist<char>::const_iterator ci2(ci); -// cout << "reversed: "; - str.reverse(); - for(i = str.begin(); i != str.end(); i++) - os << *i; - stringbuf* buff=os.rdbuf(); - string result=buff->str(); - CPPUNIT_ASSERT(!strcmp(result.c_str(),"sstxlx")); - - //cout << "removed: "; - str.remove('x'); - ostringstream os2; - for(i = str.begin(); i != str.end(); i++) - os2 << *i; - buff=os2.rdbuf(); - result=buff->str(); - CPPUNIT_ASSERT(!strcmp(result.c_str(),"sstl")); - - - //cout << "uniqued: "; - str.unique(); - ostringstream os3; - for(i = str.begin(); i != str.end(); i++) - os3 << *i; - buff=os3.rdbuf(); - result=buff->str(); - CPPUNIT_ASSERT(!strcmp(result.c_str(),"stl")); - - //cout << "sorted: "; - str.sort(); - ostringstream os4; - for(i = str.begin(); i != str.end(); i++) - os4 << *i; - buff = os4.rdbuf(); - result = buff->str(); - CPPUNIT_ASSERT(!strcmp(result.c_str(),"lst")); - - //A small compilation time check to be activated from time to time: -# if 0 - { - slist<char>::iterator sl_char_ite; - slist<int>::iterator sl_int_ite; - CPPUNIT_ASSERT( sl_char_ite != sl_int_ite ); - } -# endif -#endif -} - -void SlistTest::erase() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - int array[] = { 0, 1, 2, 3, 4 }; - slist<int> sl(array, array + 5); - slist<int>::iterator slit; - - slit = sl.erase(sl.begin()); - CPPUNIT_ASSERT( *slit == 1); - - ++slit++; ++slit; - slit = sl.erase(sl.begin(), slit); - CPPUNIT_ASSERT( *slit == 3 ); - - sl.assign(array, array + 5); - - slit = sl.erase_after(sl.begin()); - CPPUNIT_ASSERT( *slit == 2 ); - - slit = sl.begin(); ++slit; ++slit; - slit = sl.erase_after(sl.begin(), slit); - CPPUNIT_ASSERT( *slit == 3 ); - - sl.erase_after(sl.before_begin()); - CPPUNIT_ASSERT( sl.front() == 3 ); -#endif -} - -void SlistTest::insert() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - int array[] = { 0, 1, 2, 3, 4 }; - - //insert - { - slist<int> sl; - - sl.insert(sl.begin(), 5); - CPPUNIT_ASSERT( sl.front() == 5 ); - CPPUNIT_ASSERT( sl.size() == 1 ); - - //debug mode check: - //sl.insert(sl.before_begin(), array, array + 5); - - sl.insert(sl.begin(), array, array + 5); - CPPUNIT_ASSERT( sl.size() == 6 ); - int i; - slist<int>::iterator slit(sl.begin()); - for (i = 0; slit != sl.end(); ++slit, ++i) { - CPPUNIT_ASSERT( *slit == i ); - } - } - - //insert_after - { - slist<int> sl; - - //debug check: - //sl.insert_after(sl.begin(), 5); - - sl.insert_after(sl.before_begin(), 5); - CPPUNIT_ASSERT( sl.front() == 5 ); - CPPUNIT_ASSERT( sl.size() == 1 ); - - sl.insert_after(sl.before_begin(), array, array + 5); - CPPUNIT_ASSERT( sl.size() == 6 ); - int i; - slist<int>::iterator slit(sl.begin()); - for (i = 0; slit != sl.end(); ++slit, ++i) { - CPPUNIT_ASSERT( *slit == i ); - } - } -#endif -} - -void SlistTest::splice() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - int array[] = { 0, 1, 2, 3, 4 }; - - //splice - { - slist<int> sl1(array, array + 5); - slist<int> sl2(array, array + 5); - slist<int>::iterator slit; - - //a no op: - sl1.splice(sl1.begin(), sl1, sl1.begin()); - CPPUNIT_ASSERT( sl1 == sl2 ); - - slit = sl1.begin(); ++slit; - //a no op: - sl1.splice(slit, sl1, sl1.begin()); - CPPUNIT_ASSERT( sl1 == sl2 ); - - sl1.splice(sl1.end(), sl1, sl1.begin()); - slit = sl1.begin(); - CPPUNIT_ASSERT( *(slit++) == 1 ); - CPPUNIT_ASSERT( *(slit++) == 2 ); - CPPUNIT_ASSERT( *(slit++) == 3 ); - CPPUNIT_ASSERT( *(slit++) == 4 ); - CPPUNIT_ASSERT( *slit == 0 ); - sl1.splice(sl1.begin(), sl1, slit); - CPPUNIT_ASSERT( sl1 == sl2 ); - - sl1.splice(sl1.begin(), sl2); - size_t i; - for (i = 0, slit = sl1.begin(); slit != sl1.end(); ++slit, ++i) { - if (i == 5) i = 0; - CPPUNIT_ASSERT( *slit == array[i] ); - } - - slit = sl1.begin(); - advance(slit, 5); - CPPUNIT_ASSERT( *slit == 0 ); - sl2.splice(sl2.begin(), sl1, sl1.begin(), slit); - CPPUNIT_ASSERT( sl1 == sl2 ); - - slit = sl1.begin(); ++slit; - sl1.splice(sl1.begin(), sl1, slit, sl1.end()); - slit = sl1.begin(); - CPPUNIT_ASSERT( *(slit++) == 1 ); - CPPUNIT_ASSERT( *(slit++) == 2 ); - CPPUNIT_ASSERT( *(slit++) == 3 ); - CPPUNIT_ASSERT( *(slit++) == 4 ); - CPPUNIT_ASSERT( *slit == 0 ); - - // a no op - sl2.splice(sl2.end(), sl2, sl2.begin(), sl2.end()); - for (i = 0, slit = sl2.begin(); slit != sl2.end(); ++slit, ++i) { - CPPUNIT_ASSERT( i < 5 ); - CPPUNIT_ASSERT( *slit == array[i] ); - } - - slit = sl2.begin(); - advance(slit, 3); - sl2.splice(sl2.end(), sl2, sl2.begin(), slit); - slit = sl2.begin(); - CPPUNIT_ASSERT( *(slit++) == 3 ); - CPPUNIT_ASSERT( *(slit++) == 4 ); - CPPUNIT_ASSERT( *(slit++) == 0 ); - CPPUNIT_ASSERT( *(slit++) == 1 ); - CPPUNIT_ASSERT( *slit == 2 ); - } - - //splice_after - { - slist<int> sl1(array, array + 5); - slist<int> sl2(array, array + 5); - slist<int>::iterator slit; - - //a no op: - sl1.splice_after(sl1.begin(), sl1, sl1.begin()); - CPPUNIT_ASSERT( sl1 == sl2 ); - - sl1.splice_after(sl1.before_begin(), sl1, sl1.begin()); - slit = sl1.begin(); - CPPUNIT_ASSERT( *(slit++) == 1 ); - CPPUNIT_ASSERT( *(slit++) == 0 ); - CPPUNIT_ASSERT( *(slit++) == 2 ); - CPPUNIT_ASSERT( *(slit++) == 3 ); - CPPUNIT_ASSERT( *slit == 4 ); - sl1.splice_after(sl1.before_begin(), sl1, sl1.begin()); - CPPUNIT_ASSERT( sl1 == sl2 ); - - sl1.splice_after(sl1.before_begin(), sl2); - size_t i; - for (i = 0, slit = sl1.begin(); slit != sl1.end(); ++slit, ++i) { - if (i == 5) i = 0; - CPPUNIT_ASSERT( *slit == array[i] ); - } - - slit = sl1.begin(); - advance(slit, 4); - CPPUNIT_ASSERT( *slit == 4 ); - sl2.splice_after(sl2.before_begin(), sl1, sl1.before_begin(), slit); - CPPUNIT_ASSERT( sl1 == sl2 ); - - sl1.splice_after(sl1.before_begin(), sl1, sl1.begin(), sl1.previous(sl1.end())); - slit = sl1.begin(); - CPPUNIT_ASSERT( *(slit++) == 1 ); - CPPUNIT_ASSERT( *(slit++) == 2 ); - CPPUNIT_ASSERT( *(slit++) == 3 ); - CPPUNIT_ASSERT( *(slit++) == 4 ); - CPPUNIT_ASSERT( *slit == 0 ); - - // a no op - sl2.splice_after(sl2.before_begin(), sl2, sl2.before_begin(), sl2.previous(sl2.end())); - for (i = 0, slit = sl2.begin(); slit != sl2.end(); ++slit, ++i) { - CPPUNIT_ASSERT( i < 5 ); - CPPUNIT_ASSERT( *slit == array[i] ); - } - - slit = sl2.begin(); - advance(slit, 2); - sl2.splice_after(sl2.previous(sl2.end()), sl2, sl2.before_begin(), slit); - slit = sl2.begin(); - CPPUNIT_ASSERT( *(slit++) == 3 ); - CPPUNIT_ASSERT( *(slit++) == 4 ); - CPPUNIT_ASSERT( *(slit++) == 0 ); - CPPUNIT_ASSERT( *(slit++) == 1 ); - CPPUNIT_ASSERT( *slit == 2 ); - } -#endif -} - - -void SlistTest::allocator_with_state() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - char buf1[1024]; - StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1)); - - char buf2[1024]; - StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2)); - - typedef slist<int, StackAllocator<int> > SlistInt; - { - SlistInt slint1(10, 0, stack1); - SlistInt slint1Cpy(slint1); - - SlistInt slint2(10, 1, stack2); - SlistInt slint2Cpy(slint2); - - slint1.swap(slint2); - - CPPUNIT_ASSERT( slint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( slint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( slint1 == slint2Cpy ); - CPPUNIT_ASSERT( slint2 == slint1Cpy ); - CPPUNIT_ASSERT( slint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( slint2.get_allocator() == stack1 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - SlistInt slint1(stack1); - SlistInt slint1Cpy(slint1); - - SlistInt slint2(10, 1, stack2); - SlistInt slint2Cpy(slint2); - - slint1.swap(slint2); - - CPPUNIT_ASSERT( slint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( slint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( slint1 == slint2Cpy ); - CPPUNIT_ASSERT( slint2 == slint1Cpy ); - CPPUNIT_ASSERT( slint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( slint2.get_allocator() == stack1 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - SlistInt slint1(10, 0, stack1); - SlistInt slint1Cpy(slint1); - - SlistInt slint2(stack2); - SlistInt slint2Cpy(slint2); - - slint1.swap(slint2); - - CPPUNIT_ASSERT( slint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( slint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( slint1 == slint2Cpy ); - CPPUNIT_ASSERT( slint2 == slint1Cpy ); - CPPUNIT_ASSERT( slint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( slint2.get_allocator() == stack1 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - //splice(iterator, slist) - { - SlistInt slint1(10, 0, stack1); - SlistInt slint2(10, 1, stack2); - - slint1.splice(slint1.begin(), slint2); - CPPUNIT_ASSERT( slint1.size() == 20 ); - CPPUNIT_ASSERT( slint2.empty() ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - //splice(iterator, slist, iterator) - { - SlistInt slint1(10, 0, stack1); - SlistInt slint2(10, 1, stack2); - - slint1.splice(slint1.begin(), slint2, slint2.begin()); - CPPUNIT_ASSERT( slint1.size() == 11 ); - CPPUNIT_ASSERT( slint2.size() == 9 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - //splice(iterator, slist, iterator, iterator) - { - SlistInt slint1(10, 0, stack1); - SlistInt slint2(10, 1, stack2); - - SlistInt::iterator lit(slint2.begin()); - advance(lit, 5); - slint1.splice(slint1.begin(), slint2, slint2.begin(), lit); - CPPUNIT_ASSERT( slint1.size() == 15 ); - CPPUNIT_ASSERT( slint2.size() == 5 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - //splice_after(iterator, slist) - { - SlistInt slint1(10, 0, stack1); - SlistInt slint2(10, 1, stack2); - - slint1.splice_after(slint1.before_begin(), slint2); - CPPUNIT_ASSERT( slint1.size() == 20 ); - CPPUNIT_ASSERT( slint2.empty() ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - //splice_after(iterator, slist, iterator) - { - SlistInt slint1(10, 0, stack1); - SlistInt slint2(10, 1, stack2); - - slint1.splice_after(slint1.before_begin(), slint2, slint2.before_begin()); - CPPUNIT_ASSERT( slint1.size() == 11 ); - CPPUNIT_ASSERT( slint2.size() == 9 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - //splice_after(iterator, slist, iterator, iterator) - { - SlistInt slint1(10, 0, stack1); - SlistInt slint2(10, 1, stack2); - - SlistInt::iterator lit(slint2.begin()); - advance(lit, 4); - slint1.splice_after(slint1.before_begin(), slint2, slint2.before_begin(), lit); - CPPUNIT_ASSERT( slint1.size() == 15 ); - CPPUNIT_ASSERT( slint2.size() == 5 ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - stack1.reset(); stack2.reset(); - - //merge(slist) - { - SlistInt slint1(10, 0, stack1); - SlistInt slint2(10, 1, stack2); - - SlistInt slintref(stack2); - slintref.insert_after(slintref.before_begin(), 10, 1); - slintref.insert_after(slintref.before_begin(), 10, 0); - - slint1.merge(slint2); - CPPUNIT_ASSERT( slint1.size() == 20 ); - CPPUNIT_ASSERT( slint1 == slintref ); - CPPUNIT_ASSERT( slint2.empty() ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - - //merge(slist, predicate) -# if (!defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)) && \ - (!defined (_MSC_VER) || (_MSC_VER >= 1300)) - { - SlistInt slint1(10, 0, stack1); - SlistInt slint2(10, 1, stack2); - - SlistInt slintref(stack2); - slintref.insert_after(slintref.before_begin(), 10, 0); - slintref.insert_after(slintref.before_begin(), 10, 1); - - slint1.merge(slint2, greater<int>()); - CPPUNIT_ASSERT( slint1.size() == 20 ); - CPPUNIT_ASSERT( slint1 == slintref ); - CPPUNIT_ASSERT( slint2.empty() ); - } - CPPUNIT_CHECK( stack1.ok() ); - CPPUNIT_CHECK( stack2.ok() ); - - //sort - { - //This is rather a compile time test. - //We check that sort implementation is correct when list is instanciated - //with an allocator that do not have a default constructor. - SlistInt slint1(stack1); - slint1.push_front(1); - slint1.insert_after(slint1.before_begin(), 10, 0); - greater<int> gt; - slint1.sort(gt); - CPPUNIT_ASSERT( slint1.front() == 1 ); - slint1.sort(); - SlistInt::iterator slit(slint1.begin()); - advance(slit, 10); - CPPUNIT_ASSERT( *slit == 1 ); - } -# endif -#endif -} - -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) && \ - (!defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)) -# if !defined (__DMC__) -/* Simple compilation test: Check that nested types like iterator - * can be access even if type used to instanciate container is not - * yet completely defined. - */ -class IncompleteClass -{ - slist<IncompleteClass> instances; - typedef slist<IncompleteClass>::iterator it; -}; -# endif -#endif diff --git a/test/unit/sort_test.cpp b/test/unit/sort_test.cpp deleted file mode 100644 index 49bc946..0000000 --- a/test/unit/sort_test.cpp +++ /dev/null @@ -1,217 +0,0 @@ -#include <vector> -#include <algorithm> -#include <functional> - -#if defined (STLPORT) && defined (_STLP_DEBUG) && defined (_STLP_DEBUG_MODE_THROWS) -# define _STLP_DO_CHECK_BAD_PREDICATE -# include <stdexcept> -#endif - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class SortTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SortTest); - CPPUNIT_TEST(sort1); - CPPUNIT_TEST(sort2); - CPPUNIT_TEST(sort3); - CPPUNIT_TEST(sort4); - CPPUNIT_TEST(stblsrt1); - CPPUNIT_TEST(stblsrt2); -#if defined (_STLP_DO_CHECK_BAD_PREDICATE) - CPPUNIT_TEST(bad_predicate_detected); -#endif - CPPUNIT_TEST_SUITE_END(); - -protected: - void sort1(); - void sort2(); - void sort3(); - void sort4(); - void stblsrt1(); - void stblsrt2(); - void bad_predicate_detected(); - - static bool string_less(const char* a_, const char* b_) - { - return strcmp(a_, b_) < 0 ? 1 : 0; - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SortTest); - -// -// tests implementation -// -void SortTest::stblsrt1() -{ - //Check that stable_sort do sort - int numbers[6] = { 1, 50, -10, 11, 42, 19 }; - stable_sort(numbers, numbers + 6); - //-10 1 11 19 42 50 - CPPUNIT_ASSERT(numbers[0]==-10); - CPPUNIT_ASSERT(numbers[1]==1); - CPPUNIT_ASSERT(numbers[2]==11); - CPPUNIT_ASSERT(numbers[3]==19); - CPPUNIT_ASSERT(numbers[4]==42); - CPPUNIT_ASSERT(numbers[5]==50); - - char const* letters[6] = {"bb", "aa", "ll", "dd", "qq", "cc" }; - stable_sort(letters, letters + 6, string_less); - // aa bb cc dd ll qq - CPPUNIT_ASSERT( strcmp(letters[0], "aa") == 0 ); - CPPUNIT_ASSERT( strcmp(letters[1], "bb") == 0 ); - CPPUNIT_ASSERT( strcmp(letters[2], "cc") == 0 ); - CPPUNIT_ASSERT( strcmp(letters[3], "dd") == 0 ); - CPPUNIT_ASSERT( strcmp(letters[4], "ll") == 0 ); - CPPUNIT_ASSERT( strcmp(letters[5], "qq") == 0 ); -} - -struct Data { - Data(int index, int value) - : m_index(index), m_value(value) {} - - bool operator == (const Data& other) const - { return m_index == other.m_index && m_value == other.m_value; } - bool operator < (const Data& other) const - { return m_value < other.m_value; } - -private: - int m_index, m_value; -}; - -void SortTest::stblsrt2() -{ - //Check that stable_sort is stable: - Data datas[] = { - Data(0, 10), - Data(1, 8), - Data(2, 6), - Data(3, 6), - Data(4, 6), - Data(5, 4), - Data(6, 9) - }; - stable_sort(datas, datas + 7); - - CPPUNIT_ASSERT( datas[0] == Data(5, 4) ); - CPPUNIT_ASSERT( datas[1] == Data(2, 6) ); - CPPUNIT_ASSERT( datas[2] == Data(3, 6) ); - CPPUNIT_ASSERT( datas[3] == Data(4, 6) ); - CPPUNIT_ASSERT( datas[4] == Data(1, 8) ); - CPPUNIT_ASSERT( datas[5] == Data(6, 9) ); - CPPUNIT_ASSERT( datas[6] == Data(0, 10) ); -} - -void SortTest::sort1() -{ - int numbers[6] = { 1, 50, -10, 11, 42, 19 }; - - sort(numbers, numbers + 6); - // -10 1 11 19 42 50 - CPPUNIT_ASSERT(numbers[0]==-10); - CPPUNIT_ASSERT(numbers[1]==1); - CPPUNIT_ASSERT(numbers[2]==11); - CPPUNIT_ASSERT(numbers[3]==19); - CPPUNIT_ASSERT(numbers[4]==42); - CPPUNIT_ASSERT(numbers[5]==50); -} - -void SortTest::sort2() -{ - int numbers[] = { 1, 50, -10, 11, 42, 19 }; - - int count = sizeof(numbers) / sizeof(numbers[0]); - sort(numbers, numbers + count, greater<int>()); - - // 50 42 19 11 1 -10 - CPPUNIT_ASSERT(numbers[5]==-10); - CPPUNIT_ASSERT(numbers[4]==1); - CPPUNIT_ASSERT(numbers[3]==11); - CPPUNIT_ASSERT(numbers[2]==19); - CPPUNIT_ASSERT(numbers[1]==42); - CPPUNIT_ASSERT(numbers[0]==50); -} - -void SortTest::sort3() -{ - vector<bool> boolVector; - - boolVector.push_back( true ); - boolVector.push_back( false ); - - sort( boolVector.begin(), boolVector.end() ); - - CPPUNIT_ASSERT(boolVector[0]==false); - CPPUNIT_ASSERT(boolVector[1]==true); -} - -/* - * A small utility class to check a potential compiler bug - * that can result in a bad sort algorithm behavior. The type - * _Tp of the SortTestFunc has to be SortTestAux without any - * reference qualifier. - */ -struct SortTestAux { - SortTestAux (bool &b) : _b(b) - {} - - SortTestAux (SortTestAux const&other) : _b(other._b) { - _b = true; - } - - bool &_b; - -private: - //explicitely defined as private to avoid warnings: - SortTestAux& operator = (SortTestAux const&); -}; - -template <class _Tp> -void SortTestFunc (_Tp) { -} - -void SortTest::sort4() -{ - bool copy_constructor_called = false; - SortTestAux instance(copy_constructor_called); - SortTestAux &r_instance = instance; - SortTestAux const& rc_instance = instance; - - SortTestFunc(r_instance); - CPPUNIT_ASSERT(copy_constructor_called); - copy_constructor_called = false; - SortTestFunc(rc_instance); - CPPUNIT_ASSERT(copy_constructor_called); -} - -#if defined (_STLP_DO_CHECK_BAD_PREDICATE) -void SortTest::bad_predicate_detected() -{ - int numbers[] = { 0, 0, 1, 0, 0, 1, 0, 0 }; - try { - sort(numbers, numbers + sizeof(numbers) / sizeof(numbers[0]), less_equal<int>()); - - //Here is means that no exception has been raised - CPPUNIT_ASSERT( false ); - } - catch (runtime_error const&) - { /*OK bad predicate has been detected.*/ } - - try { - stable_sort(numbers, numbers + sizeof(numbers) / sizeof(numbers[0]), less_equal<int>()); - - //Here is means that no exception has been raised - CPPUNIT_ASSERT( false ); - } - catch (runtime_error const&) - { /*OK bad predicate has been detected.*/ } -} -#endif diff --git a/test/unit/sstream_header_test.cpp b/test/unit/sstream_header_test.cpp deleted file mode 100644 index 784f79a..0000000 --- a/test/unit/sstream_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <sstream> -#endif diff --git a/test/unit/sstream_test.cpp b/test/unit/sstream_test.cpp deleted file mode 100644 index c22066d..0000000 --- a/test/unit/sstream_test.cpp +++ /dev/null @@ -1,487 +0,0 @@ -#include <string> -#include "math_aux.h" - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <sstream> -# include <memory> - -# include "full_streambuf.h" - -# include "cppunit/cppunit_proxy.h" - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -// -// TestCase class -// -class SstreamTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SstreamTest); - CPPUNIT_TEST(output); - CPPUNIT_TEST(input); - CPPUNIT_TEST(input_char); - CPPUNIT_TEST(io); - CPPUNIT_TEST(err); - CPPUNIT_TEST(err_long); - CPPUNIT_TEST(maxint); - CPPUNIT_TEST(init_in); - CPPUNIT_TEST(init_out); - CPPUNIT_TEST(buf); - CPPUNIT_TEST(rdbuf); - CPPUNIT_TEST(streambuf_output); - CPPUNIT_TEST(seek); - CPPUNIT_TEST(seekp); - CPPUNIT_TEST(seek_gp); - CPPUNIT_TEST(tellp); - CPPUNIT_TEST(negative); - CPPUNIT_TEST_SUITE_END(); - - protected: - void output(); - void input(); - void input_char(); - void io(); - void err(); - void err_long(); - void maxint(); - void init_in(); - void init_out(); - void buf(); - void rdbuf(); - void streambuf_output(); - void seek(); - void seekp(); - void seek_gp(); - void tellp(); - void negative(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SstreamTest); - -// -// tests implementation -// -void SstreamTest::output() -{ - { - ostringstream s; - - s << 1 << '\n' << 2.0 << '\n' << "abcd\n" << "ghk lm\n" << "abcd ef"; - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( s.str() == "1\n2\nabcd\nghk lm\nabcd ef" ); - } - - //Following tests are mostly used to reveal problem with the MSVC /Wp64 option - //used to track 64 bits portability issue: - { - ostringstream s; - size_t i = 0; - s << i; - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( s.str() == "0" ); - } - { - ostringstream s; - ptrdiff_t i = 0; - s << i; - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( s.str() == "0" ); - } -} - -void SstreamTest::input() -{ - { - istringstream s( "1\n2\nabcd\nghk lm\nabcd ef" ); - int i = 0; - s >> i; - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( i == 1 ); - double d = 0.0; - s >> d; - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( d == 2.0 ); - string str; - s >> str; - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( str == "abcd" ); - char c; - s.get(c); // extract newline, that not extracted by operator >> - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( c == '\n' ); - getline( s, str ); - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( str == "ghk lm" ); - getline( s, str ); - CPPUNIT_ASSERT( s.eof() ); - CPPUNIT_ASSERT( str == "abcd ef" ); - } - { - istringstream s("0"); - size_t i = 1; - s >> i; - CPPUNIT_ASSERT( !s.fail() ); - CPPUNIT_ASSERT( s.eof() ); - CPPUNIT_ASSERT( i == 0 ); - } -} - -void SstreamTest::input_char() -{ - char buf[16] = { 0, '1', '2', '3' }; - istringstream s( "0" ); - s >> buf; - - CPPUNIT_ASSERT( buf[0] == '0' ); - CPPUNIT_ASSERT( buf[1] == 0 ); - CPPUNIT_ASSERT( buf[2] == '2' ); -} - - -void SstreamTest::io() -{ - stringstream s; - s << 1 << '\n' << 2.0 << '\n' << "abcd\n" << "ghk lm\n" << "abcd ef"; - CPPUNIT_ASSERT( s.good() ); - - int i = 0; - s >> i; - CPPUNIT_ASSERT( i == 1 ); - CPPUNIT_ASSERT( s.good() ); - double d = 0.0; - s >> d; - CPPUNIT_ASSERT( d == 2.0 ); - CPPUNIT_ASSERT( s.good() ); - string str; - s >> str; - CPPUNIT_ASSERT( str == "abcd" ); - CPPUNIT_ASSERT( s.good() ); - char c; - s.get(c); // extract newline, that not extracted by operator >> - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( c == '\n' ); - getline( s, str ); - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( str == "ghk lm" ); - getline( s, str ); - CPPUNIT_ASSERT( str == "abcd ef" ); - CPPUNIT_ASSERT( s.eof() ); -} - -void SstreamTest::err() -{ - stringstream s( "9" ); - - int i = 0; - s >> i; - CPPUNIT_ASSERT( !s.fail() ); - CPPUNIT_ASSERT( i == 9 ); - s >> i; - CPPUNIT_ASSERT( s.fail() ); - CPPUNIT_ASSERT( s.eof() ); - CPPUNIT_ASSERT( i == 9 ); -} - -void SstreamTest::err_long() -{ - stringstream s( "9" ); - - long i = 0; - s >> i; - CPPUNIT_ASSERT( !s.fail() ); - CPPUNIT_ASSERT( i == 9 ); - s >> i; - CPPUNIT_ASSERT( s.fail() ); - CPPUNIT_ASSERT( s.eof() ); - CPPUNIT_ASSERT( i == 9 ); -} - -void SstreamTest::maxint() -{ - stringstream s; - - s << INT_MAX << " " << UINT_MAX << " " << LONG_MAX << " " << ULONG_MAX << " " - << INT_MIN << " " << LONG_MIN; - CPPUNIT_ASSERT( s.good() ); - - int i = 0; - unsigned int u = 0; - long l = 0; - unsigned long ul = 0; - - s >> i >> u >> l >> ul; - CPPUNIT_ASSERT( s.good() ); - CPPUNIT_ASSERT( i == INT_MAX ); - CPPUNIT_ASSERT( u == UINT_MAX ); - CPPUNIT_ASSERT( l == LONG_MAX ); - CPPUNIT_ASSERT( ul == ULONG_MAX ); - - s >> i >> l; - CPPUNIT_ASSERT( !s.fail() ); - CPPUNIT_ASSERT( i == INT_MIN ); - CPPUNIT_ASSERT( l == LONG_MIN ); -} - -void SstreamTest::init_in() -{ - istringstream is( "12345" ); - int n; - - is >> n; - CPPUNIT_ASSERT( !is.fail() ); - CPPUNIT_ASSERT( n == 12345 ); - - istringstream dis( "1.2345" ); - double d; - - dis >> d; - CPPUNIT_ASSERT( !dis.fail() ); - CPPUNIT_ASSERT( are_equals(d, 1.2345) ); - - istringstream fis( "1.2345" ); - float f; - - fis >> f; - CPPUNIT_ASSERT( !fis.fail() ); - CPPUNIT_ASSERT( are_equals(f, 1.2345f) ); -} - -void SstreamTest::init_out() -{ - ostringstream os( "12345" ); - CPPUNIT_ASSERT( os.str() == "12345" ); - - os << 67; - CPPUNIT_ASSERT( os.good() ); - - // This satisfy to the Standard: - // CPPUNIT_ASSERT( os.str() == "67345" ); - // But we don't know the reason, why standard state that. - - /* - * 27.7.1.1: ... then copies the content of str into the basic_sringbuf - * underlying character sequence and initializes the input and output - * sequences according to which. If which & ios_base::out is true, initializes - * the output sequence with underlying sequence. ... - * - * I can treat this as 'like output was performed', and then I should bump - * put pointer... Looks like more useful then my previous treatment. - * - * - ptr - */ - - CPPUNIT_ASSERT( os.str() == "1234567" ); - - - os.str( "89ab" ); - CPPUNIT_ASSERT( os.str() == "89ab" ); - - os << 10; - CPPUNIT_ASSERT( os.good() ); - // CPPUNIT_ASSERT( os.str() == "10ab" ); - CPPUNIT_ASSERT( os.str() == "89ab10" ); -} - -void SstreamTest::buf() -{ - stringstream ss; - - ss << "1234567\n89\n"; - char buf[10]; - buf[7] = 'x'; - ss.get( buf, 10 ); - CPPUNIT_ASSERT( !ss.fail() ); - CPPUNIT_ASSERT( buf[0] == '1' ); - CPPUNIT_ASSERT( buf[1] == '2' ); - CPPUNIT_ASSERT( buf[2] == '3' ); - CPPUNIT_ASSERT( buf[3] == '4' ); - CPPUNIT_ASSERT( buf[4] == '5' ); - CPPUNIT_ASSERT( buf[5] == '6' ); - CPPUNIT_ASSERT( buf[6] == '7' ); // 27.6.1.3 paragraph 10, paragraph 7 - CPPUNIT_ASSERT( buf[7] == 0 ); // 27.6.1.3 paragraph 8 - char c; - ss.get(c); - CPPUNIT_ASSERT( !ss.fail() ); - CPPUNIT_ASSERT( c == '\n' ); // 27.6.1.3 paragraph 10, paragraph 7 - ss.get(c); - CPPUNIT_ASSERT( !ss.fail() ); - CPPUNIT_ASSERT( c == '8' ); -} - -void SstreamTest::rdbuf() -{ - stringstream ss; - - ss << "1234567\n89\n"; - - ostringstream os; - ss.get( *os.rdbuf(), '\n' ); - CPPUNIT_ASSERT( !ss.fail() ); - char c; - ss.get(c); - CPPUNIT_ASSERT( !ss.fail() ); - CPPUNIT_ASSERT( c == '\n' ); // 27.6.1.3 paragraph 12 - CPPUNIT_ASSERT( os.str() == "1234567" ); -} - -void SstreamTest::streambuf_output() -{ - { - istringstream in("01234567890123456789"); - CPPUNIT_ASSERT( in ); - - full_streambuf full_buf(10); - ostream out(&full_buf); - CPPUNIT_ASSERT( out ); - - out << in.rdbuf(); - CPPUNIT_ASSERT( out ); - CPPUNIT_ASSERT( in ); - //out is good we can check what has been extracted: - CPPUNIT_ASSERT( full_buf.str() == "0123456789" ); - - out << in.rdbuf(); - CPPUNIT_ASSERT( out.fail() ); - CPPUNIT_ASSERT( in ); - - ostringstream ostr; - ostr << in.rdbuf(); - CPPUNIT_ASSERT( ostr ); - CPPUNIT_ASSERT( in ); - CPPUNIT_ASSERT( ostr.str() == "0123456789" ); - } - -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - { - //If the output stream buffer throws: - istringstream in("01234567890123456789"); - CPPUNIT_ASSERT( in ); - - full_streambuf full_buf(10, true); - ostream out(&full_buf); - CPPUNIT_ASSERT( out ); - - out << in.rdbuf(); - CPPUNIT_ASSERT( out.bad() ); - CPPUNIT_ASSERT( in ); - //out is bad we have no guaranty on what has been extracted: - //CPPUNIT_ASSERT( full_buf.str() == "0123456789" ); - - out.clear(); - out << in.rdbuf(); - CPPUNIT_ASSERT( out.fail() && out.bad() ); - CPPUNIT_ASSERT( in ); - - ostringstream ostr; - ostr << in.rdbuf(); - CPPUNIT_ASSERT( ostr ); - CPPUNIT_ASSERT( in ); - CPPUNIT_ASSERT( ostr.str() == "01234567890123456789" ); - } -# endif -} - -void SstreamTest::seek() -{ - stringstream s( "0123456789" ); - - CPPUNIT_ASSERT( s.tellg() == stringstream::pos_type(0) ); - s.seekg( 6, ios::beg ); - CPPUNIT_ASSERT( s.tellg() == stringstream::pos_type(6) ); - s.seekg( -3, ios::cur ); - CPPUNIT_ASSERT( s.tellg() == stringstream::pos_type(3) ); - - istringstream is( "0123456789" ); - CPPUNIT_ASSERT( is.tellg() == stringstream::pos_type(0) ); - is.seekg( 6, ios::beg ); - CPPUNIT_ASSERT( is.tellg() == stringstream::pos_type(6) ); - is.seekg( -3, ios::cur ); - CPPUNIT_ASSERT( is.tellg() == stringstream::pos_type(3) ); -} - -void SstreamTest::seekp() -{ - ostringstream s; - - s << "1234567"; - CPPUNIT_CHECK( s.tellp() == stringstream::pos_type(7) ); - CPPUNIT_CHECK( s.str() == "1234567" ); - s.seekp( 0 ); - s << "X"; - CPPUNIT_CHECK( s.str() == "X234567" ); - s.seekp( 0, ios::beg ); - s << "Y"; - CPPUNIT_CHECK( s.str() == "Y234567" ); -} - -void SstreamTest::seek_gp() -{ - stringstream ss( "1" ); - - /* ISO/IEC 14882 2003 (and 1998 too) assume change as get as put positions - with seekg and seekp (27.6.1.3, par 38; 27.6.2.4 par 2), - but this contradict to common practice and proposed draft N2588 - (27.6.1.3, par 41; 27.6.2.5, par 4) - - Now STLport implement (i.e. change behaviour ) the draft's point of view. - */ - - ss.seekg( 0, ios::beg ); - ss.seekp( 0, ios::end ); - - ss << "2"; - - string str; - - ss >> str; - - /* CPPUNIT_CHECK( str == "2" ); --- according ISO/IEC 14882 2003 */ - CPPUNIT_CHECK( str == "12" ); -} - -void SstreamTest::tellp() -{ - { - ostringstream o( "1" ); - - o << "23456"; - - CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == stringstream::pos_type(6) ); - CPPUNIT_CHECK( o.tellp() == stringstream::pos_type(6) ); - } - { - ostringstream o; - - o << "123456"; - - CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == stringstream::pos_type(6) ); - CPPUNIT_CHECK( o.tellp() == stringstream::pos_type(6) ); - } - { - ostringstream o( "1" ); - - o << "23456789"; - - CPPUNIT_CHECK( o.rdbuf()->pubseekoff( 0, ios_base::cur, ios_base::out ) == stringstream::pos_type(9) ); - CPPUNIT_CHECK( o.tellp() == stringstream::pos_type(9) ); - } -} - - -template < class T > -string to_string( const T& v ) -{ - ostringstream oss; - oss << v; - return oss.str(); -} - -void SstreamTest::negative() -{ - CPPUNIT_CHECK( to_string<int>(-1) == "-1" ); - CPPUNIT_CHECK( to_string<long>(-1) == "-1" ); -} - -#endif diff --git a/test/unit/stack_allocator.h b/test/unit/stack_allocator.h deleted file mode 100644 index 93db960..0000000 --- a/test/unit/stack_allocator.h +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef STLPORT_UNIT_TEST_STACK_ALLOCATOR_H -#define STLPORT_UNIT_TEST_STACK_ALLOCATOR_H - -#include <algorithm> - -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -//For bad_alloc: -# include <new> -#endif - -#undef __STD -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -# define __STD std:: -#else -# define __STD -#endif - -struct State { - char *m_beg, *m_end, *m_cur; - bool m_isOk, m_swaped; - int m_nbAlloc; - - //The following members are shared among all StackAllocator instance created from - //a reference StackAllocator instance: - char **m_sharedCur; - bool *m_sharedOk; - int *m_sharedNbAlloc; - -#if defined (__DMC__) - State(){} -#endif - - State(char *beg, char *end) - : m_beg(beg), m_end(end), m_cur(m_beg), m_isOk(true), m_swaped(false), m_nbAlloc(0), - m_sharedCur(&m_cur), m_sharedOk(&m_isOk), m_sharedNbAlloc(&m_nbAlloc) {} - - State(const State& other) - : m_beg(other.m_beg), m_end(other.m_end), m_cur(0), - m_isOk(true), m_swaped(other.m_swaped), m_nbAlloc(0), - m_sharedCur(other.m_sharedCur), m_sharedOk(other.m_sharedOk), - m_sharedNbAlloc(other.m_sharedNbAlloc) {} -}; - -/* This allocator is not thread safe: - */ -template <class _Tp> -struct StackAllocator -#if defined (STLPORT) && \ - defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) - //Special Borland workaround that have problem with function - //overloading when one of the overloaded version is a template - //one. This is the case for the std::swap function. - : public __STD __stlport_class<StackAllocator<_Tp> > -#endif -{ - typedef _Tp value_type; - typedef value_type * pointer; - typedef const _Tp* const_pointer; - typedef _Tp& reference; - typedef const _Tp& const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - -#if defined (__DMC__) - StackAllocator(){} -#endif - - StackAllocator(char *beg, char *end) - : m_state(beg, end) {} - - const State& getState() const { return m_state; } -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES) - template <class _OtherTp> - StackAllocator(StackAllocator<_OtherTp> const& other) - : m_state(other.getState()) {} -#else - StackAllocator(const State& state) - : m_state(state) {} -#endif - -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATE_CLASSES) - template <class _Other> - struct rebind { - typedef StackAllocator<_Other> other; - }; -#endif - - _Tp* allocate(size_type n, void* = 0) { - if (n == 0) - return 0; - - ++(*m_state.m_sharedNbAlloc); - - if (*m_state.m_sharedCur + (n * sizeof(_Tp)) < m_state.m_end) { - char *ret = *m_state.m_sharedCur; - *m_state.m_sharedCur += n * sizeof(_Tp); - return reinterpret_cast<_Tp*>(ret); - } -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - throw __STD bad_alloc(); -# if defined (__DMC__) - return 0; -# endif -#else - return 0; -#endif - } - -#if defined (STLPORT) && \ - defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) - //Necessary extension to make StackAllocator a real STLport allocator - //implementation: - _Tp* _M_allocate(size_type n, size_type &new_n) { - new_n = n; - return allocate(n); - } -#endif - - void deallocate(pointer p, size_type n) { - if (p == 0) - return; - - --(*m_state.m_sharedNbAlloc); - - if ((char*)p == (*m_state.m_sharedCur - n * sizeof(_Tp))) { - *m_state.m_sharedCur -= n * sizeof(_Tp); - } - - if ((char*)p < m_state.m_beg || (char*)p >= m_state.m_end) { - //An object has been returned to the bad allocator instance: - *m_state.m_sharedOk = false; - } - } - - pointer address(reference __x) const {return &__x;} - const_pointer address(const_reference __x) const { return &__x; } - size_type max_size() const { return m_state.m_end - *m_state.m_sharedCur; } - void construct(pointer __p, const_reference __val) { new(__p) _Tp(__val); } - void destroy(pointer __p) { __p->~_Tp(); } - - bool ok() const { return m_state.m_isOk && (m_state.m_nbAlloc == 0); } - void reset () { - m_state.m_cur = m_state.m_beg; - m_state.m_isOk = true; - m_state.m_swaped = false; - } - bool swaped() const { return m_state.m_swaped; } - void swap(StackAllocator &other) { - __STD swap(m_state, other.m_state); - m_state.m_swaped = true; - other.m_state.m_swaped = true; - } -#if defined (STLPORT) && \ - defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) - void _M_swap_workaround(StackAllocator& __x) { swap(__x); } -#endif - - //2 StackAllocator instance are identical if they are built on top - //of the same buffer. - bool operator == (StackAllocator const& other) const - { return m_state.m_beg == other.m_state.m_beg; } - - bool operator != (StackAllocator const& other) const - { return !(*this == other); } - -private: - State m_state; -}; - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -namespace std { -#endif - -# if defined (STLPORT) && (defined (_STLP_DONT_SUPPORT_REBIND_MEMBER_TEMPLATE) || !defined (_STLP_MEMBER_TEMPLATES)) -template <class _Tp1, class _Tp2> -inline StackAllocator<_Tp2>& -__stl_alloc_rebind(StackAllocator<_Tp1>& __a, const _Tp2*) { return (StackAllocator<_Tp2>&)(__a); } -template <class _Tp1, class _Tp2> -inline StackAllocator<_Tp2> -__stl_alloc_create(const StackAllocator<_Tp1>& __a, const _Tp2*) { return StackAllocator<_Tp2>(__a.getState()); } -# endif - -# if !defined (STLPORT) || defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) - template <class _Tp> - inline void swap(StackAllocator<_Tp>& __a, StackAllocator<_Tp>& __b) - { __a.swap(__b); } -# elif !defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) -//The following overloads depends on instanciation, if new unit tests are written -//with new StackAllocator instanciations associated swap overload should also be -//written -inline void swap(StackAllocator<int>& __a, StackAllocator<int>& __b) -{ __a.swap(__b); } -inline void swap(StackAllocator<char>& __a, StackAllocator<char>& __b) -{ __a.swap(__b); } -inline void swap(StackAllocator<pair<const int, int> >& __a, - StackAllocator<pair<const int, int> >& __b) -{ __a.swap(__b); } -# endif - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -} -#endif - -#undef __STD - -#endif //STLPORT_UNIT_TEST_STACK_ALLOCATOR_H diff --git a/test/unit/stack_header_test.cpp b/test/unit/stack_header_test.cpp deleted file mode 100644 index 39946ea..0000000 --- a/test/unit/stack_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <stack> diff --git a/test/unit/stack_test.cpp b/test/unit/stack_test.cpp deleted file mode 100644 index 5ff2aaa..0000000 --- a/test/unit/stack_test.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include <algorithm> -#include <list> -#include <queue> -#include <deque> -#include <stack> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class StackTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(StackTest); - CPPUNIT_TEST(stack1); - CPPUNIT_TEST(stack2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void stack1(); - void stack2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(StackTest); - -// -// tests implementation -// -void StackTest::stack1() -{ - stack<int, deque<int> > s; - s.push(42); - s.push(101); - s.push(69); - CPPUNIT_ASSERT(s.top()==69); - s.pop(); - CPPUNIT_ASSERT(s.top()==101); - s.pop(); - CPPUNIT_ASSERT(s.top()==42); - s.pop(); - CPPUNIT_ASSERT(s.empty()); -} -void StackTest::stack2() -{ - stack<int, list<int> > s; - s.push(42); - s.push(101); - s.push(69); - CPPUNIT_ASSERT(s.top()==69); - s.pop(); - CPPUNIT_ASSERT(s.top()==101); - s.pop(); - CPPUNIT_ASSERT(s.top()==42); - s.pop(); - CPPUNIT_ASSERT(s.empty()); -} diff --git a/test/unit/stdarg_header_test.c b/test/unit/stdarg_header_test.c deleted file mode 100644 index 9901cba..0000000 --- a/test/unit/stdarg_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <stdarg.h> diff --git a/test/unit/stddef_header_test.c b/test/unit/stddef_header_test.c deleted file mode 100644 index eb00372..0000000 --- a/test/unit/stddef_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <stddef.h> diff --git a/test/unit/stdexcept_header_test.cpp b/test/unit/stdexcept_header_test.cpp deleted file mode 100644 index d8114e6..0000000 --- a/test/unit/stdexcept_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <stdexcept> diff --git a/test/unit/stdio_header_test.c b/test/unit/stdio_header_test.c deleted file mode 100644 index d8f42c1..0000000 --- a/test/unit/stdio_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <stdio.h> diff --git a/test/unit/stdlib_header_test.c b/test/unit/stdlib_header_test.c deleted file mode 100644 index a43f906..0000000 --- a/test/unit/stdlib_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <stdlib.h> diff --git a/test/unit/stldbg_include.cpp b/test/unit/stldbg_include.cpp deleted file mode 100644 index ab2c9a8..0000000 --- a/test/unit/stldbg_include.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This is compile-time test for situation below not happen. - * STLport use many defines and auxilary structures, namespaces and templates - * that included via _prolog.h. After preprocessor phase we may see: - * - * extern "C" { - * - * namespace std { } - * - * - * This is bad, but acceptable. But in STLPORT_DEBUG mode we can see - * - * extern "C" { - * - * namespace std { - * namespace private { - * - * template <class _Dummy> - * class __stl_debug_engine { - * - * - * This lead to compile-time error. - * [This due to sys/types.h contains - * - * __BEGIN_DECLS - * #include <bits/types.h> - * - * - * i.e. include other headers within extern "C" { scope. Bad, but this is fact.] - * - * Origin of problem: STLport provide proxy-headers as for C++ headers, as for C - * headers. For C headers, we shouldn't expose C++ constructions, because system - * headers may include each other by unexpected way (from STLport point of view). - * - * - ptr, 2007-04-05 - */ - -#ifdef __unix -# include <sys/types.h> -#endif diff --git a/test/unit/streambuf_header_test.cpp b/test/unit/streambuf_header_test.cpp deleted file mode 100644 index 935f909..0000000 --- a/test/unit/streambuf_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <streambuf> -#endif diff --git a/test/unit/string_header_test.c b/test/unit/string_header_test.c deleted file mode 100644 index a242eeb..0000000 --- a/test/unit/string_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <string.h> diff --git a/test/unit/string_header_test.cpp b/test/unit/string_header_test.cpp deleted file mode 100644 index 4f36b27..0000000 --- a/test/unit/string_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <string> diff --git a/test/unit/string_test.cpp b/test/unit/string_test.cpp deleted file mode 100644 index 987d68e..0000000 --- a/test/unit/string_test.cpp +++ /dev/null @@ -1,1427 +0,0 @@ -//To make GLib C++ closer to STLport behavior we need this macro: -//Only mandatory when building unit tests without STLport, do not change -//anything when building with STLport -#define _GLIBCXX_FULLY_DYNAMIC_STRING - -//Has to be first for StackAllocator swap overload to be taken -//into account (at least using GCC 4.0.1) -#include "stack_allocator.h" - -#include <vector> -#include <deque> -#include <string> -#include <algorithm> -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <sstream> -#endif - -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -# include <stdexcept> -#endif - -#if !defined (STLPORT) || defined (_STLP_THREADS) -# if defined (STLPORT) && defined (_STLP_PTHREADS) || \ - defined (__GNUC__) && !defined (__MINGW32__) -# define USE_PTHREAD_API -# include <pthread.h> -# endif - -# if defined (STLPORT) && defined (_STLP_WIN32THREADS) || \ - defined (__GNUC__) && defined (__MINGW32__) || \ - defined (_MSC_VER) -# define USE_WINDOWS_API -# include <windows.h> -# endif -#endif - -#include "stack_allocator.h" -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class StringTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(StringTest); - CPPUNIT_TEST(constructor); - CPPUNIT_TEST(trivial_char_compare); - CPPUNIT_TEST(reserve); - CPPUNIT_TEST(assign); - CPPUNIT_TEST(erase); - CPPUNIT_TEST(data); - CPPUNIT_TEST(c_str); - CPPUNIT_TEST(null_char); - CPPUNIT_TEST(insert); - CPPUNIT_TEST(replace); - CPPUNIT_TEST(resize); - CPPUNIT_TEST(short_string); - CPPUNIT_TEST(find); - CPPUNIT_TEST(bogus_edge_find); - CPPUNIT_TEST(rfind); - CPPUNIT_TEST(find_last_of); - CPPUNIT_TEST(find_last_not_of); - CPPUNIT_TEST(copy); -#if !defined (USE_PTHREAD_API) && !defined (USE_WINDOWS_API) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(mt); - CPPUNIT_STOP_IGNORE; - CPPUNIT_TEST(short_string_optim_bug); - CPPUNIT_TEST(compare); - CPPUNIT_TEST(template_expression); -#if defined (STLPORT) && ((defined (_STLP_MSVC) && (_STLP_MSVC < 1300)) || \ - (defined(__GNUC__) && defined(_STLP_USE_TEMPLATE_EXPRESSION) && \ - ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)) ) ) -# define TE_TMP_TEST_IGNORED - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(te_tmp); -#if defined (TE_TMP_TEST_IGNORED) - CPPUNIT_STOP_IGNORE; -#endif - CPPUNIT_TEST(oper_tmp); -#if defined (STLPORT) && defined (_STLP_NO_WCHAR_T) - CPPUNIT_IGNORE; -#endif -#if defined (__CYGWIN__) && !defined (STLPORT) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(template_wexpression); - CPPUNIT_STOP_IGNORE; -#if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(io); - CPPUNIT_STOP_IGNORE; -#if defined (STLPORT) && defined (_STLP_NO_CUSTOM_IO) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(allocator_with_state); - CPPUNIT_STOP_IGNORE; - CPPUNIT_TEST(capacity); - CPPUNIT_TEST(concat24); - CPPUNIT_TEST_SUITE_END(); - -protected: - void constructor(); - void trivial_char_compare(); - void reserve(); - void erase(); - void data(); - void c_str(); - void null_char(); - void insert(); - void replace(); - void resize(); - void short_string(); - void find(); - void bogus_edge_find(); - void rfind(); - void find_last_of(); - void find_last_not_of(); - void copy(); - void assign(); - void mt(); - void short_string_optim_bug(); - void compare(); - void template_expression(); - void te_tmp(); - void oper_tmp(); - void template_wexpression(); - void io(); - void allocator_with_state(); - void capacity(); - void concat24(); - - static string func(const string& par) { - string tmp( par ); - return tmp; - } - -#if defined (USE_PTHREAD_API) || defined (USE_WINDOWS_API) -# if defined (USE_PTHREAD_API) - static void* f(void*) -# else - static DWORD __stdcall f(void*) -# endif - { - string s( "qyweyuewunfkHBUKGYUGL,wehbYGUW^(@T@H!BALWD:h^&@#*@(#:JKHWJ:CND" ); - - for ( int i = 0; i < 2000000; ++i ) { - string sx = func( s ); - } - - return 0; - } -#endif - -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(StringTest); - -// -// tests implementation -// -void StringTest::constructor() -{ -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { - string s((size_t)-1, 'a'); - CPPUNIT_FAIL; - } - catch (length_error const&) { - } - catch (...) { - //Expected exception is length_error: - CPPUNIT_FAIL; - } -#endif -} - -void StringTest::trivial_char_compare() -{ - string s( "message" ); - - CPPUNIT_CHECK( s == "message" ); - CPPUNIT_CHECK( "message" == s ); -} - -void StringTest::reserve() -{ - string s; -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { - s.reserve(s.max_size() + 1); - CPPUNIT_FAIL; - } - catch (length_error const&) { - } - catch (...) { - //Expected exception is length_error: - CPPUNIT_FAIL; - } -#endif -} - -void StringTest::mt() -{ -#if defined (USE_PTHREAD_API) || defined (USE_WINDOWS_API) - const int nth = 2; -# if defined (USE_PTHREAD_API) - pthread_t t[nth]; - - for ( int i = 0; i < nth; ++i ) { - pthread_create( &t[i], 0, f, 0 ); - } - - for ( int i = 0; i < nth; ++i ) { - pthread_join( t[i], 0 ); - } -# endif // PTHREAD - -# if defined (USE_WINDOWS_API) - //DWORD start = GetTickCount(); - - HANDLE t[nth]; - - int i; // VC6 not support in-loop scope of cycle var - for ( i = 0; i < nth; ++i ) { - t[i] = CreateThread(NULL, 0, f, 0, 0, NULL); - } - - if (WaitForMultipleObjects(nth, t, TRUE, INFINITE) == WAIT_FAILED) { - // On some platforms (evc3/evc4) WaitForMultipleObjects() with fWaitAll == TRUE - // is not supported. We then wait with a loop on each thread: - for ( i = 0; i < nth; ++i ) { - WaitForSingleObject(t[i], INFINITE); - } - } - - /* - DWORD duration = GetTickCount() - start; - ostringstream ostr; - ostr << "Duration: " << duration << endl; - CPPUNIT_MESSAGE(ostr.str().c_str()); - */ -# endif -#endif -} - -void StringTest::short_string() -{ - string const ref_short_str1("str1"), ref_short_str2("str2"); - string short_str1(ref_short_str1), short_str2(ref_short_str2); - string const ref_long_str1("str 1"); - string const ref_long_str2("str 2"); - string long_str1(ref_long_str1), long_str2(ref_long_str2); - - CPPUNIT_ASSERT(short_str1 == ref_short_str1); - CPPUNIT_ASSERT(long_str1 == ref_long_str1); - - { - string str1(short_str1); - str1 = long_str1; - CPPUNIT_ASSERT(str1 == ref_long_str1); - } - - { - string str1(long_str1); - str1 = short_str1; - CPPUNIT_ASSERT(str1 == ref_short_str1); - } - - { - short_str1.swap(short_str2); - CPPUNIT_ASSERT((short_str1 == ref_short_str2) && (short_str2 == ref_short_str1)); - short_str1.swap(short_str2); - } - - { - long_str1.swap(long_str2); - CPPUNIT_ASSERT((long_str1 == ref_long_str2) && (long_str2 == ref_long_str1)); - long_str1.swap(long_str2); - } - - { - short_str1.swap(long_str1); - CPPUNIT_ASSERT((short_str1 == ref_long_str1) && (long_str1 == ref_short_str1)); - short_str1.swap(long_str1); - } - - { - long_str1.swap(short_str1); - CPPUNIT_ASSERT((short_str1 == ref_long_str1) && (long_str1 == ref_short_str1)); - long_str1.swap(short_str1); - } - - { - string a(256, 'a'); - string b(256, 'b'); - const char* as = a.c_str(); - const char* bs = b.c_str(); - swap(a, b); - CPPUNIT_ASSERT( a.c_str() == bs ); - CPPUNIT_ASSERT( b.c_str() == as ); - } - - { - //This is to test move constructor - vector<string> str_vect; - str_vect.push_back(short_str1); - str_vect.push_back(long_str1); - str_vect.push_back(short_str2); - str_vect.push_back(long_str2); - CPPUNIT_ASSERT((str_vect[0] == ref_short_str1) && - (str_vect[1] == ref_long_str1) && - (str_vect[2] == ref_short_str2) && - (str_vect[3] == ref_long_str2)); - } -} - -void StringTest::erase() -{ - char const* c_str = "Hello, World!"; - string str(c_str); - CPPUNIT_ASSERT( str == c_str ); - - str.erase(str.begin() + 1, str.end() - 1); // Erase all but first and last. - - size_t i; - for (i = 0; i < str.size(); ++i) { - switch ( i ) { - case 0: - CPPUNIT_ASSERT( str[i] == 'H' ); - break; - case 1: - CPPUNIT_ASSERT( str[i] == '!' ); - break; - default: - CPPUNIT_FAIL; - } - } - - str.insert(1, c_str); - str.erase(str.begin()); // Erase first element. - str.erase(str.end() - 1); // Erase last element. - CPPUNIT_ASSERT( str == c_str ); - str.clear(); // Erase all. - CPPUNIT_ASSERT( str.empty() ); - - str = c_str; - CPPUNIT_ASSERT( str == c_str ); - - str.erase(1, str.size() - 1); // Erase all but first and last. - for (i = 0; i < str.size(); i++) { - switch ( i ) { - case 0: - CPPUNIT_ASSERT( str[i] == 'H' ); - break; - case 1: - CPPUNIT_ASSERT( str[i] == '!' ); - break; - default: - CPPUNIT_FAIL; - } - } - - str.erase(1); - CPPUNIT_ASSERT( str == "H" ); -} - -void StringTest::data() -{ - string xx; - - CPPUNIT_ASSERT( xx.data() != 0 ); // ISO-IEC-14882:1998(E), 21.3.6, paragraph 3 -#if 0 - /* This test really not required: in ISO-IEC-14882:1998(E) paragraph 3 stated: - * '... and can have zero added to it', again: 'CAN', but not 'MUST'. - * That's why I am comment this test. But I don't remove it due to I had - * unevident problem with misinterpretation of data() return (i.e. data() - * and c_str() provide different functionality!) and expect that this is - * more-or-less common pitfall. - * - ptr - */ - string low( "2004-01-01" ); - // Blocks A and B should follow each other. - // Block A: - xx = "123456"; - xx += low; - if ( strcmp( xx.data(), "1234562004-01-01" ) != 0 ) { - return -1; - } - // End of block A - - // Block B: - xx = "1234"; - xx += ";"; - - if ( strcmp( xx.data(), "1234;" ) != 0 ) { - return -1; - } - // End of block B -#endif -} - -void StringTest::c_str() -{ - string low( "2004-01-01" ); - string xx; - string yy; - - CPPUNIT_ASSERT( *(yy.c_str()) == '\0' ); // ISO-IEC-14882:1998(E), 21.3.6, paragraph 1 - - // Blocks A and B should follow each other. - // Block A: - xx = "123456"; - xx += low; - CPPUNIT_ASSERT( strcmp( xx.c_str(), "1234562004-01-01" ) == 0 ); - // End of block A - - // Block B: - xx = "1234"; - xx += ";"; - CPPUNIT_ASSERT( strcmp( xx.c_str(), "1234;" ) == 0 ); - // End of block B -} - -void StringTest::null_char() -{ - // ISO/IEC 14882:1998(E), ISO/IEC 14882:2003(E), 21.3.4 ('... the const version') - const string s( "123456" ); - - CPPUNIT_CHECK( s[s.size()] == '\0' ); - -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { - //Check is only here to avoid warning about value of expression not used - CPPUNIT_CHECK( s.at(s.size()) == '\0' ); - CPPUNIT_FAIL; - } - catch (out_of_range const&) { - CPPUNIT_ASSERT( true ); - } - catch ( ... ) { - CPPUNIT_FAIL; - } -#endif -} - -void StringTest::insert() -{ - string strorg = "This is test string for string calls"; - string str; - /* - * In case of reallocation there is no auto reference problem - * so we reserve a big enough string to be sure to test this - * particular point. - */ - str.reserve(100); - str = strorg; - - //test self insertion: - str.insert(10, str.c_str() + 5, 15); - CPPUNIT_ASSERT( str == "This is teis test string st string for string calls" ); - - str = strorg; - str.insert(15, str.c_str() + 5, 25); - CPPUNIT_ASSERT( str == "This is test stis test string for stringring for string calls" ); - - str = strorg; - str.insert(0, str.c_str() + str.size() - 4, 4); - CPPUNIT_ASSERT( str == "allsThis is test string for string calls" ); - - str = strorg; - str.insert(0, str.c_str() + str.size() / 2 - 1, str.size() / 2 + 1); - CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" ); - - str = strorg; - string::iterator b = str.begin(); - string::const_iterator s = str.begin() + str.size() / 2 - 1; - string::const_iterator e = str.end(); - str.insert( b, s, e ); - CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" ); - - str = strorg; - str.insert(str.begin(), str.begin() + str.size() / 2 - 1, str.end()); - CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" ); - -#ifdef _STLP_MEMBER_TEMPLATES - vector<int> int_vect; - //Just a compile time test: - str.insert(str.end(), int_vect.begin(), int_vect.end()); -#endif - - string str0; - str0.insert(str0.begin(), 5, '0'); - CPPUNIT_ASSERT( str0 == "00000" ); - - string str1; - { - string::size_type pos = 0, nb = 2; - str1.insert(pos, nb, '1'); - } - CPPUNIT_ASSERT( str1 == "11" ); - - str0.insert(0, str1); - CPPUNIT_ASSERT( str0 == "1100000" ); - - string str2("2345"); - str0.insert(str0.size(), str2, 1, 2); - CPPUNIT_ASSERT( str0 == "110000034" ); - - str1.insert(str1.begin() + 1, 2, '2'); - CPPUNIT_ASSERT( str1 == "1221" ); - - str1.insert(2, "333333", 3); - CPPUNIT_ASSERT( str1 == "1233321" ); - - str1.insert(4, "4444"); - CPPUNIT_ASSERT( str1 == "12334444321" ); - - str1.insert(str1.begin() + 6, '5'); - CPPUNIT_ASSERT( str1 == "123344544321" ); -} - -void StringTest::replace() -{ - /* - * This test case is for the non template basic_string::replace method, - * this is why we play with the const iterators and reference to guaranty - * that the right method is called. - */ - const string v( "78" ); - string s( "123456" ); - string const& cs = s; - - string::iterator i = s.begin() + 1; - s.replace(i, i + 3, v.begin(), v.end()); - CPPUNIT_ASSERT( s == "17856" ); - - s = "123456"; - i = s.begin() + 1; - s.replace(i, i + 1, v.begin(), v.end()); - CPPUNIT_ASSERT( s == "1783456" ); - - s = "123456"; - i = s.begin() + 1; - string::const_iterator ci = s.begin() + 1; - s.replace(i, i + 3, ci + 3, cs.end()); - CPPUNIT_ASSERT( s == "15656" ); - - s = "123456"; - i = s.begin() + 1; - ci = s.begin() + 1; - s.replace(i, i + 3, ci, ci + 2); - CPPUNIT_ASSERT( s == "12356" ); - - s = "123456"; - i = s.begin() + 1; - ci = s.begin() + 1; - s.replace(i, i + 3, ci + 1, cs.end()); - CPPUNIT_ASSERT( s == "1345656" ); - - s = "123456"; - i = s.begin(); - ci = s.begin() + 1; - s.replace(i, i, ci, ci + 1); - CPPUNIT_CHECK( s == "2123456" ); - - s = "123456"; - s.replace(s.begin() + 4, s.end(), cs.begin(), cs.end()); - CPPUNIT_ASSERT( s == "1234123456" ); - - /* - * This is the test for the template replace method. - */ - s = "123456"; - string::iterator b = s.begin() + 4; - string::iterator e = s.end(); - string::const_iterator rb = s.begin(); - string::const_iterator re = s.end(); - s.replace(b, e, rb, re); - CPPUNIT_ASSERT( s == "1234123456" ); - - s = "123456"; - s.replace(s.begin() + 4, s.end(), s.begin(), s.end()); - CPPUNIT_ASSERT( s == "1234123456" ); - - string strorg("This is test string for string calls"); - string str = strorg; - str.replace(5, 15, str.c_str(), 10); - CPPUNIT_ASSERT( str == "This This is tefor string calls" ); - - str = strorg; - str.replace(5, 5, str.c_str(), 10); - CPPUNIT_ASSERT( str == "This This is test string for string calls" ); - -#if (defined (STLPORT) && defined(_STLP_MEMBER_TEMPLATES)) || ( !defined (STLPORT) && !defined(__GNUC__) ) - deque<char> cdeque; - cdeque.push_back('I'); - str.replace(str.begin(), str.begin() + 11, cdeque.begin(), cdeque.end()); - CPPUNIT_ASSERT( str == "Is test string for string calls" ); -#endif -} - -void StringTest::resize() -{ - string s; - - s.resize(0); - - CPPUNIT_ASSERT( *s.c_str() == 0 ); - - s = "1234567"; - - s.resize(0); - CPPUNIT_ASSERT( *s.c_str() == 0 ); - - s = "1234567"; - s.resize(1); - CPPUNIT_ASSERT( s.size() == 1 ); - CPPUNIT_ASSERT( *s.c_str() == '1' ); - CPPUNIT_ASSERT( *(s.c_str() + 1) == 0 ); - - s = "1234567"; - s.resize(10); - CPPUNIT_ASSERT( s.size() == 10 ); - CPPUNIT_ASSERT( s[6] == '7' ); - CPPUNIT_ASSERT( s[7] == 0 ); - CPPUNIT_ASSERT( s[8] == 0 ); - CPPUNIT_ASSERT( s[9] == 0 ); -} - -void StringTest::find() -{ - string s("one two three one two three"); - CPPUNIT_ASSERT( s.find("one") == 0 ); - CPPUNIT_ASSERT( s.find('t') == 4 ); - CPPUNIT_ASSERT( s.find('t', 5) == 8 ); - //We are trying to get a const reference to the npos string static member to - //force the compiler to allocate memory for this variable. It is used to reveal - //a bug of STLport which was simply declaring npos without instanciating it. -#if defined (STLPORT) && defined (_STLP_STATIC_CONST_INIT_BUG) - string::size_type const& npos_local = string::npos; -#else -# define npos_local string::npos -#endif - CPPUNIT_ASSERT( s.find("four") == npos_local ); - CPPUNIT_ASSERT( s.find("one", string::npos) == npos_local ); - - CPPUNIT_ASSERT( s.find_first_of("abcde") == 2 ); - - CPPUNIT_ASSERT( s.find_first_not_of("enotw ") == 9 ); - - string empty; - CPPUNIT_ASSERT( s.substr(s.find(empty), empty.size()) == empty ); -} - -void StringTest::bogus_edge_find() -{ - /* ISO/IEC 14882 2003, 21.3.6.1 basic_string::find [lib.string::find] - * - * size_type find(const basic_string<charT,traits,Allocator>& str, - * size_type pos = 0) const; - * Effects: Determines the lowest position xpos, if possible, such that - * both of the following conditions obtain: - * pos <= xpos and xpos + str.size() <= size(); - * at(xpos+I) == str.at(I) for all elements I of the string controlled by str. - * Returns: xpos if the function can determine such a value for xpos. Otherwise, - * returns npos. - * Notes: Uses traits::eq(). - * - * === - * So, from formal point of view - * string s; string::size_type p = s.find( "", 0, 0 ); - * should return 0 in p, i.e. position out-of-bound of string, so - * code like following is bad: - * string s; - * - * string::size_type p = s.find( "", 0, 0 ); - * - * ... - * - * if ( p != string::npos ) { // normal - * char ch = s[p]; // Arghhhhhhhhhh - * } - * - * People near Standard commete has opinion opposite to my. Even if it looks - * like bogus behaviour for me, it should be fixed. - */ - - { - string s; - string::size_type p = s.find( "", 0, 0 ); - - /* CPPUNIT_CHECK( p == string::npos ); */ - CPPUNIT_CHECK( p == 0 ); // bogus result, isn't it? - } - { - string s( "123" ); - string::size_type p = s.find( "", 0, 0 ); - - CPPUNIT_CHECK( p == 0 ); - } - { - string s( "123" ); - string::size_type p = s.find( "", 1, 0 ); - - CPPUNIT_CHECK( p == 1 ); - } - { - string s( "" ); - string::size_type p = s.find( "", 1, 0 ); - - CPPUNIT_CHECK( p == string::npos ); - } - { - string s( "123" ); - string::size_type p = s.find( "", 3, 0 ); - - CPPUNIT_CHECK( p == 3 ); // bogus result, isn't it? - } - { - string s; - string::size_type p = s.rfind( "", 0, 0 ); - - /* CPPUNIT_CHECK( p == string::npos ); */ - CPPUNIT_CHECK( p == 0 ); // bogus result, isn't it? - } - { - string s( "123" ); - string::size_type p = s.rfind( "", 0, 0 ); - - CPPUNIT_CHECK( p == 0 ); - } - { - string s( "123" ); - string::size_type p = s.rfind( "", 1, 0 ); - - CPPUNIT_CHECK( p == 1 ); - } - { - string s( "" ); - string::size_type p = s.rfind( "", 1, 0 ); - - CPPUNIT_CHECK( p == 0 ); // bogus result, isn't it? - } - { - string s( "123" ); - string::size_type p = s.rfind( "", 3, 0 ); - - CPPUNIT_CHECK( p == 3 ); // bogus result, isn't it? - } -} - -void StringTest::rfind() -{ - // 21.3.6.2 - string s("one two three one two three"); - - CPPUNIT_ASSERT( s.rfind("two") == 18 ); - CPPUNIT_ASSERT( s.rfind("two", 0) == string::npos ); - CPPUNIT_ASSERT( s.rfind("two", 11) == 4 ); - CPPUNIT_ASSERT( s.rfind('w') == 19 ); - - string test( "aba" ); - - CPPUNIT_CHECK( test.rfind( "a", 2, 1 ) == 2 ); - CPPUNIT_CHECK( test.rfind( "a", 1, 1 ) == 0 ); - CPPUNIT_CHECK( test.rfind( "a", 0, 1 ) == 0 ); - - CPPUNIT_CHECK( test.rfind( 'a', 2 ) == 2 ); - CPPUNIT_CHECK( test.rfind( 'a', 1 ) == 0 ); - CPPUNIT_CHECK( test.rfind( 'a', 0 ) == 0 ); -} - -void StringTest::find_last_of() -{ - // 21.3.6.4 - string s("one two three one two three"); - - CPPUNIT_ASSERT( s.find_last_of("abcde") == 26 ); - - string test( "aba" ); - - CPPUNIT_CHECK( test.find_last_of( "a", 2, 1 ) == 2 ); - CPPUNIT_CHECK( test.find_last_of( "a", 1, 1 ) == 0 ); - CPPUNIT_CHECK( test.find_last_of( "a", 0, 1 ) == 0 ); - - CPPUNIT_CHECK( test.find_last_of( 'a', 2 ) == 2 ); - CPPUNIT_CHECK( test.find_last_of( 'a', 1 ) == 0 ); - CPPUNIT_CHECK( test.find_last_of( 'a', 0 ) == 0 ); -} - -void StringTest::find_last_not_of() -{ - // 21.3.6.6 - string s("one two three one two three"); - - CPPUNIT_ASSERT( s.find_last_not_of("ehortw ") == 15 ); - - string test( "aba" ); - - CPPUNIT_CHECK( test.find_last_not_of( "a", 2, 1 ) == 1 ); - CPPUNIT_CHECK( test.find_last_not_of( "b", 2, 1 ) == 2 ); - CPPUNIT_CHECK( test.find_last_not_of( "a", 1, 1 ) == 1 ); - CPPUNIT_CHECK( test.find_last_not_of( "b", 1, 1 ) == 0 ); - CPPUNIT_CHECK( test.find_last_not_of( "a", 0, 1 ) == string::npos ); - CPPUNIT_CHECK( test.find_last_not_of( "b", 0, 1 ) == 0 ); - - CPPUNIT_CHECK( test.find_last_not_of( 'a', 2 ) == 1 ); - CPPUNIT_CHECK( test.find_last_not_of( 'b', 2 ) == 2 ); - CPPUNIT_CHECK( test.find_last_not_of( 'a', 1 ) == 1 ); - CPPUNIT_CHECK( test.find_last_not_of( 'b', 1 ) == 0 ); - CPPUNIT_CHECK( test.find_last_not_of( 'a', 0 ) == string::npos ); - CPPUNIT_CHECK( test.find_last_not_of( 'b', 0 ) == 0 ); -} - -void StringTest::copy() -{ - string s("foo"); - char dest[4]; - dest[0] = dest[1] = dest[2] = dest[3] = 1; - s.copy(dest, 4); - int pos = 0; - CPPUNIT_ASSERT( dest[pos++] == 'f' ); - CPPUNIT_ASSERT( dest[pos++] == 'o' ); - CPPUNIT_ASSERT( dest[pos++] == 'o' ); - CPPUNIT_ASSERT( dest[pos++] == 1 ); - - dest[0] = dest[1] = dest[2] = dest[3] = 1; - s.copy(dest, 4, 2); - pos = 0; - CPPUNIT_ASSERT( dest[pos++] == 'o' ); - CPPUNIT_ASSERT( dest[pos++] == 1 ); - -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { - s.copy(dest, 4, 5); - CPPUNIT_FAIL; - } - catch (out_of_range const&) { - } - catch ( ... ) { - CPPUNIT_FAIL; - } -#endif -} - -void StringTest::assign() -{ - string s; - char const* cstr = "test string for assign"; - - s.assign(cstr, cstr + 22); - CPPUNIT_ASSERT( s == "test string for assign" ); - - string s2("other test string"); - s.assign(s2); - CPPUNIT_ASSERT( s == s2 ); - - static string str1; - static string str2; - - // short string optim: - str1 = "123456"; - // longer than short string: - str2 = "1234567890123456789012345678901234567890"; - - CPPUNIT_ASSERT(str1[5] == '6'); - CPPUNIT_ASSERT(str2[29] == '0'); -} - -/* This test is to check if string properly supports the short string - * optimization. It has been found out that eMbedded Visual C++ 3.0 and .NET - * compilers for the ARM platform fail to pass structs and classes of certain - * size per value. This seems to be a known compiler bug. For other processors - * (e.g. x86) the error doesn't occur. - * (The ARM compiler creates a temporary object from teststr on the stack, to - * pass it to the helper function. It uses the copy constructor for this. - * After this the temporary object is copied to another place on the stack. - * The result is that the _M_finish pointer then points to the wrong buffer - * end and the size of the short string is incorrectly calculated.) - */ -void StringTest::short_string_optim_bug() -{ - string teststr("shortest"); - - bool short_string_optim_bug_helper(string teststr); - - CPPUNIT_ASSERT(true == short_string_optim_bug_helper(teststr)); -} - -bool short_string_optim_bug_helper(string teststr) -{ - size_t ss = teststr.size(); - return (ss == 8); -} - -void StringTest::compare() -{ - string str1("abcdef"); - string str2; - - str2 = "abcdef"; - CPPUNIT_ASSERT( str1.compare(str2) == 0 ); - str2 = "abcde"; - CPPUNIT_ASSERT( str1.compare(str2) > 0 ); - str2 = "abcdefg"; - CPPUNIT_ASSERT( str1.compare(str2) < 0 ); - - CPPUNIT_ASSERT( str1.compare("abcdef") == 0 ); - CPPUNIT_ASSERT( str1.compare("abcde") > 0 ); - CPPUNIT_ASSERT( str1.compare("abcdefg") < 0 ); - - str2 = "cde"; - CPPUNIT_ASSERT( str1.compare(2, 3, str2) == 0 ); - str2 = "cd"; - CPPUNIT_ASSERT( str1.compare(2, 3, str2) > 0 ); - str2 = "cdef"; - CPPUNIT_ASSERT( str1.compare(2, 3, str2) < 0 ); - - str2 = "abcdef"; - CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 3) == 0 ); - CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 2) > 0 ); - CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 4) < 0 ); - - CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 3) == 0 ); - CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 2) > 0 ); - CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 4) < 0 ); -} - -/* -class mystring : public string { -public: - mystring() {} - mystring(string const& s) : string(s) {} - - mystring& operator = (string const& s) { - string::operator = (s); - return *this; - }; -}; -*/ - -void StringTest::template_expression() -{ - string one("one"), two("two"), three("three"); - string space(1, ' '); - - // check availability of [un]equality operators - { - // string-string - one == two; - one != two; - // string-literal - one == "two"; - one != "two"; - // literal-string - "one" == two; - "one" != two; - // strsum-string - (one + two) == three; - (one + two) != three; - // string-strsum - one == (two + three); - one != (two + three); - // strsum-literal - (one + two) == "three"; - (one + two) != "three"; - // literal-strsum - "one" == (two + three); - "one" != (two + three); - // strsum-strsum - (one + two) == (two + three); - (one + two) != (two + three); - } - - { - string result(one + ' ' + two + ' ' + three); - CPPUNIT_CHECK( result == "one two three" ); - } - - { - string result(one + ' ' + two + ' ' + three, 4); - CPPUNIT_CHECK( result == "two three" ); - } - - { - string result(one + ' ' + two + ' ' + three, 4, 3); - CPPUNIT_CHECK( result == "two" ); - } - - //2 members expressions: - CPPUNIT_CHECK( (' ' + one) == " one" ); - CPPUNIT_CHECK( (one + ' ') == "one " ); - CPPUNIT_CHECK( (one + " two") == "one two" ); - CPPUNIT_CHECK( ("one " + two) == "one two" ); - CPPUNIT_CHECK( (one + space) == "one " ); - - //3 members expressions: - CPPUNIT_CHECK( ((one + space) + "two") == "one two" ); - CPPUNIT_CHECK( ("one" + (space + two)) == "one two" ); - CPPUNIT_CHECK( ((one + space) + two) == "one two" ); - CPPUNIT_CHECK( (one + (space + two)) == "one two" ); - CPPUNIT_CHECK( ((one + space) + 't') == "one t" ); - CPPUNIT_CHECK( ('o' + (space + two)) == "o two" ); - - //4 members expressions: - CPPUNIT_CHECK( ((one + space) + (two + space)) == "one two " ); - - //special operators - { - string result; - result = one + space + two; - CPPUNIT_CHECK( result == "one two" ); - - result += space + three; - CPPUNIT_CHECK( result == "one two three" ); - } - - //special append method - { - string result; - //Use reserve to avoid reallocation and really test auto-referencing problems: - result.reserve(64); - - result.append(one + space + two); - CPPUNIT_CHECK( result == "one two" ); - - result.append(space + result + space + three); - CPPUNIT_CHECK( result == "one two one two three" ); - - result = "one two"; - result.append(space + three, 1, 2); - CPPUNIT_ASSERT( result == "one twoth" ); - - result.append(space + result); - CPPUNIT_CHECK( result == "one twoth one twoth" ); - } - - //special assign method - { - string result; - //Use reserve to avoid reallocation and really test auto-referencing problems: - result.reserve(64); - - result.assign(one + space + two + space + three); - CPPUNIT_CHECK( result == "one two three" ); - - result.assign(one + space + two + space + three, 3, 5); - CPPUNIT_CHECK( result == " two " ); - - result.assign(one + result + three); - CPPUNIT_CHECK( result == "one two three" ); - } - - { - CPPUNIT_CHECK( !(one + ' ' + two).empty() ); - - char result = (one + ' ' + two)[3]; - CPPUNIT_CHECK( result == ' ' ); - - result = (one + ' ' + two).at(3); - CPPUNIT_CHECK( result == ' ' ); - -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { - result = (one + ' ' + two).at(10); - CPPUNIT_FAIL; - } - catch (out_of_range const&) { - CPPUNIT_ASSERT( result == ' ' ); - } - catch (...) { - CPPUNIT_FAIL; - } -#endif - } - - /* - mystring a("ing"); - //gcc failed to compile following expression when template expressions are activated. - //MSVC sees no problem. gcc limitation or MSVC is too cool ?? - mystring b = "str" + a; - */ -} - -#if !defined (TE_TMP_TEST_IGNORED) -class superstring -{ - public: - superstring() : - s("super") - {} - - superstring( const string& str ) : - s( str ) - {} - - superstring operator / (const string& str ) - { return superstring( s + "/" + str ); } - - superstring operator / (const char* str ) - { return superstring( s + "/" + str ); } - - private: - string s; -}; -#endif - -void StringTest::te_tmp() -{ -#if !defined (TE_TMP_TEST_IGNORED) - superstring s; - string more( "more" ); - string less( "less" ); - - superstring r = s / (more + less); -#endif -} - -class mypath -{ - public: - mypath( const string& s ) : - p( s ) - { } - - const mypath& operator / ( const string& ); - const string& str() const - { return p; } - - private: - string p; -}; - -const mypath& mypath::operator /( const string& s ) -{ - p += '/'; - p += s; - return *this; -} - -void StringTest::oper_tmp() -{ - string s1( "path1" ); - string s2( ".ext" ); - - string& rs1 = s1; - string& rs2 = s2; - - CPPUNIT_CHECK( (mypath( string( "/root" ) ) / (rs1 + rs2)).str() == "/root/path1.ext" ); -} - -void StringTest::template_wexpression() -{ -#if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) -# if !defined (__CYGWIN__) || defined (STLPORT) - wstring one(L"one"), two(L"two"), three(L"three"); - wstring space(L" "); - - { - wstring result(one + L' ' + two + L' ' + three); - CPPUNIT_CHECK( result == L"one two three" ); - } - - { - wstring result(one + L' ' + two + L' ' + three, 4); - CPPUNIT_CHECK( result == L"two three" ); - } - - { - wstring result(one + L' ' + two + L' ' + three, 4, 3); - CPPUNIT_CHECK( result == L"two" ); - } - - //2 members expressions: - CPPUNIT_CHECK( (L' ' + one) == L" one" ); - CPPUNIT_CHECK( (one + L' ') == L"one " ); - CPPUNIT_CHECK( (one + L" two") == L"one two" ); - CPPUNIT_CHECK( (L"one " + two) == L"one two" ); - CPPUNIT_CHECK( (one + space) == L"one " ); - - //3 members expressions: - CPPUNIT_CHECK( ((one + space) + L"two") == L"one two" ); - CPPUNIT_CHECK( (L"one" + (space + two)) == L"one two" ); - CPPUNIT_CHECK( ((one + space) + two) == L"one two" ); - CPPUNIT_CHECK( (one + (space + two)) == L"one two" ); - CPPUNIT_CHECK( ((one + space) + L't') == L"one t" ); - CPPUNIT_CHECK( (L'o' + (space + two)) == L"o two" ); - - //4 members expressions: - CPPUNIT_CHECK( ((one + space) + (two + space)) == L"one two " ); - - //special operators - { - wstring result; - result = one + space + two; - CPPUNIT_CHECK( result == L"one two" ); - - result += space + three; - CPPUNIT_CHECK( result == L"one two three" ); - } - - //special append method - { - wstring result; - //Use reserve to avoid reallocation and really test auto-referencing problems: - result.reserve(64); - - result.append(one + space + two); - CPPUNIT_CHECK( result == L"one two" ); - - result.append(space + result + space + three); - CPPUNIT_CHECK( result == L"one two one two three" ); - - result = L"one two"; - result.append(space + three, 1, 2); - CPPUNIT_ASSERT( result == L"one twoth" ); - - result.append(space + result); - CPPUNIT_CHECK( result == L"one twoth one twoth" ); - } - - //special assign method - { - wstring result; - //Use reserve to avoid reallocation and really test auto-referencing problems: - result.reserve(64); - - result.assign(one + space + two + space + three); - CPPUNIT_CHECK( result == L"one two three" ); - - result.assign(one + space + two + space + three, 3, 5); - CPPUNIT_CHECK( result == L" two " ); - - result.assign(one + result + three); - CPPUNIT_CHECK( result == L"one two three" ); - } - - { - CPPUNIT_CHECK( !(one + L' ' + two).empty() ); - - wchar_t result = (one + L' ' + two)[3]; - CPPUNIT_CHECK( result == L' ' ); - - result = (one + L' ' + two).at(3); - CPPUNIT_CHECK( result == L' ' ); - -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { - result = (one + L' ' + two).at(10); - CPPUNIT_FAIL; - } - catch (out_of_range const&) { - CPPUNIT_ASSERT( result == L' ' ); - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - } -# endif -#endif -} - -void StringTest::io() -{ -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) - string str("STLport"); - { - ostringstream ostr; - ostr << str; - CPPUNIT_ASSERT( ostr.good() ); - CPPUNIT_ASSERT( ostr.str() == str ); - } - { - istringstream istr(str); - string istr_content; - istr >> istr_content; - CPPUNIT_ASSERT( !istr.fail() && istr.eof() ); - CPPUNIT_ASSERT( istr_content == str ); - } - { - istringstream istr(str); - istr.width(3); - string istr_content; - istr >> istr_content; - CPPUNIT_ASSERT( !istr.fail() && !istr.eof() ); - CPPUNIT_ASSERT( istr_content == "STL" ); - } -#endif -} - -void StringTest::allocator_with_state() -{ -#if !(defined (STLPORT) && defined (_STLP_NO_CUSTOM_IO)) - - char buf1[1024]; - StackAllocator<char> stack1(buf1, buf1 + sizeof(buf1)); - - char buf2[1024]; - StackAllocator<char> stack2(buf2, buf2 + sizeof(buf2)); - - typedef basic_string<char, char_traits<char>, StackAllocator<char> > StackString; - { - StackString str1("string stack1", stack1); - StackString str1Cpy(str1); - - StackString str2("string stack2", stack2); - StackString str2Cpy(str2); - - str1.swap(str2); - - CPPUNIT_ASSERT( str1.get_allocator().swaped() ); - CPPUNIT_ASSERT( str2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( str1 == str2Cpy ); - CPPUNIT_ASSERT( str2 == str1Cpy ); - CPPUNIT_ASSERT( str1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( str2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); - stack1.reset(); stack2.reset(); - - { - StackString str1("longer string from stack1 allocator instance for dynamic allocation", stack1); - StackString str1Cpy(str1); - - StackString str2("longer string from stack2 allocator instance for dynamic allocation", stack2); - StackString str2Cpy(str2); - - str1.swap(str2); - - CPPUNIT_ASSERT( str1.get_allocator().swaped() ); - CPPUNIT_ASSERT( str2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( str1 == str2Cpy ); - CPPUNIT_ASSERT( str2 == str1Cpy ); - CPPUNIT_ASSERT( str1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( str2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); - stack1.reset(); stack2.reset(); - - - { - StackString str1("string stack1", stack1); - StackString str1Cpy(str1); - - StackString str2("longer string from stack2 allocator instance for dynamic allocation", stack2); - StackString str2Cpy(str2); - - str1.swap(str2); - - CPPUNIT_ASSERT( str1.get_allocator().swaped() ); - CPPUNIT_ASSERT( str2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( str1 == str2Cpy ); - CPPUNIT_ASSERT( str2 == str1Cpy ); - CPPUNIT_ASSERT( str1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( str2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); - stack1.reset(); stack2.reset(); - - - { - StackString str1("longer string from stack1 allocator instance for dynamic allocation", stack1); - StackString str1Cpy(str1); - - StackString str2("string stack2", stack2); - StackString str2Cpy(str2); - - str1.swap(str2); - - CPPUNIT_ASSERT( str1.get_allocator().swaped() ); - CPPUNIT_ASSERT( str2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( str1 == str2Cpy ); - CPPUNIT_ASSERT( str2 == str1Cpy ); - CPPUNIT_ASSERT( str1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( str2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); - stack1.reset(); stack2.reset(); -#endif -} - -void StringTest::capacity() -{ - string s; - - CPPUNIT_CHECK( s.capacity() > 0 ); - CPPUNIT_CHECK( s.capacity() < s.max_size() ); - CPPUNIT_CHECK( s.capacity() >= s.size() ); - -#ifndef _STLP_SHORT_STRING_SZ -# define _STLP_SHORT_STRING_SZ 16 // see stlport/stl/_string_base.h -#endif - - for ( int i = 0; i < _STLP_SHORT_STRING_SZ + 2; ++i ) { - s += ' '; - CPPUNIT_CHECK( s.capacity() > 0 ); - CPPUNIT_CHECK( s.capacity() < s.max_size() ); - CPPUNIT_CHECK( s.capacity() >= s.size() ); - } -} - -void StringTest::concat24() -{ - string s = string( "123456789012345678901234" ) + string( "123456789012345678901234" ); - - CPPUNIT_CHECK( s.length() == 48 ); - CPPUNIT_CHECK( s[23] == '4' ); - CPPUNIT_CHECK( s[24] == '1' ); - CPPUNIT_CHECK( s[47] == '4' ); -} diff --git a/test/unit/strstream_buffer_read_test.cpp b/test/unit/strstream_buffer_read_test.cpp deleted file mode 100644 index 978ac0c..0000000 --- a/test/unit/strstream_buffer_read_test.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Note: Strstreams are really broken in STLport. But strstreams are - * obsolete, and even if ones was mentioned in D7.1--D7.4 of - * Standard, we have no wish to spent time with repair ones. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <strstream> - -# include "cppunit/cppunit_proxy.h" - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -class StrstreamBufferTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(StrstreamBufferTest); - CPPUNIT_TEST(read_from_buffer); - CPPUNIT_TEST_SUITE_END(); - -protected: - void read_from_buffer(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(StrstreamBufferTest); - -void StrstreamBufferTest::read_from_buffer() -{ - char hello[] = "Hello"; - strstream stream(hello, sizeof(hello), ios_base::in); - char cur; - stream >> cur; - CPPUNIT_ASSERT(cur == 'H'); -} -#endif diff --git a/test/unit/strstream_header_test.cpp b/test/unit/strstream_header_test.cpp deleted file mode 100644 index 3d7504a..0000000 --- a/test/unit/strstream_header_test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#if !defined (_STLP_NO_IOSTREAMS) -# include <strstream> -#endif diff --git a/test/unit/strstream_test.cpp b/test/unit/strstream_test.cpp deleted file mode 100644 index 195570c..0000000 --- a/test/unit/strstream_test.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include <string> - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <strstream> -# include <limits> - -# include "cppunit/cppunit_proxy.h" - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -// -// TestCase class -// -class StrstreamTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(StrstreamTest); - CPPUNIT_TEST(input); - CPPUNIT_TEST_SUITE_END(); - -private: - void input(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(StrstreamTest); - -// -// tests implementation -// -void StrstreamTest::input() -{ -# if defined (STLPORT) && defined (_STLP_LONG_LONG) - { - istrstream is("652208307"); - _STLP_LONG_LONG rval = 0; - is >> rval; - CPPUNIT_ASSERT( rval == 652208307 ); - } - { - istrstream is("-652208307"); - _STLP_LONG_LONG rval = 0; - is >> rval; - CPPUNIT_ASSERT( rval == -652208307 ); - } -} -# endif - -#endif diff --git a/test/unit/swap_test.cpp b/test/unit/swap_test.cpp deleted file mode 100644 index 056cabf..0000000 --- a/test/unit/swap_test.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include <vector> -#include <algorithm> -#include <vector> -#include <queue> - -#if 0 /* temporary: investigation of problem with swap */ -#include <iostream> -#include <typeinfo> -#endif - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class SwapTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(SwapTest); - CPPUNIT_TEST(swap1); - CPPUNIT_TEST(swprnge1); - CPPUNIT_TEST(swap_container_non_spec); -#if defined (STLPORT) && \ - !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) && !defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(swap_container_spec); - CPPUNIT_TEST_SUITE_END(); - -protected: - void swap1(); - void swprnge1(); - void swap_container_non_spec(); - void swap_container_spec(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SwapTest); - -// -// tests implementation -// -void SwapTest::swap1() -{ - int a = 42; - int b = 19; - swap(a, b); - - CPPUNIT_ASSERT(a==19); - CPPUNIT_ASSERT(b==42); -} - -void SwapTest::swprnge1() -{ - char word1[] = "World"; - char word2[] = "Hello"; - swap_ranges((char*)word1, (char*)word1 + ::strlen(word1), (char*)word2); - CPPUNIT_ASSERT(!strcmp(word1, "Hello")); - CPPUNIT_ASSERT(!strcmp(word2, "World")); -} - -class Obj -{ - public: - Obj() : - v( 0 ) - { } - Obj( const Obj& ) : - v( 1 ) - { } - - Obj& operator =( const Obj& ) - { v = 2; return *this; } - - int v; -}; - -/* - * Following two tests check the corectness of specialization of swap(): - * for containers with container::swap method swap( a, b ) should - * use a.swap( b ), but don't try to do this substitution for container - * without swap method (in this case swap should be made via explicit members - * exchange; this assume usage of temporary object) - * - */ -void SwapTest::swap_container_non_spec() -{ - queue<Obj> v1; - queue<Obj> v2; - - v1.push( Obj() ); - v1.back().v = -1; - v1.push( Obj() ); - v1.back().v = -2; - - v2.push( Obj() ); - v2.back().v = 10; - v2.push( Obj() ); - v2.back().v = 11; - v2.push( Obj() ); - v2.back().v = 12; - - CPPUNIT_CHECK( v1.size() == 2 ); - CPPUNIT_CHECK( v2.size() == 3 ); - - swap( v1, v2 ); // this shouldn't try make it as v1.swap( v2 ), no queue::swap method! - - CPPUNIT_CHECK( v1.size() == 3 ); - CPPUNIT_CHECK( v2.size() == 2 ); - - // either copy constructor or assignment operator - CPPUNIT_CHECK( v1.front().v == 1 || v1.front().v == 2 ); - CPPUNIT_CHECK( v1.back().v == 1 || v1.back().v == 2 ); - CPPUNIT_CHECK( v2.front().v == 1 || v2.front().v == 2 ); - CPPUNIT_CHECK( v2.back().v == 1 || v2.back().v == 2 ); -} - -void SwapTest::swap_container_spec() -{ -#if 0 /* temporary: investigation of problem with swap */ - if ( typeid(/* _STLP_PRIV */ _SwapImplemented<vector<Obj> >::_Ret) == typeid(_STLP_PRIV __false_type) ) { - cerr << "false type" << endl; - } else if ( typeid(/* _STLP_PRIV */ _SwapImplemented<vector<Obj> >::_Ret) == typeid(_STLP_PRIV __true_type) ) { - cerr << "true type" << endl; - } else { - cerr << "unknown type" << endl; - } -#endif /* end of temporary */ -#if !defined (STLPORT) || \ - defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) - vector<Obj> v1; - vector<Obj> v2; - - v1.push_back( Obj() ); - v1.push_back( Obj() ); - - v1[0].v = -1; - v1[1].v = -2; - - v2.push_back( Obj() ); - v2.push_back( Obj() ); - v2.push_back( Obj() ); - - v2[0].v = 10; - v2[1].v = 11; - v2[2].v = 12; - - CPPUNIT_CHECK( v1.size() == 2 ); - CPPUNIT_CHECK( v2.size() == 3 ); - - swap( v1, v2 ); // this should has effect v1.swap( v2 ) - - CPPUNIT_CHECK( v1.size() == 3 ); - CPPUNIT_CHECK( v2.size() == 2 ); - - CPPUNIT_CHECK( v1[0].v == 10 ); - CPPUNIT_CHECK( v1[1].v == 11 ); - CPPUNIT_CHECK( v1[2].v == 12 ); - - CPPUNIT_CHECK( v2[0].v == -1 ); - CPPUNIT_CHECK( v2[1].v == -2 ); -#endif -} diff --git a/test/unit/test_errno.cpp b/test/unit/test_errno.cpp deleted file mode 100644 index ad77d3a..0000000 --- a/test/unit/test_errno.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//We are including stdlib.h and stddef.h first because under MSVC -//those headers contains a errno macro definition without the underlying value -//definition. -#include <stdlib.h> -#include <stddef.h> - -#include <errno.h> -#include <errno.h> // not typo, check errno def/undef/redef - -#ifndef _STLP_WCE - -#include "cppunit/cppunit_proxy.h" - -// -// TestCase class -// -class ErrnoTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ErrnoTest); - CPPUNIT_TEST(check); - CPPUNIT_TEST_SUITE_END(); - -protected: - void check(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ErrnoTest); - -void ErrnoTest::check() -{ - //We are using ERANGE as it is part of the C++ ISO (see Table 26 in section 19.3) - //Using ERANGE improve the test as it means that the native errno.h file has really - //been included. - errno = ERANGE; - - CPPUNIT_ASSERT( errno == ERANGE ); - errno = 0; - -/* Note: in common, you can't write ::errno or std::errno, - * due to errno in most cases is just a macro, that frequently - * (in MT environment errno is a per-thread value) expand to something like - * (*__errno_location()). I don't know way how masquerade such - * things: name of macro can't include ::. - * - * - ptr, 2005-03-30 - */ -# if 0 - if ( ::errno != 0 ) { - return 1; - } - if ( std::errno != 0 ) { - return 1; - } -# endif -} -#endif // _STLP_WCE diff --git a/test/unit/time_facets_test.cpp b/test/unit/time_facets_test.cpp deleted file mode 100644 index 19a7a3a..0000000 --- a/test/unit/time_facets_test.cpp +++ /dev/null @@ -1,402 +0,0 @@ -#include "locale_test.h" - -#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) -# include <locale> -# include <sstream> -# include <memory> -# include <stdexcept> - -# if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# endif - -static const char* tested_locales[] = { -// name, -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - "fr_FR", - "ru_RU.koi8r", - "en_GB", - "en_US", -# endif - "", - "C" -}; - -void LocaleTest::_time_put_get( const locale& loc ) -{ - { - typedef time_put<char, ostreambuf_iterator<char, char_traits<char> > > time_put_facet; - CPPUNIT_ASSERT( has_facet<time_put_facet>(loc) ); - const time_put_facet& tmp = use_facet<time_put_facet>(loc); - - struct tm xmas = { 0, 0, 12, 25, 11, 93 }; - ostringstream ostr; - ostr.imbue(loc); - string format = "%B %d %Y"; - - time_put_facet::iter_type ret = tmp.put(ostr, ostr, ' ', &xmas, format.data(), format.data() + format.size()); - CPPUNIT_ASSERT( !ret.failed() ); - - /* - * In other words, user conformation is required for reliable parsing - * of user-entered dates and times, but machine-generated formats can be - * parsed reliably. This allows parsers to be aggressive about interpreting - * user variations on standard format. - * - * ISO/IEC 14882, 22.2.5.1 - */ - typedef time_get<char, istreambuf_iterator<char, char_traits<char> > > time_get_facet; - CPPUNIT_ASSERT( has_facet<time_get_facet>(loc) ); - const time_get_facet& tmg = use_facet<time_get_facet>(loc); - basic_ios<char> io(0); - io.imbue(loc); - - istringstream istr( ostr.str() ); - istreambuf_iterator<char, char_traits<char> > i( istr ); - istreambuf_iterator<char, char_traits<char> > e; - ios_base::iostate err = ios_base::goodbit; - struct tm other = { 15, 20, 9, 14, 7, 105 }; - - i = tmg.get_monthname( i, e, io, err, &other ); - CPPUNIT_ASSERT( err == ios_base::goodbit ); - CPPUNIT_ASSERT( other.tm_mon == xmas.tm_mon ); - - ++i; ++i; ++i; ++i; // skip day of month and spaces around it - i = tmg.get_year( i, e, io, err, &other ); - - CPPUNIT_ASSERT( err == ios_base::eofbit ); - CPPUNIT_ASSERT( other.tm_year == xmas.tm_year ); - - ostringstream ostrX; - ostrX.imbue(loc); - format = "%x %X"; - - ret = tmp.put(ostrX, ostrX, ' ', &xmas, format.data(), format.data() + format.size()); - CPPUNIT_ASSERT( !ret.failed() ); - - istringstream istrX( ostrX.str() ); - istreambuf_iterator<char, char_traits<char> > j( istrX ); - - err = ios_base::goodbit; - - struct tm yet_more = { 15, 20, 9, 14, 7, 105 }; - - j = tmg.get_date( j, e, io, err, &yet_more ); - - CPPUNIT_ASSERT( err == ios_base::goodbit ); - - CPPUNIT_ASSERT( yet_more.tm_sec != xmas.tm_sec ); - CPPUNIT_ASSERT( yet_more.tm_min != xmas.tm_min ); - CPPUNIT_ASSERT( yet_more.tm_hour != xmas.tm_hour ); - CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday ); - CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon ); - CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year ); - - ++j; // skip space - - j = tmg.get_time( j, e, io, err, &yet_more ); - - CPPUNIT_ASSERT( err == ios_base::eofbit || err == ios_base::goodbit ); - - CPPUNIT_ASSERT( yet_more.tm_sec == xmas.tm_sec ); - CPPUNIT_ASSERT( yet_more.tm_min == xmas.tm_min ); - CPPUNIT_ASSERT( yet_more.tm_hour == xmas.tm_hour ); - CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday ); - CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon ); - CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year ); - } -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) - { - typedef time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > time_put_facet; - CPPUNIT_ASSERT( has_facet<time_put_facet>(loc) ); - const time_put_facet& tmp = use_facet<time_put_facet>(loc); - - struct tm xmas = { 0, 0, 12, 25, 11, 93 }; - wostringstream ostr; - ostr.imbue(loc); - wstring format = L"%B %d %Y"; - - time_put_facet::iter_type ret = tmp.put(ostr, ostr, ' ', &xmas, format.data(), format.data() + format.size()); - CPPUNIT_ASSERT( !ret.failed() ); - - /* - * In other words, user conformation is required for reliable parsing - * of user-entered dates and times, but machine-generated formats can be - * parsed reliably. This allows parsers to be aggressive about interpreting - * user variations on standard format. - * - * ISO/IEC 14882, 22.2.5.1 - */ - typedef time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > time_get_facet; - CPPUNIT_ASSERT( has_facet<time_get_facet>(loc) ); - const time_get_facet& tmg = use_facet<time_get_facet>(loc); - // Intentional instantiation with char to show a bug in a previous STLport version. - basic_ios<char> io(0); - io.imbue(loc); - - wistringstream istr( ostr.str() ); - istreambuf_iterator<wchar_t, char_traits<wchar_t> > i( istr ); - istreambuf_iterator<wchar_t, char_traits<wchar_t> > e; - ios_base::iostate err = ios_base::goodbit; - struct tm other = { 15, 20, 9, 14, 7, 105 }; - - i = tmg.get_monthname( i, e, io, err, &other ); - CPPUNIT_ASSERT( err == ios_base::goodbit ); - CPPUNIT_ASSERT( other.tm_mon == xmas.tm_mon ); - - ++i; ++i; ++i; ++i; // skip day of month and spaces around it - i = tmg.get_year( i, e, io, err, &other ); - - CPPUNIT_ASSERT( err == ios_base::eofbit ); - CPPUNIT_ASSERT( other.tm_year == xmas.tm_year ); - - wostringstream ostrX; - ostrX.imbue(loc); - format = L"%x %X"; - - ret = tmp.put(ostrX, ostrX, ' ', &xmas, format.data(), format.data() + format.size()); - CPPUNIT_ASSERT( !ret.failed() ); - - wistringstream istrX( ostrX.str() ); - istreambuf_iterator<wchar_t, char_traits<wchar_t> > j( istrX ); - - err = ios_base::goodbit; - - struct tm yet_more = { 15, 20, 9, 14, 7, 105 }; - - j = tmg.get_date( j, e, io, err, &yet_more ); - - CPPUNIT_ASSERT( err == ios_base::goodbit ); - - CPPUNIT_ASSERT( yet_more.tm_sec != xmas.tm_sec ); - CPPUNIT_ASSERT( yet_more.tm_min != xmas.tm_min ); - CPPUNIT_ASSERT( yet_more.tm_hour != xmas.tm_hour ); - CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday ); - CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon ); - CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year ); - - ++j; // skip space - - j = tmg.get_time( j, e, io, err, &yet_more ); - - CPPUNIT_ASSERT( err == ios_base::eofbit || err == ios_base::goodbit ); - - CPPUNIT_ASSERT( yet_more.tm_sec == xmas.tm_sec ); - CPPUNIT_ASSERT( yet_more.tm_min == xmas.tm_min ); - CPPUNIT_ASSERT( yet_more.tm_hour == xmas.tm_hour ); - CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday ); - CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon ); - CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year ); - } -# endif -} - -typedef void (LocaleTest::*_Test) (const locale&); -static void test_supported_locale(LocaleTest& inst, _Test __test) { - size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]); - for (size_t i = 0; i < n; ++i) { - locale loc; -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try -# endif - { - locale tmp(tested_locales[i]); - loc = tmp; - } -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - catch (runtime_error const&) { - //This locale is not supported. - continue; - } -# endif - CPPUNIT_MESSAGE( loc.name().c_str() ); - (inst.*__test)(loc); - - { - locale tmp(locale::classic(), tested_locales[i], locale::time); - loc = tmp; - } - (inst.*__test)(loc); - - { - typedef time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > > time_put_facet; - locale tmp0(locale::classic(), new time_put_facet(tested_locales[i])); - typedef time_get_byname<char, istreambuf_iterator<char, char_traits<char> > > time_get_facet; - locale tmp1(tmp0, new time_get_facet(tested_locales[i])); - loc = tmp1; - } - (inst.*__test)(loc); - } -} - -void LocaleTest::time_put_get() -{ test_supported_locale(*this, &LocaleTest::_time_put_get); } - -void LocaleTest::time_by_name() -{ -# if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - /* - * Check of the 22.1.1.2.7 standard point. Construction of a locale - * instance from a null pointer or an unknown name should result in - * a runtime_error exception. - */ -# if defined (STLPORT) || !defined (_MSC_VER) || (_MSC_VER > 1400) - try { - locale loc(locale::classic(), new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -# endif - - try { - locale loc(locale::classic(), new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - string veryLongFacetName("LC_TIME="); - veryLongFacetName.append(512, '?'); - locale loc(locale::classic(), new time_put_byname<char, ostreambuf_iterator<char, char_traits<char> > >(veryLongFacetName.c_str())); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - string veryLongFacetName("LC_TIME="); - veryLongFacetName.append(512, '?'); - locale loc(locale::classic(), new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >(veryLongFacetName.c_str())); - CPPUNIT_FAIL; - } - catch (runtime_error const& /* e */) { - //CPPUNIT_MESSAGE( e.what() ); - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), "C", locale::time); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - // On platform without real localization support we should rely on the "C" facet. - locale loc(locale::classic(), "", locale::time); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >("C")); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - // On platform without real localization support we should rely on the "C" locale facet. - locale loc(locale::classic(), new time_get_byname<char, istreambuf_iterator<char, char_traits<char> > >("")); - } - catch (runtime_error const& /* e */) { - /* CPPUNIT_MESSAGE( e.what() ); */ - CPPUNIT_FAIL; - } - catch (...) { - CPPUNIT_FAIL; - } - -# if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) - try { - locale loc(locale::classic(), new time_put_byname<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new time_put_byname<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new time_get_byname<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >(static_cast<char const*>(0))); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - - try { - locale loc(locale::classic(), new time_get_byname<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >("yasli_language")); - CPPUNIT_FAIL; - } - catch (runtime_error const&) { - } - catch (...) { - CPPUNIT_FAIL; - } - -# endif -# endif -} - -#endif diff --git a/test/unit/time_header_test.c b/test/unit/time_header_test.c deleted file mode 100644 index dbfe64b..0000000 --- a/test/unit/time_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <time.h> diff --git a/test/unit/times_test.cpp b/test/unit/times_test.cpp deleted file mode 100644 index aa13925..0000000 --- a/test/unit/times_test.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include <algorithm> -#include <numeric> -#include <functional> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class TimesTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(TimesTest); - CPPUNIT_TEST(times); - CPPUNIT_TEST_SUITE_END(); - -protected: - void times(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(TimesTest); - -// -// tests implementation -// -void TimesTest::times() -{ - int input [4] = { 1, 5, 7, 2 }; - int total = accumulate(input, input + 4, 1, multiplies<int>()); - CPPUNIT_ASSERT(total==70); -} diff --git a/test/unit/transform_test.cpp b/test/unit/transform_test.cpp deleted file mode 100644 index 81649e1..0000000 --- a/test/unit/transform_test.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include <string> -#include <iterator> -#include <vector> -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class TransformTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(TransformTest); - CPPUNIT_TEST(trnsfrm1); - CPPUNIT_TEST(trnsfrm2); - CPPUNIT_TEST(self_str); - CPPUNIT_TEST_SUITE_END(); - -protected: - void trnsfrm1(); - void trnsfrm2(); - void self_str(); - - static int negate_int(int a_) { - return -a_; - } - static char map_char(char a_, int b_) { - return char(a_ + b_); - } - static char shift( char c ) { - return char(((int)c + 1) % 256); - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(TransformTest); - -// -// tests implementation -// -void TransformTest::trnsfrm1() -{ - int numbers[6] = { -5, -1, 0, 1, 6, 11 }; - - int result[6]; - transform((int*)numbers, (int*)numbers + 6, (int*)result, negate_int); - - CPPUNIT_ASSERT(result[0]==5); - CPPUNIT_ASSERT(result[1]==1); - CPPUNIT_ASSERT(result[2]==0); - CPPUNIT_ASSERT(result[3]==-1); - CPPUNIT_ASSERT(result[4]==-6); - CPPUNIT_ASSERT(result[5]==-11); -} -void TransformTest::trnsfrm2() -{ -#if defined (__MVS__) - int trans[] = {-11, 4, -6, -6, -18, 0, 18, -14, 6, 0, -1, -59}; -#else - int trans[] = {-4, 4, -6, -6, -10, 0, 10, -6, 6, 0, -1, -77}; -#endif - char n[] = "Larry Mullen"; - const size_t count = ::strlen(n); - - string res; - transform(n, n + count, trans, back_inserter(res), map_char); - CPPUNIT_ASSERT( res == "Hello World!" ) -} - -void TransformTest::self_str() -{ - string s( "0123456789abcdefg" ); - string r( "123456789:bcdefgh" ); - transform( s.begin(), s.end(), s.begin(), shift ); - CPPUNIT_ASSERT( s == r ); -} - diff --git a/test/unit/type_traits_test.cpp b/test/unit/type_traits_test.cpp deleted file mode 100644 index d881451..0000000 --- a/test/unit/type_traits_test.cpp +++ /dev/null @@ -1,593 +0,0 @@ -#include <algorithm> -#include <vector> -#include <string> - -#include "cppunit/cppunit_proxy.h" - -#if defined (_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class TypeTraitsTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(TypeTraitsTest); -#if !defined (STLPORT) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(manips); - CPPUNIT_TEST(integer); - CPPUNIT_TEST(rational); - CPPUNIT_TEST(pointer_type); -#if defined (STLPORT) && !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(reference_type); -#if defined (STLPORT) - CPPUNIT_STOP_IGNORE; -#endif - CPPUNIT_TEST(both_pointer_type); - CPPUNIT_TEST(ok_to_use_memcpy); - CPPUNIT_TEST(ok_to_use_memmove); - CPPUNIT_TEST(trivial_destructor); - CPPUNIT_TEST(is_POD); - CPPUNIT_TEST(stlport_class); - CPPUNIT_TEST_SUITE_END(); - -protected: - void manips(); - void integer(); - void rational(); - void pointer_type(); - void reference_type(); - void both_pointer_type(); - void ok_to_use_memcpy(); - void ok_to_use_memmove(); - void trivial_destructor(); - void is_POD(); - void stlport_class(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(TypeTraitsTest); - -#if defined (STLPORT) - -# if defined (__GNUC__) && defined (_STLP_USE_NAMESPACES) -// libstdc++ sometimes exposed its own __true_type type in global -// namespace resulting in an ambiguity. -# define __true_type std::__true_type -# define __false_type std::__false_type -# endif - -int type_to_value(__true_type) -{ return 1; } -int type_to_value(__false_type) -{ return 0; } - -int* int_pointer; -int const* int_const_pointer; -int volatile* int_volatile_pointer; -int const volatile* int_const_volatile_pointer; -int int_val = 0; -int const int_const_val = 0; -int volatile int_volatile_val = 0; -int & int_ref = int_val; -int const& int_const_ref = int_val; -int const volatile& int_const_volatile_ref = int_val; - -//A type that represent any type: -struct any_type -{ - //Dummy operations to forbid to compilers with intrinsic - //type traits support to consider this type as a POD. - any_type() : m_data(1) {} - any_type(const any_type&) : m_data(2) {} - any_type& operator = (const any_type&) - { m_data = 3; return *this; } - ~any_type() { m_data = 0; } - - size_t m_data; -}; - -any_type any; -any_type* any_pointer; -any_type const* any_const_pointer; -any_type volatile* any_volatile_pointer; -any_type const volatile* any_const_volatile_pointer; - -//A type that represent any pod type -struct any_pod_type -{}; - -# if defined (_STLP_USE_BOOST_SUPPORT) -//Mandatory for compilers without without partial template specialization. -BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(any_pod_type) -# endif - -any_pod_type any_pod; -any_pod_type* any_pod_pointer; -any_pod_type const* any_pod_const_pointer; -any_pod_type volatile* any_pod_volatile_pointer; -any_pod_type const volatile* any_pod_const_volatile_pointer; - -# if defined (_STLP_USE_NAMESPACES) -namespace std { -# endif - _STLP_TEMPLATE_NULL - struct __type_traits<any_pod_type> { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; -# if defined (_STLP_USE_NAMESPACES) -} -# endif - -struct base -{}; -struct derived : public base -{}; - -// -// tests implementation -// -template <typename _Src, typename _Dst> -int is_convertible(_Src, _Dst) { -# if !defined(__BORLANDC__) - typedef typename _IsConvertible<_Src, _Dst>::_Ret _Ret; -# else - enum { _Is = _IsConvertible<_Src, _Dst>::value }; - typedef typename __bool2type<_Is>::_Ret _Ret; -# endif - return type_to_value(_Ret()); -} - -template <typename _Src, typename _Dst> -int is_cv_convertible(_Src, _Dst) { -# if !defined(__BORLANDC__) - typedef typename _IsCVConvertible<_Src, _Dst>::_Ret _Ret; -# else - enum { _Is = _IsCVConvertible<_Src, _Dst>::value }; - typedef typename __bool2type<_Is>::_Ret _Ret; -# endif - return type_to_value(_Ret()); -} -#endif - -void TypeTraitsTest::manips() -{ -#if defined (STLPORT) - { - typedef __bool2type<0>::_Ret _ZeroRet; - CPPUNIT_ASSERT( type_to_value(_ZeroRet()) == 0 ); - typedef __bool2type<1>::_Ret _OneRet; - CPPUNIT_ASSERT( type_to_value(_OneRet()) == 1 ); - typedef __bool2type<65456873>::_Ret _AnyRet; - CPPUNIT_ASSERT( type_to_value(_AnyRet()) == 1 ); - } - - { - CPPUNIT_ASSERT( __type2bool<__true_type>::_Ret == 1 ); - CPPUNIT_ASSERT( __type2bool<__false_type>::_Ret == 0 ); - CPPUNIT_ASSERT( __type2bool<any_type>::_Ret == 1 ); - } - - { - typedef _Not<__true_type>::_Ret _NotTrueRet; - CPPUNIT_ASSERT( type_to_value(_NotTrueRet()) == 0 ); - typedef _Not<__false_type>::_Ret _NotFalseRet; - CPPUNIT_ASSERT( type_to_value(_NotFalseRet()) == 1 ); - } - - { - typedef _Land2<__true_type, __true_type>::_Ret _TrueTrueRet; - CPPUNIT_ASSERT( type_to_value(_TrueTrueRet()) == 1 ); - typedef _Land2<__true_type, __false_type>::_Ret _TrueFalseRet; - CPPUNIT_ASSERT( type_to_value(_TrueFalseRet()) == 0 ); - typedef _Land2<__false_type, __true_type>::_Ret _FalseTrueRet; - CPPUNIT_ASSERT( type_to_value(_FalseTrueRet()) == 0 ); - typedef _Land2<__false_type, __false_type>::_Ret _FalseFalseRet; - CPPUNIT_ASSERT( type_to_value(_FalseFalseRet()) == 0 ); - } - - { - typedef _Land3<__true_type, __true_type, __true_type>::_Ret _TrueTrueTrueRet; - CPPUNIT_ASSERT( type_to_value(_TrueTrueTrueRet()) == 1 ); - typedef _Land3<__true_type, __true_type, __false_type>::_Ret _TrueTrueFalseRet; - CPPUNIT_ASSERT( type_to_value(_TrueTrueFalseRet()) == 0 ); - typedef _Land3<__true_type, __false_type, __true_type>::_Ret _TrueFalseTrueRet; - CPPUNIT_ASSERT( type_to_value(_TrueFalseTrueRet()) == 0 ); - typedef _Land3<__true_type, __false_type, __false_type>::_Ret _TrueFalseFalseRet; - CPPUNIT_ASSERT( type_to_value(_TrueFalseFalseRet()) == 0 ); - typedef _Land3<__false_type, __true_type, __true_type>::_Ret _FalseTrueTrueRet; - CPPUNIT_ASSERT( type_to_value(_FalseTrueTrueRet()) == 0 ); - typedef _Land3<__false_type, __true_type, __false_type>::_Ret _FalseTrueFalseRet; - CPPUNIT_ASSERT( type_to_value(_FalseTrueFalseRet()) == 0 ); - typedef _Land3<__false_type, __false_type, __true_type>::_Ret _FalseFalseTrueRet; - CPPUNIT_ASSERT( type_to_value(_FalseFalseTrueRet()) == 0 ); - typedef _Land3<__false_type, __false_type, __false_type>::_Ret _FalseFalseFalseRet; - CPPUNIT_ASSERT( type_to_value(_FalseFalseFalseRet()) == 0 ); - } - - { - typedef _Lor2<__true_type, __true_type>::_Ret _TrueTrueRet; - CPPUNIT_ASSERT( type_to_value(_TrueTrueRet()) == 1 ); - typedef _Lor2<__true_type, __false_type>::_Ret _TrueFalseRet; - CPPUNIT_ASSERT( type_to_value(_TrueFalseRet()) == 1 ); - typedef _Lor2<__false_type, __true_type>::_Ret _FalseTrueRet; - CPPUNIT_ASSERT( type_to_value(_FalseTrueRet()) == 1 ); - typedef _Lor2<__false_type, __false_type>::_Ret _FalseFalseRet; - CPPUNIT_ASSERT( type_to_value(_FalseFalseRet()) == 0 ); - } - - { - typedef _Lor3<__true_type, __true_type, __true_type>::_Ret _TrueTrueTrueRet; - CPPUNIT_ASSERT( type_to_value(_TrueTrueTrueRet()) == 1 ); - typedef _Lor3<__true_type, __true_type, __false_type>::_Ret _TrueTrueFalseRet; - CPPUNIT_ASSERT( type_to_value(_TrueTrueFalseRet()) == 1 ); - typedef _Lor3<__true_type, __false_type, __true_type>::_Ret _TrueFalseTrueRet; - CPPUNIT_ASSERT( type_to_value(_TrueFalseTrueRet()) == 1 ); - typedef _Lor3<__true_type, __false_type, __false_type>::_Ret _TrueFalseFalseRet; - CPPUNIT_ASSERT( type_to_value(_TrueFalseFalseRet()) == 1 ); - typedef _Lor3<__false_type, __true_type, __true_type>::_Ret _FalseTrueTrueRet; - CPPUNIT_ASSERT( type_to_value(_FalseTrueTrueRet()) == 1 ); - typedef _Lor3<__false_type, __true_type, __false_type>::_Ret _FalseTrueFalseRet; - CPPUNIT_ASSERT( type_to_value(_FalseTrueFalseRet()) == 1 ); - typedef _Lor3<__false_type, __false_type, __true_type>::_Ret _FalseFalseTrueRet; - CPPUNIT_ASSERT( type_to_value(_FalseFalseTrueRet()) == 1 ); - typedef _Lor3<__false_type, __false_type, __false_type>::_Ret _FalseFalseFalseRet; - CPPUNIT_ASSERT( type_to_value(_FalseFalseFalseRet()) == 0 ); - } - - { - typedef __select<1, __true_type, __false_type>::_Ret _SelectFirstRet; - CPPUNIT_ASSERT( type_to_value(_SelectFirstRet()) == 1 ); - typedef __select<0, __true_type, __false_type>::_Ret _SelectSecondRet; - CPPUNIT_ASSERT( type_to_value(_SelectSecondRet()) == 0 ); -# if defined (__BORLANDC__) - typedef __selectT<__true_type, __true_type, __false_type>::_Ret _SelectFirstRet; - CPPUNIT_ASSERT( type_to_value(_SelectFirstRet()) == 1 ); - typedef __selectT<__false_type, __true_type, __false_type>::_Ret _SelectSecondRet; - CPPUNIT_ASSERT( type_to_value(_SelectSecondRet()) == 0 ); -# endif - } - - { - base b; - derived d; - const derived cd = d; - base *pb = &b; - derived *pd = &d; - derived const *pcd = pd; - CPPUNIT_CHECK( is_convertible(any, b) == 0 ); - CPPUNIT_CHECK( is_convertible(d, b) == 1 ); - CPPUNIT_CHECK( is_convertible(cd, b) == 1 ); - // _IsCVConvertible only needs to work for pointer type: - //CPPUNIT_CHECK( is_cv_convertible(d, b) == 1 ); - //CPPUNIT_CHECK( is_cv_convertible(cd, b) == 0 ); - - //_IsConvertible do not need to work for pointers: - //CPPUNIT_CHECK( is_convertible(pd, pb) == 1 ); - //CPPUNIT_CHECK( is_convertible(pcd, pb) == 1 ); - - CPPUNIT_CHECK( is_cv_convertible(pd, pb) == 1 ); - CPPUNIT_CHECK( is_cv_convertible(pcd, pb) == 0 ); - } -#endif -} - -#if defined (STLPORT) -template <typename _Type> -int is_integer(_Type) { - typedef typename _IsIntegral<_Type>::_Ret _Ret; - return type_to_value(_Ret()); -} -#endif - -void TypeTraitsTest::integer() -{ -#if defined (STLPORT) - CPPUNIT_ASSERT( is_integer(bool()) == 1 ); - CPPUNIT_ASSERT( is_integer(char()) == 1 ); - typedef signed char signed_char; - CPPUNIT_ASSERT( is_integer(signed_char()) == 1 ); - typedef unsigned char unsigned_char; - CPPUNIT_ASSERT( is_integer(unsigned_char()) == 1 ); -# if defined (_STLP_HAS_WCHAR_T) - CPPUNIT_ASSERT( is_integer(wchar_t()) == 1 ); -# endif - CPPUNIT_ASSERT( is_integer(short()) == 1 ); - typedef unsigned short unsigned_short; - CPPUNIT_ASSERT( is_integer(unsigned_short()) == 1 ); - CPPUNIT_ASSERT( is_integer(int()) == 1 ); - typedef unsigned int unsigned_int; - CPPUNIT_ASSERT( is_integer(unsigned_int()) == 1 ); - CPPUNIT_ASSERT( is_integer(long()) == 1 ); - typedef unsigned long unsigned_long; - CPPUNIT_ASSERT( is_integer(unsigned_long()) == 1 ); -# if defined (_STLP_LONG_LONG) - typedef _STLP_LONG_LONG long_long; - CPPUNIT_ASSERT( is_integer(long_long()) == 1 ); - typedef unsigned _STLP_LONG_LONG unsigned_long_long; - CPPUNIT_ASSERT( is_integer(unsigned_long_long()) == 1 ); -# endif - CPPUNIT_ASSERT( is_integer(float()) == 0 ); - CPPUNIT_ASSERT( is_integer(double()) == 0 ); -# if !defined ( _STLP_NO_LONG_DOUBLE ) - typedef long double long_double; - CPPUNIT_ASSERT( is_integer(long_double()) == 0 ); -# endif - CPPUNIT_ASSERT( is_integer(any) == 0 ); - CPPUNIT_ASSERT( is_integer(any_pointer) == 0 ); -#endif -} - -#if defined (STLPORT) -template <typename _Type> -int is_rational(_Type) { - typedef typename _IsRational<_Type>::_Ret _Ret; - return type_to_value(_Ret()); -} -#endif - -void TypeTraitsTest::rational() -{ -#if defined (STLPORT) - CPPUNIT_ASSERT( is_rational(bool()) == 0 ); - CPPUNIT_ASSERT( is_rational(char()) == 0 ); - typedef signed char signed_char; - CPPUNIT_ASSERT( is_rational(signed_char()) == 0 ); - typedef unsigned char unsigned_char; - CPPUNIT_ASSERT( is_rational(unsigned_char()) == 0 ); -# if defined (_STLP_HAS_WCHAR_T) - CPPUNIT_ASSERT( is_rational(wchar_t()) == 0 ); -# endif - CPPUNIT_ASSERT( is_rational(short()) == 0 ); - typedef unsigned short unsigned_short; - CPPUNIT_ASSERT( is_rational(unsigned_short()) == 0 ); - CPPUNIT_ASSERT( is_rational(int()) == 0 ); - typedef unsigned int unsigned_int; - CPPUNIT_ASSERT( is_rational(unsigned_int()) == 0 ); - CPPUNIT_ASSERT( is_rational(long()) == 0 ); - typedef unsigned long unsigned_long; - CPPUNIT_ASSERT( is_rational(unsigned_long()) == 0 ); -# if defined (_STLP_LONG_LONG) - typedef _STLP_LONG_LONG long_long; - CPPUNIT_ASSERT( is_rational(long_long()) == 0 ); - typedef unsigned _STLP_LONG_LONG unsigned_long_long; - CPPUNIT_ASSERT( is_rational(unsigned_long_long()) == 0 ); -# endif - CPPUNIT_ASSERT( is_rational(float()) == 1 ); - CPPUNIT_ASSERT( is_rational(double()) == 1 ); -# if !defined ( _STLP_NO_LONG_DOUBLE ) - typedef long double long_double; - CPPUNIT_ASSERT( is_rational(long_double()) == 1 ); -# endif - CPPUNIT_ASSERT( is_rational(any) == 0 ); - CPPUNIT_ASSERT( is_rational(any_pointer) == 0 ); -#endif -} - -#if defined (STLPORT) -template <typename _Type> -int is_pointer_type(_Type) { - return type_to_value(_IsPtrType<_Type>::_Ret()); -} -#endif - -void TypeTraitsTest::pointer_type() -{ -#if defined (STLPORT) - CPPUNIT_ASSERT( is_pointer_type(int_val) == 0 ); - CPPUNIT_ASSERT( is_pointer_type(int_pointer) == 1 ); - CPPUNIT_ASSERT( is_pointer_type(int_const_pointer) == 1 ); - CPPUNIT_ASSERT( is_pointer_type(int_volatile_pointer) == 1 ); - CPPUNIT_ASSERT( is_pointer_type(int_const_volatile_pointer) == 1 ); - CPPUNIT_ASSERT( is_pointer_type(int_ref) == 0 ); - CPPUNIT_ASSERT( is_pointer_type(int_const_ref) == 0 ); - CPPUNIT_ASSERT( is_pointer_type(any) == 0 ); - CPPUNIT_ASSERT( is_pointer_type(any_pointer) == 1 ); -#endif -} - -void TypeTraitsTest::reference_type() -{ -#if defined (STLPORT) && defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_ASSERT( type_to_value(_IsRefType<int>::_Ret()) == 0 ); - CPPUNIT_ASSERT( type_to_value(_IsRefType<int*>::_Ret()) == 0 ); - CPPUNIT_ASSERT( type_to_value(_IsRefType<int&>::_Ret()) == 1 ); - CPPUNIT_ASSERT( type_to_value(_IsRefType<int const&>::_Ret()) == 1 ); - CPPUNIT_ASSERT( type_to_value(_IsRefType<int const volatile&>::_Ret()) == 1 ); - - CPPUNIT_ASSERT( type_to_value(_IsOKToSwap(int_pointer, int_pointer, __true_type(), __true_type())._Answer()) == 1 ); - CPPUNIT_ASSERT( type_to_value(_IsOKToSwap(int_pointer, int_pointer, __false_type(), __false_type())._Answer()) == 0 ); -#endif -} - -#if defined (STLPORT) -template <typename _Tp1, typename _Tp2> -int are_both_pointer_type (_Tp1, _Tp2) { - return type_to_value(_BothPtrType<_Tp1, _Tp2>::_Answer()); -} -#endif - -void TypeTraitsTest::both_pointer_type() -{ -#if defined (STLPORT) - CPPUNIT_CHECK( are_both_pointer_type(int_val, int_val) == 0 ); - CPPUNIT_CHECK( are_both_pointer_type(int_pointer, int_pointer) == 1 ); - CPPUNIT_CHECK( are_both_pointer_type(int_const_pointer, int_const_pointer) == 1 ); - CPPUNIT_CHECK( are_both_pointer_type(int_volatile_pointer, int_volatile_pointer) == 1 ); - CPPUNIT_CHECK( are_both_pointer_type(int_const_volatile_pointer, int_const_volatile_pointer) == 1 ); - CPPUNIT_CHECK( are_both_pointer_type(int_ref, int_ref) == 0 ); - CPPUNIT_CHECK( are_both_pointer_type(int_const_ref, int_const_ref) == 0 ); - CPPUNIT_CHECK( are_both_pointer_type(any, any) == 0 ); - CPPUNIT_CHECK( are_both_pointer_type(any_pointer, any_pointer) == 1 ); -#endif -} - -#if defined (STLPORT) -template <typename _Tp1, typename _Tp2> -int is_ok_to_use_memcpy(_Tp1 val1, _Tp2 val2) { - return type_to_value(_UseTrivialCopy(val1, val2)._Answer()); -} -#endif - -void TypeTraitsTest::ok_to_use_memcpy() -{ -#if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_pointer, int_pointer) == 1 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_pointer, int_pointer) == 1 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_pointer, int_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_pointer, int_const_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_pointer, int_const_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_pointer, int_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_pointer, int_const_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_const_volatile_pointer, int_const_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(int_pointer, any_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pointer, int_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pointer, any_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pointer, any_const_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pod_pointer, int_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pod_pointer, any_pod_pointer) == 1 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(any_pod_pointer, any_pod_const_pointer) == 0 ); - vector<float> **pvf = 0; - vector<int> **pvi = 0; - CPPUNIT_CHECK( is_ok_to_use_memcpy(pvf, pvi) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memcpy(pvi, pvf) == 0 ); -#endif -} - -#if defined (STLPORT) -template <typename _Tp1, typename _Tp2> -int is_ok_to_use_memmove(_Tp1 val1, _Tp2 val2) { - return type_to_value(_UseTrivialUCopy(val1, val2)._Answer()); -} -#endif - -void TypeTraitsTest::ok_to_use_memmove() -{ -#if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) - CPPUNIT_CHECK( is_ok_to_use_memmove(int_pointer, int_pointer) == 1 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_pointer, int_pointer) == 1 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(int_pointer, int_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(int_pointer, int_const_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_pointer, int_const_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_pointer, int_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_pointer, int_const_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(int_const_volatile_pointer, int_const_volatile_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(int_pointer, any_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(any_pointer, int_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(any_pointer, any_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(any_pointer, any_const_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(any_pod_pointer, int_pointer) == 0 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(any_pod_pointer, any_pod_pointer) == 1 ); - CPPUNIT_CHECK( is_ok_to_use_memmove(any_pod_pointer, any_pod_const_pointer) == 0 ); -#endif -} - -#if defined (STLPORT) -template <typename _Tp> -int has_trivial_destructor(_Tp) { - typedef typename __type_traits<_Tp>::has_trivial_destructor _TrivialDestructor; - return type_to_value(_TrivialDestructor()); -} - -struct DestructorMonitor -{ - ~DestructorMonitor() - { ++nb_destructor_call; } - - static size_t nb_destructor_call; -}; - -size_t DestructorMonitor::nb_destructor_call = 0; - -# if defined (_STLP_USE_NAMESPACES) -namespace std { -# endif - _STLP_TEMPLATE_NULL - struct __type_traits<DestructorMonitor> { - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; -# if defined (_STLP_USE_NAMESPACES) -} -# endif -#endif - -void TypeTraitsTest::trivial_destructor() -{ -#if defined (STLPORT) - CPPUNIT_CHECK( has_trivial_destructor(int_pointer) == 1 ); - CPPUNIT_CHECK( has_trivial_destructor(int_const_pointer) == 1 ); - CPPUNIT_CHECK( has_trivial_destructor(int_volatile_pointer) == 1 ); - CPPUNIT_CHECK( has_trivial_destructor(int_const_volatile_pointer) == 1 ); - CPPUNIT_CHECK( has_trivial_destructor(any_pointer) == 1 ); - CPPUNIT_CHECK( has_trivial_destructor(any) == 0 ); - CPPUNIT_CHECK( has_trivial_destructor(any_pointer) == 1 ); - CPPUNIT_CHECK( has_trivial_destructor(any_pod) == 1 ); - CPPUNIT_CHECK( has_trivial_destructor(string()) == 0 ); - - //Check of the meta information impact in a container implementation - { - vector<DestructorMonitor> v(10); - DestructorMonitor::nb_destructor_call = 0; - } - CPPUNIT_CHECK( DestructorMonitor::nb_destructor_call == 0 ); -#endif -} - -#if defined (STLPORT) -template <typename _Tp> -int is_POD_type(_Tp) { - typedef typename __type_traits<_Tp>::is_POD_type _IsPODType; - return type_to_value(_IsPODType()); -} -#endif - -void TypeTraitsTest::is_POD() -{ -#if defined (STLPORT) - CPPUNIT_CHECK( is_POD_type(int_pointer) == 1 ); - CPPUNIT_CHECK( is_POD_type(int_const_pointer) == 1 ); - CPPUNIT_CHECK( is_POD_type(int_volatile_pointer) == 1 ); - CPPUNIT_CHECK( is_POD_type(int_const_volatile_pointer) == 1 ); - CPPUNIT_CHECK( is_POD_type(any_pointer) == 1 ); - CPPUNIT_CHECK( is_POD_type(any) == 0 ); - CPPUNIT_CHECK( is_POD_type(any_pointer) == 1 ); - CPPUNIT_CHECK( is_POD_type(any_pod) == 1 ); - CPPUNIT_CHECK( is_POD_type(string()) == 0 ); -#endif -} - -#if defined (STLPORT) -template <typename _Tp> -int is_stlport_class(_Tp) { - typedef _IsSTLportClass<_Tp> _STLportClass; -# if !defined (__BORLANDC__) - typedef typename _STLportClass::_Ret _Is; -# else - typedef typename __bool2type<_STLportClass::_Is>::_Ret _Is; -# endif - return type_to_value(_Is()); -} -#endif - -void TypeTraitsTest::stlport_class() -{ -#if defined (STLPORT) - CPPUNIT_CHECK( is_stlport_class(allocator<char>()) == 1 ); -# if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) - CPPUNIT_CHECK( is_stlport_class(string()) == 1 ); -# endif - CPPUNIT_CHECK( is_stlport_class(any) == 0 ); -#endif -} diff --git a/test/unit/typeinfo_header_test.cpp b/test/unit/typeinfo_header_test.cpp deleted file mode 100644 index 7e3f5eb..0000000 --- a/test/unit/typeinfo_header_test.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <typeinfo> - -#if 0 /* !defined (_STLP_NO_RTTI) && !defined (_STLP_NO_TYPEINFO) */ -/* SourceForge: STLport bug report 1721844 - * type_info is not a member of stlp_std - */ -class A {}; - -void type_info_header_test() -{ - const std::type_info& ti = typeid(A); -} -#endif diff --git a/test/unit/unary.h b/test/unit/unary.h deleted file mode 100644 index 8c9ef43..0000000 --- a/test/unit/unary.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _unary_h -#define _unary_h -#include <cmath> -#include <cfloat> -#include <functional> //*TY 12/26/1998 - added to get unary_function - -#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) -using std::unary_function; -#endif - -struct odd : public unary_function<int, bool> { - bool operator()(int n_) const { return(n_ % 2) == 1; } -}; - -struct positive : public unary_function<int, bool> { - bool operator()(int n_) const { return n_ >= 0; } -}; - -struct square_root : public unary_function<double, double> { - double operator()(double x_) const - { return ::sqrt(x_); } -}; -#endif // _unary_h diff --git a/test/unit/unary_test.cpp b/test/unit/unary_test.cpp deleted file mode 100644 index ee480b7..0000000 --- a/test/unit/unary_test.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include <vector> -#include "unary.h" -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class UnaryTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(UnaryTest); -#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(ucompos1); - CPPUNIT_TEST(ucompos2); - CPPUNIT_STOP_IGNORE; - CPPUNIT_TEST(unegate1); - CPPUNIT_TEST(unegate2); -#if defined (STLPORT) && !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(unegate3); - CPPUNIT_TEST_SUITE_END(); - -protected: - void ucompos1(); - void ucompos2(); - void unegate1(); - void unegate2(); - void unegate3(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(UnaryTest); - -// -// tests implementation -// -void UnaryTest::unegate1() -{ - int array [3] = { 1, 2, 3 }; - //unary_negate<odd>::argument_type arg_val = 0; - int* p = find_if((int*)array, (int*)array + 3, unary_negate<odd>(odd())); - CPPUNIT_ASSERT((p != array + 3)); - CPPUNIT_ASSERT(*p==2); -} -void UnaryTest::unegate2() -{ - int array [3] = { 1, 2, 3 }; - int* p = find_if((int*)array, (int*)array + 3, not1(odd())); - CPPUNIT_ASSERT(p != array + 3); - CPPUNIT_ASSERT(*p==2); -} - -bool test_func(int param) { - return param < 3; -} -void UnaryTest::unegate3() -{ -#if !defined (STLPORT) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) - int array [3] = { 1, 2, 3 }; - int* p = find_if((int*)array, (int*)array + 3, not1(ptr_fun(test_func))); - CPPUNIT_ASSERT(p != array + 3); - CPPUNIT_ASSERT(*p==3); -#endif -} - -void UnaryTest::ucompos1() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - int input [3] = { -1, -4, -16 }; - - double output[3]; - transform((int*)input, (int*)input + 3, output, unary_compose<square_root, negate<int> >(square_root(), negate<int>())); - - CPPUNIT_ASSERT(output[0]==1); - CPPUNIT_ASSERT(output[1]==2); - CPPUNIT_ASSERT(output[2]==4); -#endif -} -void UnaryTest::ucompos2() -{ -#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) - int input [3] = { -1, -4, -16 }; - - double output [3]; - transform((int*)input, (int*)input + 3, output, compose1(square_root(), negate<int>())); - - CPPUNIT_ASSERT(output[0]==1); - CPPUNIT_ASSERT(output[1]==2); - CPPUNIT_ASSERT(output[2]==4); -#endif -} diff --git a/test/unit/uninitialized_test.cpp b/test/unit/uninitialized_test.cpp deleted file mode 100644 index 37884f7..0000000 --- a/test/unit/uninitialized_test.cpp +++ /dev/null @@ -1,245 +0,0 @@ -#include <memory> -#include <vector> -#include <list> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class UninitializedTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(UninitializedTest); - CPPUNIT_TEST(copy_test); - //CPPUNIT_TEST(fill_test); - //CPPUNIT_TEST(fill_n_test); - CPPUNIT_TEST_SUITE_END(); - -protected: - void copy_test(); - void fill_test(); - void fill_n_test(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(UninitializedTest); - -struct NotTrivialCopyStruct { - NotTrivialCopyStruct() : member(0) {} - NotTrivialCopyStruct(NotTrivialCopyStruct const&) : member(1) {} - - int member; -}; - -struct TrivialCopyStruct { - TrivialCopyStruct() : member(0) {} - TrivialCopyStruct(TrivialCopyStruct const&) : member(1) {} - - int member; -}; - -struct TrivialInitStruct { - TrivialInitStruct() - { ++nbConstructorCalls; } - - static size_t nbConstructorCalls; -}; - -size_t TrivialInitStruct::nbConstructorCalls = 0; - -#if defined (STLPORT) -# if defined (_STLP_USE_NAMESPACES) -namespace std { -# endif - _STLP_TEMPLATE_NULL - struct __type_traits<TrivialCopyStruct> { - typedef __false_type has_trivial_default_constructor; - //This is a wrong declaration just to check that internaly a simple memcpy is called: - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __false_type is_POD_type; - }; - - _STLP_TEMPLATE_NULL - struct __type_traits<TrivialInitStruct> { - //This is a wrong declaration just to check that internaly no initialization is done: - typedef __true_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __false_type is_POD_type; - }; -# if defined (_STLP_USE_NAMESPACES) -} -# endif -#endif - -struct base {}; -struct derived : public base {}; - -// -// tests implementation -// -void UninitializedTest::copy_test() -{ - { - //Random iterators - { - vector<NotTrivialCopyStruct> src(10); - vector<NotTrivialCopyStruct> dst(10); - uninitialized_copy(src.begin(), src.end(), dst.begin()); - vector<NotTrivialCopyStruct>::const_iterator it(dst.begin()), end(dst.end()); - for (; it != end; ++it) { - CPPUNIT_ASSERT( (*it).member == 1 ); - } - } - { - /** Note: we use static arrays here so the iterators are always - pointers, even in debug mode. */ - size_t const count = 10; - TrivialCopyStruct src[count]; - TrivialCopyStruct dst[count]; - - TrivialCopyStruct* it = src + 0; - TrivialCopyStruct* end = src + count; - for (; it != end; ++it) { - (*it).member = 0; - } - - uninitialized_copy(src+0, src+count, dst+0); - for (it = dst+0, end = dst+count; it != end; ++it) { -#if defined (STLPORT) - /* If the member is 1, it means that library has not found any - optimization oportunity and called the regular copy-ctor instead. */ - CPPUNIT_ASSERT( (*it).member == 0 ); -#else - CPPUNIT_ASSERT( (*it).member == 1 ); -#endif - } - } - } - - { - //Bidirectional iterator - { - vector<NotTrivialCopyStruct> src(10); - list<NotTrivialCopyStruct> dst(10); - - list<NotTrivialCopyStruct>::iterator it(dst.begin()), end(dst.end()); - for (; it != end; ++it) { - (*it).member = -1; - } - - uninitialized_copy(src.begin(), src.end(), dst.begin()); - - for (it = dst.begin(); it != end; ++it) { - CPPUNIT_ASSERT( (*it).member == 1 ); - } - } - - { - list<NotTrivialCopyStruct> src(10); - vector<NotTrivialCopyStruct> dst(10); - - vector<NotTrivialCopyStruct>::iterator it(dst.begin()), end(dst.end()); - for (; it != end; ++it) { - (*it).member = -1; - } - - uninitialized_copy(src.begin(), src.end(), dst.begin()); - - for (it = dst.begin(); it != end; ++it) { - CPPUNIT_ASSERT( (*it).member == 1 ); - } - } - } - - { - //Using containers of native types: -#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) - { - vector<int> src; - int i; - for (i = -5; i < 6; ++i) { - src.push_back(i); - } - - //Building a vector result in a uninitialized_copy call internally - vector<unsigned int> dst(src.begin(), src.end()); - vector<unsigned int>::const_iterator it(dst.begin()); - for (i = -5; i < 6; ++i, ++it) { - CPPUNIT_ASSERT( *it == (unsigned int)i ); - } - } - - { - vector<char> src; - char i; - for (i = -5; i < 6; ++i) { - src.push_back(i); - } - - //Building a vector result in a uninitialized_copy call internally - vector<unsigned int> dst(src.begin(), src.end()); - vector<unsigned int>::const_iterator it(dst.begin()); - for (i = -5; i < 6; ++i, ++it) { - CPPUNIT_ASSERT( *it == (unsigned int)i ); - } - } - - { - vector<int> src; - int i; - for (i = -5; i < 6; ++i) { - src.push_back(i); - } - - //Building a vector result in a uninitialized_copy call internally - vector<float> dst(src.begin(), src.end()); - vector<float>::const_iterator it(dst.begin()); - for (i = -5; i < 6; ++i, ++it) { - CPPUNIT_ASSERT( *it == (float)i ); - } - } - - { - vector<vector<float>*> src(10); - vector<vector<float>*> dst(src.begin(), src.end()); - } - - { - derived d; - //base *pb = &d; - derived *pd = &d; - //base **ppb = &pd; - vector<derived*> src(10, pd); - vector<base*> dst(src.begin(), src.end()); - vector<base*>::iterator it(dst.begin()), end(dst.end()); - for (; it != end; ++it) { - CPPUNIT_ASSERT( (*it) == pd ); - } - } -#endif - } - - { - //Vector initialization: - vector<TrivialInitStruct> vect(10); - //Just 1 constructor call for the default value: - CPPUNIT_ASSERT( TrivialInitStruct::nbConstructorCalls == 1 ); - } -} - -/* -void UninitializedTest::fill_test() -{ -} - -void UninitializedTest::fill_n_test() -{ -} -*/ diff --git a/test/unit/unique_test.cpp b/test/unit/unique_test.cpp deleted file mode 100644 index b080b7b..0000000 --- a/test/unit/unique_test.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include <algorithm> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class UniqueTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(UniqueTest); - CPPUNIT_TEST(uniqcpy1); - CPPUNIT_TEST(uniqcpy2); - CPPUNIT_TEST(unique1); - CPPUNIT_TEST(unique2); - CPPUNIT_TEST_SUITE_END(); - -protected: - void uniqcpy1(); - void uniqcpy2(); - void unique1(); - void unique2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(UniqueTest); - -static bool str_equal(const char* a_, const char* b_) -{ return *a_ == *b_; } -// -// tests implementation -// -void UniqueTest::unique1() -{ - int numbers[8] = { 0, 1, 1, 2, 2, 2, 3, 4 }; - unique((int*)numbers, (int*)numbers + 8); - // 0 1 2 3 4 2 3 4 - CPPUNIT_ASSERT(numbers[0]==0); - CPPUNIT_ASSERT(numbers[1]==1); - CPPUNIT_ASSERT(numbers[2]==2); - CPPUNIT_ASSERT(numbers[3]==3); - CPPUNIT_ASSERT(numbers[4]==4); - CPPUNIT_ASSERT(numbers[5]==2); - CPPUNIT_ASSERT(numbers[6]==3); - CPPUNIT_ASSERT(numbers[7]==4); -} - -void UniqueTest::unique2() -{ - const char* labels[] = {"Q", "Q", "W", "W", "E", "E", "R", "T", "T", "Y", "Y"}; - - const unsigned count = sizeof(labels) / sizeof(labels[0]); - - unique((const char**)labels, (const char**)labels + count, str_equal); - - // QWERTY - CPPUNIT_ASSERT(*labels[0] == 'Q'); - CPPUNIT_ASSERT(*labels[1] == 'W'); - CPPUNIT_ASSERT(*labels[2] == 'E'); - CPPUNIT_ASSERT(*labels[3] == 'R'); - CPPUNIT_ASSERT(*labels[4] == 'T'); - CPPUNIT_ASSERT(*labels[5] == 'Y'); - -} - -void UniqueTest::uniqcpy1() -{ - int numbers[8] = { 0, 1, 1, 2, 2, 2, 3, 4 }; - int result[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - unique_copy((int*)numbers, (int*)numbers + 8, (int*)result); - - // 0 1 2 3 4 0 0 0 - CPPUNIT_ASSERT(result[0]==0); - CPPUNIT_ASSERT(result[1]==1); - CPPUNIT_ASSERT(result[2]==2); - CPPUNIT_ASSERT(result[3]==3); - CPPUNIT_ASSERT(result[4]==4); - CPPUNIT_ASSERT(result[5]==0); - CPPUNIT_ASSERT(result[6]==0); - CPPUNIT_ASSERT(result[7]==0); -} - -void UniqueTest::uniqcpy2() -{ - const char* labels[] = {"Q", "Q", "W", "W", "E", "E", "R", "T", "T", "Y", "Y"}; - const char **plabels = (const char**)labels; - - const size_t count = sizeof(labels) / sizeof(labels[0]); - const char* uCopy[count]; - const char **puCopy = &uCopy[0]; - fill(puCopy, puCopy + count, ""); - - unique_copy(plabels, plabels + count, puCopy, str_equal); - - //QWERTY - CPPUNIT_ASSERT(*uCopy[0] == 'Q'); - CPPUNIT_ASSERT(*uCopy[1] == 'W'); - CPPUNIT_ASSERT(*uCopy[2] == 'E'); - CPPUNIT_ASSERT(*uCopy[3] == 'R'); - CPPUNIT_ASSERT(*uCopy[4] == 'T'); - CPPUNIT_ASSERT(*uCopy[5] == 'Y'); -} diff --git a/test/unit/unordered_test.cpp b/test/unit/unordered_test.cpp deleted file mode 100644 index 8d47ca7..0000000 --- a/test/unit/unordered_test.cpp +++ /dev/null @@ -1,676 +0,0 @@ -#include <vector> -#include <algorithm> -#include <string> -#if defined (STLPORT) -# include <unordered_map> -# include <unordered_set> -#endif - -//#include <iostream> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -# if defined (STLPORT) -using namespace std::tr1; -# endif -#endif - -// -// TestCase class -// -class UnorderedTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(UnorderedTest); -#if !defined (STLPORT) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(uset); - CPPUNIT_TEST(umultiset); - CPPUNIT_TEST(umap); - CPPUNIT_TEST(umultimap); - CPPUNIT_TEST(user_case); - CPPUNIT_TEST(hash_policy); - CPPUNIT_TEST(buckets); - CPPUNIT_TEST(equal_range); - CPPUNIT_EXPLICIT_TEST(benchmark1); - CPPUNIT_EXPLICIT_TEST(benchmark2); -#if !defined (_STLP_USE_CONTAINERS_EXTENSION) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(template_methods); - CPPUNIT_TEST_SUITE_END(); - -protected: - void uset(); - void umultiset(); - void umap(); - void umultimap(); - void user_case(); - void hash_policy(); - void buckets(); - void equal_range(); - void benchmark1(); - void benchmark2(); - void template_methods(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(UnorderedTest); - -const int NB_ELEMS = 2000; - -// -// tests implementation -// -void UnorderedTest::uset() -{ -#if defined (STLPORT) - typedef unordered_set<int, hash<int>, equal_to<int> > usettype; - usettype us; - - //Small compilation check of the copy constructor: - usettype us2(us); - //And assignment operator - us = us2; - - int i; - pair<usettype::iterator, bool> ret; - for (i = 0; i < NB_ELEMS; ++i) { - ret = us.insert(i); - CPPUNIT_ASSERT( ret.second ); - CPPUNIT_ASSERT( *ret.first == i ); - - ret = us.insert(i); - CPPUNIT_ASSERT( !ret.second ); - CPPUNIT_ASSERT( *ret.first == i ); - } - - vector<int> us_val; - - usettype::local_iterator lit, litEnd; - for (i = 0; i < NB_ELEMS; ++i) { - lit = us.begin(us.bucket(i)); - litEnd = us.end(us.bucket(i)); - - usettype::size_type bucket_pos = us.bucket(*lit); - for (; lit != litEnd; ++lit) { - CPPUNIT_ASSERT( us.bucket(*lit) == bucket_pos ); - us_val.push_back(*lit); - } - } - - //A compilation time check to uncomment from time to time - { - //usettype::iterator it; - //CPPUNIT_ASSERT( it != lit ); - } - - sort(us_val.begin(), us_val.end()); - for (i = 0; i < NB_ELEMS; ++i) { - CPPUNIT_ASSERT( us_val[i] == i ); - } -#endif -} - -void UnorderedTest::umultiset() -{ -#if defined (STLPORT) - typedef unordered_multiset<int, hash<int>, equal_to<int> > usettype; - usettype us; - - int i; - usettype::iterator ret; - for (i = 0; i < NB_ELEMS; ++i) { - ret = us.insert(i); - CPPUNIT_ASSERT( *ret == i ); - - ret = us.insert(i); - CPPUNIT_ASSERT( *ret == i ); - } - - CPPUNIT_ASSERT( us.size() == 2 * NB_ELEMS ); - vector<int> us_val; - - usettype::local_iterator lit, litEnd; - for (i = 0; i < NB_ELEMS; ++i) { - lit = us.begin(us.bucket(i)); - litEnd = us.end(us.bucket(i)); - - usettype::size_type bucket_pos = us.bucket(*lit); - for (; lit != litEnd; ++lit) { - CPPUNIT_ASSERT( us.bucket(*lit) == bucket_pos ); - us_val.push_back(*lit); - } - } - - sort(us_val.begin(), us_val.end()); - for (i = 0; i < NB_ELEMS; ++i) { - CPPUNIT_ASSERT( us_val[2 * i] == i ); - CPPUNIT_ASSERT( us_val[2 * i + 1] == i ); - } -#endif -} - -void UnorderedTest::umap() -{ -#if defined (STLPORT) - typedef unordered_map<int, int, hash<int>, equal_to<int> > umaptype; - umaptype us; - - //Compilation check of the [] operator: - umaptype us2; - us[0] = us2[0]; - us.clear(); - - { - //An other compilation check - typedef unordered_map<int, umaptype> uumaptype; - uumaptype uus; - umaptype const& uref = uus[0]; - umaptype ucopy = uus[0]; - ucopy = uref; - //Avoids warning: - //(void*)&uref; - } - - int i; - pair<umaptype::iterator, bool> ret; - for (i = 0; i < NB_ELEMS; ++i) { - umaptype::value_type p1(i, i); - ret = us.insert(p1); - CPPUNIT_ASSERT( ret.second ); - CPPUNIT_ASSERT( *ret.first == p1 ); - - umaptype::value_type p2(i, i + 1); - ret = us.insert(p2); - CPPUNIT_ASSERT( !ret.second ); - CPPUNIT_ASSERT( *ret.first == p1 ); - } - - { - //Lets look for some values to see if everything is normal: - umaptype::iterator umit; - for (int j = 0; j < NB_ELEMS; j += NB_ELEMS / 100) { - umit = us.find(j); - - CPPUNIT_ASSERT( umit != us.end() ); - CPPUNIT_ASSERT( (*umit).second == j ); - } - } - - CPPUNIT_ASSERT( us.size() == (size_t)NB_ELEMS ); - vector<pair<int, int> > us_val; - - umaptype::local_iterator lit, litEnd; - for (i = 0; i < NB_ELEMS; ++i) { - lit = us.begin(us.bucket(i)); - litEnd = us.end(us.bucket(i)); - - umaptype::size_type bucket_pos = us.bucket((*lit).first); - for (; lit != litEnd; ++lit) { - CPPUNIT_ASSERT( us.bucket((*lit).first) == bucket_pos ); - us_val.push_back(make_pair((*lit).first, (*lit).second)); - } - } - - sort(us_val.begin(), us_val.end()); - for (i = 0; i < NB_ELEMS; ++i) { - CPPUNIT_ASSERT( us_val[i] == make_pair(i, i) ); - } -#endif -} - -void UnorderedTest::umultimap() -{ -#if defined (STLPORT) - typedef unordered_multimap<int, int, hash<int>, equal_to<int> > umaptype; - umaptype us; - - int i; - umaptype::iterator ret; - for (i = 0; i < NB_ELEMS; ++i) { - umaptype::value_type p(i, i); - ret = us.insert(p); - CPPUNIT_ASSERT( *ret == p ); - - ret = us.insert(p); - CPPUNIT_ASSERT( *ret == p ); - } - - CPPUNIT_ASSERT( us.size() == 2 * NB_ELEMS ); - typedef pair<int, int> ptype; - vector<ptype> us_val; - - umaptype::local_iterator lit, litEnd; - for (i = 0; i < NB_ELEMS; ++i) { - lit = us.begin(us.bucket(i)); - litEnd = us.end(us.bucket(i)); - - umaptype::size_type bucket_pos = us.bucket((*lit).first); - for (; lit != litEnd; ++lit) { - CPPUNIT_ASSERT( us.bucket((*lit).first) == bucket_pos ); - us_val.push_back(ptype((*lit).first, (*lit).second)); - } - } - - sort(us_val.begin(), us_val.end()); - for (i = 0; i < NB_ELEMS; ++i) { - ptype p(i, i); - CPPUNIT_ASSERT( us_val[i * 2] == p ); - CPPUNIT_ASSERT( us_val[i * 2 + 1] == p ); - } -#endif -} - -void UnorderedTest::user_case() -{ -#if defined (STLPORT) - typedef unordered_map<int, string> UnorderedMap1; - typedef unordered_map<int, UnorderedMap1> UnorderedMap2; - - UnorderedMap1 foo; - UnorderedMap2 bar; - - foo.insert(UnorderedMap1::value_type(1, string("test1"))); - foo.insert(UnorderedMap1::value_type(2, string("test2"))); - foo.insert(UnorderedMap1::value_type(3, string("test3"))); - foo.insert(UnorderedMap1::value_type(4, string("test4"))); - foo.insert(UnorderedMap1::value_type(5, string("test5"))); - - bar.insert(UnorderedMap2::value_type(0, foo)); - UnorderedMap2::iterator it = bar.find(0); - CPPUNIT_ASSERT( it != bar.end() ); - - UnorderedMap1 &body = it->second; - UnorderedMap1::iterator cur = body.find(3); - CPPUNIT_ASSERT( cur != body.end() ); - - body.erase(body.begin(), body.end()); - CPPUNIT_ASSERT( body.empty() ); -#endif -} - -void UnorderedTest::hash_policy() -{ -#if defined (STLPORT) - unordered_set<int> int_uset; - - CPPUNIT_ASSERT( int_uset.max_load_factor() == 1.0f ); - CPPUNIT_ASSERT( int_uset.load_factor() == 0.0f ); - - size_t nbInserts = int_uset.bucket_count() - 1; - for (int i = 0; (size_t)i < nbInserts; ++i) { - int_uset.insert(i); - } - CPPUNIT_ASSERT( int_uset.size() == nbInserts ); - - int_uset.max_load_factor(0.5f); - int_uset.rehash(0); - CPPUNIT_ASSERT( int_uset.load_factor() < int_uset.max_load_factor() ); - - size_t bucketsHint = int_uset.bucket_count() + 1; - int_uset.rehash(bucketsHint); - CPPUNIT_ASSERT( int_uset.bucket_count() >= bucketsHint ); - - CPPUNIT_ASSERT( int_uset.key_eq()(10, 10) ); - CPPUNIT_ASSERT( int_uset.hash_function()(10) == 10 ); -#endif -} - -void UnorderedTest::buckets() -{ -#if defined (STLPORT) - unordered_set<int> int_uset; - - CPPUNIT_ASSERT( int_uset.bucket_count() < int_uset.max_bucket_count() ); - - int i; - size_t nbBuckets = int_uset.bucket_count(); - size_t nbInserts = int_uset.bucket_count() - 1; - for (i = 0; (size_t)i < nbInserts; ++i) { - int_uset.insert(i); - } - CPPUNIT_ASSERT( nbBuckets == int_uset.bucket_count() ); - - size_t bucketSizes = 0; - for (i = 0; (size_t)i < nbBuckets; ++i) { - bucketSizes += int_uset.bucket_size(i); - } - CPPUNIT_ASSERT( bucketSizes == int_uset.size() ); -#endif -} - -void UnorderedTest::equal_range() -{ -#if defined (STLPORT) - typedef unordered_multiset<size_t> umset; - { - //General test - umset iumset; - iumset.max_load_factor(10.0f); - - size_t nbBuckets = iumset.bucket_count(); - - for (size_t i = 0; i < nbBuckets; ++i) { - iumset.insert(i); - iumset.insert(i + nbBuckets); - iumset.insert(i + 2 * nbBuckets); - iumset.insert(i + 3 * nbBuckets); - iumset.insert(i + 4 * nbBuckets); - } - - CPPUNIT_ASSERT( nbBuckets == iumset.bucket_count() ); - CPPUNIT_ASSERT( iumset.size() == 5 * nbBuckets ); - - pair<umset::iterator, umset::iterator> p = iumset.equal_range(1); - CPPUNIT_ASSERT( p.first != p.second ); - - size_t nbElems = iumset.size(); - nbElems -= distance(p.first, p.second); - for (umset::iterator j = p.first; j != p.second;) { - iumset.erase(j++); - } - - CPPUNIT_ASSERT( nbElems == iumset.size() ); - - p = iumset.equal_range(2); - CPPUNIT_ASSERT( p.first != p.second ); - nbElems -= distance(p.first, p.second); - iumset.erase(p.first, p.second); - CPPUNIT_ASSERT( nbElems == iumset.size() ); - } - - { - //More specific test that tries to put many values in the same bucket - umset iumset; - - size_t i; - //We are going to add at least 20 values, to get a stable hash container while doing that - //we force a large number of buckets: - iumset.rehash(193); - - size_t nbBuckets = iumset.bucket_count(); - const size_t targetedBucket = nbBuckets / 2; - - //Lets put 10 values in the targeted bucket: - for (i = 0; i < 10; ++i) { - iumset.insert(targetedBucket + (i * nbBuckets)); - } - - //We put again 10 values in the targeted bucket and in reverse order: - for (i = 9; i <= 10; --i) { - iumset.insert(targetedBucket + (i * nbBuckets)); - } - - //Now we put some more elements until hash container is resized: - i = 0; - while (iumset.bucket_count() == nbBuckets) { - iumset.insert(i++); - } - - //CPPUNIT_ASSERT( iumset.bucket_size(targetedBucket) == 21 ); - - pair<umset::iterator, umset::iterator> p = iumset.equal_range(targetedBucket); - CPPUNIT_ASSERT( p.first != p.second ); - CPPUNIT_ASSERT( distance(p.first, p.second) == 3 ); - - // Now we remove some elements until hash container is resized: - nbBuckets = iumset.bucket_count(); - while (iumset.bucket_count() == nbBuckets && - !iumset.empty()) { - iumset.erase(iumset.begin()); - } - CPPUNIT_ASSERT( iumset.load_factor() <= iumset.max_load_factor() ); - - // Adding an element back shouldn't change number of buckets: - nbBuckets = iumset.bucket_count(); - iumset.insert(0); - CPPUNIT_ASSERT( iumset.bucket_count() == nbBuckets ); - } - - { - srand(0); - for (int runs = 0; runs < 2; ++runs) { - size_t magic = rand(); - umset hum; - size_t c = 0; - for (int i = 0; i < 10000; ++i) { - if ((rand() % 500) == 0) { - hum.insert(magic); - ++c; - } - else { - size_t r; - while ((r = rand()) == magic) - ; - hum.insert(r); - } - - /* - if ((float)(hum.size() + 1) / (float)hum.bucket_count() > hum.max_load_factor()) { - cout << "Hash container dump: Nb elems: " << hum.size() << ", Nb buckets: " << hum.bucket_count() << "\n"; - for (size_t b = 0; b < hum.bucket_count(); ++b) { - if (hum.bucket_size(b) != 0) { - umset::local_iterator litBegin(hum.begin(b)), litEnd(hum.end(b)); - cout << "B" << b << ": "; - for (umset::local_iterator lit = litBegin; lit != litEnd; ++lit) { - if (lit != litBegin) { - cout << " - "; - } - cout << *lit; - } - cout << "\n"; - } - } - cout << endl; - } - */ - } - CPPUNIT_ASSERT( hum.count(magic) == c ); - } - } -#endif -} - -void UnorderedTest::benchmark1() -{ -#if defined (STLPORT) - typedef unordered_multiset<size_t> umset; - - const size_t target = 500000; - umset iumset; - iumset.max_load_factor(10); - size_t i; - for (i = 0; i < target; ++i) { - iumset.insert(i); - } - - for (i = 0; i < target; ++i) { - iumset.erase(i); - } -#endif -} - -void UnorderedTest::benchmark2() -{ -#if defined (STLPORT) - typedef unordered_multiset<size_t> umset; - - const size_t target = 500000; - umset iumset; - iumset.max_load_factor(10); - size_t i; - for (i = 0; i < target; ++i) { - iumset.insert(target - i); - } - - for (i = 0; i < target; ++i) { - iumset.erase(target - i); - } -#endif -} - -struct Key -{ - Key() : m_data(0) {} - explicit Key(int data) : m_data(data) {} - - int m_data; - -#if defined (__DMC__) // slist<_Tp,_Alloc>::remove error - bool operator==(const Key&) const; -#endif -}; - -struct KeyHash -{ - size_t operator () (Key key) const - { return (size_t)key.m_data; } - - size_t operator () (int data) const - { return (size_t)data; } -}; - -struct KeyEqual -{ - bool operator () (Key lhs, Key rhs) const - { return lhs.m_data == rhs.m_data; } - - bool operator () (Key lhs, int rhs) const - { return lhs.m_data == rhs; } - - bool operator () (int lhs, Key rhs) const - { return lhs == rhs.m_data; } -}; - -struct KeyHashPtr -{ - size_t operator () (Key const volatile *key) const - { return (size_t)key->m_data; } - - size_t operator () (int data) const - { return (size_t)data; } -}; - -struct KeyEqualPtr -{ - bool operator () (Key const volatile *lhs, Key const volatile *rhs) const - { return lhs->m_data == rhs->m_data; } - - bool operator () (Key const volatile *lhs, int rhs) const - { return lhs->m_data == rhs; } - - bool operator () (int lhs, Key const volatile *rhs) const - { return lhs == rhs->m_data; } -}; - -void UnorderedTest::template_methods() -{ -#if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION) - { - typedef unordered_set<Key, KeyHash, KeyEqual> Container; - Container cont; - cont.insert(Key(1)); - cont.insert(Key(2)); - cont.insert(Key(3)); - cont.insert(Key(4)); - - CPPUNIT_ASSERT( cont.count(Key(1)) == 1 ); - CPPUNIT_ASSERT( cont.count(1) == 1 ); - CPPUNIT_ASSERT( cont.count(5) == 0 ); - - CPPUNIT_ASSERT( cont.find(2) != cont.end() ); - CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) ); - - Container const& ccont = cont; - CPPUNIT_ASSERT( ccont.find(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.bucket(2) == ccont.bucket(2) ); - CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) ); - } - - { - typedef unordered_set<Key*, KeyHashPtr, KeyEqualPtr> Container; - Container cont; - Key key1(1), key2(2), key3(3), key4(4); - cont.insert(&key1); - cont.insert(&key2); - cont.insert(&key3); - cont.insert(&key4); - - CPPUNIT_ASSERT( cont.count(1) == 1 ); - CPPUNIT_ASSERT( cont.count(5) == 0 ); - - CPPUNIT_ASSERT( cont.find(2) != cont.end() ); - CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) ); - - Container const& ccont = cont; - CPPUNIT_ASSERT( ccont.find(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.bucket(2) == ccont.bucket(2) ); - CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) ); - } - { - typedef unordered_multiset<Key, KeyHash, KeyEqual> Container; - Container cont; - cont.insert(Key(1)); - cont.insert(Key(2)); - cont.insert(Key(1)); - cont.insert(Key(2)); - - CPPUNIT_ASSERT( cont.count(Key(1)) == 2 ); - CPPUNIT_ASSERT( cont.count(1) == 2 ); - CPPUNIT_ASSERT( cont.count(5) == 0 ); - - CPPUNIT_ASSERT( cont.find(2) != cont.end() ); - CPPUNIT_ASSERT( cont.equal_range(1) != make_pair(cont.end(), cont.end()) ); - - Container const& ccont = cont; - CPPUNIT_ASSERT( ccont.find(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.bucket(2) == ccont.bucket(2) ); - CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) ); - } - - { - typedef unordered_multiset<Key const volatile*, KeyHashPtr, KeyEqualPtr> Container; - Container cont; - Key key1(1), key2(2), key3(3), key4(4); - cont.insert(&key1); - cont.insert(&key2); - cont.insert(&key3); - cont.insert(&key4); - - CPPUNIT_ASSERT( cont.count(1) == 1 ); - CPPUNIT_ASSERT( cont.count(5) == 0 ); - - CPPUNIT_ASSERT( cont.find(2) != cont.end() ); - CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) ); - - Container const& ccont = cont; - CPPUNIT_ASSERT( ccont.find(2) != ccont.end() ); - CPPUNIT_ASSERT( ccont.bucket(2) == ccont.bucket(2) ); - CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) ); - } -#endif -} - -#if defined (STLPORT) && \ - (!defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)) -# if !defined (__DMC__) -/* Simple compilation test: Check that nested types like iterator - * can be access even if type used to instanciate container is not - * yet completely defined. - */ -class IncompleteClass -{ - unordered_set<IncompleteClass> usinstances; - typedef unordered_set<IncompleteClass>::iterator usit; - unordered_multiset<IncompleteClass> usminstances; - typedef unordered_multiset<IncompleteClass>::iterator usmit; - - unordered_map<IncompleteClass, IncompleteClass> uminstances; - typedef unordered_map<IncompleteClass, IncompleteClass>::iterator umit; - unordered_multimap<IncompleteClass, IncompleteClass> umminstances; - typedef unordered_multimap<IncompleteClass, IncompleteClass>::iterator ummit; -}; -# endif -#endif diff --git a/test/unit/utility_header_test.cpp b/test/unit/utility_header_test.cpp deleted file mode 100644 index 78d67fb..0000000 --- a/test/unit/utility_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <utility> diff --git a/test/unit/valarray_header_test.cpp b/test/unit/valarray_header_test.cpp deleted file mode 100644 index f736264..0000000 --- a/test/unit/valarray_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <valarray> diff --git a/test/unit/valarray_test.cpp b/test/unit/valarray_test.cpp deleted file mode 100644 index 87ee3dc..0000000 --- a/test/unit/valarray_test.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include <valarray> - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class ValarrayTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(ValarrayTest); - CPPUNIT_TEST(transcendentals); - CPPUNIT_TEST_SUITE_END(); - -protected: - void transcendentals(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(ValarrayTest); - -// -// tests implementation -// -// For the moment this test is just a complitation test -// everyone is welcome to do a real good unit test for -// valarray functionality. -void ValarrayTest::transcendentals() -{ -#ifdef __SUNPRO_CC - using std::abs; -#endif - { - valarray<double> darray; - valarray<double> tmp; - tmp = abs(darray); - tmp = acos(darray); - tmp = asin(darray); - tmp = atan(darray); - tmp = atan2(darray, tmp); - tmp = atan2(1.0, darray); - tmp = atan2(darray, 1.0); - tmp = cos(darray); - tmp = cosh(darray); - tmp = sin(darray); - tmp = sinh(darray); - tmp = tan(darray); -#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) - tmp = tanh(darray); -#endif - tmp = exp(darray); - tmp = log(darray); - tmp = log10(darray); - tmp = pow(darray, tmp); - tmp = pow(1.0, darray); - tmp = pow(darray, 1.0); - tmp = sqrt(darray); - } - { - valarray<float> farray; - valarray<float> tmp; - tmp = abs(farray); - tmp = acos(farray); - tmp = asin(farray); - tmp = atan(farray); - tmp = atan2(farray, tmp); - tmp = atan2(1.0f, farray); - tmp = atan2(farray, 1.0f); - tmp = cos(farray); - tmp = cosh(farray); - tmp = sin(farray); - tmp = sinh(farray); - tmp = tan(farray); -#if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) - tmp = tanh(farray); -#endif - tmp = exp(farray); - tmp = log(farray); - tmp = log10(farray); - tmp = pow(farray, tmp); - tmp = pow(1.0f, farray); - tmp = pow(farray, 1.0f); - tmp = sqrt(farray); - } -#if !defined (STLPORT) || !defined (_STLP_NO_LONG_DOUBLE) - { - valarray<long double> ldarray; - valarray<long double> tmp; - tmp = abs(ldarray); - tmp = acos(ldarray); - tmp = asin(ldarray); - tmp = atan(ldarray); - tmp = atan2(ldarray, tmp); - tmp = atan2(1.0l, ldarray); - tmp = atan2(ldarray, 1.0l); - tmp = cos(ldarray); - tmp = cosh(ldarray); - tmp = sin(ldarray); - tmp = sinh(ldarray); - tmp = tan(ldarray); -# if !defined (STLPORT) || !defined (_STLP_USING_PLATFORM_SDK_COMPILER) || !defined (_M_AMD64) - tmp = tanh(ldarray); -# endif - tmp = exp(ldarray); - tmp = log(ldarray); - tmp = log10(ldarray); - tmp = pow(ldarray, tmp); - tmp = pow(1.0l, ldarray); - tmp = pow(ldarray, 1.0l); - tmp = sqrt(ldarray); - } -#endif - valarray<double> v0(2, 10); - valarray<double> v1(v0[slice(0, 1, 5)]); - v0[slice(0, 1, 5)] = 5; - valarray<double> v2(v0[gslice()]); - //valarray<double> v3(v0[valarray<bool>()]); - valarray<double> v4(v0[valarray<size_t>()]); -} diff --git a/test/unit/vector_header_test.cpp b/test/unit/vector_header_test.cpp deleted file mode 100644 index 69d2bfa..0000000 --- a/test/unit/vector_header_test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <vector> diff --git a/test/unit/vector_test.cpp b/test/unit/vector_test.cpp deleted file mode 100644 index a23ba1d..0000000 --- a/test/unit/vector_test.cpp +++ /dev/null @@ -1,553 +0,0 @@ -//Has to be first for StackAllocator swap overload to be taken -//into account (at least using GCC 4.0.1) -#include "stack_allocator.h" - -#include <vector> -#include <algorithm> -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) -# include <stdexcept> -#endif - -#include "cppunit/cppunit_proxy.h" - -#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) -using namespace std; -#endif - -// -// TestCase class -// -class VectorTest : public CPPUNIT_NS::TestCase -{ - CPPUNIT_TEST_SUITE(VectorTest); - CPPUNIT_TEST(vec_test_1); - CPPUNIT_TEST(vec_test_2); - CPPUNIT_TEST(vec_test_3); - CPPUNIT_TEST(vec_test_4); - CPPUNIT_TEST(vec_test_5); - CPPUNIT_TEST(vec_test_6); - CPPUNIT_TEST(vec_test_7); - CPPUNIT_TEST(capacity); - CPPUNIT_TEST(at); - CPPUNIT_TEST(pointer); - CPPUNIT_TEST(auto_ref); - CPPUNIT_TEST(allocator_with_state); - CPPUNIT_TEST(iterators); -#if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES) - CPPUNIT_IGNORE; -#endif - CPPUNIT_TEST(optimizations_check); - CPPUNIT_TEST(assign_check); - CPPUNIT_STOP_IGNORE; - CPPUNIT_TEST(ebo); - CPPUNIT_TEST_SUITE_END(); - -protected: - void vec_test_1(); - void vec_test_2(); - void vec_test_3(); - void vec_test_4(); - void vec_test_5(); - void vec_test_6(); - void vec_test_7(); - void capacity(); - void at(); - void pointer(); - void auto_ref(); - void allocator_with_state(); - void iterators(); - void optimizations_check(); - void assign_check(); - void ebo(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(VectorTest); - -// -// tests implementation -// -void VectorTest::vec_test_1() -{ - vector<int> v1; // Empty vector of integers. - - CPPUNIT_ASSERT( v1.empty() == true ); - CPPUNIT_ASSERT( v1.size() == 0 ); - - // CPPUNIT_ASSERT( v1.max_size() == INT_MAX / sizeof(int) ); - // cout << "max_size = " << v1.max_size() << endl; - v1.push_back(42); // Add an integer to the vector. - - CPPUNIT_ASSERT( v1.size() == 1 ); - - CPPUNIT_ASSERT( v1[0] == 42 ); - - { - vector<vector<int> > vect(10); - vector<vector<int> >::iterator it(vect.begin()), end(vect.end()); - for (; it != end; ++it) { - CPPUNIT_ASSERT( (*it).empty() ); - CPPUNIT_ASSERT( (*it).size() == 0 ); - CPPUNIT_ASSERT( (*it).capacity() == 0 ); - CPPUNIT_ASSERT( (*it).begin() == (*it).end() ); - } - } -} - -void VectorTest::vec_test_2() -{ - vector<double> v1; // Empty vector of doubles. - v1.push_back(32.1); - v1.push_back(40.5); - vector<double> v2; // Another empty vector of doubles. - v2.push_back(3.56); - - CPPUNIT_ASSERT( v1.size() == 2 ); - CPPUNIT_ASSERT( v1[0] == 32.1 ); - CPPUNIT_ASSERT( v1[1] == 40.5 ); - - CPPUNIT_ASSERT( v2.size() == 1 ); - CPPUNIT_ASSERT( v2[0] == 3.56 ); - size_t v1Cap = v1.capacity(); - size_t v2Cap = v2.capacity(); - - v1.swap(v2); // Swap the vector's contents. - - CPPUNIT_ASSERT( v1.size() == 1 ); - CPPUNIT_ASSERT( v1.capacity() == v2Cap ); - CPPUNIT_ASSERT( v1[0] == 3.56 ); - - CPPUNIT_ASSERT( v2.size() == 2 ); - CPPUNIT_ASSERT( v2.capacity() == v1Cap ); - CPPUNIT_ASSERT( v2[0] == 32.1 ); - CPPUNIT_ASSERT( v2[1] == 40.5 ); - - v2 = v1; // Assign one vector to another. - - CPPUNIT_ASSERT( v2.size() == 1 ); - CPPUNIT_ASSERT( v2[0] == 3.56 ); -} - -void VectorTest::vec_test_3() -{ - typedef vector<char> vec_type; - - vec_type v1; // Empty vector of characters. - v1.push_back('h'); - v1.push_back('i'); - - CPPUNIT_ASSERT( v1.size() == 2 ); - CPPUNIT_ASSERT( v1[0] == 'h' ); - CPPUNIT_ASSERT( v1[1] == 'i' ); - - vec_type v2(v1.begin(), v1.end()); - v2[1] = 'o'; // Replace second character. - - CPPUNIT_ASSERT( v2.size() == 2 ); - CPPUNIT_ASSERT( v2[0] == 'h' ); - CPPUNIT_ASSERT( v2[1] == 'o' ); - - CPPUNIT_ASSERT( (v1 == v2) == false ); - - CPPUNIT_ASSERT( (v1 < v2) == true ); -} - -void VectorTest::vec_test_4() -{ - vector<int> v(4); - - v[0] = 1; - v[1] = 4; - v[2] = 9; - v[3] = 16; - - CPPUNIT_ASSERT( v.front() == 1 ); - CPPUNIT_ASSERT( v.back() == 16 ); - - v.push_back(25); - - CPPUNIT_ASSERT( v.back() == 25 ); - CPPUNIT_ASSERT( v.size() == 5 ); - - v.pop_back(); - - CPPUNIT_ASSERT( v.back() == 16 ); - CPPUNIT_ASSERT( v.size() == 4 ); -} - -void VectorTest::vec_test_5() -{ - int array [] = { 1, 4, 9, 16 }; - - vector<int> v(array, array + 4); - - CPPUNIT_ASSERT( v.size() == 4 ); - - CPPUNIT_ASSERT( v[0] == 1 ); - CPPUNIT_ASSERT( v[1] == 4 ); - CPPUNIT_ASSERT( v[2] == 9 ); - CPPUNIT_ASSERT( v[3] == 16 ); -} - -void VectorTest::vec_test_6() -{ - int array [] = { 1, 4, 9, 16, 25, 36 }; - - vector<int> v(array, array + 6); - vector<int>::iterator vit; - - CPPUNIT_ASSERT( v.size() == 6 ); - CPPUNIT_ASSERT( v[0] == 1 ); - CPPUNIT_ASSERT( v[1] == 4 ); - CPPUNIT_ASSERT( v[2] == 9 ); - CPPUNIT_ASSERT( v[3] == 16 ); - CPPUNIT_ASSERT( v[4] == 25 ); - CPPUNIT_ASSERT( v[5] == 36 ); - - vit = v.erase( v.begin() ); // Erase first element. - CPPUNIT_ASSERT( *vit == 4 ); - - CPPUNIT_ASSERT( v.size() == 5 ); - CPPUNIT_ASSERT( v[0] == 4 ); - CPPUNIT_ASSERT( v[1] == 9 ); - CPPUNIT_ASSERT( v[2] == 16 ); - CPPUNIT_ASSERT( v[3] == 25 ); - CPPUNIT_ASSERT( v[4] == 36 ); - - vit = v.erase(v.end() - 1); // Erase last element. - CPPUNIT_ASSERT( vit == v.end() ); - - CPPUNIT_ASSERT( v.size() == 4 ); - CPPUNIT_ASSERT( v[0] == 4 ); - CPPUNIT_ASSERT( v[1] == 9 ); - CPPUNIT_ASSERT( v[2] == 16 ); - CPPUNIT_ASSERT( v[3] == 25 ); - - - v.erase(v.begin() + 1, v.end() - 1); // Erase all but first and last. - - CPPUNIT_ASSERT( v.size() == 2 ); - CPPUNIT_ASSERT( v[0] == 4 ); - CPPUNIT_ASSERT( v[1] == 25 ); - -} - -void VectorTest::vec_test_7() -{ - int array1 [] = { 1, 4, 25 }; - int array2 [] = { 9, 16 }; - - vector<int> v(array1, array1 + 3); - vector<int>::iterator vit; - vit = v.insert(v.begin(), 0); // Insert before first element. - CPPUNIT_ASSERT( *vit == 0 ); - - vit = v.insert(v.end(), 36); // Insert after last element. - CPPUNIT_ASSERT( *vit == 36 ); - - CPPUNIT_ASSERT( v.size() == 5 ); - CPPUNIT_ASSERT( v[0] == 0 ); - CPPUNIT_ASSERT( v[1] == 1 ); - CPPUNIT_ASSERT( v[2] == 4 ); - CPPUNIT_ASSERT( v[3] == 25 ); - CPPUNIT_ASSERT( v[4] == 36 ); - - // Insert contents of array2 before fourth element. - v.insert(v.begin() + 3, array2, array2 + 2); - - CPPUNIT_ASSERT( v.size() == 7 ); - - CPPUNIT_ASSERT( v[0] == 0 ); - CPPUNIT_ASSERT( v[1] == 1 ); - CPPUNIT_ASSERT( v[2] == 4 ); - CPPUNIT_ASSERT( v[3] == 9 ); - CPPUNIT_ASSERT( v[4] == 16 ); - CPPUNIT_ASSERT( v[5] == 25 ); - CPPUNIT_ASSERT( v[6] == 36 ); - - v.clear(); - CPPUNIT_ASSERT( v.empty() ); - - v.insert(v.begin(), 5, 10); - CPPUNIT_ASSERT( v.size() == 5 ); - CPPUNIT_ASSERT( v[0] == 10 ); - CPPUNIT_ASSERT( v[1] == 10 ); - CPPUNIT_ASSERT( v[2] == 10 ); - CPPUNIT_ASSERT( v[3] == 10 ); - CPPUNIT_ASSERT( v[4] == 10 ); - - /* - { - vector<float> vf(2.0f, 3.0f); - CPPUNIT_ASSERT( vf.size() == 2 ); - CPPUNIT_ASSERT( vf.front() == 3.0f ); - CPPUNIT_ASSERT( vf.back() == 3.0f ); - } - */ -} - -struct TestStruct -{ - unsigned int a[3]; -}; - -void VectorTest::capacity() -{ - { - vector<int> v; - - CPPUNIT_ASSERT( v.capacity() == 0 ); - v.push_back(42); - CPPUNIT_ASSERT( v.capacity() >= 1 ); - v.reserve(5000); - CPPUNIT_ASSERT( v.capacity() >= 5000 ); - } - - { - //Test that used to generate an assertion when using __debug_alloc. - vector<TestStruct> va; - va.reserve(1); - va.reserve(2); - } -} - -void VectorTest::at() { - vector<int> v; - vector<int> const& cv = v; - - v.push_back(10); - CPPUNIT_ASSERT( v.at(0) == 10 ); - v.at(0) = 20; - CPPUNIT_ASSERT( cv.at(0) == 20 ); - -#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) - try { - v.at(1) = 20; - CPPUNIT_FAIL; - } - catch (out_of_range const&) { - } - catch (...) { - CPPUNIT_FAIL; - } -#endif -} - -void VectorTest::pointer() -{ - vector<int *> v1; - vector<int *> v2 = v1; - vector<int *> v3; - - v3.insert( v3.end(), v1.begin(), v1.end() ); -} - -void VectorTest::auto_ref() -{ - vector<int> ref; - for (int i = 0; i < 5; ++i) { - ref.push_back(i); - } - - vector<vector<int> > v_v_int(1, ref); - v_v_int.push_back(v_v_int[0]); - v_v_int.push_back(ref); - v_v_int.push_back(v_v_int[0]); - v_v_int.push_back(v_v_int[0]); - v_v_int.push_back(ref); - - vector<vector<int> >::iterator vvit(v_v_int.begin()), vvitEnd(v_v_int.end()); - for (; vvit != vvitEnd; ++vvit) { - CPPUNIT_ASSERT( *vvit == ref ); - } - - /* - * Forbidden by the Standard: - v_v_int.insert(v_v_int.end(), v_v_int.begin(), v_v_int.end()); - for (vvit = v_v_int.begin(), vvitEnd = v_v_int.end(); - vvit != vvitEnd; ++vvit) { - CPPUNIT_ASSERT( *vvit == ref ); - } - */ -} - -void VectorTest::allocator_with_state() - { - char buf1[1024]; - StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1)); - - char buf2[1024]; - StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2)); - - { - typedef vector<int, StackAllocator<int> > VectorInt; - VectorInt vint1(10, 0, stack1); - VectorInt vint1Cpy(vint1); - - VectorInt vint2(10, 1, stack2); - VectorInt vint2Cpy(vint2); - - vint1.swap(vint2); - - CPPUNIT_ASSERT( vint1.get_allocator().swaped() ); - CPPUNIT_ASSERT( vint2.get_allocator().swaped() ); - - CPPUNIT_ASSERT( vint1 == vint2Cpy ); - CPPUNIT_ASSERT( vint2 == vint1Cpy ); - CPPUNIT_ASSERT( vint1.get_allocator() == stack2 ); - CPPUNIT_ASSERT( vint2.get_allocator() == stack1 ); - } - CPPUNIT_ASSERT( stack1.ok() ); - CPPUNIT_ASSERT( stack2.ok() ); - } - -struct Point { - int x, y; -}; - -struct PointEx : public Point { - PointEx() : builtFromBase(false) {} - PointEx(const Point&) : builtFromBase(true) {} - - bool builtFromBase; -}; - -#if defined (STLPORT) -# if defined (_STLP_USE_NAMESPACES) -namespace std { -# endif - _STLP_TEMPLATE_NULL - struct __type_traits<PointEx> { - typedef __false_type has_trivial_default_constructor; - typedef __true_type has_trivial_copy_constructor; - typedef __true_type has_trivial_assignment_operator; - typedef __true_type has_trivial_destructor; - typedef __true_type is_POD_type; - }; -# if defined (_STLP_USE_NAMESPACES) -} -# endif -#endif - -//This test check that vector implementation do not over optimize -//operation as PointEx copy constructor is trivial -void VectorTest::optimizations_check() -{ -#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) - vector<Point> v1(1); - CPPUNIT_ASSERT( v1.size() == 1 ); - - vector<PointEx> v2(v1.begin(), v1.end()); - CPPUNIT_ASSERT( v2.size() == 1 ); - CPPUNIT_ASSERT( v2[0].builtFromBase == true ); -#endif -} - -void VectorTest::assign_check() -{ -#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) - vector<int> v(3,1); - int array[] = { 1, 2, 3, 4, 5 }; - - v.assign( array, array + 5 ); - CPPUNIT_CHECK( v[4] == 5 ); - CPPUNIT_CHECK( v[0] == 1 ); - CPPUNIT_CHECK( v[1] == 2 ); -#endif -} - -void VectorTest::iterators() -{ - vector<int> vint(10, 0); - vector<int> const& crvint = vint; - - CPPUNIT_ASSERT( vint.begin() == vint.begin() ); - CPPUNIT_ASSERT( crvint.begin() == vint.begin() ); - CPPUNIT_ASSERT( vint.begin() == crvint.begin() ); - CPPUNIT_ASSERT( crvint.begin() == crvint.begin() ); - - CPPUNIT_ASSERT( vint.begin() != vint.end() ); - CPPUNIT_ASSERT( crvint.begin() != vint.end() ); - CPPUNIT_ASSERT( vint.begin() != crvint.end() ); - CPPUNIT_ASSERT( crvint.begin() != crvint.end() ); - - CPPUNIT_ASSERT( vint.rbegin() == vint.rbegin() ); - // Not Standard: - //CPPUNIT_ASSERT( vint.rbegin() == crvint.rbegin() ); - //CPPUNIT_ASSERT( crvint.rbegin() == vint.rbegin() ); - CPPUNIT_ASSERT( crvint.rbegin() == crvint.rbegin() ); - - CPPUNIT_ASSERT( vint.rbegin() != vint.rend() ); - // Not Standard: - //CPPUNIT_ASSERT( vint.rbegin() != crvint.rend() ); - //CPPUNIT_ASSERT( crvint.rbegin() != vint.rend() ); - CPPUNIT_ASSERT( crvint.rbegin() != crvint.rend() ); -} - - -#if !defined (STLPORT) || \ - !defined (_STLP_USE_PTR_SPECIALIZATIONS) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) -/* Simple compilation test: Check that nested types like iterator - * can be access even if type used to instanciate container is not - * yet completely defined. - */ -class IncompleteClass -{ - vector<IncompleteClass> instances; - typedef vector<IncompleteClass>::iterator it; -}; -#endif - -#if defined (STLPORT) -# define NOTHROW _STLP_NOTHROW -#else -# define NOTHROW throw() -#endif - -/* This allocator implementation purpose is simply to break some - * internal STLport mecanism specific to the STLport own allocator - * implementation. */ -template <class _Tp> -struct NotSTLportAllocator : public allocator<_Tp> { -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATE_CLASSES) - template <class _Tp1> struct rebind { - typedef NotSTLportAllocator<_Tp1> other; - }; -#endif - NotSTLportAllocator() NOTHROW {} -#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES) - template <class _Tp1> NotSTLportAllocator(const NotSTLportAllocator<_Tp1>&) NOTHROW {} -#endif - NotSTLportAllocator(const NotSTLportAllocator<_Tp>&) NOTHROW {} - ~NotSTLportAllocator() NOTHROW {} -}; - -/* This test check a potential issue with empty base class - * optimization. Some compilers (VC6) do not implement it - * correctly resulting ina wrong behavior. */ -void VectorTest::ebo() -{ - // We use heap memory as test failure can corrupt vector internal - // representation making executable crash on vector destructor invocation. - // We prefer a simple memory leak, internal corruption should be reveal - // by size or capacity checks. - typedef vector<int, NotSTLportAllocator<int> > V; - V *pv1 = new V(1, 1); - V *pv2 = new V(10, 2); - - size_t v1Capacity = pv1->capacity(); - size_t v2Capacity = pv2->capacity(); - - pv1->swap(*pv2); - - CPPUNIT_ASSERT( pv1->size() == 10 ); - CPPUNIT_ASSERT( pv1->capacity() == v2Capacity ); - CPPUNIT_ASSERT( (*pv1)[5] == 2 ); - - CPPUNIT_ASSERT( pv2->size() == 1 ); - CPPUNIT_ASSERT( pv2->capacity() == v1Capacity ); - CPPUNIT_ASSERT( (*pv2)[0] == 1 ); - - delete pv2; - delete pv1; -} - diff --git a/test/unit/wchar_header_test.c b/test/unit/wchar_header_test.c deleted file mode 100644 index 36376fe..0000000 --- a/test/unit/wchar_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <wchar.h> diff --git a/test/unit/wctype_header_test.c b/test/unit/wctype_header_test.c deleted file mode 100644 index 639878c..0000000 --- a/test/unit/wctype_header_test.c +++ /dev/null @@ -1,8 +0,0 @@ -/* This test purpose is simply to check Standard header independancy that - * is to say that the header can be included alone without any previous - * include. - * Additionnaly, for C Standard headers that STLport expose, it can also be - * used to check that files included by those headers are compatible with - * pure C compilers. - */ -#include <wctype.h> |