@@ -17,41 +17,41 @@ using ::testing::_;
17
17
class StreamCommandTest : public ::testing::Test {
18
18
protected:
19
19
void SetUp () override {
20
- stream_.reset (new FirebaseStream ());
21
20
}
22
21
23
- bool RunCommand (const FirebaseError& error ) {
22
+ bool RunCommand () {
24
23
StreamCommand cmd (&fbase_);
25
24
return cmd.execute (" BEGIN_STREAM" , &in_, &out_);
26
25
}
27
26
28
27
MockInputStream in_;
29
28
MockOutputStream out_;
30
29
MockFirebase fbase_;
31
- std::unique_ptr<FirebaseStream> stream_;
32
30
};
33
31
34
32
TEST_F (StreamCommandTest, streams) {
35
33
const String path (" /test/path" );
34
+
35
+ const String no_error = " " ;
36
+ EXPECT_CALL (fbase_, error ()).WillRepeatedly (ReturnRef (no_error));
37
+
38
+ const String data = " TestValue" ;
39
+ const String value (String (" {\" path\" :\" /test/path\" ,\" data\" :\" " ) + data + " \" ,\" type\" :\" PUT\" }" );
40
+
41
+ const FirebaseObject fo = FirebaseObject (value.c_str ());
42
+ EXPECT_CALL (fbase_, readEvent ()).WillRepeatedly (Return (fo));
43
+
36
44
EXPECT_CALL (in_, available ())
37
45
.WillRepeatedly (Return (true ));
38
46
39
47
EXPECT_CALL (in_, readLine ())
40
48
.WillOnce (Return (path))
41
49
.WillOnce (Return (" END_STREAM" ));
42
50
43
- const String data = " Test Value" ;
44
- const String value (String (" {\" path\" : \" /test/path\" , \" data\" : \" " ) + data + " \" }" );
45
- EXPECT_CALL (fbase_, available ())
51
+ EXPECT_CALL (fbase_, available ())
46
52
.WillOnce (Return (true ))
47
53
.WillRepeatedly (Return (false ));
48
-
49
- EXPECT_CALL (fbase_, startStreaming ());
50
- EXPECT_CALL (*stream_, read (_))
51
- .WillOnce (Invoke ([&value](std::string& json) {
52
- json = value.c_str ();
53
- return FirebaseStream::PUT;
54
- }));
54
+ EXPECT_CALL (fbase_, stream (path));
55
55
56
56
EXPECT_CALL (out_, print (String (" +" )))
57
57
.WillOnce (Return (1 ));
@@ -70,21 +70,23 @@ TEST_F(StreamCommandTest, streams) {
70
70
EXPECT_CALL (out_, println (String (" +OK" )))
71
71
.WillOnce (Return (1 ));
72
72
73
- ASSERT_TRUE (RunCommand (FirebaseError () ));
73
+ ASSERT_TRUE (RunCommand ());
74
74
}
75
75
76
76
TEST_F (StreamCommandTest, handlesError) {
77
- FirebaseError error (- 200 , " Test Error." );
77
+ const String error (" Test Error." );
78
78
const String path (" /test/path" );
79
79
EXPECT_CALL (in_, readLine ())
80
80
.WillOnce (Return (path));
81
81
82
+ EXPECT_CALL (fbase_, error ()).WillRepeatedly (ReturnRef (error));
83
+
82
84
EXPECT_CALL (out_, print (String (" -FAIL " )))
83
85
.WillOnce (Return (1 ));
84
86
85
- EXPECT_CALL (out_, println (String (error.message (). c_str ())))
87
+ EXPECT_CALL (out_, println (String (error.c_str ())))
86
88
.WillOnce (Return (1 ));
87
- ASSERT_FALSE (RunCommand (error ));
89
+ ASSERT_FALSE (RunCommand ());
88
90
}
89
91
90
92
} // modem
0 commit comments