You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
5.2 KiB

  1. From e10b53b87bb7ce87d1a31473e03a02ccafa78787 Mon Sep 17 00:00:00 2001
  2. From: J-P Nurmi <jpnurmi@gmail.com>
  3. Date: Tue, 3 Feb 2015 10:11:47 +0100
  4. Subject: [PATCH] Fix CIRCNetwork::FindChans() and FindQueries() to be
  5. case-insensitive
  6. The playback module failed to clear a buffer, because it tried to
  7. clear "NickServ" whereas ZNC had internally stored it has "nickserv".
  8. ---
  9. Makefile.in | 2 +-
  10. src/IRCNetwork.cpp | 6 ++--
  11. test/NetworkTest.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. 3 files changed, 101 insertions(+), 3 deletions(-)
  13. create mode 100644 test/NetworkTest.cpp
  14. --- a/Makefile.in
  15. +++ b/Makefile.in
  16. @@ -48,7 +48,7 @@ LIB_SRCS := $(addprefix src/,$(LIB_SRCS
  17. BIN_SRCS := src/main.cpp
  18. LIB_OBJS := $(patsubst %cpp,%o,$(LIB_SRCS))
  19. BIN_OBJS := $(patsubst %cpp,%o,$(BIN_SRCS))
  20. -TESTS := StringTest ConfigTest UtilsTest ThreadTest NickTest ClientTest
  21. +TESTS := StringTest ConfigTest UtilsTest ThreadTest NickTest ClientTest NetworkTest
  22. TESTS := $(addprefix test/,$(addsuffix .o,$(TESTS)))
  23. CLEAN := znc src/*.o test/*.o core core.* .version_extra .depend modules/.depend unittest
  24. DISTCLEAN := Makefile config.log config.status znc-buildmod \
  25. --- a/src/IRCNetwork.cpp
  26. +++ b/src/IRCNetwork.cpp
  27. @@ -787,8 +787,9 @@ CChan* CIRCNetwork::FindChan(CString sNa
  28. std::vector<CChan*> CIRCNetwork::FindChans(const CString& sWild) const {
  29. std::vector<CChan*> vChans;
  30. vChans.reserve(m_vChans.size());
  31. + const CString sLower = sWild.AsLower();
  32. for (std::vector<CChan*>::const_iterator it = m_vChans.begin(); it != m_vChans.end(); ++it) {
  33. - if ((*it)->GetName().WildCmp(sWild))
  34. + if ((*it)->GetName().AsLower().WildCmp(sLower))
  35. vChans.push_back(*it);
  36. }
  37. return vChans;
  38. @@ -946,8 +947,9 @@ CQuery* CIRCNetwork::FindQuery(const CSt
  39. std::vector<CQuery*> CIRCNetwork::FindQueries(const CString& sWild) const {
  40. std::vector<CQuery*> vQueries;
  41. vQueries.reserve(m_vQueries.size());
  42. + const CString sLower = sWild.AsLower();
  43. for (std::vector<CQuery*>::const_iterator it = m_vQueries.begin(); it != m_vQueries.end(); ++it) {
  44. - if ((*it)->GetName().WildCmp(sWild))
  45. + if ((*it)->GetName().AsLower().WildCmp(sLower))
  46. vQueries.push_back(*it);
  47. }
  48. return vQueries;
  49. --- /dev/null
  50. +++ b/test/NetworkTest.cpp
  51. @@ -0,0 +1,96 @@
  52. +/*
  53. + * Copyright (C) 2004-2015 ZNC, see the NOTICE file for details.
  54. + *
  55. + * Licensed under the Apache License, Version 2.0 (the "License");
  56. + * you may not use this file except in compliance with the License.
  57. + * You may obtain a copy of the License at
  58. + *
  59. + * http://www.apache.org/licenses/LICENSE-2.0
  60. + *
  61. + * Unless required by applicable law or agreed to in writing, software
  62. + * distributed under the License is distributed on an "AS IS" BASIS,
  63. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  64. + * See the License for the specific language governing permissions and
  65. + * limitations under the License.
  66. + */
  67. +
  68. +#include <gtest/gtest.h>
  69. +#include <znc/IRCNetwork.h>
  70. +#include <znc/User.h>
  71. +#include <znc/znc.h>
  72. +
  73. +class NetworkTest : public ::testing::Test {
  74. +protected:
  75. + void SetUp() { CZNC::CreateInstance(); }
  76. + void TearDown() { CZNC::DestroyInstance(); }
  77. +};
  78. +
  79. +TEST_F(NetworkTest, FindChan) {
  80. + CUser user("user");
  81. + CIRCNetwork network(&user, "network");
  82. +
  83. + EXPECT_TRUE(network.AddChan("#foo", false));
  84. + EXPECT_TRUE(network.AddChan("#Bar", false));
  85. + EXPECT_TRUE(network.AddChan("#BAZ", false));
  86. +
  87. + EXPECT_TRUE(network.FindChan("#foo"));
  88. + EXPECT_TRUE(network.FindChan("#Bar"));
  89. + EXPECT_TRUE(network.FindChan("#BAZ"));
  90. +
  91. + EXPECT_TRUE(network.FindChan("#Foo"));
  92. + EXPECT_TRUE(network.FindChan("#BAR"));
  93. + EXPECT_TRUE(network.FindChan("#baz"));
  94. +
  95. + EXPECT_FALSE(network.FindChan("#f"));
  96. + EXPECT_FALSE(network.FindChan("&foo"));
  97. + EXPECT_FALSE(network.FindChan("##foo"));
  98. +}
  99. +
  100. +TEST_F(NetworkTest, FindChans) {
  101. + CUser user("user");
  102. + CIRCNetwork network(&user, "network");
  103. +
  104. + EXPECT_TRUE(network.AddChan("#foo", false));
  105. + EXPECT_TRUE(network.AddChan("#Bar", false));
  106. + EXPECT_TRUE(network.AddChan("#BAZ", false));
  107. +
  108. + EXPECT_EQ(network.FindChans("#f*").size(), 1);
  109. + EXPECT_EQ(network.FindChans("#b*").size(), 2);
  110. + EXPECT_EQ(network.FindChans("#?A*").size(), 2);
  111. + EXPECT_EQ(network.FindChans("*z").size(), 1);
  112. +}
  113. +
  114. +TEST_F(NetworkTest, FindQuery) {
  115. + CUser user("user");
  116. + CIRCNetwork network(&user, "network");
  117. +
  118. + EXPECT_TRUE(network.AddQuery("foo"));
  119. + EXPECT_TRUE(network.AddQuery("Bar"));
  120. + EXPECT_TRUE(network.AddQuery("BAZ"));
  121. +
  122. + EXPECT_TRUE(network.FindQuery("foo"));
  123. + EXPECT_TRUE(network.FindQuery("Bar"));
  124. + EXPECT_TRUE(network.FindQuery("BAZ"));
  125. +
  126. + EXPECT_TRUE(network.FindQuery("Foo"));
  127. + EXPECT_TRUE(network.FindQuery("BAR"));
  128. + EXPECT_TRUE(network.FindQuery("baz"));
  129. +
  130. + EXPECT_FALSE(network.FindQuery("f"));
  131. + EXPECT_FALSE(network.FindQuery("fo"));
  132. + EXPECT_FALSE(network.FindQuery("FF"));
  133. +}
  134. +
  135. +TEST_F(NetworkTest, FindQueries) {
  136. + CUser user("user");
  137. + CIRCNetwork network(&user, "network");
  138. +
  139. + EXPECT_TRUE(network.AddQuery("foo"));
  140. + EXPECT_TRUE(network.AddQuery("Bar"));
  141. + EXPECT_TRUE(network.AddQuery("BAZ"));
  142. +
  143. + EXPECT_EQ(network.FindQueries("f*").size(), 1);
  144. + EXPECT_EQ(network.FindQueries("b*").size(), 2);
  145. + EXPECT_EQ(network.FindQueries("?A*").size(), 2);
  146. + EXPECT_EQ(network.FindQueries("*z").size(), 1);
  147. +}