Skip to content

Feat: Add GTest/GMock support for ESP32 #66

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .circleci/install_platform_io.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ sudo pip install -U platformio

# update PlatformIO
platformio update

# install ArduinoJson (64) and AUnit (2778) libraries
platformio lib -g install 64@5.13.2 2778
5 changes: 3 additions & 2 deletions .circleci/script_platform_io.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# run PlatformIO builds
platformio run
# Disable PIO tests until GMock support is available.
#platformio run -d ./test

# run PlatformIO unit tests
platformio run -d ./test
74 changes: 0 additions & 74 deletions test/api/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,80 +394,6 @@ TEST(api, test_blocks) { // NOLINT
ASSERT_EQ(0, version);
}

/* test_blocks_blocks_limit_page
* https://dexplorer.ark.io:8443/api/v2/blocks?limit=10&page=1
* Expected Response:
{
"meta": {
"count": int,
"pageCount": int,
"totalCount": int,
"next": null,
"previous": null,
"self": "\api/v2/blocks?limit=10&page=1",
"first": "/api/v2/blocks?limit=10&page=1",
"last": "/api/v2/blocks?limit=10&page=1"
},
"data":
[
{
"id": "string",
"version": int,
"height": int,
"previous": "string",
"forged": {
"reward": uint64_t,
"fee": uint64_t,
"total": uint64_t
},
"payload": {
"hash": "string",
"length": ing
},
"generator": {
"username": "string",
"address": "string",
"publicKey": "string"
},
"signature": "string",
"transactions": ing,
"timestamp": {
"epoch": int,
"unix": int,
"human": "string"
}
}
]
}
*/
TEST(api, test_blocks_limit_page) { // NOLINT
Ark::Client::Connection<Ark::Client::Api> connection("167.114.29.55", 4003);

auto apiVersion = connection.api.version();
ASSERT_EQ(2, apiVersion);

const auto blocksResponse = connection.api.blocks.all(5, 1);

DynamicJsonBuffer jsonBuffer(blocksResponse.size());
JsonObject& root = jsonBuffer.parseObject(blocksResponse);

JsonObject& meta = root["meta"];

int count = meta["count"];
ASSERT_NE(0, count);

int pageCount = meta["pageCount"];
ASSERT_NE(0, pageCount);

int totalCount = meta["totalCount"];
ASSERT_NE(0, totalCount);

JsonObject& dataZero = root["data"][0];

int version = dataZero["version"];
ASSERT_EQ(0, version);
}

/* test_blocks_search
*
* Expected Response:
Expand Down
7 changes: 0 additions & 7 deletions test/iot/gtest/gtest.h

This file was deleted.

72 changes: 12 additions & 60 deletions test/iot/test_main.cpp
Original file line number Diff line number Diff line change
@@ -1,71 +1,23 @@


#if (defined PLATFORMIO && defined UNIT_TEST)

#include <AUnit.h>

#if (defined ESP8266 || defined ESP32)

#ifdef ESP8266

#include <ESP8266WiFi.h>

#else

#include <WiFi.h>

#endif // ESP8266

namespace {

char ssid[] = "your_ssid"; // your network SSID (name)
const char password[] = "your_password"; // your network password

void setup_network() {
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
#include "gmock/gmock.h"
#include "gtest/gtest.h"

/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

} // namespace

#else

namespace {
void setup_network() {}
} // namespace

#endif
#include <Arduino.h>

void setup() {
Serial.begin(115200);
while (!Serial)
; // for the Arduino Leonardo/Micro only
delay(100);
setup_network();
aunit::TestRunner::setTimeout(0);
delay(1000);
Serial.begin(115200);
while (!Serial); // for the Arduino Leonardo/Micro only
delay(100);
testing::InitGoogleMock();
delay(1000);

RUN_ALL_TESTS();
}

void loop() {
aunit::TestRunner::run();
// do nothing
delay(1000);
}

#endif
2 changes: 2 additions & 0 deletions test/mocks/mock_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#ifndef MOCK_API_H
#define MOCK_API_H

#include "gmock/gmock.h"

#include "arkClient.h"
#include "host/host.h"
#include "http/http.h"
Expand Down
30 changes: 19 additions & 11 deletions test/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,32 @@ src_dir = ..
lib_dir = ..

[common]
lib_deps = ArduinoJson, AUnit
build_flags = -I../test/iot/ -I../test -I../src -I../src/include/cpp-client -DUNIT_TEST
src_filter = +<*> -<.git/> -<examples/> -<bin> -<../src/http/os/> -<_3rdParty> -<CMakeFiles> -<test/lib/googletest> -<test/lib/ArduinoJson>
lib_ldf_mode = deep
lib_deps = ArduinoJson, googletest
# ignore the 'test' lib. This isn't real but the build system somehow thinks that the test directory is also a library and does some double compiling of files
lib_ignore = test
build_flags = -I../src -I../src/include/cpp-client -I./test -I. -I.. -DUNIT_TEST
src_filter = +<*> -<.git/> -<examples/> -<bin> -<src/http/os/> -<_3rdParty> -<CMakeFiles> -<test/lib/googletest> -<test/lib/ArduinoJson> -<test/http> #ignore live HTTP tests on IoT
upload_speed = 921600

[env:esp8266]
platform = espressif8266
board = huzzah
framework = arduino
lib_deps = ${common.lib_deps}
build_flags = ${common.build_flags}
src_filter = ${common.src_filter}
upload_speed = ${common.upload_speed}
# esp8266 unit tests disabled until GTest/GMock support is worked out
#[env:esp8266]
#platform = espressif8266
#board = huzzah
#framework = arduino
#lib_ldf_mode = ${common.lib_ldf_mode}
#lib_deps = ${common.lib_deps}
#lib_ignore = ${common.lib_ignore}
#build_flags = ${common.build_flags}
#src_filter = ${common.src_filter}
#upload_speed = ${common.upload_speed}

[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
lib_ldf_mode = ${common.lib_ldf_mode}
lib_ignore = ${common.lib_ignore}
lib_deps = ${common.lib_deps}
build_flags = ${common.build_flags}
src_filter = ${common.src_filter}
Expand Down