Skip to content

Commit f86a571

Browse files
committed
tests: Add test case for std::ios_base::ate
1 parent a554cc9 commit f86a571

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ BITCOIN_TESTS =\
5151
test/cuckoocache_tests.cpp \
5252
test/denialofservice_tests.cpp \
5353
test/descriptor_tests.cpp \
54+
test/fs_tests.cpp \
5455
test/getarg_tests.cpp \
5556
test/hash_tests.cpp \
5657
test/key_io_tests.cpp \

src/test/fs_tests.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)