[PATCH 2/2] comdlg32/tests: Add GetSaveFileName extension tests.

Eryk Wieliczko ewdevel at gmail.com
Mon Nov 1 06:35:44 CDT 2010


---
 dlls/comdlg32/tests/filedlg.c |   62 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/dlls/comdlg32/tests/filedlg.c b/dlls/comdlg32/tests/filedlg.c
index 977e91d..d578ee3 100644
--- a/dlls/comdlg32/tests/filedlg.c
+++ b/dlls/comdlg32/tests/filedlg.c
@@ -1034,6 +1034,67 @@ static void test_mru(void)
     ok(ret == TRUE, "RemoveDirectoryA should have succeeded: %d\n", GetLastError());
 }
 
+static LONG_PTR WINAPI test_extension_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    HWND parent = GetParent( dlg);
+    if( msg == WM_NOTIFY) {
+        SetTimer( dlg, 0, 100, 0);
+        PostMessage( parent, WM_COMMAND, IDOK, 0);
+    }
+    if( msg == WM_TIMER) {
+        /* the dialog did not close automatically */
+        KillTimer( dlg, 0);
+        PostMessage( parent, WM_COMMAND, IDCANCEL, 0);
+    }
+    return FALSE;
+}
+
+static void test_extension(void)
+{
+    OPENFILENAME ofn = { sizeof(OPENFILENAME)};
+    char filename[1024] = {0};
+    char curdir[MAX_PATH];
+    char *filename_ptr;
+    const char *test_file_name = "deadbeef";
+    const char *test_file_name_extension = "deadbeef.txt";
+    DWORD ret;
+
+    ok(GetCurrentDirectoryA(sizeof(curdir), curdir) != 0, "Failed to get current dir err %d\n", GetLastError());
+
+    ofn.lStructSize = sizeof(ofn);
+    ofn.hwndOwner = NULL;
+    ofn.lpstrFile = filename;
+    ofn.nMaxFile = MAX_PATH;
+    ofn.Flags = OFN_EXPLORER | OFN_ENABLEHOOK;
+    ofn.lpstrDefExt = "txt";
+    ofn.lpstrInitialDir = curdir;
+    ofn.lpfnHook = test_extension_wndproc;
+
+    /* Test 1: append extension to filename */
+    ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
+    strcpy(filename, test_file_name);
+
+    ret = GetSaveFileNameA(&ofn);
+    filename_ptr = ofn.lpstrFile + strlen( ofn.lpstrFile ) - strlen( test_file_name ) - 4;
+
+    ok(1 == ret, "expected 1, got %d\n", ret);
+    ok(strlen(ofn.lpstrFile) >= strlen(test_file_name), "Filename %s is too short\n", ofn.lpstrFile );
+    ok( strcmp(filename_ptr, test_file_name_extension) == 0,
+        "Filename is %s, expected %s\n", filename_ptr, test_file_name_extension );
+
+    /* Test 2: ignore .* extension */
+    ofn.lpstrFilter = "All Files (*.*)\0*.*\0Text Files (*.txt)\0*.txt\0";
+    strcpy(filename, test_file_name);
+
+    ret = GetSaveFileNameA(&ofn);
+    filename_ptr = ofn.lpstrFile + strlen( ofn.lpstrFile ) - strlen( test_file_name );
+
+    ok(1 == ret, "expected 1, got %d\n", ret);
+    ok(strlen(ofn.lpstrFile) >= strlen(test_file_name_extension), "Filename %s is too short\n", ofn.lpstrFile );
+    ok( strcmp(filename_ptr, test_file_name) == 0,
+        "Filename is %s, expected %s\n", filename_ptr, test_file_name );
+}
+
 START_TEST(filedlg)
 {
     test_DialogCancel();
@@ -1045,4 +1106,5 @@ START_TEST(filedlg)
     test_getfolderpath();
     test_mru();
     if( resizesupported) test_resizable2();
+    test_extension();
 }
-- 
1.7.0.4




More information about the wine-patches mailing list