Skip to content

Commit 5cd6fa8

Browse files
committed
Preinstanciate object in source file
1 parent 493e622 commit 5cd6fa8

File tree

15 files changed

+33
-20
lines changed

15 files changed

+33
-20
lines changed

include/arduino-mock/EEPROM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EEPROM_ {
1313
uint8_t read(int a);
1414
void write(int a, uint8_t b);
1515
};
16-
16+
extern EEPROM_ EEPROM;
1717

1818
class EEPROMMock {
1919
public:

include/arduino-mock/Serial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class Serial_ {
9494
static size_t println(const Printable&);
9595
*/
9696
};
97+
extern Serial_ Serial;
9798

9899
SerialMock* serialMockInstance();
99100
void releaseSerialMock();

include/arduino-mock/Spark.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Spark_ {
4848
void sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, int seconds);
4949
void syncTime(); // Synchronize time with the Spark Cloud
5050
};
51+
extern Spark_ Spark;
5152

5253
SparkMock* sparkMockInstance();
5354
void releaseSparkMock();

include/arduino-mock/WiFi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class WiFi_ {
2929
char* subnetMask(); // Return Subnet mask of the network
3030
char* gatewayIP(); // Return the gateway IP address
3131
};
32+
extern WiFi_ WiFi;
3233

3334
class WiFiMock {
3435
public:

include/arduino-mock/Wire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Wire_ {
3939
return write((uint8_t)n);
4040
}
4141
};
42+
extern Wire_ Wire;
4243

4344
class WireMock {
4445
public:

src/EEPROM.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ uint8_t EEPROM_::read(int a) {
2424
void EEPROM_::write(int a, uint8_t b) {
2525
p_EEPROMMock->write(a, b);
2626
}
27+
28+
// Preinstantiate Objects
29+
EEPROM_ EEPROM;

src/Serial.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ uint8_t Serial_::available() {
112112
uint8_t Serial_::read() {
113113
return gSerialMock->read();
114114
}
115+
116+
// Preinstantiate Objects
117+
Serial_ Serial;

src/Spark.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ void Spark_::sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, int seconds) {
7272
void Spark_::syncTime() {
7373
gSparkMock->syncTime();
7474
}
75+
76+
// Preinstantiate Objects
77+
Spark_ Spark;

src/WiFi.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,6 @@ char* WiFi_::subnetMask() {
9090
char* WiFi_::gatewayIP() {
9191
return p_WiFiMock->gatewayIP();
9292
}
93+
94+
// Preinstantiate Objects
95+
WiFi_ WiFi;

src/Wire.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,6 @@ uint8_t Wire_::requestFrom(uint8_t a, uint8_t b) {
7575
uint8_t Wire_::requestFrom(uint8_t a, uint8_t b, uint8_t c) {
7676
return p_WireMock->requestFrom(a, b, c);
7777
}
78+
79+
// Preinstantiate Objects
80+
Wire_ Wire;

test/EEPROM_unittest.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#include "gtest/gtest.h"
22
#include "arduino-mock/EEPROM.h"
33
#include "arduino-mock/Arduino.h"
4-
EEPROM_ eeprom;
54
using ::testing::Return;
65

7-
TEST(eeprom, access) {
6+
TEST(EEPROM, access) {
87
EEPROMMock* mock = EEPROMMockInstance();
98
int expected_address = 5;
109
int expected_value = 6;
1110
EXPECT_CALL(*mock, read(expected_value));
1211
EXPECT_CALL(*mock, write(expected_address, expected_value));
13-
eeprom.read(expected_value);
14-
eeprom.write(expected_address, expected_value);
12+
EEPROM.read(expected_value);
13+
EEPROM.write(expected_address, expected_value);
1514
releaseEEPROMMock();
1615
}

test/Serial_unittest.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "arduino-mock/Arduino.h"
66
#include "arduino-mock/Serial.h"
77
#include "arduino-mock/serialHelper.h"
8-
Serial_ Serial;
98

109
using ::testing::_;
1110
using ::testing::Return;

test/Spark_unittest.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "arduino-mock/Arduino.h"
99

1010
#include "arduino-mock/Spark.h"
11-
Spark_ Spark;
1211

1312
using ::testing::StrCaseEq;
1413

test/Wire_unittest.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#include "gtest/gtest.h"
22
#include "arduino-mock/Wire.h"
33
#include "arduino-mock/Arduino.h"
4-
Wire_ wire;
54

65
using ::testing::Return;
7-
TEST(wire, access) {
6+
TEST(Wire, access) {
87
uint8_t value1 = 10;
98
uint8_t value2 = 12;
109
char text[] = "Mock test";
@@ -19,14 +18,14 @@ TEST(wire, access) {
1918
EXPECT_CALL(*mock, read());
2019
EXPECT_CALL(*mock, onReceive(callback_func));
2120
EXPECT_CALL(*mock, onRequest(callback_func));
22-
wire.begin();
23-
wire.beginTransmission(value1);
24-
wire.endTransmission(value1);
25-
wire.requestFrom(value1, value2);
26-
wire.write(text);
27-
wire.available();
28-
wire.read();
29-
wire.onReceive(callback_func);
30-
wire.onRequest(callback_func);
21+
Wire.begin();
22+
Wire.beginTransmission(value1);
23+
Wire.endTransmission(value1);
24+
Wire.requestFrom(value1, value2);
25+
Wire.write(text);
26+
Wire.available();
27+
Wire.read();
28+
Wire.onReceive(callback_func);
29+
Wire.onRequest(callback_func);
3130
releaseWireMock();
3231
}

test/serialHelper_unittest.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#include "arduino-mock/serialHelper.h"
66

7-
Serial_ Serial;
8-
97
using ::testing::_;
108
using ::testing::Return;
119
using ::testing::Matcher;

0 commit comments

Comments
 (0)