4 * Copyright 2011 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/test.h"
32 static HCRYPTPROV crypt_prov;
34 static const char *sha1_graphics_a8r8g8b8[] =
36 "a3cadd34d95d3d5cc23344f69aab1c2e55935fcf",
40 static inline DWORD get_stride(BITMAPINFO *bmi)
42 return ((bmi->bmiHeader.biBitCount * bmi->bmiHeader.biWidth + 31) >> 3) & ~3;
45 static inline DWORD get_dib_size(BITMAPINFO *bmi)
47 return get_stride(bmi) * abs(bmi->bmiHeader.biHeight);
50 static char *hash_dib(BITMAPINFO *bmi, void *bits)
52 DWORD dib_size = get_dib_size(bmi);
56 DWORD hash_size = sizeof(hash_buf);
58 static const char *hex = "0123456789abcdef";
60 if(!crypt_prov) return NULL;
62 if(!CryptCreateHash(crypt_prov, CALG_SHA1, 0, 0, &hash)) return NULL;
64 CryptHashData(hash, bits, dib_size, 0);
66 CryptGetHashParam(hash, HP_HASHVAL, NULL, &hash_size, 0);
67 if(hash_size != sizeof(hash_buf)) return NULL;
69 CryptGetHashParam(hash, HP_HASHVAL, hash_buf, &hash_size, 0);
70 CryptDestroyHash(hash);
72 buf = HeapAlloc(GetProcessHeap(), 0, hash_size * 2 + 1);
74 for(i = 0; i < hash_size; i++)
76 buf[i * 2] = hex[hash_buf[i] >> 4];
77 buf[i * 2 + 1] = hex[hash_buf[i] & 0xf];
84 static void compare_hash(BITMAPINFO *bmi, BYTE *bits, const char ***sha1, const char *info)
86 char *hash = hash_dib(bmi, bits);
90 skip("SHA1 hashing unavailable on this platform\n");
96 ok(!strcmp(hash, **sha1), "%d: %s: expected hash %s got %s\n",
97 bmi->bmiHeader.biBitCount, info, **sha1, hash);
100 else trace("\"%s\",\n", hash);
102 HeapFree(GetProcessHeap(), 0, hash);
105 static void draw_graphics(HDC hdc, BITMAPINFO *bmi, BYTE *bits, const char ***sha1)
107 DWORD dib_size = get_dib_size(bmi);
109 memset(bits, 0xcc, dib_size);
110 compare_hash(bmi, bits, sha1, "empty");
113 static void test_simple_graphics(void)
115 char bmibuf[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)];
116 BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
119 HBITMAP dib, orig_bm;
124 memset(bmi, 0, sizeof(bmibuf));
125 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
126 bmi->bmiHeader.biHeight = 512;
127 bmi->bmiHeader.biWidth = 512;
128 bmi->bmiHeader.biBitCount = 32;
129 bmi->bmiHeader.biPlanes = 1;
130 bmi->bmiHeader.biCompression = BI_RGB;
132 dib = CreateDIBSection(0, bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
133 ok(dib != NULL, "ret NULL\n");
134 mem_dc = CreateCompatibleDC(NULL);
135 orig_bm = SelectObject(mem_dc, dib);
137 sha1 = sha1_graphics_a8r8g8b8;
138 draw_graphics(mem_dc, bmi, bits, &sha1);
140 SelectObject(mem_dc, orig_bm);
147 CryptAcquireContextW(&crypt_prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
149 test_simple_graphics();
151 CryptReleaseContext(crypt_prov, 0);