fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / shell / source / unix / exec / urltest.cxx
blob1a48b180d54ab6db7b09702651c3e10a5c8dc9ad
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 "shellexec.hxx"
22 #include <osl/process.h>
24 #include <stdio.h>
25 #include <limits.h>
26 #include <string.h>
27 #include <strings.h>
31 int main(int argc, const char *argv[])
33 int ret = 0;
35 if( argc != 2 )
37 fprintf(stderr, "Usage: urltest <urllist>\n");
38 return -1;
41 FILE * fp = fopen( argv[1], "r" );
42 if( NULL == fp )
44 perror( argv[1] );
45 return -1;
48 // expect urltest.sh beside this binary
49 char line[LINE_MAX];
50 size_t len = strlen(argv[0]);
51 strcpy( line, argv[0] );
52 strcpy( line + len, ".sh " );
53 len += 4;
55 unsigned int errors = 0;
57 // read url(s) to test from file
58 char url[512];
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
67 OString aURL( url );
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" );
77 if( NULL != pipe )
79 char buffer[BUFSIZ];
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");
88 printf( "\n");
89 ++errors;
90 continue;
93 // remove trailing line break again
94 strtok( buffer, "\r\n" );
96 int n = pclose(pipe);
97 if( 0 != n )
99 printf("FAILED: fclose returned %d\n\n", n );
100 ++errors;
101 continue;
104 if( 0 == strcmp( url, buffer ) )
106 // strings are identical: good !
107 printf( "OK\n\n");
109 else
111 // compare failed
112 printf( "FAILED: returned string is %s\n\n", buffer);
113 ++errors;
117 else
119 perror( line );
120 ret = -2;
121 break;
125 if( ferror( fp ) )
127 perror( argv[1] );
128 ret = -1;
131 fclose( fp );
133 if( errors )
135 printf( "Number of tests failing: %u\n", errors);
136 ret = -3;
138 else
139 printf( "All tests passed OK.\n" );
142 return ret;
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */