This repository was archived by the owner on Mar 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathget-command_test.cpp
77 lines (59 loc) · 1.76 KB
/
get-command_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "Firebase.h"
#include "gtest/gtest.h"
#include "modem/db/commands.h"
#include "test/modem/mock-input-stream.h"
#include "test/modem/mock-output-stream.h"
#include "test/mock-firebase.h"
namespace firebase {
namespace modem {
using ::testing::Return;
using ::testing::ByMove;
using ::testing::ReturnRef;
using ::testing::_;
class GetCommandTest : public ::testing::Test {
protected:
void SetUp() override {
get_.reset(new MockFirebaseGet());
}
void FeedCommand(const String& path) {
const String command_fragment(String(" ") + path);
EXPECT_CALL(in_, readLine())
.WillOnce(Return(command_fragment));
}
bool RunCommand(const FirebaseError& error) {
EXPECT_CALL(*get_, error())
.WillRepeatedly(ReturnRef(error));
EXPECT_CALL(fbase_, getPtr(_))
.WillOnce(Return(ByMove(std::move(get_))));
GetCommand getCmd(&fbase_);
return getCmd.execute("GET", &in_, &out_);
}
MockInputStream in_;
MockOutputStream out_;
MockFirebase fbase_;
std::unique_ptr<MockFirebaseGet> get_;
};
TEST_F(GetCommandTest, gets) {
const String path("/test/path");
FeedCommand(path);
const String value("Test value");
EXPECT_CALL(*get_, response())
.WillOnce(ReturnRef(value));
EXPECT_CALL(out_, print(String("+")))
.WillOnce(Return(1));
EXPECT_CALL(out_, println(value))
.WillOnce(Return(1));
ASSERT_TRUE(RunCommand(FirebaseError()));
}
TEST_F(GetCommandTest, handlesError) {
FirebaseError error(-200, "Test Error.");
const String path("/test/path");
FeedCommand(path);
EXPECT_CALL(out_, print(String("-FAIL ")))
.WillOnce(Return(1));
EXPECT_CALL(out_, println(String(error.message().c_str())))
.WillOnce(Return(1));
ASSERT_FALSE(RunCommand(error));
}
} // modem
} // firebase