cpp11 branch - committing the merge (rest of it)

git-svn-id: svn://ultimatepp.org/upp/trunk@7048 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-03-16 16:35:29 +00:00
parent 51687976c2
commit e5dfeba4be
58 changed files with 1176 additions and 2335 deletions

View file

@ -0,0 +1,107 @@
#include <Core/Core.h>
using namespace Upp;
template <class T>
void CompareArray()
{
T a;
a.Add(1);
a.Add(2);
T b = clone(a);
ASSERT(a == b);
b.At(1) = 3;
ASSERT(a != b);
ASSERT(b > a);
b = clone(a);
b.Add(10);
ASSERT(a != b);
ASSERT(b > a);
}
template <class T>
void CompareBiArray()
{
T a;
a.AddTail(1);
a.AddTail(2);
T b = clone(a);
ASSERT(a == b);
b[1] = 3;
ASSERT(a != b);
ASSERT(b > a);
b = clone(a);
b.AddTail(10);
ASSERT(a != b);
ASSERT(b > a);
}
template <class T>
void CompareIndex()
{
T a;
a.Add(1);
a.Add(2);
T b = clone(a);
ASSERT(a == b);
b.Add(3);
ASSERT(a != b);
ASSERT(b > a);
b.Clear();
b.Add(1);
b.Add(3);
ASSERT(a != b);
ASSERT(b > a);
}
template <class T>
void CompareMap()
{
T a;
a.Add(1, 2);
a.Add(3, 4);
T b = clone(a);
ASSERT(a == b);
b.Add(4, 4);
ASSERT(a != b);
ASSERT(b > a);
b.Clear();
b.Add(2, 2);
b.Add(3, 4);
ASSERT(b > a);
b.Clear();
b.Add(1, 2);
b.Add(3, 5);
ASSERT(b > a);
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
CompareArray< Vector<int> >();
CompareArray< Array<int> >();
CompareArray< InVector<int> >();
CompareArray< InArray<int> >();
CompareBiArray< BiVector<int> >();
CompareBiArray< BiArray<int> >();
CompareIndex< Index<int> >();
CompareIndex< ArrayIndex<int> >();
CompareIndex< SortedIndex<int> >();
CompareMap<VectorMap<int, int> >();
CompareMap<ArrayMap<int, int> >();
CompareMap<SortedVectorMap<int, int> >();
CompareMap<SortedArrayMap<int, int> >();
LOG("===== OK");
}

View file

@ -0,0 +1,11 @@
description "Comparison for containers\377";
uses
Core;
file
CompareContainer.cpp;
mainconfig
"" = "SSE2";

View file

@ -0,0 +1,4 @@
#ifndef _CompareContainer_icpp_init_stub
#define _CompareContainer_icpp_init_stub
#include "Core/init"
#endif

183
upptst/Core11/Core11.cpp Normal file
View file

@ -0,0 +1,183 @@
#include <Core/Core.h>
using namespace Upp;
template <class T>
void TestTransfer()
{
T a, b;
a = pick(b);
ASSERT(b.IsPicked());
ASSERT(!a.IsPicked());
b = clone(a);
ASSERT(!b.IsPicked());
ASSERT(!a.IsPicked());
T c = pick(b);
T d = clone(c);
Swap(c, d);
}
template <class T>
void TestTransfers()
{
TestTransfer< Vector<T> >();
TestTransfer< Array<T> >();
TestTransfer< Index<T> >();
TestTransfer< ArrayIndex<T> >();
TestTransfer< VectorMap<int, T> >();
TestTransfer< ArrayMap<int, T> >();
TestTransfer< FixedVectorMap<int, T> >();
TestTransfer< FixedArrayMap<int, T> >();
TestTransfer< InVector<T> >();
TestTransfer< InArray<T> >();
TestTransfer< SortedIndex<int> >();
TestTransfer< SortedVectorMap<int, T> >();
TestTransfer< SortedArrayMap<int, T> >();
}
template <class InMap, class Val>
void TestInMap()
{
InMap m;
m.Add(1, "hello");
ASSERT(m.GetCount() == 1);
ASSERT(m[0] == "hello");
ASSERT(m.Get(1) == "hello");
m.Add(2, "world");
ASSERT(m.GetCount() == 2);
ASSERT(m[0] == "hello");
ASSERT(m[1] == "world");
ASSERT(m.Get(1) == "hello");
ASSERT(m.Get(2) == "world");
ASSERT(m.FindAdd(1) == 0);
ASSERT(m.FindAdd(2) == 1);
ASSERT(m.FindAdd(3) == 2);
ASSERT(m.FindAdd(0) == 0);
ASSERT(m.FindAdd(4, "four") == 4);
ASSERT(m.GetCount() == 5);
ASSERT(m[4] == "four");
ASSERT(m.GetAdd(3) == "");
ASSERT(m.GetAdd(2) == "world");
ASSERT(m.GetAdd(5) == "");
ASSERT(m.GetCount() == 6);
m.GetAdd(6) = "six";
ASSERT(m.GetCount() == 7);
ASSERT(m.Get(6) == "six");
m.GetAdd(7, "seven");
ASSERT(m[7] == "seven");
ASSERT(m.Get(7) == "seven");
ASSERT(m.Get(8, "no") == "no");
ASSERT(m.FindPtr(99) == NULL);
ASSERT(*m.FindPtr(7) == "seven");
m.Shrink();
InMap h;
h.Add(1, "1");
ASSERT(h.GetCount() == 1);
h.Clear();
ASSERT(h.GetCount() == 0);
const Val& vv = m.GetValues();
ASSERT(vv.GetCount() == vv.GetCount());
ASSERT(vv[7] == "seven");
InMap mm = pick(m);
ASSERT(m.IsPicked());
ASSERT(!mm.IsPicked());
m = clone(mm);
ASSERT(!m.IsPicked());
ASSERT(!mm.IsPicked());
mm = pick(m);
m = pick(mm);
mm.Clear();
mm.Swap(m);
m.Swap(mm);
ASSERT(mm.IsEmpty());
ASSERT(mm.GetCount() == 0);
ASSERT(!m.IsPicked());
ASSERT(!mm.IsPicked());
ASSERT(m.FindLowerBound(6) == 6);
ASSERT(m.FindUpperBound(6) == 7);
ASSERT(m.Find(6) == 6);
m.Add(6, "another six");
ASSERT(m.GetCount() == 9);
ASSERT(m.FindNext(6) == 7);
ASSERT(m.FindLast(6) == 7);
ASSERT(m.FindPrev(7) == 6);
ASSERT(m.GetKey(7) == 6);
m.Remove(0);
ASSERT(m.GetCount() == 8);
m.RemoveKey(6);
ASSERT(m.GetCount() == 6);
m.Remove(1, 2);
ASSERT(m.GetCount() == 4);
}
struct HasClone : MoveableAndDeepCopyOption<HasClone> {
Vector<int> a;
#ifdef CPP_11
HasClone(HasClone rval_ x) = default;
HasClone& operator=(HasClone rval_ x) = default;
#endif
HasClone(const HasClone& x, int) : a(x.a, 0) {}
HasClone() {}
};
struct NoClone : Moveable<NoClone> {
Vector<int> a;
};
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
TestTransfers<int>();
TestTransfers<String>();
TestTransfers<HasClone>();
TestInMap< SortedVectorMap<int, String>, InVector<String> >();
TestInMap< SortedArrayMap<int, String>, InArray<String> >();
SortedArrayMap<int, NoClone> x;
x.Create<NoClone>(1).a.Add(1);
{
SortedVectorMap<int, NoClone> mm;
mm.GetAdd(1).a.Add(12);
mm.GetAdd(1).a.Add(13);
}
{
SortedVectorMap<int, HasClone> mm;
mm.GetAdd(1).a.Add(12);
mm.GetAdd(1).a.Add(13);
}
LOG("=========== OK");
}

11
upptst/Core11/Core11.upp Normal file
View file

@ -0,0 +1,11 @@
description "Core tests for C+11\377";
uses
Core;
file
Core11.cpp;
mainconfig
"" = "SSE2";

4
upptst/Core11/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _Core11_icpp_init_stub
#define _Core11_icpp_init_stub
#include "Core/init"
#endif

View file

@ -0,0 +1,88 @@
#include <Core/Core.h>
using namespace Upp;
template <class T>
void ArrayTest()
{
T array;
array.Add(1);
array.Add(2);
array.Add(3);
DUMP(array);
}
template <class T>
void BiArrayTest()
{
T array;
array.AddTail(1);
array.AddTail(2);
array.AddTail(3);
DUMP(array);
}
template <class T>
void MapTest()
{
T map;
map.Add(1, "one");
map.Add(2, "two");
map.Add(3, "three");
DUMP(map);
map.Unlink(1);
DUMP(map);
}
template <class T>
void SortedMapTest()
{
T map;
map.Add(1, "one");
map.Add(2, "two");
map.Add(3, "three");
DUMP(map);
}
template <class T>
void FixedMapTest()
{
T map;
map.Add(1, "one");
map.Add(2, "two");
map.Add(3, "three");
map.Finish();
DUMP(map);
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
ArrayTest< Vector<int> > ();
ArrayTest< Array<int> > ();
ArrayTest< InVector<int> > ();
ArrayTest< InArray<int> > ();
ArrayTest< Index<int> > ();
ArrayTest< ArrayIndex<int> > ();
ArrayTest< SortedIndex<int> > ();
BiArrayTest< BiVector<int> > ();
BiArrayTest< BiArray<int> > ();
MapTest< VectorMap<int, String> >();
MapTest< ArrayMap<int, String> >();
SortedMapTest< SortedVectorMap<int, String> >();
SortedMapTest< SortedArrayMap<int, String> >();
FixedMapTest< FixedVectorMap<int, String> >();
FixedMapTest< FixedArrayMap<int, String> >();
One<int> x;
DUMP(x);
x.Create() = 1;
DUMP(x);
LOG("======== OK");
}

View file

@ -0,0 +1,9 @@
uses
Core;
file
NTLAsString.cpp;
mainconfig
"" = "SSE2";

4
upptst/NTLAsString/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _NTLAsString_icpp_init_stub
#define _NTLAsString_icpp_init_stub
#include "Core/init"
#endif

View file

@ -149,6 +149,10 @@ void Test(T& map)
}
}
struct Foo : Moveable<Foo> {
Vector<int> a;
};
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
@ -208,4 +212,10 @@ CONSOLE_APP_MAIN
RDUMP(sizeof(InArray<int>));
RDUMP(sizeof(SortedIndex<int>));
RDUMP(sizeof(SortedVectorMap<int, int>));
{ // Test that this compiles
SortedVectorMap<int, Foo> mm;
Foo& x = mm.Add(1);
x.a.Add(12);
}
}

View file

@ -0,0 +1,99 @@
#include <Core/Core.h>
using namespace Upp;
template <class T>
void TestCompareT(T a, T b)
{
LOG("==== TestCompare(" << a << " " << b << "): " << a.Compare(b));
ASSERT(sgn(a.Compare(b)) == -1);
ASSERT(sgn(b.Compare(a)) == 1);
ASSERT(a.Compare(a) == 0);
ASSERT(b.Compare(b) == 0);
ASSERT(a > Null);
ASSERT(b > Null);
ASSERT(a < b);
ASSERT(a <= a);
ASSERT(b <= b);
ASSERT(a <= b);
ASSERT(b > a);
ASSERT(b >= a);
ASSERT(a >= a);
ASSERT(b >= b);
ASSERT(a != b);
ASSERT(a == a);
ASSERT(b == b);
}
void TestCompare(Value a, Value b)
{
TestCompareT<Value>(a, b);
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
TestCompare("ahoj", "ahoj1");
TestCompare(WString("ahoj"), WString("ahoj1"));
TestCompare(1, 2);
TestCompare(1.1, 1.2);
TestCompare(false, true);
TestCompare((int64)1, (int64)2);
TestCompare(GetSysTime(), GetSysTime() + 1);
TestCompare(GetSysDate(), GetSysDate() + 1);
ValueArray va1; va1 << 1 << 2 << 3;
ValueArray va2; va2 << 1 << 2 << 4;
TestCompareT(va1, va2);
TestCompare(va1, va2);
va2 = va1;
va2 << 0;
TestCompareT(va1, va2);
TestCompare(va1, va2);
ValueMap m1; m1("a", 1)("b", 2);
ValueMap m2; m2("a", 1)("c", 2);
TestCompareT(m1, m2);
Value a = m1;
Value b = m2;
a.Compare(b);
TestCompare(m1, m2);
m2 = m1;
m2("b", 2);
TestCompareT(m1, m2);
TestCompare(m1, m2);
TestCompare((bool)false, 123);
TestCompare((bool)false, (int64)123);
TestCompare((bool)false, (double)123);
TestCompare((bool)false, (bool)true);
TestCompare(12, 123);
TestCompare(12, (int64)123);
TestCompare(12, (double)123);
TestCompare(0, (bool)true);
TestCompare((int64)12, 123);
TestCompare((int64)12, (int64)123);
TestCompare((int64)12, (double)123);
TestCompare((int64)0, (bool)true);
TestCompare((double)12, 123);
TestCompare((double)12, (int64)123);
TestCompare((double)12, (double)123);
TestCompare((double)0, (bool)true);
LOG("===== Everything is OK");
}

View file

@ -0,0 +1,11 @@
description "Test of Value::Compare\377";
uses
Core;
file
ValueCompare.cpp;
mainconfig
"" = "SSE2";

4
upptst/ValueCompare/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _ValueCompare_icpp_init_stub
#define _ValueCompare_icpp_init_stub
#include "Core/init"
#endif