Author: pschweitzer
Date: Sun Oct 6 22:16:42 2013
New Revision: 60566
URL:
http://svn.reactos.org/svn/reactos?rev=60566&view=rev
Log:
[PSAPI_APITEST]
Add an apitest for psapi GetDeviceDriverFileName.
I'm looking for help to bring it even farther. Ideally, it would be interesting
to be able to GetDeviceDriverFileName on ntoskrnl base address. The whole point is
about getting it dynamically.
The day we can do it properly, I can predict that it will fail on ReactOS, we're not
having
correct paths for KDCOM, HAL, and NTOSKRNL modules in the kernel (thank you FreeLdr? -
Where are you
starting '\'?)
Added:
trunk/rostests/apitests/psapi/
trunk/rostests/apitests/psapi/CMakeLists.txt (with props)
trunk/rostests/apitests/psapi/psapi.c (with props)
trunk/rostests/apitests/psapi/testlist.c (with props)
Modified:
trunk/rostests/apitests/CMakeLists.txt
Modified: trunk/rostests/apitests/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/CMakeLists.txt?r…
==============================================================================
--- trunk/rostests/apitests/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/rostests/apitests/CMakeLists.txt [iso-8859-1] Sun Oct 6 22:16:42 2013
@@ -13,6 +13,7 @@
add_subdirectory(msvcrt)
add_subdirectory(ntdll)
add_subdirectory(powrprof)
+add_subdirectory(psapi)
add_subdirectory(user32)
if((NOT MSVC) AND (ARCH STREQUAL "i386"))
add_subdirectory(w32kdll)
Added: trunk/rostests/apitests/psapi/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/psapi/CMakeLists…
==============================================================================
--- trunk/rostests/apitests/psapi/CMakeLists.txt (added)
+++ trunk/rostests/apitests/psapi/CMakeLists.txt [iso-8859-1] Sun Oct 6 22:16:42 2013
@@ -0,0 +1,10 @@
+
+list(APPEND SOURCE
+ psapi.c
+ testlist.c)
+
+add_executable(psapi_apitest ${SOURCE})
+target_link_libraries(psapi_apitest wine)
+set_module_type(psapi_apitest win32cui)
+add_importlibs(psapi_apitest psapi msvcrt kernel32 ntdll)
+add_cd_file(TARGET psapi_apitest DESTINATION reactos/bin FOR all)
Propchange: trunk/rostests/apitests/psapi/CMakeLists.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/psapi/psapi.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/psapi/psapi.c?re…
==============================================================================
--- trunk/rostests/apitests/psapi/psapi.c (added)
+++ trunk/rostests/apitests/psapi/psapi.c [iso-8859-1] Sun Oct 6 22:16:42 2013
@@ -0,0 +1,128 @@
+/*
+ * PROJECT: ReactOS api tests
+ * LICENSE: GPLv2+ - See COPYING in the top level directory
+ * PURPOSE: Test for GetDeviceDriverFileName
+ * PROGRAMMER: Pierre Schweitzer
+ */
+
+#include <apitest.h>
+#include <psapi.h>
+#include <tlhelp32.h>
+#include <stdio.h>
+
+typedef struct
+{
+ LPVOID ImageBase;
+ CHAR Path[255];
+ DWORD Len;
+} TEST_MODULE_INFO;
+
+static LPVOID IntGetImageBase(LPCSTR Image)
+{
+ HANDLE Snap;
+ MODULEENTRY32 Module;
+
+ Snap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);
+ if (Snap == INVALID_HANDLE_VALUE)
+ {
+ return (LPVOID)0x00000000;
+ }
+
+ Module.dwSize = sizeof(MODULEENTRY32);
+ if(!Module32First(Snap, &Module))
+ {
+ CloseHandle(Snap);
+ return (LPVOID)0x00000000;
+ }
+
+ do
+ {
+ if (lstrcmpiA(Module.szExePath, Image) == 0)
+ {
+ CloseHandle(Snap);
+ return (LPVOID)Module.modBaseAddr;
+ }
+ } while(Module32Next(Snap, &Module));
+
+ CloseHandle(Snap);
+ return (LPVOID)0x00000000;
+}
+
+static BOOLEAN IntGetModuleInformation(LPCSTR Module, BOOLEAN IsDriver, BOOLEAN
IsProcMod, TEST_MODULE_INFO * Info)
+{
+ CHAR System[255];
+ UINT Len;
+
+ memset(Info, 0, sizeof(TEST_MODULE_INFO));
+
+ /* Get system path */
+ Len = GetSystemWindowsDirectory(System, 255);
+ if (Len > 255 || Len == 0)
+ {
+ printf("GetSystemWindowsDirectory failed\n");
+ return FALSE;
+ }
+
+ /* Make path to module */
+ strcat(System, "\\system32\\");
+ if (IsDriver) strcat(System, "drivers\\");
+ strcat(System, Module);
+
+ /* Get base address */
+ if (IsProcMod)
+ {
+ Info->ImageBase = IntGetImageBase(System);
+ if (!Info->ImageBase)
+ {
+ printf("IntGetImageBase failed\n");
+ return FALSE;
+ }
+ }
+ else
+ {
+ /* FIXME */
+ printf("Not supported yet!\n");
+ return FALSE;
+ }
+
+ /* Skip disk */
+ strcpy(Info->Path, System + 2);
+ Info->Len = strlen(Info->Path);
+
+ return TRUE;
+}
+
+START_TEST(GetDeviceDriverFileName)
+{
+ DWORD Len;
+ CHAR FileName[255];
+ TEST_MODULE_INFO ModInfo;
+
+ SetLastError(0xDEADBEEF);
+ Len = GetDeviceDriverFileNameA(0, FileName, 255);
+ ok(Len == 0, "Len: %lu\n", Len);
+ ok(GetLastError() == ERROR_INVALID_HANDLE, "Error: %lx\n",
GetLastError());
+
+ if (IntGetModuleInformation("ntdll.dll", FALSE, TRUE, &ModInfo))
+ {
+ SetLastError(0xDEADBEEF);
+ Len = GetDeviceDriverFileNameA(ModInfo.ImageBase, FileName, 255);
+ ok(Len == ModInfo.Len, "Len: %lu\n", Len);
+ ok(GetLastError() == 0xDEADBEEF, "Error: %lx\n", GetLastError());
+ ok(lstrcmpiA(ModInfo.Path, FileName) == 0, "File name: %s\n",
FileName);
+
+ /* Test with too small buffer */
+ SetLastError(0xDEADBEEF);
+ ModInfo.Len--;
+ ModInfo.Path[ModInfo.Len] = 0;
+ FileName[ModInfo.Len] = 0;
+ Len = GetDeviceDriverFileNameA(ModInfo.ImageBase, FileName, ModInfo.Len);
+ ok(Len == ModInfo.Len, "Len: %lu\n", Len);
+ ok(GetLastError() == 0xDEADBEEF, "Error: %lx\n", GetLastError());
+ ok(lstrcmpiA(ModInfo.Path, FileName) == 0, "File name: %s\n",
FileName);
+ }
+ else
+ {
+ skip("Couldn't find info about ntdll.dll\n");
+ }
+}
Propchange: trunk/rostests/apitests/psapi/psapi.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/psapi/testlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/psapi/testlist.c…
==============================================================================
--- trunk/rostests/apitests/psapi/testlist.c (added)
+++ trunk/rostests/apitests/psapi/testlist.c [iso-8859-1] Sun Oct 6 22:16:42 2013
@@ -0,0 +1,14 @@
+#define __ROS_LONG64__
+
+#define STANDALONE
+#include <wine/test.h>
+
+extern void func_GetDeviceDriverFileName(void);
+
+const struct test winetest_testlist[] =
+{
+ { "GetDeviceDriverFileName",
func_GetDeviceDriverFileName },
+
+ { 0, 0 }
+};
+
Propchange: trunk/rostests/apitests/psapi/testlist.c
------------------------------------------------------------------------------
svn:eol-style = native