From 9ebe4f0b90a7217e479c656209e87ab6292662d5 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Mon, 22 Dec 2014 18:45:44 +0100 Subject: added unit tests and documentation for the IntType class --- test/core/model/TypesystemTest.cpp | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/core/model/TypesystemTest.cpp b/test/core/model/TypesystemTest.cpp index 4c57431..b388fe0 100644 --- a/test/core/model/TypesystemTest.cpp +++ b/test/core/model/TypesystemTest.cpp @@ -103,6 +103,47 @@ TEST(StringType, conversion) } } +/* Class IntType */ + +TEST(IntType, rtti) +{ + Manager mgr; + Rooted intType{new IntType(mgr, nullptr)}; + ASSERT_TRUE(intType->isa(RttiTypes::IntType)); + ASSERT_TRUE(intType->isa(typeOf())); + ASSERT_TRUE(intType->isa(typeOf())); +} + +TEST(IntType, creation) +{ + Manager mgr; + Rooted intType{new IntType(mgr, nullptr)}; + Variant val = intType->create(); + ASSERT_TRUE(val.isInt()); + ASSERT_EQ(0, val.asInt()); +} + +TEST(IntType, conversion) +{ + Logger logger; + Manager mgr; + Rooted intType{new IntType(mgr, nullptr)}; + + { + Variant val{314}; + ASSERT_TRUE(intType->build(val, logger)); + ASSERT_TRUE(val.isInt()); + ASSERT_EQ(314, val.asInt()); + } + + { + Variant val{"1"}; + ASSERT_FALSE(intType->build(val, logger)); + ASSERT_TRUE(val.isInt()); + ASSERT_EQ(0, val.asInt()); + } +} + /* Class ArrayType */ TEST(ArrayType, rtti) @@ -123,6 +164,7 @@ TEST(ArrayType, creation) Variant val = arrayType->create(); ASSERT_TRUE(val.isArray()); + ASSERT_TRUE(val.asArray().empty()); } TEST(ArrayType, conversion) @@ -152,7 +194,7 @@ TEST(ArrayType, conversion) Variant val{1}; ASSERT_FALSE(arrayType->build(val, logger)); ASSERT_TRUE(val.isArray()); - ASSERT_EQ(0U, val.asArray().size()); + ASSERT_TRUE(val.asArray().empty()); } } -- cgit v1.2.3