summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/common/VariantReaderTest.cpp65
-rw-r--r--test/core/managed/ManagedTest.cpp36
-rw-r--r--test/core/managed/RttiTest.cpp63
-rw-r--r--test/core/model/TypesystemTest.cpp104
4 files changed, 240 insertions, 28 deletions
diff --git a/test/core/common/VariantReaderTest.cpp b/test/core/common/VariantReaderTest.cpp
index 7972374..3d4e7bd 100644
--- a/test/core/common/VariantReaderTest.cpp
+++ b/test/core/common/VariantReaderTest.cpp
@@ -60,6 +60,71 @@ TEST(VariantReader, readString)
ASSERT_TRUE(res.first);
ASSERT_EQ("'\"\b\f\n\r\t\v", res.second);
}
+
+
+ // Hex Unicode character
+ {
+ CharReader reader("'linebreak\\u000A in unicode'");
+ auto res = VariantReader::parseString(reader, logger, {';'});
+ ASSERT_TRUE(res.first);
+ ASSERT_EQ("linebreak\n in unicode", res.second);
+ }
+}
+
+TEST(VariantReader, readStringUnicode)
+{
+ // Hex Unicode character
+ {
+ CharReader reader("'linebreak \\u000A in unicode'");
+ auto res = VariantReader::parseString(reader, logger, {';'});
+ ASSERT_TRUE(res.first);
+ ASSERT_EQ("linebreak \n in unicode", res.second);
+ }
+
+ // Hex Unicode character
+ {
+ CharReader reader("'hammer and sickle \\u262D in unicode'");
+ auto res = VariantReader::parseString(reader, logger, {';'});
+ ASSERT_TRUE(res.first);
+ ASSERT_EQ("hammer and sickle \342\230\255 in unicode", res.second);
+ }
+
+ // Octal Latin-1 character
+ {
+ CharReader reader("'copyright symbol \\251 in Unicode'");
+ auto res = VariantReader::parseString(reader, logger, {';'});
+ ASSERT_TRUE(res.first);
+ ASSERT_EQ("copyright symbol \302\251 in Unicode", res.second);
+ }
+
+ // Hexadecimal Latin-1 character
+ {
+ CharReader reader("'copyright symbol \\xA9 in Unicode'");
+ auto res = VariantReader::parseString(reader, logger, {';'});
+ ASSERT_TRUE(res.first);
+ ASSERT_EQ("copyright symbol \302\251 in Unicode", res.second);
+ }
+
+ // Errornous unicode escape sequence
+ {
+ CharReader reader("'\\uBLUB'");
+ auto res = VariantReader::parseString(reader, logger, {';'});
+ ASSERT_FALSE(res.first);
+ }
+
+ // Errornous octal escape sequence
+ {
+ CharReader reader("'\\400'");
+ auto res = VariantReader::parseString(reader, logger, {';'});
+ ASSERT_FALSE(res.first);
+ }
+
+ // Errornous hexadecimal latin1 escape sequence
+ {
+ CharReader reader("'\\xa'");
+ auto res = VariantReader::parseString(reader, logger, {';'});
+ ASSERT_FALSE(res.first);
+ }
}
TEST(VariantReader, parseUnescapedString)
diff --git a/test/core/managed/ManagedTest.cpp b/test/core/managed/ManagedTest.cpp
index f196770..c88cf7a 100644
--- a/test/core/managed/ManagedTest.cpp
+++ b/test/core/managed/ManagedTest.cpp
@@ -75,33 +75,10 @@ class TypeTestManaged5 : public Managed {
using Managed::Managed;
};
-ManagedType Type1("Type1", typeid(TypeTestManaged1));
-ManagedType Type2("Type2", typeid(TypeTestManaged2));
-ManagedType Type3("Type3", typeid(TypeTestManaged3), {&Type1});
-ManagedType Type4("Type2", typeid(TypeTestManaged4), {&Type3, &Type2});
-
-TEST(ManagedType, isa)
-{
- ASSERT_TRUE(Type1.isa(Type1));
- ASSERT_FALSE(Type1.isa(Type2));
- ASSERT_FALSE(Type1.isa(Type3));
- ASSERT_FALSE(Type1.isa(Type4));
-
- ASSERT_FALSE(Type2.isa(Type1));
- ASSERT_TRUE(Type2.isa(Type2));
- ASSERT_FALSE(Type2.isa(Type3));
- ASSERT_FALSE(Type2.isa(Type4));
-
- ASSERT_TRUE(Type3.isa(Type1));
- ASSERT_FALSE(Type3.isa(Type2));
- ASSERT_TRUE(Type3.isa(Type3));
- ASSERT_FALSE(Type3.isa(Type4));
-
- ASSERT_TRUE(Type4.isa(Type1));
- ASSERT_TRUE(Type4.isa(Type2));
- ASSERT_TRUE(Type4.isa(Type3));
- ASSERT_TRUE(Type4.isa(Type4));
-}
+static const Rtti<TypeTestManaged1> Type1("Type1");
+static const Rtti<TypeTestManaged2> Type2("Type2");
+static const Rtti<TypeTestManaged3> Type3("Type3", {&Type1});
+static const Rtti<TypeTestManaged4> Type4("Type4", {&Type3, &Type2});
TEST(Managed, type)
{
@@ -117,7 +94,10 @@ TEST(Managed, type)
ASSERT_EQ(&Type2, &m2->type());
ASSERT_EQ(&Type3, &m3->type());
ASSERT_EQ(&Type4, &m4->type());
- ASSERT_EQ(&ManagedType::None, &m5->type());
+ ASSERT_EQ(&RttiBase::None, &m5->type());
+
+ ASSERT_EQ(&Type1, &typeOf<TypeTestManaged1>());
+ ASSERT_EQ(&Type1, &typeOf(*m1));
}
}
diff --git a/test/core/managed/RttiTest.cpp b/test/core/managed/RttiTest.cpp
new file mode 100644
index 0000000..091bdea
--- /dev/null
+++ b/test/core/managed/RttiTest.cpp
@@ -0,0 +1,63 @@
+/*
+ Ousía
+ Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <array>
+#include <string>
+#include <iostream>
+
+#include <gtest/gtest.h>
+
+#include <core/managed/Rtti.hpp>
+
+namespace ousia {
+
+class RttiTestClass1 {};
+class RttiTestClass2 {};
+class RttiTestClass3 {};
+class RttiTestClass4 {};
+
+static const Rtti<RttiTestClass1> Type1("Type1");
+static const Rtti<RttiTestClass2> Type2("Type2");
+static const Rtti<RttiTestClass3> Type3("Type3", {&Type1});
+static const Rtti<RttiTestClass4> Type4("Type4", {&Type3, &Type2});
+
+TEST(Rtti, isa)
+{
+ ASSERT_TRUE(Type1.isa(Type1));
+ ASSERT_FALSE(Type1.isa(Type2));
+ ASSERT_FALSE(Type1.isa(Type3));
+ ASSERT_FALSE(Type1.isa(Type4));
+
+ ASSERT_FALSE(Type2.isa(Type1));
+ ASSERT_TRUE(Type2.isa(Type2));
+ ASSERT_FALSE(Type2.isa(Type3));
+ ASSERT_FALSE(Type2.isa(Type4));
+
+ ASSERT_TRUE(Type3.isa(Type1));
+ ASSERT_FALSE(Type3.isa(Type2));
+ ASSERT_TRUE(Type3.isa(Type3));
+ ASSERT_FALSE(Type3.isa(Type4));
+
+ ASSERT_TRUE(Type4.isa(Type1));
+ ASSERT_TRUE(Type4.isa(Type2));
+ ASSERT_TRUE(Type4.isa(Type3));
+ ASSERT_TRUE(Type4.isa(Type4));
+}
+
+}
+
diff --git a/test/core/model/TypesystemTest.cpp b/test/core/model/TypesystemTest.cpp
new file mode 100644
index 0000000..9939adf
--- /dev/null
+++ b/test/core/model/TypesystemTest.cpp
@@ -0,0 +1,104 @@
+/*
+ Ousía
+ Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <gtest/gtest.h>
+
+#include <iostream>
+
+#include <core/model/Typesystem.hpp>
+
+namespace ousia {
+namespace model {
+
+TEST(Type, rtti)
+{
+ Manager mgr(1);
+ Rooted<StringType> strType{new StringType(mgr, nullptr)};
+
+ ASSERT_TRUE(typeOf(*strType).isa(typeOf<Type>()));
+}
+
+TEST(StringType, creation)
+{
+ Manager mgr(1);
+ Rooted<StringType> strType{new StringType(mgr, nullptr)};
+
+ Variant val = strType->create();
+ ASSERT_TRUE(val.isString());
+ ASSERT_EQ("", val.asString());
+}
+
+TEST(StringType, conversion)
+{
+ Logger logger;
+ Manager mgr(1);
+ Rooted<StringType> strType{new StringType(mgr, nullptr)};
+
+ {
+ Variant val{42};
+ ASSERT_TRUE(strType->build(val, logger));
+ ASSERT_TRUE(val.isString());
+ ASSERT_EQ("42", val.asString());
+ }
+
+ {
+ Variant val{42.5};
+ ASSERT_TRUE(strType->build(val, logger));
+ ASSERT_TRUE(val.isString());
+ ASSERT_EQ("42.5", val.asString());
+ }
+
+ {
+ Variant val{true};
+ ASSERT_TRUE(strType->build(val, logger));
+ ASSERT_TRUE(val.isString());
+ ASSERT_EQ("true", val.asString());
+ }
+
+ {
+ Variant val{false};
+ ASSERT_TRUE(strType->build(val, logger));
+ ASSERT_TRUE(val.isString());
+ ASSERT_EQ("false", val.asString());
+ }
+
+ {
+ Variant val{nullptr};
+ ASSERT_TRUE(strType->build(val, logger));
+ ASSERT_TRUE(val.isString());
+ ASSERT_EQ("null", val.asString());
+ }
+
+ {
+ Variant val{"test"};
+ ASSERT_TRUE(strType->build(val, logger));
+ ASSERT_TRUE(val.isString());
+ ASSERT_EQ("test", val.asString());
+ }
+
+ {
+ Variant val{{1, 2, true, false}};
+ ASSERT_FALSE(strType->build(val, logger));
+ ASSERT_TRUE(val.isString());
+ ASSERT_EQ("", val.asString());
+ }
+
+}
+
+}
+}