Author: mjansen
Date: Mon Jun 26 14:58:08 2017
New Revision: 75205
URL:
http://svn.reactos.org/svn/reactos?rev=75205&view=rev
Log:
[APPHELP_APITEST] Add tests for SdbGetMatchingExe, to test matching on version resources.
CORE-13284
Added:
trunk/rostests/apitests/apphelp/testdata.rc (with props)
trunk/rostests/apitests/apphelp/testdb.xml (with props)
Modified:
trunk/rostests/apitests/apphelp/CMakeLists.txt
trunk/rostests/apitests/apphelp/db.cpp
Modified: trunk/rostests/apitests/apphelp/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/apphelp/CMakeLis…
==============================================================================
--- trunk/rostests/apitests/apphelp/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/rostests/apitests/apphelp/CMakeLists.txt [iso-8859-1] Mon Jun 26 14:58:08 2017
@@ -1,5 +1,7 @@
project(appcompat)
add_definitions(-D__ROS_LONG64__ -DWINETEST_USE_DBGSTR_LONGLONG)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
list(APPEND SOURCE
apphelp.c
@@ -7,8 +9,16 @@
db.cpp
env.c
layerapi.c
- testlist.c)
+ testlist.c
+ testdata.rc
+ testdb.xml)
+add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/testdb.sdb
+ COMMAND native-xml2sdb -i ${CMAKE_CURRENT_SOURCE_DIR}/testdb.xml -o
${CMAKE_CURRENT_BINARY_DIR}/testdb.sdb
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/testdb.xml native-xml2sdb)
+
+add_custom_target(testdb DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/testdb.sdb)
+add_rc_deps(testdata.rc testdb)
add_executable(apphelp_apitest ${SOURCE})
set_module_type(apphelp_apitest win32cui)
target_link_libraries(apphelp_apitest ${PSEH_LIB})
Modified: trunk/rostests/apitests/apphelp/db.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/apphelp/db.cpp?r…
==============================================================================
--- trunk/rostests/apitests/apphelp/db.cpp [iso-8859-1] (original)
+++ trunk/rostests/apitests/apphelp/db.cpp [iso-8859-1] Mon Jun 26 14:58:08 2017
@@ -1332,6 +1332,147 @@
ok(ret, "RemoveDirectoryW error: %d\n", GetLastError());
}
+static BOOL write_raw_file(const WCHAR* FileName, const void* Data, DWORD Size)
+{
+ BOOL Success;
+ DWORD dwWritten;
+ HANDLE Handle = CreateFileW(FileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
+
+ if (Handle == INVALID_HANDLE_VALUE)
+ {
+ skip("Failed to create temp file %ls, error %u\n", FileName,
GetLastError());
+ return FALSE;
+ }
+ Success = WriteFile(Handle, Data, Size, &dwWritten, NULL);
+ ok(Success == TRUE, "WriteFile failed with %u\n", GetLastError());
+ ok(dwWritten == Size, "WriteFile wrote %u bytes instead of %u\n",
dwWritten, Size);
+ CloseHandle(Handle);
+ return Success && (dwWritten == Size);
+}
+
+static bool extract_resource(const WCHAR* Filename, LPCWSTR ResourceName)
+{
+ HMODULE hMod = GetModuleHandleW(NULL);
+ HRSRC hRsrc = FindResourceW(hMod, ResourceName, MAKEINTRESOURCEW(RT_RCDATA));
+ ok(!!hRsrc, "Unable to find %s\n", wine_dbgstr_w(ResourceName));
+ if (!hRsrc)
+ return false;
+
+ HGLOBAL hGlobal = LoadResource(hMod, hRsrc);
+ DWORD Size = SizeofResource(hMod, hRsrc);
+ LPVOID pData = LockResource(hGlobal);
+
+ ok(Size && !!pData, "Unable to load %s\n",
wine_dbgstr_w(ResourceName));
+ if (!Size || !pData)
+ return false;
+
+ BOOL Written = write_raw_file(Filename, pData, Size);
+ UnlockResource(pData);
+ return Written;
+}
+
+template<typename SDBQUERYRESULT_T>
+static BOOL test_match_ex(const WCHAR* workdir, HSDB hsdb, int cur)
+{
+ WCHAR exename[MAX_PATH];
+ WCHAR* Vendor;
+ SDBQUERYRESULT_T query;
+ TAGID tagid, exetag;
+ BOOL ret, Succeed;
+ PDB pdb;
+
+ memset(&query, 0xab, sizeof(query));
+
+ swprintf(exename, L"%s\\test_match%d.exe", workdir, cur);
+
+ ret = pSdbTagRefToTagID(hsdb, 0, &pdb, &tagid);
+ ok(pdb != NULL && pdb != (PDB)0x12345678, "Expected pdb to be set to a
valid pdb, was: %p\n", pdb);
+
+ tagid = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_DATABASE);
+ ok(tagid != TAGID_NULL, "Expected to get a valid TAG_DATABASE\n");
+
+ exetag = pSdbFindFirstNamedTag(pdb, tagid, TAG_EXE, TAG_NAME, exename +
wcslen(workdir) + 1);
+
+ if (!exetag)
+ {
+ /* Test done */
+ return FALSE;
+ }
+
+ tagid = pSdbFindFirstTag(pdb, exetag, TAG_VENDOR);
+ Vendor = pSdbGetStringTagPtr(pdb, tagid);
+ Succeed = tagid != TAGID_NULL && Vendor && !wcsicmp(Vendor,
L"Succeed");
+
+ test_create_exe(exename, 0);
+
+ ret = pSdbGetMatchingExe(hsdb, exename, NULL, NULL, 0,
(SDBQUERYRESULT_VISTA*)&query);
+ DWORD exe_count = Succeed ? 1 : 0;
+
+ if (Succeed)
+ ok(ret, "SdbGetMatchingExe should not fail for %d.\n", cur);
+ else
+ ok(!ret, "SdbGetMatchingExe should not succeed for %d.\n", cur);
+
+ ok(query.dwExeCount == exe_count, "Expected dwExeCount to be %d, was %d for
%d\n", exe_count, query.dwExeCount, cur);
+ DeleteFileW(exename);
+ /* Try the next file */
+ return TRUE;
+}
+
+
+template<typename SDBQUERYRESULT_T>
+static void test_MatchApplicationsEx(void)
+{
+ WCHAR workdir[MAX_PATH], dbpath[MAX_PATH];
+ BOOL ret;
+ HSDB hsdb;
+
+ ret = GetTempPathW(_countof(workdir), workdir);
+ ok(ret, "GetTempPathW error: %d\n", GetLastError());
+ lstrcatW(workdir, L"apphelp_test");
+
+ ret = CreateDirectoryW(workdir, NULL);
+ ok(ret, "CreateDirectoryW error: %d\n", GetLastError());
+
+ /* SdbInitDatabase needs an nt-path */
+ swprintf(dbpath, L"\\??\\%s\\test.sdb", workdir);
+
+ if (extract_resource(dbpath + 4, MAKEINTRESOURCEW(101)))
+ {
+ hsdb = pSdbInitDatabase(HID_DATABASE_FULLPATH, dbpath);
+
+ ok(hsdb != NULL, "Expected a valid database handle\n");
+
+ if (!hsdb)
+ {
+ skip("SdbInitDatabase not implemented?\n");
+ }
+ else
+ {
+ size_t n;
+ /* now that our enviroment is setup, let's go ahead and run the actual
tests.. */
+ for (n = 0;; ++n)
+ {
+ if (!test_match_ex<SDBQUERYRESULT_T>(workdir, hsdb, n))
+ break;
+ }
+ pSdbReleaseDatabase(hsdb);
+ }
+ }
+ else
+ {
+ ok(0, "Unable to extract database\n");
+ }
+
+ DeleteFileW(dbpath + 4);
+
+ ret = RemoveDirectoryW(workdir);
+ ok(ret, "RemoveDirectoryW error: %d\n", GetLastError());
+}
+
+
+
+
static void test_TagRef(void)
{
WCHAR tmpdir[MAX_PATH], dbpath[MAX_PATH];
@@ -1660,9 +1801,11 @@
{
case 1:
test_MatchApplications<SDBQUERYRESULT_2k3>();
+ test_MatchApplicationsEx<SDBQUERYRESULT_2k3>();
break;
case 2:
test_MatchApplications<SDBQUERYRESULT_VISTA>();
+ test_MatchApplicationsEx<SDBQUERYRESULT_VISTA>();
break;
default:
skip("Skipping tests with SDBQUERYRESULT due to a wrong size
reported\n");
Added: trunk/rostests/apitests/apphelp/testdata.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/apphelp/testdata…
==============================================================================
--- trunk/rostests/apitests/apphelp/testdata.rc (added)
+++ trunk/rostests/apitests/apphelp/testdata.rc [iso-8859-1] Mon Jun 26 14:58:08 2017
@@ -0,0 +1,2 @@
+
+101 RCDATA "testdb.sdb"
Propchange: trunk/rostests/apitests/apphelp/testdata.rc
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/rostests/apitests/apphelp/testdb.xml
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/apphelp/testdb.x…
==============================================================================
--- trunk/rostests/apitests/apphelp/testdb.xml (added)
+++ trunk/rostests/apitests/apphelp/testdb.xml [iso-8859-1] Mon Jun 26 14:58:08 2017
@@ -0,0 +1,235 @@
+<SDB>
+ <DATABASE>
+ <NAME>ReactOS test database</NAME>
+ <OS_PLATFORM >1</OS_PLATFORM>
+ <DATABASE_ID>{551F8E78-A9DA-44AC-A24C-5A8145317BC7}</DATABASE_ID>
+ <LIBRARY>
+ </LIBRARY>
+
+ <!-- Verify that we are able to match this -->
+ <EXE>
+ <NAME>test_match0.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Succeed</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <!-- BIN_PRODUCT_VERSION? -->
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <!-- BIN_FILE_VERSION? -->
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- Verify that we are able to match this -->
+ <EXE>
+ <NAME>test_match1.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Succeed</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <!-- BIN_PRODUCT_VERSION? -->
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <!-- BIN_FILE_VERSION? -->
+ <FILE_DESCRIPTION>FILEDESCRIPTION</FILE_DESCRIPTION>
+ <COMPANY_NAME>companyname</COMPANY_NAME>
+ <ORIGINAL_FILENAME>ORIGINALFILENAME</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>internalname</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- SIZE wrong -->
+ <EXE>
+ <NAME>test_match2.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2047</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- CHECKSUM wrong -->
+ <EXE>
+ <NAME>test_match3.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x111111</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- PRODUCT_VERSION too high -->
+ <EXE>
+ <NAME>test_match4.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.1.1.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- PRODUCT_VERSION too low -->
+ <EXE>
+ <NAME>test_match5.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.0</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- FILE_VERSION wrong -->
+ <EXE>
+ <NAME>test_match6.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.1.1.1</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- FILE_DESCRIPTION wrong -->
+ <EXE>
+ <NAME>test_match7.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>Wrong Description</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- COMPANY_NAME wrong -->
+ <EXE>
+ <NAME>test_match8.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>Wrong CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- ORIGINAL_FILENAME wrong -->
+ <EXE>
+ <NAME>test_match9.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>Wrong
OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- INTERNAL_NAME wrong -->
+ <EXE>
+ <NAME>test_match10.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>wrong InternalName</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- Show that strings are checked for the full length(1) -->
+ <EXE>
+ <NAME>test_match11.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>InternalName wrong</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ <!-- Show that strings are checked for the full length(2) -->
+ <EXE>
+ <NAME>test_match12.exe</NAME>
+ <APP_NAME>Generic name</APP_NAME>
+ <VENDOR>Generic Description</VENDOR>
+ <MATCHING_FILE>
+ <NAME>*</NAME>
+ <SIZE>2048</SIZE>
+ <CHECKSUM>0x178BD629</CHECKSUM>
+ <PRODUCT_VERSION>1.0.0.1</PRODUCT_VERSION>
+ <FILE_VERSION>1.0.0.0</FILE_VERSION>
+ <FILE_DESCRIPTION>FileDescription</FILE_DESCRIPTION>
+ <COMPANY_NAME>CompanyName</COMPANY_NAME>
+ <ORIGINAL_FILENAME>OriginalFilename</ORIGINAL_FILENAME>
+ <INTERNAL_NAME>Internal</INTERNAL_NAME>
+ </MATCHING_FILE>
+ </EXE>
+ </DATABASE>
+</SDB>
Propchange: trunk/rostests/apitests/apphelp/testdb.xml
------------------------------------------------------------------------------
svn:eol-style = native