[MSI 2/4] more MsiSetTargetPath tests

Andrey Turkin pancha at mail.nnov.ru
Mon Jun 19 11:35:15 CDT 2006


hmm... $subj :) Proof of MsiSetTargetPath bugs

ChangeLog:
more MsiSetTargetPath tests added
-------------- next part --------------
--- wine-0.9.15-orig/dlls/msi/tests/package.c	2006-06-19 19:45:19.000000000 +0400
+++ wine-0.9.15/dlls/msi/tests/package.c	2006-06-19 20:02:33.000000000 +0400
@@ -326,14 +326,132 @@
     MsiCloseHandle( hpkg );
 }
 
-static void test_settargetpath_bad(void)
+static UINT get_file_targetpath(MSIHANDLE hpkg, const char *file, char *buffer, DWORD size)
 {
+    UINT r;
+    MSIHANDLE rec;
+
+    buffer[0] = 0;
+
+    rec = MsiCreateRecord(1);
+    ok( rec, "cannot create record\n");
+
+    r = MsiRecordSetString( rec, 0, file );
+    if (r)
+    {
+        MsiCloseHandle( rec );
+        return r;
+    }
+
+    r = MsiFormatRecord( hpkg, rec, buffer, &size );
+    if ( r == S_OK )
+    {
+        char *t = strrchr( buffer, '\\' );
+        if ( t )
+            t[1] = 0;
+    }
+    MsiCloseHandle( rec );
+    return r;
+}
+
+static const char *szCreateComponent = "CREATE TABLE `Component` ( "
+            "`Component` CHAR(72) NOT NULL, "
+            "`ComponentId` CHAR(38), "
+            "`Directory_` CHAR(72) NOT NULL, "
+            "`Attributes` SHORT NOT NULL, "
+            "`Condition` CHAR(255), "
+            "`KeyPath` CHAR(72) "
+            "PRIMARY KEY `Component`)";
+static const char *szCreateFeature = "CREATE TABLE `Feature` ( "
+            "`Feature` CHAR(38) NOT NULL, "
+            "`Feature_Parent` CHAR(38), "
+            "`Title` CHAR(64), "
+            "`Description` CHAR(255), "
+            "`Display` SHORT NOT NULL, "
+            "`Level` SHORT NOT NULL, "
+            "`Directory_` CHAR(72), "
+            "`Attributes` SHORT NOT NULL "
+            "PRIMARY KEY `Feature`)" ;
+static const char *szCreateFile = "CREATE TABLE `File` ( "
+            "`File` CHAR(72) NOT NULL, "
+            "`Component_` CHAR(72) NOT NULL, "
+            "`FileName` CHAR(255) NOT NULL, "
+            "`FileSize` LONG NOT NULL, "
+            "`Version` CHAR(72), "
+            "`Language` CHAR(20), "
+            "`Attributes` SHORT, "
+            "`Sequence` SHORT NOT NULL "
+            "PRIMARY KEY `File`)" ;
+static const char *szCreateMedia = "CREATE TABLE `Media` ( "
+            "`DiskId` SHORT NOT NULL, "
+            "`LastSequence` SHORT NOT NULL, "
+            "`DiskPrompt` CHAR(64), "
+            "`Cabinet` CHAR(255), "
+            "`VolumeLabel` CHAR(32), "
+            "`Source` CHAR(72) "
+            "PRIMARY KEY `DiskId`)" ;
+
+static void test_settargetpath(void)
+{
+    char tempdir[MAX_PATH+8], buffer[MAX_PATH], filebuffer[MAX_PATH];
+    DWORD sz;
     MSIHANDLE hpkg;
     UINT r;
+    MSIHANDLE hdb;
+    
+    hdb = create_package_db();
+    ok ( hdb, "failed to create package database\n" );
+
+    r = add_directory_entry( hdb, "'TARGETDIR', '', 'SourceDir'" );
+    ok( r == S_OK, "failed to add directory entry: %d\n" , r );
+
+    r = run_query( hdb, szCreateComponent ); /* these tables required by Windows Installer */
+    ok( r == S_OK, "cannot create Component table: %d\n", r );
+    r = run_query( hdb,
+            "INSERT INTO `Component`  "
+            "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `Condition`, `KeyPath`) "
+            "VALUES( 'WinWorkAround', '', 'TARGETDIR', 0, '', 'FL_TestFile')" );
+    ok( r == S_OK, "cannot add dummy component: %d\n", r );
+
+    r = run_query( hdb, szCreateFeature );
+    ok( r == S_OK, "cannot create Feature table: %d\n", r );
+    r = run_query( hdb, "INSERT INTO `Feature` "
+            "(`Feature`, `Feature_Parent`, `Display`, `Level`, `Attributes`) "
+            "VALUES( 'TestFeature', '', 0, 1, 0 )" );
+    ok( r == S_OK, "cannot add feature: %d\n", r );
+
+    r = run_query( hdb, "CREATE TABLE `FeatureComponents` (`Feature_` CHAR(38) NOT NULL, `Component_` CHAR(72) NOT NULL PRIMARY KEY `Feature_` )" );
+    ok( r == S_OK, "cannot create FeatureComponents table: %d\n", r );
+    r = run_query( hdb, "INSERT INTO `FeatureComponents` "
+            "(`Feature_`, `Component_`) VALUES( 'TestFeature', 'WinWorkAround' )" );
+    ok( r == S_OK, "cannot insert component into feature: %d\n", r );
+ 
+    r = run_query( hdb, szCreateFile );
+    ok( r == S_OK, "cannot create File table: %d\n", r );
+    r = run_query( hdb, "INSERT INTO `File` "
+            "(`File`, `Component_`, `FileName`, `FileSize`, `Version`, `Language`, `Attributes`, `Sequence`) "
+            "VALUES( 'FL_TestFile', 'WinWorkAround', 'winetest.fil', 128, '', '1033', 8, 1 )" );
+    ok( r == S_OK, "cannot add file: %d\n", r );
+
+    r = run_query( hdb, szCreateMedia );
+    ok( r == S_OK, "cannot create Media table: %d\n", r );
+    r = run_query( hdb, "INSERT INTO `Media` "
+            "(`DiskId`, `LastSequence`) "
+            "VALUES( 1, 1)" );
+    ok( r == S_OK, "cannot add media: %d\n", r );
 
-    hpkg = package_from_db(create_package_db());
+    hpkg = package_from_db( hdb );
     ok( hpkg, "failed to create package\n");
 
+    r = MsiDoAction( hpkg, "CostInitialize");
+    ok( r == ERROR_SUCCESS, "cost init failed\n" );
+
+    r = MsiDoAction( hpkg, "FileCost");
+    ok( r == ERROR_SUCCESS, "file cost failed\n" );
+
+    r = MsiDoAction( hpkg, "CostFinalize");
+    ok( r == ERROR_SUCCESS, "cost finalize failed\n" );
+
     r = MsiSetTargetPath( 0, NULL, NULL );
     ok( r == ERROR_INVALID_PARAMETER, "wrong return val\n");
 
@@ -346,6 +464,57 @@
     r = MsiSetTargetPath( hpkg, "boo", "c:\\bogusx" );
     ok( r == ERROR_DIRECTORY, "wrong return val\n");
 
+    sz = sizeof tempdir - 1;
+    r = MsiGetTargetPath( hpkg, "TARGETDIR", tempdir, &sz );
+    ok( r == S_OK, "get_file_targetpath failed: %d\n", r );
+
+    r = get_file_targetpath(hpkg, "[#FL_TestFile]", filebuffer, sizeof filebuffer-1 );
+    ok( r == S_OK, "get_file_targetpath failed: %d\n", r );
+
+    ok( strcmp(filebuffer, tempdir) == 0, "directories differ: dir path: '%s', file path: '%s'\n", tempdir, filebuffer );
+
+    if ( GetTempFileName( tempdir, "_wt", 0, buffer ) && buffer[0] )
+    {
+        char *bufend = buffer + strlen( buffer ) - 1;
+        if ( bufend[0] != '\\' )
+        {
+            bufend[1] = '\\';
+            bufend[2] = '\0';
+        }
+
+        sprintf( tempdir, "%ssubdir\\", buffer );
+        r = MsiSetTargetPath( hpkg, "TARGETDIR", buffer );
+        todo_wine {
+        ok( r == ERROR_SUCCESS, "MsiSetTargetPath on file returned %d\n", r );
+        }
+        r = MsiSetTargetPath( hpkg, "TARGETDIR", tempdir );
+        todo_wine {
+        ok( r == ERROR_SUCCESS, "MsiSetTargetPath on 'subdir' of file returned %d\n", r );
+        }
+
+        DeleteFile( buffer );
+
+        r = MsiSetTargetPath( hpkg, "TARGETDIR", buffer );
+        ok( r == ERROR_SUCCESS, "MsiSetTargetPath returned %d\n", r );
+
+        r = get_file_targetpath(hpkg, "[#FL_TestFile]", filebuffer, sizeof filebuffer-1 );
+        ok( r == S_OK, "get_file_targetpath failed\n" );
+
+        todo_wine {
+        ok( strcmp(filebuffer, buffer) == 0, "directories differ: dir path: '%s', file path: '%s'\n", buffer, filebuffer );
+        }
+
+        r = GetFileAttributes( buffer );
+        ok ( r == 0xFFFFFFFF, "file/directory exists after MsiSetTargetPath. Attributes: %08X\n", r );
+
+        r = MsiSetTargetPath( hpkg, "TARGETDIR", tempdir );
+        todo_wine {
+        ok( r == ERROR_SUCCESS, "MsiSetTargetPath on subsubdir returned %d\n", r );
+        }
+    } else {
+        trace("GetTempFileName failed, cannot do some tests\n");
+    }
+
     MsiCloseHandle( hpkg );
 }
 
@@ -844,7 +1013,7 @@
     test_getsourcepath();
     test_doaction();
     test_gettargetpath_bad();
-    test_settargetpath_bad();
+    test_settargetpath();
     test_props();
     test_condition();
 }


More information about the wine-patches mailing list