Esempio n. 1
0
void TestPublishWordUsingCOM(const CStdString& sTestFile, const CStdString& sResultFile, IDispatchPtr spWordInstance /*= 0*/, bool bExpectingFailure /*= false*/, const TCHAR* range /* = 0 */, long pageType /* = 0 */)
{
   ::DeleteFile(sResultFile);

   HRESULT hr = E_FAIL;
   if (spWordInstance == 0)
      hr = g_spDocumentPublisher->raw_Publish(_bstr_t(sTestFile),_bstr_t(sResultFile));
   else
      hr = g_spDocumentPublisher->raw_PublishWithWord(_bstr_t(sTestFile),_bstr_t(sResultFile), spWordInstance, _bstr_t(range), pageType);

   if (!bExpectingFailure)
   {
		if (FAILED(hr))      
         throw Workshare::Com::ComException(_T("Failed to publish Word file"), hr, g_spDocumentPublisher);
      

      CFileFormatInfo FileFormatInfo(sResultFile);
      CStdString sMsg;
      sMsg.Format(_T("'%s' test file not published to PDF format!"), sTestFile.c_str());
		
		if (!FileFormatInfo.IsPDFFile())
			throw CppUnitException(sMsg.c_str());
   }
   else
		if (SUCCEEDED(hr))
			throw CppUnitException(_T("Expected publishing to fail, and it didn't"));
}
void CTestRTFTablePostProcessor::CompareAndCheckResults(CStdString szFile1, CStdString szFile2, int iAnchor, int iTablesExpected)
{
	CRtfDocumentChainBuilder builder;

	builder.m_Options.SetTemplate( GET_TEST_FILE_PATH("template.rtf"));
	builder.PrepareRTFFileMembers();
	builder.ProcessOptions();
	builder.EnableHashCodes ();
	HRESULT hr = builder.AssembleRTFFileCollections(AutoInputFileData4Tests( szFile1), AutoInputFileData4Tests( szFile2));
	if(FAILED(hr))
		throw CppUnitException(_T("failed to read one of the input files"));

	hr = builder.BuildChains();
	if(FAILED(hr))
		throw CppUnitException(_T("failed to read one of the input files"));

	builder.PrepareForCompareChains();
	builder.CompareChains(builder.m_pAnchor[0], builder.m_pAnchor[1]);
	builder.FlagActualComparisonComplete();
	builder.Finalise();

	CChainElement* pIter = builder.m_pAnchor[iAnchor];

	bool bFoundJoin = false;
	int iTablesFound = CheckResults(builder, pIter, bFoundJoin);
	assertMessage( iTablesExpected == iTablesFound, _T("Did not find tables it should have"));
	assertMessage(bFoundJoin, _T("should have found a joined table"));
}
void TestRsidSensitiveCompare::DoTheCompareAndCheckResults(bool bUseRsids, std::vector<bool> vecWhichParasExpectedMatched)
{
	CStdString szFile1 = GET_TEST_FILE_PATH("brownfox_original.rtf");
	CStdString szFile2 = GET_TEST_FILE_PATH("brownfox_modified_inserted 4th and last.rtf");

	CRtfDocumentChainBuilder builder;

	builder.m_Options.SetTemplate( GET_TEST_FILE_PATH("template.rtf"));
	builder.m_Options.Flags.m_bSuppressRsidSensitiveComparison = !bUseRsids;
	builder.PrepareRTFFileMembers();
	builder.ProcessOptions();
	builder.EnableHashCodes ();
	HRESULT hr = builder.AssembleRTFFileCollections(AutoInputFileData4Tests( szFile1), AutoInputFileData4Tests( szFile2));
	if(FAILED(hr))
		throw CppUnitException(_T("failed to read one of the input files"));

	hr = builder.BuildChains();
	if(FAILED(hr))
		throw CppUnitException(_T("failed to read one of the input files"));

	builder.PrepareForCompareChains();
	builder.CompareChains(builder.m_pAnchor[0], builder.m_pAnchor[1]);
	builder.FlagActualComparisonComplete();
	builder.Finalise();

	CChainElement* pIter = builder.m_pAnchor[1];
	int iCount = 0;
	while (pIter)
	{
		if (pIter->GetType() == ROT_String)
		{
			CWideString cws;
			pIter->GetText(cws);
			if (cws.GetLength() == 228) 
			{
				if (vecWhichParasExpectedMatched[iCount])
				{
					assertMessage(pIter->IsMatched() && pIter->GetBridge(), _T("expected that one to be matched"));
				}
				else
				{
					assertMessage(!pIter->IsMatched() && !pIter->IsMoved() && !pIter->IsDeleted(), _T("expected that occurrence to be inserted"));
				}
				iCount++;
			}
		}
		pIter=pIter->GetNext();

	}

	assertMessage(iCount == (x64_int_cast)vecWhichParasExpectedMatched.size(), _T("should have found 12 total lines of interest"));



}
Esempio n. 4
0
void NotesHelper::InitialiseMessageAttachments(const LNMailMessage& message)
{
	std::string wordDocument(Workshare::Conversions::W22A(TEST_DOC_PATH.c_str()));
	wordDocument.append("Test.doc");
	LNSTATUS status = message.CreateAttachment(wordDocument.c_str(), "Test.doc");
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to create an attachment of the note"), __LINE__, _T(__FILE__));	

	std::string excelDocument(Workshare::Conversions::W22A(TEST_DOC_PATH.c_str()));
	excelDocument.append("Test.xls");
	status = message.CreateAttachment(excelDocument.c_str(), "Test.xls");
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to create an attachment of the note"), __LINE__, _T(__FILE__));	
}
Esempio n. 5
0
CStdString TestLogger::FileToString(CStdString sFile)
{
	std::ifstreamt fin(_tfopen(sFile.c_str(),_T("rb")));

	if(fin.fail() || !fin.is_open())
	{
		CStdString sErr(_T("Cannot open file : "));
		sErr += sFile;
		throw CppUnitException(sErr);
	}

	CStdString sString;
	
	for(char c = '\0';;)
	{
		c = fin.get();
	
		if( c == EOF )
			break;

		sString += c;
	}

	fin.close();
	return sString;
}
Esempio n. 6
0
void TestThreadSafety::TestMultiThreads()
{
	for (int i=0; i<2; i++)
	{
		ComparisonContext cContext;
		// The next two lines are important - they make sure the test files haven't gone walkies even
		// if you're building singlethread
		GET_TEST_FILE_PATH("Original.doc");
		GET_TEST_FILE_PATH("Modified.doc"); 
#ifdef MULTITHREAD

		HANDLE handles[THREAD_COUNT];
		for (int i=0; i<THREAD_COUNT; i++)
		{
			handles[i] = StartWorkerThread(i);
		}

		for (int i=0; i<THREAD_COUNT; i++)
		{
			ResumeThread(handles[i]);
		}

		if (WaitForMultipleObjectsEx(THREAD_COUNT, handles, TRUE, 120000, FALSE) != WAIT_OBJECT_0)
			throw CppUnitException(_T("not all of the threads finished within the timeout"));

		for (int i=0; i<THREAD_COUNT; i++)
		{
			DWORD dwExitCode;
			if (!GetExitCodeThread(handles[i], &dwExitCode))
				throw CppUnitException(_T("failed to get the thread exit code"));

			if (dwExitCode != 0)
				throw CppUnitException(_T("one of the threads failed"));
		}

		for (int i=1; i<THREAD_COUNT; i++)
		{
			assertFilesEqual(CreateRedlineName(0), CreateRedlineName(i));
		}
	}

#elif defined SINGLETHREAD
		throw SkipTestException(_T("Can't test multithreading 'cos we weren't built with it enabled"));
#else
#error ("must be one or the other")
#endif
	}
Esempio n. 7
0
// Check for a failed general assertion 
void TestCase::assertImplementation (bool          condition,
                                     std::string   conditionExpression,
                                     long          lineNumber,
                                     std::string   fileName)
{ 
    if (!condition) 
        throw CppUnitException (conditionExpression, lineNumber, fileName); 
}
void SetRequiredWordOptions()
{
	if(g_spWordApplication == 0 || g_spWordInstanceManager == 0)
		throw CppUnitException(_T("Cannot set required Word options because the global Word instance manager is not yet available"), __LINE__, _T(__FILE__));

	_variant_t vtDocType((long)Word::wdNewBlankDocument);
	Word::_DocumentPtr spTempDoc = g_spWordApplication->Documents->Add(&vtMissing, &vtMissing, &vtDocType, &vtMissing);
	g_spWordApplication->ActiveWindow->View->ShowFieldCodes = VARIANT_FALSE;
	g_spWordInstanceManager->CloseDocument(spTempDoc);
}
Esempio n. 9
0
void TestXMLProperties::TestConstructionExistingFile()
{
	try
	{
		XMLProperties xmlProperties(TEST_RESULT_FILE); 
	}
	catch(...)
	{
		throw CppUnitException(L"Failed to construct the XMLProperties class");
	}
}
Esempio n. 10
0
DocumentHelper::DocumentHelper(MetawallBackEnd::IMWHostInstanceManagerPtr spInstanceManager, const TCHAR* filename, bool SaveOnClose)
: m_SaveOnClose(VARIANT_FALSE), m_spInstanceManager(spInstanceManager)
{
	if(SaveOnClose)
		m_SaveOnClose = VARIANT_TRUE;
	
	m_spOfficeDocument = m_spInstanceManager->OpenDocument(filename, VARIANT_FALSE);
	if(m_spOfficeDocument == 0)
		throw CppUnitException(_T("Failed to instanciate [m_spOfficeDocument]"));
	
	m_spProtectApplication = CreateApplicationObject();
	if(m_spProtectApplication == 0)
		throw CppUnitException(_T("Failed to instanciate [m_spProtectApplication]"));

	m_spProtectDocuments = m_spProtectApplication->Documents;
	if(m_spProtectDocuments == 0)
		throw CppUnitException(_T("Failed to instanciate [m_spProtectDocuments]"));
	
	m_spProtectDocument = m_spProtectDocuments->Open(static_cast<IDispatch*>(m_spOfficeDocument));
	if(m_spProtectDocument == 0)
		throw CppUnitException(_T("Failed to instanciate [m_spProtectDocument]"));
}
Esempio n. 11
0
void TestXMLProperties::TestConstructionNoFile()
{
	try
	{
		XMLProperties xmlProperties(TEST_RESULT_NEW_FILE);
	}
	catch(...)
	{
		throw CppUnitException(L"Failed to construct the XMLProperties class");
	}

	assertMessage(true == CompareFiles(TEST_NEW_FILE, TEST_RESULT_NEW_FILE), L"The properties file was not created correctly");
}
Esempio n. 12
0
HANDLE NotesHelper::CreateNotesMessage(const std::tstring& toRecipients, const std::tstring& ccRecipients, const std::tstring& bccRecipients, const std::tstring& subject, const std::tstring& body, const std::tstring& from)
{
	InitialiseSession();
	NOTEHANDLE hMemo = 0;
	if(NOERROR != NSFNoteCreate(m_hMailBox, &hMemo))
		throw CppUnitException(_T("Failed to create a note"), __LINE__, _T(__FILE__));	
	
	try
	{
		SetMemoText(hMemo, FIELD_FORM, MAIL_MEMO_FORM);
		SetMemoText(hMemo, MAIL_ENTERSENDTO_ITEM, Workshare::Conversions::T22A(toRecipients.c_str()));
		SetMemoText(hMemo, MAIL_ENTERCOPYTO_ITEM, Workshare::Conversions::T22A(ccRecipients.c_str()));
		SetMemoText(hMemo, MAIL_ENTERBLINDCOPYTO_ITEM, Workshare::Conversions::T22A(bccRecipients.c_str()));
		SetMemoText(hMemo, MAIL_FROM_ITEM, Workshare::Conversions::T22A(from.c_str()));	
		SetMemoText(hMemo, MAIL_SUBJECT_ITEM, Workshare::Conversions::T22A(subject.c_str()));	
		SetMemoText(hMemo, MAIL_BODY_ITEM, Workshare::Conversions::T22A(body.c_str()));	
		SetMemoText(hMemo, MAIL_DELIVERYPRIORITY_ITEM, "Normal");	
		SetMemoText(hMemo, MAIL_DELIVERYREPORT_ITEM, "Basic");	
		SetMemoText(hMemo, MAIL_RETURNRECEIPT_ITEM, "No");	
		
		TIMEDATE tdCurrent;
		OSCurrentTIMEDATE(&tdCurrent);

		SetMemoDate(hMemo, MAIL_COMPOSEDDATE_ITEM, tdCurrent);
		SetMemoDate(hMemo, MAIL_POSTEDDATE_ITEM, tdCurrent);

		STATUS status = NSFNoteUpdate(hMemo, UPDATE_FORCE);
		if(NOERROR != status)
			throw CppUnitException(_T("Failed to update the note"), __LINE__, _T(__FILE__));	

		return hMemo; 
	}
	catch(...)
	{
		NSFNoteClose(hMemo);
		return 0;
	}
}
Esempio n. 13
0
void NotesHelper::InitialiseSession()
{
	if(m_notesInitialised)
		return;

	if (0 != NotesInit())
		throw CppUnitException(_T("Failed to Initialise Notes runtime"), __LINE__, _T(__FILE__));     

	char serverName[1024] = {0};
	if(TRUE != OSGetEnvironmentString("MailServer", serverName, sizeof(serverName)))
		throw CppUnitException(_T("Failed to obtain the Lotus Domino Mail Server"), __LINE__, _T(__FILE__)); 

	char szMailFileName[MAXUSERNAME + 1];
	strcpy(szMailFileName, MAILBOX_NAME);
	char szMailBoxPath[MAXPATH + 1] = {0};    

	OSPathNetConstruct(0, serverName, szMailFileName, szMailBoxPath);
	STATUS error = NSFDbOpen(szMailBoxPath, &m_hMailBox);
	if (NOERROR != error)
		throw CppUnitException(_T("Failed to open mail.box"), __LINE__, _T(__FILE__));	

	m_notesInitialised = true;
}
Esempio n. 14
0
void NotesHelper::InitialiseRTFAttachments(const LNMailMessage& message)
{
	LNRichText body;
	LNSTATUS status = message.GetBody(&body);
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to get the body of the message"), __LINE__, _T(__FILE__));	
	
	std::string pptDocument(Workshare::Conversions::W22A(TEST_DOC_PATH.c_str()));
	pptDocument.append("Test.ppt");
		
	LNRTCursor cursor;
	status = body.GetEndCursor(&cursor);
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to get the end cursor of the body"), __LINE__, _T(__FILE__));	

	status = body.Append("Start: ppt<", TRUE);
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to append text to the body"), __LINE__, _T(__FILE__));	

	status = body.GetEndCursor(&cursor);		
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to get the end cursor of the body"), __LINE__, _T(__FILE__));	

	status = body.CreateAttachment(pptDocument.c_str(), &cursor, "Test.ppt", FALSE);
	if(NOERROR != status)
	{
		char errorBuf[LNERROR_MESSAGE_LENGTH] = {};
		LNGetErrorMessage(status, errorBuf);
		throw CppUnitException(Workshare::Conversions::A22W(errorBuf), __LINE__, _T(__FILE__));	
	}

	std::string txtDocument(Workshare::Conversions::W22A(TEST_DOC_PATH.c_str()));
	txtDocument.append("Test.txt");
	
	status = body.GetEndCursor(&cursor);		
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to get the end cursor of the body"), __LINE__, _T(__FILE__));	

    body.Append(">, txt<", TRUE);
    status = body.GetEndCursor(&cursor);		
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to get the end cursor of the body"), __LINE__, _T(__FILE__));	

    status = body.CreateAttachment(txtDocument.c_str(), &cursor, "Test.txt", FALSE);
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to create an attachment in the RTF body of the note"), __LINE__, _T(__FILE__));	
}
Esempio n. 15
0
void DLLSetup()
{	
	MetawallBackEnd::IMWHostInstanceManagerPtr spWordInstanceManager(_T("WordInstanceManager.Controller"));
	if(spWordInstanceManager == 0)
		throw CppUnitException(_T("Failed to create an instance of [WordInstanceManager.Controller]"), __LINE__, _T(__FILE__));

	Word::_ApplicationPtr spWordApplication = spWordInstanceManager->HostApplication;  

	g_spWordInstanceManager = spWordInstanceManager;
	g_spWordApplication = spWordApplication;

	SetRequiredWordOptions();

	g_oldCustProps = Workshare::OptionApi::GetString(L"ExcludeCustomProperties");
}
Esempio n. 16
0
void NotesHelper::CreateNotesMessage(const std::tstring& recipients, const std::tstring& subject, const std::tstring& body, LNMailMessage &message)
{
	LNSTATUS status = Session::Instance()->GetNotesSession().CreateMailMessage(&message);
	if(NOERROR != status)
	{
		std::vector<char> errorbuffer(LNERROR_MESSAGE_LENGTH);
		LNINT charCount = LNGetErrorMessage(status, &errorbuffer[0]);
		throw CppUnitException(std::tstring(errorbuffer.begin(), errorbuffer.begin() + charCount), __LINE__, _T(__FILE__));	
	}

	message.SendTo(Workshare::Conversions::W22LNString(recipients.c_str()));
	message.SetSubject(Workshare::Conversions::W22LNString(subject.c_str()));
		
	LNRichText rtBody;
	message.GetBody(&rtBody);
	rtBody.Append(Workshare::Conversions::W22LNString(body.c_str()));
}
Esempio n. 17
0
void TestPublishExcelUsingCOM(const CStdString& sResultFile, IDispatchPtr spExcelInstance, long from, long to)
{
   ::DeleteFile(sResultFile);

   HRESULT hr = E_FAIL;
   hr = g_spDocumentPublisher->raw_PublishWithExcel(_bstr_t(sResultFile), spExcelInstance, from, to);

	if (FAILED(hr))      
      throw Workshare::Com::ComException(_T("Failed to publish Excel file"), hr, g_spDocumentPublisher);
   

   CFileFormatInfo FileFormatInfo(sResultFile);
   CStdString sMsg;
   sMsg.Format(_T("'%s' test file not published to PDF format!"), sResultFile.c_str());
	
	if (!FileFormatInfo.IsPDFFile())
		throw CppUnitException(sMsg.c_str());
}
Esempio n. 18
0
void AppTests::RunAppEx(const TCHAR* sPathBase, const TCHAR* sAppName)
{
	std::tstring sAppPath = sPathBase;

#ifdef _DEBUG
	sAppPath+=_T("\\debug\\");
#else
	sAppPath+=_T("\\release\\");
#endif

	sAppPath+=sAppName;

	int iResult = RunApp(sAppPath.c_str());

	RetCodeDecoder rd(iResult);
	
	if (rd.HadErrorLoading())
	{
		std::tstring sMessage;
		sMessage = _T("Fatal error running ");
		sMessage+=sAppName;
		sMessage+=_T(" unit tests. Perhaps TestRunner.dll could not be loaded?");
		throw new CppUnitException(sMessage,CPPUNIT_UNKNOWNLINENUMBER,sAppName);
	}
	
	if (rd.ErrorCount()>0)
	{
		g_iAppTestFailureCount = rd.ErrorCount()-1;
		g_iAppTestCount = rd.TestCount()-1;

		if (g_iAppTestCount<0) g_iAppTestCount = 0;

		TCHAR sBuf[128];
		
		_stprintf(sBuf,_T("%d tests failed in %s unit tests. Run app with /RunTests to view details."),rd.ErrorCount(), sAppName);
		
		throw CppUnitException(sBuf,CPPUNIT_UNKNOWNLINENUMBER,sAppName);
	}

	g_iAssertionCount = rd.AssertionCount();

	if (rd.TestCount()>0)
		g_iAppTestCount = rd.TestCount() - 1;
}
Esempio n. 19
0
void TestWordPerformance::setUp()
{
	RunningProcesses processes;
	if (processes.AreUnexpectedProcessesStillInMemory())
		throw CppUnitException(_T("Winword still in memory"));
}
Esempio n. 20
0
void NotesHelper::SetMemoDate(const HANDLE noteHandle, const std::string &field, const TIMEDATE &date)
{
	STATUS status = NSFItemSetTime(noteHandle, field.c_str(), &date);
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to set the note Form field"), __LINE__, _T(__FILE__));	
}
Esempio n. 21
0
void NotesHelper::SetMemoText(const HANDLE noteHandle, const std::string &field, const std::string data)
{
	STATUS status = NSFItemSetText(noteHandle, field.c_str(), data.c_str(), MAXWORD);
	if(NOERROR != status)
		throw CppUnitException(_T("Failed to set the note Form field"), __LINE__, _T(__FILE__));	
}
Esempio n. 22
0
void TestCase::loop2assertImplementation(bool condition, const std::string& conditionExpression, long lineNumber, long data1lineNumber, long data2lineNumber, const std::string& fileName)
{
    if (!condition)
        throw CppUnitException(conditionExpression, lineNumber, data1lineNumber, data2lineNumber, fileName);
}
Esempio n. 23
0
void TestCase::assertNull(const void* pointer, const std::string& pointerExpression, long lineNumber, const std::string& fileName)
{
	if (pointer != NULL)
		throw CppUnitException(pointerExpression + " must be NULL", lineNumber, fileName);
}
Esempio n. 24
0
void TestCase::fail (const std::string& message, long lineNumber, const std::string& fileName)
{
	throw CppUnitException(std::string("fail: ") + message, lineNumber, fileName);
}