Leaked source code of windows server 2003
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.

170 lines
4.2 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. csmutest.cpp
  5. Abstract:
  6. Content Store manager unit test
  7. Revision History:
  8. DerekM created 07/14/99
  9. ********************************************************************/
  10. #include <atlbase.h>
  11. extern CComModule _Module;
  12. #include <mbstring.h>
  13. #include <ContentStoreMgr.h>
  14. #include <stdio.h>
  15. // **************************************************************************
  16. inline LPVOID MyAlloc(DWORD cb)
  17. {
  18. return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb);
  19. }
  20. // **************************************************************************
  21. inline LPVOID MyReAlloc(LPVOID pv, DWORD cb)
  22. {
  23. return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pv, cb);
  24. }
  25. // **************************************************************************
  26. inline BOOL MyFree(LPVOID pv)
  27. {
  28. return HeapFree(GetProcessHeap(), 0, pv);
  29. }
  30. // **************************************************************************
  31. void ShowUsage(void)
  32. {
  33. printf("Usage:\n");
  34. printf("wcsutest <command> <command parameters>\n");
  35. printf("\n\nCommands:\n");
  36. printf(" ADD: adds URLs to the store\n");
  37. printf(" Usage:\n");
  38. printf(" wcsutest ADD <Vendor ID> <Vendor Name> <URL>\n");
  39. printf("\n REMOVE: removes URLs from the store\n");
  40. printf(" Usage:\n");
  41. printf(" wcsutest REMOVE <Vendor ID> <Vendor Name> [URL]\n");
  42. printf(" Note that 'URL' is optional. If it is not present, all URLs for the specified\n");
  43. printf(" for the specified vendor will be deleted.\n");
  44. printf("\n ADDFILE: adds URLs listed in the specified file to the store\n");
  45. printf(" Usage:\n");
  46. printf(" wcsutest ADD <Vendor ID> <Vendor Name> <URL File>\n");
  47. printf("\n REMOVEFILE: removes URLs listed in the specfied file from the store\n");
  48. printf(" Usage:\n");
  49. printf(" wcsutest REMOVE <Vendor ID> <Vendor Name> [URL File]\n");
  50. printf(" Note that 'URL File' is optional. If it is not present, all URLs for the specified\n");
  51. printf(" for the specified vendor will be deleted.\n");
  52. printf("\n CHECKTRUST: checks if a URL is in the store\n");
  53. printf(" Usage:\n");
  54. printf(" wcsutest CHECKTRUST <URL>\n");
  55. printf("\n");
  56. }
  57. // **************************************************************************
  58. int __cdecl wmain(int argc, WCHAR **argv, WCHAR **envp)
  59. {
  60. HRESULT hr;
  61. LPCWSTR wszURL = L"";
  62. LPCWSTR wszVendorID = L"";
  63. LPCWSTR wszVendorName = L"";
  64. CPCHContentStore cs( true );
  65. switch(argc)
  66. {
  67. case 5: wszVendorName = argv[4];
  68. case 4: wszVendorID = argv[3];
  69. case 3: wszURL = argv[2]; break;
  70. default:
  71. ShowUsage();
  72. exit( 10 );
  73. }
  74. if(SUCCEEDED(hr = cs.Acquire()))
  75. {
  76. if(!_wcsicmp( argv[1], L"ADD")) // we're adding URLs
  77. {
  78. if(argc != 5)
  79. {
  80. ShowUsage();
  81. exit(10);
  82. }
  83. if(FAILED(hr = cs.Add( wszURL, wszVendorID, wszVendorName )))
  84. {
  85. wprintf( L"Unable to register URLs: 0x%08x\n", hr );
  86. }
  87. else
  88. {
  89. wprintf( L"Successfully added URLs\n" );
  90. }
  91. }
  92. else if(!_wcsicmp( argv[1], L"REMOVE" )) // we're deleteing URLs
  93. {
  94. if(argc != 5)
  95. {
  96. ShowUsage();
  97. exit(10);
  98. }
  99. if(FAILED(hr = cs.Remove( wszURL, wszVendorID, wszVendorName )))
  100. {
  101. wprintf( L"Unable to remove URLs: 0x%08x\n", hr );
  102. }
  103. else
  104. {
  105. wprintf( L"Successfully removed URL:s\n" );
  106. }
  107. }
  108. else if (!_wcsicmp( argv[1], L"CHECKTRUST")) // we're validating a URL
  109. {
  110. bool fTrusted;
  111. if(argc != 3)
  112. {
  113. ShowUsage();
  114. exit(10);
  115. }
  116. if(FAILED(hr = cs.IsTrusted( wszURL, fTrusted )))
  117. {
  118. wprintf( L"Unable to check if URL is trusted: 0x%08x\n", hr );
  119. }
  120. else
  121. {
  122. if(fTrusted)
  123. {
  124. wprintf( L"%s is trusted!\n", wszURL );
  125. }
  126. else
  127. {
  128. wprintf( L"%s is NOT trusted!\n", wszURL );
  129. }
  130. }
  131. }
  132. else // nothing valid
  133. {
  134. ShowUsage();
  135. exit(10);
  136. }
  137. if(SUCCEEDED(hr)) cs.Release( true );
  138. }
  139. return SUCCEEDED(hr) ? 0 : 5;
  140. }