diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6513b90e8..c62a8bea4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -113,6 +113,7 @@ if (GTEST_FOUND AND GMOCK_FOUND) aul/AulTest.cpp aul/AulTest.h aul/AulMathTest.cpp + aul/AulPredefinedFunctionTest.cpp ../src/script/C4ScriptStandaloneStubs.cpp LIBRARIES libmisc diff --git a/tests/aul/AulMathTest.cpp b/tests/aul/AulMathTest.cpp index e7433c127..1130823a9 100644 --- a/tests/aul/AulMathTest.cpp +++ b/tests/aul/AulMathTest.cpp @@ -21,13 +21,7 @@ #include "script/C4Aul.h" class AulMathTest : public AulTest -{ -protected: - static const C4Value C4VINT_MIN; - static const C4Value C4VINT_MAX; -}; -const C4Value AulMathTest::C4VINT_MIN = C4VInt(-2147483647 - 1); -const C4Value AulMathTest::C4VINT_MAX = C4VInt(2147483647); +{}; TEST_F(AulMathTest, Addition) { diff --git a/tests/aul/AulPredefinedFunctionTest.cpp b/tests/aul/AulPredefinedFunctionTest.cpp new file mode 100644 index 000000000..5be911421 --- /dev/null +++ b/tests/aul/AulPredefinedFunctionTest.cpp @@ -0,0 +1,54 @@ +/* +* OpenClonk, http://www.openclonk.org +* +* Copyright (c) 2016, The OpenClonk Team and contributors +* +* Distributed under the terms of the ISC license; see accompanying file +* "COPYING" for details. +* +* "Clonk" is a registered trademark of Matthes Bender, used with permission. +* See accompanying file "TRADEMARK" for details. +* +* To redistribute this file separately, substitute the full license texts +* for the above references. +*/ + +// Testing behaviour of some predefined C4Script functions. + +#include "C4Include.h" +#include "AulTest.h" + +#include "script/C4Aul.h" + +class AulPredefFunctionTest : public AulTest +{}; + +TEST_F(AulPredefFunctionTest, Min) +{ + EXPECT_EQ(C4VInt(0), RunExpr("Min(0, 1)")); + EXPECT_EQ(C4VInt(0), RunExpr("Min(1, 0)")); + + EXPECT_EQ(C4VInt(-1), RunExpr("Min(-1, 0)")); + EXPECT_EQ(C4VInt(-1), RunExpr("Min(0, -1)")); + + EXPECT_EQ(C4VINT_MIN, RunExpr("Min(-2147483648, 0)")); + EXPECT_EQ(C4VINT_MIN, RunExpr("Min(0, -2147483648)")); + + EXPECT_EQ(C4VInt(0), RunExpr("Min(2147483647, 0)")); + EXPECT_EQ(C4VInt(0), RunExpr("Min(0, 2147483647)")); +} + +TEST_F(AulPredefFunctionTest, Max) +{ + EXPECT_EQ(C4VInt(1), RunExpr("Max(0, 1)")); + EXPECT_EQ(C4VInt(1), RunExpr("Max(1, 0)")); + + EXPECT_EQ(C4VInt(0), RunExpr("Max(-1, 0)")); + EXPECT_EQ(C4VInt(0), RunExpr("Max(0, -1)")); + + EXPECT_EQ(C4VInt(0), RunExpr("Max(-2147483648, 0)")); + EXPECT_EQ(C4VInt(0), RunExpr("Max(0, -2147483648)")); + + EXPECT_EQ(C4VINT_MAX, RunExpr("Max(2147483647, 0)")); + EXPECT_EQ(C4VINT_MAX, RunExpr("Max(0, 2147483647)")); +} diff --git a/tests/aul/AulTest.cpp b/tests/aul/AulTest.cpp index 11ba1a321..6ac22b0a3 100644 --- a/tests/aul/AulTest.cpp +++ b/tests/aul/AulTest.cpp @@ -70,6 +70,9 @@ C4Value AulTest::RunExpr(const char *expr) return RunCode(code.c_str()); } +const C4Value AulTest::C4VINT_MIN = C4VInt(-2147483647 - 1); +const C4Value AulTest::C4VINT_MAX = C4VInt(2147483647); + TEST_F(AulTest, ValueReturn) { // Make sure primitive value returns work. diff --git a/tests/aul/AulTest.h b/tests/aul/AulTest.h index 082dbd78a..fb3c1e00f 100644 --- a/tests/aul/AulTest.h +++ b/tests/aul/AulTest.h @@ -31,6 +31,9 @@ class AulTest : public ::testing::Test protected: C4Value RunCode(const char *code, bool wrap = true); C4Value RunExpr(const char *expr); + + static const C4Value C4VINT_MIN; + static const C4Value C4VINT_MAX; }; namespace aul_test {