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

Commit 7f1ed6f

Browse files
committed
Get unit tests working with arduino json
1 parent 6e39fc3 commit 7f1ed6f

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed

src/Firebase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <Arduino.h>
2424
#include <memory>
2525
#include "FirebaseHttpClient.h"
26+
// TODO(edcoyne): move this into our mock_arduino fork where we actually do the
27+
// override.
28+
#define ARDUINO_STRING_OVERRIDE
2629
#include "third-party/arduino-json-5.1.1/include/ArduinoJson.h"
2730

2831
class FirebaseGet;

src/third-party/arduino-json-5.1.1/include/ArduinoJson/Arduino/String.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
#ifndef ARDUINO
1111

12+
#ifndef ARDUINO_STRING_OVERRIDE
13+
#define ARDUINO_STRING_OVERRIDE
1214
#include <string>
13-
//typedef std::string String;
15+
typedef std::string String;
16+
#endif
1417

1518
#else
1619

test/mock-firebase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MockFirebase : public Firebase {
1919

2020
class MockFirebaseGet : public FirebaseGet {
2121
public:
22-
MOCK_CONST_METHOD0(json, const String&());
22+
MOCK_CONST_METHOD0(response, const String&());
2323
MOCK_CONST_METHOD0(error, const FirebaseError&());
2424
};
2525

test/modem/Makefile

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test : $(TESTS)
7676
for t in $(TESTS); do ./$$t; done;
7777

7878
clean :
79-
rm -f $(TESTS) gmock.a gmock_main.a arduino_mock_all.a *.o
79+
rm -f $(TESTS) gmock.a gmock_main.a arduino_mock_all.a arduino_json.a *.o
8080

8181
# Builds gmock.a and gmock_main.a. These libraries contain both
8282
# Google Mock and Google Test. A test should link with either gmock.a
@@ -122,6 +122,45 @@ ArduinoMockAll.o : $(ARDUINO_MOCK_SRCS_)
122122
arduino_mock_all.a : ArduinoMockAll.o
123123
$(AR) $(ARFLAGS) $@ $^
124124

125+
# Builds ArduinoJson
126+
ARDUINO_JSON_SRC_ = ../../src/third-party/arduino-json-5.1.1/src
127+
JsonObject.o : $(ARDUINO_JSON_SRC_)
128+
$(CXX) $(CPPFLAGS) -I$(ARDUINO_JSON_SRC_) $(CXXFLAGS) -c \
129+
$(ARDUINO_JSON_SRC_)/JsonObject.cpp
130+
131+
JsonBuffer.o : $(ARDUINO_JSON_SRC_)
132+
$(CXX) $(CPPFLAGS) -I$(ARDUINO_JSON_SRC_) $(CXXFLAGS) -c \
133+
$(ARDUINO_JSON_SRC_)/JsonBuffer.cpp
134+
135+
JsonVariant.o : $(ARDUINO_JSON_SRC_)
136+
$(CXX) $(CPPFLAGS) -I$(ARDUINO_JSON_SRC_) $(CXXFLAGS) -c \
137+
$(ARDUINO_JSON_SRC_)/JsonVariant.cpp
138+
139+
JsonArray.o : $(ARDUINO_JSON_SRC_)
140+
$(CXX) $(CPPFLAGS) -I$(ARDUINO_JSON_SRC_) $(CXXFLAGS) -c \
141+
$(ARDUINO_JSON_SRC_)/JsonArray.cpp
142+
143+
JsonParser.o : $(ARDUINO_JSON_SRC_)
144+
$(CXX) $(CPPFLAGS) -I$(ARDUINO_JSON_SRC_) $(CXXFLAGS) -c \
145+
$(ARDUINO_JSON_SRC_)/Internals/JsonParser.cpp
146+
147+
Comments.o : $(ARDUINO_JSON_SRC_)
148+
$(CXX) $(CPPFLAGS) -I$(ARDUINO_JSON_SRC_) $(CXXFLAGS) -c \
149+
$(ARDUINO_JSON_SRC_)/Internals/Comments.cpp
150+
151+
List.o : $(ARDUINO_JSON_SRC_)
152+
$(CXX) $(CPPFLAGS) -I$(ARDUINO_JSON_SRC_) $(CXXFLAGS) -c \
153+
$(ARDUINO_JSON_SRC_)/Internals/List.cpp
154+
155+
Encoding.o : $(ARDUINO_JSON_SRC_)
156+
$(CXX) $(CPPFLAGS) -I$(ARDUINO_JSON_SRC_) $(CXXFLAGS) -c \
157+
$(ARDUINO_JSON_SRC_)/Internals/Encoding.cpp
158+
159+
arduino_json.a : JsonObject.o JsonBuffer.o JsonVariant.o JsonArray.o \
160+
JsonParser.o Comments.o List.o Encoding.o
161+
$(AR) $(ARFLAGS) $@ $^
162+
163+
125164
# Builds shared objects.
126165

127166
Firebase.o : $(SRC_ROOT)/Firebase.cpp
@@ -139,7 +178,7 @@ get-command_test.o : $(TEST_DIR)/get-command_test.cpp $(GMOCK_HEADERS)
139178
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/get-command_test.cpp
140179

141180
get-command_test : get-command_test.o Firebase.o FirebaseHttpClient_dummy.o get-command.o gmock_main.a \
142-
arduino_mock_all.a
181+
arduino_mock_all.a arduino_json.a
143182
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
144183

145184

@@ -150,7 +189,7 @@ set-command_test.o : $(TEST_DIR)/set-command_test.cpp $(GMOCK_HEADERS)
150189
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/set-command_test.cpp
151190

152191
set-command_test : set-command.o set-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
153-
arduino_mock_all.a
192+
arduino_mock_all.a arduino_json.a
154193
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
155194

156195

@@ -161,7 +200,7 @@ remove-command_test.o : $(TEST_DIR)/remove-command_test.cpp $(GMOCK_HEADERS)
161200
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/remove-command_test.cpp
162201

163202
remove-command_test : remove-command.o remove-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
164-
arduino_mock_all.a
203+
arduino_mock_all.a arduino_json.a
165204
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
166205

167206

@@ -172,7 +211,7 @@ push-command_test.o : $(TEST_DIR)/push-command_test.cpp $(GMOCK_HEADERS)
172211
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/push-command_test.cpp
173212

174213
push-command_test : push-command.o push-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
175-
arduino_mock_all.a
214+
arduino_mock_all.a arduino_json.a
176215
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
177216

178217
begin-command.o : $(SRC_ROOT)/modem/begin-command.cpp
@@ -182,7 +221,7 @@ begin-command_test.o : $(TEST_DIR)/begin-command_test.cpp $(GMOCK_HEADERS)
182221
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/begin-command_test.cpp
183222

184223
begin-command_test : begin-command.o begin-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
185-
arduino_mock_all.a
224+
arduino_mock_all.a arduino_json.a
186225
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
187226

188227
stream-command.o : $(SRC_ROOT)/modem/stream-command.cpp
@@ -192,6 +231,6 @@ stream-command_test.o : $(TEST_DIR)/stream-command_test.cpp $(GMOCK_HEADERS)
192231
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/stream-command_test.cpp
193232

194233
stream-command_test : stream-command.o stream-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \
195-
arduino_mock_all.a
234+
arduino_mock_all.a arduino_json.a
196235
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
197236

test/modem/get-command_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ TEST_F(GetCommandTest, gets) {
4747
FeedCommand(path);
4848

4949
const String value("Test value");
50-
EXPECT_CALL(*get_, json())
50+
EXPECT_CALL(*get_, response())
5151
.WillOnce(ReturnRef(value));
5252

5353
EXPECT_CALL(out_, print(String("+")))

0 commit comments

Comments
 (0)