home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / test / source / main.cpp next >
Encoding:
C/C++ Source or Header  |  2010-03-04  |  2.6 KB  |  121 lines

  1. #include <stdio.h>
  2. #include <vd2/system/vdtypes.h>
  3. #include <vd2/system/cpuaccel.h>
  4. #include <vd2/system/VDString.h>
  5. #include <vd2/system/text.h>
  6. #include <vd2/system/vdstl.h>
  7. #include <vd2/system/bitmath.h>
  8.  
  9. #include "test.h"
  10.  
  11. #include <vector>
  12. #include <utility>
  13.  
  14. #if defined(_M_IX86)
  15.     #define BUILD L"80x86"
  16. #elif defined(_M_AMD64)
  17.     #define BUILD L"AMD64"
  18. #endif
  19.  
  20. namespace {
  21.     struct TestInfo {
  22.         TestFn        mpTestFn;
  23.         const char    *mpName;
  24.         bool        mbAutoRun;
  25.     };
  26.  
  27.     typedef vdfastvector<TestInfo> Tests;
  28.     Tests g_tests;
  29. }
  30.  
  31. void AddTest(TestFn f, const char *name, bool autoRun) {
  32.     TestInfo ti;
  33.     ti.mpTestFn = f;
  34.     ti.mpName = name;
  35.     ti.mbAutoRun = autoRun;
  36.     g_tests.push_back(ti);
  37. }
  38.  
  39. void help() {
  40.     wprintf(L"\n");
  41.     wprintf(L"Available tests:\n");
  42.  
  43.     for(Tests::const_iterator it(g_tests.begin()), itEnd(g_tests.end()); it!=itEnd; ++it) {
  44.         const TestInfo& ent = *it;
  45.  
  46.         wprintf(L"\t%hs%s\n", ent.mpName, ent.mbAutoRun ? L"" : L"*");
  47.     }
  48.     wprintf(L"\tAll\n");
  49. }
  50.  
  51. int wmain(int argc, wchar_t **argv) {
  52.     _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF);
  53.  
  54.     wprintf(L"VirtualDub test harness utility for " BUILD L"\n");
  55.     wprintf(L"Copyright (C) 2005-2008 Avery Lee. Licensed under GNU General Public License\n\n");
  56.  
  57.     Tests selectedTests;
  58.  
  59.     if (argc <= 1) {
  60.         help();
  61.         exit(0);
  62.     } else {
  63.         for(int i=1; i<argc; ++i) {
  64.             const wchar_t *test = argv[i];
  65.  
  66.             if (!_wcsicmp(test, L"all")) {
  67.                 for(Tests::const_iterator it(g_tests.begin()), itEnd(g_tests.end()); it!=itEnd; ++it) {
  68.                     const TestInfo& ent = *it;
  69.  
  70.                     if (ent.mbAutoRun)
  71.                         selectedTests.push_back(ent);
  72.                 }
  73.                 break;
  74.             }
  75.  
  76.             for(Tests::const_iterator it(g_tests.begin()), itEnd(g_tests.end()); it!=itEnd; ++it) {
  77.                 const TestInfo& ent = *it;
  78.  
  79.                 if (!_wcsicmp(VDTextAToW(ent.mpName).c_str(), test)) {
  80.                     selectedTests.push_back(ent);
  81.                     goto next;
  82.                 }
  83.             }
  84.  
  85.             wprintf(L"\nUnknown test: %ls\n", test);
  86.             help();
  87.             exit(5);
  88. next:
  89.             ;
  90.         }
  91.     }
  92.  
  93.     long exts = CPUCheckForExtensions();
  94.     int failedTests = 0;
  95.  
  96.     for(;;) {
  97.         CPUEnableExtensions(exts);
  98.         wprintf(L"Setting CPU extensions: %08x\n", exts);
  99.  
  100.         for(Tests::const_iterator it(selectedTests.begin()), itEnd(selectedTests.end()); it!=itEnd; ++it) {
  101.             const Tests::value_type& ent = *it;
  102.  
  103.             wprintf(L"Running test: %hs\n", ent.mpName);
  104.  
  105.             try {
  106.                 ent.mpTestFn();
  107.             } catch(const AssertionException& e) {
  108.                 wprintf(L"    TEST FAILED: %hs\n", e.gets());
  109.                 ++failedTests;
  110.             }
  111.         }
  112.  
  113.         if (!exts)
  114.             break;
  115.  
  116.         exts &= ~(1 << VDFindHighestSetBitFast(exts));
  117.     }
  118.  
  119.     return failedTests;
  120. }
  121.