PerforceComponentTests.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Jobs/JobContext.h>
  9. #include <AzCore/Jobs/JobManager.h>
  10. #include <AzCore/std/parallel/binary_semaphore.h>
  11. #include <AzTest/AzTest.h>
  12. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  13. #include <SourceControl/PerforceComponent.h>
  14. #include <SourceControl/PerforceConnection.h>
  15. #include <QTemporaryDir>
  16. namespace UnitTest
  17. {
  18. struct MockPerforceComponent
  19. : AzToolsFramework::PerforceComponent
  20. {
  21. friend struct PerforceComponentFixture;
  22. };
  23. struct PerforceComponentFixture
  24. : LeakDetectionFixture
  25. , SourceControlTest
  26. {
  27. void SetUp() override
  28. {
  29. AZ::JobManagerDesc jobDesc;
  30. AZ::JobManagerThreadDesc threadDesc;
  31. jobDesc.m_workerThreads.push_back(threadDesc);
  32. jobDesc.m_workerThreads.push_back(threadDesc);
  33. jobDesc.m_workerThreads.push_back(threadDesc);
  34. m_jobManager = aznew AZ::JobManager(jobDesc);
  35. m_jobContext = aznew AZ::JobContext(*m_jobManager);
  36. AZ::JobContext::SetGlobalContext(m_jobContext);
  37. AZ::TickBus::AllowFunctionQueuing(true);
  38. m_perforceComponent = AZStd::make_unique<MockPerforceComponent>();
  39. m_perforceComponent->Activate();
  40. m_perforceComponent->SetConnection(new MockPerforceConnection(m_command));
  41. EnableSourceControl();
  42. }
  43. void TearDown() override
  44. {
  45. AZ::TickBus::AllowFunctionQueuing(false);
  46. AZ::TickBus::ClearQueuedEvents();
  47. m_perforceComponent->Deactivate();
  48. m_perforceComponent = nullptr;
  49. AZ::JobContext::SetGlobalContext(nullptr);
  50. delete m_jobContext;
  51. delete m_jobManager;
  52. }
  53. AZStd::unique_ptr<MockPerforceComponent> m_perforceComponent;
  54. AZ::JobManager* m_jobManager = nullptr;
  55. AZ::JobContext* m_jobContext = nullptr;
  56. };
  57. TEST_F(PerforceComponentFixture, TestGetBulkFileInfo_MultipleFiles_Succeeds)
  58. {
  59. static constexpr char FileAPath[] = R"(C:\depot\dev\default.font)";
  60. static constexpr char FileBPath[] = R"(C:\depot\dev\default.xml)";
  61. m_command.m_fstatResponse =
  62. R"(... depotFile //depot/dev/default.xml)" "\r\n"
  63. R"(... clientFile C:\depot\dev\default.xml)" "\r\n"
  64. R"(... isMapped)" "\r\n"
  65. R"(... headAction integrate)" "\r\n"
  66. R"(... headType text)" "\r\n"
  67. R"(... headTime 1454346715)" "\r\n"
  68. R"(... headRev 3)" "\r\n"
  69. R"(... headChange 147109)" "\r\n"
  70. R"(... headModTime 1452731919)" "\r\n"
  71. R"(... haveRev 3)" "\r\n"
  72. "\r\n"
  73. R"(... depotFile //depot/dev/default.font)" "\r\n"
  74. R"(... clientFile C:\depot\dev\default.font)" "\r\n"
  75. R"(... isMapped)" "\r\n"
  76. R"(... headAction branch)" "\r\n"
  77. R"(... headType text)" "\r\n"
  78. R"(... headTime 1479280355)" "\r\n"
  79. R"(... headRev 1)" "\r\n"
  80. R"(... headChange 317116)" "\r\n"
  81. R"(... headModTime 1478804078)" "\r\n"
  82. R"(... haveRev 1)" "\r\n"
  83. "\r\n";
  84. AZStd::binary_semaphore callbackSignal;
  85. bool result = false;
  86. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  87. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  88. {
  89. result = success;
  90. fileInfo = info;
  91. callbackSignal.release();
  92. };
  93. AZStd::unordered_set<AZStd::string> requestFiles = { FileAPath, FileBPath };
  94. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, requestFiles, bulkCallback);
  95. WaitForSourceControl(callbackSignal);
  96. ASSERT_TRUE(result);
  97. ASSERT_EQ(fileInfo.size(), 2);
  98. for (int i = 0; i < 2; ++i)
  99. {
  100. ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
  101. ASSERT_TRUE(fileInfo[i].IsManaged());
  102. }
  103. }
  104. TEST_F(PerforceComponentFixture, TestGetBulkFileInfo_MissingFile_Succeeds)
  105. {
  106. static constexpr char FileAPath[] = R"(C:\depot\dev\does-not-exist.txt)";
  107. static constexpr char FileBPath[] = R"(C:\depot\dev\does-not-exist-two.txt)";
  108. m_command.m_fstatErrorResponse =
  109. R"(C:\depot\dev\does-not-exist.txt - no such file(s).)" "\r\n"
  110. R"(C:\depot\dev\does-not-exist-two.txt - no such file(s).)" "\r\n"
  111. "\r\n";
  112. AZStd::binary_semaphore callbackSignal;
  113. bool result = false;
  114. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  115. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  116. {
  117. result = success;
  118. fileInfo = info;
  119. callbackSignal.release();
  120. };
  121. AZStd::unordered_set<AZStd::string> requestFiles = { FileAPath, FileBPath };
  122. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, requestFiles, bulkCallback);
  123. WaitForSourceControl(callbackSignal);
  124. ASSERT_TRUE(result);
  125. ASSERT_EQ(fileInfo.size(), 2);
  126. for (int i = 0; i < 2; ++i)
  127. {
  128. ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
  129. ASSERT_EQ(fileInfo[i].m_flags, AzToolsFramework::SourceControlFlags::SCF_Writeable); // Writable should be the only flag
  130. }
  131. }
  132. TEST_F(PerforceComponentFixture, TestGetBulkFileInfo_CompareWithGetFileInfo_ResultMatches)
  133. {
  134. static constexpr char FileAPath[] = R"(C:\depot\dev\default.font)";
  135. static constexpr char FstatResponse[] =
  136. R"(... depotFile //depot/dev/default.font)" "\r\n"
  137. R"(... clientFile C:\depot\dev\default.font)" "\r\n"
  138. R"(... isMapped)" "\r\n"
  139. R"(... headAction branch)" "\r\n"
  140. R"(... headType text)" "\r\n"
  141. R"(... headTime 1479280355)" "\r\n"
  142. R"(... headRev 1)" "\r\n"
  143. R"(... headChange 317116)" "\r\n"
  144. R"(... headModTime 1478804078)" "\r\n"
  145. R"(... haveRev 1)" "\r\n"
  146. "\r\n";
  147. AZStd::binary_semaphore callbackSignal;
  148. bool result = false;
  149. AzToolsFramework::SourceControlFileInfo fileInfoSingle;
  150. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  151. auto singleCallback = [&callbackSignal, &result, &fileInfoSingle](bool success, AzToolsFramework::SourceControlFileInfo info)
  152. {
  153. result = success;
  154. fileInfoSingle = info;
  155. callbackSignal.release();
  156. };
  157. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  158. {
  159. result = success;
  160. fileInfo = info;
  161. callbackSignal.release();
  162. };
  163. AZStd::unordered_set<AZStd::string> requestFiles = { FileAPath };
  164. m_command.m_fstatResponse = FstatResponse;
  165. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, requestFiles, bulkCallback);
  166. WaitForSourceControl(callbackSignal);
  167. ASSERT_TRUE(result);
  168. m_command.m_fstatResponse = FstatResponse;
  169. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetFileInfo, FileAPath, singleCallback);
  170. WaitForSourceControl(callbackSignal);
  171. ASSERT_TRUE(result);
  172. ASSERT_FALSE(fileInfo.empty());
  173. ASSERT_EQ(fileInfoSingle.m_flags, fileInfo[0].m_flags);
  174. }
  175. TEST_F(PerforceComponentFixture, Test_ExecuteEditBulk)
  176. {
  177. static constexpr char FileAPath[] = R"(C:\depot\dev\does-not-exist.txt)";
  178. static constexpr char FileBPath[] = R"(C:\depot\dev\default.font)";
  179. m_command.m_fstatErrorResponse =
  180. R"(C:\depot\dev\does-not-exist.txt - no such file(s).)" "\r\n"
  181. "\r\n";
  182. m_command.m_fstatResponse =
  183. R"(... depotFile //depot/dev/default.font)" "\r\n"
  184. R"(... clientFile C:\depot\dev\default.font)" "\r\n"
  185. R"(... isMapped)" "\r\n"
  186. R"(... headAction branch)" "\r\n"
  187. R"(... headType text)" "\r\n"
  188. R"(... headTime 1479280355)" "\r\n"
  189. R"(... headRev 1)" "\r\n"
  190. R"(... headChange 317116)" "\r\n"
  191. R"(... headModTime 1478804078)" "\r\n"
  192. R"(... otherOpen)" "\r\n"
  193. R"(... haveRev 1)" "\r\n"
  194. "\r\n";
  195. bool addCalled = false;
  196. bool editCalled = false;
  197. m_command.m_addCallback = [&addCalled]([[maybe_unused]] const AZStd::string& args)
  198. {
  199. addCalled = true;
  200. };
  201. m_command.m_editCallback = [this, &editCalled]([[maybe_unused]] const AZStd::string& args)
  202. {
  203. editCalled = true;
  204. m_command.m_fstatResponse =
  205. R"(... depotFile //depot/dev/does-not-exist.txt)" "\r\n"
  206. R"(... clientFile C:\depot\dev\does-not-exist.txt)" "\r\n"
  207. R"(... isMapped)" "\r\n"
  208. R"(... action add)" "\r\n"
  209. R"(... change default)" "\r\n"
  210. R"(... type text)" "\r\n"
  211. R"(... actionOwner unittest)" "\r\n"
  212. R"(... workRev 1)" "\r\n"
  213. "\r\n"
  214. R"(... depotFile //depot/dev/default.font)" "\r\n"
  215. R"(... clientFile C:\depot\dev\default.font)" "\r\n"
  216. R"(... isMapped)" "\r\n"
  217. R"(... headAction add)" "\r\n"
  218. R"(... headType text)" "\r\n"
  219. R"(... headTime 1557439413)" "\r\n"
  220. R"(... headRev 1)" "\r\n"
  221. R"(... headChange 902209)" "\r\n"
  222. R"(... headModTime 1556296348)" "\r\n"
  223. R"(... haveRev 1)" "\r\n"
  224. R"(... action edit)" "\r\n"
  225. R"(... change default)" "\r\n"
  226. R"(... type text)" "\r\n"
  227. R"(... actionOwner unittest)" "\r\n"
  228. R"(... workRev 1)" "\r\n"
  229. "\r\n";
  230. };
  231. AZStd::binary_semaphore callbackSignal;
  232. bool result = false;
  233. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  234. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  235. {
  236. result = success;
  237. fileInfo = info;
  238. callbackSignal.release();
  239. };
  240. AZStd::unordered_set<AZStd::string> requestFiles = { FileAPath, FileBPath };
  241. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEditBulk, requestFiles, true, bulkCallback);
  242. WaitForSourceControl(callbackSignal);
  243. ASSERT_TRUE(result);
  244. ASSERT_TRUE(addCalled);
  245. ASSERT_TRUE(editCalled);
  246. ASSERT_EQ(fileInfo.size(), 2);
  247. for (int i = 0; i < 2; ++i)
  248. {
  249. ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
  250. }
  251. }
  252. TEST_F(PerforceComponentFixture, Test_ExecuteEditBulk_CheckedOutByOther_Failure)
  253. {
  254. static constexpr char FileBPath[] = R"(C:\depot\dev\default.font)";
  255. m_command.m_fstatResponse =
  256. R"(... depotFile //depot/dev/default.font)" "\r\n"
  257. R"(... clientFile C:\depot\dev\default.font)" "\r\n"
  258. R"(... isMapped)" "\r\n"
  259. R"(... headAction branch)" "\r\n"
  260. R"(... headType text)" "\r\n"
  261. R"(... headTime 1479280355)" "\r\n"
  262. R"(... headRev 1)" "\r\n"
  263. R"(... headChange 317116)" "\r\n"
  264. R"(... headModTime 1478804078)" "\r\n"
  265. R"(... otherOpen)" "\r\n"
  266. R"(... haveRev 1)" "\r\n"
  267. "\r\n";
  268. bool addCalled = false;
  269. bool editCalled = false;
  270. m_command.m_addCallback = [&addCalled]([[maybe_unused]] const AZStd::string& args)
  271. {
  272. addCalled = true;
  273. };
  274. m_command.m_editCallback = [&editCalled]([[maybe_unused]] const AZStd::string& args)
  275. {
  276. editCalled = true;
  277. };
  278. AZStd::binary_semaphore callbackSignal;
  279. bool result = false;
  280. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  281. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  282. {
  283. result = success;
  284. fileInfo = info;
  285. callbackSignal.release();
  286. };
  287. AZStd::unordered_set<AZStd::string> requestFiles = { FileBPath };
  288. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEditBulk, requestFiles, false, bulkCallback);
  289. WaitForSourceControl(callbackSignal);
  290. ASSERT_FALSE(result);
  291. ASSERT_FALSE(addCalled);
  292. ASSERT_FALSE(editCalled);
  293. }
  294. bool CreateDummyFile(const QString& fullPathToFile, QString contents = "")
  295. {
  296. QFileInfo fi(fullPathToFile);
  297. QDir fp(fi.path());
  298. fp.mkpath(".");
  299. QFile writer(fullPathToFile);
  300. if (!writer.open(QFile::WriteOnly))
  301. {
  302. return false;
  303. }
  304. {
  305. QTextStream ts(&writer);
  306. ts.setCodec("UTF-8");
  307. ts << contents;
  308. }
  309. return true;
  310. }
  311. TEST_F(PerforceComponentFixture, Test_ExecuteEditBulk_Local_Succeeds)
  312. {
  313. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  314. QTemporaryDir tempDir;
  315. AZStd::string fullPathA = tempDir.filePath("fileA.txt").toUtf8().constData();
  316. AZStd::string fullPathB = tempDir.filePath("fileB.txt").toUtf8().constData();
  317. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  318. for (const char* path : testPaths)
  319. {
  320. ASSERT_TRUE(CreateDummyFile(path));
  321. ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
  322. AZ::IO::SystemFile::SetWritable(path, false);
  323. ASSERT_FALSE(AZ::IO::SystemFile::IsWritable(path));
  324. }
  325. AZStd::binary_semaphore callbackSignal;
  326. bool result = false;
  327. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  328. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  329. {
  330. result = success;
  331. fileInfo = info;
  332. callbackSignal.release();
  333. };
  334. AZStd::unordered_set<AZStd::string> requestFiles = { testPaths.begin(), testPaths.end() };
  335. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEditBulk, requestFiles, false, bulkCallback);
  336. WaitForSourceControl(callbackSignal);
  337. ASSERT_TRUE(result);
  338. ASSERT_EQ(fileInfo.size(), testPaths.size());
  339. for (int i = 0; i < testPaths.size(); ++i)
  340. {
  341. ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
  342. ASSERT_TRUE(fileInfo[i].HasFlag(AzToolsFramework::SourceControlFlags::SCF_Writeable));
  343. ASSERT_TRUE(AZ::IO::SystemFile::IsWritable(testPaths[i]));
  344. }
  345. }
  346. TEST_F(PerforceComponentFixture, Test_ExecuteRenameBulk_Local_Succeeds)
  347. {
  348. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  349. QTemporaryDir tempDir;
  350. AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
  351. AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
  352. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  353. for (const char* path : testPaths)
  354. {
  355. ASSERT_TRUE(CreateDummyFile(path));
  356. ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
  357. }
  358. AZStd::binary_semaphore callbackSignal;
  359. bool result = false;
  360. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  361. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  362. {
  363. result = success;
  364. fileInfo = info;
  365. callbackSignal.release();
  366. };
  367. auto from = tempDir.filePath("o*e/*o/three/file*.txt");
  368. auto to = tempDir.filePath("o*e/*o/three/fileRenamed*.png");
  369. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestRenameBulk, from.toUtf8().constData(), to.toUtf8().constData(), bulkCallback);
  370. WaitForSourceControl(callbackSignal);
  371. ASSERT_TRUE(result);
  372. ASSERT_EQ(fileInfo.size(), testPaths.size());
  373. ASSERT_FALSE(AZ::IO::SystemFile::Exists(fullPathA.c_str()));
  374. ASSERT_FALSE(AZ::IO::SystemFile::Exists(fullPathB.c_str()));
  375. ASSERT_TRUE(AZ::IO::SystemFile::Exists(tempDir.filePath("one/two/three/fileRenamedA.png").toUtf8().constData()));
  376. ASSERT_TRUE(AZ::IO::SystemFile::Exists(tempDir.filePath("one/two/three/fileRenamedB.png").toUtf8().constData()));
  377. for (int i = 0; i < testPaths.size(); ++i)
  378. {
  379. ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
  380. ASSERT_TRUE(fileInfo[i].HasFlag(AzToolsFramework::SourceControlFlags::SCF_Tracked));
  381. }
  382. }
  383. TEST_F(PerforceComponentFixture, Test_ExecuteRenameBulk_Local_MismatchedWildcards_Fails)
  384. {
  385. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  386. QTemporaryDir tempDir;
  387. AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
  388. AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
  389. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  390. for (const char* path : testPaths)
  391. {
  392. ASSERT_TRUE(CreateDummyFile(path));
  393. ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
  394. }
  395. AZStd::binary_semaphore callbackSignal;
  396. bool result = false;
  397. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  398. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  399. {
  400. result = success;
  401. fileInfo = info;
  402. callbackSignal.release();
  403. };
  404. auto from = tempDir.filePath("o*e/*o/three/file*.txt");
  405. auto to = tempDir.filePath("o*e/two/three/fileRenamed*.png");
  406. AZ_TEST_START_TRACE_SUPPRESSION;
  407. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestRenameBulk, from.toUtf8().constData(), to.toUtf8().constData(), bulkCallback);
  408. WaitForSourceControl(callbackSignal);
  409. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  410. ASSERT_FALSE(result);
  411. ASSERT_EQ(fileInfo.size(), 0);
  412. ASSERT_TRUE(AZ::IO::SystemFile::Exists(fullPathA.c_str()));
  413. ASSERT_TRUE(AZ::IO::SystemFile::Exists(fullPathB.c_str()));
  414. ASSERT_FALSE(AZ::IO::SystemFile::Exists(tempDir.filePath("one/two/three/fileRenamedA.png").toUtf8().constData()));
  415. ASSERT_FALSE(AZ::IO::SystemFile::Exists(tempDir.filePath("one/two/three/fileRenamedB.png").toUtf8().constData()));
  416. }
  417. TEST_F(PerforceComponentFixture, Test_ExecuteDeleteBulk_Local_Succeeds)
  418. {
  419. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  420. QTemporaryDir tempDir;
  421. AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
  422. AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
  423. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  424. for (const char* path : testPaths)
  425. {
  426. ASSERT_TRUE(CreateDummyFile(path));
  427. ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
  428. }
  429. AZStd::binary_semaphore callbackSignal;
  430. bool result = false;
  431. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  432. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  433. {
  434. result = success;
  435. fileInfo = info;
  436. callbackSignal.release();
  437. };
  438. auto from = tempDir.filePath("o*e/*o/three/file*.txt");
  439. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestDeleteBulk, from.toUtf8().constData(), bulkCallback);
  440. WaitForSourceControl(callbackSignal);
  441. ASSERT_TRUE(result);
  442. ASSERT_EQ(fileInfo.size(), testPaths.size());
  443. ASSERT_FALSE(AZ::IO::SystemFile::Exists(fullPathA.c_str()));
  444. ASSERT_FALSE(AZ::IO::SystemFile::Exists(fullPathB.c_str()));
  445. for (int i = 0; i < testPaths.size(); ++i)
  446. {
  447. ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
  448. ASSERT_FALSE(fileInfo[i].HasFlag(AzToolsFramework::SourceControlFlags::SCF_Tracked));
  449. }
  450. }
  451. TEST_F(PerforceComponentFixture, Test_GetFiles_Succeeds)
  452. {
  453. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  454. QTemporaryDir tempDir;
  455. AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
  456. AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
  457. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  458. for (const char* path : testPaths)
  459. {
  460. ASSERT_TRUE(CreateDummyFile(path));
  461. ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
  462. }
  463. auto result = AzToolsFramework::LocalFileSCComponent::GetFiles(tempDir.filePath("one/tw*/fileA.txt").toUtf8().constData());
  464. ASSERT_EQ(result.size(), 0);
  465. result = AzToolsFramework::LocalFileSCComponent::GetFiles(tempDir.filePath("on...").toUtf8().constData());
  466. ASSERT_EQ(result.size(), 2);
  467. }
  468. TEST_F(PerforceComponentFixture, Test_GetFiles_StarWildcardAtEnd_OnlyReturnsFirstFile)
  469. {
  470. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  471. QTemporaryDir tempDir;
  472. AZStd::string fullPathA = tempDir.filePath("one/file1.txt").toUtf8().constData();
  473. AZStd::string fullPathB = tempDir.filePath("one/folder/file1.txt").toUtf8().constData();
  474. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  475. for (const char* path : testPaths)
  476. {
  477. ASSERT_TRUE(CreateDummyFile(path));
  478. ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
  479. }
  480. auto result = AzToolsFramework::LocalFileSCComponent::GetFiles(tempDir.filePath("one/f*").toUtf8().constData());
  481. ASSERT_EQ(result.size(), 1);
  482. }
  483. TEST_F(PerforceComponentFixture, Test_GetFiles_MultipleWildcardsAndWildcardAtEnd_Succeeds)
  484. {
  485. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  486. QTemporaryDir tempDir;
  487. AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
  488. AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
  489. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  490. for (const char* path : testPaths)
  491. {
  492. ASSERT_TRUE(CreateDummyFile(path));
  493. ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
  494. }
  495. auto result = AzToolsFramework::LocalFileSCComponent::GetFiles(tempDir.filePath("o*e/tw*/...").toUtf8().constData());
  496. ASSERT_EQ(result.size(), 2);
  497. }
  498. TEST_F(PerforceComponentFixture, Test_GetBulkFileInfo_Wildcard_Succeeds)
  499. {
  500. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  501. QTemporaryDir tempDir;
  502. AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
  503. AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
  504. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  505. for (const char* path : testPaths)
  506. {
  507. ASSERT_TRUE(CreateDummyFile(path));
  508. }
  509. AZStd::binary_semaphore callbackSignal;
  510. bool result = false;
  511. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  512. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  513. {
  514. result = success;
  515. fileInfo = info;
  516. callbackSignal.release();
  517. };
  518. AZStd::unordered_set<AZStd::string> paths = { tempDir.filePath("o*e/*o/three/file*.txt").toUtf8().constData() };
  519. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, paths, bulkCallback);
  520. WaitForSourceControl(callbackSignal);
  521. ASSERT_TRUE(result);
  522. ASSERT_EQ(fileInfo.size(), testPaths.size());
  523. using namespace AzToolsFramework;
  524. for (int i = 0; i < testPaths.size(); ++i)
  525. {
  526. ASSERT_EQ(fileInfo[i].m_status, SCS_OpSuccess);
  527. ASSERT_EQ(fileInfo[i].m_flags, SCF_Writeable | SCF_OpenByUser | SCF_Tracked);
  528. }
  529. }
  530. TEST_F(PerforceComponentFixture, Test_GetBulkFileInfo_MultipleFiles_Succeeds)
  531. {
  532. AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
  533. QTemporaryDir tempDir;
  534. AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
  535. AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
  536. AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
  537. for (const char* path : testPaths)
  538. {
  539. ASSERT_TRUE(CreateDummyFile(path));
  540. }
  541. AZStd::binary_semaphore callbackSignal;
  542. bool result = false;
  543. AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
  544. auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
  545. {
  546. result = success;
  547. fileInfo = info;
  548. callbackSignal.release();
  549. };
  550. AZStd::unordered_set<AZStd::string> paths = { fullPathA, fullPathB };
  551. AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, paths, bulkCallback);
  552. WaitForSourceControl(callbackSignal);
  553. ASSERT_TRUE(result);
  554. ASSERT_EQ(fileInfo.size(), testPaths.size());
  555. using namespace AzToolsFramework;
  556. for (int i = 0; i < testPaths.size(); ++i)
  557. {
  558. ASSERT_EQ(fileInfo[i].m_status, SCS_OpSuccess);
  559. ASSERT_EQ(fileInfo[i].m_flags, SCF_Writeable | SCF_OpenByUser | SCF_Tracked);
  560. }
  561. }
  562. }