From 5237e89bc318355bdae02a3672ee89e31dc0ff9e Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Mon, 3 Mar 2014 22:22:37 +0000 Subject: [PATCH] Fix message tags parser and add test of it --- Makefile.in | 2 +- src/Utils.cpp | 2 +- test/UtilsTest.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 test/UtilsTest.cpp diff --git a/Makefile.in b/Makefile.in index 492c78f1..b92f0fac 100644 --- a/Makefile.in +++ b/Makefile.in @@ -47,7 +47,7 @@ LIB_SRCS := $(addprefix src/,$(LIB_SRCS)) BIN_SRCS := src/main.cpp LIB_OBJS := $(patsubst %cpp,%o,$(LIB_SRCS)) BIN_OBJS := $(patsubst %cpp,%o,$(BIN_SRCS)) -TESTS := StringTest ConfigTest +TESTS := StringTest ConfigTest UtilsTest TESTS := $(addprefix test/,$(addsuffix .o,$(TESTS))) CLEAN := znc src/*.o test/*.o core core.* .version_extra .depend modules/.depend unittest DISTCLEAN := Makefile config.log config.status znc-buildmod \ diff --git a/src/Utils.cpp b/src/Utils.cpp index 16bac4b5..38e4a1a4 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -466,7 +466,7 @@ MCString CUtils::GetMessageTags(const CString& sLine) { MCString mssTags; for (VCString::const_iterator it = vsTags.begin(); it != vsTags.end(); ++it) { - mssTags[it->Token(0, false, "=")] = it->Token(1, true, "="); + mssTags[it->Token(0, false, "=", true)] = it->Token(1, true, "=", true); } return mssTags; } diff --git a/test/UtilsTest.cpp b/test/UtilsTest.cpp new file mode 100644 index 00000000..4f4197bb --- /dev/null +++ b/test/UtilsTest.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2004-2014 ZNC, see the NOTICE file for details. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +TEST(IRC32, GetMessageTags) { + EXPECT_EQ(MCString(), CUtils::GetMessageTags("")); + EXPECT_EQ(MCString(), CUtils::GetMessageTags(":nick!ident@host PRIVMSG #chan :hello world")); + + MCString exp; + exp["a"] = "b"; + EXPECT_EQ(exp, CUtils::GetMessageTags("@a=b")); + EXPECT_EQ(exp, CUtils::GetMessageTags("@a=b :nick!ident@host PRIVMSG #chan :hello world")); + EXPECT_EQ(exp, CUtils::GetMessageTags("@a=b :rest")); + exp.clear(); + + exp["ab"] = "cdef"; + exp["znc.in/gh-ij"] = "klmn,op"; + EXPECT_EQ(exp, CUtils::GetMessageTags("@ab=cdef;znc.in/gh-ij=klmn,op :rest")); + exp.clear(); + + exp["a"] = "==b=="; + EXPECT_EQ(exp, CUtils::GetMessageTags("@a===b== :rest")); + exp.clear(); +} + +TEST(IRC32, SetMessageTags) { + CString sLine; + + sLine = ":rest"; + CUtils::SetMessageTags(sLine, MCString()); + EXPECT_EQ(":rest", sLine); + + MCString tags; + tags["a"] = "b"; + CUtils::SetMessageTags(sLine, tags); + EXPECT_EQ("@a=b :rest", sLine); + + tags["c"] = "d"; + CUtils::SetMessageTags(sLine, tags); + EXPECT_EQ("@a=b;c=d :rest", sLine); +} +