tests for wallet2_api

This commit is contained in:
Ilya Kitaev 2016-02-20 19:04:56 +03:00
parent 318660dd89
commit 930bed7074
6 changed files with 170 additions and 7 deletions

View file

@ -58,6 +58,6 @@ target_link_libraries(wallet
${Boost_SERIALIZATION_LIBRARY} ${Boost_SERIALIZATION_LIBRARY}
${Boost_SYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY} ${Boost_THREAD_LIBRARY}
${Boost_REGEX_LIBRARY}
${EXTRA_LIBRARIES}) ${EXTRA_LIBRARIES})

View file

@ -32,12 +32,17 @@
#include "wallet2.h" #include "wallet2.h"
#include <memory> #include <memory>
unsigned int epee::g_test_dbg_lock_sleep = 0;
namespace Bitmonero { namespace Bitmonero {
struct WalletManagerImpl; struct WalletManagerImpl;
namespace { namespace {
static WalletManagerImpl * g_walletManager = nullptr; static WalletManagerImpl * g_walletManager = nullptr;
} }
@ -65,6 +70,8 @@ WalletImpl::WalletImpl()
} }
Wallet::~Wallet() {}
WalletImpl::~WalletImpl() WalletImpl::~WalletImpl()
{ {
//delete m_wallet; //delete m_wallet;
@ -103,6 +110,11 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co
return true; return true;
} }
std::string WalletImpl::seed() const
{
return "";
}
///////////////////////// WalletManager implementation ///////////////////////// ///////////////////////// WalletManager implementation /////////////////////////
@ -111,13 +123,16 @@ class WalletManagerImpl : public WalletManager
public: public:
Wallet * createWallet(const std::string &path, const std::string &password, Wallet * createWallet(const std::string &path, const std::string &password,
const std::string &language); const std::string &language);
Wallet * openWallet(const std::string &path, const std::string &password);
bool walletExists(const std::string &path);
int lastError() const;
private: private:
WalletManagerImpl() {} WalletManagerImpl() {}
friend struct WalletManagerFactory; friend struct WalletManagerFactory;
}; };
Wallet *WalletManager::createWallet(const std::string &path, const std::string &password, Wallet *WalletManagerImpl::createWallet(const std::string &path, const std::string &password,
const std::string &language) const std::string &language)
{ {
WalletImpl * wallet = new WalletImpl(); WalletImpl * wallet = new WalletImpl();
@ -131,6 +146,22 @@ Wallet *WalletManager::createWallet(const std::string &path, const std::string &
} }
Wallet *WalletManagerImpl::openWallet(const std::string &path, const std::string &password)
{
return nullptr;
}
bool WalletManagerImpl::walletExists(const std::string &path)
{
return false;
}
int WalletManagerImpl::lastError() const
{
return 0;
}
///////////////////// WalletManagerFactory implementation ////////////////////// ///////////////////// WalletManagerFactory implementation //////////////////////
WalletManager *WalletManagerFactory::getWalletManager() WalletManager *WalletManagerFactory::getWalletManager()
{ {
@ -142,4 +173,7 @@ WalletManager *WalletManagerFactory::getWalletManager()
} }
} }

View file

@ -54,13 +54,13 @@ struct Wallet
struct WalletManager struct WalletManager
{ {
//! creates new wallet //! creates new wallet
Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language); virtual Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language) = 0;
//! opens existing wallet //! opens existing wallet
Wallet * openWallet(const std::string &path, const std::string &password); virtual Wallet * openWallet(const std::string &path, const std::string &password) = 0;
bool walletExists(const std::string &path); virtual bool walletExists(const std::string &path) = 0;
int lastError() const; virtual int lastError() const = 0;
}; };

View file

@ -54,7 +54,7 @@ else ()
endif() endif()
endif () endif ()
add_subdirectory(core_tests) #add_subdirectory(core_tests)
add_subdirectory(crypto) add_subdirectory(crypto)
add_subdirectory(functional_tests) add_subdirectory(functional_tests)
add_subdirectory(performance_tests) add_subdirectory(performance_tests)
@ -63,6 +63,7 @@ add_subdirectory(unit_tests)
add_subdirectory(difficulty) add_subdirectory(difficulty)
add_subdirectory(hash) add_subdirectory(hash)
add_subdirectory(net_load_tests) add_subdirectory(net_load_tests)
add_subdirectory(libwallet_api_tests)
# add_subdirectory(daemon_tests) # add_subdirectory(daemon_tests)

View file

@ -0,0 +1,59 @@
# Copyright (c) 2014-2016, The Monero Project
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set(libwallet_api_tests_sources
main.cpp
)
set(libwallet_api_tests_headers
)
add_executable(libwallet_api_tests
${libwallet_api_tests_sources}
${libwallet_api_tests_headers})
target_link_libraries(libwallet_api_tests
LINK_PRIVATE
wallet
${GTEST_MAIN_LIBRARIES}
${EXTRA_LIBRARIES})
set_property(TARGET libwallet_api_tests
PROPERTY
FOLDER "tests")
if (NOT MSVC)
set_property(TARGET libwallet_api_tests
APPEND_STRING
PROPERTY
COMPILE_FLAGS " -Wno-undef -Wno-sign-compare")
endif ()
add_test(
NAME libwallet_api_tests
COMMAND libwallet_api_tests)

View file

@ -0,0 +1,69 @@
// Copyright (c) 2014-2016, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#include "gtest/gtest.h"
#include "wallet/wallet2_api.h"
//unsigned int epee::g_test_dbg_lock_sleep = 0;
struct WalletManagerTest : public testing::Test
{
Bitmonero::WalletManager * wmgr;
WalletManagerTest()
{
wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
}
};
TEST(WalletFactoryTest, WalletFactoryReturnsWalletManager)
{
Bitmonero::WalletManager * wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
EXPECT_NE(wmgr, nullptr);
}
TEST_F(WalletManagerTest, WalletManagerReturnsCreatesWallet)
{
Bitmonero::Wallet * wallet = wmgr->createWallet("test_wallet", "password", "en_US");
EXPECT_TRUE(wallet != nullptr);
}
int main(int argc, char** argv)
{
//epee::debug::get_set_enable_assert(true, false);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}