Author: tkreuzer
Date: Tue Mar 24 04:25:03 2009
New Revision: 40199
URL:
http://svn.reactos.org/svn/reactos?rev=40199&view=rev
Log:
- Add a bunch of tests for NtGdiDeleteObjectApp
- Add Is handle valid function to check whether a handle is still valid.
Added:
trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c (with props)
Modified:
trunk/rostests/apitests/w32knapi/testlist.c
trunk/rostests/apitests/w32knapi/w32knapi.c
trunk/rostests/apitests/w32knapi/w32knapi.h
Added: trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/w32knapi/ntgdi/N…
==============================================================================
--- trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c (added)
+++ trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c [iso-8859-1] Tue Mar 24
04:25:03 2009
@@ -1,0 +1,93 @@
+
+INT
+Test_NtGdiDeleteObjectApp(PTESTINFO pti)
+{
+ HDC hdc;
+ HBITMAP hbmp;
+ HBRUSH hbrush;
+ BOOL ret;
+
+ /* Try to delete 0 */
+ SetLastError(0);
+ ret = NtGdiDeleteObjectApp(0);
+ TEST(ret == 0);
+ TEST(GetLastError() == 0);
+
+ /* Delete a DC */
+ SetLastError(0);
+ hdc = CreateCompatibleDC(NULL);
+ ASSERT(hdc);
+ TEST(IsHandleValid(hdc) == 1);
+ ret = NtGdiDeleteObjectApp(hdc);
+ TEST(ret == 1);
+ TEST(GetLastError() == 0);
+ TEST(IsHandleValid(hdc) == 0);
+
+ /* Delete a brush */
+ SetLastError(0);
+ hbrush = CreateSolidBrush(0x123456);
+ ASSERT(hbrush);
+ TEST(IsHandleValid(hbrush) == 1);
+ ret = NtGdiDeleteObjectApp(hbrush);
+ TEST(ret == 1);
+ TEST(GetLastError() == 0);
+ TEST(IsHandleValid(hbrush) == 0);
+
+ /* Try to delete a stock brush */
+ SetLastError(0);
+ hbrush = GetStockObject(BLACK_BRUSH);
+ ASSERT(hbrush);
+ TEST(IsHandleValid(hbrush) == 1);
+ ret = NtGdiDeleteObjectApp(hbrush);
+ TEST(ret == 1);
+ TEST(GetLastError() == 0);
+ TEST(IsHandleValid(hbrush) == 1);
+
+ /* Delete a bitmap */
+ SetLastError(0);
+ hbmp = CreateBitmap(10, 10, 1, 1, NULL);
+ ASSERT(hbmp);
+ TEST(IsHandleValid(hbmp) == 1);
+ ret = NtGdiDeleteObjectApp(hbmp);
+ TEST(ret == 1);
+ TEST(GetLastError() == 0);
+ TEST(IsHandleValid(hbmp) == 0);
+
+ /* Create a DC for further use */
+ hdc = CreateCompatibleDC(NULL);
+ ASSERT(hdc);
+
+ /* Try to delete a brush that is selected into a DC */
+ SetLastError(0);
+ hbrush = CreateSolidBrush(0x123456);
+ ASSERT(hbrush);
+ TEST(IsHandleValid(hbrush) == 1);
+ TEST(NtGdiSelectBrush(hdc, hbrush));
+ ret = NtGdiDeleteObjectApp(hbrush);
+ TEST(ret == 1);
+ TEST(GetLastError() == 0);
+ TEST(IsHandleValid(hbrush) == 1);
+
+ /* Try to delete a bitmap that is selected into a DC */
+ SetLastError(0);
+ hbmp = CreateBitmap(10, 10, 1, 1, NULL);
+ ASSERT(hbmp);
+ TEST(IsHandleValid(hbmp) == 1);
+ TEST(NtGdiSelectBitmap(hdc, hbmp));
+ ret = NtGdiDeleteObjectApp(hbmp);
+ TEST(ret == 1);
+ TEST(GetLastError() == 0);
+ TEST(IsHandleValid(hbmp) == 1);
+
+ /* Bitmap get's deleted as soon as we dereference it */
+ NtGdiSelectBitmap(hdc, GetStockObject(DEFAULT_BITMAP));
+ TEST(IsHandleValid(hbmp) == 0);
+
+ ret = NtGdiDeleteObjectApp(hbmp);
+ TEST(ret == 1);
+ TEST(GetLastError() == 0);
+ TEST(IsHandleValid(hbmp) == 0);
+
+
+ return APISTATUS_NORMAL;
+}
Propchange: trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/rostests/apitests/w32knapi/testlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/w32knapi/testlis…
==============================================================================
--- trunk/rostests/apitests/w32knapi/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/w32knapi/testlist.c [iso-8859-1] Tue Mar 24 04:25:03 2009
@@ -13,6 +13,7 @@
#include "ntgdi/NtGdiCreateCompatibleBitmap.c"
#include "ntgdi/NtGdiCreateCompatibleDC.c"
#include "ntgdi/NtGdiCreateDIBSection.c"
+#include "ntgdi/NtGdiDeleteObjectApp.c"
#include "ntgdi/NtGdiDoPalette.c"
#include "ntgdi/NtGdiEngCreatePalette.c"
//#include "ntgdi/NtGdiEnumFontChunk.c"
@@ -72,6 +73,7 @@
{ L"NtGdiCreateCompatibleBitmap", Test_NtGdiCreateCompatibleBitmap },
{ L"NtGdiCreateCompatibleDC", Test_NtGdiCreateCompatibleDC },
{ L"NtGdiCreateDIBSection", Test_NtGdiCreateDIBSection },
+ { L"NtGdiDeleteObjectApp", Test_NtGdiDeleteObjectApp },
{ L"NtGdiDoPalette", Test_NtGdiDoPalette },
{ L"NtGdiEngCreatePalette", Test_NtGdiEngCreatePalette },
// { L"NtGdiEnumFontChunk", Test_NtGdiEnumFontChunk },
Modified: trunk/rostests/apitests/w32knapi/w32knapi.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/w32knapi/w32knap…
==============================================================================
--- trunk/rostests/apitests/w32knapi/w32knapi.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/w32knapi/w32knapi.c [iso-8859-1] Tue Mar 24 04:25:03 2009
@@ -11,6 +11,22 @@
PTEB pTeb = NtCurrentTeb();
PPEB pPeb = pTeb->ProcessEnvironmentBlock;
return pPeb->GdiSharedHandleTable;
+}
+
+BOOL
+IsHandleValid(HGDIOBJ hobj)
+{
+ USHORT Index = (ULONG_PTR)hobj;
+ PGDI_TABLE_ENTRY pentry = &GdiHandleTable[Index];
+
+ if (pentry->KernelData == NULL ||
+ pentry->KernelData < (PVOID)0x80000000 ||
+ (USHORT)pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16))
+ {
+ return FALSE;
+ }
+
+ return TRUE;
}
static DWORD WINAPI
Modified: trunk/rostests/apitests/w32knapi/w32knapi.h
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/w32knapi/w32knap…
==============================================================================
--- trunk/rostests/apitests/w32knapi/w32knapi.h [iso-8859-1] (original)
+++ trunk/rostests/apitests/w32knapi/w32knapi.h [iso-8859-1] Tue Mar 24 04:25:03 2009
@@ -37,6 +37,7 @@
extern HMODULE g_hModule;
extern PGDI_TABLE_ENTRY GdiHandleTable;
+BOOL IsHandleValid(HGDIOBJ hobj);
DWORD Syscall(LPWSTR lpszFunction, int cParams, void* pParams);
BOOL InitOsVersion();
extern UINT g_OsIdx;