Make all fstream tests use tmpnam if creating files, rather than

hard-coded names.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@135444 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sean Hunt 2011-07-18 23:51:21 +00:00
parent e6440c6fa2
commit 13aaf422e4
24 changed files with 205 additions and 156 deletions

View File

@ -19,10 +19,12 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::filebuf f; std::filebuf f;
assert(f.open("test.dat", std::ios_base::out | std::ios_base::in assert(f.open(temp, std::ios_base::out | std::ios_base::in
| std::ios_base::trunc) != 0); | std::ios_base::trunc) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn("123", 3) == 3); assert(f.sputn("123", 3) == 3);
f.pubseekoff(1, std::ios_base::beg); f.pubseekoff(1, std::ios_base::beg);
@ -33,11 +35,11 @@ int main()
assert(f2.is_open()); assert(f2.is_open());
assert(f2.sgetc() == '2'); assert(f2.sgetc() == '2');
} }
remove("test.dat"); remove(temp);
{ {
std::wfilebuf f; std::wfilebuf f;
assert(f.open("test.dat", std::ios_base::out | std::ios_base::in assert(f.open(temp, std::ios_base::out | std::ios_base::in
| std::ios_base::trunc) != 0); | std::ios_base::trunc) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn(L"123", 3) == 3); assert(f.sputn(L"123", 3) == 3);
f.pubseekoff(1, std::ios_base::beg); f.pubseekoff(1, std::ios_base::beg);
@ -48,5 +50,5 @@ int main()
assert(f2.is_open()); assert(f2.is_open());
assert(f2.sgetc() == L'2'); assert(f2.sgetc() == L'2');
} }
remove("test.dat"); remove(temp);
} }

View File

@ -20,10 +20,12 @@
int main() int main()
{ {
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::filebuf f; std::filebuf f;
assert(f.open("test.dat", std::ios_base::out | std::ios_base::in assert(f.open(temp, std::ios_base::out | std::ios_base::in
| std::ios_base::trunc) != 0); | std::ios_base::trunc) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn("123", 3) == 3); assert(f.sputn("123", 3) == 3);
f.pubseekoff(1, std::ios_base::beg); f.pubseekoff(1, std::ios_base::beg);
@ -34,11 +36,11 @@ int main()
assert(f2.is_open()); assert(f2.is_open());
assert(f2.sgetc() == '2'); assert(f2.sgetc() == '2');
} }
remove("test.dat"); remove(temp);
{ {
std::wfilebuf f; std::wfilebuf f;
assert(f.open("test.dat", std::ios_base::out | std::ios_base::in assert(f.open(temp, std::ios_base::out | std::ios_base::in
| std::ios_base::trunc) != 0); | std::ios_base::trunc) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn(L"123", 3) == 3); assert(f.sputn(L"123", 3) == 3);
f.pubseekoff(1, std::ios_base::beg); f.pubseekoff(1, std::ios_base::beg);
@ -49,6 +51,6 @@ int main()
assert(f2.is_open()); assert(f2.is_open());
assert(f2.sgetc() == L'2'); assert(f2.sgetc() == L'2');
} }
remove("test.dat"); remove(temp);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
} }

View File

@ -21,10 +21,12 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::filebuf f; std::filebuf f;
assert(f.open("test.dat", std::ios_base::out | std::ios_base::in assert(f.open(temp, std::ios_base::out | std::ios_base::in
| std::ios_base::trunc) != 0); | std::ios_base::trunc) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn("123", 3) == 3); assert(f.sputn("123", 3) == 3);
f.pubseekoff(1, std::ios_base::beg); f.pubseekoff(1, std::ios_base::beg);
@ -35,11 +37,11 @@ int main()
assert(f2.is_open()); assert(f2.is_open());
assert(f2.sgetc() == '2'); assert(f2.sgetc() == '2');
} }
remove("test.dat"); remove(temp);
{ {
std::wfilebuf f; std::wfilebuf f;
assert(f.open("test.dat", std::ios_base::out | std::ios_base::in assert(f.open(temp, std::ios_base::out | std::ios_base::in
| std::ios_base::trunc) != 0); | std::ios_base::trunc) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn(L"123", 3) == 3); assert(f.sputn(L"123", 3) == 3);
f.pubseekoff(1, std::ios_base::beg); f.pubseekoff(1, std::ios_base::beg);
@ -50,5 +52,5 @@ int main()
assert(f2.is_open()); assert(f2.is_open());
assert(f2.sgetc() == L'2'); assert(f2.sgetc() == L'2');
} }
remove("test.dat"); remove(temp);
} }

View File

@ -20,10 +20,12 @@
int main() int main()
{ {
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::filebuf f; std::filebuf f;
assert(f.open("test.dat", std::ios_base::out | std::ios_base::in assert(f.open(temp, std::ios_base::out | std::ios_base::in
| std::ios_base::trunc) != 0); | std::ios_base::trunc) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn("123", 3) == 3); assert(f.sputn("123", 3) == 3);
f.pubseekoff(1, std::ios_base::beg); f.pubseekoff(1, std::ios_base::beg);
@ -33,11 +35,11 @@ int main()
assert(f2.is_open()); assert(f2.is_open());
assert(f2.sgetc() == '2'); assert(f2.sgetc() == '2');
} }
remove("test.dat"); remove(temp);
{ {
std::wfilebuf f; std::wfilebuf f;
assert(f.open("test.dat", std::ios_base::out | std::ios_base::in assert(f.open(temp, std::ios_base::out | std::ios_base::in
| std::ios_base::trunc) != 0); | std::ios_base::trunc) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn(L"123", 3) == 3); assert(f.sputn(L"123", 3) == 3);
f.pubseekoff(1, std::ios_base::beg); f.pubseekoff(1, std::ios_base::beg);
@ -47,6 +49,6 @@ int main()
assert(f2.is_open()); assert(f2.is_open());
assert(f2.sgetc() == L'2'); assert(f2.sgetc() == L'2');
} }
remove("test.dat"); remove(temp);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
} }

View File

@ -16,34 +16,36 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::filebuf f; std::filebuf f;
assert(f.open("test.dat", std::ios_base::out) != 0); assert(f.open(temp, std::ios_base::out) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn("123", 3) == 3); assert(f.sputn("123", 3) == 3);
} }
{ {
std::filebuf f; std::filebuf f;
assert(f.open("test.dat", std::ios_base::in) != 0); assert(f.open(temp, std::ios_base::in) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sbumpc() == '1'); assert(f.sbumpc() == '1');
assert(f.sbumpc() == '2'); assert(f.sbumpc() == '2');
assert(f.sbumpc() == '3'); assert(f.sbumpc() == '3');
} }
remove("test.dat"); remove(temp);
{ {
std::wfilebuf f; std::wfilebuf f;
assert(f.open("test.dat", std::ios_base::out) != 0); assert(f.open(temp, std::ios_base::out) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sputn(L"123", 3) == 3); assert(f.sputn(L"123", 3) == 3);
} }
{ {
std::wfilebuf f; std::wfilebuf f;
assert(f.open("test.dat", std::ios_base::in) != 0); assert(f.open(temp, std::ios_base::in) != 0);
assert(f.is_open()); assert(f.is_open());
assert(f.sbumpc() == L'1'); assert(f.sbumpc() == L'1');
assert(f.sbumpc() == L'2'); assert(f.sbumpc() == L'2');
assert(f.sbumpc() == L'3'); assert(f.sbumpc() == L'3');
} }
remove("test.dat"); remove(temp);
} }

View File

@ -19,11 +19,14 @@
int main() int main()
{ {
char temp1[L_tmpnam], temp2[L_tmpnam];
tmpnam(temp1);
tmpnam(temp2);
{ {
std::fstream fs1("test1.dat", std::ios_base::in | std::ios_base::out std::fstream fs1(temp1, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
std::fstream fs2("test2.dat", std::ios_base::in | std::ios_base::out std::fstream fs2(temp2, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
fs1 << 1 << ' ' << 2; fs1 << 1 << ' ' << 2;
fs2 << 2 << ' ' << 1; fs2 << 2 << ' ' << 1;
fs1.seekg(0); fs1.seekg(0);
@ -40,13 +43,13 @@ int main()
fs2 >> i; fs2 >> i;
assert(i == 2); assert(i == 2);
} }
std::remove("test1.dat"); std::remove(temp1);
std::remove("test2.dat"); std::remove(temp2);
{ {
std::wfstream fs1("test1.dat", std::ios_base::in | std::ios_base::out std::wfstream fs1(temp1, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
std::wfstream fs2("test2.dat", std::ios_base::in | std::ios_base::out std::wfstream fs2(temp2, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
fs1 << 1 << ' ' << 2; fs1 << 1 << ' ' << 2;
fs2 << 2 << ' ' << 1; fs2 << 2 << ' ' << 1;
fs1.seekg(0); fs1.seekg(0);
@ -63,6 +66,6 @@ int main()
fs2 >> i; fs2 >> i;
assert(i == 2); assert(i == 2);
} }
std::remove("test1.dat"); std::remove(temp1);
std::remove("test2.dat"); std::remove(temp2);
} }

View File

@ -20,9 +20,10 @@
int main() int main()
{ {
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
char temp[L_tmpnam];
{ {
std::fstream fso("test.dat", std::ios_base::in | std::ios_base::out std::fstream fso(temp, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
std::fstream fs; std::fstream fs;
fs = move(fso); fs = move(fso);
double x = 0; double x = 0;
@ -31,10 +32,10 @@ int main()
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
{ {
std::wfstream fso("test.dat", std::ios_base::in | std::ios_base::out std::wfstream fso(temp, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
std::wfstream fs; std::wfstream fs;
fs = move(fso); fs = move(fso);
double x = 0; double x = 0;
@ -43,6 +44,6 @@ int main()
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
} }

View File

@ -20,11 +20,14 @@
int main() int main()
{ {
char temp1[L_tmpnam], temp2[L_tmpnam];
tmpnam(temp1);
tmpnam(temp2);
{ {
std::fstream fs1("test1.dat", std::ios_base::in | std::ios_base::out std::fstream fs1(temp1, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
std::fstream fs2("test2.dat", std::ios_base::in | std::ios_base::out std::fstream fs2(temp2, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
fs1 << 1 << ' ' << 2; fs1 << 1 << ' ' << 2;
fs2 << 2 << ' ' << 1; fs2 << 2 << ' ' << 1;
fs1.seekg(0); fs1.seekg(0);
@ -41,13 +44,13 @@ int main()
fs2 >> i; fs2 >> i;
assert(i == 2); assert(i == 2);
} }
std::remove("test1.dat"); std::remove(temp1);
std::remove("test2.dat"); std::remove(temp2);
{ {
std::wfstream fs1("test1.dat", std::ios_base::in | std::ios_base::out std::wfstream fs1(temp1, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
std::wfstream fs2("test2.dat", std::ios_base::in | std::ios_base::out std::wfstream fs2(temp2, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
fs1 << 1 << ' ' << 2; fs1 << 1 << ' ' << 2;
fs2 << 2 << ' ' << 1; fs2 << 2 << ' ' << 1;
fs1.seekg(0); fs1.seekg(0);
@ -64,6 +67,6 @@ int main()
fs2 >> i; fs2 >> i;
assert(i == 2); assert(i == 2);
} }
std::remove("test1.dat"); std::remove(temp1);
std::remove("test2.dat"); std::remove(temp2);
} }

View File

@ -20,9 +20,11 @@
int main() int main()
{ {
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::fstream fso("test.dat", std::ios_base::in | std::ios_base::out std::fstream fso(temp, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
std::fstream fs = move(fso); std::fstream fs = move(fso);
double x = 0; double x = 0;
fs << 3.25; fs << 3.25;
@ -32,8 +34,8 @@ int main()
} }
std::remove("test.dat"); std::remove("test.dat");
{ {
std::wfstream fso("test.dat", std::ios_base::in | std::ios_base::out std::wfstream fso(temp, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
std::wfstream fs = move(fso); std::wfstream fs = move(fso);
double x = 0; double x = 0;
fs << 3.25; fs << 3.25;
@ -41,6 +43,6 @@ int main()
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
} }

View File

@ -19,24 +19,26 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::fstream fs("test.dat", std::ios_base::in | std::ios_base::out std::fstream fs(temp, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
double x = 0; double x = 0;
fs << 3.25; fs << 3.25;
fs.seekg(0); fs.seekg(0);
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
{ {
std::wfstream fs("test.dat", std::ios_base::in | std::ios_base::out std::wfstream fs(temp, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
double x = 0; double x = 0;
fs << 3.25; fs << 3.25;
fs.seekg(0); fs.seekg(0);
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
} }

View File

@ -19,7 +19,7 @@
int main() int main()
{ {
char temp [L_tmpnam]; char temp[L_tmpnam];
tmpnam(temp); tmpnam(temp);
{ {
std::fstream fs(std::string(temp), std::fstream fs(std::string(temp),

View File

@ -19,22 +19,24 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::fstream fs; std::fstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
fs.open("test.dat", std::ios_base::out); fs.open(temp, std::ios_base::out);
assert(fs.is_open()); assert(fs.is_open());
fs.close(); fs.close();
assert(!fs.is_open()); assert(!fs.is_open());
} }
remove("test.dat"); remove(temp);
{ {
std::wfstream fs; std::wfstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
fs.open("test.dat", std::ios_base::out); fs.open(temp, std::ios_base::out);
assert(fs.is_open()); assert(fs.is_open());
fs.close(); fs.close();
assert(!fs.is_open()); assert(!fs.is_open());
} }
remove("test.dat"); remove(temp);
} }

View File

@ -19,11 +19,13 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::fstream fs; std::fstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
fs.open("test.dat", std::ios_base::in | std::ios_base::out fs.open(temp, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
assert(fs.is_open()); assert(fs.is_open());
double x = 0; double x = 0;
fs << 3.25; fs << 3.25;
@ -31,12 +33,12 @@ int main()
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
{ {
std::wfstream fs; std::wfstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
fs.open("test.dat", std::ios_base::in | std::ios_base::out fs.open(temp, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
assert(fs.is_open()); assert(fs.is_open());
double x = 0; double x = 0;
fs << 3.25; fs << 3.25;
@ -44,5 +46,5 @@ int main()
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
} }

View File

@ -19,11 +19,13 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::fstream fs; std::fstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
fs.open(std::string("test.dat"), std::ios_base::in | std::ios_base::out fs.open(std::string(temp), std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
assert(fs.is_open()); assert(fs.is_open());
double x = 0; double x = 0;
fs << 3.25; fs << 3.25;
@ -31,12 +33,12 @@ int main()
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
{ {
std::wfstream fs; std::wfstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
fs.open(std::string("test.dat"), std::ios_base::in | std::ios_base::out fs.open(std::string(temp), std::ios_base::in | std::ios_base::out
| std::ios_base::trunc); | std::ios_base::trunc);
assert(fs.is_open()); assert(fs.is_open());
double x = 0; double x = 0;
fs << 3.25; fs << 3.25;
@ -44,5 +46,5 @@ int main()
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
std::remove("test.dat"); std::remove(temp);
} }

View File

@ -19,9 +19,12 @@
int main() int main()
{ {
char temp1[L_tmpnam], temp2[L_tmpnam];
tmpnam(temp1);
tmpnam(temp2);
{ {
std::ofstream fs1("test1.dat"); std::ofstream fs1(temp1);
std::ofstream fs2("test2.dat"); std::ofstream fs2(temp2);
fs1 << 3.25; fs1 << 3.25;
fs2 << 4.5; fs2 << 4.5;
fs1.swap(fs2); fs1.swap(fs2);
@ -29,26 +32,26 @@ int main()
fs2 << ' ' << 4.5; fs2 << ' ' << 4.5;
} }
{ {
std::ifstream fs("test1.dat"); std::ifstream fs(temp1);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
fs >> x; fs >> x;
assert(x == 4.5); assert(x == 4.5);
} }
remove("test1.dat"); remove(temp1);
{ {
std::ifstream fs("test2.dat"); std::ifstream fs(temp2);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 4.5); assert(x == 4.5);
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test2.dat"); remove(temp2);
{ {
std::wofstream fs1("test1.dat"); std::wofstream fs1(temp1);
std::wofstream fs2("test2.dat"); std::wofstream fs2(temp2);
fs1 << 3.25; fs1 << 3.25;
fs2 << 4.5; fs2 << 4.5;
fs1.swap(fs2); fs1.swap(fs2);
@ -56,21 +59,21 @@ int main()
fs2 << ' ' << 4.5; fs2 << ' ' << 4.5;
} }
{ {
std::wifstream fs("test1.dat"); std::wifstream fs(temp1);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
fs >> x; fs >> x;
assert(x == 4.5); assert(x == 4.5);
} }
remove("test1.dat"); remove(temp1);
{ {
std::wifstream fs("test2.dat"); std::wifstream fs(temp2);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 4.5); assert(x == 4.5);
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test2.dat"); remove(temp2);
} }

View File

@ -20,31 +20,33 @@
int main() int main()
{ {
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::ofstream fso("test.dat"); std::ofstream fso(temp);
std::ofstream fs; std::ofstream fs;
fs = move(fso); fs = move(fso);
fs << 3.25; fs << 3.25;
} }
{ {
std::ifstream fs("test.dat"); std::ifstream fs(temp);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test.dat"); remove(temp);
{ {
std::wofstream fso("test.dat"); std::wofstream fso(temp);
std::wofstream fs; std::wofstream fs;
fs = move(fso); fs = move(fso);
fs << 3.25; fs << 3.25;
} }
{ {
std::wifstream fs("test.dat"); std::wifstream fs(temp);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test.dat"); remove(temp);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
} }

View File

@ -20,9 +20,12 @@
int main() int main()
{ {
char temp1[L_tmpnam], temp2[L_tmpnam];
tmpnam(temp1);
tmpnam(temp2);
{ {
std::ofstream fs1("test1.dat"); std::ofstream fs1(temp1);
std::ofstream fs2("test2.dat"); std::ofstream fs2(temp2);
fs1 << 3.25; fs1 << 3.25;
fs2 << 4.5; fs2 << 4.5;
swap(fs1, fs2); swap(fs1, fs2);
@ -30,26 +33,26 @@ int main()
fs2 << ' ' << 4.5; fs2 << ' ' << 4.5;
} }
{ {
std::ifstream fs("test1.dat"); std::ifstream fs(temp1);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
fs >> x; fs >> x;
assert(x == 4.5); assert(x == 4.5);
} }
remove("test1.dat"); remove(temp1);
{ {
std::ifstream fs("test2.dat"); std::ifstream fs(temp2);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 4.5); assert(x == 4.5);
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test2.dat"); remove(temp2);
{ {
std::wofstream fs1("test1.dat"); std::wofstream fs1(temp1);
std::wofstream fs2("test2.dat"); std::wofstream fs2(temp2);
fs1 << 3.25; fs1 << 3.25;
fs2 << 4.5; fs2 << 4.5;
swap(fs1, fs2); swap(fs1, fs2);
@ -57,21 +60,21 @@ int main()
fs2 << ' ' << 4.5; fs2 << ' ' << 4.5;
} }
{ {
std::wifstream fs("test1.dat"); std::wifstream fs(temp1);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
fs >> x; fs >> x;
assert(x == 4.5); assert(x == 4.5);
} }
remove("test1.dat"); remove(temp1);
{ {
std::wifstream fs("test2.dat"); std::wifstream fs(temp2);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 4.5); assert(x == 4.5);
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test2.dat"); remove(temp2);
} }

View File

@ -20,29 +20,31 @@
int main() int main()
{ {
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::ofstream fso("test.dat"); std::ofstream fso(temp);
std::ofstream fs = move(fso); std::ofstream fs = move(fso);
fs << 3.25; fs << 3.25;
} }
{ {
std::ifstream fs("test.dat"); std::ifstream fs(temp);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test.dat"); remove(temp);
{ {
std::wofstream fso("test.dat"); std::wofstream fso(temp);
std::wofstream fs = move(fso); std::wofstream fs = move(fso);
fs << 3.25; fs << 3.25;
} }
{ {
std::wifstream fs("test.dat"); std::wifstream fs(temp);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test.dat"); remove(temp);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
} }

View File

@ -19,26 +19,28 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::ofstream fs("test.dat"); std::ofstream fs(temp);
fs << 3.25; fs << 3.25;
} }
{ {
std::ifstream fs("test.dat"); std::ifstream fs(temp);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test.dat"); remove(temp);
{ {
std::wofstream fs("test.dat"); std::wofstream fs(temp);
fs << 3.25; fs << 3.25;
} }
{ {
std::wifstream fs("test.dat"); std::wifstream fs(temp);
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test.dat"); remove(temp);
} }

View File

@ -19,26 +19,28 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::ofstream fs(std::string("test.dat")); std::ofstream fs((std::string(temp)));
fs << 3.25; fs << 3.25;
} }
{ {
std::ifstream fs(std::string("test.dat")); std::ifstream fs((std::string(temp)));
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test.dat"); remove(temp);
{ {
std::wofstream fs(std::string("test.dat")); std::wofstream fs((std::string(temp)));
fs << 3.25; fs << 3.25;
} }
{ {
std::wifstream fs(std::string("test.dat")); std::wifstream fs((std::string(temp)));
double x = 0; double x = 0;
fs >> x; fs >> x;
assert(x == 3.25); assert(x == 3.25);
} }
remove("test.dat"); remove(temp);
} }

View File

@ -19,22 +19,24 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::ofstream fs; std::ofstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
fs.open("test.dat"); fs.open(temp);
assert(fs.is_open()); assert(fs.is_open());
fs.close(); fs.close();
assert(!fs.is_open()); assert(!fs.is_open());
} }
remove("test.dat"); remove(temp);
{ {
std::wofstream fs; std::wofstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
fs.open("test.dat"); fs.open(temp);
assert(fs.is_open()); assert(fs.is_open());
fs.close(); fs.close();
assert(!fs.is_open()); assert(!fs.is_open());
} }
remove("test.dat"); remove(temp);
} }

View File

@ -19,38 +19,40 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::ofstream fs; std::ofstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
char c = 'a'; char c = 'a';
fs << c; fs << c;
assert(fs.fail()); assert(fs.fail());
fs.open("test.dat"); fs.open(temp);
assert(fs.is_open()); assert(fs.is_open());
fs << c; fs << c;
} }
{ {
std::ifstream fs("test.dat"); std::ifstream fs(temp);
char c = 0; char c = 0;
fs >> c; fs >> c;
assert(c == 'a'); assert(c == 'a');
} }
remove("test.dat"); remove(temp);
{ {
std::wofstream fs; std::wofstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
wchar_t c = L'a'; wchar_t c = L'a';
fs << c; fs << c;
assert(fs.fail()); assert(fs.fail());
fs.open("test.dat"); fs.open(temp);
assert(fs.is_open()); assert(fs.is_open());
fs << c; fs << c;
} }
{ {
std::wifstream fs("test.dat"); std::wifstream fs(temp);
wchar_t c = 0; wchar_t c = 0;
fs >> c; fs >> c;
assert(c == L'a'); assert(c == L'a');
} }
remove("test.dat"); remove(temp);
} }

View File

@ -19,38 +19,40 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::ofstream fs; std::ofstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
char c = 'a'; char c = 'a';
fs << c; fs << c;
assert(fs.fail()); assert(fs.fail());
fs.open(std::string("test.dat")); fs.open(std::string(temp));
assert(fs.is_open()); assert(fs.is_open());
fs << c; fs << c;
} }
{ {
std::ifstream fs("test.dat"); std::ifstream fs(temp);
char c = 0; char c = 0;
fs >> c; fs >> c;
assert(c == 'a'); assert(c == 'a');
} }
remove("test.dat"); remove(temp);
{ {
std::wofstream fs; std::wofstream fs;
assert(!fs.is_open()); assert(!fs.is_open());
wchar_t c = L'a'; wchar_t c = L'a';
fs << c; fs << c;
assert(fs.fail()); assert(fs.fail());
fs.open(std::string("test.dat")); fs.open(std::string(temp));
assert(fs.is_open()); assert(fs.is_open());
fs << c; fs << c;
} }
{ {
std::wifstream fs("test.dat"); std::wifstream fs(temp);
wchar_t c = 0; wchar_t c = 0;
fs >> c; fs >> c;
assert(c == L'a'); assert(c == L'a');
} }
remove("test.dat"); remove(temp);
} }

View File

@ -19,16 +19,18 @@
int main() int main()
{ {
char temp[L_tmpnam];
tmpnam(temp);
{ {
std::ofstream fs("test.dat"); std::ofstream fs(temp);
std::filebuf* fb = fs.rdbuf(); std::filebuf* fb = fs.rdbuf();
assert(fb->sputc('r') == 'r'); assert(fb->sputc('r') == 'r');
} }
remove("test.dat"); remove(temp);
{ {
std::wofstream fs("test.dat"); std::wofstream fs(temp);
std::wfilebuf* fb = fs.rdbuf(); std::wfilebuf* fb = fs.rdbuf();
assert(fb->sputc(L'r') == L'r'); assert(fb->sputc(L'r') == L'r');
} }
remove("test.dat"); remove(temp);
} }