From 21d1af382df3decb9c50ef486c0c8f79a587f46a Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 3 Nov 2013 14:36:22 +0000 Subject: [PATCH] upptst: Ref, S_type git-svn-id: svn://ultimatepp.org/upp/trunk@6518 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- upptst/Ref/Ref.cpp | 59 +++++++++++++++++++++++++++++++++++- upptst/S_type/S_type.cpp | 64 ++++++++++++++++++++++++++++++++++++++++ upptst/S_type/S_type.sch | 15 ++++++++++ upptst/S_type/S_type.upp | 13 ++++++++ upptst/S_type/init | 5 ++++ 5 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 upptst/S_type/S_type.cpp create mode 100644 upptst/S_type/S_type.sch create mode 100644 upptst/S_type/S_type.upp create mode 100644 upptst/S_type/init diff --git a/upptst/Ref/Ref.cpp b/upptst/Ref/Ref.cpp index c648af74b..03505e7f9 100644 --- a/upptst/Ref/Ref.cpp +++ b/upptst/Ref/Ref.cpp @@ -16,10 +16,45 @@ void TestRef(const T& x) ref.SetNull(); ASSERT(IsNull(a)); ASSERT(ref.IsNull()); + + ref.Get() = x; + ASSERT(!IsNull(a)); + ASSERT(!ref.IsNull()); + ref.SetValue(Null); ASSERT(IsNull(a)); ASSERT(ref.IsNull()); + + ref.Get() = x; + ASSERT(!IsNull(a)); + + ref = Null; + ASSERT(IsNull(a)); + ASSERT(ref.IsNull()); + + ref.Get() = x; + ASSERT(!IsNull(a)); + + ref = (Value)Null; + ASSERT(IsNull(a)); + ASSERT(ref.IsNull()); } + + DUMP(ref.GetType()); + DUMP(GetValueTypeNo()); + ASSERT(ref.GetType() == GetValueTypeNo()); + + ASSERT(ref.Is()); + + T b; + Ref r2(b); + T& f = r2.Get(); + f = x; + ASSERT(x == b); + + r2.Get() = 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); } diff --git a/upptst/S_type/S_type.cpp b/upptst/S_type/S_type.cpp new file mode 100644 index 000000000..01c417a71 --- /dev/null +++ b/upptst/S_type/S_type.cpp @@ -0,0 +1,64 @@ +#include + +using namespace Upp; +#define SCHEMADIALECT +#define MODEL +#include +#include +#include + +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()) + 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"))); +} diff --git a/upptst/S_type/S_type.sch b/upptst/S_type/S_type.sch new file mode 100644 index 000000000..98680472b --- /dev/null +++ b/upptst/S_type/S_type.sch @@ -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 diff --git a/upptst/S_type/S_type.upp b/upptst/S_type/S_type.upp new file mode 100644 index 000000000..c49092816 --- /dev/null +++ b/upptst/S_type/S_type.upp @@ -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 + "" = ""; + diff --git a/upptst/S_type/init b/upptst/S_type/init new file mode 100644 index 000000000..71c49d9b2 --- /dev/null +++ b/upptst/S_type/init @@ -0,0 +1,5 @@ +#ifndef _S_type_icpp_init_stub +#define _S_type_icpp_init_stub +#include "Sql/init" +#include "plugin/sqlite3/init" +#endif