Added background plugin tests in flipper client

Summary: Added tests for flipper client which makes sure that didconnect is called in the case of background plugin. It also checks the case of a non background plugin.

Reviewed By: jknoxville

Differential Revision: D13152686

fbshipit-source-id: 7850f66a42d669243f656a1e1c26584869ee919f
This commit is contained in:
Pritesh Nandgaonkar
2018-11-23 03:40:41 -08:00
committed by Facebook Github Bot
parent ca1f0202d7
commit 8327e1ff71
2 changed files with 57 additions and 4 deletions

View File

@@ -1,11 +1,10 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
* Copyright (c) Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#include <Flipper/FlipperClient.h>
#include <FlipperTestLib/FlipperPluginMock.h>
#include <FlipperTestLib/FlipperConnectionManagerMock.h>
@@ -289,6 +288,46 @@ TEST(FlipperClientTests, testExceptionUnknownApi) {
"connection Unknown not found for method execute");
}
TEST(FlipperClientTests, testBackgroundPluginActivated) {
auto socket = new FlipperConnectionManagerMock;
FlipperClient client(
std::unique_ptr<FlipperConnectionManagerMock>{socket}, state);
bool pluginConnected = false;
const auto connectionCallback = [&](std::shared_ptr<FlipperConnection> conn) {
pluginConnected = true;
};
const auto disconnectionCallback = [&]() { pluginConnected = false; };
auto plugin = std::make_shared<FlipperPluginMock>(
"Test", connectionCallback, disconnectionCallback, true);
client.addPlugin(plugin);
client.start();
EXPECT_TRUE(pluginConnected);
client.stop();
EXPECT_FALSE(pluginConnected);
}
TEST(FlipperClientTests, testNonBackgroundPluginNotActivated) {
auto socket = new FlipperConnectionManagerMock;
FlipperClient client(
std::unique_ptr<FlipperConnectionManagerMock>{socket}, state);
bool pluginConnected = false;
const auto connectionCallback = [&](std::shared_ptr<FlipperConnection> conn) {
pluginConnected = true;
};
const auto disconnectionCallback = [&]() { pluginConnected = false; };
auto plugin = std::make_shared<FlipperPluginMock>(
"Test", connectionCallback, disconnectionCallback, false);
client.addPlugin(plugin);
client.start();
EXPECT_FALSE(pluginConnected);
client.stop();
EXPECT_FALSE(pluginConnected);
}
} // namespace test
} // namespace flipper
} // namespace facebook