summaryrefslogtreecommitdiffstats
path: root/private/oleutest/simpcntr/tests.cpp
blob: 48a535d881a08db5f83218ddc6bc0fdabff00230 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1992 - 1993.
//
//  File:   	tests.cpp
//
//  Contents:	Implementations of the Upper Layer unit tests for Inplace
//
//  Classes:
//
//  Functions: 	Test1
//
//  History:    dd-mmm-yy Author    Comment
//		27-Apr-94 ricksa    author
//
//--------------------------------------------------------------------------

#include "pre.h"
#include "iocs.h"
#include "ias.h"
#include "ioipf.h"
#include "ioips.h"
#include "app.h"
#include "site.h"
#include "doc.h"
#include "tests.h"
#include "utaccel.h"

const CLSID CLSID_SimpleServer = {0xbcf6d4a0, 0xbe8c, 0x1068, { 0xb6, 0xd4,
	0x00, 0xdd, 0x01, 0x0c, 0x05, 0x09 }};

const TCHAR *pszErrorTitle = TEXT("Unit Test FAILURE");

//+-------------------------------------------------------------------------
//
//  Function:   TestMsgPostThread
//
//  Synopsis:   We use this thread to post messages to the inplace server
//
//  Arguments:  [pvApp] - application object
//
//  Algorithm:  Post key board message for the accelerator for the container
//              and wait 3 seconds to see if we get response. If we do, then
//              continue by posting an accelerator to the embeddinging and
//              waiting three seconds for a response. Finally post messages
//              to everyone telling them the test is over.
//
//  History:    dd-mmm-yy Author    Comment
//              02-May-94 ricksa    author
//
//  Notes:      
//
//--------------------------------------------------------------------------
extern "C" DWORD TestMsgPostThread(void *pvApp)
{
    CSimpleApp *pApp = (CSimpleApp *) pvApp;
    HRESULT hr = ResultFromScode(E_UNEXPECTED);

    // Send an accelerator bound for the container
    PostMessage(pApp->m_hwndUIActiveObj, WM_CHAR, SIMPCNTR_UT_ACCEL, 1);

    // Give 6 seconds for chance to process an accelerator
    for (int i = 0; i < 6; i++)
    {
        // Get embedding and container a chance to process the accelerator
        Sleep(1000);

        // See if it got processed
        if (pApp->m_fGotUtestAccelerator)
        {
            break;
        }
    }

    if (pApp->m_fGotUtestAccelerator)
    {
        hr = S_OK;
    }
    else
    {
        // The container did not received the accelerator
        MessageBox(pApp->m_hAppWnd,
            TEXT("Container didn't recieve accelerator"),
                pszErrorTitle, MB_OK);
    }

    PostMessage(pApp->m_hDriverWnd, WM_TESTEND,
        SUCCEEDED(hr) ? TEST_SUCCESS : TEST_FAILURE, (LPARAM) hr);

    PostMessage(pApp->m_hAppWnd, WM_SYSCOMMAND, SC_CLOSE, 0L);

    return 0;
}




//+-------------------------------------------------------------------------
//
//  Function:	Test1
//
//  Synopsis:   Inserts an inplace object into this container
//
//  Arguments:	pApp	-- a pointer to the CSimpleApp that we're a part of  
//
//  Algorithm:  Create a simple server object. Activate the simple server
//              object. Send the container an accelerator and confirm that
//              the accelerator worked. Send the object an accelerator and
//              make sure that that accelerator worked. Then return the
//              result of the test to the test driver.
//
//  History:    dd-mmm-yy Author    Comment
//              27-Apr-94 ricksa    author
//
//  Notes:      
//
//--------------------------------------------------------------------------
void Test1(CSimpleApp *pApp)
{
    // Create the inplace object
    HRESULT hr;
    static FORMATETC formatetc;

    //insert the simple server object

    formatetc.dwAspect = DVASPECT_CONTENT;
    formatetc.cfFormat = NULL;
    formatetc.lindex = -1;

    //need to create the client site

    pApp->m_lpDoc->m_lpSite = CSimpleSite::Create(pApp->m_lpDoc);

    hr = OleCreate(
                CLSID_SimpleServer,
                IID_IOleObject,
		OLERENDER_DRAW,
                &formatetc,
		&pApp->m_lpDoc->m_lpSite->m_OleClientSite,
		pApp->m_lpDoc->m_lpSite->m_lpObjStorage, 
		(void **) &(pApp->m_lpDoc->m_lpSite->m_lpOleObject));

    if(hr == NOERROR)
    {
        // Activate the inplace object
        pApp->m_lpDoc->m_lpSite->InitObject(TRUE);

        // Default to unexpected failure
        hr = ResultFromScode(E_UNEXPECTED);

        if (pApp->m_lpDoc->m_fInPlaceActive)
        {
            // Create thread to send windows messages to container and
            // embedding
            DWORD dwThreadId;

            HANDLE hThread = CreateThread(
                NULL,               // Security attributes - default
                0,                  // Stack size - default
                TestMsgPostThread,  // Addresss of thread function
                pApp,               // Parameter to thread
                0,                  // Flags - run immediately
                &dwThreadId);       // Thread ID returned - unused.

            if (hThread != NULL)
            {
                // Thread was created so tell routine & dump handle
                // we won't use.
                hr = S_OK;
                CloseHandle(hThread);
            }
            else
            {
                // The container did not received the accelerator
                MessageBox(pApp->m_hAppWnd,
                    TEXT("Could not create message sending thread"),
                        pszErrorTitle, MB_OK);
            }
        }
        else
        {
            // The object did not get activated in place
            MessageBox(pApp->m_hAppWnd, TEXT("Could not activate in place"),
                pszErrorTitle, MB_OK);
        }
    }
    else
    {
        // We could not create the object
        MessageBox(pApp->m_hAppWnd, TEXT("Could not create embedding"),
            pszErrorTitle, MB_OK);
    }

    if (FAILED(hr))
    {
        PostMessage(pApp->m_hDriverWnd, WM_TESTEND,
            SUCCEEDED(hr) ? TEST_SUCCESS : TEST_FAILURE, (LPARAM) hr);
    }

    return;
}