upptst: Ref, S_type

git-svn-id: svn://ultimatepp.org/upp/trunk@6518 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-11-03 14:36:22 +00:00
parent 96f6065632
commit 21d1af382d
5 changed files with 155 additions and 1 deletions

View file

@ -16,10 +16,45 @@ void TestRef(const T& x)
ref.SetNull();
ASSERT(IsNull(a));
ASSERT(ref.IsNull());
ref.Get<T>() = x;
ASSERT(!IsNull(a));
ASSERT(!ref.IsNull());
ref.SetValue(Null);
ASSERT(IsNull(a));
ASSERT(ref.IsNull());
ref.Get<T>() = x;
ASSERT(!IsNull(a));
ref = Null;
ASSERT(IsNull(a));
ASSERT(ref.IsNull());
ref.Get<T>() = x;
ASSERT(!IsNull(a));
ref = (Value)Null;
ASSERT(IsNull(a));
ASSERT(ref.IsNull());
}
DUMP(ref.GetType());
DUMP(GetValueTypeNo<T>());
ASSERT(ref.GetType() == GetValueTypeNo<T>());
ASSERT(ref.Is<T>());
T b;
Ref r2(b);
T& f = r2.Get<T>();
f = x;
ASSERT(x == b);
r2.Get<T>() = x;
ASSERT(x == b);
LOG("-------------------");
}
@ -33,10 +68,32 @@ CONSOLE_APP_MAIN
TestRef(123);
TestRef(123.456);
TestRef((int64)123);
TestRef(Value("hello Value!"));
TestRef(ValueMap()("key1", 1)("key2", 2));
TestRef(ValueArray() << "v1" << "v2");
TestRef(Blue());
TestRef(Rect(1, 2, 3, 4));
String text;
Ref textref(text);
textref = "TEST";
DUMP(text);
ASSERT(text == "TEST");
int x;
Ref ref(x);
ref.SetValue(1.0);
DLOG(x);
DUMP(x);
ASSERT(x == 1);
Ref empty;
DUMP(empty.GetValue());
DUMP(empty.IsNull());
DUMP(IsNull(empty.GetValue()));
DUMP(~empty);
}

64
upptst/S_type/S_type.cpp Normal file
View file

@ -0,0 +1,64 @@
#include <Sql/Sql.h>
using namespace Upp;
#define SCHEMADIALECT <plugin/sqlite3/S_type.h>
#define MODEL <Sqlite3Bug/Sqlite3bug.sch>
#include <Sql/sch_header.h>
#include <Sql/sch_source.h>
#include <Sql/sch_schema.h>
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
S_TEST test;
test.GetRef(TEXT) = "Hello!";
test.GetRef(TEXT1) = "text1!";
DUMP(test.Get(TEXT));
DUMP(test.Get());
DUMP(test);
S_TEST test2 = test;
ASSERT(test2 == test);
ASSERT(test2.Get() == test.Get());
test2.NUMBER = 1;
ASSERT(test2 != test);
ASSERT(test2.Get() != test.Get());
LOG("------------------------");
{
ValueMap m;
test.Clear();
DUMP(test);
for(int i = 0; i < test.GetCount(); i++) {
ASSERT(IsNull(test.Get(i)));
Ref f = test.GetRef(i);
Value v;
if(f.Is<int>())
v = i + 1000;
else
v = "text " + AsString(i);
m.Add(test.GetId(i), v);
test.Set(i, v);
}
DUMP(test);
DUMP(test.Get());
ASSERT(test.Get() == m);
}
LOG("------------------------");
ASSERT(test.Get(TEST).IsVoid());
ValueMap m;
m(TEXT, "texttest")(NUMBER1, 123456)(A[2], 10);
test.Set(m);
DUMP(test);
test = m;
DUMP(test);
DDUMPC(S_TEST::GetColumnIds());
DDUMP(SqlCompile(SQLITE3, ~S_TEST::ColumnSet()));
DDUMP(SqlCompile(SQLITE3, ~S_TEST::ColumnSet("PREFIX_")));
DDUMP(SqlCompile(SQLITE3, ~S_TEST::Of("TABLE")));
}

15
upptst/S_type/S_type.sch Normal file
View file

@ -0,0 +1,15 @@
TABLE_ (BASE1)
INT_ (NUMBER1)
STRING_ (TEXT1, 200)
INT_ARRAY_ (A, 5)
END_TABLE
TABLE_ (BASE2)
INT_ (NUMBER2)
STRING_ (TEXT2, 200)
END_TABLE
TABLE_II_ (TEST, BASE1, BASE2)
INT_ (NUMBER)
STRING_ (TEXT, 200)
END_TABLE

13
upptst/S_type/S_type.upp Normal file
View file

@ -0,0 +1,13 @@
description "Demonstrates a possible bug in Sqlite 3 interface\377";
uses
Sql,
plugin/sqlite3;
file
S_type.sch,
S_type.cpp;
mainconfig
"" = "";

5
upptst/S_type/init Normal file
View file

@ -0,0 +1,5 @@
#ifndef _S_type_icpp_init_stub
#define _S_type_icpp_init_stub
#include "Sql/init"
#include "plugin/sqlite3/init"
#endif