This source file includes following definitions.
- SetUp
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_family.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_unittest_util.h"
namespace {
namespace gt = gfx::test;
#define EXPECT_IMAGE_NON_NULL_AND_SIZE(image, expected_width, expected_height) \
do { \
const gfx::Image* image_ = image; \
EXPECT_TRUE(image_); \
EXPECT_EQ(expected_width, image_->Width()); \
EXPECT_EQ(expected_height, image_->Height()); \
} while(0)
class ImageFamilyTest : public testing::Test {
public:
virtual void SetUp() OVERRIDE {
EXPECT_TRUE(image_family_.empty());
image_family_.Add(gt::CreateImageSkia(32, 32));
EXPECT_FALSE(image_family_.empty());
image_family_.Add(gt::CreateImageSkia(16, 16));
image_family_.Add(gt::CreateImageSkia(64, 64));
gfx::Image image(gt::CreateImageSkia(32, 32));
image_family_.Add(image);
image_family_.Add(gt::CreateImageSkia(3, 12));
image_family_.Add(gt::CreateImageSkia(12, 48));
image_family_.Add(gt::CreateImageSkia(512, 128));
image_family_.Add(gt::CreateImageSkia(256, 64));
EXPECT_FALSE(image_family_.empty());
}
gfx::ImageFamily image_family_;
};
TEST_F(ImageFamilyTest, Clear) {
image_family_.clear();
EXPECT_TRUE(image_family_.empty());
}
TEST_F(ImageFamilyTest, Iteration) {
gfx::ImageFamily::const_iterator it = image_family_.begin();
gfx::ImageFamily::const_iterator end = image_family_.end();
EXPECT_TRUE(it != end);
EXPECT_EQ(gfx::Size(3, 12), it->Size());
++it;
EXPECT_TRUE(it != end);
EXPECT_EQ(gfx::Size(12, 48), it->Size());
it++;
EXPECT_TRUE(it != end);
EXPECT_EQ(gfx::Size(16, 16), it->Size());
++it;
EXPECT_TRUE(it != end);
EXPECT_EQ(gfx::Size(32, 32), it->Size());
--it;
EXPECT_TRUE(it != end);
EXPECT_EQ(gfx::Size(16, 16), it->Size());
++it;
++it;
EXPECT_TRUE(it != end);
EXPECT_EQ(gfx::Size(64, 64), (*it).Size());
++it;
EXPECT_TRUE(it != end);
EXPECT_EQ(gfx::Size(256, 64), it->Size());
++it;
EXPECT_TRUE(it != end);
EXPECT_EQ(gfx::Size(512, 128), it->Size());
++it;
EXPECT_TRUE(it == end);
}
TEST_F(ImageFamilyTest, Get) {
gfx::ImageFamily empty_family;
EXPECT_TRUE(empty_family.empty());
EXPECT_FALSE(empty_family.GetBest(32, 32));
EXPECT_FALSE(empty_family.GetBest(0, 32));
EXPECT_FALSE(empty_family.GetBest(32, 0));
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 0), 16, 16);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 16), 16, 16);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 64), 16, 16);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(16, 0), 16, 16);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(64, 0), 16, 16);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(2, 12), 3, 12);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(2, 13), 12, 48);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(10, 60), 12, 48);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(63, 32), 64, 64);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(64, 32), 64, 64);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(65, 32), 256, 64);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 63), 64, 64);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 64), 12, 48);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 65), 12, 48);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 32), 32, 32);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(31, 31), 32, 32);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(17, 17), 32, 32);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(16, 16), 16, 16);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(3, 3), 16, 16);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(512, 512), 64, 64);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(16, 64), 12, 48);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(2, 8), 3, 12);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(64, 16), 256, 64);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(260, 65), 512, 128);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(255, 51), 256, 64);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(260, 52), 512, 128);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(654, 129), 512, 128);
}
TEST_F(ImageFamilyTest, ZeroWidthAndHeight) {
image_family_.Add(gfx::Image());
image_family_.Add(gt::CreateImageSkia(32, 0));
image_family_.Add(gt::CreateImageSkia(0, 32));
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 0), 0, 0);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(1, 1), 16, 16);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 32), 32, 32);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 1), 0, 0);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(0, 32), 0, 0);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(1, 0), 0, 0);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 0), 0, 0);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(1, 32), 12, 48);
EXPECT_IMAGE_NON_NULL_AND_SIZE(image_family_.GetBest(32, 1), 256, 64);
}
}