Bug 1286168 - Add a RAII class to initialize ImageLib services in GTests. r=njn

This commit is contained in:
Seth Fowler 2016-07-12 00:38:32 -07:00
parent d6df5b5f4a
commit a92a8b9e06
6 changed files with 28 additions and 35 deletions

View File

@ -15,6 +15,7 @@
#include "mozilla/gfx/2D.h"
#include "Decoder.h"
#include "gfxColor.h"
#include "imgITools.h"
#include "nsCOMPtr.h"
#include "SurfacePipe.h"
#include "SurfacePipeFactory.h"
@ -99,6 +100,23 @@ struct BGRAColor
// General Helpers
///////////////////////////////////////////////////////////////////////////////
/**
* A RAII class that ensure that ImageLib services are available. Any tests that
* require ImageLib to be initialized (for example, any test that uses the
* SurfaceCache; see image::EnsureModuleInitialized() for the full list) can
* use this class to ensure that ImageLib services are available. Failure to do
* so can result in strange, non-deterministic failures.
*/
struct AutoInitializeImageLib
{
AutoInitializeImageLib()
{
// Ensure that ImageLib services are initialized.
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
EXPECT_TRUE(imgTools != nullptr);
}
};
/// Loads a file from the current directory. @return an nsIInputStream for it.
already_AddRefed<nsIInputStream> LoadFile(const char* aRelativePath);

View File

@ -87,13 +87,8 @@ RunDecodeToSurface(const ImageTestCase& aTestCase)
class ImageDecodeToSurface : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
// Ensure that ImageLib services are initialized.
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
EXPECT_TRUE(imgTools != nullptr);
}
protected:
AutoInitializeImageLib mInit;
};
TEST_F(ImageDecodeToSurface, PNG) { RunDecodeToSurface(GreenPNGTestCase()); }

View File

@ -206,13 +206,8 @@ CheckDownscaleDuringDecode(const ImageTestCase& aTestCase)
class ImageDecoders : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
// Ensure that ImageLib services are initialized.
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
EXPECT_TRUE(imgTools != nullptr);
}
protected:
AutoInitializeImageLib mInit;
};
TEST_F(ImageDecoders, PNGSingleChunk)

View File

@ -61,13 +61,8 @@ AssertConfiguringDeinterlacingFilterFails(const IntSize& aSize)
class ImageDeinterlacingFilter : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
// Ensure that ImageLib services are initialized.
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
EXPECT_TRUE(imgTools != nullptr);
}
protected:
AutoInitializeImageLib mInit;
};
TEST_F(ImageDeinterlacingFilter, WritePixels100_100)

View File

@ -135,13 +135,8 @@ CheckMetadata(const ImageTestCase& aTestCase,
class ImageDecoderMetadata : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
// Ensure that ImageLib services are initialized.
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
EXPECT_TRUE(imgTools != nullptr);
}
protected:
AutoInitializeImageLib mInit;
};
TEST_F(ImageDecoderMetadata, PNG) { CheckMetadata(GreenPNGTestCase()); }

View File

@ -131,13 +131,8 @@ CheckPalettedSurfacePipeMethodResults(SurfacePipe* aPipe,
class ImageSurfacePipeIntegration : public ::testing::Test
{
protected:
static void SetUpTestCase()
{
// Ensure that ImageLib services are initialized.
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
EXPECT_TRUE(imgTools != nullptr);
}
protected:
AutoInitializeImageLib mInit;
};
TEST_F(ImageSurfacePipeIntegration, SurfacePipe)