From 6da90a37164a41781e486e729c1d15183ed823da Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 2 Jan 2019 12:08:57 -0600 Subject: [PATCH 01/14] chore: Remove static decoration from base path functions Removed static from base path functions to clear warnings. If this function is in a header it is public and should not be static. --- src/include/cpp-client/api/paths.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/include/cpp-client/api/paths.h b/src/include/cpp-client/api/paths.h index fcbc31c2..aab2c7fe 100644 --- a/src/include/cpp-client/api/paths.h +++ b/src/include/cpp-client/api/paths.h @@ -23,7 +23,7 @@ namespace Paths { namespace Blocks { - static const char* base() { return "/api/v2/blocks"; }; + const char* base() { return "/api/v2/blocks"; }; /***/ extern std::string get(Host& newHost, const char *const blockId); /***/ @@ -39,7 +39,7 @@ namespace Blocks namespace Delegates { - static const char* base() { return "/api/v2/delegates"; }; + const char* base() { return "/api/v2/delegates"; }; /***/ extern std::string get(Host& newHost, const char *const identifier); /***/ @@ -55,7 +55,7 @@ namespace Delegates namespace Node { - static const char* base() { return "/api/v2/node"; }; + const char* base() { return "/api/v2/node"; }; /***/ extern std::string configuration(Host& newHost); /***/ @@ -69,7 +69,7 @@ namespace Node namespace Peers { - static const char* base() { return "/api/v2/peers"; }; + const char* base() { return "/api/v2/peers"; }; /***/ extern std::string get(Host& newHost, const char *const ip); /***/ @@ -81,7 +81,7 @@ namespace Peers namespace Transactions { - static const char* base() { return "/api/v2/transactions"; }; + const char* base() { return "/api/v2/transactions"; }; /***/ extern std::string getUnconfirmed(Host& newHost, const char *const identifier); /***/ @@ -101,7 +101,7 @@ namespace Transactions namespace Votes { - static const char* base() { return "/api/v2/votes"; }; + const char* base() { return "/api/v2/votes"; }; /***/ extern std::string get(Host& newHost, const char *const identifier); /***/ @@ -113,7 +113,7 @@ namespace Votes namespace Wallets { - static const char* base() { return "/api/v2/wallets"; }; + const char* base() { return "/api/v2/wallets"; }; /***/ extern std::string get(Host& newHost, const char *const identifier); /***/ From 1e8678e77d4f1545bacf3c3fc73e130c83d0b20e Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 2 Jan 2019 12:15:47 -0600 Subject: [PATCH 02/14] chore: Cleared signed/unsigned mismatch warnings. --- src/api/paths.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/api/paths.cpp b/src/api/paths.cpp index cb142eaa..958993c1 100644 --- a/src/api/paths.cpp +++ b/src/api/paths.cpp @@ -43,9 +43,9 @@ std::pair Ark::Client::API::Paths::Blocks::search( char uri[96] = { }; snprintf(uri, sizeof(uri), "%s%s/search?limit=%d&page=%d", newHost.toString().c_str(), Ark::Client::API::Paths::Blocks::base(), limit, page); std::string parameterBuffer; - int count = 0; + auto count = 0ul; for (const auto& p : bodyParameters) { - count++; + ++count; parameterBuffer += p.first + '=' + p.second; if (bodyParameters.size() > 1 && count < bodyParameters.size()) { parameterBuffer += '&'; @@ -228,9 +228,9 @@ std::pair Ark::Client::API::Paths::Transactions::searc char uri[96] = { }; snprintf(uri, sizeof(uri), "%s%s/search?limit=%d&page=%d", newHost.toString().c_str(), Ark::Client::API::Paths::Transactions::base(), limit, page); std::string parameterBuffer; - int count = 0; + auto count = 0ul; for (const auto& p : bodyParameters) { - count++; + ++count; parameterBuffer += p.first + '=' + p.second; if (bodyParameters.size() > 1 && count < bodyParameters.size()) { parameterBuffer += '&'; @@ -364,9 +364,9 @@ std::pair Ark::Client::API::Paths::Wallets::search( char uri[96] = { }; snprintf(uri, sizeof(uri), "%s%s/search?limit=%d&page=%d", newHost.toString().c_str(), Ark::Client::API::Paths::Wallets::base(), limit, page); std::string parameterBuffer; - int count = 0; + auto count = 0ul; for (const auto& p : bodyParameters) { - count++; + ++count; parameterBuffer += p.first + '=' + p.second; if (bodyParameters.size() > 1 && count < bodyParameters.size()) { parameterBuffer += '&'; From dfe4bec5b5ad24bdbb550480ae2d5818a26ac81d Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 2 Jan 2019 12:15:47 -0600 Subject: [PATCH 03/14] chore: Cleared signed/unsigned mismatch warnings. --- src/api/paths.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/api/paths.cpp b/src/api/paths.cpp index cb142eaa..958993c1 100644 --- a/src/api/paths.cpp +++ b/src/api/paths.cpp @@ -43,9 +43,9 @@ std::pair Ark::Client::API::Paths::Blocks::search( char uri[96] = { }; snprintf(uri, sizeof(uri), "%s%s/search?limit=%d&page=%d", newHost.toString().c_str(), Ark::Client::API::Paths::Blocks::base(), limit, page); std::string parameterBuffer; - int count = 0; + auto count = 0ul; for (const auto& p : bodyParameters) { - count++; + ++count; parameterBuffer += p.first + '=' + p.second; if (bodyParameters.size() > 1 && count < bodyParameters.size()) { parameterBuffer += '&'; @@ -228,9 +228,9 @@ std::pair Ark::Client::API::Paths::Transactions::searc char uri[96] = { }; snprintf(uri, sizeof(uri), "%s%s/search?limit=%d&page=%d", newHost.toString().c_str(), Ark::Client::API::Paths::Transactions::base(), limit, page); std::string parameterBuffer; - int count = 0; + auto count = 0ul; for (const auto& p : bodyParameters) { - count++; + ++count; parameterBuffer += p.first + '=' + p.second; if (bodyParameters.size() > 1 && count < bodyParameters.size()) { parameterBuffer += '&'; @@ -364,9 +364,9 @@ std::pair Ark::Client::API::Paths::Wallets::search( char uri[96] = { }; snprintf(uri, sizeof(uri), "%s%s/search?limit=%d&page=%d", newHost.toString().c_str(), Ark::Client::API::Paths::Wallets::base(), limit, page); std::string parameterBuffer; - int count = 0; + auto count = 0ul; for (const auto& p : bodyParameters) { - count++; + ++count; parameterBuffer += p.first + '=' + p.second; if (bodyParameters.size() > 1 && count < bodyParameters.size()) { parameterBuffer += '&'; From 036e8c592c23e8d99aea81e15afdd543ca953241 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 3 Jan 2019 12:06:33 -0600 Subject: [PATCH 04/14] chore: Remove unused header --- test/api/paths.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/api/paths.cpp b/test/api/paths.cpp index 8e30a17c..74fa5731 100644 --- a/test/api/paths.cpp +++ b/test/api/paths.cpp @@ -1,6 +1,5 @@ #include "gtest/gtest.h" -#include "gmock/gmock.h" #include "arkClient.h" From de0c05b766540150343c376675e193c238ba7d18 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 3 Jan 2019 12:06:57 -0600 Subject: [PATCH 05/14] refactor: Remove unused gtest adapter --- test/iot/gtest/gtest.h | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 test/iot/gtest/gtest.h diff --git a/test/iot/gtest/gtest.h b/test/iot/gtest/gtest.h deleted file mode 100644 index 55752bcc..00000000 --- a/test/iot/gtest/gtest.h +++ /dev/null @@ -1,9 +0,0 @@ - - -#ifndef __GTEST_H__ -#define __GTEST_H__ - -#include -#include - -#endif From 5107878478cb0becf9c08b6d5d2ea8588289d286 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 3 Jan 2019 12:07:15 -0600 Subject: [PATCH 06/14] fix: Add missing header --- test/mocks/mock_api.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/mocks/mock_api.h b/test/mocks/mock_api.h index 2d90b734..21ea7edb 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" From d2f0e5a6a76d1aaef54243166402de41b780be16 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 3 Jan 2019 12:07:40 -0600 Subject: [PATCH 07/14] refactor: Replace aunit with googletest --- test/platformio.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/platformio.ini b/test/platformio.ini index 60aa607d..e863aaf6 100644 --- a/test/platformio.ini +++ b/test/platformio.ini @@ -13,7 +13,7 @@ src_dir = .. lib_dir = .. [env:esp8266] -lib_deps = ArduinoJson, AUnit +lib_deps = ArduinoJson, googletest platform = espressif8266 board = huzzah framework = arduino @@ -22,7 +22,7 @@ src_filter = +<*> -<.git/> - - -<../src/http/os/> -<_3rdParty> - upload_speed = 921600 [env:esp32] -lib_deps = ArduinoJson, AUnit +lib_deps = ArduinoJson, googletest platform = espressif32 board = esp32dev framework = arduino From 6e033e3d16d5658cb97f42ead05e33e101f7c7e2 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 3 Jan 2019 12:07:55 -0600 Subject: [PATCH 08/14] refactor: Replace aunit with googletest --- test/iot/test_main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/iot/test_main.cpp b/test/iot/test_main.cpp index 2b6043fc..3d839430 100644 --- a/test/iot/test_main.cpp +++ b/test/iot/test_main.cpp @@ -2,7 +2,8 @@ #if (defined PLATFORMIO && defined UNIT_TEST) -#include +#include "gmock/gmock.h" +#include "gtest/gtest.h" #if (defined ESP8266 || defined ESP32) @@ -52,7 +53,9 @@ void setup_network() namespace { + void setup_network() {} + } #endif @@ -62,12 +65,12 @@ void setup() { while (!Serial); // for the Arduino Leonardo/Micro only delay(100); setup_network(); - aunit::TestRunner::setTimeout(0); + testing::gmock_setup(); delay(1000); } void loop() { - aunit::TestRunner::run(); + testing::gmock_loop(); } #endif From 4805f7278d264c894b4f310376948d901e064f83 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 31 Jan 2019 21:43:59 -0600 Subject: [PATCH 09/14] chore: Removed duplicate block test that was not using mocks --- test/api/blocks.cpp | 74 --------------------------------------------- 1 file changed, 74 deletions(-) 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: From 053f5e058eba2b707af53bc52aada237922c68de Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 31 Jan 2019 21:44:57 -0600 Subject: [PATCH 10/14] refactor: Converted to use gmock Removed unused code --- test/iot/test_main.cpp | 57 +++--------------------------------------- 1 file changed, 3 insertions(+), 54 deletions(-) diff --git a/test/iot/test_main.cpp b/test/iot/test_main.cpp index af722935..0a90f936 100644 --- a/test/iot/test_main.cpp +++ b/test/iot/test_main.cpp @@ -1,71 +1,20 @@ - - #if (defined PLATFORMIO && defined UNIT_TEST) #include "gmock/gmock.h" #include "gtest/gtest.h" -#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); - - /* 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(); - testing::gmock_setup(); + testing::InitGoogleMock(); delay(1000); } void loop() { - testing::gmock_loop(); + RUN_ALL_TESTS(); } #endif From 0169733db8419dd4401fcb44b23dc00c2d1ac9fd Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 31 Jan 2019 21:45:20 -0600 Subject: [PATCH 11/14] fix: Corrected config to work with GMock --- test/platformio.ini | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/platformio.ini b/test/platformio.ini index 32bf50e2..5354ce32 100644 --- a/test/platformio.ini +++ b/test/platformio.ini @@ -14,16 +14,21 @@ src_dir = .. lib_dir = .. [common] +lib_ldf_mode = deep lib_deps = ArduinoJson, googletest -build_flags = -I../test/iot/ -I../test -I../src -I../src/include/cpp-client -DUNIT_TEST -src_filter = +<*> -<.git/> - - -<../src/http/os/> -<_3rdParty> - - - +# 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_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} @@ -32,6 +37,8 @@ upload_speed = ${common.upload_speed} 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} From ba33851b2afa7b14cc4c8e06601d5dcbcc849514 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 1 Feb 2019 12:13:48 -0600 Subject: [PATCH 12/14] chore: Remove explicit install of dependencies Let the project config handle it. --- .circleci/install_platform_io.sh | 3 --- 1 file changed, 3 deletions(-) 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 From 17c4de641710e88a599a43e17da1fdea8154b4f0 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 1 Feb 2019 12:14:46 -0600 Subject: [PATCH 13/14] refactor: Re-enable ESP32 unit tests Since ESP32 is now supported by GTest, re-enable it. Disable ESP8266 until it can be supported. --- .circleci/script_platform_io.sh | 5 +++-- test/platformio.ini | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) 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/platformio.ini b/test/platformio.ini index 5354ce32..5dcfb969 100644 --- a/test/platformio.ini +++ b/test/platformio.ini @@ -22,16 +22,17 @@ 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_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} +# 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 From f533cab844348696164fa0d8263224b8a30d48d3 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 13 Feb 2019 18:32:04 -0600 Subject: [PATCH 14/14] misc: make IoT tests only run once --- test/iot/test_main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/iot/test_main.cpp b/test/iot/test_main.cpp index 0a90f936..56f0fac0 100644 --- a/test/iot/test_main.cpp +++ b/test/iot/test_main.cpp @@ -11,10 +11,13 @@ void setup() { delay(100); testing::InitGoogleMock(); delay(1000); + + RUN_ALL_TESTS(); } void loop() { - RUN_ALL_TESTS(); + // do nothing + delay(1000); } #endif