This test has an unclear name and asserts things that are unrelated to the purpose of the test. It would also be simpler using InProcessServer as its basis, not DefaultDisplayServerTestFixture (side note: that name has become misleading.) It is also overcomplicated in its use of management of connection. It should look like:
Just some quick notes:
1088 + * Copyright © 2013 Canonical Ltd.
...
3383 + * Copyright © 2013 Canonical Ltd.
I know this was first proposed months ago - but was it really written last year? And not changed this year?
~~~~
+TEST_F( MirClientTrustS essionAPITest, client_ trust_session_ api) for(mir_ connect( mir_test_ socket, __PRETTY_ FUNCTION_ _, connection_ callback, this)); TRUE(connection != NULL); TRUE(mir_ connection_ is_valid( connection) ); get_error_ message( connection) ); for(mir_ connection_ start_trust_ session( connection, __LINE__, trust_session_ start_callback, NULL, this)); TRUE(trust_ session != NULL); for(mir_ trust_session_ stop(trust_ session, trust_session_ stop_callback, this)); release( connection) ; client_ process( client_ config) ;
+{
+ struct ClientConfig : ClientConfigCommon
+ {
+ void exec()
+ {
+ mir_wait_
+
+ ASSERT_
+ EXPECT_
+ EXPECT_STREQ("", mir_connection_
+
+ mir_wait_
+ ASSERT_
+ EXPECT_EQ(started, 1);
+
+ mir_wait_
+ EXPECT_EQ(stopped, 1);
+
+ mir_connection_
+ }
+ } client_config;
+
+ launch_
+}
This test has an unclear name and asserts things that are unrelated to the purpose of the test. It would also be simpler using InProcessServer as its basis, not DefaultDisplayS erverTestFixtur e (side note: that name has become misleading.) It is also overcomplicated in its use of management of connection. It should look like:
TEST_F( TrustSessionCli entAPI, can_start_ and_stop_ a_trust_ session) wait_for( mir_connection_ start_trust_ session( connection, arbitrarty_ base_session_ pid, trust_session_ start_callback, null_event_ callback, this)); THAT(trust_ session, Ne(NULL)); THAT(started, Eq(1));
{
mir_
ASSERT_
EXPECT_
mir_ wait_for( mir_trust_ session_ stop(trust_ session, trust_session_ stop_callback, this)); THAT(stopped, Eq(1));
EXPECT_
}
~~~~
+struct TrustSession : public testing::Test :NiceMock< mtd::MockTrustS essionListener> trust_session_ listener; :NiceMock< mtd::MockSceneS ession> trusted_helper; :NiceMock< mtd::MockSceneS ession> trusted_app1; :NiceMock< mtd::MockSceneS ession> trusted_app2;
+{
+ TrustSession()
+ {
+ }
+
+ testing:
+ testing:
+ testing:
+ testing:
NiceMock is inappropriate as these are the interactions under test.
+}; TrustSession, start_and_stop)
+}
+
+TEST_F(
the name doesn't reflect what the test is about. There is no mention of adding and removing apps.
+{ shared( trusted_ helper) ; ptr<ms: :Session> shared_app1 = mt::fake_ shared( trusted_ app1); ptr<ms: :Session> shared_app2 = mt::fake_ shared( trusted_ app2); nImpl trust_session( shared_ helper, session( ), shared( trust_session_ listener) );
+ using namespace testing;
+
+ auto shared_helper = mt::fake_
+ std::shared_
+ std::shared_
+
+ ms::TrustSessio
+ ms::a_trust_
+ mt::fake_
All the above initialization could be in the fixture
+ EXPECT_ CALL(trusted_ helper, begin_trust_ session( )).Times( 1); CALL(trusted_ helper, end_trust_ session( )).Times( 1); CALL(trusted_ app1, begin_trust_ session( )).Times( 0); CALL(trusted_ app1, end_trust_ session( )).Times( 0); CALL(trusted_ app2, begin_trust_ session( )).Times( 0); CALL(trusted_ app2, end_trust_ session( )).Times( 0);
+ EXPECT_
+
+ EXPECT_
+ EXPECT_
+
+ EXPECT_
+ EXPECT_
These Times(0) are only relevant because of NiceMock
+ EXPECT_ CALL(trust_ session_ listener, trusted_ session_ beginning( _, shared_ app1)). Times(1) ; CALL(trust_ session_ listener, trusted_ session_ beginning( _, shared_ app2)). Times(1) ; CALL(trust_ session_ listener, trusted_ session_ ending( _, shared_ app1)). Times(1) ; CALL(trust_ session_ listener, trusted_ session_ ending( _, shared_ app2)). Times(1) ; start() ; add_trusted_ child(shared_ app1); add_trusted_ child(shared_ app2); stop();
+ EXPECT_
+
+ EXPECT_
+ EXPECT_
+
+ trust_session.
+ trust_session.
+ trust_session.
+ trust_session.
+}
Really the test is:
TEST_F( TrustSession, trusted_ child_apps_ get_start_ and_stop_ notifications) CALL(trust_ session_ listener, trusted_ session_ beginning( _, shared_ app1)). Times(1) ; CALL(trust_ session_ listener, trusted_ session_ beginning( _, shared_ app2)). Times(1) ;
{
EXPECT_
EXPECT_
EXPECT_ CALL(trust_ session_ listener, trusted_ session_ ending( _, shared_ app1)). Times(1) ; CALL(trust_ session_ listener, trusted_ session_ ending( _, shared_ app2)). Times(1) ;
EXPECT_
trust_ session. add_trusted_ child(shared_ app1); session. add_trusted_ child(shared_ app2);
trust_
}
And the fixture:
struct TrustSession : public testing::Test :NiceMock< mtd::MockTrustS essionListener> trust_session_ listener; :MockSceneSessi on trusted_helper; :MockSceneSessi on trusted_app1; :MockSceneSessi on trusted_app2;
{
testing:
mtd:
mtd:
mtd:
std: :shared_ ptr<ms: :Session> shared_helper = mt::fake_ shared( trusted_ helper) ; :shared_ ptr<ms: :Session> shared_app1 = mt::fake_ shared( trusted_ app1); :shared_ ptr<ms: :Session> shared_app2 = mt::fake_ shared( trusted_ app2);
std:
std:
ms: :TrustSessionIm pl trust_session{ shared_ helper,
ms::a_trust_ session( ),
mt::fake_ shared( trust_session_ listener) };
void SetUp()
EXPECT_ CALL(trusted_ helper, begin_trust_ session( )).Times( 1);
EXPECT_ CALL(trusted_ helper, end_trust_ session( )).Times( 1);
{
InSequence seq;
}
void TearDown()
trust_ session. stop();
{
}
};