@@ -26,6 +26,18 @@ bool is_open(const file& file) {
2626 return file.rdbuf ()->is_open ();
2727}
2828
29+ // / Tests file type traits and member types
30+ TEST (file, type_traits) {
31+ using traits = std::char_traits<char >;
32+
33+ static_assert (std::is_base_of_v<std::basic_iostream<char >, file>);
34+ static_assert (std::is_same_v<file::char_type, char >);
35+ static_assert (std::is_same_v<file::traits_type, traits>);
36+ static_assert (std::is_same_v<file::int_type, traits::int_type>);
37+ static_assert (std::is_same_v<file::pos_type, traits::pos_type>);
38+ static_assert (std::is_same_v<file::off_type, traits::off_type>);
39+ }
40+
2941// / Tests file creation with label
3042TEST (file, create_with_label) {
3143 file tmpfile = file (LABEL);
@@ -109,8 +121,8 @@ TEST(file, copy_file) {
109121
110122 EXPECT_TRUE (fs::is_regular_file (tmpfile));
111123
112- auto stream = std::ifstream (copy.path ());
113- auto content = std::string (std::istreambuf_iterator< char > (stream), {});
124+ std::ifstream stream = std::ifstream (copy.path ());
125+ std::string content = std::string (std::istreambuf_iterator (stream), {});
114126 EXPECT_EQ (content, " Hello, world!" );
115127}
116128
@@ -136,8 +148,8 @@ TEST(file, move_to_self) {
136148 EXPECT_TRUE (fs::exists (path));
137149
138150 {
139- auto stream = std::ifstream (path);
140- auto content = std::string (std::istreambuf_iterator< char > (stream), {});
151+ std::ifstream stream = std::ifstream (path);
152+ std::string content = std::string (std::istreambuf_iterator (stream), {});
141153 EXPECT_EQ (content, " Hello, world!" );
142154 }
143155
@@ -165,8 +177,8 @@ TEST(file, move_to_existing_file) {
165177 EXPECT_FALSE (fs::exists (path, ec));
166178
167179 {
168- auto stream = std::ifstream (to);
169- auto content = std::string (std::istreambuf_iterator< char > (stream), {});
180+ std::ifstream stream = std::ifstream (to);
181+ std::string content = std::string (std::istreambuf_iterator (stream), {});
170182 EXPECT_EQ (content, " Hello, world!" );
171183 }
172184
@@ -207,18 +219,27 @@ TEST(file, destructor) {
207219// / Tests file move constructor
208220TEST (file, move_constructor) {
209221 file fst = file ();
222+ fst << " Hello!" ;
223+
210224 file snd = file (std::move (fst));
211225
212226 EXPECT_FALSE (snd.path ().empty ());
213227 EXPECT_TRUE (fs::exists (snd));
214228 EXPECT_TRUE (is_open (snd));
229+
230+ snd.seekg (0 );
231+ std::string content;
232+ snd >> content;
233+ EXPECT_EQ (content, " Hello!" );
215234}
216235
217236// / Tests file move assignment operator
218237TEST (file, move_assignment) {
219238 file fst = file ();
239+
220240 {
221241 file snd = file ();
242+ snd << " Hello!" ;
222243
223244 fs::path path1 = fst;
224245 fs::path path2 = snd;
@@ -233,6 +254,11 @@ TEST(file, move_assignment) {
233254 }
234255
235256 EXPECT_FALSE (fst.path ().empty ());
257+
258+ fst.seekg (0 );
259+ std::string content;
260+ fst >> content;
261+ EXPECT_EQ (content, " Hello!" );
236262}
237263
238264// / Tests file swapping
0 commit comments