diff --git a/upptst/FixedMap/FixedMap.cpp b/upptst/FixedMap/FixedMap.cpp new file mode 100644 index 000000000..b1da57587 --- /dev/null +++ b/upptst/FixedMap/FixedMap.cpp @@ -0,0 +1,54 @@ +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_FILE|LOG_COUT); + + FixedVectorMap 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 =========="); +} diff --git a/upptst/FixedMap/FixedMap.upp b/upptst/FixedMap/FixedMap.upp new file mode 100644 index 000000000..3da2daf9e --- /dev/null +++ b/upptst/FixedMap/FixedMap.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + FixedMap.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/upptst/FixedMap/init b/upptst/FixedMap/init new file mode 100644 index 000000000..5696884ef --- /dev/null +++ b/upptst/FixedMap/init @@ -0,0 +1,4 @@ +#ifndef _FixedMap_icpp_init_stub +#define _FixedMap_icpp_init_stub +#include "Core/init" +#endif diff --git a/upptst/Heap/Heap.upp b/upptst/Heap/Heap.upp index a7545e4c7..46d6d1bb3 100644 --- a/upptst/Heap/Heap.upp +++ b/upptst/Heap/Heap.upp @@ -1,9 +1,9 @@ -uses - Core; - -file - Heap.cpp; - -mainconfig - "" = ""; - +uses + Core; + +file + Heap.cpp; + +mainconfig + "" = ""; + diff --git a/upptst/Heap/init b/upptst/Heap/init new file mode 100644 index 000000000..d73c1c295 --- /dev/null +++ b/upptst/Heap/init @@ -0,0 +1,4 @@ +#ifndef _Heap_icpp_init_stub +#define _Heap_icpp_init_stub +#include "Core/init" +#endif diff --git a/upptst/NanoStrings/NanoStrings.cpp b/upptst/NanoStrings/NanoStrings.cpp new file mode 100644 index 000000000..67bdd5eb0 --- /dev/null +++ b/upptst/NanoStrings/NanoStrings.cpp @@ -0,0 +1,64 @@ +#include + +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 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 ==================="); +} diff --git a/upptst/NanoStrings/NanoStrings.upp b/upptst/NanoStrings/NanoStrings.upp new file mode 100644 index 000000000..c68a845a8 --- /dev/null +++ b/upptst/NanoStrings/NanoStrings.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + NanoStrings.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/upptst/NanoStrings/init b/upptst/NanoStrings/init new file mode 100644 index 000000000..f37ac1698 --- /dev/null +++ b/upptst/NanoStrings/init @@ -0,0 +1,4 @@ +#ifndef _NanoStrings_icpp_init_stub +#define _NanoStrings_icpp_init_stub +#include "Core/init" +#endif diff --git a/upptst/ize/ize.cpp b/upptst/ize/ize.cpp index bff2a40e9..d7d3f347a 100644 --- a/upptst/ize/ize.cpp +++ b/upptst/ize/ize.cpp @@ -53,6 +53,20 @@ void TestMap() Test(data); } +template +void TestFixedMap() +{ + T data; + + data.Add(1, typeid(T).name()); + data.Add(2, "123"); + data.Add(3, "433"); + + data.Finish(); + + Test(data); +} + CONSOLE_APP_MAIN { StdLogSetup(LOG_FILE|LOG_COUT); @@ -90,5 +104,11 @@ CONSOLE_APP_MAIN TestMap< SortedArrayMap >(); TestMap< WithDeepCopy< SortedArrayMap > >(); + TestFixedMap< FixedVectorMap >(); + TestFixedMap< WithDeepCopy< FixedVectorMap > >(); + + TestFixedMap< FixedArrayMap >(); + TestFixedMap< WithDeepCopy< FixedArrayMap > >(); + LOG("========= EVERYTHING OK =========="); }