OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
| 11 #include <memory> |
| 12 |
11 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "webrtc/base/scoped_ptr.h" | |
13 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 14 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
14 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 15 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
15 #include "webrtc/modules/desktop_capture/mouse_cursor.h" | 16 #include "webrtc/modules/desktop_capture/mouse_cursor.h" |
16 #include "webrtc/modules/desktop_capture/win/cursor.h" | 17 #include "webrtc/modules/desktop_capture/win/cursor.h" |
17 #include "webrtc/modules/desktop_capture/win/cursor_unittest_resources.h" | 18 #include "webrtc/modules/desktop_capture/win/cursor_unittest_resources.h" |
18 #include "webrtc/modules/desktop_capture/win/scoped_gdi_object.h" | 19 #include "webrtc/modules/desktop_capture/win/scoped_gdi_object.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Loads |left| from resources, converts it to a |MouseCursor| instance and | 25 // Loads |left| from resources, converts it to a |MouseCursor| instance and |
25 // compares pixels with |right|. Returns true of MouseCursor bits match |right|. | 26 // compares pixels with |right|. Returns true of MouseCursor bits match |right|. |
26 // |right| must be a 32bpp cursor with alpha channel. | 27 // |right| must be a 32bpp cursor with alpha channel. |
27 bool ConvertToMouseShapeAndCompare(unsigned left, unsigned right) { | 28 bool ConvertToMouseShapeAndCompare(unsigned left, unsigned right) { |
28 HMODULE instance = GetModuleHandle(NULL); | 29 HMODULE instance = GetModuleHandle(NULL); |
29 | 30 |
30 // Load |left| from the EXE module's resources. | 31 // Load |left| from the EXE module's resources. |
31 win::ScopedCursor cursor(reinterpret_cast<HCURSOR>( | 32 win::ScopedCursor cursor(reinterpret_cast<HCURSOR>( |
32 LoadImage(instance, MAKEINTRESOURCE(left), IMAGE_CURSOR, 0, 0, 0))); | 33 LoadImage(instance, MAKEINTRESOURCE(left), IMAGE_CURSOR, 0, 0, 0))); |
33 EXPECT_TRUE(cursor != NULL); | 34 EXPECT_TRUE(cursor != NULL); |
34 | 35 |
35 // Convert |cursor| to |mouse_shape|. | 36 // Convert |cursor| to |mouse_shape|. |
36 HDC dc = GetDC(NULL); | 37 HDC dc = GetDC(NULL); |
37 rtc::scoped_ptr<MouseCursor> mouse_shape( | 38 std::unique_ptr<MouseCursor> mouse_shape( |
38 CreateMouseCursorFromHCursor(dc, cursor)); | 39 CreateMouseCursorFromHCursor(dc, cursor)); |
39 ReleaseDC(NULL, dc); | 40 ReleaseDC(NULL, dc); |
40 | 41 |
41 EXPECT_TRUE(mouse_shape.get()); | 42 EXPECT_TRUE(mouse_shape.get()); |
42 | 43 |
43 // Load |right|. | 44 // Load |right|. |
44 cursor.Set(reinterpret_cast<HCURSOR>( | 45 cursor.Set(reinterpret_cast<HCURSOR>( |
45 LoadImage(instance, MAKEINTRESOURCE(right), IMAGE_CURSOR, 0, 0, 0))); | 46 LoadImage(instance, MAKEINTRESOURCE(right), IMAGE_CURSOR, 0, 0, 0))); |
46 | 47 |
47 ICONINFO iinfo; | 48 ICONINFO iinfo; |
48 EXPECT_TRUE(GetIconInfo(cursor, &iinfo)); | 49 EXPECT_TRUE(GetIconInfo(cursor, &iinfo)); |
49 EXPECT_TRUE(iinfo.hbmColor); | 50 EXPECT_TRUE(iinfo.hbmColor); |
50 | 51 |
51 // Make sure the bitmaps will be freed. | 52 // Make sure the bitmaps will be freed. |
52 win::ScopedBitmap scoped_mask(iinfo.hbmMask); | 53 win::ScopedBitmap scoped_mask(iinfo.hbmMask); |
53 win::ScopedBitmap scoped_color(iinfo.hbmColor); | 54 win::ScopedBitmap scoped_color(iinfo.hbmColor); |
54 | 55 |
55 // Get |scoped_color| dimensions. | 56 // Get |scoped_color| dimensions. |
56 BITMAP bitmap_info; | 57 BITMAP bitmap_info; |
57 EXPECT_TRUE(GetObject(scoped_color, sizeof(bitmap_info), &bitmap_info)); | 58 EXPECT_TRUE(GetObject(scoped_color, sizeof(bitmap_info), &bitmap_info)); |
58 | 59 |
59 int width = bitmap_info.bmWidth; | 60 int width = bitmap_info.bmWidth; |
60 int height = bitmap_info.bmHeight; | 61 int height = bitmap_info.bmHeight; |
61 EXPECT_TRUE(DesktopSize(width, height).equals(mouse_shape->image()->size())); | 62 EXPECT_TRUE(DesktopSize(width, height).equals(mouse_shape->image()->size())); |
62 | 63 |
63 // Get the pixels from |scoped_color|. | 64 // Get the pixels from |scoped_color|. |
64 int size = width * height; | 65 int size = width * height; |
65 rtc::scoped_ptr<uint32_t[]> data(new uint32_t[size]); | 66 std::unique_ptr<uint32_t[]> data(new uint32_t[size]); |
66 EXPECT_TRUE(GetBitmapBits(scoped_color, size * sizeof(uint32_t), data.get())); | 67 EXPECT_TRUE(GetBitmapBits(scoped_color, size * sizeof(uint32_t), data.get())); |
67 | 68 |
68 // Compare the 32bpp image in |mouse_shape| with the one loaded from |right|. | 69 // Compare the 32bpp image in |mouse_shape| with the one loaded from |right|. |
69 return memcmp(data.get(), mouse_shape->image()->data(), | 70 return memcmp(data.get(), mouse_shape->image()->data(), |
70 size * sizeof(uint32_t)) == 0; | 71 size * sizeof(uint32_t)) == 0; |
71 } | 72 } |
72 | 73 |
73 } // namespace | 74 } // namespace |
74 | 75 |
75 TEST(MouseCursorTest, MatchCursors) { | 76 TEST(MouseCursorTest, MatchCursors) { |
76 EXPECT_TRUE(ConvertToMouseShapeAndCompare(IDD_CURSOR1_24BPP, | 77 EXPECT_TRUE(ConvertToMouseShapeAndCompare(IDD_CURSOR1_24BPP, |
77 IDD_CURSOR1_32BPP)); | 78 IDD_CURSOR1_32BPP)); |
78 | 79 |
79 EXPECT_TRUE(ConvertToMouseShapeAndCompare(IDD_CURSOR1_8BPP, | 80 EXPECT_TRUE(ConvertToMouseShapeAndCompare(IDD_CURSOR1_8BPP, |
80 IDD_CURSOR1_32BPP)); | 81 IDD_CURSOR1_32BPP)); |
81 | 82 |
82 EXPECT_TRUE(ConvertToMouseShapeAndCompare(IDD_CURSOR2_1BPP, | 83 EXPECT_TRUE(ConvertToMouseShapeAndCompare(IDD_CURSOR2_1BPP, |
83 IDD_CURSOR2_32BPP)); | 84 IDD_CURSOR2_32BPP)); |
84 | 85 |
85 EXPECT_TRUE(ConvertToMouseShapeAndCompare(IDD_CURSOR3_4BPP, | 86 EXPECT_TRUE(ConvertToMouseShapeAndCompare(IDD_CURSOR3_4BPP, |
86 IDD_CURSOR3_32BPP)); | 87 IDD_CURSOR3_32BPP)); |
87 } | 88 } |
88 | 89 |
89 } // namespace webrtc | 90 } // namespace webrtc |
OLD | NEW |