1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "shellexec.hxx"
22 #include <osl/process.h>
31 int main(int argc
, const char *argv
[])
37 fprintf(stderr
, "Usage: urltest <urllist>\n");
41 FILE * fp
= fopen( argv
[1], "r" );
48 // expect urltest.sh beside this binary
50 size_t len
= strlen(argv
[0]);
51 strcpy( line
, argv
[0] );
52 strcpy( line
+ len
, ".sh " );
55 unsigned int errors
= 0;
57 // read url(s) to test from file
59 while( NULL
!= fgets(url
, sizeof(url
), fp
))
61 // remove trailing line break
62 strtok( url
, "\r\n" );
64 printf( "Passing URL: %s\n", url
);
66 // test the encoding functionality from shellexec.cxx
68 OStringBuffer aBuffer
;
69 escapeForShell(aBuffer
, aURL
);
71 // append encoded URL as (only) parameter to the script
72 strcpy( line
+ len
, aBuffer
.getStr() );
74 printf( "Command line: %s\n", line
);
76 FILE * pipe
= popen( line
, "r" );
81 // initialize buffer with '\0'
82 memset(buffer
, '\0', BUFSIZ
);
84 // read the output of the script
85 if(NULL
== fgets( buffer
, BUFSIZ
, pipe
))
87 perror("FAILED: output of script could not be read");
93 // remove trailing line break again
94 strtok( buffer
, "\r\n" );
99 printf("FAILED: fclose returned %d\n\n", n
);
104 if( 0 == strcmp( url
, buffer
) )
106 // strings are identical: good !
112 printf( "FAILED: returned string is %s\n\n", buffer
);
135 printf( "Number of tests failing: %u\n", errors
);
139 printf( "All tests passed OK.\n" );
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */