diff options
| author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-10-25 21:23:38 +0000 |
|---|---|---|
| committer | andreas <andreas@daaaf23c-2e50-4459-9457-1e69db5a47bf> | 2014-10-25 21:23:38 +0000 |
| commit | 250d6a4dbe61b6798cd090abeabdc0ece8237dd3 (patch) | |
| tree | 05a15d388c8b8444b6ddd4c6806cd4f66169c2a0 /test/core/script/Variant.cpp | |
| parent | dbb94be50c67ce2d4a132b0811c2a8dac825b49b (diff) | |
some restructuring, added first version of the mozjs plugin
git-svn-id: file:///var/local/svn/basicwriter@78 daaaf23c-2e50-4459-9457-1e69db5a47bf
Diffstat (limited to 'test/core/script/Variant.cpp')
| -rw-r--r-- | test/core/script/Variant.cpp | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/test/core/script/Variant.cpp b/test/core/script/Variant.cpp deleted file mode 100644 index f229e3a..0000000 --- a/test/core/script/Variant.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - 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 <core/script/Variant.hpp> -#include <core/script/Function.hpp> -#include <core/script/Object.hpp> - -namespace ousia { -namespace script { - -TEST(Variant, getBooleanValue) -{ - ASSERT_TRUE((Variant{true}).getBooleanValue()); - ASSERT_FALSE((Variant{false}).getBooleanValue()); - ASSERT_FALSE((Variant{(int64_t)0}).getBooleanValue()); - ASSERT_TRUE((Variant{(int64_t)1}).getBooleanValue()); - ASSERT_FALSE((Variant{0.0}).getBooleanValue()); - ASSERT_TRUE((Variant{1.2}).getBooleanValue()); - ASSERT_FALSE((Variant{""}).getBooleanValue()); -} - -TEST(Variant, getIntegerValue) -{ - Variant vi{(int64_t)42}; - Variant vf{42.0}; - - ASSERT_EQ(42, vi.getIntegerValue()); - ASSERT_EQ(42, vf.getIntegerValue()); - ASSERT_EQ(1, (Variant{true}).getIntegerValue()); - ASSERT_EQ(0, (Variant{false}).getIntegerValue()); -} - -TEST(Variant, getNumberValue) -{ - Variant vi{(int64_t)42}; - Variant vf{42.5}; - - ASSERT_EQ(42, vi.getNumberValue()); - ASSERT_EQ(42.5, vf.getNumberValue()); - ASSERT_EQ(1.0, (Variant{true}).getIntegerValue()); - ASSERT_EQ(0.0, (Variant{false}).getIntegerValue()); -} - -TEST(Variant, getStringValue) -{ - Variant v{"hello world"}; - ASSERT_EQ("hello world", v.getStringValue()); -} - -TEST(Variant, getArrayValue) -{ - Variant v{{"test1", (int64_t)42}}; - ASSERT_EQ(2, v.getArrayValue().size()); - ASSERT_EQ("test1", v.getArrayValue()[0].getStringValue()); - ASSERT_EQ(42, v.getArrayValue()[1].getIntegerValue()); -} - -TEST(Variant, getMapValue) -{ - Variant v{{{"key1", "entry1"}, {"key2", "entry2"}}}; - - auto map = v.getMapValue(); - ASSERT_EQ(2, map.size()); - - ASSERT_EQ("entry1", (*map.find("key1")).second.getStringValue()); - ASSERT_EQ("entry2", (*map.find("key2")).second.getStringValue()); -} - -TEST(Variant, getFunctionValue) -{ - int64_t i = 0; - HostFunction f{[](const std::vector<Variant> &args, void *data) { - *((int64_t*)data) = args[0].getIntegerValue(); - return Variant{"Hello World"}; - }, &i}; - - Variant v{&f}; - ASSERT_TRUE(v.getFunctionValue() != nullptr); - ASSERT_EQ("Hello World", v.getFunctionValue()->call({{(int64_t)42}}).getStringValue()); - ASSERT_EQ(42, i); -} - - -} -} - |
