From e9e2852ce1d7b3cdbbcc115d63f1d4d0ab25457f Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 13:12:43 -0700 Subject: [PATCH] Fixed test asserts --- src/ByteBuffer.cpp | 3 -- src/CompositeChat.cpp | 62 ++++++++++++++++++++--------------------- src/CraftingRecipes.cpp | 2 ++ src/Globals.h | 7 +++-- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index ae4e72737..9d97d8614 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -46,9 +46,6 @@ #ifdef SELF_TEST -#define assert_test(x) ( !!(x) || \ - LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), abort(1)) - /// Self-test of the VarInt-reading and writing code static class cByteBufferSelfTest { diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp index 3eec35657..19ed30d78 100644 --- a/src/CompositeChat.cpp +++ b/src/CompositeChat.cpp @@ -32,15 +32,15 @@ public: cCompositeChat Msg; Msg.ParseText("Testing @2color codes and http://links parser"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 4); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[3]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == "@2"); - assert(Parts[2]->m_Style == "@2"); - assert(Parts[3]->m_Style == "@2"); + assert_test(Parts.size() == 4); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[3]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == "@2"); + assert_test(Parts[2]->m_Style == "@2"); + assert_test(Parts[3]->m_Style == "@2"); } void TestParser2(void) @@ -48,15 +48,15 @@ public: cCompositeChat Msg; Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 4); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[2]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[3]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == "@3"); - assert(Parts[1]->m_Style == "@5"); - assert(Parts[2]->m_Style == "@5"); - assert(Parts[3]->m_Style == "@5"); + assert_test(Parts.size() == 4); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[2]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[3]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == "@3"); + assert_test(Parts[1]->m_Style == "@5"); + assert_test(Parts[2]->m_Style == "@5"); + assert_test(Parts[3]->m_Style == "@5"); } void TestParser3(void) @@ -64,11 +64,11 @@ public: cCompositeChat Msg; Msg.ParseText("http://links.starting the text"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 2); - assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[1]->m_PartType == cCompositeChat::ptText); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == ""); + assert_test(Parts.size() == 2); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == ""); } void TestParser4(void) @@ -76,11 +76,11 @@ public: cCompositeChat Msg; Msg.ParseText("links finishing the text: http://some.server"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 2); - assert(Parts[0]->m_PartType == cCompositeChat::ptText); - assert(Parts[1]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[0]->m_Style == ""); - assert(Parts[1]->m_Style == ""); + assert_test(Parts.size() == 2); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptText); + assert_test(Parts[1]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[0]->m_Style == ""); + assert_test(Parts[1]->m_Style == ""); } void TestParser5(void) @@ -88,9 +88,9 @@ public: cCompositeChat Msg; Msg.ParseText("http://only.links"); const cCompositeChat::cParts & Parts = Msg.GetParts(); - assert(Parts.size() == 1); - assert(Parts[0]->m_PartType == cCompositeChat::ptUrl); - assert(Parts[0]->m_Style == ""); + assert_test(Parts.size() == 1); + assert_test(Parts[0]->m_PartType == cCompositeChat::ptUrl); + assert_test(Parts[0]->m_Style == ""); } } gTest; diff --git a/src/CraftingRecipes.cpp b/src/CraftingRecipes.cpp index 868182394..be9f45caa 100644 --- a/src/CraftingRecipes.cpp +++ b/src/CraftingRecipes.cpp @@ -192,7 +192,9 @@ void cCraftingGrid::Dump(void) { for (int y = 0; y < m_Height; y++) for (int x = 0; x < m_Width; x++) { + #ifdef _DEBUG int idx = x + m_Width * y; + #endif LOGD("Slot (%d, %d): Type %d, health %d, count %d", x, y, m_Items[idx].m_ItemType, m_Items[idx].m_ItemDamage, m_Items[idx].m_ItemCount ); diff --git a/src/Globals.h b/src/Globals.h index b046e6db0..2cd160677 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -234,9 +234,10 @@ template class SizeChecker; // Pretty much the same as ASSERT() but stays in Release builds #define VERIFY( x ) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), exit(1), 0 ) ) - - - +// Same as assert but in all Self test builds +#ifdef SELF_TEST +#define assert_test(x) ( !!(x) || (assert(0), exit(1), 0)) +#endif /// A generic interface used mainly in ForEach() functions template class cItemCallback