Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.2 KiB

  1. #include "stdafx.h"
  2. #include "shelldrt.h"
  3. // g_aTestDlls
  4. //
  5. // The array of tests that we are available to be run
  6. vector<SHTESTDESCRIPTOR> g_aTests;
  7. vector<HMODULE> g_ahTestDlls;
  8. // usage
  9. //
  10. // Displays program usage instructions. Does NOT exit on its own.
  11. void usage()
  12. {
  13. _ftprintf(stderr, TEXT("\nSHELLDRT: Shell Developer Regression Tests\n")
  14. TEXT("---------------------------------------------------------------------\n")
  15. TEXT("Usage: SHELLDRT -h [[testdll1] ...]\n")
  16. TEXT("\n")
  17. TEXT("Where: -h Help (this list)\n"));
  18. }
  19. // AddTestsFromDll
  20. //
  21. // Given the name of a test dll, loads it and queries it for the tests it contains,
  22. // adding them to the mix.
  23. bool AddTestsFromDll(LPCTSTR pszDllName)
  24. {
  25. HMODULE hMod = LoadLibrary(pszDllName);
  26. if (!hMod)
  27. return false;
  28. g_ahTestDlls.push_back( hMod );
  29. SHTESTLISTPROC pfnListTests = (SHTESTLISTPROC) GetProcAddress(hMod, "ListTestProcs");
  30. if (!pfnListTests)
  31. {
  32. _ftprintf(stderr, TEXT("SHELLDRT: Test dll %s does not expose the ListTestProcs entry point.\n"), pszDllName);
  33. return false;
  34. }
  35. DWORD cTests = pfnListTests(NULL);
  36. if (!cTests)
  37. {
  38. _ftprintf(stderr, TEXT("SHELLDRT: Test dll %s exposes no tests.\n"), pszDllName);
  39. return false;
  40. }
  41. AutoPtr<SHTESTDESCRIPTOR> spDescriptors = new SHTESTDESCRIPTOR[cTests];
  42. if (cTests != pfnListTests(spDescriptors))
  43. {
  44. fprintf(stderr, "SHELLDRT: Test dll %s advertised %d tests but did not supply them all.\n", pszDllName, cTests);
  45. return false;
  46. }
  47. for (DWORD i = 0; i < cTests; i++)
  48. g_aTests.push_back(spDescriptors[i]);
  49. return true;
  50. }
  51. // AddTestsFromLocalDir
  52. //
  53. // Looks in the current directory for test dlls and adds them to the array
  54. void AddTestsFromLocalDir()
  55. {
  56. WIN32_FIND_DATA finddata;
  57. AutoFindHandle spFindHandle;
  58. BOOL fHaveFile = TRUE;
  59. for (spFindHandle = FindFirstFile(TEXT("shdrt-*.dll"), &finddata); (INVALID_HANDLE_VALUE != spFindHandle) && fHaveFile;
  60. fHaveFile = FindNextFile(spFindHandle, &finddata))
  61. {
  62. if (!AddTestsFromDll(finddata.cFileName))
  63. {
  64. _ftprintf(stderr, TEXT("SHELLDRT: Cannot load test dll %s [Err: %08dX]\n"), finddata.cFileName, GetLastError());
  65. ExitProcess(0);
  66. }
  67. }
  68. }
  69. // RunTests
  70. //
  71. // Loops through the loaded tests and
  72. bool RunTests()
  73. {
  74. for (DWORD i = 0; i < g_aTests.size(); i++)
  75. {
  76. _ftprintf(stdout, TEXT("Starting Test : %s\n"), g_aTests[i]._pszTestName);
  77. if (g_aTests[i]._pfnTestProc())
  78. {
  79. _ftprintf(stdout, TEXT("Success : %s\n"), g_aTests[i]._pszTestName);
  80. }
  81. else
  82. {
  83. _ftprintf(stderr, TEXT("** FAILURE ** : %s\n"), g_aTests[i]._pszTestName);
  84. return false;
  85. }
  86. }
  87. _ftprintf(stdout, TEXT("++ SUCCESS ++\n"));
  88. return true;
  89. }
  90. // main
  91. //
  92. // Program entry point
  93. #ifdef UNICODE
  94. extern "C"
  95. {
  96. int __cdecl wmain(int argc, wchar_t* argv[])
  97. {
  98. #else
  99. int __cdecl main(int argc, char* argv[])
  100. {
  101. #endif
  102. LPTSTR p;
  103. argc--;
  104. argv++;
  105. while ( argc-- > 0 )
  106. {
  107. p = *argv++;
  108. if ( *p == '-' || *p == '/' )
  109. {
  110. p++;
  111. switch ( tolower(*p) )
  112. {
  113. case 'h':
  114. usage();
  115. ExitProcess(0);
  116. default:
  117. usage();
  118. ExitProcess(0);
  119. }
  120. }
  121. else
  122. {
  123. if (!AddTestsFromDll(p))
  124. {
  125. _ftprintf(stderr, TEXT("SHELLDRT: Cannot load test dll %s [Err: %08dX]\n"), p, GetLastError());
  126. ExitProcess(0);
  127. }
  128. }
  129. }
  130. // If no tests were specified manually on the command line, look for
  131. // them in the current directory
  132. if (0 == g_aTests.size())
  133. AddTestsFromLocalDir();
  134. // If still no tests, there's nothing to do
  135. if (0 == g_aTests.size())
  136. {
  137. _ftprintf(stderr, TEXT("SHELLDRT: No tests specified and none found in current directory.\n"));
  138. usage();
  139. ExitProcess(0);
  140. }
  141. return RunTests();
  142. }
  143. #ifdef UNICODE
  144. }
  145. #endif