This source file includes following definitions.
- createBoxShape
- TEST_F
- TEST_F
#include "config.h"
#include "core/rendering/shapes/BoxShape.h"
#include "platform/geometry/RoundedRect.h"
#include <gtest/gtest.h>
namespace WebCore {
class BoxShapeTest : public ::testing::Test {
protected:
BoxShapeTest() { }
PassOwnPtr<Shape> createBoxShape(const RoundedRect& bounds, float shapeMargin)
{
return Shape::createLayoutBoxShape(bounds, TopToBottomWritingMode, Length(shapeMargin, Fixed));
}
};
}
namespace {
using namespace WebCore;
#define TEST_EXCLUDED_INTERVAL(shapePtr, lineTop, lineHeight, expectedLeft, expectedRight) \
{ \
SegmentList result; \
shapePtr->getExcludedIntervals(lineTop, lineHeight, result); \
EXPECT_EQ(1u, result.size()); \
if (result.size() == 1u) { \
EXPECT_FLOAT_EQ(expectedLeft, result[0].logicalLeft); \
EXPECT_FLOAT_EQ(expectedRight, result[0].logicalRight); \
} \
}
#define TEST_NO_EXCLUDED_INTERVAL(shapePtr, lineTop, lineHeight) \
{ \
SegmentList result; \
shapePtr->getExcludedIntervals(lineTop, lineHeight, result); \
EXPECT_EQ(0u, result.size()); \
}
TEST_F(BoxShapeTest, zeroRadii)
{
OwnPtr<Shape> shape = createBoxShape(RoundedRect(0, 0, 100, 50), 10);
EXPECT_FALSE(shape->isEmpty());
EXPECT_EQ(LayoutRect(-10, -10, 120, 70), shape->shapeMarginLogicalBoundingBox());
EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-9, 1));
EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-10, 0));
EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(-10, 200));
EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(5, 10));
EXPECT_TRUE(shape->lineOverlapsShapeMarginBounds(59, 1));
EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(-12, 2));
EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(60, 1));
EXPECT_FALSE(shape->lineOverlapsShapeMarginBounds(100, 200));
TEST_EXCLUDED_INTERVAL(shape, -9, 1, -10, 110);
TEST_EXCLUDED_INTERVAL(shape, -10, 0, -10, 110);
TEST_EXCLUDED_INTERVAL(shape, -10, 200, -10, 110);
TEST_EXCLUDED_INTERVAL(shape, 5, 10, -10, 110);
TEST_EXCLUDED_INTERVAL(shape, 59, 1, -10, 110);
TEST_NO_EXCLUDED_INTERVAL(shape, -12, 2);
TEST_NO_EXCLUDED_INTERVAL(shape, 60, 1);
TEST_NO_EXCLUDED_INTERVAL(shape, 100, 200);
}
TEST_F(BoxShapeTest, getIntervals)
{
const RoundedRect::Radii cornerRadii(IntSize(10, 15), IntSize(10, 20), IntSize(25, 15), IntSize(20, 30));
OwnPtr<Shape> shape = createBoxShape(RoundedRect(IntRect(0, 0, 100, 100), cornerRadii), 0);
EXPECT_FALSE(shape->isEmpty());
EXPECT_EQ(LayoutRect(0, 0, 100, 100), shape->shapeMarginLogicalBoundingBox());
TEST_EXCLUDED_INTERVAL(shape, 10, 95, 0, 100);
TEST_EXCLUDED_INTERVAL(shape, 5, 25, 0, 100);
TEST_EXCLUDED_INTERVAL(shape, 15, 6, 0, 100);
TEST_EXCLUDED_INTERVAL(shape, 20, 50, 0, 100);
TEST_EXCLUDED_INTERVAL(shape, 69, 5, 0, 100);
TEST_EXCLUDED_INTERVAL(shape, 85, 10, 0, 97.320511f);
}
}