Chromium Code Reviews| Index: skia/ext/bitmap_platform_device_mac_unittest.cc |
| diff --git a/skia/ext/bitmap_platform_device_mac_unittest.cc b/skia/ext/bitmap_platform_device_mac_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3ca6a8f68762eb80a2a8adc9cf68433b6c86244d |
| --- /dev/null |
| +++ b/skia/ext/bitmap_platform_device_mac_unittest.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "skia/ext/bitmap_platform_device_mac.h" |
| + |
| +#include "base/scoped_ptr.h" |
| +#include "skia/ext/skia_utils_mac.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SkMatrix.h" |
| +#include "third_party/skia/include/core/SkRegion.h" |
| + |
| +namespace skia { |
| + |
| +class BitmapPlatformDeviceMacTest : public testing::Test { |
| + public: |
| + BitmapPlatformDeviceMacTest() { |
| + bitmap_.reset( |
| + BitmapPlatformDevice::Create(NULL, 400, 300, /*is_opaque=*/true)); |
|
jeremy
2010/07/18 11:24:07
Could you make the dimensions, constants
Nico
2010/07/19 15:14:51
Done.
|
| + } |
| + |
| + scoped_ptr<BitmapPlatformDevice> bitmap_; |
| +}; |
| + |
| +TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithTranslate) { |
| + SkMatrix transform; |
| + transform.setTranslate(50, 140); |
| + |
| + SkRegion clip_region; |
| + SkIRect rect; |
| + rect.set(0, 0, 400, 300); |
| + clip_region.setRect(rect); |
| + bitmap_->setMatrixClip(transform, clip_region); |
| + |
| + CGContextRef context = bitmap_->GetBitmapContext(); |
| + SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); |
| + transform.mapRect(&clip_rect); |
| + EXPECT_EQ(0, clip_rect.fLeft); |
| + EXPECT_EQ(0, clip_rect.fTop); |
| + EXPECT_EQ(400, clip_rect.width()); |
| + EXPECT_EQ(300, clip_rect.height()); |
| +} |
| + |
| +TEST_F(BitmapPlatformDeviceMacTest, ClipRectTransformWithScale) { |
| + SkMatrix transform; |
| + transform.setScale(0.5, 0.5); |
| + |
| + SkRegion clip_region; |
| + SkIRect rect; |
| + rect.set(0, 0, 400, 300); |
| + clip_region.setRect(rect); |
| + bitmap_->setMatrixClip(transform, clip_region); |
| + |
| + CGContextRef context = bitmap_->GetBitmapContext(); |
| + SkRect clip_rect = gfx::CGRectToSkRect(CGContextGetClipBoundingBox(context)); |
| + transform.mapRect(&clip_rect); |
| + EXPECT_EQ(0, clip_rect.fLeft); |
| + EXPECT_EQ(0, clip_rect.fTop); |
| + EXPECT_EQ(400, clip_rect.width()); |
| + EXPECT_EQ(300, clip_rect.height()); |
| +} |
| + |
| +} // namespace skia |