James Hawkins : msi: Handle carriage returns in MsiDatabaseImport.

Alexandre Julliard julliard at winehq.org
Tue Feb 12 16:46:15 CST 2008


Module: wine
Branch: master
Commit: ec086f77e3261dacb501b0f03265cd68cbaaa44e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=ec086f77e3261dacb501b0f03265cd68cbaaa44e

Author: James Hawkins <truiken at gmail.com>
Date:   Tue Feb 12 01:37:56 2008 -0600

msi: Handle carriage returns in MsiDatabaseImport.

---

 dlls/msi/database.c         |   22 +++++++--
 dlls/msi/tests/automation.c |    1 +
 dlls/msi/tests/db.c         |   98 ++++++++++++++++---------------------------
 3 files changed, 54 insertions(+), 67 deletions(-)

diff --git a/dlls/msi/database.c b/dlls/msi/database.c
index a7dc285..425486e 100644
--- a/dlls/msi/database.c
+++ b/dlls/msi/database.c
@@ -317,12 +317,18 @@ static void msi_parse_line(LPWSTR *line, LPWSTR **entries, DWORD *num_entries)
     /* store pointers into the data */
     for (i = 0, ptr = *line; i < count; i++)
     {
+        while (*ptr && *ptr == '\r') ptr++;
         save = ptr;
 
-        while (*ptr && *ptr != '\t' && *ptr != '\n') ptr++;
+        while (*ptr && *ptr != '\t' && *ptr != '\n' && *ptr != '\r') ptr++;
 
         /* NULL-separate the data */
-        if (*ptr)
+        if (*ptr == '\n' || *ptr == '\r')
+        {
+            while (*ptr == '\n' || *ptr == '\r')
+                *(ptr++) = '\0';
+        }
+        else if (*ptr)
             *ptr++ = '\0';
 
         (*entries)[i] = save;
@@ -598,11 +604,11 @@ UINT MSI_DatabaseImport(MSIDATABASE *db, LPCWSTR folder, LPCWSTR file)
 {
     UINT r;
     DWORD len, i;
-    DWORD num_labels;
+    DWORD num_labels, num_types;
     DWORD num_columns, num_records = 0;
     LPWSTR *columns, *types, *labels;
     LPWSTR path, ptr, data;
-    LPWSTR **records;
+    LPWSTR **records = NULL;
     LPWSTR **temp_records;
 
     static const WCHAR backslash[] = {'\\',0};
@@ -625,9 +631,15 @@ UINT MSI_DatabaseImport(MSIDATABASE *db, LPCWSTR folder, LPCWSTR file)
 
     ptr = data;
     msi_parse_line( &ptr, &columns, &num_columns );
-    msi_parse_line( &ptr, &types, NULL );
+    msi_parse_line( &ptr, &types, &num_types );
     msi_parse_line( &ptr, &labels, &num_labels );
 
+    if (num_columns != num_types)
+    {
+        r = ERROR_FUNCTION_FAILED;
+        goto done;
+    }
+
     records = msi_alloc(sizeof(LPWSTR *));
     if (!records)
     {
diff --git a/dlls/msi/tests/automation.c b/dlls/msi/tests/automation.c
index 3ae4a7b..8cf764e 100644
--- a/dlls/msi/tests/automation.c
+++ b/dlls/msi/tests/automation.c
@@ -272,6 +272,7 @@ static void create_database(const CHAR *name, const msi_table *tables, int num_t
 
         write_file(table->filename, table->data, (table->size - 1) * sizeof(char));
 
+        printf("table->filename: %s\n", table->filename);
         r = MsiDatabaseImportA(db, CURR_DIR, table->filename);
         ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
 
diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c
index 684379e..fa3b55b 100644
--- a/dlls/msi/tests/db.c
+++ b/dlls/msi/tests/db.c
@@ -1643,10 +1643,7 @@ static void test_msiimport(void)
     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
     r = add_table_to_db(hdb, endlines1);
-    todo_wine
-    {
-        ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
-    }
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
     r = add_table_to_db(hdb, endlines2);
     ok(r == ERROR_FUNCTION_FAILED,
@@ -1749,7 +1746,8 @@ static void test_msiimport(void)
     MsiCloseHandle(rec);
 
     r = MsiViewFetch(view, &rec);
-    ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
+    ok(r == ERROR_NO_MORE_ITEMS,
+       "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
 
     r = MsiViewClose(view);
     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
@@ -1758,37 +1756,28 @@ static void test_msiimport(void)
 
     query = "SELECT * FROM `Table`";
     r = MsiDatabaseOpenView(hdb, query, &view);
-    todo_wine
-    {
-        ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
-    }
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
     r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
     count = MsiRecordGetFieldCount(rec);
-    todo_wine
-    {
-        ok(count == 6, "Expected 6, got %d\n", count);
-        ok(check_record(rec, 1, "A"), "Expected A\n");
-        ok(check_record(rec, 2, "B"), "Expected B\n");
-        ok(check_record(rec, 3, "C"), "Expected C\n");
-        ok(check_record(rec, 4, "D"), "Expected D\n");
-        ok(check_record(rec, 5, "E"), "Expected E\n");
-        ok(check_record(rec, 6, "F"), "Expected F\n");
-    }
+    ok(count == 6, "Expected 6, got %d\n", count);
+    ok(check_record(rec, 1, "A"), "Expected A\n");
+    ok(check_record(rec, 2, "B"), "Expected B\n");
+    ok(check_record(rec, 3, "C"), "Expected C\n");
+    ok(check_record(rec, 4, "D"), "Expected D\n");
+    ok(check_record(rec, 5, "E"), "Expected E\n");
+    ok(check_record(rec, 6, "F"), "Expected F\n");
     MsiCloseHandle(rec);
 
     r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
     count = MsiRecordGetFieldCount(rec);
-    todo_wine
-    {
-        ok(count == 6, "Expected 6, got %d\n", count);
-        ok(check_record(rec, 1, "s72"), "Expected s72\n");
-        ok(check_record(rec, 2, "s72"), "Expected s72\n");
-        ok(check_record(rec, 3, "s72"), "Expected s72\n");
-        ok(check_record(rec, 4, "s72"), "Expected s72\n");
-        ok(check_record(rec, 5, "s72"), "Expected s72\n");
-        ok(check_record(rec, 6, "s72"), "Expected s72\n");
-    }
+    ok(count == 6, "Expected 6, got %d\n", count);
+    ok(check_record(rec, 1, "s72"), "Expected s72\n");
+    ok(check_record(rec, 2, "s72"), "Expected s72\n");
+    ok(check_record(rec, 3, "s72"), "Expected s72\n");
+    ok(check_record(rec, 4, "s72"), "Expected s72\n");
+    ok(check_record(rec, 5, "s72"), "Expected s72\n");
+    ok(check_record(rec, 6, "s72"), "Expected s72\n");
     MsiCloseHandle(rec);
 
     MsiViewClose(view);
@@ -1796,51 +1785,36 @@ static void test_msiimport(void)
 
     query = "SELECT * FROM `Table`";
     r = MsiDatabaseOpenView(hdb, query, &view);
-    todo_wine
-    {
-        ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
-    }
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
     r = MsiViewExecute(view, 0);
-    todo_wine
-    {
-        ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
-    }
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
     r = MsiViewFetch(view, &rec);
-    todo_wine
-    {
-        ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
-        ok(check_record(rec, 1, "a"), "Expected 'a'\n");
-        ok(check_record(rec, 2, "b"), "Expected 'b'\n");
-        ok(check_record(rec, 3, "c"), "Expected 'c'\n");
-        ok(check_record(rec, 4, "d"), "Expected 'd'\n");
-        ok(check_record(rec, 5, "e"), "Expected 'e'\n");
-        ok(check_record(rec, 6, "f"), "Expected 'f'\n");
-    }
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+    ok(check_record(rec, 1, "a"), "Expected 'a'\n");
+    ok(check_record(rec, 2, "b"), "Expected 'b'\n");
+    ok(check_record(rec, 3, "c"), "Expected 'c'\n");
+    ok(check_record(rec, 4, "d"), "Expected 'd'\n");
+    ok(check_record(rec, 5, "e"), "Expected 'e'\n");
+    ok(check_record(rec, 6, "f"), "Expected 'f'\n");
 
     MsiCloseHandle(rec);
 
     r = MsiViewFetch(view, &rec);
-    todo_wine
-    {
-        ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
-        ok(check_record(rec, 1, "g"), "Expected 'g'\n");
-        ok(check_record(rec, 2, "h"), "Expected 'h'\n");
-        ok(check_record(rec, 3, "i"), "Expected 'i'\n");
-        ok(check_record(rec, 4, "j"), "Expected 'j'\n");
-        ok(check_record(rec, 5, "k"), "Expected 'k'\n");
-        ok(check_record(rec, 6, "l"), "Expected 'l'\n");
-    }
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+    ok(check_record(rec, 1, "g"), "Expected 'g'\n");
+    ok(check_record(rec, 2, "h"), "Expected 'h'\n");
+    ok(check_record(rec, 3, "i"), "Expected 'i'\n");
+    ok(check_record(rec, 4, "j"), "Expected 'j'\n");
+    ok(check_record(rec, 5, "k"), "Expected 'k'\n");
+    ok(check_record(rec, 6, "l"), "Expected 'l'\n");
 
     MsiCloseHandle(rec);
 
     r = MsiViewFetch(view, &rec);
-    todo_wine
-    {
-        ok(r == ERROR_NO_MORE_ITEMS,
-           "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
-    }
+    ok(r == ERROR_NO_MORE_ITEMS,
+       "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
 
     MsiViewClose(view);
     MsiCloseHandle(view);




More information about the wine-cvs mailing list