static void translateinfstringex_test(void) { HINF hinf; HRESULT hr; char buffer[MAX_PATH]; DWORD size = MAX_PATH; create_inf_file(); /* need to see if there are any flags */ /* try a NULL filename */ hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try an empty filename */ hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr); /* try a NULL hinf */ hr = pOpenINFEngine("c:\\test.inf", "Options.NTx86", 0, NULL, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* open the INF without the Install section specified */ hr = pOpenINFEngine("c:\\test.inf", NULL, 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); /* try a NULL hinf */ hr = pTranslateInfStringEx(NULL, "c:\\test.inf", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try a NULL filename */ hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try an empty filename */ size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", (UINT)hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %ld\n", size); } /* try a NULL translate section */ hr = pTranslateInfStringEx(hinf, "c:\\test.inf", NULL, "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try an empty translate section */ hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "", "InstallDir", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %ld\n", hr); /* try a NULL translate key */ hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", NULL, buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* try an empty translate key */ hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %ld\n", hr); /* successfully translate the string */ size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %ld\n", size); } /* try a NULL hinf */ hr = pCloseINFEngine(NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr); /* successfully close the hinf */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); /* open the inf with the install section */ hr = pOpenINFEngine("c:\\test.inf", "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); /* translate the string with the install section specified */ size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); ok(!strcmp(buffer, PROG_FILES), "Expected %s, got %s\n", PROG_FILES, buffer); ok(size == PROG_FILES_LEN, "Expected size %ld, got %ld\n", PROG_FILES_LEN, size); /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %ld\n", hr); DeleteFileA("c:\\test.inf"); }
static void translateinfstringex_test(void) { HINF hinf; HRESULT hr; char buffer[MAX_PATH]; DWORD size = MAX_PATH; hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL); if (hr == E_UNEXPECTED) { win_skip("Skipping tests on win9x because of brokenness\n"); return; } create_inf_file(); /* need to see if there are any flags */ /* try a NULL filename */ hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty filename */ hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* NT+ */ || hr == HRESULT_FROM_WIN32(E_UNEXPECTED) /* 9x */, "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND or E_UNEXPECTED), got %08x\n", hr); /* try a NULL hinf */ hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* open the INF without the Install section specified */ hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* try a NULL hinf */ hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try a NULL filename */ hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty filename */ memset(buffer, 'a', 25); buffer[24] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %d\n", size); } /* try a NULL translate section */ hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty translate section */ hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr); /* try a NULL translate key */ hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL, buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty translate key */ hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr); /* successfully translate the string */ memset(buffer, 'a', 25); buffer[24] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %d\n", size); } /* try a NULL hinf */ hr = pCloseINFEngine(NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* successfully close the hinf */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* open the inf with the install section */ hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* translate the string with the install section specified */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer); ok(size == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, size); /* Single quote test (Note size includes null on return from call) */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); { char drive[MAX_PATH]; lstrcpyA(drive, PROG_FILES_ROOT); drive[3] = 0x00; /* Just keep the system drive plus '\' */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, drive), "Expected %s, got %s\n", drive, buffer); ok(size == strlen(drive)+1, "Expected size %d, got %d\n", lstrlenA(drive)+1, size); } /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); DeleteFileA(inf_file); /* Create another .inf file which is just here to trigger a wine bug */ { char data[1024]; char *ptr = data; DWORD dwNumberOfBytesWritten; HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); append_str(&ptr, "[Version]\n"); append_str(&ptr, "Signature=\"$Chicago$\"\n"); append_str(&ptr, "[section]\n"); append_str(&ptr, "NotACustomDestination=Version\n"); append_str(&ptr, "CustomDestination=CustInstDestSection\n"); append_str(&ptr, "[CustInstDestSection]\n"); append_str(&ptr, "49010=DestA,1\n"); append_str(&ptr, "49020=DestB\n"); append_str(&ptr, "49030=DestC\n"); append_str(&ptr, "49040=DestD\n"); append_str(&ptr, "[Options.NTx86]\n"); append_str(&ptr, "Result2=%%49030%%\n"); append_str(&ptr, "[DestA]\n"); append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); /* The point of this test is to have HKCU just before the quoted HKLM */ append_str(&ptr, "[DestB]\n"); append_str(&ptr, "HKCU,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); append_str(&ptr, "[DestC]\n"); append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',"); append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n"); append_str(&ptr, "[DestD]\n"); append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL); CloseHandle(hf); } /* open the inf with the install section */ hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* Single quote test (Note size includes null on return from call) */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); DeleteFileA(inf_file); }