Process Hacker
t_support.c
Go to the documentation of this file.
1 #include "tests.h"
2 
3 static VOID Test_rectangle(
4  VOID
5  )
6 {
7  PH_RECTANGLE r1;
8  PH_RECTANGLE r2;
9 
10  r1.Left = 0;
11  r1.Top = 0;
12  r1.Width = 1024;
13  r1.Height = 1024;
14 
15  r2.Width = 100;
16  r2.Height = 100;
17 
18  r2.Left = -10;
19  r2.Top = -10;
20  PhAdjustRectangleToBounds(&r2, &r1);
21  assert(r2.Left == 0 && r2.Top == 0 && r2.Width == 100 && r2.Height == 100);
22 
23  r2.Left = 1100;
24  r2.Top = 1100;
25  PhAdjustRectangleToBounds(&r2, &r1);
26  assert(r2.Left == 924 && r2.Top == 924 && r2.Width == 100 && r2.Height == 100);
27 
28  PhCenterRectangle(&r2, &r1);
29  assert(r2.Left == 462 && r2.Top == 462 && r2.Width == 100 && r2.Height == 100);
30 }
31 
32 static BOOLEAN AreGuidsEqual(
33  _In_ PGUID Guid1,
34  _In_ PWSTR Guid2
35  )
36 {
37  GUID guid2;
38  UNICODE_STRING us;
39 
40  RtlInitUnicodeString(&us, Guid2);
41  RtlGUIDFromString(&us, &guid2);
42 
43  return memcmp(Guid1, &guid2, sizeof(GUID)) == 0;
44 }
45 
46 static VOID Test_guid(
47  VOID
48  )
49 {
50  GUID guid;
51  GUID ns;
52  UNICODE_STRING dnsNamespace = RTL_CONSTANT_STRING(L"{6ba7b810-9dad-11d1-80b4-00c04fd430c8}");
53  UNICODE_STRING urlNamespace = RTL_CONSTANT_STRING(L"{6ba7b811-9dad-11d1-80b4-00c04fd430c8}");
54  UNICODE_STRING oidNamespace = RTL_CONSTANT_STRING(L"{6ba7b812-9dad-11d1-80b4-00c04fd430c8}");
55  UNICODE_STRING x500Namespace = RTL_CONSTANT_STRING(L"{6ba7b814-9dad-11d1-80b4-00c04fd430c8}");
56 
57  // Taken from http://svn.python.org/projects/python/branches/py3k/Lib/test/test_uuid.py
58 
59  RtlGUIDFromString(&dnsNamespace, &ns);
60  PhGenerateGuidFromName(&guid, &ns, "python.org", 10, GUID_VERSION_MD5);
61  assert(AreGuidsEqual(&guid, L"{6fa459ea-ee8a-3ca4-894e-db77e160355e}"));
62 
63  RtlGUIDFromString(&urlNamespace, &ns);
64  PhGenerateGuidFromName(&guid, &ns, "http://python.org/", 18, GUID_VERSION_MD5);
65  assert(AreGuidsEqual(&guid, L"{9fe8e8c4-aaa8-32a9-a55c-4535a88b748d}"));
66 
67  RtlGUIDFromString(&oidNamespace, &ns);
68  PhGenerateGuidFromName(&guid, &ns, "1.3.6.1", 7, GUID_VERSION_SHA1);
69  assert(AreGuidsEqual(&guid, L"{1447fa61-5277-5fef-a9b3-fbc6e44f4af3}"));
70 
71  RtlGUIDFromString(&x500Namespace, &ns);
72  PhGenerateGuidFromName(&guid, &ns, "c=ca", 4, GUID_VERSION_SHA1);
73  assert(AreGuidsEqual(&guid, L"{cc957dd1-a972-5349-98cd-874190002798}"));
74 }
75 
76 static VOID Test_ellipsis(
77  VOID
78  )
79 {
80  PPH_STRING input;
81  PPH_STRING output;
82 
83  // Normal
84 
85  input = PhCreateString(L"asdf 1234");
86 
87  output = PhEllipsisString(input, 9);
88  assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
89  output = PhEllipsisString(input, 999);
90  assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
91  output = PhEllipsisString(input, 8);
92  assert(wcscmp(output->Buffer, L"asdf ...") == 0);
93  output = PhEllipsisString(input, 7);
94  assert(wcscmp(output->Buffer, L"asdf...") == 0);
95  output = PhEllipsisString(input, 5);
96  assert(wcscmp(output->Buffer, L"as...") == 0);
97  output = PhEllipsisString(input, 4);
98  assert(wcscmp(output->Buffer, L"a...") == 0);
99  output = PhEllipsisString(input, 3);
100  assert(wcscmp(output->Buffer, L"...") == 0);
101  output = PhEllipsisString(input, 2);
102  assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
103  output = PhEllipsisString(input, 1);
104  assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
105  output = PhEllipsisString(input, 0);
106  assert(wcscmp(output->Buffer, L"asdf 1234") == 0);
107 
108  // Path
109 
110  input = PhCreateString(L"C:\\abcdef\\1234.abc");
111 
112  output = PhEllipsisStringPath(input, 18);
113  assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
114  output = PhEllipsisStringPath(input, 999);
115  assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
116  output = PhEllipsisStringPath(input, 17);
117  assert(wcscmp(output->Buffer, L"C:\\ab...\\1234.abc") == 0); // last part is kept
118  output = PhEllipsisStringPath(input, 16);
119  assert(wcscmp(output->Buffer, L"C:\\a...\\1234.abc") == 0);
120  output = PhEllipsisStringPath(input, 15);
121  assert(wcscmp(output->Buffer, L"C:\\...\\1234.abc") == 0);
122  output = PhEllipsisStringPath(input, 14);
123  assert(wcscmp(output->Buffer, L"C:...\\1234.abc") == 0);
124  output = PhEllipsisStringPath(input, 13);
125  assert(wcscmp(output->Buffer, L"C...\\1234.abc") == 0);
126  output = PhEllipsisStringPath(input, 12);
127  assert(wcscmp(output->Buffer, L"...\\1234.abc") == 0);
128  output = PhEllipsisStringPath(input, 11);
129  assert(wcscmp(output->Buffer, L"C:\\a....abc") == 0); // the two sides are split as evenly as possible
130  output = PhEllipsisStringPath(input, 10);
131  assert(wcscmp(output->Buffer, L"C:\\....abc") == 0);
132  output = PhEllipsisStringPath(input, 9);
133  assert(wcscmp(output->Buffer, L"C:\\...abc") == 0);
134  output = PhEllipsisStringPath(input, 8);
135  assert(wcscmp(output->Buffer, L"C:...abc") == 0);
136  output = PhEllipsisStringPath(input, 7);
137  assert(wcscmp(output->Buffer, L"C:...bc") == 0);
138  output = PhEllipsisStringPath(input, 6);
139  assert(wcscmp(output->Buffer, L"C...bc") == 0);
140  output = PhEllipsisStringPath(input, 5);
141  assert(wcscmp(output->Buffer, L"C...c") == 0);
142  output = PhEllipsisStringPath(input, 4);
143  assert(wcscmp(output->Buffer, L"...c") == 0);
144  output = PhEllipsisStringPath(input, 3);
145  assert(wcscmp(output->Buffer, L"...") == 0);
146  output = PhEllipsisStringPath(input, 2);
147  assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
148  output = PhEllipsisStringPath(input, 1);
149  assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
150  output = PhEllipsisStringPath(input, 0);
151  assert(wcscmp(output->Buffer, L"C:\\abcdef\\1234.abc") == 0);
152 }
153 
155  VOID
156  )
157 {
158  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"", L"", FALSE, FALSE) == 0);
159  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asdf", FALSE, FALSE) == 0);
160  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asDF", FALSE, FALSE) > 0);
161  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asDF", TRUE, FALSE) == 0);
162  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asdff", FALSE, FALSE) < 0);
163  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdfff", L"asdff", FALSE, FALSE) > 0);
164 
165  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&asdf", L"asdf", FALSE, FALSE) == 0);
166  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&asdf", L"&asdf", FALSE, FALSE) == 0);
167  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&asdf", FALSE, FALSE) != 0);
168  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&&asdf", FALSE, FALSE) == 0);
169  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&&asdf", L"&&asdf", FALSE, FALSE) == 0);
170  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&&&asdf", L"&&asdf", FALSE, FALSE) != 0);
171  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"AAA&&asdf", L"aaa&&&asdf", TRUE, FALSE) == 0);
172  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"AAA&&&&asdf", L"aaa&&&&asdf", TRUE, FALSE) == 0);
173 
174  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"", L"", FALSE, TRUE) == 0);
175  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asdf", FALSE, TRUE) == 0);
176  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asDF", FALSE, TRUE) > 0);
177  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asDF", TRUE, TRUE) == 0);
178  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdf", L"asdff", FALSE, TRUE) == 0);
179  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"asdfff", L"asdff", FALSE, TRUE) != 0);
180 
181  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&asdf", L"asdf", FALSE, TRUE) == 0);
182  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&asdf", L"&asdf", FALSE, TRUE) == 0);
183  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&asdf", FALSE, TRUE) != 0);
184  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&&asdf&", FALSE, TRUE) == 0);
185  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf", L"&&asdf&&", FALSE, TRUE) == 0);
186  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf&", L"&&asdf", FALSE, TRUE) == 0);
187  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&asdf&&", L"&&asdf", FALSE, TRUE) != 0);
188  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&&asdf", L"&&asdf", FALSE, TRUE) == 0);
189  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"&&&&asdf", L"&&asdf&&", FALSE, TRUE) != 0);
190  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"AAA&&asdf", L"aaa&&&asdf&&", TRUE, TRUE) == 0);
191  assert(PhCompareUnicodeStringZIgnoreMenuPrefix(L"AAA&&&&asdf", L"aaa&&&&asdf&&", TRUE, TRUE) == 0);
192 }
193 
195  VOID
196  )
197 {
198  Test_rectangle();
199  Test_guid();
200  Test_ellipsis();
202 }