From a248cc8f6284754c4b1abbe35ba42465437eb0b0 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Tue, 5 Sep 2006 20:26:56 -0700 Subject: [PATCH] msi: Fix creation of the default format in MsiFormatRecord. --- dlls/msi/format.c | 48 ++++++++++++++++++++++++++----- dlls/msi/tests/format.c | 63 +++++++++++++++++++---------------------- 2 files changed, 70 insertions(+), 41 deletions(-) diff --git a/dlls/msi/format.c b/dlls/msi/format.c index b0d9d5219a5..6dc92f90995 100644 --- a/dlls/msi/format.c +++ b/dlls/msi/format.c @@ -50,19 +50,53 @@ static LPWSTR build_default_format(MSIRECORD* record) { int i; int count; - LPWSTR rc; - static const WCHAR fmt[] = {'%','i',':',' ','[','%','i',']',' ',0}; - WCHAR buf[11]; + LPWSTR rc, buf; + static const WCHAR fmt[] = {'%','i',':',' ','%','s',' ',0}; + static const WCHAR fmt_null[] = {'%','i',':',' ',' ',0}; + static const WCHAR fmt_index[] = {'%','i',0}; + LPCWSTR str; + WCHAR index[10]; + DWORD size, max_len, len; count = MSI_RecordGetFieldCount(record); - rc = msi_alloc((11*count)*sizeof(WCHAR)); - rc[0] = 0; + max_len = MAX_PATH; + buf = msi_alloc((max_len + 1) * sizeof(WCHAR)); + + rc = NULL; + size = 1; for (i = 1; i <= count; i++) { - sprintfW(buf,fmt,i,i); - strcatW(rc,buf); + sprintfW(index,fmt_index,i); + str = MSI_RecordGetString(record, i); + len = (str) ? lstrlenW(str) : 0; + len += (sizeof(fmt_null) - 3) + lstrlenW(index); + size += len; + + if (len > max_len) + { + max_len = len; + buf = msi_realloc(buf, (max_len + 1) * sizeof(WCHAR)); + if (!buf) return NULL; + } + + if (str) + sprintfW(buf,fmt,i,str); + else + sprintfW(buf,fmt_null,i); + + if (!rc) + { + rc = msi_alloc(size * sizeof(WCHAR)); + lstrcpyW(rc, buf); + } + else + { + rc = msi_realloc(rc, size * sizeof(WCHAR)); + lstrcatW(rc, buf); + } } + msi_free(buf); return rc; } diff --git a/dlls/msi/tests/format.c b/dlls/msi/tests/format.c index c619c102299..c9f9bc35b7c 100644 --- a/dlls/msi/tests/format.c +++ b/dlls/msi/tests/format.c @@ -1501,6 +1501,24 @@ static void test_formatrecord_package(void) ok( sz == 51, "size wrong (%li)\n",sz); ok( 0 == strcmp(buffer,"1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: "), "wrong output(%s)\n",buffer); + r = MsiSetProperty(package, "prop", "val"); + ok( r == ERROR_SUCCESS, "failed to set propertY: %d\n", r); + + r = MsiRecordSetString(hrec, 0, NULL); + r = MsiRecordSetString(hrec, 1, "[2]"); + r = MsiRecordSetString(hrec, 2, "stuff"); + r = MsiRecordSetString(hrec, 3, "prop"); + r = MsiRecordSetString(hrec, 4, "[prop]"); + r = MsiRecordSetString(hrec, 5, "[noprop]"); + sz = sizeof buffer; + r = MsiFormatRecord(package, hrec, buffer, &sz); + ok( r == ERROR_SUCCESS, "format failed with empty buffer (%i)\n",r); + todo_wine + { + ok( sz == 66, "size wrong (%li)\n",sz); + ok( 0 == strcmp(buffer,"1: [2] 2: stuff 3: prop 4: val 5: 6: 7: 8: 9: 10: 11: 12: "), "wrong output(%s)\n",buffer); + } + /* now put play games with escaping */ r = MsiRecordSetString(hrec, 0, "[1] [2] [\\3asdf]"); r = MsiRecordSetString(hrec, 1, "boo"); @@ -1715,33 +1733,25 @@ static void test_formatrecord_tables(void) /* property doesn't exist */ size = MAX_PATH; + /*MsiRecordSetString( hrec, 0, "[1]" ); */ MsiRecordSetString( hrec, 1, "[idontexist]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); - todo_wine - { - ok( !lstrcmp( buf, "1: " ), "Expected '1: ', got %s\n", buf ); - } + ok( !lstrcmp( buf, "1: " ), "Expected '1: ', got %s\n", buf ); /* property exists */ size = MAX_PATH; MsiRecordSetString( hrec, 1, "[imaprop]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); - todo_wine - { - ok( !lstrcmp( buf, "1: ringer " ), "Expected '1: ringer ', got %s\n", buf ); - } + ok( !lstrcmp( buf, "1: ringer " ), "Expected '1: ringer ', got %s\n", buf ); /* environment variable doesn't exist */ size = MAX_PATH; MsiRecordSetString( hrec, 1, "[%idontexist]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); - todo_wine - { - ok( !lstrcmp( buf, "1: " ), "Expected '1: ', got %s\n", buf ); - } + ok( !lstrcmp( buf, "1: " ), "Expected '1: ', got %s\n", buf ); /* environment variable exists */ size = MAX_PATH; @@ -1749,20 +1759,14 @@ static void test_formatrecord_tables(void) MsiRecordSetString( hrec, 1, "[%crazyvar]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); - todo_wine - { - ok( !lstrcmp( buf, "1: crazyval " ), "Expected '1: crazyval ', got %s\n", buf ); - } + ok( !lstrcmp( buf, "1: crazyval " ), "Expected '1: crazyval ', got %s\n", buf ); /* file key before CostInitialize */ size = MAX_PATH; MsiRecordSetString( hrec, 1, "[#frontal_file]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); - todo_wine - { - ok( !lstrcmp( buf, "1: " ), "Expected '1: ', got %s\n", buf ); - } + ok( !lstrcmp( buf, "1: " ), "Expected '1: ', got %s\n", buf ); r = MsiDoAction(hpkg, "CostInitialize"); ok( r == ERROR_SUCCESS, "CostInitialize failed: %d\n", r); @@ -1778,31 +1782,22 @@ static void test_formatrecord_tables(void) MsiRecordSetString( hrec, 1, "[#frontal_file]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); - todo_wine - { - ok( !lstrcmp( buf, "1: C:\\frontal.txt " ), "Expected '1: C:\\frontal.txt ', got %s\n", buf); - } + ok( !lstrcmp( buf, "1: C:\\frontal.txt " ), "Expected '1: C:\\frontal.txt ', got %s\n", buf); /* frontal short file key */ size = MAX_PATH; MsiRecordSetString( hrec, 1, "[!frontal_file]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); - todo_wine - { - ok( !lstrcmp( buf, "1: C:\\frontal.txt " ), "Expected '1: C:\\frontal.txt ', got %s\n", buf); - } + ok( !lstrcmp( buf, "1: C:\\frontal.txt " ), "Expected '1: C:\\frontal.txt ', got %s\n", buf); /* temporal full file key */ size = MAX_PATH; MsiRecordSetString( hrec, 1, "[#temporal_file]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); - todo_wine - { - ok( !lstrcmp( buf, "1: C:\\I am a really long directory\\temporal.txt " ), - "Expected '1: C:\\I am a really long directory\\temporal.txt ', got %s\n", buf); - } + ok( !lstrcmp( buf, "1: C:\\I am a really long directory\\temporal.txt " ), + "Expected '1: C:\\I am a really long directory\\temporal.txt ', got %s\n", buf); /* temporal short file key */ size = MAX_PATH; @@ -1846,7 +1841,7 @@ static void test_formatrecord_tables(void) /* component with INSTALLSTATE_LOCAL */ size = MAX_PATH; - MsiRecordSetString( hrec, 1, "[$temporal]" ); + MsiRecordSetString( hrec, 0, "[$temporal]" ); r = MsiFormatRecord( hpkg, hrec, buf, &size ); ok( r == ERROR_SUCCESS, "format record failed: %d\n", r); todo_wine