| 163 | } |
| 164 | |
| 165 | void TFileTest::TestRW() { |
| 166 | TFile f1("f1.txt", CreateNew); |
| 167 | UNIT_ASSERT(f1.IsOpen()); |
| 168 | UNIT_ASSERT_VALUES_EQUAL(f1.GetName(), "f1.txt"); |
| 169 | UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 0); |
| 170 | ui32 d[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 171 | f1.Write(&d, sizeof(ui32) * 10); |
| 172 | UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 40); |
| 173 | UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 40); |
| 174 | UNIT_ASSERT_VALUES_EQUAL(f1.Seek(12, sSet), 12); |
| 175 | f1.Flush(); |
| 176 | ui32 v; |
| 177 | f1.Load(&v, sizeof(v)); |
| 178 | UNIT_ASSERT_VALUES_EQUAL(v, 3u); |
| 179 | UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 16); |
| 180 | |
| 181 | TFile f2 = f1; |
| 182 | UNIT_ASSERT(f2.IsOpen()); |
| 183 | UNIT_ASSERT_VALUES_EQUAL(f2.GetName(), "f1.txt"); |
| 184 | UNIT_ASSERT_VALUES_EQUAL(f2.GetPosition(), 16); |
| 185 | UNIT_ASSERT_VALUES_EQUAL(f2.GetLength(), 40); |
| 186 | f2.Write(&v, sizeof(v)); |
| 187 | |
| 188 | UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 20); |
| 189 | UNIT_ASSERT_VALUES_EQUAL(f1.Seek(-4, sCur), 16); |
| 190 | v = 0; |
| 191 | f1.Load(&v, sizeof(v)); |
| 192 | UNIT_ASSERT_VALUES_EQUAL(v, 3u); |
| 193 | f1.Close(); |
| 194 | UNIT_ASSERT(!f1.IsOpen()); |
| 195 | UNIT_ASSERT(!f2.IsOpen()); |
| 196 | UNIT_ASSERT(unlink("f1.txt") == 0); |
| 197 | } |
| 198 | |
| 199 | #ifdef _unix_ |
| 200 | #include <locale.h> |