Skip to content

Commit

Permalink
Merge pull request LedgerHQ#37 from teams2ua/develop
Browse files Browse the repository at this point in the history
Fix some tests for MSVC
  • Loading branch information
KhalilBellakrid authored Oct 29, 2018
2 parents 28e3294 + aa16b72 commit 8812727
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ core/lib/secp256k1/tmp/
node_modules
api/djinni/support-lib/*.mk
api/djinni/support-lib/*.Makefile
.vscode/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include(UseBackportedModules)
# The project version number.
set(VERSION_MAJOR 1 CACHE STRING "Project major version number.")
set(VERSION_MINOR 1 CACHE STRING "Project minor version number.")
set(VERSION_PATCH 3 CACHE STRING "Project patch version number.")
set(VERSION_PATCH 4 CACHE STRING "Project patch version number.")
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)
Expand Down
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ branches:
image:
- Visual Studio 2015
environment:
LIB_VERSION: 1.1.3 #Hardcode the LIB_VERSION : should be retrieved by building libcore node module and run tests/lib_version.js
LIB_VERSION: 1.1.4 #Hardcode the LIB_VERSION : should be retrieved by building libcore node module and run tests/lib_version.js
nodejs_version: "9"
appveyor_rdp_password:
secure: jb1LsDmcxCww7tA38S3xSw==
priv_key:
secure: jI9y+0Gesg/xCoBv/ffAvnvQ/G9R4s9LY+oAk2ZzI/pjK8gWFFYbX3PjyYBjCTl891yv/l0jS62jh2LZifMgwSeMM+q0Fqjm5RIAEoZGxhPLf0vVWU0nI7v5zGaX7BNeXySaZjKb0LL3LJ4jC/NaeLD+i0p+3JmTMm16V3DQG/m8HLfrpzr4oGgx6xtj3pd7NWgsSzHKhY5SgC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5XIeu/WwPZHfQjGnDlME0VgkRWflA/Pjt0GcyDSLURXQBk+5JJhn9FjGPCKD+db4xQkW7zhep/su5urEf0HYTmVHRiKMZNfBPGSnL/Lmr6343qc6YF78lyX2U9saoJrf+tuxqAHtUq0KhkHltbNeIUaxvcC7TcH+kEm/Uxl/al8iRiMWE86b8z/wiFQI1xA+oejrFQivbyZVJ+cOifoZ7HhYwP+niOnUG+ZzT5WFLejnsnd4Lwdi5XzWaKKooIPtZ9qcyk15SFzVBayEeeljNk/gByrT6U+25LUqO6ekXrZ+A86Tmjkhp67B5+JNxis+k3sCZ63ASP6LhL9NvrVNky1ZGB8WAZ/hs=
matrix:
Expand Down
2 changes: 1 addition & 1 deletion core/src/collections/DynamicObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace ledger {

optional<std::string> DynamicObject::getString(const std::string &key) {
auto v = _values.lift(key);
if (_values.empty() || !v.hasValue() || v.getValue().type != api::DynamicType::STRING)
if (!v.hasValue() || v.getValue().type != api::DynamicType::STRING)
return optional<std::string>();
return optional<std::string>(v.getValue().string);
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/collections/MapLike.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ namespace ledger {
}

Option<V> lift(const K &key) const {
return Try<V>::from([this, &key] () {
return at(key);
}).toOption();
auto it = _container.find(key);
if (it == _container.end()) {
return Option<V>::NONE;
}
return Option<V>(it->second);
}

bool contains(const K &key) const {
Expand Down
13 changes: 6 additions & 7 deletions core/src/debug/RotatingEncryptableSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ namespace ledger {

void RotatingEncryptableSink::log(const spdlog::details::log_msg &msg) {
auto context = _context;
std::string message = msg.formatted.data();
auto size = msg.formatted.size();
std::string message = msg.formatted.str();
auto self = shared_from_this();
context->execute(make_runnable([self, message, size] () {
self->_sink_it(message, size);
context->execute(make_runnable([self, message] () {
self->_sink_it(message);
}));
}

Expand All @@ -75,13 +74,13 @@ namespace ledger {
}));
}

void RotatingEncryptableSink::_sink_it(std::string msg, std::size_t size) {
void RotatingEncryptableSink::_sink_it(std::string msg) {
// TODO: implement encryption
_current_size += size;
_current_size += msg.size();
if (_current_size > _max_size)
{
_rotate();
_current_size = size;
_current_size = msg.size();
}

spdlog::details::log_msg spdlog_msg;
Expand Down
2 changes: 1 addition & 1 deletion core/src/debug/RotatingEncryptableSink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace ledger {
virtual void flush() override;

protected:
void _sink_it(std::string msg, std::size_t size);
void _sink_it(std::string msg);

private:
static spdlog::filename_t calc_filename(
Expand Down
9 changes: 4 additions & 5 deletions core/src/utils/DateUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@


#if defined(_WIN32) || defined(_WIN64)
#if defined(_MSC_VER) && _MSC_VER <= 1900
long shift = 0;
int result = _get_timezone(&shift);
#define timezone shift
#if defined(_MSC_VER)
time_t timegm(struct tm* tm) { return _mkgmtime(tm); }
#else
time_t timegm(struct tm* tm) { return mktime(tm) - timezone; }
#endif
time_t timegm(struct tm* tm) { return mktime(tm) - timezone; }
#endif

std::chrono::system_clock::time_point ledger::core::DateUtils::fromJSON(const std::string &str) {
Expand Down
8 changes: 0 additions & 8 deletions core/test/bytes/byteswriter_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,13 @@ using namespace ledger::core;
TEST(BytesWriter, WriteBeValues) {
EXPECT_EQ(BytesWriter().writeBeValue(12U).toByteArray(), std::vector<uint8_t>({0x00, 0x00, 0x00, 12}));
EXPECT_EQ(BytesWriter().writeBeValue((uint8_t)12).toByteArray(), std::vector<uint8_t>({12}));
#ifdef __MINGW32__
EXPECT_EQ(BytesWriter().writeBeValue(12ULL).toByteArray(), std::vector<uint8_t>({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 12}));
#else
EXPECT_EQ(BytesWriter().writeBeValue(12UL).toByteArray(), std::vector<uint8_t>({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 12}));
#endif
}

TEST(BytesWriter, WriteLeValues) {
EXPECT_EQ(BytesWriter().writeLeValue(12U).toByteArray(), std::vector<uint8_t>({12, 0x00, 0x00, 00}));
EXPECT_EQ(BytesWriter().writeLeValue((uint8_t)12).toByteArray(), std::vector<uint8_t>({12}));
#ifdef __MINGW32__
EXPECT_EQ(BytesWriter().writeLeValue(12ULL).toByteArray(), std::vector<uint8_t>({12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
#else
EXPECT_EQ(BytesWriter().writeLeValue(12UL).toByteArray(), std::vector<uint8_t>({12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
#endif
}

TEST(BytesWriter, WriteVarInt) {
Expand Down
16 changes: 8 additions & 8 deletions core/test/debug/logger_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
*
*/

#include <gtest/gtest.h>
#include <EventLooper.hpp>
#include <EventThread.hpp>
#include <NativeThreadDispatcher.hpp>
#include <NativePathResolver.hpp>
#include <fstream>
#include <ledger/core/debug/logger.hpp>
#include <CoutLogPrinter.hpp>
#include <iostream>
#include <ledger/core/debug/logger.hpp>
#include <ledger/core/utils/optional.hpp>
#include <spdlog/details/os.h>
#include <gtest/gtest.h>
#include <iostream>
#include <string>
#include <fstream>
#include <streambuf>
Expand All @@ -47,13 +47,13 @@ TEST(LoggerTest, LogAndOverflow) {
auto dispatcher = std::make_shared<NativeThreadDispatcher>();
auto logPrinter = std::make_shared<CoutLogPrinter>(dispatcher->getMainExecutionContext());
auto resolver = std::make_shared<NativePathResolver>();

auto logLineExample = std::string("2017-03-02T10:07:06Z+01:00 D: This is a log XXX") + spdlog::details::os::default_eol;
std::shared_ptr<spdlog::logger> logger = ledger::core::logger::create("test_logs",
std::experimental::optional<std::string>(),
dispatcher->getSerialExecutionContext("logger"),
resolver,
logPrinter,
(std::string("2017-03-02T10:07:06Z+01:00 D: This is a log \n").size() + 3) * 199
logLineExample.size() * 199
);
dispatcher->getMainExecutionContext()->execute(make_runnable([=] () {
for (auto i = 0; i < 200; i++) {
Expand All @@ -79,13 +79,13 @@ TEST(LoggerTest, LogNoOverflow) {
auto dispatcher = std::make_shared<NativeThreadDispatcher>();
auto logPrinter = std::make_shared<CoutLogPrinter>(dispatcher->getMainExecutionContext());
auto resolver = std::make_shared<NativePathResolver>();

auto logLineExample = std::string("2017-03-02T10:07:06Z+01:00 D: This is a log XXX") + spdlog::details::os::default_eol;
std::shared_ptr<spdlog::logger> logger = ledger::core::logger::create("test_logs_1",
std::experimental::optional<std::string>(),
dispatcher->getSerialExecutionContext("logger"),
resolver,
logPrinter,
(std::string("2017-03-02T10:07:06Z+01:00 D: This is a log \n").size() + 3) * 200
logLineExample.size() * 200
);
dispatcher->getMainExecutionContext()->execute(make_runnable([=] () {
for (auto i = 0; i < 200; i++) {
Expand Down
2 changes: 1 addition & 1 deletion core/test/lib/libledger-test/MongooseHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void MongooseHttpClient::execute(const std::shared_ptr<ledger::core::api::HttpRe
}

nc = mg_connect_http(&_mgr, ::ev_handler, method.c_str(), request->getUrl().c_str(), headers.str().c_str(), c_body); // Pass headers and body data

assert(nc != nullptr);
nc->user_data = new std::pair<std::shared_ptr<ledger::core::api::HttpRequest>, std::shared_ptr<MongooseHttpClient>>(request, self);
mg_set_protocol_http_websocket(nc);
}));
Expand Down
2 changes: 2 additions & 0 deletions core/test/net/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.0)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
include_directories(${gmock_SOURCE_DIR}/include ${gmock_SOURCE_DIR})
include_directories(${CMAKE_BINARY_DIR}/include)
if (APPLE)
add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)
Expand All @@ -11,6 +12,7 @@ include_directories(../lib/libledger-test/)
add_executable(ledger-core-net-tests main.cpp http_client_tests.cpp websocket_client_tests.cpp)

target_link_libraries(ledger-core-net-tests gtest gtest_main)
target_link_libraries(ledger-core-net-tests gmock)
target_link_libraries(ledger-core-net-tests ledger-core)
target_link_libraries(ledger-core-net-tests ledger-test)
target_link_libraries(ledger-core-net-tests ledger-qt-host)
Expand Down
12 changes: 6 additions & 6 deletions core/test/net/http_client_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST(HttpClient, GET) {
auto dispatcher = std::make_shared<NativeThreadDispatcher>();
auto client = std::make_shared<MongooseHttpClient>(dispatcher->getSerialExecutionContext("client"));
auto worker = dispatcher->getSerialExecutionContext("worker");
ledger::core::HttpClient http("http://localhost:8000", client, worker);
ledger::core::HttpClient http("http://127.0.0.1:8000", client, worker);
{
auto server = std::make_shared<MongooseSimpleRestServer>(dispatcher->getSerialExecutionContext("server"));

Expand Down Expand Up @@ -94,7 +94,7 @@ TEST(HttpClient, GETJson) {
auto dispatcher = std::make_shared<NativeThreadDispatcher>();
auto client = std::make_shared<MongooseHttpClient>(dispatcher->getSerialExecutionContext("client"));
auto worker = dispatcher->getSerialExecutionContext("worker");
ledger::core::HttpClient http("http://localhost:8000", client, worker);
ledger::core::HttpClient http("http://127.0.0.1:8000", client, worker);
{
auto server = std::make_shared<MongooseSimpleRestServer>(dispatcher->getSerialExecutionContext("server"));

Expand Down Expand Up @@ -127,7 +127,7 @@ TEST(HttpClient, GETJsonError) {
auto dispatcher = std::make_shared<NativeThreadDispatcher>();
auto client = std::make_shared<MongooseHttpClient>(dispatcher->getSerialExecutionContext("client"));
auto worker = dispatcher->getSerialExecutionContext("worker");
ledger::core::HttpClient http("http://localhost:8000", client, worker);
ledger::core::HttpClient http("http://127.0.0.1:8000", client, worker);
{
auto server = std::make_shared<MongooseSimpleRestServer>(dispatcher->getSerialExecutionContext("server"));

Expand Down Expand Up @@ -161,7 +161,7 @@ TEST(HttpClient, POST) {
auto dispatcher = std::make_shared<NativeThreadDispatcher>();
auto client = std::make_shared<MongooseHttpClient>(dispatcher->getSerialExecutionContext("client"));
auto worker = dispatcher->getSerialExecutionContext("worker");
ledger::core::HttpClient http("http://localhost:8000", client, worker);
ledger::core::HttpClient http("http://127.0.0.1:8000", client, worker);
{
auto server = std::make_shared<MongooseSimpleRestServer>(dispatcher->getSerialExecutionContext("server"));

Expand Down Expand Up @@ -237,7 +237,7 @@ TEST(HttpClient, GETWithSax) {
auto dispatcher = std::make_shared<NativeThreadDispatcher>();
auto client = std::make_shared<MongooseHttpClient>(dispatcher->getSerialExecutionContext("client"));
auto worker = dispatcher->getSerialExecutionContext("worker");
ledger::core::HttpClient http("http://localhost:8000", client, worker);
ledger::core::HttpClient http("http://127.0.0.1:8000", client, worker);
{
auto server = std::make_shared<MongooseSimpleRestServer>(dispatcher->getSerialExecutionContext("server"));

Expand Down Expand Up @@ -317,7 +317,7 @@ TEST(HttpClient, GETWithSaxError) {
auto dispatcher = std::make_shared<NativeThreadDispatcher>();
auto client = std::make_shared<MongooseHttpClient>(dispatcher->getSerialExecutionContext("client"));
auto worker = dispatcher->getSerialExecutionContext("worker");
ledger::core::HttpClient http("http://localhost:8000", client, worker);
ledger::core::HttpClient http("http://127.0.0.1:8000", client, worker);
{
auto server = std::make_shared<MongooseSimpleRestServer>(dispatcher->getSerialExecutionContext("server"));

Expand Down
Loading

0 comments on commit 8812727

Please sign in to comment.