1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-09 20:42:44 +03:00
Files
mvfst/quic/common/test/MonitoredObjectTest.cpp
Brandon Schlinker ea056eb960 Use folly::ObserverContainer for socket observer [2/x]
Summary:
This diff is part of larger change to switch to using `folly::ObserverContainer` (introduced in D27062840).

This diff:
- Renames `quic::Observer` to `quic::LegacyObserver`.
- Switches to using `quic::SocketObserverInterface` instead of `quic::Observer` when referencing structures used for the observer interface. For instance, `quic::Observer::WriteEvent` changes to `quic::SocketObserverInterface::WriteEvent`.

Differential Revision: D35000152

fbshipit-source-id: f387231fd58e8e763c3d7ed0a9c6fcec3b2324e2
2022-04-18 04:19:31 -07:00

37 lines
941 B
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <quic/common/MonitoredObject.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <functional>
using namespace std;
using namespace quic;
using namespace ::testing;
class MockObjectObserver {
public:
MOCK_METHOD(void, accessed, (const string&));
};
TEST(MonitoredObjectTest, TestObserverCalled) {
InSequence s;
string x = "abc";
MockObjectObserver observer;
auto accessFn =
std::bind(&MockObjectObserver::accessed, &observer, placeholders::_1);
MonitoredObject<string> mo(x, accessFn);
EXPECT_CALL(observer, accessed(x)).Times(1);
EXPECT_EQ(x, mo->c_str());
EXPECT_CALL(observer, accessed(x + "d")).Times(1);
mo->append("d");
EXPECT_CALL(observer, accessed(x + "de")).Times(1);
mo->append("e");
}