[SHELL32_APITEST] SHChangeNotify: Improve coverity (#6798)

Improve coverity and speed.
JIRA issue: CORE-13950
- Move NUM_STAGE to the header file.
- Add stages.
- Add DIRTYPE_DESKTOP_DIR and
  DIRTYPE_PRINTERS directory types.
- Improve speed more.
This commit is contained in:
Katayama Hirofumi MZ 2024-04-24 18:25:15 +09:00 committed by GitHub
parent 24e088daa8
commit 8337df2bd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 104 additions and 47 deletions

View File

@ -11,7 +11,6 @@
#include "shell32_apitest_sub.h"
#include <assert.h>
#define NUM_STAGE 4
#define NUM_STEP 8
#define NUM_CHECKS 12
#define INTERVAL 0
@ -236,24 +235,10 @@ static void DoStepCheck(INT iStage, INT iStep, LPCSTR checks)
switch (iStage)
{
case 0:
{
static const TEST_ANSWER c_answers[] =
{
{ __LINE__, "000000010000010000000000" }, // 0
{ __LINE__, "000000040000000000000400" }, // 1
{ __LINE__, "000000000200020000000000" }, // 2
{ __LINE__, "000000000000080000000000" }, // 3
{ __LINE__, "000000000001010000000000" }, // 4
{ __LINE__, "000000000002020000000000" }, // 5
{ __LINE__, "000000000000000020000000" }, // 6
{ __LINE__, "000010000000100000000000" }, // 7
};
C_ASSERT(_countof(c_answers) == NUM_STEP);
lineno = c_answers[iStep].lineno;
answer = c_answers[iStep].answer;
break;
}
case 1:
case 3:
case 6:
case 9:
{
static const TEST_ANSWER c_answers[] =
{
@ -272,6 +257,27 @@ static void DoStepCheck(INT iStage, INT iStep, LPCSTR checks)
break;
}
case 2:
case 4:
case 5:
case 7:
{
static const TEST_ANSWER c_answers[] =
{
{ __LINE__, "000000000000000000000000" }, // 0
{ __LINE__, "000000000000000000000000" }, // 1
{ __LINE__, "000000000000000000000000" }, // 2
{ __LINE__, "000000000000000000000000" }, // 3
{ __LINE__, "000000000000000000000000" }, // 4
{ __LINE__, "000000000000000000000000" }, // 5
{ __LINE__, "000000000000000000000000" }, // 6
{ __LINE__, "000000000000000000000000" }, // 7
};
C_ASSERT(_countof(c_answers) == NUM_STEP);
lineno = c_answers[iStep].lineno;
answer = c_answers[iStep].answer;
break;
}
case 8:
{
static const TEST_ANSWER c_answers[] =
{
@ -279,8 +285,8 @@ static void DoStepCheck(INT iStage, INT iStep, LPCSTR checks)
{ __LINE__, "000000040000000000000400" }, // 1
{ __LINE__, "000000000200020000000000" }, // 2
{ __LINE__, "000000000000080000000000" }, // 3
{ __LINE__, "000000000001010000000000" }, // 4 // Recursive
{ __LINE__, "000000000002020000000000" }, // 5 // Recursive
{ __LINE__, "000000000001010000000000" }, // 4 // Recursive case
{ __LINE__, "000000000002020000000000" }, // 5 // Recursive case
{ __LINE__, "000000000000000020000000" }, // 6
{ __LINE__, "000010000000100000000000" }, // 7
};
@ -290,30 +296,13 @@ static void DoStepCheck(INT iStage, INT iStep, LPCSTR checks)
if (iStep == 4 || iStep == 5) // Recursive cases
{
if (lstrcmpA(checks, "000000000000000000000000") == 0)
{
trace("Warning! Recursive cases...\n");
answer = "000000000000000000000000";
else
trace("Warning\n");
}
}
break;
}
case 3:
{
static const TEST_ANSWER c_answers[] =
{
{ __LINE__, "000000010000010000000000" }, // 0
{ __LINE__, "000000040000000000000400" }, // 1
{ __LINE__, "000000000200020000000000" }, // 2
{ __LINE__, "000000000000080000000000" }, // 3
{ __LINE__, "000000000001010000000000" }, // 4 // Recursive
{ __LINE__, "000000000002020000000000" }, // 5 // Recursive
{ __LINE__, "000000000000000020000000" }, // 6
{ __LINE__, "000010000000100000000000" }, // 7
};
C_ASSERT(_countof(c_answers) == NUM_STEP);
lineno = c_answers[iStep].lineno;
answer = c_answers[iStep].answer;
break;
}
default:
{
assert(0);
@ -334,7 +323,7 @@ static DWORD WINAPI StageThreadFunc(LPVOID arg)
// 0: Create file1 in dir1
s_iStep = 0;
trace("Step %d\n", s_iStep);
::Sleep(1000); // Extra wait
SHChangeNotify(0, SHCNF_PATHW | SHCNF_FLUSH, NULL, NULL);
ZeroMemory(s_abChecks, sizeof(s_abChecks));
ret = DoCreateFile(s_szFile1InDir1);
ok_int(ret, TRUE);

View File

@ -14,7 +14,9 @@
typedef enum DIRTYPE
{
DIRTYPE_DESKTOP = 0,
DIRTYPE_DESKTOP_DIR,
DIRTYPE_DRIVES,
DIRTYPE_PRINTERS,
DIRTYPE_DIR1,
DIRTYPE_MAX
} DIRTYPE;
@ -24,8 +26,6 @@ static LPITEMIDLIST s_pidl[DIRTYPE_MAX];
static UINT s_uRegID = 0;
static INT s_iStage = -1;
#define NUM_STAGE 4
#define EVENTS (SHCNE_CREATE | SHCNE_DELETE | SHCNE_MKDIR | SHCNE_RMDIR | \
SHCNE_RENAMEFOLDER | SHCNE_RENAMEITEM | SHCNE_UPDATEDIR | SHCNE_UPDATEITEM)
@ -40,11 +40,23 @@ inline LPITEMIDLIST DoGetPidl(INT iDir)
SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &ret);
break;
}
case DIRTYPE_DESKTOP_DIR:
{
WCHAR szPath1[MAX_PATH];
SHGetSpecialFolderPathW(NULL, szPath1, CSIDL_DESKTOPDIRECTORY, FALSE);
ret = ILCreateFromPathW(szPath1);
break;
}
case DIRTYPE_DRIVES:
{
SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &ret);
break;
}
case DIRTYPE_PRINTERS:
{
SHGetSpecialFolderLocation(NULL, CSIDL_PRINTERS, &ret);
break;
}
case DIRTYPE_DIR1:
{
WCHAR szPath1[MAX_PATH];
@ -85,8 +97,8 @@ static BOOL InitSHCN(HWND hwnd)
{
case 0:
{
entry.fRecursive = TRUE;
entry.pidl = s_pidl[DIRTYPE_DESKTOP];
entry.fRecursive = FALSE;
entry.pidl = NULL;
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
@ -94,7 +106,7 @@ static BOOL InitSHCN(HWND hwnd)
case 1:
{
entry.fRecursive = TRUE;
entry.pidl = s_pidl[DIRTYPE_DRIVES];
entry.pidl = NULL;
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
@ -102,12 +114,60 @@ static BOOL InitSHCN(HWND hwnd)
case 2:
{
entry.fRecursive = FALSE;
entry.pidl = s_pidl[DIRTYPE_DIR1];
entry.pidl = s_pidl[DIRTYPE_DESKTOP];
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
}
case 3:
{
entry.fRecursive = TRUE;
entry.pidl = s_pidl[DIRTYPE_DESKTOP];
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
}
case 4:
{
entry.fRecursive = TRUE;
entry.pidl = s_pidl[DIRTYPE_DESKTOP_DIR];
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
}
case 5:
{
entry.fRecursive = FALSE;
entry.pidl = s_pidl[DIRTYPE_DRIVES];
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
}
case 6:
{
entry.fRecursive = TRUE;
entry.pidl = s_pidl[DIRTYPE_DRIVES];
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
}
case 7:
{
entry.fRecursive = TRUE;
entry.pidl = s_pidl[DIRTYPE_PRINTERS];
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
}
case 8:
{
entry.fRecursive = FALSE;
entry.pidl = s_pidl[DIRTYPE_DIR1];
sources = SHCNRF_NewDelivery | SHCNRF_ShellLevel;
events = EVENTS;
break;
}
case 9:
{
entry.fRecursive = TRUE;
entry.pidl = s_pidl[DIRTYPE_DIR1];
@ -293,13 +353,19 @@ wWinMain(
wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wc.lpszClassName = SUB_CLASSNAME;
if (!RegisterClassW(&wc))
{
assert(0);
return -1;
}
HWND hwnd = CreateWindowW(SUB_CLASSNAME, SUB_CLASSNAME, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 100,
NULL, NULL, hInstance, NULL);
if (!hwnd)
{
assert(0);
return -2;
}
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);

View File

@ -10,6 +10,8 @@
#define WM_SHELL_NOTIFY (WM_USER + 100)
#define NUM_STAGE 10
static inline HWND DoWaitForWindow(LPCWSTR clsname, LPCWSTR text, BOOL bClosing, BOOL bForce)
{
HWND hwnd = NULL;