Module: wine Branch: master Commit: 980e00c63b17906413fe99c54b897001d1f63630 URL: http://source.winehq.org/git/wine.git/?a=commit;h=980e00c63b17906413fe99c54b...
Author: Dan Hipschman dsh@linux.ucla.edu Date: Thu Feb 28 18:57:52 2008 -0800
qmgr: Implement IEnumBackgroundCopyFiles_Next.
---
dlls/qmgr/enum_files.c | 38 +++++++++++++-- dlls/qmgr/tests/enum_files.c | 106 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 138 insertions(+), 6 deletions(-)
diff --git a/dlls/qmgr/enum_files.c b/dlls/qmgr/enum_files.c index 0f0a2d8..6602f68 100644 --- a/dlls/qmgr/enum_files.c +++ b/dlls/qmgr/enum_files.c @@ -1,7 +1,7 @@ /* * Queue Manager (BITS) File Enumerator * - * Copyright 2007 Google (Roy Shea) + * Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -73,15 +73,45 @@ static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_Release( return ref; }
-/*** IEnumBackgroundCopyFiles methods ***/ +/* Return reference to one or more files in the file enumerator */ static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Next( IEnumBackgroundCopyFiles* iface, ULONG celt, IBackgroundCopyFile **rgelt, ULONG *pceltFetched) { - FIXME("Not implemented\n"); - return E_NOTIMPL; + EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface; + ULONG fetched; + ULONG i; + IBackgroundCopyFile *file; + + /* Despite documented behavior, Windows (tested on XP) is not verifying + that the caller set pceltFetched to zero. No check here. */ + + fetched = min(celt, This->numFiles - This->indexFiles); + if (pceltFetched) + *pceltFetched = fetched; + else + { + /* We need to initialize this array if the caller doesn't request + the length because length_is will default to celt. */ + for (i = 0; i < celt; i++) + rgelt[i] = NULL; + + /* pceltFetched can only be NULL if celt is 1 */ + if (celt != 1) + return E_INVALIDARG; + } + + /* Fill in the array of objects */ + for (i = 0; i < fetched; i++) + { + file = This->files[This->indexFiles++]; + IBackgroundCopyFile_AddRef(file); + rgelt[i] = file; + } + + return fetched == celt ? S_OK : S_FALSE; }
static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Skip( diff --git a/dlls/qmgr/tests/enum_files.c b/dlls/qmgr/tests/enum_files.c index 5cddee5..452aad6 100644 --- a/dlls/qmgr/tests/enum_files.c +++ b/dlls/qmgr/tests/enum_files.c @@ -1,7 +1,7 @@ /* * Unit test suite for Enum Background Copy Files Interface * - * Copyright 2007 Google (Roy Shea) + * Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,7 +27,7 @@ #include "bits.h"
/* Globals used by many tests */ -#define NUM_FILES 2 +#define NUM_FILES 2 /* At least two. */ static const WCHAR test_remoteNameA[] = {'r','e','m','o','t','e','A', 0}; static const WCHAR test_localNameA[] = {'l','o','c','a','l','A', 0}; static const WCHAR test_remoteNameB[] = {'r','e','m','o','t','e','B', 0}; @@ -116,12 +116,114 @@ static void test_GetCount(void) ok(fileCount == test_fileCount, "Got incorrect count\n"); }
+/* Test Next with a NULL pceltFetched*/ +static void test_Next_walkListNull(void) +{ + HRESULT hres; + IBackgroundCopyFile *file; + ULONG i; + + /* Fetch the available files */ + for (i = 0; i < test_fileCount; i++) + { + hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, NULL); + ok(hres == S_OK, "Next failed: %08x\n", hres); + if(hres != S_OK) + { + skip("Unable to get file from test_enumFiles\n"); + return; + } + IBackgroundCopyFile_Release(file); + } + + /* Attempt to fetch one more than the number of available files */ + hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, NULL); + ok(hres == S_FALSE, "Next off end of available files failed: %08x\n", hres); +} + +/* Test Next by requesting one file at a time */ +static void test_Next_walkList_1(void) +{ + HRESULT hres; + IBackgroundCopyFile *file; + ULONG fetched; + ULONG i; + + /* Fetch the available files */ + for (i = 0; i < test_fileCount; i++) + { + file = NULL; + fetched = 0; + hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, &fetched); + ok(hres == S_OK, "Next failed: %08x\n", hres); + if(hres != S_OK) + { + skip("Unable to get file from test_enumFiles\n"); + return; + } + ok(fetched == 1, "Next returned the incorrect number of files: %08x\n", hres); + ok(file != NULL, "Next returned NULL\n"); + if (file) + IBackgroundCopyFile_Release(file); + } + + /* Attempt to fetch one more than the number of available files */ + fetched = 0; + hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 1, &file, &fetched); + ok(hres == S_FALSE, "Next off end of available files failed: %08x\n", hres); + ok(fetched == 0, "Next returned the incorrect number of files: %08x\n", hres); +} + +/* Test Next by requesting multiple files at a time */ +static void test_Next_walkList_2(void) +{ + HRESULT hres; + IBackgroundCopyFile *files[NUM_FILES]; + ULONG fetched; + ULONG i; + + for (i = 0; i < test_fileCount; i++) + files[i] = NULL; + + fetched = 0; + hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, test_fileCount, files, &fetched); + ok(hres == S_OK, "Next failed: %08x\n", hres); + if(hres != S_OK) + { + skip("Unable to get file from test_enumFiles\n"); + return; + } + ok(fetched == test_fileCount, "Next returned the incorrect number of files: %08x\n", hres); + + for (i = 0; i < test_fileCount; i++) + { + ok(files[i] != NULL, "Next returned NULL\n"); + if (files[i]) + IBackgroundCopyFile_Release(files[i]); + } +} + +/* Test Next Error conditions */ +static void test_Next_errors(void) +{ + HRESULT hres; + IBackgroundCopyFile *files[NUM_FILES]; + + /* E_INVALIDARG: pceltFetched can ONLY be NULL if celt is 1 */ + hres = IEnumBackgroundCopyFiles_Next(test_enumFiles, 2, files, NULL); + ok(hres == E_INVALIDARG, "Invalid call to Next succeeded: %08x\n", hres); +} + typedef void (*test_t)(void);
START_TEST(enum_files) { static const test_t tests[] = { test_GetCount, + test_Next_walkListNull, + test_Next_walkList_1, + test_Next_walkList_2, + test_Next_errors, 0 }; const test_t *test;