Skip to content
Permalink
Browse files

test: Add GTest/GMock support for ESP32 (#66)

  • Loading branch information...
ciband authored and faustbrian committed Feb 14, 2019
1 parent 60af13f commit baf8cbc9dc88ee962393f411f69e5b8191ece3ac
@@ -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
@@ -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
@@ -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:

This file was deleted.

Oops, something went wrong.
@@ -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
@@ -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"
@@ -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}

0 comments on commit baf8cbc

Please sign in to comment.
You can’t perform that action at this time.