123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <AzCore/Jobs/JobContext.h>
- #include <AzCore/Jobs/JobManager.h>
- #include <AzCore/std/parallel/binary_semaphore.h>
- #include <AzTest/AzTest.h>
- #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
- #include <SourceControl/PerforceComponent.h>
- #include <SourceControl/PerforceConnection.h>
- #include <QTemporaryDir>
- namespace UnitTest
- {
- struct MockPerforceComponent
- : AzToolsFramework::PerforceComponent
- {
- friend struct PerforceComponentFixture;
- };
- struct PerforceComponentFixture
- : LeakDetectionFixture
- , SourceControlTest
- {
- void SetUp() override
- {
- AZ::JobManagerDesc jobDesc;
- AZ::JobManagerThreadDesc threadDesc;
- jobDesc.m_workerThreads.push_back(threadDesc);
- jobDesc.m_workerThreads.push_back(threadDesc);
- jobDesc.m_workerThreads.push_back(threadDesc);
- m_jobManager = aznew AZ::JobManager(jobDesc);
- m_jobContext = aznew AZ::JobContext(*m_jobManager);
- AZ::JobContext::SetGlobalContext(m_jobContext);
- AZ::TickBus::AllowFunctionQueuing(true);
- m_perforceComponent = AZStd::make_unique<MockPerforceComponent>();
- m_perforceComponent->Activate();
- m_perforceComponent->SetConnection(new MockPerforceConnection(m_command));
- EnableSourceControl();
- }
- void TearDown() override
- {
- AZ::TickBus::AllowFunctionQueuing(false);
- AZ::TickBus::ClearQueuedEvents();
- m_perforceComponent->Deactivate();
- m_perforceComponent = nullptr;
- AZ::JobContext::SetGlobalContext(nullptr);
- delete m_jobContext;
- delete m_jobManager;
- }
- AZStd::unique_ptr<MockPerforceComponent> m_perforceComponent;
- AZ::JobManager* m_jobManager = nullptr;
- AZ::JobContext* m_jobContext = nullptr;
- };
- TEST_F(PerforceComponentFixture, TestGetBulkFileInfo_MultipleFiles_Succeeds)
- {
- static constexpr char FileAPath[] = R"(C:\depot\dev\default.font)";
- static constexpr char FileBPath[] = R"(C:\depot\dev\default.xml)";
- m_command.m_fstatResponse =
- R"(... depotFile //depot/dev/default.xml)" "\r\n"
- R"(... clientFile C:\depot\dev\default.xml)" "\r\n"
- R"(... isMapped)" "\r\n"
- R"(... headAction integrate)" "\r\n"
- R"(... headType text)" "\r\n"
- R"(... headTime 1454346715)" "\r\n"
- R"(... headRev 3)" "\r\n"
- R"(... headChange 147109)" "\r\n"
- R"(... headModTime 1452731919)" "\r\n"
- R"(... haveRev 3)" "\r\n"
- "\r\n"
- R"(... depotFile //depot/dev/default.font)" "\r\n"
- R"(... clientFile C:\depot\dev\default.font)" "\r\n"
- R"(... isMapped)" "\r\n"
- R"(... headAction branch)" "\r\n"
- R"(... headType text)" "\r\n"
- R"(... headTime 1479280355)" "\r\n"
- R"(... headRev 1)" "\r\n"
- R"(... headChange 317116)" "\r\n"
- R"(... headModTime 1478804078)" "\r\n"
- R"(... haveRev 1)" "\r\n"
- "\r\n";
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- AZStd::unordered_set<AZStd::string> requestFiles = { FileAPath, FileBPath };
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, requestFiles, bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_EQ(fileInfo.size(), 2);
- for (int i = 0; i < 2; ++i)
- {
- ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
- ASSERT_TRUE(fileInfo[i].IsManaged());
- }
- }
- TEST_F(PerforceComponentFixture, TestGetBulkFileInfo_MissingFile_Succeeds)
- {
- static constexpr char FileAPath[] = R"(C:\depot\dev\does-not-exist.txt)";
- static constexpr char FileBPath[] = R"(C:\depot\dev\does-not-exist-two.txt)";
- m_command.m_fstatErrorResponse =
- R"(C:\depot\dev\does-not-exist.txt - no such file(s).)" "\r\n"
- R"(C:\depot\dev\does-not-exist-two.txt - no such file(s).)" "\r\n"
- "\r\n";
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- AZStd::unordered_set<AZStd::string> requestFiles = { FileAPath, FileBPath };
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, requestFiles, bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_EQ(fileInfo.size(), 2);
- for (int i = 0; i < 2; ++i)
- {
- ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
- ASSERT_EQ(fileInfo[i].m_flags, AzToolsFramework::SourceControlFlags::SCF_Writeable); // Writable should be the only flag
- }
- }
- TEST_F(PerforceComponentFixture, TestGetBulkFileInfo_CompareWithGetFileInfo_ResultMatches)
- {
- static constexpr char FileAPath[] = R"(C:\depot\dev\default.font)";
- static constexpr char FstatResponse[] =
- R"(... depotFile //depot/dev/default.font)" "\r\n"
- R"(... clientFile C:\depot\dev\default.font)" "\r\n"
- R"(... isMapped)" "\r\n"
- R"(... headAction branch)" "\r\n"
- R"(... headType text)" "\r\n"
- R"(... headTime 1479280355)" "\r\n"
- R"(... headRev 1)" "\r\n"
- R"(... headChange 317116)" "\r\n"
- R"(... headModTime 1478804078)" "\r\n"
- R"(... haveRev 1)" "\r\n"
- "\r\n";
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AzToolsFramework::SourceControlFileInfo fileInfoSingle;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto singleCallback = [&callbackSignal, &result, &fileInfoSingle](bool success, AzToolsFramework::SourceControlFileInfo info)
- {
- result = success;
- fileInfoSingle = info;
- callbackSignal.release();
- };
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- AZStd::unordered_set<AZStd::string> requestFiles = { FileAPath };
- m_command.m_fstatResponse = FstatResponse;
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, requestFiles, bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- m_command.m_fstatResponse = FstatResponse;
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetFileInfo, FileAPath, singleCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_FALSE(fileInfo.empty());
- ASSERT_EQ(fileInfoSingle.m_flags, fileInfo[0].m_flags);
- }
- TEST_F(PerforceComponentFixture, Test_ExecuteEditBulk)
- {
- static constexpr char FileAPath[] = R"(C:\depot\dev\does-not-exist.txt)";
- static constexpr char FileBPath[] = R"(C:\depot\dev\default.font)";
- m_command.m_fstatErrorResponse =
- R"(C:\depot\dev\does-not-exist.txt - no such file(s).)" "\r\n"
- "\r\n";
- m_command.m_fstatResponse =
- R"(... depotFile //depot/dev/default.font)" "\r\n"
- R"(... clientFile C:\depot\dev\default.font)" "\r\n"
- R"(... isMapped)" "\r\n"
- R"(... headAction branch)" "\r\n"
- R"(... headType text)" "\r\n"
- R"(... headTime 1479280355)" "\r\n"
- R"(... headRev 1)" "\r\n"
- R"(... headChange 317116)" "\r\n"
- R"(... headModTime 1478804078)" "\r\n"
- R"(... otherOpen)" "\r\n"
- R"(... haveRev 1)" "\r\n"
- "\r\n";
- bool addCalled = false;
- bool editCalled = false;
- m_command.m_addCallback = [&addCalled]([[maybe_unused]] const AZStd::string& args)
- {
- addCalled = true;
- };
- m_command.m_editCallback = [this, &editCalled]([[maybe_unused]] const AZStd::string& args)
- {
- editCalled = true;
- m_command.m_fstatResponse =
- R"(... depotFile //depot/dev/does-not-exist.txt)" "\r\n"
- R"(... clientFile C:\depot\dev\does-not-exist.txt)" "\r\n"
- R"(... isMapped)" "\r\n"
- R"(... action add)" "\r\n"
- R"(... change default)" "\r\n"
- R"(... type text)" "\r\n"
- R"(... actionOwner unittest)" "\r\n"
- R"(... workRev 1)" "\r\n"
- "\r\n"
- R"(... depotFile //depot/dev/default.font)" "\r\n"
- R"(... clientFile C:\depot\dev\default.font)" "\r\n"
- R"(... isMapped)" "\r\n"
- R"(... headAction add)" "\r\n"
- R"(... headType text)" "\r\n"
- R"(... headTime 1557439413)" "\r\n"
- R"(... headRev 1)" "\r\n"
- R"(... headChange 902209)" "\r\n"
- R"(... headModTime 1556296348)" "\r\n"
- R"(... haveRev 1)" "\r\n"
- R"(... action edit)" "\r\n"
- R"(... change default)" "\r\n"
- R"(... type text)" "\r\n"
- R"(... actionOwner unittest)" "\r\n"
- R"(... workRev 1)" "\r\n"
- "\r\n";
- };
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- AZStd::unordered_set<AZStd::string> requestFiles = { FileAPath, FileBPath };
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEditBulk, requestFiles, true, bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_TRUE(addCalled);
- ASSERT_TRUE(editCalled);
- ASSERT_EQ(fileInfo.size(), 2);
- for (int i = 0; i < 2; ++i)
- {
- ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
- }
- }
- TEST_F(PerforceComponentFixture, Test_ExecuteEditBulk_CheckedOutByOther_Failure)
- {
- static constexpr char FileBPath[] = R"(C:\depot\dev\default.font)";
- m_command.m_fstatResponse =
- R"(... depotFile //depot/dev/default.font)" "\r\n"
- R"(... clientFile C:\depot\dev\default.font)" "\r\n"
- R"(... isMapped)" "\r\n"
- R"(... headAction branch)" "\r\n"
- R"(... headType text)" "\r\n"
- R"(... headTime 1479280355)" "\r\n"
- R"(... headRev 1)" "\r\n"
- R"(... headChange 317116)" "\r\n"
- R"(... headModTime 1478804078)" "\r\n"
- R"(... otherOpen)" "\r\n"
- R"(... haveRev 1)" "\r\n"
- "\r\n";
- bool addCalled = false;
- bool editCalled = false;
- m_command.m_addCallback = [&addCalled]([[maybe_unused]] const AZStd::string& args)
- {
- addCalled = true;
- };
- m_command.m_editCallback = [&editCalled]([[maybe_unused]] const AZStd::string& args)
- {
- editCalled = true;
- };
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- AZStd::unordered_set<AZStd::string> requestFiles = { FileBPath };
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEditBulk, requestFiles, false, bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_FALSE(result);
- ASSERT_FALSE(addCalled);
- ASSERT_FALSE(editCalled);
- }
- bool CreateDummyFile(const QString& fullPathToFile, QString contents = "")
- {
- QFileInfo fi(fullPathToFile);
- QDir fp(fi.path());
- fp.mkpath(".");
- QFile writer(fullPathToFile);
- if (!writer.open(QFile::WriteOnly))
- {
- return false;
- }
- {
- QTextStream ts(&writer);
- ts.setCodec("UTF-8");
- ts << contents;
- }
- return true;
- }
- TEST_F(PerforceComponentFixture, Test_ExecuteEditBulk_Local_Succeeds)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("fileA.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("fileB.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
- AZ::IO::SystemFile::SetWritable(path, false);
- ASSERT_FALSE(AZ::IO::SystemFile::IsWritable(path));
- }
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- AZStd::unordered_set<AZStd::string> requestFiles = { testPaths.begin(), testPaths.end() };
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestEditBulk, requestFiles, false, bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_EQ(fileInfo.size(), testPaths.size());
- for (int i = 0; i < testPaths.size(); ++i)
- {
- ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
- ASSERT_TRUE(fileInfo[i].HasFlag(AzToolsFramework::SourceControlFlags::SCF_Writeable));
- ASSERT_TRUE(AZ::IO::SystemFile::IsWritable(testPaths[i]));
- }
- }
- TEST_F(PerforceComponentFixture, Test_ExecuteRenameBulk_Local_Succeeds)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
- }
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- auto from = tempDir.filePath("o*e/*o/three/file*.txt");
- auto to = tempDir.filePath("o*e/*o/three/fileRenamed*.png");
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestRenameBulk, from.toUtf8().constData(), to.toUtf8().constData(), bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_EQ(fileInfo.size(), testPaths.size());
- ASSERT_FALSE(AZ::IO::SystemFile::Exists(fullPathA.c_str()));
- ASSERT_FALSE(AZ::IO::SystemFile::Exists(fullPathB.c_str()));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(tempDir.filePath("one/two/three/fileRenamedA.png").toUtf8().constData()));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(tempDir.filePath("one/two/three/fileRenamedB.png").toUtf8().constData()));
- for (int i = 0; i < testPaths.size(); ++i)
- {
- ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
- ASSERT_TRUE(fileInfo[i].HasFlag(AzToolsFramework::SourceControlFlags::SCF_Tracked));
- }
- }
- TEST_F(PerforceComponentFixture, Test_ExecuteRenameBulk_Local_MismatchedWildcards_Fails)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
- }
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- auto from = tempDir.filePath("o*e/*o/three/file*.txt");
- auto to = tempDir.filePath("o*e/two/three/fileRenamed*.png");
- AZ_TEST_START_TRACE_SUPPRESSION;
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestRenameBulk, from.toUtf8().constData(), to.toUtf8().constData(), bulkCallback);
- WaitForSourceControl(callbackSignal);
- AZ_TEST_STOP_TRACE_SUPPRESSION(1);
- ASSERT_FALSE(result);
- ASSERT_EQ(fileInfo.size(), 0);
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(fullPathA.c_str()));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(fullPathB.c_str()));
- ASSERT_FALSE(AZ::IO::SystemFile::Exists(tempDir.filePath("one/two/three/fileRenamedA.png").toUtf8().constData()));
- ASSERT_FALSE(AZ::IO::SystemFile::Exists(tempDir.filePath("one/two/three/fileRenamedB.png").toUtf8().constData()));
- }
- TEST_F(PerforceComponentFixture, Test_ExecuteDeleteBulk_Local_Succeeds)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
- }
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- auto from = tempDir.filePath("o*e/*o/three/file*.txt");
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::RequestDeleteBulk, from.toUtf8().constData(), bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_EQ(fileInfo.size(), testPaths.size());
- ASSERT_FALSE(AZ::IO::SystemFile::Exists(fullPathA.c_str()));
- ASSERT_FALSE(AZ::IO::SystemFile::Exists(fullPathB.c_str()));
- for (int i = 0; i < testPaths.size(); ++i)
- {
- ASSERT_EQ(fileInfo[i].m_status, AzToolsFramework::SourceControlStatus::SCS_OpSuccess);
- ASSERT_FALSE(fileInfo[i].HasFlag(AzToolsFramework::SourceControlFlags::SCF_Tracked));
- }
- }
- TEST_F(PerforceComponentFixture, Test_GetFiles_Succeeds)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
- }
- auto result = AzToolsFramework::LocalFileSCComponent::GetFiles(tempDir.filePath("one/tw*/fileA.txt").toUtf8().constData());
- ASSERT_EQ(result.size(), 0);
- result = AzToolsFramework::LocalFileSCComponent::GetFiles(tempDir.filePath("on...").toUtf8().constData());
- ASSERT_EQ(result.size(), 2);
- }
- TEST_F(PerforceComponentFixture, Test_GetFiles_StarWildcardAtEnd_OnlyReturnsFirstFile)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("one/file1.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("one/folder/file1.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
- }
- auto result = AzToolsFramework::LocalFileSCComponent::GetFiles(tempDir.filePath("one/f*").toUtf8().constData());
- ASSERT_EQ(result.size(), 1);
- }
- TEST_F(PerforceComponentFixture, Test_GetFiles_MultipleWildcardsAndWildcardAtEnd_Succeeds)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- ASSERT_TRUE(AZ::IO::SystemFile::Exists(path));
- }
- auto result = AzToolsFramework::LocalFileSCComponent::GetFiles(tempDir.filePath("o*e/tw*/...").toUtf8().constData());
- ASSERT_EQ(result.size(), 2);
- }
- TEST_F(PerforceComponentFixture, Test_GetBulkFileInfo_Wildcard_Succeeds)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- }
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- AZStd::unordered_set<AZStd::string> paths = { tempDir.filePath("o*e/*o/three/file*.txt").toUtf8().constData() };
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, paths, bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_EQ(fileInfo.size(), testPaths.size());
- using namespace AzToolsFramework;
- for (int i = 0; i < testPaths.size(); ++i)
- {
- ASSERT_EQ(fileInfo[i].m_status, SCS_OpSuccess);
- ASSERT_EQ(fileInfo[i].m_flags, SCF_Writeable | SCF_OpenByUser | SCF_Tracked);
- }
- }
- TEST_F(PerforceComponentFixture, Test_GetBulkFileInfo_MultipleFiles_Succeeds)
- {
- AzToolsFramework::SourceControlConnectionRequestBus::Broadcast(&AzToolsFramework::SourceControlConnectionRequestBus::Events::EnableSourceControl, false);
- QTemporaryDir tempDir;
- AZStd::string fullPathA = tempDir.filePath("one/two/three/fileA.txt").toUtf8().constData();
- AZStd::string fullPathB = tempDir.filePath("one/two/three/fileB.txt").toUtf8().constData();
- AZStd::vector<const char*> testPaths = { fullPathA.c_str(), fullPathB.c_str() };
- for (const char* path : testPaths)
- {
- ASSERT_TRUE(CreateDummyFile(path));
- }
- AZStd::binary_semaphore callbackSignal;
- bool result = false;
- AZStd::vector<AzToolsFramework::SourceControlFileInfo> fileInfo;
- auto bulkCallback = [&callbackSignal, &result, &fileInfo](bool success, AZStd::vector<AzToolsFramework::SourceControlFileInfo> info)
- {
- result = success;
- fileInfo = info;
- callbackSignal.release();
- };
- AZStd::unordered_set<AZStd::string> paths = { fullPathA, fullPathB };
- AzToolsFramework::SourceControlCommandBus::Broadcast(&AzToolsFramework::SourceControlCommandBus::Events::GetBulkFileInfo, paths, bulkCallback);
- WaitForSourceControl(callbackSignal);
- ASSERT_TRUE(result);
- ASSERT_EQ(fileInfo.size(), testPaths.size());
- using namespace AzToolsFramework;
- for (int i = 0; i < testPaths.size(); ++i)
- {
- ASSERT_EQ(fileInfo[i].m_status, SCS_OpSuccess);
- ASSERT_EQ(fileInfo[i].m_flags, SCF_Writeable | SCF_OpenByUser | SCF_Tracked);
- }
- }
- }
|