int _tmain(int argc, _TCHAR* argv[]) { if (argc != 3) { printf("Testing failed - Not enough parameters passed\n"); printf(" please pass two documents as parameters\n"); return -1; } CoInitialize(NULL); try { TestDiscoverToFile(argv[1]); printf("Discover to file test complete\n"); TestPDF(argv[1]); printf("PDF test complete\n"); TestCompare(argv[1], argv[2]); printf("Compare Test Complete\n"); TestDiscover(argv[1]); printf("Discover Test Complete\n"); TestRedact(argv[1]); printf("Redact test complete\n"); TestClean(argv[1]); printf("Clean test complete\n"); } catch (_com_error& ex) { printf("Testing failed - COM ERROR %x\n", ex.Error()); CoUninitialize(); return -1; } catch (std::exception& ex) { printf("Testing failed\n"); printf(ex.what()); printf("\n"); CoUninitialize(); return -1; } catch (...) { printf("Testing failed\n"); CoUninitialize(); return -1; } CoUninitialize(); return 0; }
int main( int argc, char *argv[] ) { #ifdef __SW_BW FILE *my_stdout; my_stdout = freopen( "tmp.log", "a", stdout ); if( my_stdout == NULL ) { fprintf( stderr, "Unable to redirect stdout\n" ); exit( -1 ); } #endif /*** Initialize ***/ strcpy( ProgramName, strlwr( argv[0] ) ); /* store filename */ /*** Test various functions ***/ TestCompare(); /* compare stuff */ TestMove(); /* moving data about */ TestCase(); /* upper/lowercase stuff */ TestSearch(); /* searching stuff */ TestSubstring(); /* substring stuff */ TestToken(); /* tokenizing stuff */ TestLocale(); /* locale stuff */ TestError(); /* error string stuff */ TestFormatted(); /* formatted I/O stuff */ TestBounded(); /* bounded string stuff */ #ifdef __X86__ TestCompareF(); TestMoveF(); TestCaseF(); TestSearchF(); TestSubstringF(); TestTokenF(); #endif /*** Print a pass/fail message and quit ***/ if( NumErrors != 0 ) { printf( "%s: FAILURE (%d errors).\n", ProgramName, NumErrors ); return( EXIT_FAILURE ); } printf( "Tests completed (%s).\n", strlwr( argv[0] ) ); #ifdef __SW_BW fprintf( stderr, "Tests completed (%s).\n", strlwr( argv[0] ) ); fclose( my_stdout ); _dwShutDown(); #endif return( 0 ); }
/*---------------------------------------------------------------------------------------------- Perform some tests on the LgCollatingEngine class. Return S_OK if all tests succeed, or an appropriate COM error code. ----------------------------------------------------------------------------------------------*/ HRESULT TestCollatingEngine::Run() { HRESULT hr; // WarnHr(E_FAIL); #ifdef OLD_SOURCE_TREE // Make a collater for English. Initialize it the standard way with a moniker. IClassInitMonikerPtr qcim; hr = qcim.CreateInstance(CLSID_ClassInitMoniker); WarnHr(hr); int lid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); hr = qcim->InitNew(CLSID_LgSystemCollater, (const BYTE *)&lid, isizeof(lid)); WarnHr(hr); IBindCtxPtr qbc; hr = ::CreateBindCtx(NULL, &qbc); WarnHr(hr); hr = qcim->BindToObject(qbc, NULL, IID_ILgCollatingEngine, (void **) &m_qcoleng); WarnHr(hr); #endif // def OLD_SOURCE_TREE // ## ILgFontManagerPtr qfm; // ## qfm.CreateInstance(CLSID_LgFontManager); try { m_qcoleng.CreateInstance(CLSID_LgSystemCollater); } catch (Throwable & thr) { return thr.Error(); } catch (...) { return WarnHr(E_FAIL); } // Create sort keys for some strings and use them. StrUni stuValBlank = L""; StrUni stuValSpace = L" a"; StrUni stuValA = L"a"; StrUni stuValB = L"b"; StrUni stuValAUpper = L"A"; StrUni stuValAnd = L"and"; StrUni stuValAny = L"any"; StrUni stuValAndUpper = L"And"; StrUni stuValPunct = L";(* #([/"; // REVIEW LarsH #define FIXED_BUG_173 1 #ifdef FIXED_BUG_173 { IgnoreWarnings iw; hr = m_qcoleng->Compare(stuValB.Bstr(), stuValA.Bstr(), fcoDefault, NULL); if (SUCCEEDED(hr)) Failure("Compare() with NULL return ptr should have failed"); } #endif int nRes = -1; // NULL sbstrs are valid, but the CollatingOption isn't. // REVIEW LarsH: // Are invalid CollatingOptions are supposed to be ignored, or answered with an error? { IgnoreWarnings iw; hr = m_qcoleng->Compare(NULL, stuValA.Bstr(), (enum LgCollatingOptions)37, &nRes); if (!FAILED(hr)) Failure("get_SortKey with invalid option should have failed."); // WarnHr(hr); // if (nRes != -1) // Failure("Compare() with invalid CollatingOption gave wrong answer"); } // Try a sequence of test comparisions. TestCompare(stuValBlank, stuValBlank, 0); TestCompare(stuValBlank, stuValSpace, -1); TestCompare(stuValBlank, stuValA, -1); TestCompare(stuValBlank, stuValAUpper, -1); TestCompare(stuValSpace, stuValA, -1); TestCompare(stuValA, stuValBlank, 1); TestCompare(stuValA, stuValB, -1); TestCompare(stuValB, stuValA, 1); TestCompare(stuValA, stuValAUpper, -1); TestCompare(stuValB, stuValAUpper, 1); TestCompare(stuValA, stuValAnd, -1); TestCompare(stuValAny, stuValAnd, 1); TestCompare(stuValAny, stuValAndUpper, 1); TestCompare(stuValAnd, stuValAnd, 0); TestCompare(stuValBlank, stuValPunct, -1); TestCompare(stuValPunct, stuValA, -1); TestCompare(stuValBlank, (wchar *)NULL, 0); TestCompare((wchar *)NULL, stuValA, -1); TestCompare(stuValA, (wchar *)NULL, 1); // REVIEW JohnT(LarsH): interface needs to define what happens to characters that // are not part of the character set for that language. E.g. behavior is defined // by the such-and-such procedure for converting string to 8-bit etc. // Invalid surrogate sequences. StrUni stuValInvalid1 = L"\xdc00"; StrUni stuValInvalid2 = L"\xdb80"; StrUni stuValInvalid3 = L"\xdc00\xdc00"; StrUni stuValSurr = L"\xdb80\xdc00"; // valid surrogate pair, but invalid code point // At this point I don't know what the result of the // comparison should be, or whether it should return a failure code, but at least // we can make sure it doesn't crash. int nResult; hr = m_qcoleng->Compare(stuValInvalid1.Bstr(), stuValInvalid2.Bstr(), fcoDefault, &nResult); hr = m_qcoleng->Compare(stuValInvalid3.Bstr(), stuValSurr.Bstr(), fcoDefault, &nResult); hr = m_qcoleng->Compare(stuValSurr.Bstr(), stuValAnd.Bstr(), fcoDefault, &nResult); // test case-insensitive comparison // TODO LarsH: ought to test both locale-dependent and locale-independent // case folding. See UTR#21 and CaseFolding.txt. But to do this we need // to be able to set the locale. So far we have no such concept IMO. SmartBstr sbstrKeyAnd = L"foo"; SmartBstr sbstrKeyAndUpper = L"bar"; SmartBstr sbstrKeyAny = L"baz"; hr = m_qcoleng->get_SortKey(stuValAnd.Bstr(), fcoIgnoreCase, &sbstrKeyAnd); TestFailZero(sbstrKeyAnd, "get_SortKey"); TestHrFail(hr, "getting SortKey on string"); hr = m_qcoleng->get_SortKey(stuValAndUpper.Bstr(), fcoIgnoreCase, &sbstrKeyAndUpper); TestFailZero(sbstrKeyAndUpper, "get_SortKey"); TestHrFail(hr, "getting SortKey on string"); hr = m_qcoleng->get_SortKey(stuValAny.Bstr(), fcoIgnoreCase, &sbstrKeyAny); TestFailZero(sbstrKeyAny, "get_SortKey"); TestHrFail(hr, "getting SortKey on string"); if(wcscmp(sbstrKeyAnd, sbstrKeyAndUpper)) Failure("String compare failed"); if (wcscmp(sbstrKeyAnd, sbstrKeyAny) >= 0) Failure("String compare failed"); // REVIEW LarsH: we need a test specific to DontIgnoreVariant, whatever that means hr = m_qcoleng->get_SortKey(stuValAnd.Bstr(), fcoDontIgnoreVariant, &sbstrKeyAnd); TestFailZero(sbstrKeyAnd, "get_SortKey"); TestHrFail(hr, "getting SortKey on string"); hr = m_qcoleng->get_SortKey(stuValAndUpper.Bstr(), fcoDontIgnoreVariant, &sbstrKeyAndUpper); TestFailZero(sbstrKeyAndUpper, "get_SortKey"); TestHrFail(hr, "getting SortKey on string"); hr = m_qcoleng->get_SortKey(stuValAny.Bstr(), fcoDontIgnoreVariant, &sbstrKeyAny); TestFailZero(sbstrKeyAny, "get_SortKey"); TestHrFail(hr, "getting SortKey on string"); if(wcscmp(sbstrKeyAnd, sbstrKeyAndUpper) >= 0) Failure("String compare failed"); if (wcscmp(sbstrKeyAnd, sbstrKeyAny) >= 0) Failure("String compare failed"); // Try to break get_SortKey() #define FIXED_BUG_431 1 #ifdef FIXED_BUG_431 { IgnoreWarnings iw; hr = m_qcoleng->get_SortKey(stuValAny.Bstr(), (enum LgCollatingOptions)(-2), &sbstrKeyAny); if (!FAILED(hr) || sbstrKeyAny) Failure("get_SortKey with invalid option should have failed and returned NULL."); hr = m_qcoleng->get_SortKey(stuValAny.Bstr(), fcoDefault, NULL); if (!FAILED(hr)) Failure("get_SortKey with NULL return ptr should have failed."); } #endif m_qcoleng.Clear(); // really? what for? do I need this elsewhere? // Why . instead of -> ? return S_OK; }