fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dtrans / source / cnttype / wbench / testcnttype.cxx
blob77a01ecef72e97645b0d9a308ebdd328b58cdee3
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 // my defines
37 #define TEST_CLIPBOARD
38 #define RDB_SYSPATH "d:\\projects\\src621\\dtrans\\wntmsci7\\bin\\applicat.rdb"
40 // namesapces
42 using namespace ::std;
43 using namespace ::cppu;
44 using namespace ::com::sun::star::datatransfer;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::container;
49 void ShutdownServiceMgr( Reference< XMultiServiceFactory >& SrvMgr )
51 // Cast factory to XComponent
52 Reference< XComponent > xComponent( SrvMgr, UNO_QUERY );
54 if ( !xComponent.is() )
55 OSL_FAIL("Error shuting down");
57 // Dispose and clear factory
58 xComponent->dispose();
59 SrvMgr.clear();
62 sal_Bool readCntTypesFromFileIntoVector( char* fname, vector< string >& vecData )
64 FILE* fstream;
66 fstream = fopen( fname, "r+" );
67 if ( !fstream )
68 return sal_False;
70 // set pointer to file start
71 fseek( fstream, 0L, SEEK_SET );
73 char line[1024];
74 while ( fscanf( fstream, "%[^\n]s", line ) != EOF )
76 vecData.push_back( line );
77 fgetc( fstream );
80 fclose( fstream );
82 return sal_True;
85 sal_Bool processCntTypesAndWriteResultIntoFile( char* fname, vector< string >& vecData, Reference< XMimeContentTypeFactory > cnttypeFactory )
87 FILE* fstream;
89 fstream = fopen( fname, "w" );
90 if ( !fstream )
91 return sal_False;
93 // set pointer to file start
94 fseek( fstream, 0L, SEEK_SET );
96 vector< string >::iterator iter_end = vecData.end( );
97 for ( vector< string >::iterator iter = vecData.begin( ); iter != iter_end; ++iter )
99 try
101 fprintf( fstream, "Read: %s\n", iter->c_str( ) );
103 Reference< XMimeContentType > xMCntTyp = cnttypeFactory->createMimeContentType( OUString::createFromAscii( iter->c_str( ) ) );
105 fwprintf( fstream, OUString("Type: %s\n"), xMCntTyp->getMediaType( ).getStr( ) );
106 fwprintf( fstream, OUString("Subtype: %s\n"), xMCntTyp->getMediaSubtype( ).getStr( ) );
108 Sequence< OUString > seqParam = xMCntTyp->getParameters( );
109 sal_Int32 nParams = seqParam.getLength( );
111 for ( sal_Int32 i = 0; i < nParams; i++ )
113 fwprintf( fstream, OUString("PName: %s\n"), seqParam[i].getStr( ) );
114 fwprintf( fstream, OUString("PValue: %s\n"), xMCntTyp->getParameterValue( seqParam[i] ).getStr( ) );
117 catch( IllegalArgumentException& ex )
119 fwprintf( fstream, OUString("Read incorrect content type!\n\n") );
121 catch( NoSuchElementException& )
123 fwprintf( fstream, OUString("Value of parameter not available\n") );
125 catch( ... )
127 fwprintf( fstream, OUString("Unknown error!\n\n") );
130 fwprintf( fstream, OUString("\n#############################################\n\n") );
133 fclose( fstream );
135 return sal_True;
138 // main
140 int SAL_CALL main( int nArgc, char* argv[] )
142 if ( nArgc != 3 )
143 printf( "Start with: testcnttype input-file output-file\n" );
145 // get the global service-manager
147 OUString rdbName = OUString( RDB_SYSPATH );
148 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
150 // Print a message if an error occurred.
151 if ( !g_xFactory.is( ) )
153 OSL_FAIL("Can't create RegistryServiceFactory");
154 return(-1);
157 vector< string > vecCntTypes;
159 // open input-file and read the data
160 if ( !readCntTypesFromFileIntoVector( argv[1], vecCntTypes ) )
162 printf( "Can't open input file" );
163 ShutdownServiceMgr( g_xFactory );
166 Reference< XMimeContentTypeFactory >
167 xMCntTypeFactory( g_xFactory->createInstance("com.sun.star.datatransfer.MimeContentTypeFactory"), UNO_QUERY );
169 if ( !xMCntTypeFactory.is( ) )
171 OSL_FAIL( "Error creating MimeContentTypeFactory Service" );
172 return(-1);
175 if ( !processCntTypesAndWriteResultIntoFile( argv[2], vecCntTypes, xMCntTypeFactory ) )
177 printf( "Can't open output file" );
178 ShutdownServiceMgr( g_xFactory );
181 // shutdown the service manager
183 ShutdownServiceMgr( g_xFactory );
185 return 0;
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */