| 174 | } |
| 175 | |
| 176 | inline void TestSort() { |
| 177 | TDirHier dh; |
| 178 | const TString dir("tmpdir"); |
| 179 | |
| 180 | // prepare fs |
| 181 | { |
| 182 | TMersenne<ui32> rnd; |
| 183 | const TString prefixes[] = { |
| 184 | "a", "b", "xxx", "111", ""}; |
| 185 | |
| 186 | dh.AddDir(dir); |
| 187 | |
| 188 | for (size_t i = 0; i < 100; ++i) { |
| 189 | const TString fname = dir + LOCSLASH_C + prefixes[i % Y_ARRAY_SIZE(prefixes)] + ToString(rnd.GenRand()); |
| 190 | |
| 191 | dh.AddFile(fname); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | TVector<TString> fnames; |
| 196 | |
| 197 | { |
| 198 | TDirIterator d(dir, TDirIterator::TOptions().SetSortByName()); |
| 199 | |
| 200 | for (auto it = d.begin(); it != d.end(); ++it) { |
| 201 | if (it->fts_info == FTS_F) { |
| 202 | fnames.push_back(it->fts_name); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | TVector<TString> sorted(fnames); |
| 208 | Sort(sorted.begin(), sorted.end()); |
| 209 | |
| 210 | UNIT_ASSERT_VALUES_EQUAL(JoinWithNewline(fnames), JoinWithNewline(sorted)); |
| 211 | } |
| 212 | |
| 213 | inline void TestError() { |
| 214 | UNIT_ASSERT_EXCEPTION(TDirIterator("./notexistingfilename"), TDirIterator::TError); |