What's new? | Help | Directory | Sign in
Google
gears
Improving Your Web Browser
  
  
  
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright 2008 Google Inc. All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#import <cstring>

#import "gears/blob/blob_input_stream_sf.h"
#import "gears/blob/buffer_blob.h"
#import "third_party/scoped_ptr/scoped_ptr.h"

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define LOCATION __FILE__ ", line " TOSTRING(__LINE__)
#undef TEST_ASSERT
#define TEST_ASSERT(b) \
{ \
if (!(b)) { \
LOG(("TestBlobInputStreamSf - failed (%d)\n", __LINE__)); \
assert(error); \
if (!error->empty()) *error += STRING16(L", "); \
*error += STRING16(L"failed at " LOCATION); \
return false; \
} \
}

namespace {
// Amount of data that we create (8MB).
const std::vector<uint8>::size_type data_size(1024 * 1024 * 8);

// Buffer for holding that amount of data.
uint8_t *buffer(0);
}

// This function assumes that the stream passed in has |data_size|
// bytes available for reading.
static bool TestBlobInputStreamSfReadFullStream(std::string16 *error,
NSInputStream *stream) {
assert(stream);
BOOL rslt = [stream hasBytesAvailable];
TEST_ASSERT(rslt == YES);

memset(buffer, 0, data_size);
NSInteger numRead = [stream read:buffer maxLength:8];
TEST_ASSERT(numRead == 8);
TEST_ASSERT(buffer[0] == 79);
TEST_ASSERT(buffer[7] == 79);
TEST_ASSERT(buffer[8] == 0);

memset(buffer, 0, data_size);
numRead = [stream read:buffer maxLength:data_size];
TEST_ASSERT(numRead == data_size - 8);
TEST_ASSERT(buffer[0] == 79);
TEST_ASSERT(buffer[data_size - 9] == 79);
TEST_ASSERT(buffer[data_size - 8] == 0);

rslt = [stream hasBytesAvailable];
TEST_ASSERT(rslt == YES); // Testing OSX 10.4 workaround.

memset(buffer, 0, data_size);
numRead = [stream read:buffer maxLength:data_size];
TEST_ASSERT(numRead == 0);
TEST_ASSERT(buffer[0] == 0);

return true;
}

bool TestBlobInputStreamSf(std::string16 *error) {
// Some data we can use to initialize our blobs.
std::vector<uint8> data(data_size, 79);
scoped_refptr<BlobInterface> blob(new BufferBlob(&data));
bool ok = true;

// Initialize the buffer.
buffer = new uint8[data_size];
scoped_array<uint8> buffer_cleaner(buffer);

{
BlobInputStream *stream;

// Test BlobInputStream::initFromBlob
stream = [[[BlobInputStream alloc] initFromBlob:blob.get()] autorelease];
uint8_t *bufferPointer;
NSUInteger len;
[stream open];
BOOL rslt = [stream getBuffer:&bufferPointer length:&len];
TEST_ASSERT(rslt == NO);

ok &= TestBlobInputStreamSfReadFullStream(error, stream);
[stream close];
}
{
// Test a BlobInputStream that has not been initialized with a blob.
BlobInputStream *blobStream = [[[BlobInputStream alloc] init] autorelease];

[blobStream open];
BOOL rslt = [blobStream hasBytesAvailable];
TEST_ASSERT(rslt == YES); // Testing OSX 10.4 workaround.

memset(buffer, 0, data_size);
NSInteger numRead = [blobStream read:buffer maxLength:data_size];
TEST_ASSERT(numRead == 0);
TEST_ASSERT(buffer[0] == 0);
[blobStream close];

// Hand a blob to the BlobInputStream.
[blobStream reset:blob.get()];
[blobStream open];
ok &= TestBlobInputStreamSfReadFullStream(error, blobStream);
[blobStream close];

// reset a BlobInputStream that already has a blob assigned.
[blobStream reset:blob.get()];
[blobStream open];
ok &= TestBlobInputStreamSfReadFullStream(error, blobStream);
[blobStream close];
}

return ok;
}
Show details Hide details

Change log

r2364 by gears.daemon on Jul 15, 2008   Diff
[Author: playmobil]

* #include -> #import in all obj-c files.
* Added include guards to all obj-c
headers.
 * Removed a few stale Safari files.

PRESUBMIT=passed
R=dimich
CC=gears-eng@googlegroups.com
DELTA=339  (66 added, 171 deleted, 102
changed)
...
Go to: 
Project members, sign in to write a code review

Older revisions

r2066 by gears.daemon on Jun 23, 2008   Diff
[Author: bgarcia]

Replace all HttpRequest::Send*
functions with a single
Send(BlobInterface *) function.
...
r2012 by gears.daemon on Jun 18, 2008   Diff
[Author: bgarcia]

Fix BlobInputStream on Safari.
Activate all blob testing for Safari.

...
r1936 by gears.daemon on Jun 11, 2008   Diff
[Author: fry]

make blob support official!

PRESUBMIT=passed
...
All revisions of this file

File info

Size: 4934 bytes, 140 lines