~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to testsuite/libbase/CurlStreamTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
//   Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
3
 
// 
4
 
// This program is free software; you can redistribute it and/or modify
5
 
// it under the terms of the GNU General Public License as published by
6
 
// the Free Software Foundation; either version 3 of the License, or
7
 
// (at your option) any later version.
8
 
// 
9
 
// This program is distributed in the hope that it will be useful,
10
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
// GNU General Public License for more details.
13
 
// 
14
 
// You should have received a copy of the GNU General Public License
15
 
// along with this program; if not, write to the Free Software
16
 
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
 
18
 
#ifdef HAVE_CONFIG_H
19
 
#include "gnashconfig.h"
20
 
#endif
21
 
 
22
 
#include "NetworkAdapter.h"
23
 
#include "tu_file.h"
24
 
 
25
 
#include <memory>               // for auto_ptr
26
 
#include <cstdio>
27
 
#include <iostream>
28
 
#include <cassert>
29
 
 
30
 
using namespace std;
31
 
 
32
 
const char* post = NULL;
33
 
 
34
 
#define CHUNK_SIZE 4
35
 
 
36
 
static void
37
 
dump_curl(const char* url, ostream& os)
38
 
{
39
 
        std::auto_ptr<gnash::IOChannel> reader;
40
 
        if ( post )
41
 
        {
42
 
                reader.reset( gnash::NetworkAdapter::make_stream(url, post) );
43
 
        }
44
 
        else
45
 
        {
46
 
                reader.reset( gnash::NetworkAdapter::make_stream(url) );
47
 
        }
48
 
 
49
 
        assert(reader.get());
50
 
 
51
 
        char buf[CHUNK_SIZE];
52
 
 
53
 
        while (size_t read = reader->read(buf, CHUNK_SIZE) )
54
 
        {
55
 
                for (size_t i=0; i<read; i++) {
56
 
                        os << buf[i];
57
 
                }
58
 
        }
59
 
 
60
 
}
61
 
 
62
 
static void
63
 
dump_tu_file(const char* url, ostream& os)
64
 
{
65
 
        tu_file* reader = new tu_file(url, "r");
66
 
        assert(reader);
67
 
        if (reader->bad()) return;
68
 
 
69
 
        char buf[CHUNK_SIZE];
70
 
 
71
 
        while ( size_t read = reader->read(buf, CHUNK_SIZE) )
72
 
        {
73
 
                for (size_t i=0; i<read; i++) {
74
 
                        os << buf[i];
75
 
                }
76
 
        }
77
 
 
78
 
        if ( reader->eof() )
79
 
                printf("-EOF-\n");
80
 
 
81
 
}
82
 
 
83
 
static void
84
 
dump_file(const char* url, ostream& os)
85
 
{
86
 
        FILE* f = fopen(url, "r");
87
 
        if (!f) return;
88
 
 
89
 
        char buf[CHUNK_SIZE];
90
 
 
91
 
        while ( size_t read=fread(buf, 1, CHUNK_SIZE, f) )
92
 
        {
93
 
                for (size_t i=0; i<read; i++) {
94
 
                        os << buf[i];
95
 
                }
96
 
        }
97
 
 
98
 
}
99
 
 
100
 
int
101
 
main(int argc, char** argv)
102
 
{
103
 
        const char* input = INPUT; // Should be the path to this file
104
 
 
105
 
        if ( argc == 1 )
106
 
        {
107
 
                cerr << "Usage: " << argv[0] << " <url> [<postdata>]" << endl;
108
 
                exit(EXIT_FAILURE);
109
 
        }
110
 
 
111
 
        if ( argc > 1 ) input = argv[1];
112
 
 
113
 
        if ( argc > 2 ) post = argv[2];
114
 
 
115
 
        cout << "input: " << input << endl;
116
 
        if ( post ) cout << "post data: " << post << endl;
117
 
 
118
 
#if 0
119
 
        cout << "FILE" << endl;
120
 
        dump_file(input, cout);
121
 
        cout << "TU_FILE" << endl;
122
 
        dump_tu_file(input, cout);
123
 
#endif
124
 
        cout << "CURL" << endl;
125
 
        dump_curl(input, cout);
126
 
 
127
 
        return 0;
128
 
}
129