ReactOS 0.4.15-dev-7934-g1dc8d80
ExtractIconEx.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for ExtractIconEx routine
5 * COPYRIGHT: Copyright 2019 George Bișoc (george.bisoc@reactos.org)
6 * Copyright 2023 Doug Lyons (douglyons@douglyons.com)
7 */
8
9#include "shelltest.h"
10#include <stdio.h>
11
12typedef struct
13{
17
19{
20 FILE *fp = NULL;
21 bool exists = FALSE;
22
23 fp = fopen(FileName, "r");
24 if (fp != NULL)
25 {
26 exists = TRUE;
27 fclose(fp);
28 }
29 return exists;
30}
31
33{
34 FILE *fout;
35 HGLOBAL hData;
36 HRSRC hRes;
37 LPVOID lpResLock;
38 UINT iSize;
39
41 {
42 skip("'%s' already exists. Exiting now\n", FileName);
43 return FALSE;
44 }
45
47 if (hRes == NULL)
48 {
49 skip("Could not locate resource (%d). Exiting now\n", i);
50 return FALSE;
51 }
52
53 iSize = SizeofResource(NULL, hRes);
54
55 hData = LoadResource(NULL, hRes);
56 if (hData == NULL)
57 {
58 skip("Could not load resource (%d). Exiting now\n", i);
59 return FALSE;
60 }
61
62 // Lock the resource into global memory.
63 lpResLock = LockResource(hData);
64 if (lpResLock == NULL)
65 {
66 skip("Could not lock resource (%d). Exiting now\n", i);
67 return FALSE;
68 }
69
70 fout = fopen(FileName, "wb");
71 fwrite(lpResLock, iSize, 1, fout);
72 fclose(fout);
73 return TRUE;
74}
75
77{
78 /* Executable file with icon */
79 {L"%SystemRoot%\\System32\\cmd.exe", 1},
80
81 /* Executable file without icon */
82 {L"%SystemRoot%\\System32\\autochk.exe", 0},
83
84 /* Non-existing files */
85 {L"%SystemRoot%\\non-existent-file.sdf", 0},
86
87 /* Multiple icons in the same EXE file (18 icons) */
88 {L"%SystemRoot%\\explorer.exe", 18},
89
90 /* Multiple icons in the same ICO file (6 icons)
91 * Per MS: If the file is an .ico file, the return value is 1. */
92 {L"sysicon.ico", 1},
93
94 /* ICO file with both normal and PNG icons */
95 {L"ROS.ico", 0}
96};
97
99{
100 UINT i, nReturnedIcons, nExtractedIcons;
101 CHAR FileName[2][13] = { "ROS.ico", "sysicon.ico" };
102
103 if (!ResourceToFile(2, FileName[0]))
104 return;
105 if (!ResourceToFile(3, FileName[1]))
106 return;
107
108 /* Check count of icons returned */
109 for (i = 0; i < _countof(IconTests); ++i)
110 {
111 nReturnedIcons = ExtractIconExW(IconTests[i].pszFilePath, -1, NULL, NULL, 0);
112 ok(nReturnedIcons == IconTests[i].nIcons, "ExtractIconExW(%u): Expects %u icons, got %u\n", i, IconTests[i].nIcons, nReturnedIcons);
113 }
114
115 /* Check if the 0th icon can be extracted successfully */
116 for (i = 0; i < _countof(IconTests); ++i)
117 {
118 nExtractedIcons = ExtractIconExW(IconTests[i].pszFilePath, 0, NULL, NULL, 1);
119 ok(nExtractedIcons == IconTests[i].nIcons, "ExtractIconExW(%u): Expects %u icons, got %u\n", i, IconTests[i].nIcons, nExtractedIcons);
120 }
121
124}
BOOL ResourceToFile(INT i, LPCSTR FileName)
EXTRACTICONTESTS IconTests[]
BOOL FileExists(LPCSTR FileName)
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:849
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define RT_RCDATA
Definition: pedump.c:372
#define ExtractIconEx
Definition: shellapi.h:689
#define _countof(array)
Definition: sndvol32.h:68
const uint16_t * PCWSTR
Definition: typedefs.h:57
int32_t INT
Definition: typedefs.h:58
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
const char * LPCSTR
Definition: xmlstorage.h:183
char CHAR
Definition: xmlstorage.h:175