1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: urltest.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "shellexec.hxx"
33 #include <osl/process.h>
40 // -----------------------------------------------------------------------
42 int main(int argc
, const char *argv
[])
48 fprintf(stderr
, "Usage: urltest <urllist>\n");
52 FILE * fp
= fopen( argv
[1], "r" );
59 // expect urltest.sh beside this binary
61 size_t len
= strlen(argv
[0]);
62 strcpy( line
, argv
[0] );
63 strcpy( line
+ len
, ".sh " );
66 unsigned int errors
= 0;
68 // read url(s) to test from file
70 while( NULL
!= fgets(url
, sizeof(url
), fp
))
72 // remove trailing line break
73 strtok( url
, "\r\n" );
75 printf( "Passing URL: %s\n", url
);
77 // test the encoding functionality from shellexec.cxx
78 rtl::OString
aURL( url
);
79 rtl::OStringBuffer aBuffer
;
80 escapeForShell(aBuffer
, aURL
);
82 // append encoded URL as (only) parameter to the script
83 strcpy( line
+ len
, aBuffer
.getStr() );
85 printf( "Command line: %s\n", line
);
87 FILE * pipe
= popen( line
, "r" );
92 // initialize buffer with '\0'
93 memset(buffer
, '\0', BUFSIZ
);
95 // read the output of the script
96 if(NULL
== fgets( buffer
, BUFSIZ
, pipe
))
98 perror("FAILED: output of script could not be read");
104 // remove trailing line break again
105 strtok( buffer
, "\r\n" );
107 int n
= pclose(pipe
);
110 printf("FAILED: fclose returned %d\n\n", n
);
115 if( 0 == strcmp( url
, buffer
) )
117 // strings are identical: good !
123 printf( "FAILED: returned string is %s\n\n", buffer
);
146 printf( "Number of tests failing: %d\n", errors
);
150 printf( "All tests passed OK.\n" );