From 391a300d086d9152bb2ca260d65859734648ace7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 27 Aug 2018 21:18:10 +0200 Subject: [PATCH] Add unit tests for "evmc_create()" --- test/unittests/CMakeLists.txt | 8 ++++++++ test/unittests/test_loader.cpp | 13 +++++++++++++ test/unittests/vm_mock_default.c | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 test/unittests/vm_mock_default.c diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index baa3e6e..ec3f85a 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -5,6 +5,10 @@ add_library(vm-mock SHARED vm_mock.c) target_link_libraries(vm-mock PRIVATE evmc) +add_library(vm-mock-default SHARED vm_mock_default.c) +target_link_libraries(vm-mock-default PRIVATE evmc) + + if(UNIX) set(cmd create_symlink) else() @@ -13,6 +17,7 @@ endif() add_custom_command( TARGET vm-mock POST_BUILD + COMMAND ${CMAKE_COMMAND} -E ${cmd} $ libaaa.so COMMAND ${CMAKE_COMMAND} -E ${cmd} $ double_prefix_aaa.evm COMMAND ${CMAKE_COMMAND} -E ${cmd} $ double-prefix-aaa.evm @@ -26,6 +31,9 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E ${cmd} $ ../aaa.evm COMMAND ${CMAKE_COMMAND} -E ${cmd} $ failure.vm COMMAND ${CMAKE_COMMAND} -E ${cmd} $ abi42.vm + + COMMAND ${CMAKE_COMMAND} -E ${cmd} $ default.evmc + COMMAND ${CMAKE_COMMAND} -E touch empty.file ) diff --git a/test/unittests/test_loader.cpp b/test/unittests/test_loader.cpp index 4eb2871..3a3b332 100644 --- a/test/unittests/test_loader.cpp +++ b/test/unittests/test_loader.cpp @@ -245,6 +245,19 @@ TEST(loader, lib_) EXPECT_EQ(x, nullptr); } +TEST(loader, load_default) +{ + auto path = "unittests/default.evmc"; + + evmc_loader_error_code ec; + auto fn = evmc_load(path, &ec); + EXPECT_EQ(ec, EVMC_LOADER_SUCCESS); + EXPECT_EQ((uintptr_t)fn(), 0xdeaf); + + fn = evmc_load(path, nullptr); + EXPECT_EQ((uintptr_t)fn(), 0xdeaf); +} + TEST(loader, load_and_create_failure) { evmc_loader_error_code ec; diff --git a/test/unittests/vm_mock_default.c b/test/unittests/vm_mock_default.c new file mode 100644 index 0000000..d063a36 --- /dev/null +++ b/test/unittests/vm_mock_default.c @@ -0,0 +1,11 @@ +/* EVMC: Ethereum Client-VM Connector API. + * Copyright 2018 The EVMC Authors. + * Licensed under the Apache License, Version 2.0. See the LICENSE file. + */ + +#include + +EVMC_EXPORT void* evmc_create() +{ + return (void*)0xdeaf; +}