mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Expose zip archive reading support (issue #30).
Move ClientReadHandler to CefByteReadHandler in cef_wrapper.h. Add support for the time_t data type to cef_parser.py. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@125 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "include/cef_wrapper.h"
|
||||
#include "cefclient.h"
|
||||
#include "binding_test.h"
|
||||
#include "download_handler.h"
|
||||
@@ -408,21 +409,21 @@ public:
|
||||
// Show the uiapp contents
|
||||
if(LoadBinaryResource(IDS_UIPLUGIN, dwSize, pBytes)) {
|
||||
resourceStream = CefStreamReader::CreateForHandler(
|
||||
new ClientReadHandler(pBytes, dwSize));
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
mimeType = L"text/html";
|
||||
}
|
||||
} else if(wcsstr(url.c_str(), L"/ps_logo2.png") != NULL) {
|
||||
// Any time we find "ps_logo2.png" in the URL substitute in our own image
|
||||
if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
|
||||
resourceStream = CefStreamReader::CreateForHandler(
|
||||
new ClientReadHandler(pBytes, dwSize));
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
mimeType = L"image/png";
|
||||
}
|
||||
} else if(wcsstr(url.c_str(), L"/logoball.png") != NULL) {
|
||||
// Load the "logoball.png" image resource.
|
||||
if(LoadBinaryResource(IDS_LOGOBALL, dwSize, pBytes)) {
|
||||
resourceStream = CefStreamReader::CreateForHandler(
|
||||
new ClientReadHandler(pBytes, dwSize));
|
||||
new CefByteReadHandler(pBytes, dwSize, NULL));
|
||||
mimeType = L"image/png";
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "resource_util.h"
|
||||
|
||||
|
||||
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
|
||||
{
|
||||
extern HINSTANCE hInst;
|
||||
@@ -24,67 +23,3 @@ bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ClientReadHandler implementation
|
||||
|
||||
ClientReadHandler::ClientReadHandler(LPBYTE pBytes, DWORD dwSize)
|
||||
: bytes_(pBytes), size_(dwSize), offset_(0) {}
|
||||
|
||||
size_t ClientReadHandler::Read(void* ptr, size_t size, size_t n)
|
||||
{
|
||||
Lock();
|
||||
size_t s = (size_ - offset_) / size;
|
||||
size_t ret = min(n, s);
|
||||
memcpy(ptr, bytes_ + offset_, ret * size);
|
||||
offset_ += ret * size;
|
||||
Unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ClientReadHandler::Seek(long offset, int whence)
|
||||
{
|
||||
int rv = -1L;
|
||||
Lock();
|
||||
switch(whence) {
|
||||
case SEEK_CUR:
|
||||
if(offset_ + offset > size_) {
|
||||
break;
|
||||
}
|
||||
offset_ += offset;
|
||||
rv = offset_;
|
||||
break;
|
||||
case SEEK_END:
|
||||
if(offset > (int)size_) {
|
||||
break;
|
||||
}
|
||||
offset_ = size_ - offset;
|
||||
rv = offset_;
|
||||
case SEEK_SET:
|
||||
if(offset > (int)size_) {
|
||||
break;
|
||||
}
|
||||
offset_ = offset;
|
||||
rv = offset_;
|
||||
break;
|
||||
}
|
||||
Unlock();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
long ClientReadHandler::Tell()
|
||||
{
|
||||
Lock();
|
||||
long rv = offset_;
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
int ClientReadHandler::Eof()
|
||||
{
|
||||
Lock();
|
||||
int rv = (offset_ >= size_);
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
@@ -6,34 +6,5 @@
|
||||
|
||||
#include "include/cef.h"
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
// Load a resource of type BINARY
|
||||
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes);
|
||||
|
||||
|
||||
// Implementation of the stream read handler for reading in-memory data.
|
||||
class ClientReadHandler : public CefThreadSafeBase<CefReadHandler>
|
||||
{
|
||||
public:
|
||||
ClientReadHandler(LPBYTE pBytes, DWORD dwSize);
|
||||
|
||||
// Read raw binary data.
|
||||
virtual size_t Read(void* ptr, size_t size, size_t n);
|
||||
|
||||
// Seek to the specified offset position. |whence| may be any one of
|
||||
// SEEK_CUR, SEEK_END or SEEK_SET.
|
||||
virtual int Seek(long offset, int whence);
|
||||
|
||||
// Return the current offset position.
|
||||
virtual long Tell();
|
||||
|
||||
// Return non-zero if at end of file.
|
||||
virtual int Eof();
|
||||
|
||||
private:
|
||||
LPBYTE bytes_;
|
||||
DWORD size_, offset_;
|
||||
};
|
||||
|
@@ -2,6 +2,7 @@
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "include/cef_wrapper.h"
|
||||
#include "scheme_test.h"
|
||||
#include "string_util.h"
|
||||
#include "resource_util.h"
|
||||
|
254
tests/unittests/zip_reader_unittest.cc
Normal file
254
tests/unittests/zip_reader_unittest.cc
Normal file
@@ -0,0 +1,254 @@
|
||||
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "include/cef_wrapper.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
unsigned char g_test_zip[] = {
|
||||
0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x7f,
|
||||
0x57, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61,
|
||||
0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x50, 0x4b, 0x03, 0x04, 0x0a,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x7f, 0x57, 0x3d, 0xf8, 0x47, 0x0c,
|
||||
0xc6, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00,
|
||||
0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76,
|
||||
0x65, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x2e, 0x74, 0x78, 0x74,
|
||||
0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x6f, 0x66, 0x20,
|
||||
0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x2e, 0x50, 0x4b, 0x03, 0x04, 0x0a,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x7f, 0x57, 0x3d, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
|
||||
0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76,
|
||||
0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x31, 0x2f, 0x50,
|
||||
0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x7f, 0x57,
|
||||
0x3d, 0x43, 0xe3, 0x11, 0x5f, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
|
||||
0x00, 0x21, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72,
|
||||
0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
|
||||
0x20, 0x31, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x61, 0x2e, 0x74,
|
||||
0x78, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x6f,
|
||||
0x66, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x41, 0x2e, 0x50, 0x4b,
|
||||
0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x7f, 0x57, 0x3d,
|
||||
0x80, 0xb0, 0x3c, 0x74, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00,
|
||||
0x21, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63,
|
||||
0x68, 0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20,
|
||||
0x31, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x62, 0x2e, 0x74, 0x78,
|
||||
0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x6f, 0x66,
|
||||
0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x42, 0x2e, 0x50, 0x4b, 0x03,
|
||||
0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x7f, 0x57, 0x3d, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
|
||||
0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68,
|
||||
0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x31,
|
||||
0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x31, 0x61, 0x2f, 0x50,
|
||||
0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x7f, 0x57,
|
||||
0x3d, 0x15, 0xed, 0x04, 0x2c, 0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00,
|
||||
0x00, 0x2c, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72,
|
||||
0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
|
||||
0x20, 0x31, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x31, 0x61,
|
||||
0x2f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x61, 0x31, 0x2e, 0x74, 0x78,
|
||||
0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x6f, 0x66,
|
||||
0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x41, 0x31, 0x2e, 0x50, 0x4b,
|
||||
0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x7f, 0x57, 0x3d,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x16, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63,
|
||||
0x68, 0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20,
|
||||
0x32, 0x2f, 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x80, 0x57, 0x3d, 0x1a, 0x5d, 0x57, 0x5d, 0x14, 0x00, 0x00, 0x00,
|
||||
0x14, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74,
|
||||
0x5f, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c,
|
||||
0x64, 0x65, 0x72, 0x20, 0x32, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x32,
|
||||
0x61, 0x2e, 0x74, 0x78, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
|
||||
0x73, 0x20, 0x6f, 0x66, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x32, 0x41,
|
||||
0x2e, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x67, 0x7f, 0x57, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74,
|
||||
0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x2f,
|
||||
0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x70, 0x7f, 0x57, 0x3d, 0xf8, 0x47, 0x0c, 0xc6, 0x13, 0x00, 0x00, 0x00,
|
||||
0x13, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x74, 0x65,
|
||||
0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x66,
|
||||
0x69, 0x6c, 0x65, 0x20, 0x31, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x01,
|
||||
0x02, 0x14, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x7f, 0x57,
|
||||
0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
|
||||
0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f,
|
||||
0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64,
|
||||
0x65, 0x72, 0x20, 0x31, 0x2f, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x0a,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x7f, 0x57, 0x3d, 0x43, 0xe3, 0x11,
|
||||
0x5f, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xa7,
|
||||
0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68,
|
||||
0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x31,
|
||||
0x2f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x31, 0x61, 0x2e, 0x74, 0x78, 0x74,
|
||||
0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x78, 0x7f, 0x57, 0x3d, 0x80, 0xb0, 0x3c, 0x74, 0x14, 0x00, 0x00, 0x00,
|
||||
0x14, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0x74, 0x65,
|
||||
0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x66,
|
||||
0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x31, 0x2f, 0x66, 0x69, 0x6c, 0x65,
|
||||
0x20, 0x31, 0x62, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x01, 0x02, 0x14,
|
||||
0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x7f, 0x57, 0x3d, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
|
||||
0x00, 0x4d, 0x01, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72,
|
||||
0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
|
||||
0x20, 0x31, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x31, 0x61,
|
||||
0x2f, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x7c, 0x7f, 0x57, 0x3d, 0x15, 0xed, 0x04, 0x2c, 0x15, 0x00, 0x00,
|
||||
0x00, 0x15, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x8b, 0x01, 0x00, 0x00, 0x74,
|
||||
0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x2f,
|
||||
0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x31, 0x2f, 0x66, 0x6f, 0x6c,
|
||||
0x64, 0x65, 0x72, 0x20, 0x31, 0x61, 0x2f, 0x66, 0x69, 0x6c, 0x65, 0x20,
|
||||
0x31, 0x61, 0x31, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b, 0x01, 0x02, 0x14,
|
||||
0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x7f, 0x57, 0x3d, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
|
||||
0x00, 0xea, 0x01, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72,
|
||||
0x63, 0x68, 0x69, 0x76, 0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
|
||||
0x20, 0x32, 0x2f, 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x02, 0x80, 0x57, 0x3d, 0x1a, 0x5d, 0x57, 0x5d, 0x14,
|
||||
0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x1e, 0x02, 0x00,
|
||||
0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76,
|
||||
0x65, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x20, 0x32, 0x2f, 0x66,
|
||||
0x69, 0x6c, 0x65, 0x20, 0x32, 0x61, 0x2e, 0x74, 0x78, 0x74, 0x50, 0x4b,
|
||||
0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x09, 0x00, 0x9d, 0x02,
|
||||
0x00, 0x00, 0x71, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// Test Zip reading.
|
||||
TEST(ZipReaderTest, Read)
|
||||
{
|
||||
// Create the stream reader.
|
||||
CefRefPtr<CefStreamReader> stream(
|
||||
CefStreamReader::CreateForData(g_test_zip, sizeof(g_test_zip) - 1));
|
||||
ASSERT_TRUE(stream.get() != NULL);
|
||||
|
||||
// Create the Zip reader.
|
||||
CefRefPtr<CefZipReader> reader(CefZipReader::Create(stream));
|
||||
ASSERT_TRUE(reader.get() != NULL);
|
||||
|
||||
char buff[25];
|
||||
|
||||
// Walk through the archive contents.
|
||||
ASSERT_TRUE(reader->MoveToFirstFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/");
|
||||
ASSERT_EQ(reader->GetFileSize(), 0);
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/file 1.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 19);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 19);
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1.", 19));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/");
|
||||
ASSERT_EQ(reader->GetFileSize(), 0);
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/file 1a.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 20);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 20);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1A.", 20));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/file 1b.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 20);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 20);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1B.", 20));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/folder 1a/");
|
||||
ASSERT_EQ(reader->GetFileSize(), 0);
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(),
|
||||
L"test_archive/folder 1/folder 1a/file 1a1.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 21);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 21);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1A1.", 21));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 2/");
|
||||
ASSERT_EQ(reader->GetFileSize(), 0);
|
||||
|
||||
ASSERT_TRUE(reader->MoveToNextFile());
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 2/file 2a.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 20);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 20);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 2A.", 20));
|
||||
|
||||
ASSERT_FALSE(reader->MoveToNextFile());
|
||||
|
||||
// Try seeking a particular file
|
||||
ASSERT_TRUE(reader->MoveToFile(L"TEST_ARCHIVE/FOLDER 1/FILE 1B.TXT", false));
|
||||
ASSERT_EQ(reader->GetFileName(), L"test_archive/folder 1/file 1b.txt");
|
||||
ASSERT_EQ(reader->GetFileSize(), 20);
|
||||
ASSERT_TRUE(reader->OpenFile(L""));
|
||||
ASSERT_EQ(reader->ReadFile(buff, sizeof(buff)), 20);
|
||||
ASSERT_TRUE(reader->CloseFile());
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents of file 1B.", 20));
|
||||
|
||||
ASSERT_TRUE(reader->MoveToFile(L"test_archive/folder 1/file 1b.txt", true));
|
||||
ASSERT_FALSE(reader->MoveToFile(L"test_archive/folder 1/FILE 1B.txt", true));
|
||||
|
||||
ASSERT_TRUE(reader->Close());
|
||||
}
|
||||
|
||||
// Test CefZipArchive object.
|
||||
TEST(ZipReaderTest, ReadArchive)
|
||||
{
|
||||
// Create the stream reader.
|
||||
CefRefPtr<CefStreamReader> stream(
|
||||
CefStreamReader::CreateForData(g_test_zip, sizeof(g_test_zip) - 1));
|
||||
ASSERT_TRUE(stream.get() != NULL);
|
||||
|
||||
// Create the Zip archive object.
|
||||
CefRefPtr<CefZipArchive> archive(new CefZipArchive());
|
||||
|
||||
ASSERT_EQ(archive->Load(stream, false), 5);
|
||||
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/file 1.txt"));
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/folder 1/file 1a.txt"));
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/FOLDER 1/file 1b.txt"));
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/folder 1/folder 1a/file 1a1.txt"));
|
||||
ASSERT_TRUE(archive->HasFile(L"test_archive/folder 2/file 2a.txt"));
|
||||
|
||||
// Test content retrieval.
|
||||
CefRefPtr<CefZipArchive::File> file;
|
||||
file = archive->GetFile(L"test_archive/folder 2/file 2a.txt");
|
||||
ASSERT_TRUE(file.get());
|
||||
|
||||
ASSERT_EQ(file->GetDataSize(), 20);
|
||||
ASSERT_TRUE(!strncmp(reinterpret_cast<const char*>(file->GetData()),
|
||||
"Contents of file 2A.", 20));
|
||||
|
||||
// Test stream reading.
|
||||
CefRefPtr<CefStreamReader> reader(file->GetStreamReader());
|
||||
ASSERT_TRUE(reader.get());
|
||||
|
||||
char buff[8];
|
||||
ASSERT_EQ(reader->Read(buff, 1, 8), 8);
|
||||
ASSERT_TRUE(!strncmp(buff, "Contents", 8));
|
||||
ASSERT_EQ(reader->Read(buff, 1, 8), 8);
|
||||
ASSERT_TRUE(!strncmp(buff, " of file", 8));
|
||||
ASSERT_EQ(reader->Read(buff, 1, 8), 4);
|
||||
ASSERT_TRUE(!strncmp(buff, " 2A.", 4));
|
||||
ASSERT_TRUE(reader->Eof());
|
||||
}
|
Reference in New Issue
Block a user