28#include <gmock/gmock.h>
29#include <gtest/gtest.h>
50 ASSERT_EQ(port.getId(), 0);
51 ASSERT_EQ(port2.
getId(), 2);
55TEST(PortTest, OneSidedConnection)
60 ASSERT_FALSE(port.isConnected());
67 ASSERT_TRUE(port.isConnected());
68 ASSERT_EQ(&port.getPeer(), &port2);
73 ASSERT_FALSE(port.isConnected());
78TEST(PortTest, TwoSidedConnection)
83 ASSERT_FALSE(port.isConnected());
89 ASSERT_TRUE(port.isConnected());
90 ASSERT_EQ(&port.getPeer(), &port2);
92 ASSERT_EQ(&port2.
getPeer(), &port);
96 ASSERT_FALSE(port.isConnected());
98 ASSERT_EQ(&port2.
getPeer(), &port);
102 ASSERT_FALSE(port.isConnected());
107TEST(PortTest, OverwriteConnection)
109 TestPort port(0), port2(2), port3(6);
112 ASSERT_FALSE(port.isConnected());
113 ASSERT_FALSE(port2.isConnected());
118 ASSERT_TRUE(port.isConnected());
119 ASSERT_EQ(&port.getPeer(), &port2);
120 ASSERT_FALSE(port2.isConnected());
125 ASSERT_TRUE(port.isConnected());
126 ASSERT_EQ(&port.getPeer(), &port3);
127 ASSERT_FALSE(port2.isConnected());
132TEST(PortDeathTest, TakeOverNoPort)
135 GTEST_SKIP() <<
"Skipping as assertions are "
136 "stripped out of fast builds";
143TEST(PortDeathTest, TakeOverDisconnected)
146 GTEST_SKIP() <<
"Skipping as assertions are "
147 "stripped out of fast builds";
150 ASSERT_DEATH(port.takeOverFrom(&port2),
"");
158TEST(PortDeathTest, TakeOverConnected)
161 GTEST_SKIP() <<
"Skipping as assertions are "
162 "stripped out of fast builds";
166 ASSERT_DEATH(port.takeOverFrom(&port2),
"");
174TEST(PortDeathTest, TakeOverOneSided)
177 GTEST_SKIP() <<
"Skipping as assertions are "
178 "stripped out of fast builds";
180 TestPort port(0), port2(2), port3(6);
182 ASSERT_DEATH(port.takeOverFrom(&port2),
"");
192TEST(PortTest, TakeOverOneSided)
194 TestPort port(0), port2(2), port3(6), port4(10);
197 port.takeOverFrom(&port2);
199 ASSERT_TRUE(port.isConnected());
200 ASSERT_EQ(&port.getPeer(), &port3);
201 ASSERT_FALSE(port2.isConnected());
202 ASSERT_TRUE(port3.isConnected());
203 ASSERT_EQ(&port3.getPeer(), &port);
215 TestPort port(0), port2(2), port3(6);
218 port.takeOverFrom(&port2);
220 ASSERT_TRUE(port.isConnected());
221 ASSERT_EQ(&port.getPeer(), &port3);
223 ASSERT_EQ(&port3.
getPeer(), &port);
231 std::ostringstream buffer;
232 old = std::cout.rdbuf(buffer.rdbuf());
236 std::cout << port << std::endl;
237 EXPECT_EQ(buffer.str(),
"TestPort\n");
240 std::cout.rdbuf(old);
Ports are used to interface objects to each other.
Port & getPeer()
Return a reference to this port's peer.
bool isConnected() const
Is this port currently connected to a peer?
void takeOverFrom(Port *old)
A utility function to make it easier to swap out ports.
virtual void unbind()
Dettach from a peer port.
virtual void bind(Port &peer)
Attach to a peer port.
PortID getId() const
Get the port id.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
TEST(PortTest, GetId)
Test getting the port id.