Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 24cea1c

Browse files
committed
unit tests are all working with new changes
1 parent 657c6d3 commit 24cea1c

9 files changed

+61
-56
lines changed

modem/json_util.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef MODEM_JSON_UTIL_H
2+
#define MODEM_JSON_UTIL_H
3+
4+
namespace firebase {
5+
namespace modem {
6+
7+
// TODO(edcoyne): We should use a json library to escape.
8+
inline String EncodeForJson(String input) {
9+
input.replace("\\", "\\\\");
10+
input.replace("\"", "\\\"");
11+
return "\"" + input + "\"";
12+
}
13+
14+
} // modem
15+
} // firebase
16+
17+
#endif // MODEM_JSON_UTIL_H

modem/push-command.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
#include "modem/commands.h"
2+
#include "modem/json_util.h"
23

34
namespace firebase {
45
namespace modem {
5-
namespace {
6-
// TODO(edcoyne): We should use a json library to escape.
7-
String EncodeForJson(String input) {
8-
input.replace("\\", "\\\\");
9-
input.replace("\"", "\\\"");
10-
return "\"" + input + "\"";
11-
}
12-
} // namespace
136

147
bool PushCommand::execute(const String& command,
158
InputStream* in, OutputStream* out) {

modem/set-command.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
#include "modem/commands.h"
2+
#include "modem/json_util.h"
23

34
namespace firebase {
45
namespace modem {
5-
namespace {
6-
// TODO(edcoyne): We should use a json library to escape.
7-
String EncodeForJson(String input) {
8-
input.replace("\\", "\\\\");
9-
input.replace("\"", "\\\"");
10-
return "\"" + input + "\"";
11-
}
12-
} // namespace
136

147
bool SetCommand::execute(const String& command,
158
InputStream* in, OutputStream* out) {

modem/test/Makefile

+20-20
Original file line numberDiff line numberDiff line change
@@ -130,54 +130,54 @@ FirebaseHttpClient_dummy.o : $(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dum
130130

131131
# Builds tests.
132132

133-
get-command.o : $(PROJECT_ROOT)/modem/get-command.cc
134-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/get-command.cc
133+
get-command.o : $(PROJECT_ROOT)/modem/get-command.cpp
134+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/get-command.cpp
135135

136-
get-command_test.o : $(TEST_DIR)/get-command_test.cc $(GMOCK_HEADERS)
137-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/get-command_test.cc
136+
get-command_test.o : $(TEST_DIR)/get-command_test.cpp $(GMOCK_HEADERS)
137+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/get-command_test.cpp
138138

139139
get-command_test : get-command_test.o Firebase.o FirebaseHttpClient_dummy.o get-command.o gmock_main.a \
140140
arduino_mock_all.a
141141
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
142142

143143

144-
set-command.o : $(PROJECT_ROOT)/modem/set-command.cc
145-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/set-command.cc
144+
set-command.o : $(PROJECT_ROOT)/modem/set-command.cpp
145+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/set-command.cpp
146146

147-
set-command_test.o : $(TEST_DIR)/set-command_test.cc $(GMOCK_HEADERS)
148-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/set-command_test.cc
147+
set-command_test.o : $(TEST_DIR)/set-command_test.cpp $(GMOCK_HEADERS)
148+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/set-command_test.cpp
149149

150150
set-command_test : set-command.o set-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
151151
arduino_mock_all.a
152152
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
153153

154154

155-
remove-command.o : $(PROJECT_ROOT)/modem/remove-command.cc
156-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/remove-command.cc
155+
remove-command.o : $(PROJECT_ROOT)/modem/remove-command.cpp
156+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/remove-command.cpp
157157

158-
remove-command_test.o : $(TEST_DIR)/remove-command_test.cc $(GMOCK_HEADERS)
159-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/remove-command_test.cc
158+
remove-command_test.o : $(TEST_DIR)/remove-command_test.cpp $(GMOCK_HEADERS)
159+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/remove-command_test.cpp
160160

161161
remove-command_test : remove-command.o remove-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
162162
arduino_mock_all.a
163163
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
164164

165165

166-
push-command.o : $(PROJECT_ROOT)/modem/push-command.cc
167-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/push-command.cc
166+
push-command.o : $(PROJECT_ROOT)/modem/push-command.cpp
167+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/push-command.cpp
168168

169-
push-command_test.o : $(TEST_DIR)/push-command_test.cc $(GMOCK_HEADERS)
170-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/push-command_test.cc
169+
push-command_test.o : $(TEST_DIR)/push-command_test.cpp $(GMOCK_HEADERS)
170+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/push-command_test.cpp
171171

172172
push-command_test : push-command.o push-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
173173
arduino_mock_all.a
174174
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
175175

176-
begin-command.o : $(PROJECT_ROOT)/modem/begin-command.cc
177-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/begin-command.cc
176+
begin-command.o : $(PROJECT_ROOT)/modem/begin-command.cpp
177+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/modem/begin-command.cpp
178178

179-
begin-command_test.o : $(TEST_DIR)/begin-command_test.cc $(GMOCK_HEADERS)
180-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/begin-command_test.cc
179+
begin-command_test.o : $(TEST_DIR)/begin-command_test.cpp $(GMOCK_HEADERS)
180+
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/begin-command_test.cpp
181181

182182
begin-command_test : begin-command.o begin-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
183183
arduino_mock_all.a

modem/test/begin-command_test.cc renamed to modem/test/begin-command_test.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "gtest/gtest.h"
2-
#include "test/mock-firebase.h"
3-
#include "modem/test/mock-output-stream.h"
4-
#include "modem/test/mock-input-stream.h"
51
#include "Firebase.h"
2+
#include "gtest/gtest.h"
63
#include "modem/commands.h"
4+
#include "modem/test/mock-input-stream.h"
5+
#include "modem/test/mock-output-stream.h"
6+
#include "test/mock-firebase.h"
77

88
namespace firebase {
99
namespace modem {
@@ -17,7 +17,7 @@ using ::testing::_;
1717
class BeginCommandTest : public ::testing::Test {
1818
protected:
1919
void FeedCommand(const String& host, const String& auth = "") {
20-
String command_fragment(String(" ") + host);
20+
String command_fragment(host);
2121
if (!auth.empty()) {
2222
command_fragment += String(" ") + auth;
2323
}

modem/test/get-command_test.cc renamed to modem/test/get-command_test.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
#include "Firebase.h"
12
#include "gtest/gtest.h"
2-
#include "modem/test/mock-output-stream.h"
3+
#include "modem/commands.h"
34
#include "modem/test/mock-input-stream.h"
5+
#include "modem/test/mock-output-stream.h"
46
#include "test/mock-firebase.h"
5-
#include "Firebase.h"
6-
#include "modem/commands.h"
77

88
namespace firebase {
99
namespace modem {

modem/test/push-command_test.cc renamed to modem/test/push-command_test.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include "gtest/gtest.h"
2-
#include "test/mock-firebase.h"
3-
#include "modem/test/mock-output-stream.h"
4-
#include "modem/test/mock-input-stream.h"
51
#include "Firebase.h"
2+
#include "gtest/gtest.h"
63
#include "modem/commands.h"
4+
#include "modem/json_util.h"
5+
#include "modem/test/mock-input-stream.h"
6+
#include "modem/test/mock-output-stream.h"
7+
#include "test/mock-firebase.h"
78

89
namespace firebase {
910
namespace modem {
@@ -43,11 +44,11 @@ class PushCommandTest : public ::testing::Test {
4344
EXPECT_CALL(*push_, error())
4445
.WillRepeatedly(ReturnRef(error));
4546

46-
EXPECT_CALL(fbase_, pushPtr(_, data))
47+
EXPECT_CALL(fbase_, pushPtr(_, EncodeForJson(data)))
4748
.WillOnce(Return(ByMove(std::move(push_))));
4849

4950
PushCommand pushCmd(&fbase_);
50-
return pushCmd.execute("SET", &in_, &out_);
51+
return pushCmd.execute("PUSH", &in_, &out_);
5152
}
5253

5354
MockInputStream in_;

modem/test/remove-command_test.cc renamed to modem/test/remove-command_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ TEST_F(RemoveCommandTest, success) {
4646
const String path("/test/path");
4747
FeedCommand(path);
4848

49-
EXPECT_CALL(out_, print(String("+OK")))
49+
EXPECT_CALL(out_, println(String("+OK")))
5050
.WillOnce(Return(3));
5151

5252
ASSERT_TRUE(RunCommand(FirebaseError()));

modem/test/set-command_test.cc renamed to modem/test/set-command_test.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include "gtest/gtest.h"
2-
#include "test/mock-firebase.h"
3-
#include "modem/test/mock-output-stream.h"
4-
#include "modem/test/mock-input-stream.h"
51
#include "Firebase.h"
2+
#include "gtest/gtest.h"
63
#include "modem/commands.h"
4+
#include "modem/json_util.h"
5+
#include "modem/test/mock-input-stream.h"
6+
#include "modem/test/mock-output-stream.h"
7+
#include "test/mock-firebase.h"
78

89
namespace firebase {
910
namespace modem {
@@ -43,7 +44,7 @@ class SetCommandTest : public ::testing::Test {
4344
EXPECT_CALL(*set_, error())
4445
.WillRepeatedly(ReturnRef(error));
4546

46-
EXPECT_CALL(fbase_, setPtr(_, data))
47+
EXPECT_CALL(fbase_, setPtr(_, EncodeForJson(data)))
4748
.WillOnce(Return(ByMove(std::move(set_))));
4849

4950
SetCommand setCmd(&fbase_);

0 commit comments

Comments
 (0)