MCPcopy Create free account
hub / github.com/catboost/catboost / RunRenameTest

Function RunRenameTest

util/system/fs_ut.cpp:97–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97void RunRenameTest(TFsPath src, TFsPath dst) {
98 // if previous running was failed
99 TFsPath dir1 = "dir";
100 TFsPath dir2 = "dst_dir";
101
102 NFs::Remove(src);
103 NFs::Remove(dst);
104
105 NFs::Remove(dir1 / src);
106 NFs::Remove(dir1);
107 NFs::Remove(dir2 / src);
108 NFs::Remove(dir2);
109
110 {
111 TFile file(src, CreateNew | WrOnly);
112 file.Write("123", 3);
113 }
114
115 UNIT_ASSERT(NFs::Rename(src, dst));
116 UNIT_ASSERT(NFs::Exists(dst));
117 UNIT_ASSERT(!NFs::Exists(src));
118
119 {
120 TFile file(dst, OpenExisting);
121 UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 3);
122 }
123
124 NFs::MakeDirectory(dir1);
125 {
126 TFile file(dir1 / src, CreateNew | WrOnly);
127 file.Write("123", 3);
128 }
129 UNIT_ASSERT(NFs::Rename(dir1, dir2));
130 UNIT_ASSERT(NFs::Exists(dir2 / src));
131 UNIT_ASSERT(!NFs::Exists(dir1));
132
133 {
134 TFile file(dir2 / src, OpenExisting);
135 UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 3);
136 }
137
138 UNIT_ASSERT(!NFs::Remove(src));
139 UNIT_ASSERT(NFs::Remove(dst));
140 UNIT_ASSERT(!NFs::Remove(dir1));
141 UNIT_ASSERT(NFs::Remove(dir2 / src));
142 UNIT_ASSERT(NFs::Remove(dir2));
143}
144
145void TFsTest::TestRename() {
146 RunRenameTest("src.txt", "dst.txt");

Callers 1

TestRenameMethod · 0.85

Calls 3

MakeDirectoryFunction · 0.85
WriteMethod · 0.45
GetLengthMethod · 0.45

Tested by 1

TestRenameMethod · 0.68