From 75668d7c9eeeb49c786b021575ca7a98c3303dce Mon Sep 17 00:00:00 2001
From: Nate Gallaher <ngallaher@deepthought.org>
Date: Sun, 18 Oct 2009 12:47:02 -0400
Subject: [PATCH] Test for bug 20227

Tests that a query on a join of two tables returns data from the correct
table. i.e.: two tables both containing the column "action" are joined
and filtered on the equality of this column. In the buggy case, all
rows of the joined table would be returned, since the first action
column is always equal to itself.
---
 dlls/msi/tests/db.c |   97 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c
index 019ff5e..904a974 100644
--- a/dlls/msi/tests/db.c
+++ b/dlls/msi/tests/db.c
@@ -1566,6 +1566,102 @@ static void test_binary(void)
     DeleteFile( msifile );
 }
 
+/* Test for bug 20227 */
+static void test_where_not_in_selected(void)
+{
+    MSIHANDLE hdb = 0, rec, view;
+    LPCSTR query;
+    UINT r;
+
+    hdb = create_db();
+    ok( hdb, "failed to create db\n");
+
+    r = run_query(hdb, 0,
+            "CREATE TABLE `IESTable` ("
+            "`Action` CHAR(64), "
+            "`Condition` CHAR(64), "
+            "`Sequence` LONG PRIMARY KEY `Sequence`)");
+    ok( r == S_OK, "Cannot create IESTable table: %d\n", r);
+
+    r = run_query(hdb, 0,
+            "CREATE TABLE `CATable` ("
+            "`Action` CHAR(64), "
+            "`Type` LONG PRIMARY KEY `Type`)");
+    ok( r == S_OK, "Cannot create CATable table: %d\n", r);
+
+    r = run_query(hdb, 0, "INSERT INTO `IESTable` "
+            "( `Action`, `Condition`, `Sequence`) "
+            "VALUES ( 'clean', 'cond4', 4)");
+    ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
+
+    r = run_query(hdb, 0, "INSERT INTO `IESTable` "
+            "( `Action`, `Condition`, `Sequence`) "
+            "VALUES ( 'depends', 'cond1', 1)");
+    ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
+
+    r = run_query(hdb, 0, "INSERT INTO `IESTable` "
+            "( `Action`, `Condition`, `Sequence`) "
+            "VALUES ( 'build', 'cond2', 2)");
+    ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
+
+    r = run_query(hdb, 0, "INSERT INTO `IESTable` "
+            "( `Action`, `Condition`, `Sequence`) "
+            "VALUES ( 'build2', 'cond6', 6)");
+    ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
+
+    r = run_query(hdb, 0, "INSERT INTO `IESTable` "
+            "( `Action`, `Condition`, `Sequence`) "
+            "VALUES ( 'build', 'cond3', 3)");
+    ok(r == S_OK, "cannot add entry to IESTable table:%d\n", r );
+
+    r = run_query(hdb, 0, "INSERT INTO `CATable` "
+            "( `Action`, `Type` ) "
+            "VALUES ( 'build', 32)");
+    ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
+
+    r = run_query(hdb, 0, "INSERT INTO `CATable` "
+            "( `Action`, `Type` ) "
+            "VALUES ( 'depends', 64)");
+    ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
+
+    r = run_query(hdb, 0, "INSERT INTO `CATable` "
+            "( `Action`, `Type` ) "
+            "VALUES ( 'clean', 63)");
+    ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
+
+    r = run_query(hdb, 0, "INSERT INTO `CATable` "
+            "( `Action`, `Type` ) "
+            "VALUES ( 'build2', 34)");
+    ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
+    query = "Select IESTable.Condition from CATable, IESTable where "
+            "CATable.Action = IESTable.Action and CATable.Type = 32";
+    r = MsiDatabaseOpenView(hdb, query, &view);
+    ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
+
+    r = MsiViewExecute(view, 0);
+    ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
+
+    r = MsiViewFetch(view, &rec);
+    ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
+
+    ok( check_record( rec, 1, "cond2"), "wrong condition\n");
+
+    MsiCloseHandle( rec );
+    r = MsiViewFetch(view, &rec);
+    ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
+
+    ok( check_record( rec, 1, "cond3"), "wrong condition\n");
+
+    MsiCloseHandle( rec );
+    MsiViewClose(view);
+    MsiCloseHandle(view);
+
+    MsiCloseHandle( hdb );
+    DeleteFile(msifile);
+
+}
+
+
 static void test_where(void)
 {
     MSIHANDLE hdb = 0, rec, view;
@@ -8205,6 +8301,7 @@ START_TEST(db)
     test_longstrings();
     test_streamtable();
     test_binary();
+    test_where_not_in_selected();
     test_where();
     test_msiimport();
     test_binary_import();
-- 
1.6.0.4

