From 5b7638d9f48aa6230e4f55c0349b40f2aafd554c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 25 Dec 2015 14:46:39 +0100 Subject: [PATCH] More CBot tests --- test/unit/CBot/CBot.cpp | 108 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 4 deletions(-) diff --git a/test/unit/CBot/CBot.cpp b/test/unit/CBot/CBot.cpp index 040904e2..35964419 100644 --- a/test/unit/CBot/CBot.cpp +++ b/test/unit/CBot/CBot.cpp @@ -389,6 +389,44 @@ TEST_F(CBotUT, BasicOperations) ); } +TEST_F(CBotUT, VarBasic) +{ + ExecuteTest( + "extern void VarBasic()\n" + "{\n" + " int a = 5;\n" + " ASSERT(a == 5);\n" + " int b = 3;\n" + " ASSERT(b == 3);\n" + " b = a;\n" + " ASSERT(b == 5);\n" + " ASSERT(b == a);\n" + " b = a + b;\n" + " ASSERT(b == 10);\n" + " ASSERT(b == 2*a);\n" + "}\n" + ); +} + +TEST_F(CBotUT, VarDefinitions) +{ + ExecuteTest( + "extern void TestUndefined()\n" + "{\n" + " ASSERT(a == 0);\n" + "}\n", + CBotErrUndefVar + ); + ExecuteTest( + "extern void TestRedefined()\n" + "{\n" + " int a = 5;\n" + " int a = 3;\n" + "}\n", + CBotErrRedefVar + ); +} + TEST_F(CBotUT, Functions) { ExecuteTest( @@ -439,21 +477,38 @@ TEST_F(CBotUT, FunctionRecursionStackOverflow) TEST_F(CBotUT, FunctionOverloading) { ExecuteTest( - "void func(int test)\n" + "int func(string test)\n" "{\n" - " FAIL();\n" + " return 1;\n" "}\n" - "void func(string test)\n" + "int func(int test)\n" "{\n" + " return 2;\n" "}\n" "\n" "extern void FunctionOverloading()\n" "{\n" - " func(\"5\");\n" + " ASSERT(func(\"5\") == 1);\n" + " ASSERT(func(5) == 2);\n" "}\n" ); } +TEST_F(CBotUT, FunctionRedefined) +{ + ExecuteTest( + "int func(int test)\n" + "{\n" + " return 1;\n" + "}\n" + "int func(int test)\n" + "{\n" + " return 2;\n" + "}\n", + CBotErrRedefFunc + ); +} + TEST_F(CBotUT, ClassConstructor) { ExecuteTest( @@ -526,3 +581,48 @@ TEST_F(CBotUT, DISABLED_ClassDestructorNaming) static_cast(-1) ); } + +// TODO: This doesn't work +TEST_F(CBotUT, DISABLED_ClassMethodOverloading) +{ + ExecuteTest( + "public class TestClass {\n" + " public int test(string test) {\n" + " return 1;\n" + " }\n" + " public int test(int test) {\n" + " return 2;" + " }\n" + "}\n" + "extern void ClassMethodOverloading() {\n" + " TestClass t();\n" + " ASSERT(t.test(\"5\") == 1);\n" + " ASSERT(t.test(5) == 2);\n" + "}\n" + ); +} + +TEST_F(CBotUT, ClassMethodRedefined) +{ + ExecuteTest( + "public class TestClass {\n" + " public int test(string test) {\n" + " return 1;\n" + " }\n" + " public int test(string test) {\n" + " return 2;" + " }\n" + "}\n", + CBotErrRedefFunc + ); +} + +// TODO: Not only doesn't work but segfaults +TEST_F(CBotUT, DISABLED_ClassRedefined) +{ + ExecuteTest( + "public class TestClass {}\n" + "public class TestClass {}\n", + CBotErrRedefClass + ); +} \ No newline at end of file