summaryrefslogtreecommitdiffstats
path: root/src/CompositeChat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/CompositeChat.cpp')
-rw-r--r--src/CompositeChat.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp
index d1eb0b852..353835039 100644
--- a/src/CompositeChat.cpp
+++ b/src/CompositeChat.cpp
@@ -6,6 +6,7 @@
#include "Globals.h"
#include "CompositeChat.h"
#include "ClientHandle.h"
+#include "SelfTests.h"
@@ -19,16 +20,14 @@ class SelfTest_CompositeChat
public:
SelfTest_CompositeChat(void)
{
- fprintf(stderr, "cCompositeChat self test...\n");
- TestParser1();
- TestParser2();
- TestParser3();
- TestParser4();
- TestParser5();
- fprintf(stderr, "cCompositeChat self test finished.\n");
+ cSelfTests::Get().Register(cSelfTests::SelfTestFunction(&TestParser1), "CompositeChat parser test 1");
+ cSelfTests::Get().Register(cSelfTests::SelfTestFunction(&TestParser2), "CompositeChat parser test 2");
+ cSelfTests::Get().Register(cSelfTests::SelfTestFunction(&TestParser3), "CompositeChat parser test 3");
+ cSelfTests::Get().Register(cSelfTests::SelfTestFunction(&TestParser4), "CompositeChat parser test 4");
+ cSelfTests::Get().Register(cSelfTests::SelfTestFunction(&TestParser5), "CompositeChat parser test 5");
}
- void TestParser1(void)
+ static void TestParser1(void)
{
cCompositeChat Msg;
Msg.ParseText("Testing @2color codes and http://links parser");
@@ -44,7 +43,7 @@ public:
assert_test(Parts[3]->m_Style == "@2");
}
- void TestParser2(void)
+ static void TestParser2(void)
{
cCompositeChat Msg;
Msg.ParseText("@3Advanced stuff: @5overriding color codes and http://links.with/@4color-in-them handling");
@@ -60,7 +59,7 @@ public:
assert_test(Parts[3]->m_Style == "@5");
}
- void TestParser3(void)
+ static void TestParser3(void)
{
cCompositeChat Msg;
Msg.ParseText("http://links.starting the text");
@@ -72,7 +71,7 @@ public:
assert_test(Parts[1]->m_Style == "");
}
- void TestParser4(void)
+ static void TestParser4(void)
{
cCompositeChat Msg;
Msg.ParseText("links finishing the text: http://some.server");
@@ -84,7 +83,7 @@ public:
assert_test(Parts[1]->m_Style == "");
}
- void TestParser5(void)
+ static void TestParser5(void)
{
cCompositeChat Msg;
Msg.ParseText("http://only.links");
@@ -342,7 +341,11 @@ AString cCompositeChat::ExtractText(void) const
}
case ptUrl:
{
- Msg.append(((cUrlPart *)(*itr))->m_Url);
+ Msg.append((static_cast<cUrlPart *>(*itr))->m_Url);
+ break;
+ }
+ case ptShowAchievement:
+ {
break;
}
} // switch (PartType)
@@ -419,7 +422,7 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const
case cCompositeChat::ptClientTranslated:
{
- const cCompositeChat::cClientTranslatedPart & p = (const cCompositeChat::cClientTranslatedPart &)**itr;
+ const cCompositeChat::cClientTranslatedPart & p = static_cast<const cCompositeChat::cClientTranslatedPart &>(**itr);
Part["translate"] = p.m_Text;
Json::Value With;
for (AStringVector::const_iterator itrW = p.m_Parameters.begin(), endW = p.m_Parameters.end(); itrW != endW; ++itr)
@@ -436,7 +439,7 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const
case cCompositeChat::ptUrl:
{
- const cCompositeChat::cUrlPart & p = (const cCompositeChat::cUrlPart &)**itr;
+ const cCompositeChat::cUrlPart & p = static_cast<const cCompositeChat::cUrlPart &>(**itr);
Part["text"] = p.m_Text;
Json::Value Url;
Url["action"] = "open_url";
@@ -449,7 +452,7 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const
case cCompositeChat::ptSuggestCommand:
case cCompositeChat::ptRunCommand:
{
- const cCompositeChat::cCommandPart & p = (const cCompositeChat::cCommandPart &)**itr;
+ const cCompositeChat::cCommandPart & p = static_cast<const cCompositeChat::cCommandPart &>(**itr);
Part["text"] = p.m_Text;
Json::Value Cmd;
Cmd["action"] = (p.m_PartType == cCompositeChat::ptRunCommand) ? "run_command" : "suggest_command";
@@ -461,7 +464,7 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const
case cCompositeChat::ptShowAchievement:
{
- const cCompositeChat::cShowAchievementPart & p = (const cCompositeChat::cShowAchievementPart &)**itr;
+ const cCompositeChat::cShowAchievementPart & p = static_cast<const cCompositeChat::cShowAchievementPart &>(**itr);
Part["translate"] = "chat.type.achievement";
Json::Value Ach;