| 1 |
/* |
| 2 |
* Copyright © 2018 Simon Désaulniers |
| 3 |
* Author: Simon Désaulniers <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of dpaste. |
| 6 |
* |
| 7 |
* dpaste is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation, either version 3 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* dpaste is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with dpaste. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <catch.hpp> |
| 22 |
|
| 23 |
#include "tests.h" |
| 24 |
#include "node.h" |
| 25 |
|
| 26 |
namespace dpaste { |
| 27 |
namespace tests { |
| 28 |
|
| 29 |
class PirateNodeTester { |
| 30 |
#define YARRRRR |
| 31 |
public: |
| 32 |
PirateNodeTester () {} |
| 33 |
virtual ~PirateNodeTester () {} |
| 34 |
|
| 35 |
bool is_running(const dpaste::Node& n) const { return n.running_; } |
| 36 |
}; |
| 37 |
|
| 38 |
TEST_CASE("Node get/paste on DHT", "[Node][get][paste]") { |
| 39 |
PirateNodeTester pt; |
| 40 |
|
| 41 |
const std::string PIN = random_pin(); |
| 42 |
std::vector<uint8_t> data = {0, 1, 2, 3, 4}; |
| 43 |
dpaste::Node node {}; |
| 44 |
node.run(); |
| 45 |
|
| 46 |
SECTION ( "pasting data {0,1,2,3,4}" ) { |
| 47 |
REQUIRE ( node.paste(PIN, std::vector<uint8_t> {data}) ); |
| 48 |
|
| 49 |
SECTION ( "getting pasted blob back from the DHT" ) { |
| 50 |
auto rd = node.get(PIN); |
| 51 |
REQUIRE ( data == rd.front() ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
node.stop(); |
| 56 |
REQUIRE ( not pt.is_running(node) ); |
| 57 |
} |
| 58 |
|
| 59 |
} /* tests */ |
| 60 |
} /* dpaste */ |
| 61 |
|
| 62 |
/* vim: set ts=4 sw=4 tw=120 et :*/ |
| 63 |
|