summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fxcodec/bmp/cfx_bmpdecompressor.cpp4
-rw-r--r--core/fxcodec/bmp/cfx_bmpdecompressor.h3
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.cpp7
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.h3
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.cpp7
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.h3
-rw-r--r--core/fxcodec/codec/cfx_codec_memory.cpp8
-rw-r--r--core/fxcodec/codec/cfx_codec_memory.h12
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp10
-rw-r--r--core/fxcodec/gif/cfx_gifcontext.cpp4
-rw-r--r--core/fxcodec/gif/cfx_gifcontext.h3
-rw-r--r--core/fxcodec/gif/cfx_gifcontext_unittest.cpp174
12 files changed, 126 insertions, 112 deletions
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
index 383955624c..a25afdf6c9 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
@@ -659,8 +659,8 @@ void CFX_BmpDecompressor::SaveDecodingStatus(int32_t status) {
decode_status_ = status;
}
-void CFX_BmpDecompressor::SetInputBuffer(uint8_t* src_buf, uint32_t src_size) {
- input_buffer_ = pdfium::MakeRetain<CFX_CodecMemory>(src_buf, src_size);
+void CFX_BmpDecompressor::SetInputBuffer(pdfium::span<uint8_t> src_buf) {
+ input_buffer_ = pdfium::MakeRetain<CFX_CodecMemory>(src_buf);
}
FX_FILESIZE CFX_BmpDecompressor::GetAvailInput(uint8_t** avail_buf) {
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.h b/core/fxcodec/bmp/cfx_bmpdecompressor.h
index 519297881a..ed013a2a09 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.h
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.h
@@ -15,6 +15,7 @@
#include <vector>
#include "core/fxcodec/codec/cfx_codec_memory.h"
+#include "third_party/base/span.h"
class CFX_BmpContext;
@@ -26,7 +27,7 @@ class CFX_BmpDecompressor {
void Error();
int32_t DecodeImage();
int32_t ReadHeader();
- void SetInputBuffer(uint8_t* src_buf, uint32_t src_size);
+ void SetInputBuffer(pdfium::span<uint8_t> src_buf);
FX_FILESIZE GetAvailInput(uint8_t** avail_buf);
jmp_buf jmpbuf_;
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp
index f4bfa010dc..75e59edf2b 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.cpp
+++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp
@@ -69,9 +69,6 @@ FX_FILESIZE CCodec_BmpModule::GetAvailInput(Context* pContext,
return ctx->m_Bmp.GetAvailInput(avail_buf_ptr);
}
-void CCodec_BmpModule::Input(Context* pContext,
- uint8_t* src_buf,
- uint32_t src_size) {
- auto* ctx = static_cast<CFX_BmpContext*>(pContext);
- ctx->m_Bmp.SetInputBuffer(src_buf, src_size);
+void CCodec_BmpModule::Input(Context* pContext, pdfium::span<uint8_t> src_buf) {
+ static_cast<CFX_BmpContext*>(pContext)->m_Bmp.SetInputBuffer(src_buf);
}
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.h b/core/fxcodec/codec/ccodec_bmpmodule.h
index ca2340d978..42d686e6f3 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.h
+++ b/core/fxcodec/codec/ccodec_bmpmodule.h
@@ -12,6 +12,7 @@
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "third_party/base/span.h"
class CFX_DIBAttribute;
@@ -34,7 +35,7 @@ class CCodec_BmpModule {
std::unique_ptr<Context> Start(Delegate* pDelegate);
FX_FILESIZE GetAvailInput(Context* pContext, uint8_t** avail_buf_ptr);
- void Input(Context* pContext, uint8_t* src_buf, uint32_t src_size);
+ void Input(Context* pContext, pdfium::span<uint8_t> src_buf);
int32_t ReadHeader(Context* pContext,
int32_t* width,
int32_t* height,
diff --git a/core/fxcodec/codec/ccodec_gifmodule.cpp b/core/fxcodec/codec/ccodec_gifmodule.cpp
index 7bf216e393..872d90f770 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.cpp
+++ b/core/fxcodec/codec/ccodec_gifmodule.cpp
@@ -72,9 +72,6 @@ uint32_t CCodec_GifModule::GetAvailInput(Context* pContext,
return context->GetAvailInput(avail_buf_ptr);
}
-void CCodec_GifModule::Input(Context* pContext,
- const uint8_t* src_buf,
- uint32_t src_size) {
- auto* context = static_cast<CFX_GifContext*>(pContext);
- context->SetInputBuffer((uint8_t*)src_buf, src_size);
+void CCodec_GifModule::Input(Context* pContext, pdfium::span<uint8_t> src_buf) {
+ static_cast<CFX_GifContext*>(pContext)->SetInputBuffer(src_buf);
}
diff --git a/core/fxcodec/codec/ccodec_gifmodule.h b/core/fxcodec/codec/ccodec_gifmodule.h
index cbc8fc6815..f14665ba2c 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.h
+++ b/core/fxcodec/codec/ccodec_gifmodule.h
@@ -13,6 +13,7 @@
#include "core/fxcodec/gif/cfx_gif.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
+#include "third_party/base/span.h"
class CFX_DIBAttribute;
@@ -43,7 +44,7 @@ class CCodec_GifModule {
std::unique_ptr<Context> Start(Delegate* pDelegate);
uint32_t GetAvailInput(Context* context, uint8_t** avail_buf_ptr);
- void Input(Context* context, const uint8_t* src_buf, uint32_t src_size);
+ void Input(Context* context, pdfium::span<uint8_t> src_buf);
CFX_GifDecodeStatus ReadHeader(Context* context,
int* width,
int* height,
diff --git a/core/fxcodec/codec/cfx_codec_memory.cpp b/core/fxcodec/codec/cfx_codec_memory.cpp
index 8eac02c9ee..b8cf97b098 100644
--- a/core/fxcodec/codec/cfx_codec_memory.cpp
+++ b/core/fxcodec/codec/cfx_codec_memory.cpp
@@ -6,13 +6,13 @@
#include <algorithm>
-CFX_CodecMemory::CFX_CodecMemory(uint8_t* buffer, size_t size)
- : buffer_(buffer), size_(size) {}
+CFX_CodecMemory::CFX_CodecMemory(pdfium::span<uint8_t> buffer)
+ : buffer_(buffer) {}
CFX_CodecMemory::~CFX_CodecMemory() = default;
bool CFX_CodecMemory::Seek(size_t pos) {
- if (pos > size_)
+ if (pos > buffer_.size())
return false;
pos_ = pos;
@@ -23,7 +23,7 @@ size_t CFX_CodecMemory::ReadBlock(void* buffer, size_t size) {
if (!buffer || !size || IsEOF())
return 0;
- size_t bytes_to_read = std::min(size, size_ - pos_);
+ size_t bytes_to_read = std::min(size, buffer_.size() - pos_);
memcpy(buffer, &buffer_[pos_], bytes_to_read);
pos_ += bytes_to_read;
return bytes_to_read;
diff --git a/core/fxcodec/codec/cfx_codec_memory.h b/core/fxcodec/codec/cfx_codec_memory.h
index 6eee72a32d..e726dc5320 100644
--- a/core/fxcodec/codec/cfx_codec_memory.h
+++ b/core/fxcodec/codec/cfx_codec_memory.h
@@ -6,27 +6,27 @@
#define CORE_FXCODEC_CODEC_CFX_CODEC_MEMORY_H_
#include "core/fxcrt/retain_ptr.h"
+#include "third_party/base/span.h"
class CFX_CodecMemory : public Retainable {
public:
template <typename T, typename... Args>
friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
- uint8_t* GetBuffer() { return buffer_; }
- size_t GetSize() const { return size_; }
+ uint8_t* GetBuffer() { return buffer_.data(); }
+ size_t GetSize() const { return buffer_.size(); }
size_t GetPosition() const { return pos_; }
- bool IsEOF() const { return pos_ >= size_; }
+ bool IsEOF() const { return pos_ >= buffer_.size(); }
size_t ReadBlock(void* buffer, size_t size);
// Sets the cursor position to |pos| if possible.
bool Seek(size_t pos);
private:
- CFX_CodecMemory(uint8_t* buffer, size_t size);
+ explicit CFX_CodecMemory(pdfium::span<uint8_t> buffer);
~CFX_CodecMemory() override;
- uint8_t* const buffer_;
- const size_t size_;
+ pdfium::span<uint8_t> const buffer_;
size_t pos_ = 0;
};
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index 8ebb119dff..c5fb1e3a13 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -765,7 +765,7 @@ bool CCodec_ProgressiveDecoder::BmpDetectImageType(CFX_DIBAttribute* pAttribute,
}
m_offSet += size;
- pBmpModule->Input(m_pBmpContext.get(), m_pSrcBuf, size);
+ pBmpModule->Input(m_pBmpContext.get(), {m_pSrcBuf, size});
std::vector<uint32_t> palette;
int32_t readResult = pBmpModule->ReadHeader(
m_pBmpContext.get(), &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom,
@@ -873,7 +873,7 @@ bool CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule,
return false;
}
m_offSet += dwSize;
- pBmpModule->Input(m_pBmpContext.get(), m_pSrcBuf, dwSize + dwAvail);
+ pBmpModule->Input(m_pBmpContext.get(), {m_pSrcBuf, dwSize + dwAvail});
return true;
}
@@ -969,8 +969,8 @@ bool CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
}
m_offSet += dwAmountToFetchFromFile;
- pGifModule->Input(m_pGifContext.get(), m_pSrcBuf,
- dwAmountToFetchFromFile + dwUnusedBuffer);
+ pGifModule->Input(m_pGifContext.get(),
+ {m_pSrcBuf, dwAmountToFetchFromFile + dwUnusedBuffer});
m_InvalidateGifBuffer = false;
return true;
}
@@ -989,7 +989,7 @@ bool CCodec_ProgressiveDecoder::GifDetectImageType(CFX_DIBAttribute* pAttribute,
return false;
}
m_offSet += size;
- pGifModule->Input(m_pGifContext.get(), m_pSrcBuf, size);
+ pGifModule->Input(m_pGifContext.get(), {m_pSrcBuf, size});
m_SrcComponents = 1;
CFX_GifDecodeStatus readResult = pGifModule->ReadHeader(
m_pGifContext.get(), &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
diff --git a/core/fxcodec/gif/cfx_gifcontext.cpp b/core/fxcodec/gif/cfx_gifcontext.cpp
index 4083072fbe..f746bc13c5 100644
--- a/core/fxcodec/gif/cfx_gifcontext.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext.cpp
@@ -342,8 +342,8 @@ CFX_GifDecodeStatus CFX_GifContext::LoadFrame(int32_t frame_num) {
return CFX_GifDecodeStatus::Error;
}
-void CFX_GifContext::SetInputBuffer(uint8_t* src_buf, uint32_t src_size) {
- input_buffer_ = pdfium::MakeRetain<CFX_CodecMemory>(src_buf, src_size);
+void CFX_GifContext::SetInputBuffer(pdfium::span<uint8_t> src_buf) {
+ input_buffer_ = pdfium::MakeRetain<CFX_CodecMemory>(src_buf);
}
uint32_t CFX_GifContext::GetAvailInput(uint8_t** avail_buf) const {
diff --git a/core/fxcodec/gif/cfx_gifcontext.h b/core/fxcodec/gif/cfx_gifcontext.h
index f96cf058b2..90657b05bb 100644
--- a/core/fxcodec/gif/cfx_gifcontext.h
+++ b/core/fxcodec/gif/cfx_gifcontext.h
@@ -16,6 +16,7 @@
#include "core/fxcodec/gif/cfx_lzwdecompressor.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "third_party/base/span.h"
class CFX_GifContext : public CCodec_GifModule::Context {
public:
@@ -40,7 +41,7 @@ class CFX_GifContext : public CCodec_GifModule::Context {
CFX_GifDecodeStatus ReadHeader();
CFX_GifDecodeStatus GetFrame();
CFX_GifDecodeStatus LoadFrame(int32_t frame_num);
- void SetInputBuffer(uint8_t* src_buf, uint32_t src_size);
+ void SetInputBuffer(pdfium::span<uint8_t> src_buf);
uint32_t GetAvailInput(uint8_t** avail_buf) const;
size_t GetFrameNum() const { return images_.size(); }
diff --git a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
index d6cfa1fd0d..0d8941f72f 100644
--- a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
@@ -22,122 +22,134 @@ class CFX_GifContextForTest : public CFX_GifContext {
};
TEST(CFX_GifContext, SetInputBuffer) {
- CFX_GifContextForTest context(nullptr, nullptr);
+ uint8_t buffer[] = {0x00, 0x01, 0x02};
+ {
+ // Context must not outlive its buffers.
+ CFX_GifContextForTest context(nullptr, nullptr);
- context.SetInputBuffer(nullptr, 0);
- EXPECT_EQ(nullptr, context.InputBuffer()->GetBuffer());
- EXPECT_EQ(0u, context.InputBuffer()->GetSize());
- EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({nullptr, 0});
+ EXPECT_EQ(nullptr, context.InputBuffer()->GetBuffer());
+ EXPECT_EQ(0u, context.InputBuffer()->GetSize());
+ EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer(nullptr, 100);
- EXPECT_EQ(nullptr, context.InputBuffer()->GetBuffer());
- EXPECT_EQ(100u, context.InputBuffer()->GetSize());
- EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({nullptr, 100});
+ EXPECT_EQ(nullptr, context.InputBuffer()->GetBuffer());
+ EXPECT_EQ(100u, context.InputBuffer()->GetSize());
+ EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- uint8_t buffer[] = {0x00, 0x01, 0x02};
- context.SetInputBuffer(buffer, 0);
- EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
- EXPECT_EQ(0u, context.InputBuffer()->GetSize());
- EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
-
- context.SetInputBuffer(buffer, 3);
- EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
- EXPECT_EQ(3u, context.InputBuffer()->GetSize());
- EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
-
- context.SetInputBuffer(buffer, 100);
- EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
- EXPECT_EQ(100u, context.InputBuffer()->GetSize());
- EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
-}
+ context.SetInputBuffer({buffer, 0});
+ EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
+ EXPECT_EQ(0u, context.InputBuffer()->GetSize());
+ EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
-TEST(CFX_GifContext, ReadData) {
- CFX_GifContextForTest context(nullptr, nullptr);
+ context.SetInputBuffer({buffer, 3});
+ EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
+ EXPECT_EQ(3u, context.InputBuffer()->GetSize());
+ EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- context.SetInputBuffer(nullptr, 0);
- EXPECT_FALSE(context.ReadData(nullptr, 0));
- EXPECT_FALSE(context.ReadData(nullptr, 10));
+ context.SetInputBuffer({buffer, 100});
+ EXPECT_EQ(buffer, context.InputBuffer()->GetBuffer());
+ EXPECT_EQ(100u, context.InputBuffer()->GetSize());
+ EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
+ }
+}
+TEST(CFX_GifContext, ReadData) {
std::vector<uint8_t> dest_buffer;
- EXPECT_FALSE(context.ReadData(dest_buffer.data(), 0));
- EXPECT_FALSE(context.ReadData(dest_buffer.data(), 10));
-
uint8_t src_buffer[] = {0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09};
- context.SetInputBuffer(src_buffer, 0);
- dest_buffer.resize(sizeof(src_buffer));
- EXPECT_FALSE(context.ReadData(dest_buffer.data(), sizeof(src_buffer)));
-
- context.SetInputBuffer(src_buffer, 1);
- EXPECT_FALSE(context.ReadData(dest_buffer.data(), sizeof(src_buffer)));
- EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
- EXPECT_FALSE(context.ReadData(nullptr, sizeof(src_buffer)));
- EXPECT_FALSE(context.ReadData(nullptr, 1));
- EXPECT_TRUE(context.ReadData(dest_buffer.data(), 1));
- EXPECT_EQ(src_buffer[0], dest_buffer[0]);
-
- context.SetInputBuffer(src_buffer, sizeof(src_buffer));
- EXPECT_FALSE(context.ReadData(nullptr, sizeof(src_buffer)));
- EXPECT_TRUE(context.ReadData(dest_buffer.data(), sizeof(src_buffer)));
- for (size_t i = 0; i < sizeof(src_buffer); i++)
- EXPECT_EQ(src_buffer[i], dest_buffer[i]);
-
- context.SetInputBuffer(src_buffer, sizeof(src_buffer));
- for (size_t i = 0; i < sizeof(src_buffer); i++) {
+ {
+ // Context must not outlive its buffers.
+ CFX_GifContextForTest context(nullptr, nullptr);
+
+ context.SetInputBuffer({nullptr, 0});
+ EXPECT_FALSE(context.ReadData(nullptr, 0));
+ EXPECT_FALSE(context.ReadData(nullptr, 10));
+
+ EXPECT_FALSE(context.ReadData(dest_buffer.data(), 0));
+ EXPECT_FALSE(context.ReadData(dest_buffer.data(), 10));
+
+ context.SetInputBuffer({src_buffer, 0});
+ dest_buffer.resize(sizeof(src_buffer));
+ EXPECT_FALSE(context.ReadData(dest_buffer.data(), sizeof(src_buffer)));
+
+ context.SetInputBuffer({src_buffer, 1});
+ EXPECT_FALSE(context.ReadData(dest_buffer.data(), sizeof(src_buffer)));
+ EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
+ EXPECT_FALSE(context.ReadData(nullptr, sizeof(src_buffer)));
+ EXPECT_FALSE(context.ReadData(nullptr, 1));
EXPECT_TRUE(context.ReadData(dest_buffer.data(), 1));
- EXPECT_EQ(src_buffer[i], dest_buffer[0]);
+ EXPECT_EQ(src_buffer[0], dest_buffer[0]);
+
+ context.SetInputBuffer(src_buffer);
+ EXPECT_FALSE(context.ReadData(nullptr, sizeof(src_buffer)));
+ EXPECT_TRUE(context.ReadData(dest_buffer.data(), sizeof(src_buffer)));
+ for (size_t i = 0; i < sizeof(src_buffer); i++)
+ EXPECT_EQ(src_buffer[i], dest_buffer[i]);
+
+ context.SetInputBuffer(src_buffer);
+ for (size_t i = 0; i < sizeof(src_buffer); i++) {
+ EXPECT_TRUE(context.ReadData(dest_buffer.data(), 1));
+ EXPECT_EQ(src_buffer[i], dest_buffer[0]);
+ }
}
}
TEST(CFX_GifContext, ReadGifSignature) {
CFX_GifContextForTest context(nullptr, nullptr);
-
{
uint8_t data[1];
- context.SetInputBuffer(data, 0);
+ context.SetInputBuffer({data, 0});
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadGifSignature());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// Make sure testing the entire signature
{
uint8_t data[] = {'G', 'I', 'F'};
- context.SetInputBuffer(data, sizeof(data));
+ context.SetInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadGifSignature());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
{
uint8_t data[] = {'N', 'O', 'T', 'G', 'I', 'F'};
- context.SetInputBuffer(data, sizeof(data));
+ context.SetInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// Make sure not matching GIF8*a
{
uint8_t data[] = {'G', 'I', 'F', '8', '0', 'a'};
- context.SetInputBuffer(data, sizeof(data));
+ context.SetInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// Make sure not matching GIF**a
{
uint8_t data[] = {'G', 'I', 'F', '9', '2', 'a'};
- context.SetInputBuffer(data, sizeof(data));
+ context.SetInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// One valid signature
{
uint8_t data[] = {'G', 'I', 'F', '8', '7', 'a'};
- context.SetInputBuffer(data, sizeof(data));
+ context.SetInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// The other valid signature
{
uint8_t data[] = {'G', 'I', 'F', '8', '9', 'a'};
- context.SetInputBuffer(data, sizeof(data));
+ context.SetInputBuffer(data);
EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadGifSignature());
EXPECT_EQ(6u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
}
@@ -145,15 +157,16 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
CFX_GifContextForTest context(nullptr, nullptr);
{
uint8_t data[1];
- context.SetInputBuffer(data, 0);
+ context.SetInputBuffer({data, 0});
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished,
context.ReadLogicalScreenDescriptor());
+ context.SetInputBuffer({});
}
// LSD with all the values zero'd
{
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)];
memset(&lsd, 0, sizeof(CFX_GifLocalScreenDescriptor));
- context.SetInputBuffer(lsd, sizeof(CFX_GifLocalScreenDescriptor));
+ context.SetInputBuffer(lsd);
EXPECT_EQ(CFX_GifDecodeStatus::Success,
context.ReadLogicalScreenDescriptor());
@@ -164,12 +177,13 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
EXPECT_EQ(0, context.height_);
EXPECT_EQ(0u, context.bc_index_);
EXPECT_EQ(0u, context.pixel_aspect_);
+ context.SetInputBuffer({});
}
// LSD with no global palette
{
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)] = {0x0A, 0x00, 0x00, 0x0F,
0x00, 0x01, 0x02};
- context.SetInputBuffer(lsd, sizeof(CFX_GifLocalScreenDescriptor));
+ context.SetInputBuffer(lsd);
EXPECT_EQ(CFX_GifDecodeStatus::Success,
context.ReadLogicalScreenDescriptor());
@@ -180,17 +194,19 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
EXPECT_EQ(0x0F00, context.height_);
EXPECT_EQ(0u, context.bc_index_); // bc_index_ is 0 if no global palette
EXPECT_EQ(2u, context.pixel_aspect_);
+ context.SetInputBuffer({});
}
// LSD with global palette bit set, but no global palette
{
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)] = {0x0A, 0x00, 0x00, 0x0F,
0x80, 0x01, 0x02};
- context.SetInputBuffer(lsd, sizeof(CFX_GifLocalScreenDescriptor));
+ context.SetInputBuffer(lsd);
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished,
context.ReadLogicalScreenDescriptor());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// LSD with global palette
{
@@ -199,7 +215,7 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
uint8_t palette[4 * sizeof(CFX_GifPalette)];
} data = {{0x0A, 0x00, 0x00, 0x0F, 0xA9, 0x01, 0x02},
{0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1}};
- context.SetInputBuffer(reinterpret_cast<uint8_t*>(&data), sizeof(data));
+ context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Success,
context.ReadLogicalScreenDescriptor());
@@ -209,12 +225,12 @@ TEST(CFX_GifContext, ReadLocalScreenDescriptor) {
EXPECT_EQ(0x0F00, context.height_);
EXPECT_EQ(1u, context.bc_index_);
EXPECT_EQ(2u, context.pixel_aspect_);
-
EXPECT_EQ(1u, context.global_pal_exp_);
EXPECT_EQ(1, context.global_sort_flag_);
EXPECT_EQ(2, context.global_color_resolution_);
EXPECT_EQ(0, memcmp(data.palette, context.global_palette_.data(),
sizeof(data.palette)));
+ context.SetInputBuffer({});
}
}
@@ -227,21 +243,21 @@ TEST(CFX_GifContext, ReadHeader) {
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)];
} data = {{'N', 'O', 'T', 'G', 'I', 'F'},
{0x0A, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x02}};
- context.SetInputBuffer(reinterpret_cast<uint8_t*>(&data), sizeof(data));
+ context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Error, context.ReadHeader());
-
EXPECT_EQ(sizeof(data.signature), context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// Short after signature
{
uint8_t signature[] = {'G', 'I', 'F', '8', '7', 'a'};
- context.SetInputBuffer(reinterpret_cast<uint8_t*>(&signature),
- sizeof(signature));
+ context.SetInputBuffer(
+ {reinterpret_cast<uint8_t*>(&signature), sizeof(signature)});
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadHeader());
-
EXPECT_EQ(sizeof(signature), context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// Success without global palette
{
@@ -250,15 +266,15 @@ TEST(CFX_GifContext, ReadHeader) {
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)];
} data = {{'G', 'I', 'F', '8', '7', 'a'},
{0x0A, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x02}};
- context.SetInputBuffer(reinterpret_cast<uint8_t*>(&data), sizeof(data));
+ context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadHeader());
-
EXPECT_EQ(sizeof(data), context.InputBuffer()->GetPosition());
EXPECT_EQ(0x000A, context.width_);
EXPECT_EQ(0x0F00, context.height_);
EXPECT_EQ(0u, context.bc_index_); // bc_index_ is 0 if no global palette
EXPECT_EQ(2u, context.pixel_aspect_);
+ context.SetInputBuffer({});
}
// Missing Global Palette
{
@@ -267,11 +283,11 @@ TEST(CFX_GifContext, ReadHeader) {
uint8_t lsd[sizeof(CFX_GifLocalScreenDescriptor)];
} data = {{'G', 'I', 'F', '8', '7', 'a'},
{0x0A, 0x00, 0x00, 0x0F, 0x80, 0x01, 0x02}};
- context.SetInputBuffer(reinterpret_cast<uint8_t*>(&data), sizeof(data));
+ context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Unfinished, context.ReadHeader());
-
EXPECT_EQ(sizeof(data.signature), context.InputBuffer()->GetPosition());
+ context.SetInputBuffer({});
}
// Success with global palette
{
@@ -282,10 +298,9 @@ TEST(CFX_GifContext, ReadHeader) {
} data = {{'G', 'I', 'F', '8', '7', 'a'},
{0x0A, 0x00, 0x00, 0x0F, 0xA9, 0x01, 0x02},
{0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1}};
- context.SetInputBuffer(reinterpret_cast<uint8_t*>(&data), sizeof(data));
+ context.SetInputBuffer({reinterpret_cast<uint8_t*>(&data), sizeof(data)});
EXPECT_EQ(CFX_GifDecodeStatus::Success, context.ReadHeader());
-
EXPECT_EQ(sizeof(data), context.InputBuffer()->GetPosition());
EXPECT_EQ(0x000A, context.width_);
EXPECT_EQ(0x0F00, context.height_);
@@ -296,5 +311,6 @@ TEST(CFX_GifContext, ReadHeader) {
EXPECT_EQ(2, context.global_color_resolution_);
EXPECT_EQ(0, memcmp(data.palette, context.global_palette_.data(),
sizeof(data.palette)));
+ context.SetInputBuffer({});
}
}