Commit b3f11ceb authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

msi/tests: Use the helpers from utils.h in more modules.

parent c1fb54ad
......@@ -32,6 +32,7 @@
#include <oaidl.h>
#include "wine/test.h"
#include "utils.h"
static BOOL is_wow64;
......@@ -42,7 +43,6 @@ DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
static const char *msifile = "winetest-automation.msi";
static FILETIME systemtime;
static CHAR CURR_DIR[MAX_PATH];
static EXCEPINFO excepinfo;
/*
......@@ -152,13 +152,6 @@ static const CHAR registry_dat[] = "Registry\tRoot\tKey\tName\tValue\tComponent_
"regdata\t1\tSOFTWARE\\Wine\\msitest\tblah\tbad\tdangler\n"
"OrderTest\t1\tSOFTWARE\\Wine\\msitest\tOrderTestName\tOrderTestValue\tcomponent\n";
typedef struct _msi_table
{
const CHAR *filename;
const CHAR *data;
int size;
} msi_table;
#define ADD_TABLE(x) {#x".idt", x##_dat, sizeof(x##_dat)}
static const msi_table tables[] =
......@@ -214,42 +207,6 @@ static void init_functionpointers(void)
#undef GET_PROC
}
static BOOL is_process_limited(void)
{
SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
PSID Group = NULL;
BOOL IsInGroup;
HANDLE token;
if (!AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &Group) ||
!CheckTokenMembership(NULL, Group, &IsInGroup))
{
trace("Could not check if the current user is an administrator\n");
FreeSid(Group);
return FALSE;
}
FreeSid(Group);
if (!IsInGroup)
{
/* Only administrators have enough privileges for these tests */
return TRUE;
}
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
{
BOOL ret;
TOKEN_ELEVATION_TYPE type = TokenElevationTypeDefault;
DWORD size;
ret = GetTokenInformation(token, TokenElevationType, &type, sizeof(type), &size);
CloseHandle(token);
return (ret && type == TokenElevationTypeLimited);
}
return FALSE;
}
static LONG delete_key_portable( HKEY key, LPCSTR subkey, REGSAM access )
{
if (pRegDeleteKeyExA)
......@@ -297,7 +254,7 @@ static void write_msi_summary_info(MSIHANDLE db, const msi_summary_info *info, i
MsiCloseHandle(summary);
}
static void create_database(const CHAR *name, const msi_table *tables, int num_tables,
static void create_database_suminfo(const CHAR *name, const msi_table *tables, int num_tables,
const msi_summary_info *info, int num_info)
{
MSIHANDLE db;
......@@ -339,7 +296,7 @@ static BOOL create_package(LPWSTR path)
DWORD len;
/* Prepare package */
create_database(msifile, tables, ARRAY_SIZE(tables), summary_info, ARRAY_SIZE(summary_info));
create_database_suminfo(msifile, tables, ARRAY_SIZE(tables), summary_info, ARRAY_SIZE(summary_info));
len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
CURR_DIR, -1, path, MAX_PATH);
......@@ -355,8 +312,6 @@ static BOOL create_package(LPWSTR path)
* Installation helpers
*/
static char PROG_FILES_DIR[MAX_PATH];
static BOOL get_program_files_dir(LPSTR buf)
{
HKEY hkey;
......@@ -374,24 +329,6 @@ static BOOL get_program_files_dir(LPSTR buf)
return TRUE;
}
static void create_file(const CHAR *name, DWORD size)
{
HANDLE file;
DWORD written, left;
file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
WriteFile(file, name, strlen(name), &written, NULL);
WriteFile(file, "\n", strlen("\n"), &written, NULL);
left = size - lstrlenA(name) - 1;
SetFilePointer(file, left, NULL, FILE_CURRENT);
SetEndOfFile(file);
CloseHandle(file);
}
static void create_test_files(void)
{
CreateDirectoryA("msitest", NULL);
......@@ -407,20 +344,6 @@ static void create_test_files(void)
create_file("msitest\\filename", 100);
}
static BOOL delete_pf(const CHAR *rel_path, BOOL is_file)
{
CHAR path[MAX_PATH];
lstrcpyA(path, PROG_FILES_DIR);
lstrcatA(path, "\\");
lstrcatA(path, rel_path);
if (is_file)
return DeleteFileA(path);
else
return RemoveDirectoryA(path);
}
static void delete_test_files(void)
{
DeleteFileA("msitest\\cabout\\new\\five.txt");
......
......@@ -29,6 +29,7 @@
#include <msiquery.h>
#include "wine/test.h"
#include "utils.h"
static const char *msifile = "winetest-db.msi";
static const char *msifile2 = "winetst2-db.msi";
......@@ -212,22 +213,6 @@ static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
return ret;
}
static UINT run_query( MSIHANDLE hdb, MSIHANDLE hrec, const char *query )
{
MSIHANDLE hview = 0;
UINT r;
r = MsiDatabaseOpenViewA(hdb, query, &hview);
if( r != ERROR_SUCCESS )
return r;
r = MsiViewExecute(hview, hrec);
if( r == ERROR_SUCCESS )
r = MsiViewClose(hview);
MsiCloseHandle(hview);
return r;
}
static UINT run_queryW( MSIHANDLE hdb, MSIHANDLE hrec, const WCHAR *query )
{
MSIHANDLE hview = 0;
......@@ -1502,29 +1487,6 @@ static void test_longstrings(void)
DeleteFileA(msifile);
}
static void create_file_data(LPCSTR name, LPCSTR data, DWORD size)
{
HANDLE file;
DWORD written;
file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
if (file == INVALID_HANDLE_VALUE)
return;
WriteFile(file, data, strlen(data), &written, NULL);
WriteFile(file, "\n", strlen("\n"), &written, NULL);
if (size)
{
SetFilePointer(file, size, NULL, FILE_BEGIN);
SetEndOfFile(file);
}
CloseHandle(file);
}
#define create_file(name) create_file_data(name, name, 0)
static void test_streamtable(void)
{
MSIHANDLE hdb = 0, rec, view, hsi;
......@@ -1607,7 +1569,7 @@ static void test_streamtable(void)
MsiCloseHandle( view );
/* insert a file into the _Streams table */
create_file( "test.txt" );
create_file( "test.txt", 0 );
rec = MsiCreateRecord( 2 );
MsiRecordSetStringA( rec, 1, "data" );
......@@ -1629,7 +1591,7 @@ static void test_streamtable(void)
MsiCloseHandle( view );
/* insert another one */
create_file( "test1.txt" );
create_file( "test1.txt", 0 );
rec = MsiCreateRecord( 2 );
MsiRecordSetStringA( rec, 1, "data1" );
......@@ -1651,7 +1613,7 @@ static void test_streamtable(void)
MsiCloseHandle( view );
/* try again */
create_file( "test1.txt" );
create_file( "test1.txt", 0 );
rec = MsiCreateRecord( 2 );
MsiRecordSetStringA( rec, 1, "data1" );
......@@ -1691,7 +1653,7 @@ static void test_streamtable(void)
memset(buf, 0, MAX_PATH);
r = MsiRecordReadStream( rec, 2, buf, &size );
ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
ok( !lstrcmpA(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
ok( !lstrcmpA(buf, "test.txt"), "Expected 'test.txt', got %s\n", buf);
MsiCloseHandle( rec );
MsiViewClose( view );
......@@ -1716,14 +1678,14 @@ static void test_streamtable(void)
memset(buf, 0, MAX_PATH);
r = MsiRecordReadStream( rec, 2, buf, &size );
ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
ok( !lstrcmpA(buf, "test1.txt\n"), "Expected 'test1.txt\\n', got %s\n", buf);
ok( !lstrcmpA(buf, "test1.txt"), "Expected 'test1.txt', got %s\n", buf);
MsiCloseHandle( rec );
MsiViewClose( view );
MsiCloseHandle( view );
/* perform an update */
create_file( "test2.txt" );
create_file( "test2.txt", 0 );
rec = MsiCreateRecord( 1 );
r = MsiRecordSetStreamA( rec, 1, "test2.txt" );
......@@ -1761,7 +1723,7 @@ static void test_streamtable(void)
memset(buf, 0, MAX_PATH);
r = MsiRecordReadStream( rec, 2, buf, &size );
ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
ok( !lstrcmpA(buf, "test2.txt\n"), "Expected 'test2.txt\\n', got %s\n", buf);
ok( !lstrcmpA(buf, "test2.txt"), "Expected 'test2.txt', got %s\n", buf);
MsiCloseHandle( rec );
MsiViewClose( view );
......@@ -1773,7 +1735,7 @@ static void test_streamtable(void)
r = MsiOpenDatabaseW(msifileW, MSIDBOPEN_CREATEDIRECT, &hdb);
ok(r == ERROR_SUCCESS, "Failed to create database\n");
ok( hdb, "failed to create db\n");
create_file( "test.txt" );
create_file( "test.txt", 0 );
rec = MsiCreateRecord( 2 );
MsiRecordSetStringA( rec, 1, "data" );
r = MsiRecordSetStreamA( rec, 2, "test.txt" );
......@@ -1809,7 +1771,7 @@ static void test_streamtable(void)
memset(buf, 0, MAX_PATH);
r = MsiRecordReadStream( rec, 2, buf, &size );
ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
ok( !lstrcmpA(buf, "test.txt\n"), "Expected 'test.txt\\n', got '%s' (%lu)\n", buf, size);
ok( !lstrcmpA(buf, "test.txt"), "Expected 'test.txt', got '%s' (%lu)\n", buf, size);
MsiCloseHandle( rec );
/* open a handle to the "data" stream (and keep it open during removal) */
......@@ -1865,7 +1827,7 @@ static void test_binary(void)
r = run_query( hdb, 0, query );
ok( r == ERROR_SUCCESS, "Cannot create Binary table: %d\n", r );
create_file( "test.txt" );
create_file( "test.txt", 0 );
rec = MsiCreateRecord( 1 );
r = MsiRecordSetStreamA( rec, 1, "test.txt" );
ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
......@@ -1892,7 +1854,7 @@ static void test_binary(void)
r = run_query( hdb, 0, query );
ok( r == ERROR_SUCCESS, "Cannot create Binary table: %d\n", r );
create_file( "test.txt" );
create_file( "test.txt", 0 );
rec = MsiCreateRecord( 1 );
r = MsiRecordSetStreamA( rec, 1, "test.txt" );
ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r );
......@@ -1932,7 +1894,7 @@ static void test_binary(void)
memset( buf, 0, MAX_PATH );
r = MsiRecordReadStream( rec, 2, buf, &size );
ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
ok( !lstrcmpA(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
ok( !lstrcmpA(buf, "test.txt"), "Expected 'test.txt', got %s\n", buf );
r = MsiCloseHandle( rec );
ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
......@@ -1951,7 +1913,7 @@ static void test_binary(void)
memset( buf, 0, MAX_PATH );
r = MsiRecordReadStream( rec, 3, buf, &size );
ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
ok( !lstrcmpA(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
ok( !lstrcmpA(buf, "test.txt"), "Expected 'test.txt', got %s\n", buf );
r = MsiCloseHandle( rec );
ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
......@@ -2178,8 +2140,6 @@ static void test_where(void)
DeleteFileA(msifile);
}
static CHAR CURR_DIR[MAX_PATH];
static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
"s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
"TestTable\tFirstPrimaryColumn\n"
......@@ -7992,7 +7952,7 @@ static void test_dbmerge(void)
r = run_query(href, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
create_file("binary.dat");
create_file("binary.dat", 0);
hrec = MsiCreateRecord(1);
MsiRecordSetStreamA(hrec, 1, "binary.dat");
......@@ -8017,8 +7977,7 @@ static void test_dbmerge(void)
ZeroMemory(buf, MAX_PATH);
r = MsiRecordReadStream(hrec, 2, buf, &size);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
ok(!lstrcmpA(buf, "binary.dat\n"),
"Expected \"binary.dat\\n\", got \"%s\"\n", buf);
ok(!lstrcmpA(buf, "binary.dat"), "Expected \"binary.dat\", got \"%s\"\n", buf);
MsiCloseHandle(hrec);
......
......@@ -30,6 +30,7 @@
#include <wtypes.h>
#include "wine/test.h"
#include "utils.h"
static UINT (WINAPI *pMsiApplyPatchA)( LPCSTR, LPCSTR, INSTALLTYPE, LPCSTR );
static UINT (WINAPI *pMsiGetPatchInfoExA)( LPCSTR, LPCSTR, LPCSTR, MSIINSTALLCONTEXT,
......@@ -42,10 +43,6 @@ static const char *mspfile = "winetest-patch.msp";
static const WCHAR msifileW[] = L"winetest-patch.msi";
static const WCHAR mspfileW[] = L"winetest-patch.msp";
static char CURR_DIR[MAX_PATH];
static char PROG_FILES_DIR[MAX_PATH];
static char COMMON_FILES_DIR[MAX_PATH];
/* msi database data */
static const char property_dat[] =
......@@ -136,8 +133,6 @@ struct msi_table
int size;
};
#define ADD_TABLE( x ) { #x".idt", x##_dat, sizeof(x##_dat) }
static const struct msi_table tables[] =
{
ADD_TABLE( directory ),
......@@ -167,23 +162,6 @@ static void init_function_pointers( void )
#undef GET_PROC
}
static BOOL is_process_limited(void)
{
HANDLE token;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
{
BOOL ret;
TOKEN_ELEVATION_TYPE type = TokenElevationTypeDefault;
DWORD size;
ret = GetTokenInformation(token, TokenElevationType, &type, sizeof(type), &size);
CloseHandle(token);
return (ret && type == TokenElevationTypeLimited);
}
return FALSE;
}
static BOOL get_program_files_dir( char *buf, char *buf2 )
{
HKEY hkey;
......@@ -209,40 +187,6 @@ static BOOL get_program_files_dir( char *buf, char *buf2 )
return TRUE;
}
static void create_file_data( const char *filename, const char *data, DWORD size )
{
HANDLE file;
DWORD written;
file = CreateFileA( filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL );
if (file == INVALID_HANDLE_VALUE)
return;
WriteFile( file, data, strlen( data ), &written, NULL );
if (size)
{
SetFilePointer( file, size, NULL, FILE_BEGIN );
SetEndOfFile( file );
}
CloseHandle( file );
}
#define create_file( name, size ) create_file_data( name, name, size )
static BOOL delete_pf( const char *rel_path, BOOL is_file )
{
char path[MAX_PATH];
strcpy( path, PROG_FILES_DIR );
strcat( path, "\\" );
strcat( path, rel_path );
if (is_file)
return DeleteFileA( path );
else
return RemoveDirectoryA( path );
}
static DWORD get_pf_file_size( const char *filename )
{
char path[MAX_PATH];
......@@ -313,7 +257,7 @@ static void set_suminfo( const WCHAR *filename )
ok( r == ERROR_SUCCESS, "failed to close database %u\n", r );
}
static void create_database( const char *filename, const struct msi_table *tables, UINT num_tables )
static void create_database_suminfo( const char *filename, const struct msi_table *tables, UINT num_tables )
{
MSIHANDLE hdb;
UINT r, i;
......@@ -761,7 +705,7 @@ static void test_simple_patch( void )
CreateDirectoryA( "msitest", NULL );
create_file( "msitest\\patch.txt", 1000 );
create_database( msifile, tables, ARRAY_SIZE(tables) );
create_database_suminfo( msifile, tables, ARRAY_SIZE(tables) );
create_patch( mspfile );
MsiSetInternalUI( INSTALLUILEVEL_NONE, NULL );
......@@ -962,7 +906,7 @@ static void test_MsiOpenDatabase( void )
MsiCloseHandle( hdb );
DeleteFileA( mspfile );
create_database( msifile, tables, ARRAY_SIZE(tables) );
create_database_suminfo( msifile, tables, ARRAY_SIZE(tables) );
create_patch( mspfile );
r = MsiOpenDatabaseW( msifileW, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &hdb );
......@@ -1100,7 +1044,7 @@ static void test_system_tables( void )
CreateDirectoryA( "msitest", NULL );
create_file( "msitest\\patch.txt", 1000 );
create_database( msifile, tables, ARRAY_SIZE(tables) );
create_database_suminfo( msifile, tables, ARRAY_SIZE(tables) );
create_patch( mspfile );
MsiSetInternalUI( INSTALLUILEVEL_NONE, NULL );
......@@ -1290,7 +1234,7 @@ static void test_patch_registration( void )
CreateDirectoryA( "msitest", NULL );
create_file( "msitest\\patch.txt", 1000 );
create_database( msifile, tables, ARRAY_SIZE(tables) );
create_database_suminfo( msifile, tables, ARRAY_SIZE(tables) );
create_patch( mspfile );
MsiSetInternalUI( INSTALLUILEVEL_NONE, NULL );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment