fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / dtrans / source / cnttype / wbench / testcnttype.cxx
blobe7fe844e2c31f9731dcfdb597adb52fd15da8e48
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 .
20 #include <cppuhelper/servicefactory.hxx>
21 #include <com/sun/star/lang/XTypeProvider.hpp>
22 #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 #include <com/sun/star/container/NoSuchElementException.hpp>
24 #include <com/sun/star/datatransfer/XMimeContentType.hpp>
25 #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
26 #include <com/sun/star/lang/XComponent.hpp>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
29 #include <osl/diagnose.h>
31 #include <stdio.h>
33 #include <vector>
35 //-------------------------------------------------------------
36 // my defines
37 //-------------------------------------------------------------
39 #define TEST_CLIPBOARD
40 #define RDB_SYSPATH "d:\\projects\\src621\\dtrans\\wntmsci7\\bin\\applicat.rdb"
42 //------------------------------------------------------------
43 // namesapces
44 //------------------------------------------------------------
46 using namespace ::rtl;
47 using namespace ::std;
48 using namespace ::cppu;
49 using namespace ::com::sun::star::datatransfer;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star::container;
54 //----------------------------------------------------------------
56 //----------------------------------------------------------------
58 void ShutdownServiceMgr( Reference< XMultiServiceFactory >& SrvMgr )
60 // Cast factory to XComponent
61 Reference< XComponent > xComponent( SrvMgr, UNO_QUERY );
63 if ( !xComponent.is() )
64 OSL_FAIL("Error shuting down");
66 // Dispose and clear factory
67 xComponent->dispose();
68 SrvMgr.clear();
69 SrvMgr = Reference< XMultiServiceFactory >();
72 //----------------------------------------------------------------
74 //----------------------------------------------------------------
76 sal_Bool readCntTypesFromFileIntoVector( char* fname, vector< string >& vecData )
78 FILE* fstream;
80 fstream = fopen( fname, "r+" );
81 if ( !fstream )
82 return sal_False;
84 // set pointer to file start
85 fseek( fstream, 0L, SEEK_SET );
87 char line[1024];
88 while ( fscanf( fstream, "%[^\n]s", line ) != EOF )
90 vecData.push_back( line );
91 fgetc( fstream );
94 fclose( fstream );
96 return sal_True;
99 //----------------------------------------------------------------
101 //----------------------------------------------------------------
103 sal_Bool processCntTypesAndWriteResultIntoFile( char* fname, vector< string >& vecData, Reference< XMimeContentTypeFactory > cnttypeFactory )
105 FILE* fstream;
107 fstream = fopen( fname, "w" );
108 if ( !fstream )
109 return sal_False;
111 // set pointer to file start
112 fseek( fstream, 0L, SEEK_SET );
114 vector< string >::iterator iter_end = vecData.end( );
115 for ( vector< string >::iterator iter = vecData.begin( ); iter != iter_end; ++iter )
119 fprintf( fstream, "Read: %s\n", iter->c_str( ) );
121 Reference< XMimeContentType > xMCntTyp = cnttypeFactory->createMimeContentType( OUString::createFromAscii( iter->c_str( ) ) );
123 fwprintf( fstream, OUString("Type: %s\n"), xMCntTyp->getMediaType( ).getStr( ) );
124 fwprintf( fstream, OUString("Subtype: %s\n"), xMCntTyp->getMediaSubtype( ).getStr( ) );
126 Sequence< OUString > seqParam = xMCntTyp->getParameters( );
127 sal_Int32 nParams = seqParam.getLength( );
129 for ( sal_Int32 i = 0; i < nParams; i++ )
131 fwprintf( fstream, OUString("PName: %s\n"), seqParam[i].getStr( ) );
132 fwprintf( fstream, OUString("PValue: %s\n"), xMCntTyp->getParameterValue( seqParam[i] ).getStr( ) );
135 catch( IllegalArgumentException& ex )
137 fwprintf( fstream, OUString("Read incorrect content type!\n\n") );
139 catch( NoSuchElementException& )
141 fwprintf( fstream, OUString("Value of parameter not available\n") );
143 catch( ... )
145 fwprintf( fstream, OUString("Unknown error!\n\n") );
148 fwprintf( fstream, OUString("\n#############################################\n\n") );
151 fclose( fstream );
153 return sal_True;
156 //----------------------------------------------------------------
157 // main
158 //----------------------------------------------------------------
160 int SAL_CALL main( int nArgc, char* argv[] )
162 if ( nArgc != 3 )
163 printf( "Start with: testcnttype input-file output-file\n" );
165 //-------------------------------------------------
166 // get the global service-manager
167 //-------------------------------------------------
168 OUString rdbName = OUString( RDB_SYSPATH );
169 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
171 // Print a message if an error occurred.
172 if ( !g_xFactory.is( ) )
174 OSL_FAIL("Can't create RegistryServiceFactory");
175 return(-1);
178 vector< string > vecCntTypes;
180 // open input-file and read the data
181 if ( !readCntTypesFromFileIntoVector( argv[1], vecCntTypes ) )
183 printf( "Can't open input file" );
184 ShutdownServiceMgr( g_xFactory );
187 Reference< XMimeContentTypeFactory >
188 xMCntTypeFactory( g_xFactory->createInstance( OUString("com.sun.star.datatransfer.MimeContentTypeFactory") ), UNO_QUERY );
190 if ( !xMCntTypeFactory.is( ) )
192 OSL_FAIL( "Error creating MimeContentTypeFactory Service" );
193 return(-1);
196 if ( !processCntTypesAndWriteResultIntoFile( argv[2], vecCntTypes, xMCntTypeFactory ) )
198 printf( "Can't open output file" );
199 ShutdownServiceMgr( g_xFactory );
202 //--------------------------------------------------
203 // shutdown the service manager
204 //--------------------------------------------------
206 ShutdownServiceMgr( g_xFactory );
208 return 0;
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */