void TestLockDocument::TestLockAttachment() { DocProviderWorker objWorker; LockManager docLock; CStdString sDocID(DocumentID::GetDocProviderId() + TEST_DIRECTORY + TEST_DOC + _T(".doc")); DocumentID docID(sDocID); CStdString szDummyUser(_T("HighHouseShadow")); CStdString sLockFileName(docID.GetLockFileName(szDummyUser, false)); WSDocNonCom wsDoc; objWorker.GetDocument(sDocID,NULL,wsDoc); HRESULT hrLock = docLock.CreateLock(sDocID, szDummyUser); if(FAILED(hrLock)) { CStdString szErr; szErr.Format(_T("CreateLock returned a Failure Error code - %08x"),hrLock); assertMessage(false, szErr); } if (_taccess(sLockFileName, 0) == -1) { assertMessage(false, _T("We didn't create a lock file as HighHouseShadow")); } HRESULT hrUnlock = docLock.RemoveLock(sDocID,szDummyUser); if(FAILED(hrUnlock)) { CStdString szErr; szErr.Format(_T("CreateLock returned a Failure Error code - %08x"),hrUnlock); assertMessage(false,szErr); } if (_taccess(sLockFileName, 0) != -1) { assertMessage(false, _T("We didn't remove the HighHouseShadow lock")); } }
void TestLockDocument::TestAlreadyLockedByOther() { DocProviderWorker objWorker; CStdString sDocID(DocumentID::GetDocProviderId() + TEST_DIRECTORY + TEST_DOC + _T(".doc")); DocumentID docID(sDocID); CStdString sLockFileName(docID.GetLockFileName(_T("apple"), false)); WSDocNonCom wsDoc; LockManager docLock; objWorker.GetDocument(sDocID, 0, wsDoc); docLock.CreateLock(sDocID, _T("apple")); if (_taccess(sLockFileName, 0) == -1) { assertMessage(false, _T("Unable to create lock file")); } assertTest(objWorker.LockDocument(sDocID, LOCK_DOCUMENT) == E_DOCUMENT_LOCKED_BY_ANOTHER); assertMessage(docLock.RemoveLock(docID, _T("apple")) == S_OK, _T("Failed to unlock document at end of test")); }
void TestCloseDocument::TestFailIfLockedByOther() { DocProviderWorker objWorker; WSDocNonCom wsDoc; DocumentID docTarget(DocumentID::GenerateIdFromFilePath(sTestOriginalFileName)); wsDoc.SetDescription(docTarget.GetDescription()); wsDoc.SetLocalFile(docTarget.GetWorkingFile()); assertTest(objWorker.ImportDocument(wsDoc, false) == S_OK); m_wsImportedDoc = wsDoc; LockManager lckMngr; assertTest(lckMngr.CreateLock(wsDoc.GetDocId(),_T("poptart")) == S_OK); assertTest(objWorker.CloseDocument(wsDoc,0) == S_OK); wsDoc.SetFlags(wsDoc.GetFlags()|DOCUMENT_LOCKED_BY_US); assertTest(objWorker.CloseDocument(wsDoc,0) == E_DOCUMENT_LOCKED_BY_ANOTHER); lckMngr.RemoveLock(wsDoc.GetDocId(),_T("poptart")); }