1313// limitations under the License.
1414
1515#include < cstring>
16+ #include < memory>
1617#include < string>
1718
1819#include " gmock/gmock.h"
@@ -67,9 +68,9 @@ TEST(StringopTest, ProtobufStringDuplication) {
6768}
6869
6970TEST (StringopTest, ProtobufStringReversal) {
70- StringopSandbox sandbox;
71- ASSERT_THAT (sandbox. Init (), IsOk ());
72- StringopApi api (& sandbox);
71+ SAPI_ASSERT_OK_AND_ASSIGN (std::unique_ptr< StringopSandbox> sandbox,
72+ sapi::MakeSandbox<StringopSandbox> ());
73+ StringopApi api (sandbox. get () );
7374
7475 stringop::StringReverse proto;
7576 proto.set_input (" Hello" );
@@ -84,9 +85,9 @@ TEST(StringopTest, ProtobufStringReversal) {
8485}
8586
8687TEST (StringopTest, RawStringDuplication) {
87- StringopSandbox sandbox;
88- ASSERT_THAT (sandbox. Init (), IsOk ());
89- StringopApi api (& sandbox);
88+ SAPI_ASSERT_OK_AND_ASSIGN (std::unique_ptr< StringopSandbox> sandbox,
89+ sapi::MakeSandbox<StringopSandbox> ());
90+ StringopApi api (sandbox. get () );
9091
9192 sapi::v::LenVal param (" 0123456789" , 10 );
9293 SAPI_ASSERT_OK_AND_ASSIGN (int return_value,
@@ -101,9 +102,9 @@ TEST(StringopTest, RawStringDuplication) {
101102}
102103
103104TEST (StringopTest, RawStringReversal) {
104- StringopSandbox sandbox;
105- ASSERT_THAT (sandbox. Init (), IsOk ());
106- StringopApi api (& sandbox);
105+ SAPI_ASSERT_OK_AND_ASSIGN (std::unique_ptr< StringopSandbox> sandbox,
106+ sapi::MakeSandbox<StringopSandbox> ());
107+ StringopApi api (sandbox. get () );
107108
108109 sapi::v::LenVal param (" 0123456789" , 10 );
109110 {
@@ -121,7 +122,7 @@ TEST(StringopTest, RawStringReversal) {
121122 {
122123 // Let's call it again with different data as argument, reusing the
123124 // existing LenVal object.
124- EXPECT_THAT (param.ResizeData (sandbox. rpc_channel (), 16 ), IsOk ());
125+ EXPECT_THAT (param.ResizeData (sandbox-> rpc_channel (), 16 ), IsOk ());
125126 memcpy (param.GetData () + 10 , " ABCDEF" , 6 );
126127 absl::string_view data (reinterpret_cast <const char *>(param.GetData ()),
127128 param.GetDataSize ());
@@ -139,26 +140,27 @@ TEST(StringopTest, RawStringReversal) {
139140}
140141
141142TEST (StringopTest, RawStringLength) {
142- StringopSandbox sandbox;
143- ASSERT_THAT (sandbox. Init (), IsOk ());
144- StringopApi api (& sandbox);
143+ SAPI_ASSERT_OK_AND_ASSIGN (std::unique_ptr< StringopSandbox> sandbox,
144+ sapi::MakeSandbox<StringopSandbox> ());
145+ StringopApi api (sandbox. get () );
145146 SAPI_ASSERT_OK_AND_ASSIGN (void * target_mem_ptr, api.get_raw_c_string ());
146147 SAPI_ASSERT_OK_AND_ASSIGN (size_t len,
147- sandbox. rpc_channel ()->Strlen (target_mem_ptr));
148+ sandbox-> rpc_channel ()->Strlen (target_mem_ptr));
148149 EXPECT_THAT (len, Eq (10 ));
149150}
150151
151152TEST (StringopTest, RawStringReading) {
152- StringopSandbox sandbox;
153- ASSERT_THAT (sandbox. Init (), IsOk ());
154- StringopApi api (& sandbox);
153+ SAPI_ASSERT_OK_AND_ASSIGN (std::unique_ptr< StringopSandbox> sandbox,
154+ sapi::MakeSandbox<StringopSandbox> ());
155+ StringopApi api (sandbox. get () );
155156 SAPI_ASSERT_OK_AND_ASSIGN (void * target_mem_ptr, api.get_raw_c_string ());
156157 SAPI_ASSERT_OK_AND_ASSIGN (size_t len,
157- sandbox. rpc_channel ()->Strlen (target_mem_ptr));
158+ sandbox-> rpc_channel ()->Strlen (target_mem_ptr));
158159 EXPECT_THAT (len, Eq (10 ));
159160
160161 SAPI_ASSERT_OK_AND_ASSIGN (
161- std::string data, sandbox.GetCString (sapi::v::RemotePtr (target_mem_ptr)));
162+ std::string data,
163+ sandbox->GetCString (sapi::v::RemotePtr (target_mem_ptr)));
162164 EXPECT_THAT (data, StrEq (" Ten chars." ));
163165}
164166
0 commit comments