Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita326a81

Browse files
committed
import test/
1 parent6f1ec7d commita326a81

13 files changed

+867
-0
lines changed

‎test/dummies/ESP8266HTTPClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Need a placeholder for complilation for now.
2+
classHTTPClient {};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifdef __GNUC__
2+
#defineUNUSED_ARG(x) UNUSED_ ## x__attribute__((__unused__))
3+
#else
4+
#defineUNUSED_ARG(x) UNUSED_ ## x
5+
#endif
6+
7+
#include"FirebaseHttpClient.h"
8+
9+
classFirebaseHttpClientDummy :publicFirebaseHttpClient {
10+
public:
11+
voidsetReuseConnection(boolUNUSED_ARG(reuse))override {
12+
}
13+
14+
voidbegin(const String&UNUSED_ARG(url))override {
15+
}
16+
17+
voidbegin(const String&UNUSED_ARG(host),const String& UNUSED_ARG(path))override {
18+
}
19+
20+
voidend()override {
21+
}
22+
23+
voidaddHeader(const String&UNUSED_ARG(name),const String& UNUSED_ARG(value))override {
24+
}
25+
26+
voidcollectHeaders(constchar*UNUSED_ARG(header_keys[]),const int UNUSED_ARG(count))override {
27+
}
28+
29+
Stringheader(const String&UNUSED_ARG(name))override {
30+
return"";
31+
}
32+
33+
intsendRequest(const String&UNUSED_ARG(method),const String& UNUSED_ARG(data))override {
34+
return0;
35+
}
36+
37+
StringgetString()override {
38+
return"";
39+
}
40+
41+
Stream*getStreamPtr()override {
42+
returnnullptr;
43+
}
44+
45+
StringerrorToString(intUNUSED_ARG(error_code))override {
46+
returnString();
47+
}
48+
};
49+
50+
FirebaseHttpClient*FirebaseHttpClient::create() {
51+
returnnewFirebaseHttpClientDummy();
52+
}
53+

‎test/dummies/Stream.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef TEST_DUMMIES_STREAM_H
2+
#defineTEST_DUMMIES_STREAM_H
3+
4+
#include"Arduino.h"
5+
6+
classStream {
7+
public:
8+
intavailable() {
9+
return0;
10+
}
11+
StringreadStringUntil(constchar term__attribute__((unused))) {
12+
returnString();
13+
}
14+
intprintln(const String&) {
15+
return0;
16+
}
17+
intprintln(constchar*) {
18+
return0;
19+
}
20+
intprintln(int) {
21+
return0;
22+
}
23+
intprint(constchar*) {
24+
return0;
25+
}
26+
charpeek() {
27+
return'\0';
28+
}
29+
charread() {
30+
return'\0';
31+
}
32+
};
33+
34+
#endif// TEST_DUMMIES_STREAM_H

‎test/mock-firebase.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef TEST_MOCK_FIREBASE_H
2+
#defineTEST_MOCK_FIREBASE_H
3+
4+
#include<memory>
5+
#include"gtest/gtest.h"
6+
#include"Firebase.h"
7+
8+
namespacefirebase {
9+
namespacemodem {
10+
11+
classMockFirebase :publicFirebase {
12+
public:
13+
MOCK_METHOD1(getPtr, std::unique_ptr<FirebaseGet>(const String&));
14+
MOCK_METHOD2(setPtr, std::unique_ptr<FirebaseSet>(const String&,const String&));
15+
MOCK_METHOD2(pushPtr, std::unique_ptr<FirebasePush>(const String&,const String&));
16+
MOCK_METHOD1(removePtr, std::unique_ptr<FirebaseRemove>(const String&));
17+
MOCK_METHOD1(streamPtr, std::unique_ptr<FirebaseStream>(const String&));
18+
};
19+
20+
classMockFirebaseGet :publicFirebaseGet {
21+
public:
22+
MOCK_CONST_METHOD0(json,const String&());
23+
MOCK_CONST_METHOD0(error,const FirebaseError&());
24+
};
25+
26+
classMockFirebaseSet :publicFirebaseSet {
27+
public:
28+
MOCK_CONST_METHOD0(json,const String&());
29+
MOCK_CONST_METHOD0(error,const FirebaseError&());
30+
};
31+
32+
classMockFirebasePush :publicFirebasePush {
33+
public:
34+
MOCK_CONST_METHOD0(name,const String&());
35+
MOCK_CONST_METHOD0(error,const FirebaseError&());
36+
};
37+
38+
classMockFirebaseRemove :publicFirebaseRemove {
39+
public:
40+
MOCK_CONST_METHOD0(error,const FirebaseError&());
41+
};
42+
43+
classMockFirebaseStream :publicFirebaseStream {
44+
public:
45+
MOCK_METHOD0(available,bool());
46+
MOCK_METHOD1(read, Event(String& event));
47+
MOCK_CONST_METHOD0(error,const FirebaseError&());
48+
};
49+
50+
}// modem
51+
}// firebase
52+
#endif// TEST_MOCK_FIREBASE_H

‎test/modem/Makefile

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# A sample Makefile for building both Google Mock and Google Test and
2+
# using them in user tests. This file is self-contained, so you don't
3+
# need to use the Makefile in Google Test's source tree. Please tweak
4+
# it to suit your environment and project. You may want to move it to
5+
# your project's root directory.
6+
#
7+
# SYNOPSIS:
8+
#
9+
# make [all] - makes everything.
10+
# make TARGET - makes the given target.
11+
# make clean - removes all files generated by make.
12+
13+
# Please tweak the following variable definitions as needed by your
14+
# project, except GMOCK_HEADERS and GTEST_HEADERS, which you can use
15+
# in your own targets but shouldn't modify.
16+
17+
# Points to the root of Google Test, relative to where this file is.
18+
# Remember to tweak this if you move this file, or if you want to use
19+
# a copy of Google Test at a different location.
20+
GTEST_DIR = ../googletest/googletest/
21+
22+
# Points to the root of Google Mock, relative to where this file is.
23+
# Remember to tweak this if you move this file.
24+
GMOCK_DIR = ../googletest/googlemock/
25+
26+
# Points to the root of Arduino mock, relative to where this file is.
27+
# Remember to tweak this if you move this file.
28+
ARDUINO_MOCK_DIR = ../arduino-mock/
29+
30+
# Where to find user code.
31+
TEST_DIR = .
32+
33+
PROJECT_ROOT = ../../
34+
SRC_ROOT =$(PROJECT_ROOT)/src
35+
36+
# Flags passed to the preprocessor.
37+
# Set Google Test and Google Mock's header directories as system
38+
# directories, such that the compiler doesn't generate warnings in
39+
# these headers.
40+
CPPFLAGS += -isystem$(GTEST_DIR)/include -isystem$(GMOCK_DIR)/include\
41+
-I$(ARDUINO_MOCK_DIR)/include/arduino-mock/\
42+
-I$(ARDUINO_MOCK_DIR)/include/\
43+
-I$(PROJECT_ROOT)/test/dummies\
44+
-I$(PROJECT_ROOT)/src\
45+
-I$(PROJECT_ROOT)
46+
47+
# Flags passed to the C++ compiler.
48+
CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11
49+
50+
# All tests produced by this Makefile. Remember to add new tests you
51+
# created to the list.
52+
TESTS = get-command_test set-command_test remove-command_test\
53+
push-command_test begin-command_test stream-command_test
54+
55+
# All Google Test headers. Usually you shouldn't change this
56+
# definition.
57+
GTEST_HEADERS =$(GTEST_DIR)/include/gtest/*.h\
58+
$(GTEST_DIR)/include/gtest/internal/*.h
59+
60+
# All Google Mock headers. Note that all Google Test headers are
61+
# included here too, as they are #included by Google Mock headers.
62+
# Usually you shouldn't change this definition.
63+
GMOCK_HEADERS =$(GMOCK_DIR)/include/gmock/*.h\
64+
$(GMOCK_DIR)/include/gmock/internal/*.h\
65+
$(GTEST_HEADERS)
66+
67+
# Arduino Mock headers.
68+
# Usually you shouldn't change this definition.
69+
ARDUINO_MOCK_HEADERS =$(ARDUINO_MOCK_DIR)/include/arduino-mock/*.h
70+
71+
# House-keeping build targets.
72+
73+
all :$(TESTS)
74+
75+
test :$(TESTS)
76+
fortin$(TESTS);do ./$$t;done;
77+
78+
clean :
79+
rm -f$(TESTS) gmock.a gmock_main.a arduino_mock_all.a*.o
80+
81+
# Builds gmock.a and gmock_main.a. These libraries contain both
82+
# Google Mock and Google Test. A test should link with either gmock.a
83+
# or gmock_main.a, depending on whether it defines its own main()
84+
# function. It's fine if your test only uses features from Google
85+
# Test (and not Google Mock).
86+
87+
# Usually you shouldn't tweak such internal variables, indicated by a
88+
# trailing _.
89+
GTEST_SRCS_ =$(GTEST_DIR)/src/*.cc$(GTEST_DIR)/src/*.h$(GTEST_HEADERS)
90+
GMOCK_SRCS_ =$(GMOCK_DIR)/src/*.cc$(GMOCK_HEADERS)
91+
ARDUINO_MOCK_SRCS_ =$(ARDUINO_MOCK_DIR)/src/*.cc$(ARDUINO_MOCK_HEADERS)
92+
93+
# For simplicity and to avoid depending on implementation details of
94+
# Google Mock and Google Test, the dependencies specified below are
95+
# conservative and not optimized. This is fine as Google Mock and
96+
# Google Test compile fast and for ordinary users their source rarely
97+
# changes.
98+
gtest-all.o :$(GTEST_SRCS_)
99+
$(CXX)$(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR)$(CXXFLAGS)\
100+
-c $(GTEST_DIR)/src/gtest-all.cc
101+
102+
gmock-all.o :$(GMOCK_SRCS_)
103+
$(CXX)$(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR)$(CXXFLAGS)\
104+
-c $(GMOCK_DIR)/src/gmock-all.cc
105+
106+
gmock_main.o :$(GMOCK_SRCS_)
107+
$(CXX)$(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR)$(CXXFLAGS)\
108+
-c $(GMOCK_DIR)/src/gmock_main.cc
109+
110+
gmock.a : gmock-all.o gtest-all.o
111+
$(AR)$(ARFLAGS)$@$^
112+
113+
gmock_main.a : gmock-all.o gtest-all.o gmock_main.o
114+
$(AR)$(ARFLAGS)$@$^
115+
116+
117+
# Builds Arduino mocks.
118+
ArduinoMockAll.o :$(ARDUINO_MOCK_SRCS_)
119+
$(CXX)$(CPPFLAGS) -I$(ARDUINO_MOCK_DIR)$(CXXFLAGS) -c\
120+
$(ARDUINO_MOCK_DIR)/src/ArduinoMockAll.cc
121+
122+
arduino_mock_all.a : ArduinoMockAll.o
123+
$(AR)$(ARFLAGS)$@$^
124+
125+
# Builds shared objects.
126+
127+
Firebase.o :$(SRC_ROOT)/Firebase.cpp
128+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/Firebase.cpp
129+
130+
FirebaseHttpClient_dummy.o :$(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dummy.cpp
131+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dummy.cpp
132+
133+
# Builds tests.
134+
135+
get-command.o :$(SRC_ROOT)/modem/get-command.cpp
136+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/get-command.cpp
137+
138+
get-command_test.o :$(TEST_DIR)/get-command_test.cpp$(GMOCK_HEADERS)
139+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(TEST_DIR)/get-command_test.cpp
140+
141+
get-command_test : get-command_test.o Firebase.o FirebaseHttpClient_dummy.o get-command.o gmock_main.a\
142+
arduino_mock_all.a
143+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
144+
145+
146+
set-command.o :$(SRC_ROOT)/modem/set-command.cpp
147+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/set-command.cpp
148+
149+
set-command_test.o :$(TEST_DIR)/set-command_test.cpp$(GMOCK_HEADERS)
150+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(TEST_DIR)/set-command_test.cpp
151+
152+
set-command_test : set-command.o set-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a\
153+
arduino_mock_all.a
154+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
155+
156+
157+
remove-command.o :$(SRC_ROOT)/modem/remove-command.cpp
158+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/remove-command.cpp
159+
160+
remove-command_test.o :$(TEST_DIR)/remove-command_test.cpp$(GMOCK_HEADERS)
161+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(TEST_DIR)/remove-command_test.cpp
162+
163+
remove-command_test : remove-command.o remove-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a\
164+
arduino_mock_all.a
165+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
166+
167+
168+
push-command.o :$(SRC_ROOT)/modem/push-command.cpp
169+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/push-command.cpp
170+
171+
push-command_test.o :$(TEST_DIR)/push-command_test.cpp$(GMOCK_HEADERS)
172+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(TEST_DIR)/push-command_test.cpp
173+
174+
push-command_test : push-command.o push-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a\
175+
arduino_mock_all.a
176+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
177+
178+
begin-command.o :$(SRC_ROOT)/modem/begin-command.cpp
179+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/begin-command.cpp
180+
181+
begin-command_test.o :$(TEST_DIR)/begin-command_test.cpp$(GMOCK_HEADERS)
182+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(TEST_DIR)/begin-command_test.cpp
183+
184+
begin-command_test : begin-command.o begin-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a\
185+
arduino_mock_all.a
186+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
187+
188+
stream-command.o :$(SRC_ROOT)/modem/stream-command.cpp
189+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/stream-command.cpp
190+
191+
stream-command_test.o :$(TEST_DIR)/stream-command_test.cpp$(GMOCK_HEADERS)
192+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(TEST_DIR)/stream-command_test.cpp
193+
194+
stream-command_test : stream-command.o stream-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a\
195+
arduino_mock_all.a
196+
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
197+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp