-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemoryDeviceContext.Test.cpp
122 lines (117 loc) · 3.05 KB
/
MemoryDeviceContext.Test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "WindowsInclude.h"
#include "MemoryDeviceContext.h"
#include "Exception.h"
#include <UnitTest/UnitTest.h>
using UnitTest::Assert;
namespace Wex
{
TEST_CLASS(MemoryDeviceContextTest)
{
public:
MemoryDeviceContextTest()
{
}
#if 0
TEST_METHOD(HandleConstructor_DefaultRectWithDestructor)
{
const auto sourceDeviceContext = reinterpret_cast<HDC>(1);
const auto left = 2;
const auto top = 3;
const auto width = 4;
const auto height = 5;
const auto dc = reinterpret_cast<HDC>(6);
const auto deviceWidth = 7;
const auto deviceHeight = 8;
const auto bitmap = reinterpret_cast<HBITMAP>(9);
const auto oldBitmap = reinterpret_cast<HBITMAP>(10);
API_MOCK(::CreateCompatibleDC) mockCreate([=](HDC h)
{
Assert.AreEqual(sourceDeviceContext, h);
return dc;
});
API_MOCK(::GetClipBox) mockClip([=](HDC h, RECT* rc)
{
Assert.AreEqual(sourceDeviceContext, h);
Assert.IsNotNull(rc);
*rc = Rect{ Point{ left, top }, Size{ width, height } };
return 0;
});
API_MOCK(::LPtoDP) mockConvert([=](HDC h, POINT* p, int c)
{
Assert.AreEqual(sourceDeviceContext, h);
Assert.IsNotNull(p);
Assert.AreEqual(1, c);
p->x = deviceWidth;
p->y = deviceHeight;
return TRUE;
});
API_MOCK(::CreateCompatibleBitmap) mockCreateBitmap(
[&](HDC h, int cx, int cy)
{
Assert.AreEqual(dc, h);
Assert.AreEqual(deviceWidth, cx);
Assert.AreEqual(deviceHeight, cy);
return bitmap;
});
API_MOCK(::SelectObject) mockSelect([=](HDC h, HGDIOBJ o) -> HGDIOBJ
{
Assert.AreEqual(dc, h);
if (o == bitmap)
return oldBitmap;
Assert.AreEqual(oldBitmap, o);
return nullptr;
});
API_MOCK(::SetWindowOrgEx) mockOrg([=](HDC h, int x, int y, POINT* p)
{
Assert.AreEqual(dc, h);
Assert.AreEqual(left, x);
Assert.AreEqual(top, y);
Assert.IsNull(p);
return TRUE;
});
API_MOCK(::BitBlt) mockBit(
[=](HDC s, int x, int y, int w, int h, HDC d, int dx, int dy, DWORD o)
{
Assert.AreEqual(sourceDeviceContext, s);
Assert.AreEqual(left, x);
Assert.AreEqual(top, y);
Assert.AreEqual(width, w);
Assert.AreEqual(height, h);
Assert.AreEqual(dc, d);
Assert.AreEqual(left, dx);
Assert.AreEqual(top, dy);
Assert.AreEqual(SRCCOPY, o);
return TRUE;
});
API_MOCK(::DeleteDC) mockDeleteContext([=](HDC h)
{
Assert.AreEqual(dc, h);
return TRUE;
});
API_MOCK(::DeleteObject) mockDeleteBitmap([=](HGDIOBJ object)
{
Assert.AreEqual(bitmap, object);
return TRUE;
});
MemoryDeviceContext deviceContext{ sourceDeviceContext };
Assert.AreEqual(dc, deviceContext.dc);
}
TEST_METHOD(HandleConstructor_RectWithDestructor)
{
}
#endif
TEST_METHOD(HandleConstructor_Exception)
{
API_MOCK(::CreateCompatibleDC) mock([](HDC)
{
return static_cast<HDC>(nullptr);
});
Assert.ThrowsType<Exception>(
[]{ MemoryDeviceContext{ nullptr }; },
[](const Exception& exception)
{
Assert.AreEqual("CreateCompatibleDC", exception.GetLocation());
});
}
};
}