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.

202 lines
6.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: tests.cpp
  7. //
  8. // Contents: Implementations of the Upper Layer unit tests for Inplace
  9. //
  10. // Classes:
  11. //
  12. // Functions: Test1
  13. //
  14. // History: dd-mmm-yy Author Comment
  15. // 27-Apr-94 ricksa author
  16. //
  17. //--------------------------------------------------------------------------
  18. #include "pre.h"
  19. #include "iocs.h"
  20. #include "ias.h"
  21. #include "ioipf.h"
  22. #include "ioips.h"
  23. #include "app.h"
  24. #include "site.h"
  25. #include "doc.h"
  26. #include "tests.h"
  27. #include "utaccel.h"
  28. const CLSID CLSID_SimpleServer = {0xbcf6d4a0, 0xbe8c, 0x1068, { 0xb6, 0xd4,
  29. 0x00, 0xdd, 0x01, 0x0c, 0x05, 0x09 }};
  30. const TCHAR *pszErrorTitle = TEXT("Unit Test FAILURE");
  31. //+-------------------------------------------------------------------------
  32. //
  33. // Function: TestMsgPostThread
  34. //
  35. // Synopsis: We use this thread to post messages to the inplace server
  36. //
  37. // Arguments: [pvApp] - application object
  38. //
  39. // Algorithm: Post key board message for the accelerator for the container
  40. // and wait 3 seconds to see if we get response. If we do, then
  41. // continue by posting an accelerator to the embeddinging and
  42. // waiting three seconds for a response. Finally post messages
  43. // to everyone telling them the test is over.
  44. //
  45. // History: dd-mmm-yy Author Comment
  46. // 02-May-94 ricksa author
  47. //
  48. // Notes:
  49. //
  50. //--------------------------------------------------------------------------
  51. extern "C" DWORD TestMsgPostThread(void *pvApp)
  52. {
  53. CSimpleApp *pApp = (CSimpleApp *) pvApp;
  54. HRESULT hr = ResultFromScode(E_UNEXPECTED);
  55. // Send an accelerator bound for the container
  56. PostMessage(pApp->m_hwndUIActiveObj, WM_CHAR, SIMPCNTR_UT_ACCEL, 1);
  57. // Give 6 seconds for chance to process an accelerator
  58. for (int i = 0; i < 6; i++)
  59. {
  60. // Get embedding and container a chance to process the accelerator
  61. Sleep(1000);
  62. // See if it got processed
  63. if (pApp->m_fGotUtestAccelerator)
  64. {
  65. break;
  66. }
  67. }
  68. if (pApp->m_fGotUtestAccelerator)
  69. {
  70. hr = S_OK;
  71. }
  72. else
  73. {
  74. // The container did not received the accelerator
  75. MessageBox(pApp->m_hAppWnd,
  76. TEXT("Container didn't recieve accelerator"),
  77. pszErrorTitle, MB_OK);
  78. }
  79. PostMessage(pApp->m_hDriverWnd, WM_TESTEND,
  80. SUCCEEDED(hr) ? TEST_SUCCESS : TEST_FAILURE, (LPARAM) hr);
  81. PostMessage(pApp->m_hAppWnd, WM_SYSCOMMAND, SC_CLOSE, 0L);
  82. return 0;
  83. }
  84. //+-------------------------------------------------------------------------
  85. //
  86. // Function: Test1
  87. //
  88. // Synopsis: Inserts an inplace object into this container
  89. //
  90. // Arguments: pApp -- a pointer to the CSimpleApp that we're a part of
  91. //
  92. // Algorithm: Create a simple server object. Activate the simple server
  93. // object. Send the container an accelerator and confirm that
  94. // the accelerator worked. Send the object an accelerator and
  95. // make sure that that accelerator worked. Then return the
  96. // result of the test to the test driver.
  97. //
  98. // History: dd-mmm-yy Author Comment
  99. // 27-Apr-94 ricksa author
  100. //
  101. // Notes:
  102. //
  103. //--------------------------------------------------------------------------
  104. void Test1(CSimpleApp *pApp)
  105. {
  106. // Create the inplace object
  107. HRESULT hr;
  108. static FORMATETC formatetc;
  109. //insert the simple server object
  110. formatetc.dwAspect = DVASPECT_CONTENT;
  111. formatetc.cfFormat = NULL;
  112. formatetc.lindex = -1;
  113. //need to create the client site
  114. pApp->m_lpDoc->m_lpSite = CSimpleSite::Create(pApp->m_lpDoc);
  115. hr = OleCreate(
  116. CLSID_SimpleServer,
  117. IID_IOleObject,
  118. OLERENDER_DRAW,
  119. &formatetc,
  120. &pApp->m_lpDoc->m_lpSite->m_OleClientSite,
  121. pApp->m_lpDoc->m_lpSite->m_lpObjStorage,
  122. (void **) &(pApp->m_lpDoc->m_lpSite->m_lpOleObject));
  123. if(hr == NOERROR)
  124. {
  125. // Activate the inplace object
  126. pApp->m_lpDoc->m_lpSite->InitObject(TRUE);
  127. // Default to unexpected failure
  128. hr = ResultFromScode(E_UNEXPECTED);
  129. if (pApp->m_lpDoc->m_fInPlaceActive)
  130. {
  131. // Create thread to send windows messages to container and
  132. // embedding
  133. DWORD dwThreadId;
  134. HANDLE hThread = CreateThread(
  135. NULL, // Security attributes - default
  136. 0, // Stack size - default
  137. TestMsgPostThread, // Addresss of thread function
  138. pApp, // Parameter to thread
  139. 0, // Flags - run immediately
  140. &dwThreadId); // Thread ID returned - unused.
  141. if (hThread != NULL)
  142. {
  143. // Thread was created so tell routine & dump handle
  144. // we won't use.
  145. hr = S_OK;
  146. CloseHandle(hThread);
  147. }
  148. else
  149. {
  150. // The container did not received the accelerator
  151. MessageBox(pApp->m_hAppWnd,
  152. TEXT("Could not create message sending thread"),
  153. pszErrorTitle, MB_OK);
  154. }
  155. }
  156. else
  157. {
  158. // The object did not get activated in place
  159. MessageBox(pApp->m_hAppWnd, TEXT("Could not activate in place"),
  160. pszErrorTitle, MB_OK);
  161. }
  162. }
  163. else
  164. {
  165. // We could not create the object
  166. MessageBox(pApp->m_hAppWnd, TEXT("Could not create embedding"),
  167. pszErrorTitle, MB_OK);
  168. }
  169. if (FAILED(hr))
  170. {
  171. PostMessage(pApp->m_hDriverWnd, WM_TESTEND,
  172. SUCCEEDED(hr) ? TEST_SUCCESS : TEST_FAILURE, (LPARAM) hr);
  173. }
  174. return;
  175. }