-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libcxx] [test] Add a test for the range of file offsets #122798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f3ed43
[libcxx] [test] Add a test for the range of file offsets
mstorsjo cc0bbb3
Remove the TODO comment, add a static assert.
mstorsjo a943081
Add comments about the purpose of the test, and about the static assert.
mstorsjo 4f202ce
Try to fix the static_assert() for pre-C++17
mstorsjo 1683503
Don't use lambdas in TEST_REQUIRE
mstorsjo a1c8550
Add more XFAILs and comments about them.
mstorsjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/offset_range.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // <fstream> | ||
|
|
||
| // XFAIL: target={{.*}}-windows{{.*}} | ||
|
|
||
| #include <fstream> | ||
| #include <iostream> | ||
| #include <cassert> | ||
| #include <vector> | ||
|
|
||
| #include "assert_macros.h" | ||
| #include "platform_support.h" | ||
| #include "test_macros.h" | ||
|
|
||
| void test_tellg(std::streamoff total_size) { | ||
| std::vector<char> data(8192); | ||
| for (std::size_t i = 0; i < data.size(); ++i) | ||
| data[i] = static_cast<char>(i % (1 << 8 * sizeof(char))); | ||
| std::string p = get_temp_file_name(); | ||
| { | ||
| std::ofstream ofs; | ||
| ofs.open(p, std::ios::out | std::ios::binary); | ||
| assert(ofs.is_open()); | ||
| for (std::streamoff size = 0; size < total_size;) { | ||
| std::size_t n = std::min(static_cast<std::streamoff>(data.size()), total_size - size); | ||
| ofs.write(data.data(), n); | ||
| size += n; | ||
| } | ||
| assert(!ofs.fail()); | ||
| ofs.close(); | ||
| } | ||
| { | ||
| std::ifstream ifs; | ||
| ifs.open(p, std::ios::binary); | ||
| assert(ifs.is_open()); | ||
| std::streamoff in_off = ifs.tellg(); | ||
| TEST_REQUIRE(in_off == 0, [&] { test_eprintf("in_off = %ld\n", in_off); }); | ||
| ifs.seekg(total_size - 20, std::ios::beg); | ||
| in_off = ifs.tellg(); | ||
| TEST_REQUIRE(in_off == total_size - 20, [&] { | ||
| test_eprintf("ref = %zu, in_off = %ld\n", total_size - 20, in_off); | ||
| }); | ||
| ifs.seekg(10, std::ios::cur); | ||
| in_off = ifs.tellg(); | ||
| TEST_REQUIRE(in_off == total_size - 10, [&] { | ||
| test_eprintf("ref = %zu, in_off = %ld\n", total_size - 10, in_off); | ||
| }); | ||
| ifs.seekg(0, std::ios::end); | ||
| in_off = ifs.tellg(); | ||
| TEST_REQUIRE(in_off == total_size, [&] { test_eprintf("ref = %zu, in_off = %ld\n", total_size, in_off); }); | ||
| } | ||
| std::remove(p.c_str()); | ||
| } | ||
|
|
||
| int main(int, char**) { | ||
| static_assert(sizeof(std::streamoff) > 4); | ||
|
||
| test_tellg(0x100000042ULL); | ||
| return 0; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a short comment what you're testing?