/* * PROJECT: ReactOS api tests * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory * PURPOSE: Test for CImage * PROGRAMMER: Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com) */ #include #ifdef __REACTOS__ #include #else #include #include #include const char *g_file = NULL; int g_line = 0; void ok_func(BOOL value, const char *fmt, ...) { va_list va; va_start(va, fmt); if (!value) { printf("%s (%d): ", g_file, g_line); vprintf(fmt, va); } va_end(va); } #undef ok #define ok g_file = __FILE__; g_line = __LINE__; ok_func #define START_TEST(x) int main(void) #endif const TCHAR* szFiles[] = { TEXT("ant.png"), TEXT("ant.tif"), TEXT("ant.gif"), TEXT("ant.jpg"), TEXT("ant.bmp"), }; static TCHAR szTempPath[MAX_PATH]; TCHAR* file_name(const TCHAR* file) { static TCHAR buffer[MAX_PATH]; lstrcpy(buffer, szTempPath); lstrcat(buffer, TEXT("\\")); lstrcat(buffer, file); return buffer; } static void write_bitmap(HINSTANCE hInst, int id, TCHAR* file) { HRSRC rsrc; rsrc = FindResource(hInst, MAKEINTRESOURCE(id), MAKEINTRESOURCE(RT_BITMAP)); ok(rsrc != NULL, "Expected to find an image resource\n"); if (rsrc) { void *rsrc_data; HANDLE hfile; BOOL ret; HGLOBAL glob = LoadResource(hInst, rsrc); DWORD rsrc_size = SizeofResource(hInst, rsrc); rsrc_data = LockResource(glob); hfile = CreateFile(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); ok(hfile != INVALID_HANDLE_VALUE, "Unable to open temp file: %lu\n", GetLastError()); if (hfile != INVALID_HANDLE_VALUE) { BITMAPFILEHEADER bfh; DWORD dwWritten; bfh.bfType = 'MB'; bfh.bfSize = rsrc_size + sizeof(BITMAPFILEHEADER); bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); bfh.bfReserved1 = bfh.bfReserved2 = 0; ret = WriteFile(hfile, &bfh, sizeof(bfh), &dwWritten, NULL); ok(ret, "Unable to write temp file: %lu\n", GetLastError()); ret = WriteFile(hfile, rsrc_data, rsrc_size, &dwWritten, NULL); ok(ret, "Unable to write temp file: %lu\n", GetLastError()); CloseHandle(hfile); } UnlockResource(rsrc_data); } } START_TEST(CImage) { HRESULT hr; TCHAR* file; BOOL bOK; int width, height, bpp; size_t n; CImage image1, image2; COLORREF color; HDC hDC; #if 0 width = image1.GetWidth(); height = image1.GetHeight(); bpp = image1.GetBPP(); #endif HINSTANCE hInst = GetModuleHandle(NULL); GetTempPath(MAX_PATH, szTempPath); image1.LoadFromResource(hInst, 1); ok(!image1.IsNull(), "Expected image1 is not null\n"); width = image1.GetWidth(); ok(width == 48, "Expected width to be 48, was: %d\n", width); height = image1.GetHeight(); ok(height == 48, "Expected height to be 48, was: %d\n", height); bpp = image1.GetBPP(); ok(bpp == 8, "Expected bpp to be 8, was: %d\n", bpp); image2.LoadFromResource(hInst, 2); ok(!image2.IsNull(), "Expected image2 is not null\n"); image2.SetTransparentColor(RGB(255, 255, 255)); width = image2.GetWidth(); ok(width == 32, "Expected width to be 32, was: %d\n", width); height = image2.GetHeight(); ok(height == 32, "Expected height to be 32, was: %d\n", height); bpp = image2.GetBPP(); ok(bpp == 8, "Expected bpp to be 8, was: %d\n", bpp); color = image1.GetPixel(5, 5); ok(color == RGB(166, 202, 240), "Expected color to be 166, 202, 240; was: %i, %i, %i\n", GetRValue(color), GetGValue(color), GetBValue(color)); hDC = image1.GetDC(); bOK = image2.Draw(hDC, 0, 0); image1.ReleaseDC(); ok(bOK != FALSE, "Expected bDraw to be TRUE, was: %d\n", bOK); image2.Destroy(); color = image1.GetPixel(5, 5); ok(color == RGB(255, 0,0), "Expected color to be 255, 0, 0; was: %i, %i, %i\n", GetRValue(color), GetGValue(color), GetBValue(color)); file = file_name(TEXT("ant.bmp")); write_bitmap(hInst, 1, file); hr = image2.Load(file); ok(hr == S_OK, "Expected hr to be S_OK, was: %08lx\n", hr); ok(!image2.IsNull(), "Expected image1 is not null\n"); bOK = DeleteFile(file); ok(bOK, "Expected bOK to be TRUE, was: %d\n", bOK); width = image2.GetWidth(); ok(width == 48, "Expected width to be 48, was: %d\n", width); height = image2.GetHeight(); ok(height == 48, "Expected height to be 48, was: %d\n", height); bpp = image2.GetBPP(); ok(bpp == 8, "Expected bpp to be 8, was: %d\n", bpp); for (n = 0; n < _countof(szFiles); ++n) { file = file_name(szFiles[n]); image2.Destroy(); if (n == 0) hr = image1.Save(file, Gdiplus::ImageFormatPNG); else hr = image1.Save(file); ok(hr == S_OK, "Expected hr to be S_OK, was: %08lx (for %i)\n", hr, n); bOK = (GetFileAttributes(file) != 0xFFFFFFFF); ok(bOK, "Expected bOK to be TRUE, was: %d (for %i)\n", bOK, n); hr = image2.Load(file); ok(hr == S_OK, "Expected hr to be S_OK, was: %08lx (for %i)\n", hr, n); bOK = DeleteFile(file); ok(bOK, "Expected bOK to be TRUE, was: %d (for %i)\n", bOK, n); width = image2.GetWidth(); ok(width == 48, "Expected width to be 48, was: %d (for %i)\n", width, n); height = image2.GetHeight(); ok(height == 48, "Expected height to be 48, was: %d (for %i)\n", height, n); bpp = image2.GetBPP(); if (n == 3) { ok(bpp == 24, "Expected bpp to be 24, was: %d (for %i)\n", bpp, n); } else { ok(bpp == 8, "Expected bpp to be 8, was: %d (for %i)\n", bpp, n); } color = image1.GetPixel(5, 5); ok(color == RGB(255, 0,0), "Expected color to be 255, 0, 0; was: %i, %i, %i (for %i)\n", GetRValue(color), GetGValue(color), GetBValue(color), n); } }