Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to the current release #34

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ test/test_all
#ignore external lib
/lib/gmock/gmock/
/lib/gtest/gtest/

#ingore IDE files
.vscode
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required (VERSION 2.8.8)
cmake_minimum_required (VERSION 3.20.0)
project (arduino_mock)

find_package(Threads REQUIRED)
add_subdirectory(lib/gtest)
add_subdirectory(lib/gmock)

message ("building arduino_mock")
message("Gtest include: ${GTEST_INCLUDE_DIRS}")
Expand All @@ -25,14 +24,13 @@ target_link_libraries(arduino_mock
${CMAKE_THREAD_LIBS_INIT}
)

set_target_properties( arduino_mock
PROPERTIES
set_target_properties(arduino_mock PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/dist/bin"
)

add_dependencies(arduino_mock gtest gmock)
add_dependencies(arduino_mock gtest)

option(test "Build all tests." OFF)

Expand Down
8 changes: 7 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ set -eu
cd -- "$(dirname -- "$0")"
mkdir -p build
cd build
cmake -Dtest=ON ..

if [ "$OSTYPE" == "win32" -o "$OSTYPE" == "msys" ] ; then
cmake -Dtest=ON .. -G "MSYS Makefiles";
else
cmake -Dtest=ON .. -G "Unix Makefiles";
fi

make
ctest -V
1 change: 1 addition & 0 deletions include/arduino-mock/Arduino.h → include/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define ARDUINO_H

#include <stdint.h>
#include <Serial.h>

#ifdef __cplusplus
extern "C" {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions include/arduino-mock/SPI.h → include/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SPISettings {
}
};

class SPI_ {
class SPIClass {
public:
void begin();
void usingInterrupt(uint8_t );
Expand All @@ -36,7 +36,7 @@ class SPI_ {
void detachInterrupt();
};

extern SPI_ SPI;
extern SPIClass SPI;

class SPIMock {
public:
Expand Down
3 changes: 3 additions & 0 deletions include/arduino-mock/Serial.h → include/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class Serial_ {
static size_t println(const Printable&);
*/
};

class HardwareSerial : public Serial_ {};

extern Serial_ Serial;

SerialMock* serialMockInstance();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 0 additions & 17 deletions lib/gmock/CMakeLists.txt

This file was deleted.

8 changes: 5 additions & 3 deletions lib/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ project(gtest_builder C CXX)
include(ExternalProject)

ExternalProject_Add(gtest
URL https://github.com/google/googletest/archive/release-1.7.0.zip
URL https://github.com/google/googletest/archive/release-1.10.0.zip
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest
INSTALL_COMMAND ""
)

# Specify include dir
ExternalProject_Get_Property(gtest source_dir)
set(GTEST_INCLUDE_DIRS ${source_dir}/include PARENT_SCOPE)
set(GTEST_INCLUDE_DIRS ${source_dir}/googletest/include PARENT_SCOPE)
set(GMOCK_INCLUDE_DIRS ${source_dir}/googlemock/include PARENT_SCOPE)

# Specify MainTest's link libraries
ExternalProject_Get_Property(gtest binary_dir)
set(GTEST_LIBS_DIR ${binary_dir} PARENT_SCOPE)
set(GTEST_LIBS_DIR ${binary_dir}/lib PARENT_SCOPE)
set(GMOCK_LIBS_DIR ${binary_dir}/lib PARENT_SCOPE)
2 changes: 1 addition & 1 deletion src/Arduino.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "arduino-mock/Arduino.h"
#include "Arduino.h"

static ArduinoMock* arduinoMock = NULL;
ArduinoMock* arduinoMockInstance() {
Expand Down
2 changes: 1 addition & 1 deletion src/EEPROM.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Implementation of EEPROM mock **/

#include "arduino-mock/EEPROM.h"
#include "EEPROM.h"

static EEPROMMock* p_EEPROMMock = NULL;
EEPROMMock* EEPROMMockInstance() {
Expand Down
2 changes: 1 addition & 1 deletion src/IRremote.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "arduino-mock/IRremote.h"
#include "IRremote.h"

// Taken from IRremoteInt.h
#define ERR 0
Expand Down
32 changes: 16 additions & 16 deletions src/SPI.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "arduino-mock/SPI.h"
#include "SPI.h"

static SPIMock* p_SPIMock = NULL;
SPIMock* SPIMockInstance() {
Expand All @@ -15,62 +15,62 @@ void releaseSPIMock() {
}
}

void SPI_::begin() {
void SPIClass::begin() {
p_SPIMock->begin();
}

void SPI_::usingInterrupt(uint8_t a) {
void SPIClass::usingInterrupt(uint8_t a) {
p_SPIMock->usingInterrupt(a);
}

void SPI_::notUsingInterrupt(uint8_t a) {
void SPIClass::notUsingInterrupt(uint8_t a) {
p_SPIMock->notUsingInterrupt(a);
}


void SPI_::beginTransaction(SPISettings a) {
void SPIClass::beginTransaction(SPISettings a) {
return p_SPIMock->beginTransaction(a);
}

uint8_t SPI_::transfer(uint8_t a) {
uint8_t SPIClass::transfer(uint8_t a) {
return p_SPIMock->transfer(a);
}

uint16_t SPI_::transfer16(uint16_t a) {
uint16_t SPIClass::transfer16(uint16_t a) {
return p_SPIMock->transfer16(a);
}

void SPI_::transfer(void * a, size_t b) {
void SPIClass::transfer(void * a, size_t b) {
return p_SPIMock->transfer(a, b);
}

void SPI_::endTransaction(void) {
void SPIClass::endTransaction(void) {
return p_SPIMock->endTransaction();
}

void SPI_::end(void) {
void SPIClass::end(void) {
return p_SPIMock->end();
}

void SPI_::setBitOrder(uint8_t a) {
void SPIClass::setBitOrder(uint8_t a) {
p_SPIMock->setBitOrder(a);
}

void SPI_::setDataMode(uint8_t a) {
void SPIClass::setDataMode(uint8_t a) {
p_SPIMock->setDataMode(a);
}

void SPI_::setClockDivider(uint8_t a) {
void SPIClass::setClockDivider(uint8_t a) {
return p_SPIMock->setClockDivider(a);
}

void SPI_::attachInterrupt() {
void SPIClass::attachInterrupt() {
return p_SPIMock->attachInterrupt();
}

void SPI_::detachInterrupt() {
void SPIClass::detachInterrupt() {
return p_SPIMock->detachInterrupt();
}

// Preinstantiate Objects
SPI_ SPI;
SPIClass SPI;
2 changes: 1 addition & 1 deletion src/Serial.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2014 http://switchdevice.com

#include "arduino-mock/Serial.h"
#include "Serial.h"

static SerialMock* gSerialMock = NULL;
SerialMock* serialMockInstance() {
Expand Down
2 changes: 1 addition & 1 deletion src/Spark.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2014 http://switchdevice.com

#include "arduino-mock/Spark.h"
#include "Spark.h"

static SparkMock* gSparkMock = NULL;
SparkMock* sparkMockInstance() {
Expand Down
2 changes: 1 addition & 1 deletion src/WiFi.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "arduino-mock/WiFi.h"
#include "WiFi.h"

static WiFiMock* p_WiFiMock = NULL;
WiFiMock* WiFiMockInstance() {
Expand Down
2 changes: 1 addition & 1 deletion src/Wire.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "arduino-mock/Wire.h"
#include "Wire.h"

static WireMock* p_WireMock = NULL;
WireMock* WireMockInstance() {
Expand Down
2 changes: 1 addition & 1 deletion src/serialHelper.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "arduino-mock/serialHelper.h"
#include "serialHelper.h"

stringCapture::stringCapture()
: d() {
Expand Down
2 changes: 1 addition & 1 deletion test/Arduino_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This example code is in the public domain.

#include "gtest/gtest.h"
#include "arduino-mock/Arduino.h"
#include "Arduino.h"

using ::testing::Return;
TEST(digitalRead, 2) {
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target_link_libraries(test_all
${GTEST_LIBS_DIR}/libgtest.a
${GTEST_LIBS_DIR}/libgtest_main.a
${GMOCK_LIBS_DIR}/libgmock.a
${GMOCK_LIBS_DIR}/libgmock_main.a
${CMAKE_THREAD_LIBS_INIT}
)

Expand Down
4 changes: 2 additions & 2 deletions test/EEPROM_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "gtest/gtest.h"
#include "arduino-mock/EEPROM.h"
#include "arduino-mock/Arduino.h"
#include "EEPROM.h"
#include "Arduino.h"
using ::testing::Return;

TEST(EEPROM, access) {
Expand Down
4 changes: 2 additions & 2 deletions test/SPI_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "gtest/gtest.h"
#include "arduino-mock/SPI.h"
#include "arduino-mock/Arduino.h"
#include "SPI.h"
#include "Arduino.h"


using ::testing::Return;
Expand Down
6 changes: 3 additions & 3 deletions test/Serial_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// This example code is in the public domain.

#include "gtest/gtest.h"
#include "arduino-mock/Arduino.h"
#include "arduino-mock/Serial.h"
#include "arduino-mock/serialHelper.h"
#include "Arduino.h"
#include "Serial.h"
#include "serialHelper.h"

using ::testing::_;
using ::testing::Return;
Expand Down
4 changes: 2 additions & 2 deletions test/Spark_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#define DEBUG_LOG false

#include "gtest/gtest.h"
#include "arduino-mock/Arduino.h"
#include "Arduino.h"

#include "arduino-mock/Spark.h"
#include "Spark.h"

using ::testing::StrCaseEq;

Expand Down
4 changes: 2 additions & 2 deletions test/WiFi_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "gtest/gtest.h"
#include "arduino-mock/WiFi.h"
#include "arduino-mock/Arduino.h"
#include "WiFi.h"
#include "Arduino.h"

WiFi_ wifi;

Expand Down
4 changes: 2 additions & 2 deletions test/Wire_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "gtest/gtest.h"
#include "arduino-mock/Wire.h"
#include "arduino-mock/Arduino.h"
#include "Wire.h"
#include "Arduino.h"

using ::testing::Return;
TEST(Wire, access) {
Expand Down
6 changes: 3 additions & 3 deletions test/serialHelper_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "gtest/gtest.h"
#include "arduino-mock/Arduino.h"
#include "arduino-mock/Serial.h"
#include "Arduino.h"
#include "Serial.h"

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

using ::testing::_;
using ::testing::Return;
Expand Down