@@ -57,6 +57,15 @@ class TestProxyBase : public ProxyBase
5757 }
5858};
5959
60+ struct NonTriviallyConstructibleType
61+ {
62+ NonTriviallyConstructibleType () : value{kInitialValue } {}
63+
64+ static constexpr std::int32_t kInitialValue {21 };
65+
66+ std::int32_t value;
67+ };
68+
6069template <typename MethodType>
6170class ProxyMethodTestFixture : public ::testing::Test
6271{
@@ -115,6 +124,11 @@ using WithInArgs = ::testing::Types<InArgsAndReturn, InArgsOnly>;
115124using WithoutInArgs = ::testing::Types<ReturnOnly, NoInArgsOrReturn>;
116125using WithResult = ::testing::Types<InArgsAndReturn, ReturnOnly>;
117126
127+ using NonTrivialConstructibleInArgsAndReturn = NonTriviallyConstructibleType(NonTriviallyConstructibleType,
128+ NonTriviallyConstructibleType);
129+ using NonTrivialConstructibleInArgsOnly = void (NonTriviallyConstructibleType, NonTriviallyConstructibleType);
130+ using NonTrivialConstructibleReturnOnly = NonTriviallyConstructibleType();
131+
118132template <typename T>
119133using ProxyMethodAllArgCombinationsTestFixture = ProxyMethodTestFixture<T>;
120134TYPED_TEST_SUITE (ProxyMethodAllArgCombinationsTestFixture, AllArgCombinations, );
@@ -127,15 +141,18 @@ template <typename T>
127141using ProxyMethodWithoutInArgsTestFixture = ProxyMethodTestFixture<T>;
128142TYPED_TEST_SUITE (ProxyMethodWithoutInArgsTestFixture, WithoutInArgs, );
129143
130- template <typename T>
131- using ProxyMethodWithResultTestFixture = ProxyMethodTestFixture<T>;
132- TYPED_TEST_SUITE (ProxyMethodWithResultTestFixture, WithResult, );
133-
134144using ProxyMethodWithInArgsAndReturnFixture = ProxyMethodTestFixture<InArgsAndReturn>;
135145using ProxyMethodWithReturnOnlyFixture = ProxyMethodTestFixture<ReturnOnly>;
136146using ProxyMethodWithNoInArgsOrReturnFixture = ProxyMethodTestFixture<NoInArgsOrReturn>;
137147using ProxyMethodWithInArgsOnlyFixture = ProxyMethodTestFixture<InArgsOnly>;
138148
149+ using ProxyMethodWithNonTrivialConstructibleInArgsAndReturnFixture =
150+ ProxyMethodTestFixture<NonTrivialConstructibleInArgsAndReturn>;
151+ using ProxyMethodWithNonTrivialConstructibleReturnOnlyFixture =
152+ ProxyMethodTestFixture<NonTrivialConstructibleReturnOnly>;
153+ using ProxyMethodWithNonTrivialConstructibleInArgsOnlyFixture =
154+ ProxyMethodTestFixture<NonTrivialConstructibleInArgsOnly>;
155+
139156TYPED_TEST (ProxyMethodAllArgCombinationsTestFixture, Construction)
140157{
141158 // When constructing a ProxyMethod with all combinations of InArgs / return types
@@ -804,5 +821,174 @@ TEST(DetermineNextAvailableQueueSlot, DetermineNextAvailableQueueSlotCanFail)
804821 EXPECT_EQ (result, MakeUnexpected (ComErrc::kCallQueueFull ));
805822}
806823
824+ TEST_F (ProxyMethodWithNonTrivialConstructibleInArgsAndReturnFixture, InitializeInArgsAndReturnValuesInitializesInArgs)
825+ {
826+ this ->GivenAValidProxyMethod ();
827+
828+ // When calling InitializeInArgsAndReturnValues
829+ const auto result = this ->unit_ ->InitializeInArgsAndReturnValues ();
830+
831+ // Then a valid result is returned
832+ EXPECT_TRUE (result.has_value ());
833+
834+ // and Allocate returns a pointer pointing to an initialized object (i.e. the non-trivial default constructor was
835+ // called, initializing value to NonTriviallyConstructibleType::kInitialValue
836+ auto method_in_arg_ptr_tuple = this ->unit_ ->Allocate ();
837+ ASSERT_TRUE (method_in_arg_ptr_tuple.has_value ());
838+
839+ auto & method_in_arg_ptr_0 = std::get<0 >(method_in_arg_ptr_tuple.value ());
840+ NonTriviallyConstructibleType& in_arg_0{*method_in_arg_ptr_0};
841+ EXPECT_EQ (in_arg_0.value , NonTriviallyConstructibleType::kInitialValue );
842+
843+ auto & method_in_arg_ptr_1 = std::get<1 >(method_in_arg_ptr_tuple.value ());
844+ NonTriviallyConstructibleType& in_arg_1{*method_in_arg_ptr_1};
845+ EXPECT_EQ (in_arg_1.value , NonTriviallyConstructibleType::kInitialValue );
846+ }
847+
848+ TEST_F (ProxyMethodWithNonTrivialConstructibleInArgsAndReturnFixture,
849+ InitializeInArgsAndReturnValuesPropagatesErrorFromGetInArgsBuffer)
850+ {
851+ this ->GivenAValidProxyMethod ();
852+
853+ // Expect that GetInArgsBuffer is called once on the binding mock and returns an error.
854+ EXPECT_CALL (this ->proxy_method_binding_mock_ , GetInArgsBuffer (0U ))
855+ .WillOnce (Return (MakeUnexpected (ComErrc::kBindingFailure )));
856+
857+ // When calling InitializeInArgsAndReturnValues
858+ const auto result = this ->unit_ ->InitializeInArgsAndReturnValues ();
859+
860+ // Then an error is returned
861+ ASSERT_FALSE (result.has_value ());
862+ EXPECT_EQ (result.error (), ComErrc::kBindingFailure );
863+ }
864+
865+ TEST_F (ProxyMethodWithNonTrivialConstructibleInArgsAndReturnFixture,
866+ InitializeInArgsAndReturnValuesPropagatesErrorFromGetReturnValueBuffer)
867+ {
868+ this ->GivenAValidProxyMethod ();
869+
870+ // Expect that GetReturnValueBuffer is called once on the binding mock and returns an error.
871+ EXPECT_CALL (this ->proxy_method_binding_mock_ , GetReturnValueBuffer (0U ))
872+ .WillOnce (Return (MakeUnexpected (ComErrc::kBindingFailure )));
873+
874+ // When calling InitializeInArgsAndReturnValues
875+ const auto result = this ->unit_ ->InitializeInArgsAndReturnValues ();
876+
877+ // Then an error is returned
878+ ASSERT_FALSE (result.has_value ());
879+ EXPECT_EQ (result.error (), ComErrc::kBindingFailure );
880+ }
881+
882+ TEST_F (ProxyMethodWithNonTrivialConstructibleInArgsAndReturnFixture,
883+ CallOperator_ZeroCopy_InitializeInArgsAndReturnValuesInitializesInReturn)
884+ {
885+ this ->GivenAValidProxyMethod ();
886+
887+ // When calling InitializeInArgsAndReturnValues
888+ this ->unit_ ->InitializeInArgsAndReturnValues ();
889+
890+ // Then the zero copy call operator returns a pointer pointing to an initialized object (i.e. the non-trivial
891+ // default constructor was called, initializing value to NonTriviallyConstructibleType::kInitialValue
892+ auto method_in_arg_ptr_tuple = this ->unit_ ->Allocate ();
893+ ASSERT_TRUE (method_in_arg_ptr_tuple.has_value ());
894+
895+ auto & method_in_arg_ptr_0 = std::get<0 >(method_in_arg_ptr_tuple.value ());
896+ auto & method_in_arg_ptr_1 = std::get<1 >(method_in_arg_ptr_tuple.value ());
897+ auto method_return_ptr = this ->unit_ ->operator ()(std::move (method_in_arg_ptr_0), std::move (method_in_arg_ptr_1));
898+ ASSERT_TRUE (method_return_ptr.has_value ());
899+
900+ NonTriviallyConstructibleType& return_value{*(method_return_ptr.value ())};
901+ EXPECT_EQ (return_value.value , NonTriviallyConstructibleType::kInitialValue );
902+ }
903+
904+ TEST_F (ProxyMethodWithNonTrivialConstructibleInArgsAndReturnFixture,
905+ CallOperator_WithCopy_InitializeInArgsAndReturnValuesInitializesInReturn)
906+ {
907+ this ->GivenAValidProxyMethod ();
908+
909+ // When calling InitializeInArgsAndReturnValues
910+ this ->unit_ ->InitializeInArgsAndReturnValues ();
911+
912+ // Then the copy call operator returns a pointer pointing to an initialized object (i.e. the non-trivial
913+ // default constructor was called, initializing value to NonTriviallyConstructibleType::kInitialValue
914+ auto method_return_ptr = this ->unit_ ->operator ()(NonTriviallyConstructibleType{}, NonTriviallyConstructibleType{});
915+ ASSERT_TRUE (method_return_ptr.has_value ());
916+
917+ NonTriviallyConstructibleType& return_value{*(method_return_ptr.value ())};
918+ EXPECT_EQ (return_value.value , NonTriviallyConstructibleType::kInitialValue );
919+ }
920+
921+ TEST_F (ProxyMethodWithNonTrivialConstructibleInArgsOnlyFixture, InitializeInArgsAndReturnValuesInitializesInArgs)
922+ {
923+ this ->GivenAValidProxyMethod ();
924+
925+ // When calling InitializeInArgsAndReturnValues
926+ this ->unit_ ->InitializeInArgsAndReturnValues ();
927+
928+ // Then Allocate returns a pointer pointing to an initialized object (i.e. the non-trivial default constructor was
929+ // called, initializing value to NonTriviallyConstructibleType::kInitialValue
930+ auto method_in_arg_ptr_tuple = this ->unit_ ->Allocate ();
931+ ASSERT_TRUE (method_in_arg_ptr_tuple.has_value ());
932+
933+ auto & method_in_arg_ptr_0 = std::get<0 >(method_in_arg_ptr_tuple.value ());
934+ NonTriviallyConstructibleType& in_arg_0{*method_in_arg_ptr_0};
935+ EXPECT_EQ (in_arg_0.value , NonTriviallyConstructibleType::kInitialValue );
936+
937+ auto & method_in_arg_ptr_1 = std::get<1 >(method_in_arg_ptr_tuple.value ());
938+ NonTriviallyConstructibleType& in_arg_1{*method_in_arg_ptr_1};
939+ EXPECT_EQ (in_arg_1.value , NonTriviallyConstructibleType::kInitialValue );
940+ }
941+
942+ TEST_F (ProxyMethodWithNonTrivialConstructibleInArgsOnlyFixture,
943+ InitializeInArgsAndReturnValuesPropagatesErrorFromBinding)
944+ {
945+ this ->GivenAValidProxyMethod ();
946+
947+ // Expect that GetInArgsBuffer is called once on the binding mock and returns an error.
948+ EXPECT_CALL (this ->proxy_method_binding_mock_ , GetInArgsBuffer (0U ))
949+ .WillOnce (Return (MakeUnexpected (ComErrc::kBindingFailure )));
950+
951+ // When calling InitializeInArgsAndReturnValues
952+ const auto result = this ->unit_ ->InitializeInArgsAndReturnValues ();
953+
954+ // Then an error is returned
955+ ASSERT_FALSE (result.has_value ());
956+ EXPECT_EQ (result.error (), ComErrc::kBindingFailure );
957+ }
958+
959+ TEST_F (ProxyMethodWithNonTrivialConstructibleReturnOnlyFixture,
960+ CallOperator_WithCopy_InitializeInArgsAndReturnValuesInitializesInReturn)
961+ {
962+ this ->GivenAValidProxyMethod ();
963+
964+ // When calling InitializeInArgsAndReturnValues
965+ this ->unit_ ->InitializeInArgsAndReturnValues ();
966+
967+ // Then the copy call operator returns a pointer pointing to an initialized object (i.e. the non-trivial
968+ // default constructor was called, initializing value to NonTriviallyConstructibleType::kInitialValue
969+ auto method_return_ptr = this ->unit_ ->operator ()();
970+ ASSERT_TRUE (method_return_ptr.has_value ());
971+
972+ NonTriviallyConstructibleType& return_value{*(method_return_ptr.value ())};
973+ EXPECT_EQ (return_value.value , NonTriviallyConstructibleType::kInitialValue );
974+ }
975+
976+ TEST_F (ProxyMethodWithNonTrivialConstructibleReturnOnlyFixture,
977+ InitializeInArgsAndReturnValuesPropagatesErrorFromBinding)
978+ {
979+ this ->GivenAValidProxyMethod ();
980+
981+ // Expect that GetReturnValueBuffer is called once on the binding mock and returns an error.
982+ EXPECT_CALL (this ->proxy_method_binding_mock_ , GetReturnValueBuffer (0U ))
983+ .WillOnce (Return (MakeUnexpected (ComErrc::kBindingFailure )));
984+
985+ // When calling InitializeInArgsAndReturnValues
986+ const auto result = this ->unit_ ->InitializeInArgsAndReturnValues ();
987+
988+ // Then an error is returned
989+ ASSERT_FALSE (result.has_value ());
990+ EXPECT_EQ (result.error (), ComErrc::kBindingFailure );
991+ }
992+
807993} // namespace
808994} // namespace score::mw::com::impl
0 commit comments