first commit

This commit is contained in:
Jose Caban
2025-06-07 11:34:38 -04:00
commit 0eb2d7c07d
4708 changed files with 1500614 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
#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);
}

View File

@@ -0,0 +1,50 @@
#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_;
}

View File

@@ -0,0 +1,135 @@
#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_;
}

View File

@@ -0,0 +1,38 @@
#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);
}

View File

@@ -0,0 +1,364 @@
#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" );
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,168 @@
#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

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,55 @@
#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
}

View File

@@ -0,0 +1,149 @@
#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 &param1, const int &param2) {
return param1 + param2;
}
int test_func2 (int &param1, 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
}

View File

@@ -0,0 +1,54 @@
#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]));
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,110 @@
#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
}

View File

@@ -0,0 +1,48 @@
#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);
}

View File

@@ -0,0 +1,49 @@
#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

View File

@@ -0,0 +1,80 @@
#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);
}

View File

@@ -0,0 +1,49 @@
#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;
}

View File

@@ -0,0 +1,71 @@
#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
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,170 @@
#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
}

View File

@@ -0,0 +1,654 @@
#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

View File

@@ -0,0 +1,279 @@
#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<EFBFBD>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<EFBFBD>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<61>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 '<27>' char here because doing so would make test result
// dependant on char being consider as signed or not...
string strs[] = {"abdd", /* "ab<61>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

View File

@@ -0,0 +1,19 @@
#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

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,121 @@
#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
}

View File

@@ -0,0 +1,129 @@
#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]);
}

View File

@@ -0,0 +1,73 @@
#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;
}

View File

@@ -0,0 +1,225 @@
/*
* 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

View File

@@ -0,0 +1,31 @@
/*
* 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

View File

@@ -0,0 +1,101 @@
/*
* 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

View File

@@ -0,0 +1,145 @@
/*
* 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_*/

View File

@@ -0,0 +1,140 @@
/*
* 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

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,13 @@
/* 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

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,75 @@
#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
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,520 @@
#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), '<EFBFBD>') );
}
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

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,330 @@
//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

View File

@@ -0,0 +1,33 @@
#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);
}

View File

@@ -0,0 +1,10 @@
#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

View File

@@ -0,0 +1,178 @@
#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_);
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,193 @@
#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

View File

@@ -0,0 +1,80 @@
#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

21
extern/STLport/5.2.1/test/unit/fib.h vendored Normal file
View File

@@ -0,0 +1,21 @@
#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

View File

@@ -0,0 +1,61 @@
#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);
}

View File

@@ -0,0 +1,135 @@
#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 );
}

View File

@@ -0,0 +1,58 @@
#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]);
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,73 @@
#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);
}

View File

@@ -0,0 +1,10 @@
/* 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

View File

@@ -0,0 +1,915 @@
#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

View File

@@ -0,0 +1,46 @@
#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

View File

@@ -0,0 +1,76 @@
#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 );
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,92 @@
#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);
}

View File

@@ -0,0 +1,49 @@
#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);
}

View File

@@ -0,0 +1,434 @@
//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

View File

@@ -0,0 +1,108 @@
#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);
}

View File

@@ -0,0 +1,87 @@
#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);
}

View File

@@ -0,0 +1,72 @@
#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);
}

View File

@@ -0,0 +1,61 @@
#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);
}

View File

@@ -0,0 +1,70 @@
#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") );
}

View File

@@ -0,0 +1,110 @@
#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

View File

@@ -0,0 +1,10 @@
/* 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

View File

@@ -0,0 +1,10 @@
/* 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

View File

@@ -0,0 +1,10 @@
/* 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

View File

@@ -0,0 +1,10 @@
/* 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

View File

@@ -0,0 +1,116 @@
#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

18
extern/STLport/5.2.1/test/unit/iota.h vendored Normal file
View File

@@ -0,0 +1,18 @@
#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

View File

@@ -0,0 +1,47 @@
#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
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,159 @@
#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
}

View File

@@ -0,0 +1,10 @@
/* 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

View File

@@ -0,0 +1,169 @@
#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
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,50 @@
#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);
}

View File

@@ -0,0 +1,48 @@
#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);
}

View File

@@ -0,0 +1,8 @@
/* 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>

View File

@@ -0,0 +1,317 @@
/* 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
}

View File

@@ -0,0 +1,8 @@
/* 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>

Some files were not shown because too many files have changed in this diff Show More