|
| 1 | +// Copyright (c) 2011-2018 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | +// |
| 5 | +#include <fs.h> |
| 6 | +#include <test/test_bitcoin.h> |
| 7 | + |
| 8 | +#include <boost/test/unit_test.hpp> |
| 9 | + |
| 10 | +BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup) |
| 11 | + |
| 12 | +BOOST_AUTO_TEST_CASE(fsbridge_fstream) |
| 13 | +{ |
| 14 | + fs::path tmpfolder = SetDataDir("fsbridge_fstream"); |
| 15 | + // tmpfile1 should be the same as tmpfile2 |
| 16 | + fs::path tmpfile1 = tmpfolder / "fs_tests_₿_🏃"; |
| 17 | + fs::path tmpfile2 = tmpfolder / L"fs_tests_₿_🏃"; |
| 18 | + { |
| 19 | + fsbridge::ofstream file(tmpfile1); |
| 20 | + file << "bitcoin"; |
| 21 | + } |
| 22 | + { |
| 23 | + fsbridge::ifstream file(tmpfile2); |
| 24 | + std::string input_buffer; |
| 25 | + file >> input_buffer; |
| 26 | + BOOST_CHECK_EQUAL(input_buffer, "bitcoin"); |
| 27 | + } |
| 28 | + { |
| 29 | + fsbridge::ifstream file(tmpfile1, std::ios_base::in | std::ios_base::ate); |
| 30 | + std::string input_buffer; |
| 31 | + file >> input_buffer; |
| 32 | + BOOST_CHECK_EQUAL(input_buffer, ""); |
| 33 | + } |
| 34 | + { |
| 35 | + fsbridge::ofstream file(tmpfile2, std::ios_base::out | std::ios_base::app); |
| 36 | + file << "tests"; |
| 37 | + } |
| 38 | + { |
| 39 | + fsbridge::ifstream file(tmpfile1); |
| 40 | + std::string input_buffer; |
| 41 | + file >> input_buffer; |
| 42 | + BOOST_CHECK_EQUAL(input_buffer, "bitcointests"); |
| 43 | + } |
| 44 | + { |
| 45 | + fsbridge::ofstream file(tmpfile2, std::ios_base::out | std::ios_base::trunc); |
| 46 | + file << "bitcoin"; |
| 47 | + } |
| 48 | + { |
| 49 | + fsbridge::ifstream file(tmpfile1); |
| 50 | + std::string input_buffer; |
| 51 | + file >> input_buffer; |
| 52 | + BOOST_CHECK_EQUAL(input_buffer, "bitcoin"); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +BOOST_AUTO_TEST_SUITE_END() |
0 commit comments