Skip to content

Commit

Permalink
tests: Add test case for std::ios_base::ate
Browse files Browse the repository at this point in the history
  • Loading branch information
ken2812221 authored and furszy committed Aug 1, 2021
1 parent 2e57cd4 commit 1a02a8a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ BITCOIN_TESTS =\
test/evo_deterministicmns_tests.cpp \
test/evo_specialtx_tests.cpp \
test/flatfile_tests.cpp \
test/fs_tests.cpp \
test/getarg_tests.cpp \
test/hash_tests.cpp \
test/key_tests.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ set(BITCOIN_TESTS
${CMAKE_CURRENT_SOURCE_DIR}/evo_deterministicmns_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/evo_specialtx_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/flatfile_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fs_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/getarg_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/hash_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/key_tests.cpp
Expand Down
56 changes: 56 additions & 0 deletions src/test/fs_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2011-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//
#include "fs.h"
#include "test/test_pivx.h"

#include <boost/test/unit_test.hpp>

BOOST_FIXTURE_TEST_SUITE(fs_tests, BasicTestingSetup)

BOOST_AUTO_TEST_CASE(fsbridge_fstream)
{
fs::path tmpfolder = SetDataDir("fsbridge_fstream");
// tmpfile1 should be the same as tmpfile2
fs::path tmpfile1 = tmpfolder / "fs_tests_₿_🏃";
fs::path tmpfile2 = tmpfolder / L"fs_tests_₿_🏃";
{
fsbridge::ofstream file(tmpfile1);
file << "bitcoin";
}
{
fsbridge::ifstream file(tmpfile2);
std::string input_buffer;
file >> input_buffer;
BOOST_CHECK_EQUAL(input_buffer, "bitcoin");
}
{
fsbridge::ifstream file(tmpfile1, std::ios_base::in | std::ios_base::ate);
std::string input_buffer;
file >> input_buffer;
BOOST_CHECK_EQUAL(input_buffer, "");
}
{
fsbridge::ofstream file(tmpfile2, std::ios_base::out | std::ios_base::app);
file << "tests";
}
{
fsbridge::ifstream file(tmpfile1);
std::string input_buffer;
file >> input_buffer;
BOOST_CHECK_EQUAL(input_buffer, "bitcointests");
}
{
fsbridge::ofstream file(tmpfile2, std::ios_base::out | std::ios_base::trunc);
file << "bitcoin";
}
{
fsbridge::ifstream file(tmpfile1);
std::string input_buffer;
file >> input_buffer;
BOOST_CHECK_EQUAL(input_buffer, "bitcoin");
}
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 1a02a8a

Please sign in to comment.