From: Mark Jansen Date: Mon, 26 Jun 2017 14:58:08 +0000 (+0000) Subject: [APPHELP_APITEST] Add tests for SdbGetMatchingExe, to test matching on version resour... X-Git-Tag: ReactOS-0.4.6~170 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=54d38174b1807c0907bd9de7377fb5c73b352539;hp=a04fdc1e997a967ec95d05e338a606df01df48d8 [APPHELP_APITEST] Add tests for SdbGetMatchingExe, to test matching on version resources. CORE-13284 svn path=/trunk/; revision=75205 --- diff --git a/rostests/apitests/apphelp/CMakeLists.txt b/rostests/apitests/apphelp/CMakeLists.txt index 454723f3440..ec218d2230e 100644 --- a/rostests/apitests/apphelp/CMakeLists.txt +++ b/rostests/apitests/apphelp/CMakeLists.txt @@ -1,14 +1,24 @@ project(appcompat) add_definitions(-D__ROS_LONG64__ -DWINETEST_USE_DBGSTR_LONGLONG) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + list(APPEND SOURCE apphelp.c data.c 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}) diff --git a/rostests/apitests/apphelp/db.cpp b/rostests/apitests/apphelp/db.cpp index ad3f053a6d1..8fb1bc6b6e7 100644 --- a/rostests/apitests/apphelp/db.cpp +++ b/rostests/apitests/apphelp/db.cpp @@ -1332,6 +1332,147 @@ static void test_MatchApplications(void) 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 +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 +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(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 @@ START_TEST(db) { case 1: test_MatchApplications(); + test_MatchApplicationsEx(); break; case 2: test_MatchApplications(); + test_MatchApplicationsEx(); break; default: skip("Skipping tests with SDBQUERYRESULT due to a wrong size reported\n"); diff --git a/rostests/apitests/apphelp/testdata.rc b/rostests/apitests/apphelp/testdata.rc new file mode 100644 index 00000000000..2c973f047ee --- /dev/null +++ b/rostests/apitests/apphelp/testdata.rc @@ -0,0 +1,2 @@ + +101 RCDATA "testdb.sdb" diff --git a/rostests/apitests/apphelp/testdb.xml b/rostests/apitests/apphelp/testdb.xml new file mode 100644 index 00000000000..9158d328473 --- /dev/null +++ b/rostests/apitests/apphelp/testdb.xml @@ -0,0 +1,235 @@ + + + ReactOS test database + 1 + {551F8E78-A9DA-44AC-A24C-5A8145317BC7} + + + + + + test_match0.exe + Generic name + Succeed + + * + 2048 + 0x178BD629 + 1.0.0.1 + + 1.0.0.0 + + FileDescription + CompanyName + OriginalFilename + InternalName + + + + + test_match1.exe + Generic name + Succeed + + * + 2048 + 0x178BD629 + 1.0.0.1 + + 1.0.0.0 + + FILEDESCRIPTION + companyname + ORIGINALFILENAME + internalname + + + + + test_match2.exe + Generic name + Generic Description + + * + 2047 + 0x178BD629 + 1.0.0.1 + 1.0.0.0 + FileDescription + CompanyName + OriginalFilename + InternalName + + + + + test_match3.exe + Generic name + Generic Description + + * + 2048 + 0x111111 + 1.0.0.1 + 1.0.0.0 + FileDescription + CompanyName + OriginalFilename + InternalName + + + + + test_match4.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.1.1.1 + 1.0.0.0 + FileDescription + CompanyName + OriginalFilename + InternalName + + + + + test_match5.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.0.0.0 + 1.0.0.0 + FileDescription + CompanyName + OriginalFilename + InternalName + + + + + test_match6.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.0.0.1 + 1.1.1.1 + FileDescription + CompanyName + OriginalFilename + InternalName + + + + + test_match7.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.0.0.1 + 1.0.0.0 + Wrong Description + CompanyName + OriginalFilename + InternalName + + + + + test_match8.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.0.0.1 + 1.0.0.0 + FileDescription + Wrong CompanyName + OriginalFilename + InternalName + + + + + test_match9.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.0.0.1 + 1.0.0.0 + FileDescription + CompanyName + Wrong OriginalFilename + InternalName + + + + + test_match10.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.0.0.1 + 1.0.0.0 + FileDescription + CompanyName + OriginalFilename + wrong InternalName + + + + + test_match11.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.0.0.1 + 1.0.0.0 + FileDescription + CompanyName + OriginalFilename + InternalName wrong + + + + + test_match12.exe + Generic name + Generic Description + + * + 2048 + 0x178BD629 + 1.0.0.1 + 1.0.0.0 + FileDescription + CompanyName + OriginalFilename + Internal + + + +