[PATCH 1/2] ole32/tests: Improve the HGLOBAL stream tests for Seek. [try 2]

Reece Dunn msclrhd at googlemail.com
Wed Feb 24 18:22:07 CST 2010


try 1: add tests for invalid arguments and integer overflow.
try 2: add more test cases to cover edge conditions for the function
and more invalid arguments.

- Reece
-------------- next part --------------
From 2d65df4c2bb2b50d159510cf68e0607cabc9a108 Mon Sep 17 00:00:00 2001
From: Reece Dunn <msclrhd at gmail.com>
Date: Wed, 24 Feb 2010 23:56:06 +0000
Subject: [PATCH 1/2] ole32/tests: Improve the HGLOBAL stream tests for Seek.

---
 dlls/ole32/tests/hglobalstream.c |  163 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 158 insertions(+), 5 deletions(-)

diff --git a/dlls/ole32/tests/hglobalstream.c b/dlls/ole32/tests/hglobalstream.c
index 4fee612..585ba31 100644
--- a/dlls/ole32/tests/hglobalstream.c
+++ b/dlls/ole32/tests/hglobalstream.c
@@ -75,23 +75,176 @@ static void test_streamonhglobal(IStream *pStream)
     hr = IStream_SetSize(pStream, ull);
     ok_ole_success(hr, "IStream_SetSize");
 
-    /* ignores HighPart */
-    ll.u.HighPart = -1;
+    /* IStream_Seek -- NULL position argument */
+    ll.u.HighPart = 0;
     ll.u.LowPart = 0;
-    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, NULL);
+    ok_ole_success(hr, "IStream_Seek");
+
+    /* IStream_Seek -- valid position argument (seek from current position) */
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+    ok(ull.u.LowPart == sizeof(data), "should have set LowPart to %d instead of %d\n", sizeof(data), ull.u.LowPart);
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- invalid seek argument */
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_END+1, &ull);
+    todo_wine
+    ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
+    todo_wine
+    ok(ull.u.LowPart == sizeof(data), "should have set LowPart to %d instead of %d\n", sizeof(data), ull.u.LowPart);
     todo_wine
+    ok(ull.u.HighPart == 0, "should not have changed HighPart, got %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- valid position argument (seek to beginning) */
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
     ok_ole_success(hr, "IStream_Seek");
     ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- valid position argument (seek to end) */
+    ll.u.HighPart = 0;
+    ll.u.LowPart = sizeof(data);
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_END, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+    ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- ignore HighPart in the move value (seek from current position) */
+    ll.u.HighPart = 0;
+    ll.u.LowPart = sizeof(data);
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = -1;
+    ll.u.LowPart = 0;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
+    todo_wine
+    ok_ole_success(hr, "IStream_Seek");
+    todo_wine
+    ok(ull.u.LowPart == sizeof(data), "should have set LowPart to %d instead of %d\n", sizeof(data), ull.u.LowPart);
     todo_wine
     ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
 
-    /* ignores HighPart */
+    /* IStream_Seek -- ignore HighPart in the move value (seek to beginning) */
+    ll.u.HighPart = 0;
+    ll.u.LowPart = sizeof(data);
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
     ll.u.HighPart = -1;
     ll.u.LowPart = 0;
-    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, NULL);
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
+    todo_wine
+    ok_ole_success(hr, "IStream_Seek");
+    todo_wine
+    ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %d\n", ull.u.LowPart);
+    todo_wine
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- invalid LowPart value (seek from current position) */
+    ll.u.HighPart = 0;
+    ll.u.LowPart = sizeof(data);
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0x80000000;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
+    todo_wine
+    ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
+    todo_wine
+    ok(ull.u.LowPart == sizeof(data), "should have set LowPart to %d instead of %d\n", sizeof(data), ull.u.LowPart);
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- invalid LowPart value (seek to beginning) */
+    ll.u.HighPart = 0;
+    ll.u.LowPart = sizeof(data);
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0x80000000;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
     todo_wine
+    ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08x\n", hr);
+    todo_wine
+    ok(ull.u.LowPart == sizeof(data), "should have set LowPart to %d instead of %d\n", sizeof(data), ull.u.LowPart);
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- valid LowPart value (seek to beginning) */
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0x7FFFFFFF;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+    ok(ull.u.LowPart == 0x7FFFFFFF, "should have set LowPart to 0x7FFFFFFF instead of %08x\n", ull.u.LowPart);
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- valid LowPart value (seek from current position) */
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
     ok_ole_success(hr, "IStream_Seek");
 
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0x7FFFFFFF;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+    ok(ull.u.LowPart == 0x7FFFFFFF, "should have set LowPart to 0x7FFFFFFF instead of %08x\n", ull.u.LowPart);
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- second seek allows you to go past 0x7FFFFFFF size */
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 9;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+    ok(ull.u.LowPart == 0x80000008, "should have set LowPart to 0x80000008 instead of %08x\n", ull.u.LowPart);
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
+    /* IStream_Seek -- seek wraps position/size on integer overflow */
+    ull.u.HighPart = 0xCAFECAFE;
+    ull.u.LowPart = 0xCAFECAFE;
+    ll.u.HighPart = 0;
+    ll.u.LowPart = 0x7FFFFFFF;
+    hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
+    ok_ole_success(hr, "IStream_Seek");
+    ok(ull.u.LowPart == 0x00000007, "should have set LowPart to 0x00000007 instead of %08x\n", ull.u.LowPart);
+    todo_wine
+    ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %d\n", ull.u.HighPart);
+
     hr = IStream_Commit(pStream, STGC_DEFAULT);
     ok_ole_success(hr, "IStream_Commit");
 
-- 
1.6.3.3


More information about the wine-patches mailing list