Skip to content

Commit

Permalink
changed to reading file for data
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Feb 26, 2012
1 parent 2d0d16a commit 6e9560d
Show file tree
Hide file tree
Showing 4 changed files with 945 additions and 3 deletions.
1 change: 1 addition & 0 deletions multipart_form.dart
Expand Up @@ -2,6 +2,7 @@ class MultipartForm {
MultipartForm(){
}
void parse(HTTPRequest req, Function cb){

req.dataReceived = (List<int> data){
data.forEach((value){
print('value is $value');
Expand Down
54 changes: 51 additions & 3 deletions test/multipart_test.dart
Expand Up @@ -2,6 +2,7 @@
#import('../lib/testing/unittest/unittest_vm.dart');
#import('../multipart_library.dart');
#import('../lib/HTTP/http.dart');
#import('dart:io');

void main(){
testMultipartForm();
Expand All @@ -23,20 +24,67 @@ class HTTPRequestMockImpl implements HTTPRequest{
}
}

List<int> dataChunkOne = const [10,13,10,13];
List<int> dataChunkTwo = const [13,10,13,10];

testMultipartForm(){
List<int> dataChunkOne = const [10,13,10,13];
List<int> dataChunkTwo = const [13,10,13,10];
HTTPRequestMockImpl req = new HTTPRequestMockImpl();
MultipartForm form = new MultipartForm();
asyncTest('MultipartForm ideal scenario',1, (){
form.parse(req, (err, fields, files) {
print('err is $err, fields is $fields, and files is $files');
callbackDone();
Expect.equals('ones', err);
Expect.equals('one', err);
});
req.invokeDataReceivedHandler(dataChunkOne);
req.invokeDataReceivedHandler(dataChunkTwo);
req.invokeDataEndHandler();
});

req = new HTTPRequestMockImpl();
form = new MultipartForm();
String fileName = "./resources/test.dat";
int result;
int bytesRead;
List<int> buffer = new List<int>();
ChunkedInputStream x = new ChunkedInputStream((new File(fileName)).openInputStream());
x.chunkSize = 1024;
x.dataHandler = () {
buffer.addAll(x.read());
print('in dataHandler...${buffer.length}');
};
x.closeHandler = () {
print('finished reading ${buffer.length} bytes.');
bytesRead = buffer.length;
//MultipartParser multipartParser = new MultipartParser();
//multipartParser.boundary = '-------WebKitFormBoundaryrMpAWVGZS3EX1kAY';

asyncTest('MultipartForm ideal scenario, from file',1, (){
form.parse(req, (err, fields, files) {
print('err is $err, fields is $fields, and files is $files');
callbackDone();
Expect.equals('one', err);
});
req.invokeDataReceivedHandler(buffer);
//req.invokeDataReceivedHandler(dataChunkTwo);
req.invokeDataEndHandler();
});


//result = multipartParser.write(buffer);
//print('expected is $bytesRead');
//print('result is $result');
};


// asyncTest('MultipartForm ideal scenario',1, (){
// form.parse(req, (err, fields, files) {
// print('err is $err, fields is $fields, and files is $files');
// callbackDone();
// Expect.equals('one', err);
// });
// req.invokeDataReceivedHandler(dataChunkOne);
// req.invokeDataReceivedHandler(dataChunkTwo);
// req.invokeDataEndHandler();
// });
}

0 comments on commit 6e9560d

Please sign in to comment.