- EXPECT_TRUE(client.nextProtoLength != 0);
- EXPECT_EQ(client.nextProtoLength, server.nextProtoLength);
- EXPECT_EQ(memcmp(client.nextProto, server.nextProto,
- server.nextProtoLength), 0);
- string selected((const char*)client.nextProto, client.nextProtoLength);
- EXPECT_EQ(selected.compare("baz"), 0);
-}
+ AsyncSSLSocket::UniquePtr clientSock(
+ new AsyncSSLSocket(clientCtx, &eventBase, fds[0], false));
+ AsyncSSLSocket::UniquePtr serverSock(
+ new AsyncSSLSocket(serverCtx, &eventBase, fds[1], true));
+ client = folly::make_unique<NpnClient>(std::move(clientSock));
+ server = folly::make_unique<NpnServer>(std::move(serverSock));
+
+ eventBase.loop();
+ }
+
+ void expectProtocol(const std::string& proto) {
+ EXPECT_NE(client->nextProtoLength, 0);
+ EXPECT_EQ(client->nextProtoLength, server->nextProtoLength);
+ EXPECT_EQ(
+ memcmp(client->nextProto, server->nextProto, server->nextProtoLength),
+ 0);
+ string selected((const char*)client->nextProto, client->nextProtoLength);
+ EXPECT_EQ(proto, selected);
+ }
+
+ void expectNoProtocol() {
+ EXPECT_EQ(client->nextProtoLength, 0);
+ EXPECT_EQ(server->nextProtoLength, 0);
+ EXPECT_EQ(client->nextProto, nullptr);
+ EXPECT_EQ(server->nextProto, nullptr);
+ }
+
+ void expectProtocolType() {
+ if (GetParam().first == SSLContext::NextProtocolType::ANY &&
+ GetParam().second == SSLContext::NextProtocolType::ANY) {
+ EXPECT_EQ(client->protocolType, server->protocolType);
+ } else if (GetParam().first == SSLContext::NextProtocolType::ANY ||
+ GetParam().second == SSLContext::NextProtocolType::ANY) {
+ // Well not much we can say
+ } else {
+ expectProtocolType(GetParam());
+ }
+ }
+
+ void expectProtocolType(NextProtocolTypePair expected) {
+ EXPECT_EQ(client->protocolType, expected.first);
+ EXPECT_EQ(server->protocolType, expected.second);
+ }