xref: /aoo41x/main/dtrans/source/test/test_dtrans.cxx (revision 48123e16)
1*48123e16SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*48123e16SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*48123e16SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*48123e16SAndrew Rist  * distributed with this work for additional information
6*48123e16SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*48123e16SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*48123e16SAndrew Rist  * "License"); you may not use this file except in compliance
9*48123e16SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*48123e16SAndrew Rist  *
11*48123e16SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*48123e16SAndrew Rist  *
13*48123e16SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*48123e16SAndrew Rist  * software distributed under the License is distributed on an
15*48123e16SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*48123e16SAndrew Rist  * KIND, either express or implied.  See the License for the
17*48123e16SAndrew Rist  * specific language governing permissions and limitations
18*48123e16SAndrew Rist  * under the License.
19*48123e16SAndrew Rist  *
20*48123e16SAndrew Rist  *************************************************************/
21*48123e16SAndrew Rist 
22*48123e16SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dtrans.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir //------------------------------------------------------------------------
29cdf0e10cSrcweir // interface includes
30cdf0e10cSrcweir //------------------------------------------------------------------------
31cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp>
32cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboardManager.hpp>
33cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp>
34cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
35cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //------------------------------------------------------------------------
39cdf0e10cSrcweir // other includes
40cdf0e10cSrcweir //------------------------------------------------------------------------
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
44cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
45cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
46cdf0e10cSrcweir #include <rtl/ustring.hxx>
47cdf0e10cSrcweir #include <osl/diagnose.h>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #include <stdlib.h>
50cdf0e10cSrcweir #include <stdio.h>
51cdf0e10cSrcweir #include <string.h>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //#include <memory>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //#include <process.h>
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //------------------------------------------------------------------------
58cdf0e10cSrcweir // my defines
59cdf0e10cSrcweir //------------------------------------------------------------------------
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #ifdef UNX
62cdf0e10cSrcweir #define PATH_SEPERATOR '/'
63cdf0e10cSrcweir #else
64cdf0e10cSrcweir #define PATH_SEPERATOR '\\'
65cdf0e10cSrcweir #endif
66cdf0e10cSrcweir 
67cdf0e10cSrcweir #define ENSURE( a, b ) if( !a ) { fprintf( stderr, b "\n" ); exit( -1 ); }
68cdf0e10cSrcweir #define TEST( a, b ) fprintf( stderr, "Testing " a ); fprintf( stderr, b ? "passed\n" : "FAILED\n" )
69cdf0e10cSrcweir #define PERFORM( a, b ) fprintf( stderr, "Performing " a); b; fprintf( stderr, "done\n" )
70cdf0e10cSrcweir #define TRACE( a ) fprintf( stderr, a )
71cdf0e10cSrcweir 
72cdf0e10cSrcweir //------------------------------------------------------------------------
73cdf0e10cSrcweir //	namespaces
74cdf0e10cSrcweir //------------------------------------------------------------------------
75cdf0e10cSrcweir 
76cdf0e10cSrcweir using namespace	::rtl;
77cdf0e10cSrcweir using namespace ::std;
78cdf0e10cSrcweir using namespace ::cppu;
79cdf0e10cSrcweir using namespace ::com::sun::star::container;
80cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer;
81cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::clipboard;
82cdf0e10cSrcweir using namespace ::com::sun::star::uno;
83cdf0e10cSrcweir using namespace ::com::sun::star::io;
84cdf0e10cSrcweir using namespace	::com::sun::star::lang;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //------------------------------------------------------------------------
87cdf0e10cSrcweir //	globals
88cdf0e10cSrcweir //------------------------------------------------------------------------
89cdf0e10cSrcweir 
90cdf0e10cSrcweir const char * app = NULL;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //------------------------------------------------------------------------
93cdf0e10cSrcweir //	ClipboardOwner
94cdf0e10cSrcweir //------------------------------------------------------------------------
95cdf0e10cSrcweir 
96cdf0e10cSrcweir class ClipboardOwner : public WeakImplHelper1< XClipboardOwner >
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	Reference< XClipboard >    m_xClipboard;
99cdf0e10cSrcweir 	Reference< XTransferable > m_xTransferable;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	sal_uInt32 m_nReceivedLostOwnerships;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir public:
104cdf0e10cSrcweir 	ClipboardOwner();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	//--------------------------------------------------------------------
107cdf0e10cSrcweir 	// XClipboardOwner
108cdf0e10cSrcweir 	//--------------------------------------------------------------------
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	virtual void SAL_CALL lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans ) throw(RuntimeException);
111cdf0e10cSrcweir 
receivedLostOwnerships()112cdf0e10cSrcweir 	sal_uInt32 receivedLostOwnerships() { return m_nReceivedLostOwnerships; };
lostOwnershipClipboardValue()113cdf0e10cSrcweir 	Reference< XClipboard >    lostOwnershipClipboardValue() { return m_xClipboard; }
lostOwnershipTransferableValue()114cdf0e10cSrcweir 	Reference< XTransferable > lostOwnershipTransferableValue() { return m_xTransferable; };
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir //------------------------------------------------------------------------
118cdf0e10cSrcweir //	ctor
119cdf0e10cSrcweir //------------------------------------------------------------------------
120cdf0e10cSrcweir 
ClipboardOwner()121cdf0e10cSrcweir ClipboardOwner::ClipboardOwner():
122cdf0e10cSrcweir 	m_nReceivedLostOwnerships( 0 )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir //------------------------------------------------------------------------
127cdf0e10cSrcweir //	lostOwnership
128cdf0e10cSrcweir //------------------------------------------------------------------------
129cdf0e10cSrcweir 
lostOwnership(const Reference<XClipboard> & xClipboard,const Reference<XTransferable> & xTrans)130cdf0e10cSrcweir void SAL_CALL ClipboardOwner::lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans )
131cdf0e10cSrcweir 	throw(RuntimeException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	m_nReceivedLostOwnerships++;
134cdf0e10cSrcweir 	m_xClipboard = xClipboard;
135cdf0e10cSrcweir 	m_xTransferable = xTrans;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir //------------------------------------------------------------------------
139cdf0e10cSrcweir //	ClipboardListener
140cdf0e10cSrcweir //------------------------------------------------------------------------
141cdf0e10cSrcweir 
142cdf0e10cSrcweir class ClipboardListener : public WeakImplHelper1< XClipboardListener >
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	Reference< XClipboard >    m_xClipboard;
145cdf0e10cSrcweir 	Reference< XTransferable > m_xTransferable;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	sal_uInt32 m_nReceivedChangedContentsEvents;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir public:
150cdf0e10cSrcweir 	ClipboardListener();
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	//--------------------------------------------------------------------
153cdf0e10cSrcweir 	// XClipboardOwner
154cdf0e10cSrcweir 	//--------------------------------------------------------------------
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	virtual void SAL_CALL changedContents( const ClipboardEvent& event ) throw(RuntimeException);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	//--------------------------------------------------------------------
159cdf0e10cSrcweir 	// XEventListener
160cdf0e10cSrcweir 	//--------------------------------------------------------------------
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	virtual void SAL_CALL disposing( const EventObject& event ) throw(RuntimeException);
163cdf0e10cSrcweir 
receivedChangedContentsEvents()164cdf0e10cSrcweir 	sal_uInt32 receivedChangedContentsEvents() { return m_nReceivedChangedContentsEvents; };
changedContentsEventClipboardValue()165cdf0e10cSrcweir 	Reference< XClipboard >    changedContentsEventClipboardValue() { return m_xClipboard; }
changedContentsEventTransferableValue()166cdf0e10cSrcweir 	Reference< XTransferable > changedContentsEventTransferableValue() { return m_xTransferable; };
167cdf0e10cSrcweir };
168cdf0e10cSrcweir 
169cdf0e10cSrcweir //------------------------------------------------------------------------
170cdf0e10cSrcweir //	ctor
171cdf0e10cSrcweir //------------------------------------------------------------------------
172cdf0e10cSrcweir 
ClipboardListener()173cdf0e10cSrcweir ClipboardListener::ClipboardListener():
174cdf0e10cSrcweir 	m_nReceivedChangedContentsEvents( 0 )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir //------------------------------------------------------------------------
179cdf0e10cSrcweir //	changedContents
180cdf0e10cSrcweir //------------------------------------------------------------------------
181cdf0e10cSrcweir 
changedContents(const ClipboardEvent & event)182cdf0e10cSrcweir void SAL_CALL ClipboardListener::changedContents( const ClipboardEvent& event )
183cdf0e10cSrcweir 	throw(RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 	m_nReceivedChangedContentsEvents++;
186cdf0e10cSrcweir 	m_xClipboard = Reference< XClipboard > (event.Source, UNO_QUERY);
187cdf0e10cSrcweir 	m_xTransferable = event.Contents;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //------------------------------------------------------------------------
191cdf0e10cSrcweir //	disposing
192cdf0e10cSrcweir //------------------------------------------------------------------------
193cdf0e10cSrcweir 
disposing(const EventObject & event)194cdf0e10cSrcweir void SAL_CALL ClipboardListener::disposing( const EventObject& event )
195cdf0e10cSrcweir 	throw(RuntimeException)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir //------------------------------------------------------------------------
200cdf0e10cSrcweir //	StringTransferable
201cdf0e10cSrcweir //------------------------------------------------------------------------
202cdf0e10cSrcweir 
203cdf0e10cSrcweir class StringTransferable : public WeakImplHelper2< XClipboardOwner, XTransferable >
204cdf0e10cSrcweir {
205cdf0e10cSrcweir public:
206cdf0e10cSrcweir 	StringTransferable( );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	//--------------------------------------------------------------------
209cdf0e10cSrcweir 	// XTransferable
210cdf0e10cSrcweir 	//--------------------------------------------------------------------
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 	virtual Any SAL_CALL getTransferData( const DataFlavor& aFlavor ) throw(UnsupportedFlavorException, IOException, RuntimeException);
213cdf0e10cSrcweir     virtual Sequence< DataFlavor > SAL_CALL getTransferDataFlavors(  ) throw(RuntimeException);
214cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL isDataFlavorSupported( const DataFlavor& aFlavor ) throw(RuntimeException);
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	//--------------------------------------------------------------------
217cdf0e10cSrcweir 	// XClipboardOwner
218cdf0e10cSrcweir 	//--------------------------------------------------------------------
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	virtual void SAL_CALL lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans ) throw(RuntimeException);
221cdf0e10cSrcweir 
receivedLostOwnership()222cdf0e10cSrcweir 	sal_Bool receivedLostOwnership() { return m_receivedLostOwnership; };
clearReceivedLostOwnership()223cdf0e10cSrcweir 	void clearReceivedLostOwnership() { m_receivedLostOwnership = sal_False; };
224cdf0e10cSrcweir 
225cdf0e10cSrcweir private:
226cdf0e10cSrcweir 	Sequence< DataFlavor > m_seqDFlv;
227cdf0e10cSrcweir 	OUString               m_Data;
228cdf0e10cSrcweir 	sal_Bool               m_receivedLostOwnership;
229cdf0e10cSrcweir };
230cdf0e10cSrcweir 
231cdf0e10cSrcweir //------------------------------------------------------------------------
232cdf0e10cSrcweir //	ctor
233cdf0e10cSrcweir //------------------------------------------------------------------------
234cdf0e10cSrcweir 
StringTransferable()235cdf0e10cSrcweir StringTransferable::StringTransferable( ) :
236cdf0e10cSrcweir 	m_seqDFlv( 1 ),
237cdf0e10cSrcweir 	m_receivedLostOwnership( sal_False ),
238cdf0e10cSrcweir 	m_Data( OUString::createFromAscii("clipboard test content") )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir 	DataFlavor df;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 	/*
243cdf0e10cSrcweir 	df.MimeType = L"text/plain; charset=unicode";
244cdf0e10cSrcweir 	df.DataType = getCppuType( ( OUString* )0 );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	m_seqDFlv[0] = df;
247cdf0e10cSrcweir 	*/
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	//df.MimeType = L"text/plain; charset=windows1252";
250cdf0e10cSrcweir 	df.MimeType = OUString::createFromAscii( "text/html" );
251cdf0e10cSrcweir 	df.DataType = getCppuType( ( Sequence< sal_Int8 >* )0 );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 	m_seqDFlv[0] = df;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir //------------------------------------------------------------------------
257cdf0e10cSrcweir //	getTransferData
258cdf0e10cSrcweir //------------------------------------------------------------------------
259cdf0e10cSrcweir 
getTransferData(const DataFlavor & aFlavor)260cdf0e10cSrcweir Any SAL_CALL StringTransferable::getTransferData( const DataFlavor& aFlavor )
261cdf0e10cSrcweir 	throw(UnsupportedFlavorException, IOException, RuntimeException)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir 	Any anyData;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	/*if ( aFlavor == m_seqDFlv[0] )
266cdf0e10cSrcweir 	{
267cdf0e10cSrcweir 		anyData = makeAny( m_Data );
268cdf0e10cSrcweir 	} */
269cdf0e10cSrcweir #if 0
270cdf0e10cSrcweir 	else if ( aFlavor == m_seqDFlv[0] )
271cdf0e10cSrcweir 	{
272cdf0e10cSrcweir 		OString aStr( m_Data.getStr( ), m_Data.getLength( ), 1252 );
273cdf0e10cSrcweir 		Sequence< sal_Int8 > sOfChars( aStr.getLength( ) );
274cdf0e10cSrcweir 		sal_Int32 lenStr = aStr.getLength( );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 		for ( sal_Int32 i = 0; i < lenStr; ++i )
277cdf0e10cSrcweir 			sOfChars[i] = aStr[i];
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 		anyData = makeAny( sOfChars );
280cdf0e10cSrcweir 	}
281cdf0e10cSrcweir #endif
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 	return anyData;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir //------------------------------------------------------------------------
287cdf0e10cSrcweir //	getTransferDataFlavors
288cdf0e10cSrcweir //------------------------------------------------------------------------
289cdf0e10cSrcweir 
getTransferDataFlavors()290cdf0e10cSrcweir Sequence< DataFlavor > SAL_CALL StringTransferable::getTransferDataFlavors(  )
291cdf0e10cSrcweir 	throw(RuntimeException)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir 	return m_seqDFlv;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir //------------------------------------------------------------------------
297cdf0e10cSrcweir //	isDataFlavorSupported
298cdf0e10cSrcweir //------------------------------------------------------------------------
299cdf0e10cSrcweir 
isDataFlavorSupported(const DataFlavor & aFlavor)300cdf0e10cSrcweir sal_Bool SAL_CALL StringTransferable::isDataFlavorSupported( const DataFlavor& aFlavor )
301cdf0e10cSrcweir 	throw(RuntimeException)
302cdf0e10cSrcweir {
303cdf0e10cSrcweir 	sal_Int32 nLength = m_seqDFlv.getLength( );
304cdf0e10cSrcweir 	sal_Bool bRet     = sal_False;
305cdf0e10cSrcweir 
306cdf0e10cSrcweir //	for ( sal_Int32 i = 0; i < nLength; ++i )
307cdf0e10cSrcweir //	{
308cdf0e10cSrcweir //		if ( m_seqDFlv[i] == aFlavor )
309cdf0e10cSrcweir //		{
310cdf0e10cSrcweir //			bRet = sal_True;
311cdf0e10cSrcweir //			break;
312cdf0e10cSrcweir //		}
313cdf0e10cSrcweir //	}
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 	return bRet;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
318cdf0e10cSrcweir //------------------------------------------------------------------------
319cdf0e10cSrcweir //	lostOwnership
320cdf0e10cSrcweir //------------------------------------------------------------------------
321cdf0e10cSrcweir 
lostOwnership(const Reference<XClipboard> & xClipboard,const Reference<XTransferable> & xTrans)322cdf0e10cSrcweir void SAL_CALL StringTransferable::lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans )
323cdf0e10cSrcweir 	throw(RuntimeException)
324cdf0e10cSrcweir {
325cdf0e10cSrcweir 	m_receivedLostOwnership = sal_True;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir //------------------------------------------------------------------------
329cdf0e10cSrcweir //	main
330cdf0e10cSrcweir //------------------------------------------------------------------------
331cdf0e10cSrcweir 
main(int argc,const char * argv[])332cdf0e10cSrcweir int SAL_CALL main( int argc, const char* argv[] )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 	OUString aRegistry;
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	//------------------------------------------------------------------
337cdf0e10cSrcweir 	// check command line parameters
338cdf0e10cSrcweir 	//------------------------------------------------------------------
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 	if ( NULL == ( app = strrchr( argv[0], PATH_SEPERATOR ) ) )
341cdf0e10cSrcweir 		app = argv[0];
342cdf0e10cSrcweir 	else
343cdf0e10cSrcweir 		app++;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 	for( int n = 1; n < argc; n++ )
346cdf0e10cSrcweir 	{
347cdf0e10cSrcweir 		if( strncmp( argv[n], "-r", 2 ) == 0 )
348cdf0e10cSrcweir 		{
349cdf0e10cSrcweir 			if( strlen( argv[n] ) > 2 )
350cdf0e10cSrcweir 				aRegistry = OUString::createFromAscii( argv[n] + 2 );
351cdf0e10cSrcweir 			else if ( n + 1 < argc )
352cdf0e10cSrcweir 				aRegistry = OUString::createFromAscii( argv[++n] );
353cdf0e10cSrcweir 		}
354cdf0e10cSrcweir 	}
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 	if( aRegistry.getLength() == 0 )
357cdf0e10cSrcweir 		fprintf( stderr, "Usage: %s -r full-path-to-applicat.rdb\n", app );
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 	//------------------------------------------------------------------
360cdf0e10cSrcweir 	// create service manager
361cdf0e10cSrcweir 	//------------------------------------------------------------------
362cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xServiceManager;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	try
365cdf0e10cSrcweir 	{
366cdf0e10cSrcweir 		xServiceManager = createRegistryServiceFactory( aRegistry, sal_True );
367cdf0e10cSrcweir 		ENSURE( xServiceManager.is(), "*** ERROR *** service manager could not be created." );
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 		//--------------------------------------------------------------
370cdf0e10cSrcweir 		// create an instance of GenericClipboard service
371cdf0e10cSrcweir 		//--------------------------------------------------------------
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 		Sequence< Any > arguments(1);
374cdf0e10cSrcweir 		arguments[0] = makeAny( OUString::createFromAscii( "generic" ) );
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 		Reference< XClipboard > xClipboard( xServiceManager->createInstanceWithArguments(
377cdf0e10cSrcweir 			OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.GenericClipboard" ),
378cdf0e10cSrcweir 			arguments ), UNO_QUERY );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 		ENSURE( xClipboard.is(), "*** ERROR *** generic clipboard service could not be created." );
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 		Reference< XClipboardNotifier > xClipboardNotifier( xClipboard, UNO_QUERY );
383cdf0e10cSrcweir 		Reference< XClipboardListener > xClipboardListener = new ClipboardListener();
384cdf0e10cSrcweir 		ClipboardListener * pListener = (ClipboardListener *) xClipboardListener.get();
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 		if( xClipboardNotifier.is() )
387cdf0e10cSrcweir 			xClipboardNotifier->addClipboardListener( xClipboardListener );
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 		//--------------------------------------------------------------
390cdf0e10cSrcweir 		// run various tests on clipboard implementation
391cdf0e10cSrcweir 		//--------------------------------------------------------------
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 		TRACE( "\n*** testing generic clipboard service ***\n" );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 		Reference< XTransferable > xContents = new StringTransferable();
396cdf0e10cSrcweir 		Reference< XClipboardOwner > xOwner  = new ClipboardOwner();
397cdf0e10cSrcweir 		ClipboardOwner *pOwner = (ClipboardOwner *) xOwner.get();
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 		TEST( "initial contents (none): ", xClipboard->getContents().is() == sal_False );
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 		PERFORM( "update on contents with clipboard owner: ", xClipboard->setContents( xContents, xOwner ) );
402cdf0e10cSrcweir 		TEST( "current clipboard contents: ", xContents == xClipboard->getContents() );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 		if( xClipboardNotifier.is() )
405cdf0e10cSrcweir 		{
406cdf0e10cSrcweir 			TEST( "if received changedContents notifications: ", pListener->receivedChangedContentsEvents() > 0 );
407cdf0e10cSrcweir 			TEST( "if received exactly 1 changedContents notification: ", pListener->receivedChangedContentsEvents() == 1 );
408cdf0e10cSrcweir 			TEST( "if received changedContents notification for correct clipboard: ", pListener->changedContentsEventClipboardValue() == xClipboard );
409cdf0e10cSrcweir 			TEST( "if received changedContents notification for correct clipboard: ", pListener->changedContentsEventTransferableValue() == xContents );
410cdf0e10cSrcweir 		}
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 		PERFORM( "update on contents without data (clear): ", xClipboard->setContents( Reference< XTransferable >(), Reference< XClipboardOwner >() ) );
413cdf0e10cSrcweir 		TEST( "if received lostOwnership message(s): ", pOwner->receivedLostOwnerships() > 0 );
414cdf0e10cSrcweir 		TEST( "if received exactly 1 lostOwnership message: ", pOwner->receivedLostOwnerships() == 1 );
415cdf0e10cSrcweir 		TEST( "if received lostOwnership message for the correct clipboard: ", pOwner->lostOwnershipClipboardValue() == xClipboard );
416cdf0e10cSrcweir 		TEST( "if received lostOwnership message for the correct transferable: ", pOwner->lostOwnershipTransferableValue() == xContents );
417cdf0e10cSrcweir 		TEST( "current clipboard contents (none): ", xClipboard->getContents().is() == sal_False );
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 		if( xClipboardNotifier.is() )
420cdf0e10cSrcweir 		{
421cdf0e10cSrcweir 			TEST( "if received changedContents notifications: ", pListener->receivedChangedContentsEvents() > 1 );
422cdf0e10cSrcweir 			TEST( "if received exactly 1 changedContents notification: ", pListener->receivedChangedContentsEvents() == 2 );
423cdf0e10cSrcweir 			TEST( "if received changedContents notification for correct clipboard: ", pListener->changedContentsEventClipboardValue() == xClipboard );
424cdf0e10cSrcweir 			TEST( "if received changedContents notification for correct transferable: ", ! pListener->changedContentsEventTransferableValue().is() );
425cdf0e10cSrcweir 		}
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 		PERFORM( "update on contents without clipboard owner: ", xClipboard->setContents( xContents, Reference< XClipboardOwner >() ) );
428cdf0e10cSrcweir 		TEST( "that no further lostOwnership messages were received: ", pOwner->receivedLostOwnerships() == 1 );
429cdf0e10cSrcweir 		TEST( "current clipboard contents: ", xContents == xClipboard->getContents() );
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 		if( xClipboardNotifier.is() )
432cdf0e10cSrcweir 		{
433cdf0e10cSrcweir 			TEST( "if received changedContents notifications: ", pListener->receivedChangedContentsEvents() > 2 );
434cdf0e10cSrcweir 			TEST( "if received exactly 1 changedContents notification: ", pListener->receivedChangedContentsEvents() == 3 );
435cdf0e10cSrcweir 			TEST( "if received changedContents notification for correct clipboard: ", pListener->changedContentsEventClipboardValue() == xClipboard );
436cdf0e10cSrcweir 			TEST( "if received changedContents notification for correct transferable: ", pListener->changedContentsEventTransferableValue() == xContents );
437cdf0e10cSrcweir 		}
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 		PERFORM( "update on contents without data (clear): ", xClipboard->setContents( Reference< XTransferable >(), Reference< XClipboardOwner >() ) );
441cdf0e10cSrcweir 		TEST( "that no further lostOwnership messages were received: ", pOwner->receivedLostOwnerships() == 1 );
442cdf0e10cSrcweir 		TEST( "current clipboard contents (none): ", xClipboard->getContents().is() == sal_False );
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 		if( xClipboardNotifier.is() )
445cdf0e10cSrcweir 		{
446cdf0e10cSrcweir 			TEST( "if received changedContents notifications: ", pListener->receivedChangedContentsEvents() > 3 );
447cdf0e10cSrcweir 			TEST( "if received exactly 1 changedContents notification: ", pListener->receivedChangedContentsEvents() == 4 );
448cdf0e10cSrcweir 			TEST( "if received changedContents notification for correct clipboard: ", pListener->changedContentsEventClipboardValue() == xClipboard );
449cdf0e10cSrcweir 			TEST( "if received changedContents notification for correct transferable: ", ! pListener->changedContentsEventTransferableValue().is() );
450cdf0e10cSrcweir 		}
451cdf0e10cSrcweir 
452cdf0e10cSrcweir 		//--------------------------------------------------------------
453cdf0e10cSrcweir 		// create an instance of ClipboardManager service
454cdf0e10cSrcweir 		//--------------------------------------------------------------
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 		Reference< XClipboardManager > xClipboardManager( xServiceManager->createInstance(
457cdf0e10cSrcweir 			OUString::createFromAscii( "com.sun.star.datatransfer.clipboard.ClipboardManager" ) ), UNO_QUERY );
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 		ENSURE( xClipboardManager.is(), "*** ERROR *** clipboard manager service could not be created." );
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 		//--------------------------------------------------------------
462cdf0e10cSrcweir 		// run various tests on clipboard manager implementation
463cdf0e10cSrcweir 		//--------------------------------------------------------------
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 		TRACE( "\n*** testing clipboard manager service ***\n" );
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 		TEST( "initial number of clipboards (0): ", xClipboardManager->listClipboardNames().getLength() == 0 );
468cdf0e10cSrcweir 		PERFORM( "insertion of generic clipboard: ", xClipboardManager->addClipboard( xClipboard ) );
469cdf0e10cSrcweir 		TEST( "number of inserted clipboards (1): ", xClipboardManager->listClipboardNames().getLength() == 1 );
470cdf0e10cSrcweir 		TEST( "name of inserted clipboard (generic): ", xClipboardManager->listClipboardNames()[0] == OUString::createFromAscii( "generic" ) );
471cdf0e10cSrcweir 		TEST( "inserted clipboard instance: ", xClipboardManager->getClipboard( OUString::createFromAscii( "generic" ) ) == xClipboard );
472cdf0e10cSrcweir 		PERFORM( "removal of generic clipboard: ", xClipboardManager->removeClipboard( OUString::createFromAscii( "generic" ) ) );
473cdf0e10cSrcweir 		TEST( "number of inserted clipboards (0): ", xClipboardManager->listClipboardNames().getLength() == 0 );
474cdf0e10cSrcweir 		TRACE( "Testing inserted clipboard instance (none): " );
475cdf0e10cSrcweir 		try
476cdf0e10cSrcweir 		{
477cdf0e10cSrcweir 			xClipboardManager->getClipboard( OUString::createFromAscii( "generic" ) );
478cdf0e10cSrcweir 			TRACE( "FAILED\n" );
479cdf0e10cSrcweir 		}
480cdf0e10cSrcweir 		catch( NoSuchElementException e )
481cdf0e10cSrcweir 		{
482cdf0e10cSrcweir 			TRACE( "passed\n" );
483cdf0e10cSrcweir 		}
484cdf0e10cSrcweir 	}
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 	catch ( Exception aException )
487cdf0e10cSrcweir 	{
488cdf0e10cSrcweir 		ENSURE( sal_False, "*** ERROR *** exception caught." );
489cdf0e10cSrcweir 	}
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 	//--------------------------------------------------------------------
492cdf0e10cSrcweir 	// shutdown the service manager
493cdf0e10cSrcweir 	//--------------------------------------------------------------------
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 	// query XComponent interface
496cdf0e10cSrcweir 	Reference< XComponent > xComponent( xServiceManager, UNO_QUERY );
497cdf0e10cSrcweir 
498cdf0e10cSrcweir 	ENSURE( xComponent.is(), "*** ERROR *** service manager does not support XComponent." );
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 	// Dispose and clear factory
501cdf0e10cSrcweir 	xComponent->dispose();
502cdf0e10cSrcweir 	xServiceManager.clear();
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	fprintf( stderr, "Done.\n" );
505cdf0e10cSrcweir 	return 0;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 
509