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 pathbegin-command_test.cpp
84 lines (66 loc) · 2.08 KB
/
begin-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
78
79
80
81
82
83
84
#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::StartsWith;
using ::testing::Matcher;
using ::testing::_;
class BeginCommandTest : public ::testing::Test {
protected:
void FeedCommand(const String& host, const String& auth = "") {
String command_fragment(host);
if (!auth.empty()) {
command_fragment += String(" ") + auth;
}
EXPECT_CALL(in_, readLine())
.WillOnce(Return(command_fragment));
}
void ExpectOutput(const String& output) {
EXPECT_CALL(out_, println(output))
.WillOnce(Return(3));
}
void ExpectOutputStartsWith(const String& output) {
// We have to be explicit here due to the polymorphic nature of println().
const Matcher<const String&> matcher = StartsWith(output);
EXPECT_CALL(out_, println(matcher))
.WillOnce(Return(3));
}
MockInputStream in_;
MockOutputStream out_;
};
TEST_F(BeginCommandTest, hostOnly) {
const String host("http://test.firebase.com");
FeedCommand(host);
ExpectOutput("+OK");
BeginCommand command;
ASSERT_TRUE(command.execute("BEGIN_DB", &in_, &out_));
std::unique_ptr<Firebase> firebase(command.firebase());
EXPECT_EQ("", firebase->auth());
}
TEST_F(BeginCommandTest, hostAndAuth) {
const String host("http://test.firebase.com");
const String auth("afasdfsadfasdssfadsfsd");
FeedCommand(host, auth);
ExpectOutput("+OK");
BeginCommand command;
ASSERT_TRUE(command.execute("BEGIN_DB", &in_, &out_));
std::unique_ptr<Firebase> firebase(command.firebase());
EXPECT_EQ(auth, firebase->auth());
}
TEST_F(BeginCommandTest, neitherHostNorAuth) {
FeedCommand("");
ExpectOutputStartsWith("-FAIL");
BeginCommand command;
ASSERT_FALSE(command.execute("BEGIN_DB", &in_, &out_));
std::unique_ptr<Firebase> firebase(command.firebase());
EXPECT_FALSE(firebase);
}
} // modem
} // firebase