Пример #1
0
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"));
	}
}
Пример #2
0
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"));	
}
Пример #3
0
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"));
}
Пример #4
0
void TestLockDocument::TestLockNonExistentAttachment()
{
	DocProviderWorker	objWorker;
	CStdString			sDocID(DocumentID::GetDocProviderId() + TEST_DIRECTORY + TEST_DOC _T(".doc") + _T("?attach.xdf"));
	CStdString			sLockFileName(TEST_DIRECTORY + TEST_DOC _T(".doc") _T("." TEST_DMS_EXT _T("\\Version 1\\attach.xdf_Bones.lock")));
	CStdString			sFile(_T("c:\\Not\\here.doc"));

	::DeleteFile(sFile.c_str());
	::DeleteFile(sLockFileName.c_str());

	WSDocNonCom			wsDoc;
	LockManager			docLock;
	const CStdString	sUsername(_T("Bones"));

	HRESULT hrLock = docLock.CreateLock(sDocID, sUsername);

	if(SUCCEEDED(hrLock))
		assertMessage(false,_T("Reported Succeeded in creating lock on non existent file"));

	if (_taccess(sLockFileName, 0) != -1 )
	{
		assertMessage(false, _T("Lock file exists for a non existent document"));
	}	
}