diff --git a/CMakeLists.txt b/CMakeLists.txt index ac16dee6a5e4a95ddfe9e2439879b05c8ec0b069..044cc20ac4c18f77be79084cff60ffbe16623cf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,6 +304,8 @@ IF(OPENDHT_TESTS) tests/tests_runner.cpp tests/infohashtester.h tests/infohashtester.cpp + tests/dhtrunnertester.h + tests/dhtrunnertester.cpp ) if (OPENDHT_SHARED) TARGET_LINK_LIBRARIES(opendht_unit_tests opendht) diff --git a/tests/Makefile.am b/tests/Makefile.am index 5308335e7eccb0fe0f61f6d5d20b1e943d5ee7c5..22b6ce4d3600909fc2eb880790b041d08c9c2ddf 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,7 +3,7 @@ bin_PROGRAMS = opendht_unit_tests AM_CPPFLAGS = -I../include -nobase_include_HEADERS = infohashtester.h -opendht_unit_tests_SOURCES = tests_runner.cpp infohashtester.cpp +nobase_include_HEADERS = infohashtester.h dhtrunnertester.h +opendht_unit_tests_SOURCES = tests_runner.cpp infohashtester.cpp dhtrunnertester.cpp opendht_unit_tests_LDFLAGS = -lopendht -lcppunit -L@top_builddir@/src/.libs @GnuTLS_LIBS@ endif diff --git a/tests/dhtrunnertester.cpp b/tests/dhtrunnertester.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93e550d1faf896fd968a0848fd4207bb6f57e740 --- /dev/null +++ b/tests/dhtrunnertester.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2018 Savoir-faire Linux Inc. + * + * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include "dhtrunnertester.h" + +// std +#include <iostream> +#include <string> + +namespace test { +CPPUNIT_TEST_SUITE_REGISTRATION(DhtRunnerTester); + +void +DhtRunnerTester::setUp() { + node1.run(42222, {}, true); + node2.run(42232, {}, true); + node2.bootstrap(node1.getBound()); +} + +void +DhtRunnerTester::tearDown() { + node1.join(); + node2.join(); +} + +void +DhtRunnerTester::testConstructors() { + CPPUNIT_ASSERT(node1.getBoundPort() == 42222); + CPPUNIT_ASSERT(node2.getBoundPort() == 42232); +} + +void +DhtRunnerTester::testGetPut() { + auto key = dht::InfoHash::get("123"); + dht::Value val {"hey"}; + auto val_data = val.data; + node1.put(key, std::move(val)); + auto vals = node2.get(key).get(); + CPPUNIT_ASSERT(not vals.empty()); + CPPUNIT_ASSERT(vals.front()->data == val_data); +} + +void +DhtRunnerTester::testListen() { + // TODO +} + +} // namespace test diff --git a/tests/dhtrunnertester.h b/tests/dhtrunnertester.h new file mode 100644 index 0000000000000000000000000000000000000000..9c64491bbae2892592ab1f4a2a6a1dbda66594f8 --- /dev/null +++ b/tests/dhtrunnertester.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018 Savoir-faire Linux Inc. + * + * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#pragma once + +// cppunit +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <opendht/dhtrunner.h> + +namespace test { + +class DhtRunnerTester : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(DhtRunnerTester); + CPPUNIT_TEST(testConstructors); + CPPUNIT_TEST(testGetPut); + CPPUNIT_TEST(testListen); + CPPUNIT_TEST_SUITE_END(); + + dht::DhtRunner node1 {}; + dht::DhtRunner node2 {}; + public: + /** + * Method automatically called before each test by CppUnit + */ + void setUp(); + /** + * Method automatically called after each test CppUnit + */ + void tearDown(); + /** + * Test the differents behaviors of constructors + */ + void testConstructors(); + /** + * Test get and put methods + */ + void testGetPut(); + /** + * Test listen method + */ + void testListen(); +}; + +} // namespace test diff --git a/tests/infohashtester.cpp b/tests/infohashtester.cpp index d9baba0776f8eceeee89c97059352545e6a13a53..fa02c3d61cec543afffb43a060b35b1bbe508c8b 100644 --- a/tests/infohashtester.cpp +++ b/tests/infohashtester.cpp @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include "infohashtester.h" diff --git a/tests/infohashtester.h b/tests/infohashtester.h index 2558d3afc6fcffeb0c2fb16a49875688ea30579c..b76bb62a8791a8f1a1a11af759085e3edde68a09 100644 --- a/tests/infohashtester.h +++ b/tests/infohashtester.h @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #pragma once