Browse Source

Update googletest to latest version and cleanup integration test.

https://github.com/google/googletest/pull/1439 makes it possible to
remove horrible hacks I wrote before.
master
Alexey Sokolov 3 years ago
parent
commit
01507188c3
4 changed files with 37 additions and 143 deletions
  1. +2
    -2
      Makefile.in
  2. +0
    -1
      test/integration/CMakeLists.txt
  3. +34
    -139
      test/integration/main.cpp
  4. +1
    -1
      third_party/googletest

+ 2
- 2
Makefile.in View File

@ -110,9 +110,9 @@ unittest: $(LIB_OBJS) test/gtest-all.o test/gmock-all.o test/gmock-main.o $(TEST
$(E) Linking unit test...
$(Q)$(CXX) $(LDFLAGS) -o $@ $(LIB_OBJS) test/gtest-all.o test/gmock-all.o test/gmock-main.o $(TESTS) $(LIBS)
inttest: test/Integration.o test/Int-gtest-all.o test/Int-gmock-all.o test/Int-gmock-main.o
inttest: test/Integration.o test/Int-gtest-all.o test/Int-gmock-all.o
$(E) Linking integration test...
$(Q)g++ -std=c++11 -o $@ test/Integration.o test/Int-gtest-all.o test/Int-gmock-all.o test/Int-gmock-main.o $(LIBS) $(qt_LIBS)
$(Q)g++ -std=c++11 -o $@ test/Integration.o test/Int-gtest-all.o test/Int-gmock-all.o $(LIBS) $(qt_LIBS)
man:
@$(MAKE) -C man $(C)

+ 0
- 1
test/integration/CMakeLists.txt View File

@ -33,7 +33,6 @@ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
"GTEST_HAS_POSIX_RE=0")
add_executable(inttest "main.cpp"
"${GMOCK_ROOT}/src/gmock_main.cc"
"${GTEST_ROOT}/src/gtest-all.cc"
"${GMOCK_ROOT}/src/gmock-all.cc")

+ 34
- 139
test/integration/main.cpp View File

@ -33,14 +33,6 @@
#include <memory>
#define Z \
do { \
if (::testing::Test::HasFatalFailure()) { \
std::cerr << "At: " << __FILE__ << ":" << __LINE__ << std::endl; \
return; \
} \
} while (0)
#ifndef ZNC_BIN_DIR
#define ZNC_BIN_DIR ""
#endif
@ -222,25 +214,25 @@ void WriteConfig(QString path) {
Process p(ZNC_BIN_DIR "/znc", QStringList() << "--debug"
<< "--datadir" << path
<< "--makeconf");
p.ReadUntil("Listen on port");Z; p.Write("12345");
p.ReadUntil("Listen using SSL");Z; p.Write();
p.ReadUntil("IPv6");Z; p.Write();
p.ReadUntil("Username");Z; p.Write("user");
p.ReadUntil("password");Z; p.Write("hunter2", false);
p.ReadUntil("Confirm");Z; p.Write("hunter2", false);
p.ReadUntil("Nick [user]");Z; p.Write();
p.ReadUntil("Alternate nick [user_]");Z; p.Write();
p.ReadUntil("Ident [user]");Z; p.Write();
p.ReadUntil("Real name");Z; p.Write();
p.ReadUntil("Bind host");Z; p.Write();
p.ReadUntil("Set up a network?");Z; p.Write();
p.ReadUntil("Name [freenode]");Z; p.Write("test");
p.ReadUntil("Server host (host only)");Z; p.Write("127.0.0.1");
p.ReadUntil("Server uses SSL?");Z; p.Write();
p.ReadUntil("6667");Z; p.Write();
p.ReadUntil("password");Z; p.Write();
p.ReadUntil("channels");Z; p.Write();
p.ReadUntil("Launch ZNC now?");Z; p.Write("no");
p.ReadUntil("Listen on port"); p.Write("12345");
p.ReadUntil("Listen using SSL"); p.Write();
p.ReadUntil("IPv6"); p.Write();
p.ReadUntil("Username"); p.Write("user");
p.ReadUntil("password"); p.Write("hunter2", false);
p.ReadUntil("Confirm"); p.Write("hunter2", false);
p.ReadUntil("Nick [user]"); p.Write();
p.ReadUntil("Alternate nick [user_]"); p.Write();
p.ReadUntil("Ident [user]"); p.Write();
p.ReadUntil("Real name"); p.Write();
p.ReadUntil("Bind host"); p.Write();
p.ReadUntil("Set up a network?"); p.Write();
p.ReadUntil("Name [freenode]"); p.Write("test");
p.ReadUntil("Server host (host only)"); p.Write("127.0.0.1");
p.ReadUntil("Server uses SSL?"); p.Write();
p.ReadUntil("6667"); p.Write();
p.ReadUntil("password"); p.Write();
p.ReadUntil("channels"); p.Write();
p.ReadUntil("Launch ZNC now?"); p.Write("no");
p.ShouldFinishItself();
// clang-format on
}
@ -248,12 +240,10 @@ void WriteConfig(QString path) {
TEST(Config, AlreadyExists) {
QTemporaryDir dir;
WriteConfig(dir.path());
Z;
Process p(ZNC_BIN_DIR "/znc", QStringList() << "--debug"
<< "--datadir" << dir.path()
<< "--makeconf");
p.ReadUntil("already exists");
Z;
p.CanDie();
}
@ -273,10 +263,8 @@ class ZNCTest : public testing::Test {
protected:
void SetUp() override {
WriteConfig(m_dir.path());
Z;
ASSERT_TRUE(m_server.listen(QHostAddress::LocalHost, 6667))
<< m_server.errorString().toStdString();
Z;
}
Socket ConnectIRCd() {
@ -405,33 +393,25 @@ class ZNCTest : public testing::Test {
TEST_F(ZNCTest, Connect) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
ircd.ReadUntil("CAP LS");
Z;
auto client = ConnectClient();
Z;
client.Write("PASS :hunter2");
client.Write("NICK nick");
client.Write("USER user/test x x :x");
client.ReadUntil("Welcome");
Z;
client.Close();
client = ConnectClient();
Z;
client.Write("PASS :user:hunter2");
client.Write("NICK nick");
client.Write("USER u x x x");
client.ReadUntil("Welcome");
Z;
client.Close();
client = ConnectClient();
Z;
client.Write("NICK nick");
client.Write("USER user x x x");
client.ReadUntil("Configure your client to send a server password");
@ -439,25 +419,19 @@ TEST_F(ZNCTest, Connect) {
ircd.Write(":server 001 nick :Hello");
ircd.ReadUntil("WHO");
Z;
}
TEST_F(ZNCTest, Channel) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.ReadUntil("Welcome");
Z;
client.Write("JOIN #znc");
client.Close();
ircd.Write(":server 001 nick :Hello");
ircd.ReadUntil("JOIN #znc");
Z;
ircd.Write(":nick JOIN :#znc");
ircd.Write(":server 353 nick #znc :nick");
ircd.Write(":server 366 nick #znc :End of /NAMES list");
@ -465,31 +439,23 @@ TEST_F(ZNCTest, Channel) {
ircd.ReadUntil("PONG 1");
client = LoginClient();
Z;
client.ReadUntil(":nick JOIN :#znc");
Z;
}
TEST_F(ZNCTest, HTTP) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto reply = HttpGet(QNetworkRequest(QUrl("http://127.0.0.1:12345/")));
Z;
EXPECT_THAT(reply->rawHeader("Server").toStdString(), HasSubstr("ZNC"));
}
TEST_F(ZNCTest, FixCVE20149403) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
ircd.Write(":server 001 nick :Hello");
ircd.Write(":server 005 nick CHANTYPES=# :supports");
ircd.Write(":server PING :1");
ircd.ReadUntil("PONG 1");
Z;
QNetworkRequest request;
request.setRawHeader("Authorization",
@ -517,17 +483,13 @@ TEST_F(ZNCTest, FixCVE20149403) {
TEST_F(ZNCTest, FixFixOfCVE20149403) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
ircd.Write(":server 001 nick :Hello");
ircd.Write(":nick JOIN @#znc");
ircd.ReadUntil("MODE @#znc");
Z;
ircd.Write(":server 005 nick STATUSMSG=@ :supports");
ircd.Write(":server PING :12345");
ircd.ReadUntil("PONG 12345");
Z;
QNetworkRequest request;
request.setRawHeader("Authorization",
@ -559,27 +521,21 @@ TEST_F(ZNCTest, InvalidConfigInChan) {
)";
out.flush();
auto znc = Run();
Z;
znc->ShouldFinishItself(1);
}
TEST_F(ZNCTest, NotifyConnectModule) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.Write("znc loadmod notify_connect");
client.ReadUntil("Loaded module");
Z;
auto client2 = ConnectClient();
client2.Write("PASS :hunter2");
client2.Write("NICK nick");
client2.Write("USER user/test x x :x");
client.ReadUntil("NOTICE nick :*** user attached from 127.0.0.1");
Z;
auto client3 = ConnectClient();
client3.Write("PASS :hunter2");
@ -587,49 +543,36 @@ TEST_F(ZNCTest, NotifyConnectModule) {
client3.Write("USER user@identifier/test x x :x");
client.ReadUntil(
"NOTICE nick :*** user@identifier attached from 127.0.0.1");
Z;
client2.ReadUntil(
"NOTICE nick :*** user@identifier attached from 127.0.0.1");
Z;
client2.Write("QUIT");
client.ReadUntil("NOTICE nick :*** user detached from 127.0.0.1");
Z;
client3.Close();
client.ReadUntil(
"NOTICE nick :*** user@identifier detached from 127.0.0.1");
Z;
}
TEST_F(ZNCTest, ShellModule) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.Write("znc loadmod shell");
client.Write("PRIVMSG *shell :echo blahblah");
client.ReadUntil("PRIVMSG nick :blahblah");
Z;
client.ReadUntil("PRIVMSG nick :znc$");
Z;
}
TEST_F(ZNCTest, WatchModule) {
// TODO test other messages
// TODO test options
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.Write("znc loadmod watch");
client.Write("PRIVMSG *watch :add *");
client.ReadUntil("Adding entry:");
Z;
ircd.Write(":server 001 nick :Hello");
ircd.Write(":nick JOIN :#znc");
ircd.Write(":n!i@h PRIVMSG #znc :\001ACTION foo\001");
@ -643,20 +586,15 @@ TEST_F(ZNCTest, Modperl) {
return;
}
auto znc = Run();
Z;
znc->CanLeak();
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.Write("znc loadmod modperl");
client.Write("znc loadmod perleval");
client.Write("PRIVMSG *perleval :2+2");
client.ReadUntil(":*perleval!znc@znc.in PRIVMSG nick :Result: 4");
Z;
client.Write("PRIVMSG *perleval :$self->GetUser->GetUserName");
client.ReadUntil("Result: user");
Z;
}
TEST_F(ZNCTest, Modpython) {
@ -665,64 +603,46 @@ TEST_F(ZNCTest, Modpython) {
return;
}
auto znc = Run();
Z;
znc->CanLeak();
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.Write("znc loadmod modpython");
client.Write("znc loadmod pyeval");
client.Write("PRIVMSG *pyeval :2+2");
client.ReadUntil(":*pyeval!znc@znc.in PRIVMSG nick :4");
Z;
client.Write("PRIVMSG *pyeval :module.GetUser().GetUserName()");
client.ReadUntil("nick :'user'");
Z;
ircd.Write(":server 001 nick :Hello");
ircd.Write(":n!u@h PRIVMSG nick :Hi\xF0, github issue #1229");
// "replacement character"
client.ReadUntil("Hi\xEF\xBF\xBD, github issue");
Z;
}
TEST_F(ZNCTest, Encoding) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
ircd.Write(":server 001 nick :hello");
// legacy
ircd.Write(":n!u@h PRIVMSG nick :Hello\xE6world");
client.ReadUntil("Hello\xE6world");
Z;
client.Write("PRIVMSG *controlpanel :SetNetwork Encoding $me $net UTF-8");
client.ReadUntil("Encoding = UTF-8");
Z;
ircd.Write(":n!u@h PRIVMSG nick :Hello\xE6world");
client.ReadUntil("Hello\xEF\xBF\xBDworld");
Z;
client.Write(
"PRIVMSG *controlpanel :SetNetwork Encoding $me $net ^CP-1251");
client.ReadUntil("Encoding = ^CP-1251");
Z;
ircd.Write(":n!u@h PRIVMSG nick :Hello\xE6world");
client.ReadUntil("Hello\xD0\xB6world");
Z;
ircd.Write(":n!u@h PRIVMSG nick :Hello\xD0\xB6world");
client.ReadUntil("Hello\xD0\xB6world");
Z;
}
TEST_F(ZNCTest, BuildMod) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
QTemporaryDir srcd;
QDir srcdir(srcd.path());
QFile file(srcdir.filePath("testmod.cpp"));
@ -764,16 +684,12 @@ TEST_F(ZNCTest, BuildMod) {
client.Write("znc loadmod testmod");
client.Write("PRIVMSG *testmod :hi");
client.ReadUntil("Lorem ipsum");
Z;
}
TEST_F(ZNCTest, AutoAttachModule) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
InstallModule("testmod.cpp", R"(
#include <znc/Modules.h>
#include <znc/Client.h>
@ -787,49 +703,36 @@ TEST_F(ZNCTest, AutoAttachModule) {
};
MODULEDEFS(TestModule, "Test")
)");
Z;
client.Write("znc loadmod testmod");
client.Write("PRIVMSG *controlpanel :Set AutoClearChanBuffer $me no");
client.Write("znc loadmod autoattach");
client.Write("PRIVMSG *autoattach :Add * * *");
client.ReadUntil("Added to list");
Z;
ircd.Write(":server 001 nick :Hello");
ircd.Write(":nick JOIN :#znc");
ircd.Write(":server 353 nick #znc :nick");
ircd.Write(":server 366 nick #znc :End of /NAMES list");
ircd.Write(":foo PRIVMSG #znc :hi");
client.ReadUntil(":foo PRIVMSG");
Z;
client.Write("detach #znc");
client.ReadUntil("Detached");
Z;
ircd.Write(":foo PRIVMSG #znc :hello");
ircd.ReadUntil("TEST");
Z;
client.ReadUntil("hello");
Z;
}
TEST_F(ZNCTest, KeepNickModule) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.Write("znc loadmod keepnick");
client.ReadUntil("Loaded module");
Z;
ircd.ReadUntil("NICK user");
ircd.Write(":server 433 * nick :Nickname is already in use.");
ircd.ReadUntil("NICK user_");
Z;
ircd.Write(":server 001 user_ :Hello");
client.ReadUntil("Connected!");
Z;
ircd.ReadUntil("NICK user");
Z;
ircd.Write(":server 435 user_ user #error :Nope :-P");
client.ReadUntil(
":*keepnick!znc@znc.in PRIVMSG user_ "
@ -838,19 +741,14 @@ TEST_F(ZNCTest, KeepNickModule) {
TEST_F(ZNCTest, ModuleCSRFOverride) {
auto znc = Run();
Z;
auto ircd = ConnectIRCd();
Z;
auto client = LoginClient();
Z;
client.Write("znc loadmod samplewebapi");
client.ReadUntil("Loaded module");
Z;
auto request = QNetworkRequest(QUrl("http://127.0.0.1:12345/mods/global/samplewebapi/"));
auto reply = HttpPost(request, {
{"text", "ipsum"}
})->readAll().toStdString();
Z;
EXPECT_THAT(reply, HasSubstr("ipsum"));
}
@ -859,68 +757,65 @@ TEST_F(ZNCTest, ModuleCrypt) {
ASSERT_TRUE(conf.open(QIODevice::Append | QIODevice::Text));
QTextStream(&conf) << "ServerThrottle = 1\n";
auto znc = Run();
Z;
auto ircd1 = ConnectIRCd();
Z;
auto client1 = LoginClient();
Z;
client1.Write("znc loadmod controlpanel");
client1.Write("PRIVMSG *controlpanel :CloneUser user user2");
client1.ReadUntil("User user2 added!");
client1.Write("PRIVMSG *controlpanel :Set Nick user2 nick2");
Z;
client1.Write("znc loadmod crypt");
client1.ReadUntil("Loaded module");
Z;
auto ircd2 = ConnectIRCd();
Z;
auto client2 = ConnectClient();
client2.Write("PASS user2:hunter2");
client2.Write("NICK nick2");
client2.Write("USER user2/test x x :x");
Z;
client2.Write("znc loadmod crypt");
client2.ReadUntil("Loaded module");
Z;
client1.Write("PRIVMSG *crypt :keyx nick2");
client1.ReadUntil("Sent my DH1080 public key to nick2");
Z;
QByteArray pub1("");
ircd1.ReadUntilAndGet("NOTICE nick2 :DH1080_INIT ", pub1);
ircd2.Write(":user!user@user/test " + pub1);
Z;
client2.ReadUntil("Received DH1080 public key from user");
Z;
client2.ReadUntil("Key for user successfully set.");
Z;
QByteArray pub2("");
ircd2.ReadUntilAndGet("NOTICE user :DH1080_FINISH ", pub2);
ircd1.Write(":nick2!user2@user2/test " + pub2);
Z;
client1.ReadUntil("Key for nick2 successfully set.");
Z;
client1.Write("PRIVMSG *crypt :listkeys");
QByteArray key1("");
client1.ReadUntilAndGet("| nick2 | ", key1);
Z;
client2.Write("PRIVMSG *crypt :listkeys");
QByteArray key2("");
client2.ReadUntilAndGet("| user | ", key2);
Z;
ASSERT_EQ(key1.mid(11), key2.mid(11));
client1.Write("PRIVMSG .nick2 :Hello");
QByteArray secretmsg;
ircd1.ReadUntilAndGet("PRIVMSG nick2 :+OK ", secretmsg);
Z;
ircd2.Write(":user!user@user/test " + secretmsg);
client2.ReadUntil("Hello");
Z;
}
} // namespace
class ThrowListener : public testing::EmptyTestEventListener {
void OnTestPartResult(const testing::TestPartResult& result) override {
if (result.type() == testing::TestPartResult::kFatalFailure &&
!std::uncaught_exception()) {
throw testing::AssertionException(result);
}
}
};
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
testing::UnitTest::GetInstance()->listeners().Append(new ThrowListener);
return RUN_ALL_TESTS();
}

+ 1
- 1
third_party/googletest

@ -1 +1 @@
Subproject commit f570b27e15a4e921d59495622a82277a3e1e8f87
Subproject commit 9737e63c69e94ac5777caa0bc77c77d5206467f3

Loading…
Cancel
Save