Creating the *real* autotest nest

git-svn-id: svn://ultimatepp.org/upp/trunk@7141 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-04-02 18:36:01 +00:00
parent dc9a464a45
commit 6d3aa8ba61
230 changed files with 9963 additions and 73 deletions

View file

@ -0,0 +1,51 @@
#include <Core/Core.h>
using namespace Upp;
#ifdef flagAUTOTEST
#define N 100000000
#else
#define N 5000000
#endif
CONSOLE_APP_MAIN
{
Vector<int> x;
BiVector<int> y;
for(int i = 0; i < N; i++) {
if(i % 10000 == 0)
Cout() << i << ' ' << x.GetCount() << '\n';
switch(rand() % 6) {
case 0:
case 1:
x.Add(i);
y.AddTail(i);
break;
case 2:
case 3:
x.Insert(0, i);
y.AddHead(i);
break;
case 4:
if(x.GetCount()) {
x.Drop();
y.DropTail();
}
break;
case 5:
if(x.GetCount()) {
x.Remove(0, 1);
y.DropHead();
}
break;
}
ASSERT(x.GetCount() == y.GetCount());
for(int i = 0; i < x.GetCount(); i++)
ASSERT(x[i] == y[i]);
if(x.GetCount() > 10000) {
x.Clear();
y.Clear();
}
}
LOG("========== OK");
}

View file

@ -0,0 +1,10 @@
uses
Core;
file
BiVector.cpp;
mainconfig
"" = "",
"" = "AUTOTEST";

4
autotest/BiVector/init Normal file
View file

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

View file

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

4
autotest/CParser/init Normal file
View file

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

60
autotest/CParser/main.cpp Normal file
View file

@ -0,0 +1,60 @@
#include <Core/Core.h>
using namespace Upp;
#define CHECK_OVERFLOW(s, method, overflow) \
{ \
DLOG(s << ' ' << #method); \
bool isoverflow = false; \
try { \
CParser p(s); \
DDUMP(p.method); \
} \
catch(CParser::Error e) { \
DLOG("Overflow: " << e); \
isoverflow = true; \
} \
ASSERT(isoverflow == overflow); \
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
CParser p("i if while 12345 alfa");
ASSERT(p.Id("i"));
ASSERT(p.Id("if"));
ASSERT(p.Id("while"));
ASSERT(p.IsInt());
ASSERT(p.ReadInt() == 12345);
ASSERT(p.IsId());
ASSERT(p.ReadId() == "alfa");
CHECK_OVERFLOW("2147483647", ReadInt(), false);
CHECK_OVERFLOW("2147483648", ReadInt(), true);
CHECK_OVERFLOW("-2147483648", ReadInt(), false);
CHECK_OVERFLOW("-2147483649", ReadInt(), true);
CHECK_OVERFLOW("ffffffff", ReadNumber(16), false);
CHECK_OVERFLOW("100000000", ReadNumber(16), true);
CHECK_OVERFLOW("9223372036854775807", ReadInt64(), false);
CHECK_OVERFLOW("9223372036854775808", ReadInt64(), true);
CHECK_OVERFLOW("-9223372036854775808", ReadInt64(), false);
CHECK_OVERFLOW("-9223372036854775809", ReadInt64(), true);
CHECK_OVERFLOW("ffffffffffffffff", ReadNumber64(16), false);
CHECK_OVERFLOW("10000000000000000", ReadNumber64(16), true);
DDUMP(1 * pow(10.0, 500));
CHECK_OVERFLOW("1e300", ReadDouble(), false);
CHECK_OVERFLOW("1e500", ReadDouble(), true);
CHECK_OVERFLOW("-1e300", ReadDouble(), false);
CHECK_OVERFLOW("-1e500", ReadDouble(), true);
CHECK_OVERFLOW(String('0', 500), ReadDouble(), true);
LOG("=========== OK");
}

View file

@ -0,0 +1,22 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
CParser p(" someid $$ and");
LOG("GetPtr: " << AsCString(p.GetPtr()));
LOG("GetSpacePtr: " << AsCString(p.GetSpacePtr()));
p.Id("someid");
LOG("GetPtr: " << AsCString(p.GetPtr()));
LOG("GetSpacePtr: " << AsCString(p.GetSpacePtr()));
p.Char('$');
LOG("GetPtr: " << AsCString(p.GetPtr()));
LOG("GetSpacePtr: " << AsCString(p.GetSpacePtr()));
p.Char('$');
LOG("GetPtr: " << AsCString(p.GetPtr()));
LOG("GetSpacePtr: " << AsCString(p.GetSpacePtr()));
LOG("========== OK");
}

View file

@ -0,0 +1,11 @@
description "Test of CParser::GetWhitespacePtr\377";
uses
Core;
file
CParserWspc.cpp;
mainconfig
"" = "SSE2";

View file

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

View file

@ -0,0 +1,43 @@
#include <Core/Core.h>
using namespace Upp;
ConditionVariable cv;
Mutex mtx;
int count;
bool texit;
void WorkThread()
{
for(;;) {
Mutex::Lock __(mtx);
LOG("Before wait");
if(texit) break;
cv.Wait(mtx);
LOG("After wait");
if(texit) break;
count++;
}
LOG("Exiting work thread");
}
CONSOLE_APP_MAIN
{
Thread t[10];
for(int i = 0; i < 10; i++)
t[i].Run(callback(WorkThread));
for(int i = 0; i < 1000; i++) {
Mutex::Lock __(mtx);
cv.Signal();
}
{
Mutex::Lock __(mtx);
texit = true;
}
texit = true;
cv.Broadcast();
for(int i = 0; i < 10; i++)
t[i].Wait();
LOG(count);
LOG("======== OK");
}

View file

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

4
autotest/CVariable/init Normal file
View file

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

View file

@ -0,0 +1,84 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
#ifdef CPP_11
StdLogSetup(LOG_COUT|LOG_FILE);
int a = 0;
{
Callback cb;
cb = [&] { a = 1; LOG("Callback"); };
cb();
ASSERT(a == 1);
}
{
Callback1<int> cb;
cb = [&](int b) { a = b; LOG("Callback1"); };
cb(123);
ASSERT(a == 123);
}
{
Callback2<int, int> cb;
cb = [&](int b, int c) { a = b + c; LOG("Callback2"); };
cb(1, 20);
ASSERT(a == 21);
}
{
Callback3<int, int, int> cb;
cb = [&](int b, int c, int d) { a = b + c + d; LOG("Callback3"); };
cb(1, 20, 300);
ASSERT(a == 321);
}
{
Callback4<int, int, int, int> cb;
cb = [&](int b, int c, int d, int e) { a = b + c + d + e; LOG("Callback4"); };
cb(1, 20, 300, 4000);
ASSERT(a == 4321);
}
{
Gate cb;
cb = [&] { a = 1; LOG("Gate"); return true; };
ASSERT(cb());
ASSERT(a == 1);
}
{
Gate1<int> cb;
cb = [&](int b) { a = b; LOG("Gate1"); return false; };
ASSERT(!cb(123));
ASSERT(a == 123);
}
{
Gate2<int, int> cb;
cb = [&](int b, int c) { a = b + c; LOG("Gate2"); return true; };
ASSERT(cb(1, 20));
ASSERT(a == 21);
}
{
Gate3<int, int, int> cb;
cb = [&](int b, int c, int d) { a = b + c + d; LOG("Gate3"); return true; };
ASSERT(cb(1, 20, 300));
ASSERT(a == 321);
}
{
Gate4<int, int, int, int> cb;
cb = [&](int b, int c, int d, int e) { a = b + c + d + e; LOG("Gate4"); return true; };
ASSERT(cb(1, 20, 300, 4000));
ASSERT(a == 4321);
}
LOG("========== OK");
#endif
}

View file

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

View file

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

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

View file

@ -0,0 +1,12 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
LOG("Hello!");
Buffer<int> x(200);
Exit(0);
LOG("Control should never reach here...");
NEVER();
}

View file

@ -2,7 +2,7 @@ uses
Core;
file
fail_assert.cpp;
ConsoleExit.cpp;
mainconfig
"" = "SSE2";

View file

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

View file

@ -0,0 +1,37 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
SetLanguage(LNG_('C','S','C','Z'));
ConvertTime cv;
DUMP(cv.Format(Date(2013, 1, 2)));
ASSERT(cv.Format(Date(2013, 1, 2)) == "02.01.2013");
DUMP(cv.Format(Time(2013, 1, 2)));
ASSERT(cv.Format(Time(2013, 1, 2)) == "02.01.2013");
DUMP(cv.Format(Time(2013, 1, 2, 11, 12, 13)));
ASSERT(cv.Format(Time(2013, 1, 2, 11, 12, 13)) == "02.01.2013 11:12:13");
cv.TimeAlways();
DUMP(cv.Format(Date(2013, 1, 2)));
ASSERT(cv.Format(Date(2013, 1, 2)) == "02.01.2013 00:00:00");
DUMP(cv.Format(Time(2013, 1, 2, 11, 12, 13)));
ASSERT(cv.Format(Time(2013, 1, 2, 11, 12, 13)) == "02.01.2013 11:12:13");
DUMP(cv.Scan("15.6.2010"));
ASSERT(cv.Scan("15.6.2010") == Time(2010, 6, 15, 0, 0, 0));
cv.DayEnd();
DUMP(cv.Scan("15.6.2010"));
ASSERT(cv.Scan("15.6.2010") == Time(2010, 6, 15, 23, 59, 59));
}

View file

@ -2,7 +2,7 @@ uses
Core;
file
timeout.cpp;
Convert.cpp;
mainconfig
"" = "SSE2";

4
autotest/Convert/init Normal file
View file

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

View file

@ -0,0 +1,16 @@
#include <Core/Core.h>
using namespace Upp;
#define CHECK_OVERFLOW(s, cls, overflow) { cls x; Value v = x.Scan(s); LOG(s << " -> " << v); ASSERT(v.IsError() == overflow); }
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
CHECK_OVERFLOW("2147483647", ConvertInt, false);
CHECK_OVERFLOW("2147483648", ConvertInt, true);
CHECK_OVERFLOW("-2147483647", ConvertInt, false);
CHECK_OVERFLOW("-2147483648", ConvertInt, true);
}

View file

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

View file

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

183
autotest/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");
}

View file

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

4
autotest/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,15 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN {
StdLogSetup(LOG_FILE|LOG_COUT);
for(int i = 0; i < 30000; i++) {
Date d = Date(1970, 1, 1) + i;
int64 n = GetUTCSeconds(ToTime(d));
// DLOG(d << ' ' << GetLeapSeconds(d) << ' ' << n);
ASSERT(TimeFromUTC(n) == ToTime(d));
}
LOG("=========== OK");
}

View file

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

4
autotest/DateTime/init Normal file
View file

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

View file

@ -0,0 +1,18 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
for(;;) {
Cout() << "Press ENTER to open FileOut\n";
ReadStdIn();
FileOut out(ConfigFile("testfile"));
if(out) {
Cout() << "file opened\nPress ENTER to close\n";
ReadStdIn();
}
else
Cout() << "NOT opened\n";
}
}

View file

@ -0,0 +1,11 @@
description "Testing the locking of FileOut\377";
uses
Core;
file
FileOutLocking.cpp;
mainconfig
"" = "SSE2";

View file

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

View file

@ -0,0 +1,176 @@
#include <Core/Core.h>
using namespace Upp;
void PosOverrunTest()
{
String tmpfile = GetTempFileName("pos");
FileOut fo;
if(!fo.Open(tmpfile)) {
Cout() << "PosOverrunTest: error creating file " << tmpfile << "\n";
return;
}
for(int i = 0; i < 0x10000; i++)
fo.PutIW(i);
int64 size = fo.GetSize();
fo.Close();
if(fo.IsError() || size != 0x20000) {
Cout() << "PosOverrunTest generator error, file " << tmpfile << "\n";
return;
}
FileIn fi;
fi.SetBufferSize(4096);
if(!fi.Open(tmpfile)) {
Cout() << "PosOverrunTest: error reopening temporary file " << tmpfile << "\n";
return;
}
for(int i = 0; i < 4096; i++)
fi.Get();
char buffer[32];
fi.GetAll(buffer, 32);
bool ok = true;
for(int i = 0; i < 16; i++) {
int strmval = Peek16le(buffer + 2 * i);
int expect = 2048 + i;
if(strmval != expect) {
Cout() << "PosOverrunTest: " << FormatIntHex(expect, 4) << " expected, " << FormatIntHex(strmval, 4) << " found\n";
ok = false;
}
}
if(ok)
Cout() << "PosOverrunTest: finished without errors\n";
}
enum {
T_READ = 1,
T_READGROUP = 2,
T_WRITE = 4,
T_WRITEGROUP = 8,
T_SEEK = 16
};
String Copy(Stream& s, int spos, int ssize, int tpos, dword style) {
bool lf = dynamic_cast<BlockStream *>(&s);
if(lf) LOG("<<");
if(style & T_SEEK)
s.Seek(spos);
Buffer<byte> b(ssize);
int sz = 0;
if(style & T_READ)
if(style & T_READGROUP) {
while(sz < ssize) {
int c = s.Get();
if(c < 0)
break;
b[sz++] = c;
}
ssize = sz;
}
else
ssize = (int)s.Get(b, ssize);
if(lf) LOG(">>");
if(style & T_SEEK)
s.Seek(tpos);
if(style & T_WRITE)
if(style & T_WRITEGROUP)
for(int i = 0; i < ssize; i++)
s.Put(b[i]);
else
s.Put(b, ssize);
if(style & T_READ)
return String(b, ssize);
return Null;
}
String InFile() { return GetDataFile("FileStream.cpp"); }
void StreamTest() {
FileIn in(InFile());
FileOut out(ConfigFile("chips1.cpp"));
for(;;) {
int c = in.Get();
if(c < 0)
break;
out.Put(c);
}
in.Seek(300);
out.Seek(300);
for(int i = 0; i < 2000; i++)
out.Put(in.Get());
out.SetBufferSize(8);
out.Seek(0);
LOG("================================================");
StringStream ss(LoadFile(InFile()));
int nn = 0;
dword style = 0;
while(nn < 100000000) {
if(++nn % 1000 == 0)
Cout() << "ops: " << nn << ", len: " << ss.GetSize()
<< ", buffersize: " << out.GetBufferSize() << "\n";
if(ss.GetSize() > 256*1024) {
int sz = (rand() % 1000) * 100;
ss.SetSize(sz);
out.SetSize(sz);
LOG("Adjusted size: " << ss.GetSize());
}
if(ss.GetSize() != out.GetSize()) {
DUMP(ss.GetSize());
DUMP(out.GetSize());
Panic("SIZE MISMATCH!");
return;
}
if((rand() & 255) == 0)
{
int64 p = out.GetPos();
out.Seek(0);
if(ss.GetResult() != LoadStream(out)) {
out.Seek(0);
SaveFile(ConfigFile("f1.txt"), LoadStream(out));
SaveFile(ConfigFile("f2.txt"), ss.GetResult());
Panic("CONTENT INEQUAL!");
return;
}
out.Seek(p);
}
int spos = ss.GetSize() ? rand() % (int)ss.GetSize() : 0;
int ssize = rand() % (out.GetBufferSize() * 7);
int tpos = ss.GetSize() ? MAKELONG(rand(), rand()) % (int)ss.GetSize() : 0;
if((rand() & 3) == 0)
tpos = minmax<int>(spos - (rand() & 63) + 32, 0, (int)out.GetSize());
if((rand() & 3) == 0)
ssize = rand() % (3 * out.GetBufferSize());
if((rand() & 4091) == 0) {
style++;
Cout() << "MODE: " << style << "\n";
}
LOG("---------------------");
LOG("spos: " << spos << " ssize: " << ssize << " tpos: " << tpos << " style: " << style);
// DUMP(ss.GetSize());
// DUMP(out.GetSize());
String a = Copy(out, spos, ssize, tpos, style);
String b = Copy(ss, spos, ssize, tpos, style);
// DUMP(ss.GetSize());
// DUMP(out.GetSize());
if((rand() & 1023) == 0)
out.SetBufferSize((rand() & 127) + 2);
if(a != b) {
SaveFile(ConfigFile("f1c.txt"), a);
SaveFile(ConfigFile("f2c.txt"), b);
out.Seek(0);
SaveFile(ConfigFile("f1.txt"), LoadStream(out));
SaveFile(ConfigFile("f2.txt"), ss.GetResult());
DUMP(ss.GetSize());
Panic("INEQUAL READ IN COPY!");
return;
}
}
}
CONSOLE_APP_MAIN
{
// DataBase::FullTest();
PosOverrunTest();
StreamTest();
}

View file

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

4
autotest/FileStream/init Normal file
View file

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

View file

@ -0,0 +1,58 @@
#include "Core/Core.h"
using namespace Upp;
CONSOLE_APP_MAIN
{
{
HttpRequest http("www.ultimatepp.org");
InFilterStream in;
http.WhenContent = callback(&in, &InFilterStream::Out);
in.More = callback(&http, &HttpRequest::Do);
http.Blocking();
ASSERT(!in.IsEof());
String h;
h = in.GetLine();
ASSERT(h.StartsWith("<!DOCTYPE"));
while(!in.IsEof())
h = in.GetLine();
ASSERT(h.EndsWith("BODY>"));
}
String path = GetHomeDirFile("test.gz");
{
FileOut fout(path);
Zlib zlib;
OutFilterStream out(fout, zlib);
zlib.GZip().Compress();
for(int i = 0; i < 100000; i++)
out.Put(FormatIntBase(i, 27));
out.Close();
}
String data;
for(int i = 0; i < 100000; i++)
data.Cat(FormatIntBase(i, 27));
SaveFile(path + ".1", GZCompress(data));
#if 0
SaveFile(path, GZCompress(data));
#endif
for(int pass = 0; pass < 2; pass++) {
FileIn fin(path);
Zlib zlib;
InFilterStream in(fin, zlib);
zlib.GZip().Decompress();
if(pass)
for(int i = 0; i < data.GetCount(); i++) {
char c = in.Get();
ASSERT(c == data[i]);
}
else
for(int i = 0; i < data.GetCount(); i += 17) {
int n = min(data.GetCount() - i, 17);
String h = in.Get(n);
ASSERT(h == data.Mid(i, n));
}
ASSERT(in.Get() < 0);
ASSERT(in.IsEof());
}
}

View file

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

View file

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

View file

@ -0,0 +1,54 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
FixedVectorMap<String, String> fmap;
ASSERT(fmap.IsEmpty());
for(int i = 0; i < 10; i++)
fmap.Add(AsString(100 + (i & 1 ? -1 : 1) * i), AsString(i));
DUMPM(fmap);
fmap.Finish();
DUMPM(fmap);
ASSERT(!fmap.IsEmpty());
ASSERT(fmap.GetCount() == 10);
ASSERT(fmap.Find("foo") < 0);
ASSERT(fmap.FindPtr("foo") == NULL);
for(int i = 0; i < 10; i++) {
ASSERT(fmap.Get(AsString(100 + (i & 1 ? -1 : 1) * i)) == AsString(i));
ASSERT(*fmap.FindPtr(AsString(100 + (i & 1 ? -1 : 1) * i)) == AsString(i));
}
fmap.Clear();
ASSERT(fmap.IsEmpty());
for(int i = 1; i < 10; i++)
for(int j = 0; j < i; j++)
fmap.Add(AsString(j)) = AsString(j);
fmap.Finish();
DUMPM(fmap);
for(int i = 0; i < 10; i++) {
int q = fmap.Find(AsString(i));
int n = 0;
while(q >= 0) {
n++;
ASSERT(fmap[q] == AsString(i));
q = fmap.FindNext(q);
}
ASSERT(n == 9 - i);
}
LOG("========= EVERYTHING OK ==========");
}

View file

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

4
autotest/FixedMap/init Normal file
View file

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

View file

@ -0,0 +1,41 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
String rndset;
rndset << "[]<>;`%%%%";
rndset << rndset;
rndset << rndset;
rndset << rndset;
for(int i = 32; i < 128; i++)
if(IsAlpha(i) || IsDigit(i))
rndset.Cat(i);
for(;;) {
String fmtstr;
while(Random(20))
fmtstr << (char)rndset[Random(rndset.GetCount())];
Vector<Value> v;
for(;;) {
int q = Random(5);
if(q == 0)
break;
switch(q) {
case 1:
v.Add((int)Random(100));
break;
case 2:
v.Add(AsString(Random(100)));
break;
case 3:
v.Add(GetSysDate() + Random(100));
break;
}
}
DUMP(fmtstr);
DUMPC(v);
DUMP(NFormat(fmtstr, v));
}
}

View file

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

View file

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

View file

@ -0,0 +1,26 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
String dir1 = GetHomeDirFile("gztest1");
DeleteFolderDeep(dir1);
RealizeDirectory(dir1);
String file1 = AppendFileName(dir1, "test.cpp");
String gzfile1 = AppendFileName(dir1, "test.cpp.gz");
String dir2 = GetHomeDirFile("gztest2");
DeleteFolderDeep(dir2);
RealizeDirectory(dir2);
String file2 = AppendFileName(dir2, "test.cpp");
String gzfile2 = AppendFileName(dir2, "test.cpp.gz");
SaveFile(file1, LoadFile(GetDataFile("GZCompressFile.cpp")));
GZCompressFile(file1);
SaveFile(gzfile2, LoadFile(gzfile1));
GZDecompressFile(gzfile2);
ASSERT(LoadFile(file1) == LoadFile(file2));
}

View file

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

View file

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

104
autotest/Gzip/Gzip.cpp Normal file
View file

@ -0,0 +1,104 @@
#include <Core/Core.h>
using namespace Upp;
void Put(Zlib& zip, const String& data, int fixed, int rndmask)
{
int done = 0;
while(done < data.GetCount()) {
int n = min(fixed ? fixed : (rand() & rndmask), data.GetCount() - done);
zip.Put(~data + done, n);
done += n;
}
DDUMP(done);
}
void Test(int size, dword cmask, int fixed, int rndmask)
{
for(int crc = 0; crc < 2; crc++)
for(int gzip = 0; gzip < 2; gzip++)
for(int cs = 0; cs < 3; cs++) {
String data;
for(int i = 0; i < size; i++) {
data.Cat(rand());
if((rand() & cmask) == 0)
data.Cat("Something to test compression too...");
}
DLOG("====================");
DDUMP(fixed);
DDUMP(gzip);
DDUMP(crc);
DLOG("COMPRESS: " << data.GetCount());
Zlib zip;
zip.GZip(gzip);
zip.ChunkSize(cs == 0 ? 128 : cs == 1 ? 2048 : 65536).CRC(crc).Compress();
Put(zip, data, fixed, rndmask);
zip.End();
String deflated = zip;
DDUMP(deflated.GetCount());
dword crc = zip.GetCRC();
// LOGHEXDUMP(~deflated, deflated.GetCount());
String z = gzip ? GZCompress(data) : ZCompress(data);
DDUMP(z.GetCount());
// LOGHEXDUMP(~z, z.GetCount());
if(crc)
ASSERT(crc == CRC32(data));
ASSERT(deflated == z);
DLOG("====================");
DLOG("DECOMPRESS: " << deflated.GetCount());
String zz = gzip ? GZDecompress(deflated) : ZDecompress(deflated);
DDUMP(zz.GetCount());
zip.CRC(crc).Decompress();
Put(zip, deflated, fixed, rndmask);
zip.End();
String inflated = zip;
ASSERT(!zip.IsError());
DDUMP(inflated.GetCount());
ASSERT(inflated == data);
if(crc)
ASSERT(zip.GetCRC() == crc);
}
}
void Test2(int n, int fixed, int rndmask)
{
Test(n, 0xffffffff, fixed, rndmask);
Test(n, 255, fixed, rndmask);
Test(n, 15, fixed, rndmask);
Test(n, 1, fixed, rndmask);
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
String gzf = LoadFile(GetHomeDirFile("mbox.gz"));
Zlib z;
z.GZip().Decompress();
z.Put(gzf);
z.End();
DDUMP(~z);
DDUMP(z.GetGZipComment());
DDUMP(z.GetGZipName());
DDUMP(GZDecompress(gzf));
for(int x = 3; x < 10000000; x += x) {
Test(x, 0xffffffff, 1, 2047);
Test(x, 0xffffffff, 3, 2047);
Test(x, 0xffffffff, 128, 2047);
Test(x, 0xffffffff, 2048, 2047);
Test(x, 0xffffffff, 8192, 2047);
Test(x, 0xffffffff, 100000, 2047);
Test(x, 0xffffffff, 0, 2047);
}
LOG("*************************************");
LOG("EVERYTHING IS OK");
}

View file

@ -2,7 +2,7 @@ uses
Core;
file
error.cpp;
Gzip.cpp;
mainconfig
"" = "SSE2";

4
autotest/Gzip/init Normal file
View file

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

143
autotest/Heap/Heap.cpp Normal file
View file

@ -0,0 +1,143 @@
#include <Core/Core.h>
using namespace Upp;
void HSet(byte *ptr, int sz)
{
if(!ptr) return;
int q = (uintptr_t)ptr % 257;
while(sz--)
*ptr++ = (byte)q++;
}
void HCheck(byte *ptr, int sz)
{
if(!ptr) return;
int q = (uintptr_t)ptr % 257;
while(sz--)
ASSERT(*ptr++ == (byte)q++);
}
int count;
byte *ptr[8192];
size_t sz[8192];
void MCheck()
{
MemoryCheckDebug();
for(int i = 0; i < count; i++)
HCheck(ptr[i], sz[i]);
}
void HClear() {
for(int i = 0; i < count; i++) {
HCheck(ptr[i], sz[i]);
delete ptr[i];
ptr[i] = NULL;
sz[i] = 0;
MCheck();
}
MemoryCheck();
MemoryCheckDebug();
}
void MClear(bool del = false) {
for(int i = 0; i < count; i++) {
HCheck(ptr[i], sz[i]);
MemoryFree(ptr[i]);
ptr[i] = NULL;
sz[i] = 0;
MCheck();
}
MemoryCheck();
MemoryCheckDebug();
}
int RndSize()
{
return rand() & 255;
switch(rand() & 3) {
case 0: return rand() & 255;
case 1: return rand() & 16383;
}
return (rand() + rand() + rand()) & 0x1ffff;
}
void HeapTest(int cnt, int N, bool chk)
{
int mask = cnt - 1;
count = cnt;
memset(ptr, 0, sizeof(ptr));
memset(sz, 0, sizeof(sz));
for(int n = 1; n < N; n++) {
if(n % 1000 == 0)
LOG(n);
int q = n & mask;
if(chk)
MCheck();
else
HCheck(ptr[q], sz[q]);
delete (byte *)ptr[q];
ptr[q] = NULL;
if(chk) MCheck();
sz[q] = RndSize();
ptr[q] = new byte[sz[q]];
HSet(ptr[q], sz[q]);
if(chk) MCheck();
}
HClear();
MCheck();
LOG("Stage 1 (new/delete) passed\r\n");
for(int n2 = 1; n2 < N; n2++) {
if(n2 % 1000 == 0)
LOG(n2);
int q = n2 & mask;
if(chk)
MCheck();
else
HCheck(ptr[q], sz[q]);
// LOGF("Free: %p\n", (void *)ptr[q]);
MemoryFree((byte *)ptr[q]);
ptr[q] = NULL;
if(chk) MCheck();
sz[q] = RndSize();
ptr[q] = (byte *)MemoryAlloc(sz[q]);
// LOGF("Alloc: %d %p\n", sz[q], (void *)ptr[q]);
ASSERT(((int)(uintptr_t)ptr[q] & 15) == 0);
HSet(ptr[q], sz[q]);
if(chk) MCheck();
}
MClear();
LOG("Stage 2 (MemoryAlloc/MemoryFree) passed");
for(int n3 = 1; n3 < N; n3++) {
if(n3 % 1000 == 0)
LOG(n3);
int q = n3 & mask;
if(chk)
MCheck();
else
HCheck(ptr[q], sz[q]);
MemoryFree((byte *)ptr[q]);
ptr[q] = NULL;
if(chk) MCheck();
sz[q] = RndSize();
ptr[q] = (byte *)MemoryAllocSz(sz[q]);
ASSERT(((int)(uintptr_t)ptr[q] & 15) == 0);
HSet(ptr[q], sz[q]);
if(chk) MCheck();
}
MClear();
LOG("Stage 3 (MemoryAllocSz/MemoryFree) passed");
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
LOG("Allocator test:");
HeapTest(256, 100000, true);
LOG("Checked allocator test Passed");
HeapTest(8192, 1000000, false);
LOG("Quick allocator test Passed");
HeapTest(8192, 100 * 1000000, false);
LOG("Allocator test Passed");
}

9
autotest/Heap/Heap.upp Normal file
View file

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

4
autotest/Heap/init Normal file
View file

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

67
autotest/HeapMT/Heap.cpp Normal file
View file

@ -0,0 +1,67 @@
#include <Core/Core.h>
#define N 1000 * 100
#define THREADS 5
using namespace Upp;
Mutex mutex;
Semaphore todo;
BiVector<int *> queue;
void ProducerThread()
{
for(int i = 0; i < N; i++) {
if(i % 1000 == 0)
LOG(i);
mutex.Enter();
queue.AddHead() = new int;
mutex.Leave();
todo.Release();
MemoryCheckDebug();
}
LOG("Producer shutdown");
}
void ConsumerThread()
{
for(;;) {
todo.Wait();
Mutex::Lock __(mutex);
if(queue.GetCount()) {
int *ptr = queue.Tail();
if(!ptr) break;
queue.DropTail();
delete ptr;
}
MemoryCheckDebug();
}
LOG("Consumer shutdown");
}
CONSOLE_APP_MAIN {
StdLogSetup(LOG_COUT);
Thread producer[THREADS];
Thread consumer[THREADS];
for(int i = 0; i < THREADS; i++) {
producer[i].Run(callback(ProducerThread));
consumer[i].Run(callback(ConsumerThread));
}
for(int i = 0; i < THREADS; i++) {
producer[i].Wait();
LOG("Producer #" << i << " terminated");
}
mutex.Enter();
queue.AddHead(NULL);
mutex.Leave();
for(int i = 0; i < THREADS; i++)
todo.Release();
for(int i = 0; i < THREADS; i++) {
consumer[i].Wait();
LOG("Consumer #" << i << " terminated");
}
MemoryCheckDebug();
LOG("App shutdown");
LOG("Passed");
}

View file

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

4
autotest/HeapMT/init Normal file
View file

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

View file

@ -0,0 +1,49 @@
#include <Core/Core.h>
using namespace Upp;
#define LLOG(x) RLOG(x)
#define LDUMP(x) RDUMP(x)
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
HttpRequest::Trace();
const Tuple2<const char *, const char *> x[] = {
{ "https://www.servis24.cz", "" },
{ "rcmania.cz", "</html>" },
// { "http://www.facebook.com/pages/Upp", "" },
{ "www.oexchange.org", "" },
{ "http://pagead2.googlesyndication.com/pagead/show_ads.js", "" },
{ "www.ultimatepp.org", "</script></BODY>" },
{ "www.idnes.cz", "</html>" },
{ "www.google.com", "</script>" },
{ "http://wattsupwiththat.com/", "</html>" },
{ "http://www.rcalbum.com", "</html>" },
};
for(int nd = 0; nd < 1; nd++)
for(int i = 0; i < __countof(x); i++) {
LLOG("=============================================");
LLOG("URL: " << x[i].a);
HttpRequest h(x[i].a);
if(nd)
h.Timeout(0);
if(IsNull(h.Execute())) {
DUMP(~h);
LLOG("Error:\n" << h.GetErrorDesc());
NEVER();
}
if((~h).Find(x[i].b) < 0) {
LLOG("Content:\n" << ~h);
NEVER();
}
}
{
HttpRequest h("www.idnes.cz");
h.MaxContentSize(10000);
h.Execute();
ASSERT(h.IsError());
LDUMP(h.GetError());
}
LLOG("*********** Everything is OK");
}

View file

@ -0,0 +1,10 @@
uses
Core,
Core\SSL;
file
HttpRequest.cpp;
mainconfig
"" = "SSE2";

View file

@ -0,0 +1,5 @@
#ifndef _HttpRequest_icpp_init_stub
#define _HttpRequest_icpp_init_stub
#include "Core/init"
#include "Core\SSL/init"
#endif

30
autotest/INI/INI.cpp Normal file
View file

@ -0,0 +1,30 @@
#include <Core/Core.h>
using namespace Upp;
namespace Config {
INI_STRING(text, "default text", "Text parameter");
};
struct Test {
int x;
String a;
};
Test y = { 123, "123" };
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
SetIniFile(GetDataFile("test.ini"));
for(;;) {
LOG(Config::text);
LOG(GetIniInfoFormatted());
getchar();
SetIniFile(GetDataFile("test.ini"));
}
}

10
autotest/INI/INI.upp Normal file
View file

@ -0,0 +1,10 @@
uses
Core;
file
test.ini,
INI.cpp;
mainconfig
"" = "SSE2";

4
autotest/INI/init Normal file
View file

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

1
autotest/INI/test.ini Normal file
View file

@ -0,0 +1 @@
text = Just a test

View file

@ -0,0 +1,203 @@
#include <Core/Core.h>
using namespace Upp;
template <class C1, class C2>
void Compare(C1& a, C2& b)
{
ASSERT(a.GetCount() == b.GetCount());
for(int i = 0; i < a.GetCount(); i++)
ASSERT(a[i] == b[i]);
typename C1::Iterator ia = a.Begin();
typename C2::Iterator ib = b.Begin();
while(ib != b.End()) {
ASSERT(*ia == *ib);
ia++;
ib++;
}
}
void InArrayTest()
{
SeedRandom();
Vector<int> q;
InArray<int> iv;
Compare(q, iv);
iv.Insert(0) = 0;
q.Insert(0) = 0;
iv.Insert(1) = -1;
q.Insert(1) = -1;
for(int j = 0; j < 10000; j++) {
if(j % 1000 == 0)
LOG(j);
int i = Random(iv.GetCount());
iv.Insert(i) = i;
q.Insert(i) = i;
Compare(q, iv);
ASSERT(iv.End() - iv.Begin() == iv.GetCount());
}
for(int i = 0; i < 100; i++) {
int n = Random(100) + 20;
InArray<int>::Iterator it2, it = iv.Begin();
it += n;
ASSERT(it - iv.Begin() == n);
it2 = it;
for(int j = 0; j < 10; j++) {
ASSERT(it2 - iv.Begin() == n + j);
++it2;
}
it2 = it;
for(int j = 0; j < 10; j++) {
ASSERT(it2 - iv.Begin() == n - j);
--it2;
}
}
StableSort(q);
StableSort(iv);
Compare(q, iv);
}
void TestUpperBound()
{
{
InArray<int> v;
for(int i = 0; i < 3000; i++) {
if(i % 1000 == 0)
LOG(i);
v.Insert(i) = i;
ASSERT(v.FindUpperBound(i) == i + 1);
for(int j = 0; j < i; j++)
ASSERT(v.FindUpperBound(j) == j + 1);
}
}
{
InArray<int> v;
for(int i = 0; i < 3000; i++) {
if(i % 1000 == 0)
LOG(i);
for(int j = 0; j < 7; j++)
v.Insert(7 * i) = i;
ASSERT(v.FindUpperBound(i) == 7 * i + 7);
for(int j = 0; j < i; j++)
ASSERT(v.FindUpperBound(j) == 7 * j + 7);
}
}
}
void TestLowerBound()
{
{
InArray<int> v;
for(int i = 0; i < 3000; i++) {
if(i % 1000 == 0)
LOG(i);
v.Insert(i) = i;
ASSERT(v.FindLowerBound(i) == i);
for(int j = 0; j < i; j++)
ASSERT(v.FindLowerBound(j) == j);
}
}
{
InArray<int> v;
for(int i = 0; i < 3000; i++) {
if(i % 1000 == 0)
LOG(i);
for(int j = 0; j < 7; j++)
v.Insert(7 * i) = i;
ASSERT(v.FindLowerBound(i) == 7 * i);
for(int j = 0; j < i; j++)
ASSERT(v.FindLowerBound(j) == 7 * j);
}
}
}
void SetTest()
{
for(int j = 0; j < 100; j++) {
LOG(j);
Vector<int> va;
InArray<int> ia;
for(int i = 0; i < 1000; i++) {
int q = Random(100);
int ii = FindUpperBound(va, q);
va.Insert(ii) = q;
ia.InsertUpperBound(q);
Compare(va, ia);
ii = ia.Find(q);
ASSERT(ia[ii] == q);
ASSERT(ia.Find(200) < 0);
}
}
}
void RemoveTest()
{
SeedRandom();
Vector<int> q;
InArray<int> iv;
Compare(q, iv);
iv.Insert(0) = 0;
q.Insert(0) = 0;
iv.Insert(1) = -1;
q.Insert(1) = -1;
for(int j = 0; j < 10000000; j++) {
if(j % 1000 == 0)
LOG(j);
if(iv.GetCount() > 200 && Random(4) == 1) {
int i = Random(iv.GetCount() - 21);
int n = Random(20);
iv.Remove(i, n);
q.Remove(i, n);
}
else {
int i = Random(iv.GetCount());
iv.Insert(i) = i;
q.Insert(i) = i;
}
Compare(q, iv);
ASSERT(iv.End() - iv.Begin() == iv.GetCount());
}
}
void InsertNTest()
{
SeedRandom();
Vector<int> av;
InArray<int> iv;
for(int i = 0; i < 100000; i++) {
if(i % 1000 == 0)
LOG(i);
if(av.GetCount() > 2000) {
av.Clear();
iv.Clear();
}
int pos = av.GetCount() ? Random(av.GetCount()) : 0;
int n = Random(30);
av.InsertN(pos, n);
iv.InsertN(pos, n);
for(int j = 0; j < n; j++) {
int r = Random();
av[pos + j] = r;
iv[pos + j] = r;
}
Compare(av, iv);
}
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
SeedRandom();
RemoveTest();
InsertNTest();
SetTest();
TestLowerBound();
TestUpperBound();
InArrayTest();
}

View file

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

4
autotest/InArray/init Normal file
View file

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

View file

@ -0,0 +1,266 @@
#include <Core/Core.h>
using namespace Upp;
template <class C1, class C2>
void Compare(C1& a, C2& b)
{
ASSERT(a.GetCount() == b.GetCount());
for(int i = 0; i < a.GetCount(); i++)
ASSERT(a[i] == b[i]);
typename C1::Iterator ia = a.Begin();
typename C2::Iterator ib = b.Begin();
while(ib != b.End()) {
ASSERT(*ia == *ib);
ia++;
ib++;
}
}
template <class T>
void Check(const InVector<T>& iv)
{
ASSERT(iv.GetCount() == 0 || iv.FindUpperBound(iv.Top()) == iv.GetCount());
}
template <class T>
T ToType(int);
template <>
String ToType(int i)
{
return AsString(i);
}
template <>
int ToType(int i)
{
return i;
}
template <class T>
void InVectorTest()
{
SeedRandom();
Vector<T> q;
InVector<T> iv;
Compare(q, iv);
iv.Insert(0) = 0;
q.Insert(0) = 0;
iv.Insert(1) = ToType<T>(-1);
q.Insert(1) = ToType<T>(-1);
for(int j = 0; j < 10000; j++) {
if(j % 1000 == 0)
LOG(j);
int i = Random(iv.GetCount());
iv.Insert(i) = ToType<T>(i);
q.Insert(i) = ToType<T>(i);
Compare(q, iv);
}
for(int i = 0; i < 100; i++) {
int n = Random(100) + 20;
typename InVector<T>::Iterator it2, it = iv.Begin();
it += n;
ASSERT(it - iv.Begin() == n);
it2 = it;
for(int j = 0; j < 10; j++) {
ASSERT(it2 - iv.Begin() == n + j);
++it2;
}
it2 = it;
for(int j = 0; j < 10; j++) {
ASSERT(it2 - iv.Begin() == n - j);
--it2;
}
}
StableSort(q);
StableSort(iv);
Compare(q, iv);
}
template <class T>
void TestUpperBound()
{
{
InVector<T> v;
for(int i = 0; i < 3000; i++) {
if(i % 1000 == 0)
LOG(i);
v.Insert(i) = ToType<T>(i);
ASSERT(v.FindUpperBound(ToType<T>(i)) == i + 1);
for(int j = 0; j < i; j++)
ASSERT(v.FindUpperBound(ToType<T>(j)) == j + 1);
Check(v);
}
}
{
InVector<T> v;
for(int i = 0; i < 3000; i++) {
if(i % 1000 == 0)
LOG(i);
for(int j = 0; j < 7; j++)
v.Insert(7 * i) = ToType<T>(i);
ASSERT(v.FindUpperBound(ToType<T>(i)) == 7 * i + 7);
for(int j = 0; j < i; j++)
ASSERT(v.FindUpperBound(ToType<T>(j)) == 7 * j + 7);
Check(v);
}
}
}
template <class T>
void TestLowerBound()
{
{
InVector<T> v;
for(int i = 0; i < 3000; i++) {
if(i % 1000 == 0)
LOG(i);
v.Insert(i) = ToType<T>(i);
ASSERT(v.FindLowerBound(ToType<T>(i)) == i);
for(int j = 0; j < i; j++)
ASSERT(v.FindLowerBound(ToType<T>(j)) == j);
Check(v);
}
}
{
InVector<T> v;
for(int i = 0; i < 3000; i++) {
if(i % 1000 == 0)
LOG(i);
for(int j = 0; j < 7; j++)
v.Insert(7 * i) = ToType<T>(i);
ASSERT(v.FindLowerBound(ToType<T>(i)) == 7 * i);
for(int j = 0; j < i; j++)
ASSERT(v.FindLowerBound(ToType<T>(j)) == 7 * j);
Check(v);
}
}
}
template <class T>
void SetTest()
{
for(int j = 0; j < 100; j++) {
LOG(j);
Vector<T> va;
InVector<T> ia;
for(int i = 0; i < 1000; i++) {
int q = Random(100);
int ii = FindUpperBound(va, ToType<T>(q));
T val = ToType<T>(q);
va.Insert(ii) = val;
ia.InsertUpperBound(val);
Compare(va, ia);
Check(ia);
ii = ia.Find(val);
ASSERT(ia[ii] == val);
ASSERT(ia.Find(ToType<T>(20000)) < 0);
}
}
}
template <class T>
void RemoveTest()
{
SeedRandom();
Vector<T> q;
InVector<T> iv;
Compare(q, iv);
iv.Insert(0) = 0;
q.Insert(0) = 0;
iv.Insert(1) = ToType<T>(-1);
q.Insert(1) = ToType<T>(-1);
for(int j = 0; j < 10000000; j++) {
if(j % 1000 == 0)
LOG(j);
if(iv.GetCount() > 200 && Random(4) == 1) {
int i = Random(iv.GetCount() - 21);
int n = Random(20);
iv.Remove(i, n);
q.Remove(i, n);
}
else {
int i = Random(iv.GetCount());
iv.Insert(i) = ToType<T>(i);
q.Insert(i) = ToType<T>(i);
}
Compare(q, iv);
ASSERT(iv.End() - iv.Begin() == iv.GetCount());
}
}
template <class T>
void InsertNTest()
{
SeedRandom();
Vector<T> av;
InVector<T> iv;
for(int i = 0; i < 100000; i++) {
if(i % 1000 == 0)
LOG(i);
if(av.GetCount() > 2000) {
av.Clear();
iv.Clear();
}
int pos = av.GetCount() ? Random(av.GetCount()) : 0;
int n = Random(30);
av.InsertN(pos, n);
iv.InsertN(pos, n);
for(int j = 0; j < n; j++) {
int r = Random();
av[pos + j] = ToType<T>(r);
iv[pos + j] = ToType<T>(r);
}
Compare(av, iv);
}
}
struct TestType : Moveable<TestType> {
int x;
String y;
bool operator<(const TestType& b) const { return CombineCompare(x, b.x)(y, b.y) < 0; }
bool operator==(const TestType& b) const { return x == b.x && y == b.y; }
TestType(int i) { x = i; y = AsString(i ^ 7); }
TestType() {}
};
template <>
TestType ToType(int i)
{
return TestType(i);
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_FILE|LOG_COUT);
SeedRandom();
SetTest<int>();
TestLowerBound<int>();
TestUpperBound<int>();
RemoveTest<int>();
InsertNTest<int>();
InVectorTest<int>();
SetTest<String>();
TestLowerBound<String>();
TestUpperBound<String>();
RemoveTest<String>();
InsertNTest<String>();
InVectorTest<String>();
SetTest<TestType>();
TestLowerBound<TestType>();
TestUpperBound<TestType>();
RemoveTest<TestType>();
InsertNTest<TestType>();
InVectorTest<TestType>();
}

View file

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

4
autotest/InVector/init Normal file
View file

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

View file

@ -4,5 +4,5 @@ using namespace Upp;
CONSOLE_APP_MAIN
{
Sleep(20000);
ASSERT(QPDecode("=3DTest=\r\n=3D") == "=Test=");
}

View file

@ -0,0 +1,11 @@
description "Various inet based encoding/decoding schemes\377";
uses
Core;
file
InetCode.cpp;
mainconfig
"" = "SSE2";

4
autotest/InetCode/init Normal file
View file

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

96
autotest/JSON/JSON.cpp Normal file
View file

@ -0,0 +1,96 @@
#include <Core/Core.h>
using namespace Upp;
struct TestStruct
{
struct TestV : Moveable<TestV>
{
double a;
Value b;
String c;
bool d;
String ToString() const
{
return Format("a=%d, b=%d", a,b);
}
void Jsonize(JsonIO &json)
{
json
("a", a)
("b", b)
("c", c)
("d", d)
;
}
TestV() { c = "Some text"; d = false; }
};
void Add(double a, Value b)
{
TestV v;
v.a = a;
v.b = b;
static int ii;
map.Add("SomeKey" + AsString(++ii), v);
}
void Jsonize(JsonIO &json)
{
StringMap(json, map); // <- string map
}
void Xmlize(XmlIO &xio) {
XmlizeByJsonize(xio, *this);
}
VectorMap<String,TestV> map;
};
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
Vector<Value> a, b;
a.Add();
String json = StoreAsJson(a);
RDUMP(json);
LoadFromJson(b, json);
RDUMPC(b);
ASSERT(b.GetCount() == 1 && IsNull(b[0]));
TestStruct test, test2;
test.Add(0, 0);
test.Add(-1.2345, Date(2007, 12, 12));
LoadFromJson(test2, StoreAsJson(test));
RLOG(StoreAsJson(test));
RLOG("===================");
RLOG(StoreAsJson(test2));
ASSERT(StoreAsJson(test) == StoreAsJson(test2));
RLOG("===================");
StoreAsJsonFile(test, NULL, true);
LoadFromJsonFile(test2);
ASSERT(StoreAsJson(test) == StoreAsJson(test2));
String fn = ConfigFile("h");
StoreAsJsonFile(test, fn, true);
RDUMP(LoadFile(fn));
LoadFromJsonFile(test2);
ASSERT(StoreAsJson(test) == StoreAsJson(test2));
TestStruct test3;
ASSERT(!LoadFromJson(test2, "{\"SomeKey1\":{\"a\":\"X\",\"b\":2},\"SomeKey2\":{\"a\":1,\"b\":2}}"));
ASSERT(!LoadFromJsonFile(test2, "c:aksjdfhkjaskjdfkhasdf"));
RLOG("================================");
String xml = StoreAsXML(test, "test");
RLOG(xml);
LoadFromXML(test2, xml);
ASSERT(StoreAsXML(test, "test") == xml);
RLOG("Everything is OK.");
}

View file

@ -2,7 +2,7 @@ uses
Core;
file
leaks.cpp;
JSON.cpp;
mainconfig
"" = "SSE2";

4
autotest/JSON/init Normal file
View file

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

View file

@ -0,0 +1,18 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN {
StdLogSetup(LOG_FILE|LOG_COUT);
Date d = GetSysDate();
Time t = GetSysTime();
String h = Json("date", d)("time", t)("array", JsonArray() << d << t);
DDUMP(h);
Value v = ParseJSON(h);
ASSERT(v["date"] == d);
ASSERT(v["time"] == t);
ASSERT(v["array"][0] == d);
ASSERT(v["array"][1] == t);
}

View file

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

4
autotest/JsonDATE/init Normal file
View file

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

View file

@ -0,0 +1,22 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
VectorMap<String, String> map = LoadIniFile(GetDataFile("test.ini"));
DDUMPM(map);
const Tuple2<const char *, const char *> et[] = {
{ "alfa", "alfa_value" },
{ "_beta", "beta_value" },
{ "gamma", "gamma_value" },
{ "included", "included_value" },
{ "delta", "delta_value" },
};
ASSERT(map.GetCount() == __countof(et));
for(int i = 0; i < map.GetCount(); i++) {
ASSERT(map.GetKey(i) == et[i].a);
ASSERT(map[i] == et[i].b);
}
}

View file

@ -0,0 +1,11 @@
uses
Core;
file
test2.ini,
test.ini,
LoadIniStream.cpp;
mainconfig
"" = "SSE2";

View file

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

View file

@ -0,0 +1,16 @@
alfa=alfa_value
_beta=beta_value
;comment=comment
gamma= gamma_value
#another comment = gggg
@include test2.ini
delta=delta_value
@end
past_end=this should not be there...

View file

@ -0,0 +1 @@
included=included_value

View file

@ -1,11 +0,0 @@
description "This takes 20 second, which would result in timeout, if not ##WAIT: 1\377";
uses
Core;
file
Long.cpp;
mainconfig
"" = "SSE2";

View file

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

35
autotest/Maps/Maps.cpp Normal file
View file

@ -0,0 +1,35 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN{
StdLogSetup(LOG_FILE|LOG_COUT);
VectorMap<int, String> m;
m(1, "one")(2, "two");
DDUMPM(m);
ASSERT(m.Get(1) == "one");
ASSERT(m.Get(2) == "two");
{
SortedVectorMap<int, String> m;
m(2, "two")(1, "one");
DDUMPM(m);
ASSERT(m.Get(1) == "one");
ASSERT(m.Get(2) == "two");
}
{
SortedArrayMap<int, String> m;
m(1, "one")(2, "two");
DDUMPM(m);
ASSERT(m.Get(1) == "one");
ASSERT(m.Get(2) == "two");
}
{
ValueMap m;
m(1, "one")(2, "two");
DDUMP(m);
ASSERT(m[1] == "one");
ASSERT(m[2] == "two");
}
}

9
autotest/Maps/Maps.upp Normal file
View file

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

4
autotest/Maps/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _Maps_icpp_init_stub
#define _Maps_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";

View file

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

View file

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

View file

@ -0,0 +1,31 @@
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
double d = 0;
ASSERT(!IsNaN(d));
ASSERT(!IsInf(d));
ASSERT(IsFin(d));
d = sqrt(StrDbl("-1.0"));
ASSERT(IsNaN(d));
ASSERT(!IsInf(d));
ASSERT(!IsFin(d));
d = 1e300;
d *= d;
ASSERT(!IsNaN(d));
ASSERT(IsInf(d));
ASSERT(!IsFin(d));
d = 1e300;
d *= -d;
ASSERT(!IsNaN(d));
ASSERT(IsInf(d));
ASSERT(!IsFin(d));
LOG("Everything OK");
}

4
autotest/NaNINF/init Normal file
View file

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

View file

@ -0,0 +1,64 @@
#include <Core/Core.h>
using namespace Upp;
// WARNING: 64-bit OS and 8GB RAM required to run this test
String RandomString(int maxlen = 70)
{
int len = Random(maxlen);
String h;
for(int i = 0; i < len; i++)
h.Cat(Random(26) + 'a');
return h;
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
MemoryLimitKb(8000000);
for(int sz = 0; sz < 2; sz++) {
for(int pass = 0; pass < 2; pass++) {
LOG("--------------------");
DUMP(sz);
DUMP(pass);
{
NanoStrings ns;
Vector<dword> ws;
ns.ZeroTerminated(sz);
SeedRandom();
for(int i = 0; i < 140000000; i++) {
if(i % 10000000 == 0)
RLOG("Created " << i);
String s = pass ? "x" : RandomString(Random(4) ? 5 : 50);
ws.Add(ns.Add(s));
}
ns.DumpProfile();
LOG("---- Strings " << MemoryUsedKb() << " KB used -------");
LOG(MemoryProfile());
SeedRandom();
for(int i = 0; i < ws.GetCount(); i++) {
if(i % 10000000 == 0)
RLOG("Tested " << i);
String s = pass ? "x" : RandomString(Random(4) ? 5 : 50);
if((sz ? String(ns.GetPtr(ws[i])) : ns.Get(ws[i])) != s) {
DUMP(i);
DUMP(ns.Get(ws[i]));
DUMP(s);
NEVER();
}
}
LOG("Test OK");
}
LOG("===== EMPTY " << MemoryUsedKb() << " KB used -------");
LOG(MemoryProfile());
}
}
LOG("============ Everything OK ===================");
}

View file

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

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