tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / extensions / test / ole / cppToUno / testcppuno.cxx
blobe64541ed2fc0846dbf8eac28322df24562c967aa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #pragma warning(disable: 4917)
22 #if !defined WIN32_LEAN_AND_MEAN
23 # define WIN32_LEAN_AND_MEAN
24 #endif
25 #include <windows.h>
26 #include <comdef.h>
27 #include <atlbase.h>
28 #include <atlcom.h>
29 #include <stdio.h>
30 #include <com/sun/star/bridge/ModelDependent.hpp>
31 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <oletest/XCallback.hpp>
34 #include <rtl/process.h>
35 #include <cppuhelper/servicefactory.hxx>
36 #include <rtl/string.h>
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::bridge;
42 using namespace com::sun::star::bridge::ModelDependent;
43 using namespace cppu;
45 HRESULT doTest();
46 bool incrementMultidimensionalIndex(
47 sal_Int32 dimensions,
48 const sal_Int32 * parDimensionLengths,
49 sal_Int32 * parMultidimensionalIndex);
51 int SAL_CALL main( int /*argc*/, char** /*argv*/ )
53 HRESULT hr;
54 if( FAILED( hr=CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
56 printf("CoInitializeEx failed \n");
57 return -1;
61 if( FAILED(hr=doTest()))
63 _com_error err( hr);
64 const CHAR * errMsg= err.ErrorMessage();
65 MessageBoxA( NULL, errMsg, "Test failed", MB_ICONERROR);
68 CoUninitialize();
69 return 0;
73 HRESULT doTest()
75 HRESULT hr= S_OK;
76 long j = 0;
77 SAFEARRAY* par;
78 CComDispatchDriver disp;
79 CComVariant result;
80 CComVariant param1;
81 CComPtr<IUnknown> spUnkFactory;
82 if( SUCCEEDED( spUnkFactory.CoCreateInstance(L"com.sun.star.ServiceManager")))
84 disp= spUnkFactory;
85 param1= L"oletest.OleTest";
86 disp.Invoke1( L"createInstance", &param1, &result);
88 disp= result.pdispVal;
90 // disp contains now oletest.OleTest
92 // one dimensional array
93 par= SafeArrayCreateVector( VT_UI1, 0, 5);
94 unsigned char arbyte[]= { 1,2,3,4,5};
95 for(long i= 0; i < 5;i++)
96 hr= SafeArrayPutElement( par, &i, &arbyte[i]);
98 result.Clear();
99 param1.vt= VT_ARRAY| VT_UI1;
100 param1.byref= par;
101 disp.Invoke1(L"methodByte", &param1, &result);
102 SafeArrayDestroy( par);
105 // two dimensional array
106 SAFEARRAYBOUND bounds[2];
107 // least significant dimension first, Dimension 1
108 bounds[0].cElements= 3;
109 bounds[0].lLbound= 0;
110 // Dimension 2
111 bounds[1].cElements= 2;
112 bounds[1].lLbound= 0;
113 par= SafeArrayCreate( VT_I4, 2, bounds );
115 long uBound1;
116 long uBound2;
117 hr= SafeArrayGetUBound( par, 1, &uBound1);
118 hr= SafeArrayGetUBound( par, 2, &uBound2);
120 long index2[2];
121 memset( index2, 0, 2 * sizeof( long) );
122 long dimLengths[]={3,2};
124 long data;
127 data= index2[1] * 3 + index2[0] +1;
128 hr= SafeArrayPutElement( par, index2, &data);
129 }while( incrementMultidimensionalIndex( 2, dimLengths, index2) );
131 long* pdata;
132 long (*dataL)[2][3];
133 hr= SafeArrayAccessData( par, (void**)&pdata);
134 dataL= (long(*)[2][3])pdata;
136 for (long i= 0; i < 2; i ++)
138 for(long j= 0; j < 3; j++)
139 data= (*dataL)[i][j];
141 hr= SafeArrayUnaccessData(par);
143 result.Clear();
144 param1.vt= VT_ARRAY | VT_I4;
145 param1.byref= par;
146 disp.Invoke1(L"methodSequence", &param1, &result);
148 SAFEARRAY* arRet= result.parray;
150 for(long i= 0; i < 2 ; i++)
152 CComVariant varx;
153 varx.Clear();
154 hr= SafeArrayGetElement( arRet, &i, &varx);
155 SAFEARRAY* ari= varx.parray;
157 for( j= 0; j < 3; j++)
159 CComVariant varj;
160 varj.Clear();
161 hr= SafeArrayGetElement( ari, &j, &varj);
166 SafeArrayDestroy( par);
169 return hr;
172 // left index is least significant
173 bool incrementMultidimensionalIndex(
174 sal_Int32 dimensions,
175 const sal_Int32 * parDimensionLengths,
176 sal_Int32 * parMultidimensionalIndex)
178 if( dimensions < 1)
179 return sal_False;
181 bool ret= sal_True;
182 bool carry= sal_True; // to get into the while loop
184 sal_Int32 currentDimension= 0; //most significant is 1
185 while( carry)
187 parMultidimensionalIndex[ currentDimension ]++;
188 // if carryover, set index to 0 and handle carry on a level above
189 if( parMultidimensionalIndex[ currentDimension] > (parDimensionLengths[ currentDimension] - 1))
190 parMultidimensionalIndex[ currentDimension]= 0;
191 else
192 carry= sal_False;
194 currentDimension ++;
195 // if dimensions drops below 1 and carry is set than then all indices are 0 again
196 // this is signalled by returning sal_False
197 if( currentDimension > dimensions - 1 && carry)
199 carry= sal_False;
200 ret= sal_False;
203 return ret;
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */