[colobot] 185/377: Added ASSERT() to CBot unit tests
Didier Raboud
odyx at moszumanska.debian.org
Wed Mar 30 13:34:14 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit a18c2c39d9af0a417ed3ccd12231083d2f0f1cff
Author: krzys-h <krzys_h at interia.pl>
Date: Wed Dec 23 21:08:30 2015 +0100
Added ASSERT() to CBot unit tests
---
test/unit/CBot/CBot.cpp | 64 +++++++++++++++++++++++++++++++++++++------------
1 file changed, 49 insertions(+), 15 deletions(-)
diff --git a/test/unit/CBot/CBot.cpp b/test/unit/CBot/CBot.cpp
index e908a78..6ebbb13 100644
--- a/test/unit/CBot/CBot.cpp
+++ b/test/unit/CBot/CBot.cpp
@@ -28,6 +28,7 @@ public:
{
CBotProgram::Init();
CBotProgram::AddFunction("FAIL", rFail, cFail);
+ CBotProgram::AddFunction("ASSERT", rAssert, cAssert);
}
void TearDown()
@@ -74,6 +75,24 @@ private:
throw CBotTestFail(message);
}
+ static CBotTypResult cAssert(CBotVar* &var, void* user)
+ {
+ if (var == nullptr) return CBotTypResult(CBotErrLowParam);
+ if (var->GetType() != CBotTypBoolean) return CBotTypResult(CBotErrBadString);
+ var = var->GetNext();
+ return CBotTypResult(CBotTypVoid);
+ }
+
+ static bool rAssert(CBotVar* var, CBotVar* result, int& exception, void* user)
+ {
+ bool status = var->GetValInt();
+ if (!status)
+ {
+ throw CBotTestFail("CBot assertion failed");
+ }
+ return true;
+ }
+
// Modified version of PutList from src/script/script.cpp
// Should be probably moved somewhere into the CBot library
void PrintVars(std::stringstream& ss, CBotVar* var, const std::string& baseName = "", bool bArray = false)
@@ -219,7 +238,7 @@ protected:
}
};
-TEST_F(CBotUT, Test)
+TEST_F(CBotUT, EmptyTest)
{
ExecuteTest(
"extern void EmptyTest()"
@@ -228,20 +247,6 @@ TEST_F(CBotUT, Test)
);
}
-TEST_F(CBotUT, DISABLED_TestFail)
-{
- ExecuteTest(
- "extern void FailingTest()"
- "{"
- " FAIL();"
- "}"
- "extern void AnotherFailingTest()"
- "{"
- " FAIL(\"This is a message\");"
- "}"
- );
-}
-
TEST_F(CBotUT, DivideByZero)
{
ExecuteTest(
@@ -273,4 +278,33 @@ TEST_F(CBotUT, UndefinedFunction)
"}",
CBotErrUndefCall
);
+}
+
+TEST_F(CBotUT, BasicOperations)
+{
+ ExecuteTest(
+ "extern void Comparations()"
+ "{"
+ " ASSERT(true);"
+ " ASSERT(!false);"
+ " ASSERT(1 != 0);"
+ " ASSERT(1 == 1);"
+ " ASSERT(1 > 0);"
+ " ASSERT(1 >= 0);"
+ " ASSERT(1 >= 1);"
+ " ASSERT(0 < 1);"
+ " ASSERT(0 <= 1);"
+ " ASSERT(1 <= 1);"
+ "}"
+ ""
+ "extern void BasicMath()"
+ "{"
+ " ASSERT(2+2 == 4);"
+ " ASSERT(4-2 == 2);"
+ " ASSERT(2*2 == 4);"
+ " ASSERT(2/2 == 1);"
+ " ASSERT(5%2 == 1);"
+ " ASSERT(5**3 == 125);"
+ "}"
+ );
}
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list