Bug 1255107 (Part 1) - Add a RowHasPixels() utility function to allow tests to compare rows to an arbitrary sequence of BGRAColor values. r=njn

This commit is contained in:
Seth Fowler 2016-06-21 18:15:26 -07:00
Родитель 703e02d24b
Коммит e9ae1e161e
2 изменённых файлов: 59 добавлений и 1 удалений

Просмотреть файл

@ -23,6 +23,7 @@ namespace image {
using namespace gfx;
using std::abs;
using std::vector;
///////////////////////////////////////////////////////////////////////////////
// General Helpers
@ -42,12 +43,24 @@ using std::abs;
return rv; \
}
#define ASSERT_GE_OR_RETURN(a, b, rv) \
EXPECT_GE(a, b); \
if (!((a) >= (b))) { \
return rv; \
}
#define ASSERT_LE_OR_RETURN(a, b, rv) \
EXPECT_LE(a, b); \
if (!((a) <= (b))) { \
return rv; \
}
#define ASSERT_LT_OR_RETURN(a, b, rv) \
EXPECT_LT(a, b); \
if (!((a) < (b))) { \
return rv; \
}
already_AddRefed<nsIInputStream>
LoadFile(const char* aRelativePath)
{
@ -205,6 +218,41 @@ PalettedRectIsSolidColor(Decoder* aDecoder, const IntRect& aRect, uint8_t aColor
return true;
}
bool
RowHasPixels(SourceSurface* aSurface,
int32_t aRow,
const vector<BGRAColor>& aPixels)
{
ASSERT_GE_OR_RETURN(aRow, 0, false);
IntSize surfaceSize = aSurface->GetSize();
ASSERT_EQ_OR_RETURN(aPixels.size(), size_t(surfaceSize.width), false);
ASSERT_LT_OR_RETURN(aRow, surfaceSize.height, false);
RefPtr<DataSourceSurface> dataSurface = aSurface->GetDataSurface();
ASSERT_TRUE_OR_RETURN(dataSurface, false);
ASSERT_EQ_OR_RETURN(dataSurface->Stride(), surfaceSize.width * 4, false);
DataSourceSurface::ScopedMap mapping(dataSurface,
DataSourceSurface::MapType::READ);
ASSERT_TRUE_OR_RETURN(mapping.IsMapped(), false);
uint8_t* data = dataSurface->GetData();
ASSERT_TRUE_OR_RETURN(data != nullptr, false);
int32_t rowLength = dataSurface->Stride();
for (int32_t col = 0; col < surfaceSize.width; ++col) {
int32_t i = aRow * rowLength + col * 4;
ASSERT_EQ_OR_RETURN(aPixels[col].mBlue, data[i + 0], false);
ASSERT_EQ_OR_RETURN(aPixels[col].mGreen, data[i + 1], false);
ASSERT_EQ_OR_RETURN(aPixels[col].mRed, data[i + 2], false);
ASSERT_EQ_OR_RETURN(aPixels[col].mAlpha, data[i + 3], false);
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
// SurfacePipe Helpers

Просмотреть файл

@ -6,6 +6,8 @@
#ifndef mozilla_image_test_gtest_Common_h
#define mozilla_image_test_gtest_Common_h
#include <vector>
#include "gtest/gtest.h"
#include "mozilla/Maybe.h"
@ -157,6 +159,14 @@ bool PalettedRectIsSolidColor(Decoder* aDecoder,
const gfx::IntRect& aRect,
uint8_t aColor);
/**
* @returns true if the pixels in @aRow of @aSurface match the pixels given in
* @aPixels.
*/
bool RowHasPixels(gfx::SourceSurface* aSurface,
int32_t aRow,
const std::vector<BGRAColor>& aPixels);
///////////////////////////////////////////////////////////////////////////////
// SurfacePipe Helpers