COMCTL32: Fix some DPA functions
Felix Nawothnig
felix.nawothnig at t-online.de
Thu Jul 7 19:00:00 CDT 2005
ChangeLog:
Fix some DPA functions so they pass the new tests.
-------------- next part --------------
Index: dlls/comctl32/dpa.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/dpa.c,v
retrieving revision 1.1
diff -u -p -r1.1 dpa.c
--- dlls/comctl32/dpa.c 6 Jul 2005 10:32:18 -0000 1.1
+++ dlls/comctl32/dpa.c 7 Jul 2005 23:57:55 -0000
@@ -540,15 +540,16 @@ INT WINAPI DPA_InsertPtr (const HDPA hdp
if (!hdpa || i < 0) return -1;
- if (i >= 0x7fff)
- i = hdpa->nItemCount;
-
- if (i >= hdpa->nItemCount)
- return DPA_SetPtr(hdpa, i, p) ? i : -1;
+ /* append item if index is out of bounds */
+ i = min(hdpa->nItemCount, i);
/* create empty spot at the end */
if (!DPA_SetPtr(hdpa, hdpa->nItemCount, 0)) return -1;
- memmove (hdpa->ptrs + i + 1, hdpa->ptrs + i, (hdpa->nItemCount - i - 1) * sizeof(LPVOID));
+
+ if (i != hdpa->nItemCount - 1)
+ memmove (hdpa->ptrs + i + 1, hdpa->ptrs + i,
+ (hdpa->nItemCount - i - 1) * sizeof(LPVOID));
+
hdpa->ptrs[i] = p;
return i;
}
@@ -574,7 +575,7 @@ BOOL WINAPI DPA_SetPtr (const HDPA hdpa,
TRACE("(%p %d %p)\n", hdpa, i, p);
- if (!hdpa || i < 0 || i > 0x7fff)
+ if (!hdpa || i < 0)
return FALSE;
if (hdpa->nItemCount <= i) {
@@ -824,13 +825,7 @@ INT WINAPI DPA_Search (const HDPA hdpa,
}
}
- if (uOptions & DPAS_INSERTBEFORE) {
- if (r == -1) r = 0;
- TRACE("-- ret=%d\n", r);
- return r;
- }
-
- if (uOptions & DPAS_INSERTAFTER) {
+ if (uOptions & (DPAS_INSERTBEFORE | DPAS_INSERTAFTER)) {
TRACE("-- ret=%d\n", l);
return l;
}
@@ -942,13 +937,13 @@ VOID WINAPI DPA_EnumCallback (HDPA hdpa,
TRACE("(%p %p %p)\n", hdpa, enumProc, lParam);
if (!hdpa)
- return;
+ return;
if (hdpa->nItemCount <= 0)
- return;
+ return;
for (i = 0; i < hdpa->nItemCount; i++) {
- if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
- return;
+ if ((enumProc)(hdpa->ptrs[i], lParam) == 0)
+ return;
}
return;
Index: dlls/comctl32/tests/dpa.c
===================================================================
RCS file: /home/wine/wine/dlls/comctl32/tests/dpa.c,v
retrieving revision 1.10
diff -u -p -r1.10 dpa.c
--- dlls/comctl32/tests/dpa.c 7 Jul 2005 11:26:26 -0000 1.10
+++ dlls/comctl32/tests/dpa.c 7 Jul 2005 23:57:56 -0000
@@ -229,12 +229,12 @@ static void test_dpa(void)
ok(ret == 3, "ret=%d\n", ret);
/* Append item using out of bound index */
ret = pDPA_InsertPtr(dpa, 5, (PVOID)2);
- todo_wine ok(ret == 4, "ret=%d\n", ret);
+ ok(ret == 4, "ret=%d\n", ret);
/* Append item using DPA_APPEND */
ret = pDPA_InsertPtr(dpa, DPA_APPEND, (PVOID)4);
- todo_wine ok(ret == 5, "ret=%d\n", ret);
+ ok(ret == 5, "ret=%d\n", ret);
- todo_wine ok(CheckDPA(dpa, 0x516324, &dw), "dw=0x%lx\n", dw);
+ ok(CheckDPA(dpa, 0x516324, &dw), "dw=0x%lx\n", dw);
for(i = 1; i <= 6; i++)
{
@@ -306,7 +306,7 @@ static void test_dpa(void)
/* DPAS_INSERTBEFORE works just like DPAS_INSERTAFTER */
i = pDPA_Search(dpa, (PVOID)3, 0,
CB_CmpLT, 0xdeadbeef, DPAS_SORTED|DPAS_INSERTBEFORE);
- todo_wine ok(i == 2, "i=%d\n", i);
+ ok(i == 2, "i=%d\n", i);
/* Re-insert the item */
ret = pDPA_InsertPtr(dpa, 2, (PVOID)3);
@@ -355,9 +355,9 @@ static void test_dpa(void)
}
/* Setting item with huge index should work */
- todo_wine ok(pDPA_SetPtr(dpa2, 0x12345, (PVOID)0xdeadbeef), "\n");
+ ok(pDPA_SetPtr(dpa2, 0x12345, (PVOID)0xdeadbeef), "\n");
ret = pDPA_GetPtrIndex(dpa2, (PVOID)0xdeadbeef);
- todo_wine ok(ret == 0x12345, "ret=%d\n", ret);
+ ok(ret == 0x12345, "ret=%d\n", ret);
pDPA_DeleteAllPtrs(dpa2);
ok(CheckDPA(dpa2, 0, &dw2), "dw2=0x%lx\n", dw2);
More information about the wine-patches
mailing list