diff --git a/.circleci/install_platform_io.sh b/.circleci/install_platform_io.sh index fcb69f6d..4d7860a5 100644 --- a/.circleci/install_platform_io.sh +++ b/.circleci/install_platform_io.sh @@ -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 diff --git a/.circleci/script_platform_io.sh b/.circleci/script_platform_io.sh index 096cbf1d..7b558de4 100644 --- a/.circleci/script_platform_io.sh +++ b/.circleci/script_platform_io.sh @@ -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 diff --git a/test/api/blocks.cpp b/test/api/blocks.cpp index 5a6a5da1..9d77bb77 100644 --- a/test/api/blocks.cpp +++ b/test/api/blocks.cpp @@ -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 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: diff --git a/test/iot/gtest/gtest.h b/test/iot/gtest/gtest.h deleted file mode 100644 index 49e5ebec..00000000 --- a/test/iot/gtest/gtest.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __GTEST_H__ -#define __GTEST_H__ - -#include -#include - -#endif diff --git a/test/iot/test_main.cpp b/test/iot/test_main.cpp index a1a965a4..56f0fac0 100644 --- a/test/iot/test_main.cpp +++ b/test/iot/test_main.cpp @@ -1,71 +1,23 @@ - - #if (defined PLATFORMIO && defined UNIT_TEST) -#include - -#if (defined ESP8266 || defined ESP32) - -#ifdef ESP8266 - -#include - -#else - -#include - -#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 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 diff --git a/test/mocks/mock_api.h b/test/mocks/mock_api.h index 75bf890e..6b882e3b 100644 --- a/test/mocks/mock_api.h +++ b/test/mocks/mock_api.h @@ -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" diff --git a/test/platformio.ini b/test/platformio.ini index bb84b63e..5dcfb969 100644 --- a/test/platformio.ini +++ b/test/platformio.ini @@ -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/> - - -<../src/http/os/> -<_3rdParty> - - - +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/> - - - -<_3rdParty> - - - - #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}