@@ -939,92 +939,100 @@ TEST(file_with_one_byte_size)
939
939
VERIFY_IS_TRUE (inFile.is_eof ());
940
940
}
941
941
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)
945
943
TEST (read_one_byte_at_4G)
946
944
{
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 ());
956
949
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);
961
951
962
- DWORD dwBytesWritten;
963
- LARGE_INTEGER i;
964
- i.QuadPart = 0x100000000 ;
952
+ // write 1 byte
953
+ auto data = ' a' ;
965
954
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 ;
968
958
969
- CloseHandle (handle);
959
+ SetFilePointerEx (handle, i /* 4GB*/ , NULL , FILE_END);
960
+ WriteFile (handle, data.get (), 1 , &dwBytesWritten, NULL );
970
961
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);
974
963
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);
977
967
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' );
979
972
}
980
973
981
974
// 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)
982
975
// because the file created would be too big
983
-
984
976
#endif
985
977
#else
986
978
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
+
987
998
TEST (write_one_byte_at_4G)
988
999
{
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' );
1006
1016
}
1007
1017
1008
1018
TEST (read_one_byte_at_4G)
1009
1019
{
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" );
1019
1024
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 ();
1023
1029
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 ();
1026
1034
1027
- VERIFY_ARE_EQUAL (aCharacter, ' a' );
1035
+ VERIFY_ARE_EQUAL (aCharacter, ' a' );
1028
1036
}
1029
1037
1030
1038
#endif
0 commit comments