Skip to content

Commit 0d8110e

Browse files
committed
fix build for win32
-fix compilation warning for win32 -disable test for win32 -use RAII pattern to delete file -fix spacing issues
1 parent d2dacb5 commit 0d8110e

File tree

2 files changed

+77
-61
lines changed

2 files changed

+77
-61
lines changed

Release/src/streams/windows/fileio.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,11 @@ size_t _write_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ str
394394
else
395395
{
396396
pOverlapped->Offset = (DWORD)position;
397+
#ifdef _WIN64
397398
pOverlapped->OffsetHigh = (DWORD)(position >> 32);
399+
#else
400+
pOverlapped->OffsetHigh = 0;
401+
#endif
398402
}
399403

400404
_WriteRequest<streams::details::_file_info_impl>* req = nullptr;
@@ -491,7 +495,11 @@ size_t _read_file_async(_In_ streams::details::_file_info_impl *fInfo, _In_ stre
491495
auto pOverlapped = new EXTENDED_OVERLAPPED(_ReadFileCompletionRoutine<streams::details::_file_info_impl>);
492496
pOverlapped->m_scheduler = scheduler.get();
493497
pOverlapped->Offset = (DWORD)offset;
498+
#ifdef _WIN64
494499
pOverlapped->OffsetHigh = (DWORD)(offset >> 32);
500+
#else
501+
pOverlapped->OffsetHigh = 0;
502+
#endif
495503

496504
_ReadRequest<streams::details::_file_info_impl>* req = nullptr;
497505

Release/tests/Functional/streams/fstreambuf_tests.cpp

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -939,92 +939,100 @@ TEST(file_with_one_byte_size)
939939
VERIFY_IS_TRUE(inFile.is_eof());
940940
}
941941

942-
943-
#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
944-
942+
#if ( !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) && defined(_WIN64)
945943
TEST(read_one_byte_at_4G)
946944
{
947-
// Create a file with one byte.
948-
string_t filename = U("read_one_byte_at_4G.txt");
949-
// create a sparse file with sparse file apis
950-
auto handle = CreateSparseFile(filename.c_str());
951-
if (handle == INVALID_HANDLE_VALUE)
952-
{
953-
wprintf(L"CreateFile failed w/err 0x%08lx\n", GetLastError());
954-
return;
955-
}
945+
// Create a file with one byte.
946+
string_t filename = U("read_one_byte_at_4G.txt");
947+
// create a sparse file with sparse file apis
948+
auto handle = CreateSparseFile(filename.c_str());
956949

957-
// write 1 byte
958-
const DWORD size = 1;
959-
auto data = std::unique_ptr<BYTE>(new BYTE[size]);
960-
*(data.get()) = 'a';
950+
VERIFY_ARE_EQUAL(handle, INVALID_HANDLE_VALUE);
961951

962-
DWORD dwBytesWritten;
963-
LARGE_INTEGER i;
964-
i.QuadPart = 0x100000000;
952+
// write 1 byte
953+
auto data = 'a';
965954

966-
SetFilePointerEx(handle, i /*4GB*/, NULL, FILE_END);
967-
WriteFile(handle, data.get(), size, &dwBytesWritten, NULL);
955+
DWORD dwBytesWritten;
956+
LARGE_INTEGER i;
957+
i.QuadPart = 0x100000000;
968958

969-
CloseHandle(handle);
959+
SetFilePointerEx(handle, i /*4GB*/, NULL, FILE_END);
960+
WriteFile(handle, data.get(), 1, &dwBytesWritten, NULL);
970961

971-
// read the file with casablanca streams
972-
concurrency::streams::streambuf<char> file_buf = OPEN<char>(filename, std::ios_base::in).get();
973-
file_buf.seekoff(4 * 1024 * 1024 * 1024ll, ::std::ios_base::beg, ::std::ios_base::in);
962+
CloseHandle(handle);
974963

975-
int aCharacter = file_buf.getc().get();
976-
file_buf.close().wait();
964+
// read the file with casablanca streams
965+
concurrency::streams::streambuf<char> file_buf = OPEN<char>(filename, std::ios_base::in).get();
966+
file_buf.seekoff(4 * 1024 * 1024 * 1024ll, ::std::ios_base::beg, ::std::ios_base::in);
977967

978-
VERIFY_ARE_EQUAL(aCharacter, 'a');
968+
int aCharacter = file_buf.getc().get();
969+
file_buf.close().wait();
970+
971+
VERIFY_ARE_EQUAL(aCharacter, 'a');
979972
}
980973

981974
// since casablanca does not use sparse file apis we're not doing the reverse test (write one byte at 4Gb and verify with std apis)
982975
// because the file created would be too big
983-
984976
#endif
985977
#else
986978

979+
980+
struct TidyStream
981+
{
982+
string_t _fileName;
983+
concurrency::streams::streambuf<char> _stream;
984+
985+
TidyStream(string_t filename)
986+
{
987+
_fileName = filename;
988+
_stream = OPEN<char>(filename, std::ios_base::out | ::std::ios_base::in).get();
989+
}
990+
991+
~TidyStream()
992+
{
993+
_stream.close().wait();
994+
std::remove(_fileName.c_str());
995+
}
996+
};
997+
987998
TEST(write_one_byte_at_4G)
988999
{
989-
// write using casablanca streams
990-
concurrency::streams::streambuf<char>::off_type pos = 4 * 1024 * 1024 * 1024ll;
991-
// Create a file with one byte.
992-
string_t filename = U("write_one_byte_at_4G.txt");
993-
concurrency::streams::streambuf<char> file_buf = OPEN<char>(filename, std::ios_base::out).get();
994-
file_buf.seekoff(pos, ::std::ios_base::beg, ::std::ios_base::out);
995-
996-
file_buf.putc('a').wait();
997-
file_buf.close().wait();
998-
999-
// verify with std streams
1000-
std::fstream stream(get_full_name(filename), std::ios_base::in);
1001-
stream.seekg(pos);
1002-
char c;
1003-
stream >> c;
1004-
stream.close();
1005-
VERIFY_ARE_EQUAL(c, 'a');
1000+
// write using casablanca streams
1001+
concurrency::streams::streambuf<char>::off_type pos = 4 * 1024 * 1024 * 1024ll;
1002+
1003+
string_t filename = U("write_one_byte_at_4G.txt");
1004+
TidyStream file_buf(filename);
1005+
file_buf._stream.seekoff(pos, ::std::ios_base::beg, ::std::ios_base::out);
1006+
file_buf._stream.putc('a').wait();
1007+
file_buf._stream.sync().get();
1008+
1009+
// verify with std streams
1010+
std::fstream stream(get_full_name(filename), std::ios_base::in);
1011+
stream.seekg(pos);
1012+
char c;
1013+
stream >> c;
1014+
stream.close();
1015+
VERIFY_ARE_EQUAL(c, 'a');
10061016
}
10071017

10081018
TEST(read_one_byte_at_4G)
10091019
{
1010-
// write with std stream
1011-
concurrency::streams::streambuf<char>::off_type pos = 4 * 1024 * 1024 * 1024ll;
1012-
// Create a file with one byte.
1013-
string_t filename = U("read_one_byte_at_4G.txt");
1014-
1015-
std::fstream stream(get_full_name(filename), std::ios_base::out);
1016-
stream.seekg(pos);
1017-
stream << 'a';
1018-
stream.close();
1020+
// write with std stream
1021+
concurrency::streams::streambuf<char>::off_type pos = 4 * 1024 * 1024 * 1024ll;
1022+
// Create a file with one byte.
1023+
string_t filename = U("read_one_byte_at_4G.txt");
10191024

1020-
// verify with casablanca streams
1021-
concurrency::streams::streambuf<char> file_buf = OPEN<char>(filename, std::ios_base::in).get();
1022-
file_buf.seekoff(pos, ::std::ios_base::beg, ::std::ios_base::in);
1025+
std::fstream stream(get_full_name(filename), std::ios_base::out);
1026+
stream.seekg(pos);
1027+
stream << 'a';
1028+
stream.close();
10231029

1024-
int aCharacter = file_buf.getc().get();
1025-
file_buf.close().wait();
1030+
// verify with casablanca streams
1031+
TidyStream file_buf(filename);
1032+
file_buf._stream.seekoff(pos, ::std::ios_base::beg, ::std::ios_base::in);
1033+
int aCharacter = file_buf._stream.getc().get();
10261034

1027-
VERIFY_ARE_EQUAL(aCharacter, 'a');
1035+
VERIFY_ARE_EQUAL(aCharacter, 'a');
10281036
}
10291037

10301038
#endif

0 commit comments

Comments
 (0)