ReactOS 0.4.16-dev-2380-gf63df20
hglobalstream.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "wine/test.h"
Include dependency graph for hglobalstream.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define ok_ole_success(hr, func)   ok(hr == S_OK, func " failed with error %#08lx\n", hr)
 
#define CHECK_EXPECTED_METHOD(method_name)
 

Functions

static void test_streamonhglobal (void)
 
static HRESULT WINAPI TestStream_QueryInterface (IStream *iface, REFIID riid, void **ppv)
 
static ULONG WINAPI TestStream_AddRef (IStream *iface)
 
static ULONG WINAPI TestStream_Release (IStream *iface)
 
static HRESULT WINAPI TestStream_Read (IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
 
static HRESULT WINAPI TestStream_Write (IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
 
static HRESULT WINAPI TestStream_Seek (IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
 
static HRESULT WINAPI TestStream_SetSize (IStream *iface, ULARGE_INTEGER libNewSize)
 
static HRESULT WINAPI TestStream_CopyTo (IStream *iface, IStream *pStream, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
 
static HRESULT WINAPI TestStream_Commit (IStream *iface, DWORD grfCommitFlags)
 
static HRESULT WINAPI TestStream_Revert (IStream *iface)
 
static HRESULT WINAPI TestStream_LockRegion (IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
 
static HRESULT WINAPI TestStream_UnlockRegion (IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
 
static HRESULT WINAPI TestStream_Stat (IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
 
static HRESULT WINAPI TestStream_Clone (IStream *iface, IStream **pStream)
 
static void test_copyto (void)
 
static void test_freed_hglobal (void)
 
static void stream_info (IStream *stream, HGLOBAL *hmem, int *size, int *pos)
 
static void test_IStream_Clone (void)
 
 START_TEST (hglobalstream)
 

Variables

static char const *constexpected_method_list
 
static IStreamVtbl StreamVtbl
 
static IStream Test_Stream = { &StreamVtbl }
 

Macro Definition Documentation

◆ CHECK_EXPECTED_METHOD

#define CHECK_EXPECTED_METHOD (   method_name)
Value:
do { \
ok(*expected_method_list != NULL, "Extra method %s called\n", method_name); \
{ \
ok(!strcmp(*expected_method_list, method_name), "Expected %s to be called instead of %s\n", \
*expected_method_list, method_name); \
} \
} while(0)
#define NULL
Definition: types.h:112
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3319
static char const *const * expected_method_list
Definition: hglobalstream.c:34

Definition at line 36 of file hglobalstream.c.

◆ COBJMACROS

#define COBJMACROS

Definition at line 22 of file hglobalstream.c.

◆ ok_ole_success

#define ok_ole_success (   hr,
  func 
)    ok(hr == S_OK, func " failed with error %#08lx\n", hr)

Definition at line 32 of file hglobalstream.c.

Function Documentation

◆ START_TEST()

START_TEST ( hglobalstream  )

Definition at line 723 of file hglobalstream.c.

724{
726 test_copyto();
729}
static void test_IStream_Clone(void)
static void test_copyto(void)
static void test_streamonhglobal(void)
Definition: hglobalstream.c:47
static void test_freed_hglobal(void)

◆ stream_info()

static void stream_info ( IStream stream,
HGLOBAL hmem,
int size,
int pos 
)
static

Definition at line 536 of file hglobalstream.c.

537{
538 HRESULT hr;
539 STATSTG stat;
541 ULARGE_INTEGER newpos;
542
543 *hmem = 0;
544 *size = *pos = -1;
545
547 ok(hr == S_OK, "unexpected %#lx\n", hr);
548
549 memset(&stat, 0x55, sizeof(stat));
550 hr = IStream_Stat(stream, &stat, STATFLAG_DEFAULT);
551 ok(hr == S_OK, "unexpected %#lx\n", hr);
552 ok(stat.type == STGTY_STREAM, "unexpected %#lx\n", stat.type);
553 ok(!stat.pwcsName, "unexpected %p\n", stat.pwcsName);
554 ok(IsEqualIID(&stat.clsid, &GUID_NULL), "unexpected %s\n", wine_dbgstr_guid(&stat.clsid));
555 ok(!stat.cbSize.HighPart, "unexpected %#lx\n", stat.cbSize.HighPart);
556 *size = stat.cbSize.LowPart;
557
558 offset.QuadPart = 0;
559 hr = IStream_Seek(stream, offset, STREAM_SEEK_CUR, &newpos);
560 ok(hr == S_OK, "unexpected %#lx\n", hr);
561 ok(!newpos.HighPart, "unexpected %#lx\n", newpos.HighPart);
562 *pos = newpos.LowPart;
563}
#define stat
Definition: acwin.h:99
#define ok(value,...)
Definition: atltest.h:57
HRESULT WINAPI GetHGlobalFromStream(IStream *stream, HGLOBAL *phglobal)
GLsizeiptr size
Definition: glext.h:5919
GLintptr offset
Definition: glext.h:5920
#define S_OK
Definition: intsafe.h:52
#define GUID_NULL
Definition: ks.h:106
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:206
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
$ULONG LowPart
Definition: ntbasedef.h:581
$ULONG HighPart
Definition: ntbasedef.h:582
Definition: stat.h:66
Definition: parse.h:23

Referenced by context_update_stream_info(), draw_primitive(), indexbuffer(), load_numbered_arrays(), process_vertices_strided(), test_IStream_Clone(), wined3d_device_process_vertices(), and wined3d_stream_info_from_declaration().

◆ test_copyto()

static void test_copyto ( void  )
static

Definition at line 434 of file hglobalstream.c.

435{
436 IStream *pStream, *pStream2;
438 static const char szHello[] = "Hello";
440 static const char *methods_copyto[] =
441 {
442 "TestStream_Write",
443 NULL
444 };
445 ULONG written;
446 ULARGE_INTEGER ullRead;
447 ULARGE_INTEGER ullWritten;
448 ULARGE_INTEGER libNewPosition;
449 static const LARGE_INTEGER llZero;
450 char buffer[15];
451
452 ok_ole_success(hr, "CreateStreamOnHGlobal");
453
454 expected_method_list = methods_copyto;
455
456 hr = IStream_Write(pStream, szHello, sizeof(szHello), &written);
457 ok_ole_success(hr, "IStream_Write");
458 ok(written == sizeof(szHello), "only %ld bytes written\n", written);
459
460 hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL);
461 ok_ole_success(hr, "IStream_Seek");
462
463 cb.QuadPart = sizeof(szHello);
464 hr = IStream_CopyTo(pStream, &Test_Stream, cb, &ullRead, &ullWritten);
465 ok(ullWritten.QuadPart == 5, "ullWritten was %ld instead\n", (ULONG)ullWritten.QuadPart);
466 ok(ullRead.QuadPart == sizeof(szHello), "only %ld bytes read\n", (ULONG)ullRead.QuadPart);
467 ok_ole_success(hr, "IStream_CopyTo");
468
469 ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list);
470
471 hr = IStream_Clone(pStream, &pStream2);
472 ok_ole_success(hr, "IStream_Clone");
473
474 hr = IStream_Seek(pStream2, llZero, STREAM_SEEK_CUR, &libNewPosition);
475 ok_ole_success(hr, "IStream_Seek");
476 ok(libNewPosition.QuadPart == sizeof(szHello), "libNewPosition wasn't set correctly for the cloned stream\n");
477
478 hr = IStream_Seek(pStream2, llZero, STREAM_SEEK_SET, NULL);
479 ok_ole_success(hr, "IStream_Seek");
480
481 hr = IStream_Read(pStream2, buffer, sizeof(buffer), NULL);
482 ok_ole_success(hr, "IStream_Read");
483 ok(!strcmp(buffer, szHello), "read data \"%s\" didn't match originally written data\n", buffer);
484
485 IStream_Release(pStream2);
486 IStream_Release(pStream);
487}
#define TRUE
Definition: types.h:120
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL delete_on_release, IStream **stream)
static MonoProfilerRuntimeShutdownBeginCallback cb
Definition: metahost.c:118
GLuint buffer
Definition: glext.h:5915
#define ok_ole_success(hr, func)
Definition: hglobalstream.c:32
static IStream Test_Stream
static const LARGE_INTEGER llZero
Definition: moniker.c:1425
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
uint32_t ULONG
Definition: typedefs.h:59

Referenced by START_TEST().

◆ test_freed_hglobal()

static void test_freed_hglobal ( void  )
static

Definition at line 489 of file hglobalstream.c.

490{
491 static const char teststring[] = "this is a test string";
492 HRESULT hr;
493 IStream *pStream;
494 HGLOBAL hglobal;
495 char *p;
496 char buffer[sizeof(teststring) + 8];
497 ULARGE_INTEGER ull;
498 ULONG read, written;
499
500 hglobal = GlobalAlloc(GMEM_DDESHARE|GMEM_NODISCARD|GMEM_MOVEABLE, strlen(teststring) + 1);
501 ok(hglobal != NULL, "GlobalAlloc failed with error %ld\n", GetLastError());
502 p = GlobalLock(hglobal);
503 strcpy(p, teststring);
504 GlobalUnlock(hglobal);
505
506 hr = CreateStreamOnHGlobal(hglobal, FALSE, &pStream);
507 ok_ole_success(hr, "CreateStreamOnHGlobal");
508
509 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
510 ok_ole_success(hr, "IStream_Read");
511 ok(!strcmp(buffer, teststring), "buffer data %s differs\n", buffer);
512 ok(read == sizeof(teststring) ||
513 broken(read == ((sizeof(teststring) + 3) & ~3)), /* win9x rounds the size */
514 "read should be sizeof(teststring) instead of %ld\n", read);
515
516 GlobalFree(hglobal);
517
518 memset(buffer, 0, sizeof(buffer));
519 read = -1;
520 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
521 ok_ole_success(hr, "IStream_Read");
522 ok(buffer[0] == 0, "buffer data should be untouched\n");
523 ok(read == 0, "read should be 0 instead of %ld\n", read);
524
525 ull.QuadPart = sizeof(buffer);
526 hr = IStream_SetSize(pStream, ull);
527 ok(hr == E_OUTOFMEMORY, "IStream_SetSize with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08lx\n", hr);
528
529 hr = IStream_Write(pStream, buffer, sizeof(buffer), &written);
530 ok(hr == E_OUTOFMEMORY, "IStream_Write with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08lx\n", hr);
531 ok(written == 0, "written should be 0 instead of %ld\n", written);
532
533 IStream_Release(pStream);
534}
#define read
Definition: acwin.h:96
#define broken(x)
Definition: atltest.h:178
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FALSE
Definition: types.h:117
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
GLfloat GLfloat p
Definition: glext.h:8902
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
static ERESOURCE GlobalLock
Definition: sys_arch.c:8
strcpy
Definition: string.h:131
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GMEM_NODISCARD
Definition: winbase.h:326
#define GMEM_MOVEABLE
Definition: winbase.h:318
#define GMEM_DDESHARE
Definition: winbase.h:322

Referenced by START_TEST().

◆ test_IStream_Clone()

static void test_IStream_Clone ( void  )
static

Definition at line 565 of file hglobalstream.c.

566{
567 static const char hello[] = "Hello World!";
568 char buf[32];
569 HRESULT hr;
570 IStream *stream, *clone;
571 HGLOBAL orig_hmem, hmem, hmem_clone;
572 ULARGE_INTEGER newsize;
574 int size, pos, ret;
575
576 /* test simple case for Clone */
577 orig_hmem = GlobalAlloc(GMEM_MOVEABLE, 0);
578 ok(orig_hmem != 0, "unexpected %p\n", orig_hmem);
579 hr = CreateStreamOnHGlobal(orig_hmem, TRUE, &stream);
580 ok(hr == S_OK, "unexpected %#lx\n", hr);
581
583 ok(hr == E_INVALIDARG, "unexpected %#lx\n", hr);
584
585 hr = GetHGlobalFromStream(NULL, &hmem);
586 ok(hr == E_INVALIDARG, "unexpected %#lx\n", hr);
587
588 stream_info(stream, &hmem, &size, &pos);
589 ok(hmem == orig_hmem, "handles should match\n");
590 ok(size == 0, "unexpected %d\n", size);
591 ok(pos == 0, "unexpected %d\n", pos);
592
593 hr = IStream_Clone(stream, &clone);
594 ok(hr == S_OK, "unexpected %#lx\n", hr);
595
596 hr = IStream_Write(stream, hello, sizeof(hello), NULL);
597 ok(hr == S_OK, "unexpected %#lx\n", hr);
598
599 stream_info(stream, &hmem, &size, &pos);
600 ok(hmem == orig_hmem, "handles should match\n");
601 ok(size == 13, "unexpected %d\n", size);
602 ok(pos == 13, "unexpected %d\n", pos);
603
604 stream_info(clone, &hmem_clone, &size, &pos);
605 ok(hmem_clone == hmem, "handles should match\n");
606 ok(size == 13, "unexpected %d\n", size);
607 ok(pos == 0, "unexpected %d\n", pos);
608
609 buf[0] = 0;
610 hr = IStream_Read(clone, buf, sizeof(buf), NULL);
611 ok(hr == S_OK, "unexpected %#lx\n", hr);
612 ok(!strcmp(buf, hello), "wrong stream contents\n");
613
614 newsize.QuadPart = 0x8000;
615 hr = IStream_SetSize(stream, newsize);
616 ok(hr == S_OK, "unexpected %#lx\n", hr);
617
618 stream_info(stream, &hmem, &size, &pos);
619 ok(hmem == orig_hmem, "handles should match\n");
620 ok(size == 0x8000, "unexpected %#x\n", size);
621 ok(pos == 13, "unexpected %d\n", pos);
622
623 stream_info(clone, &hmem_clone, &size, &pos);
624 ok(hmem_clone == hmem, "handles should match\n");
625 ok(size == 0x8000, "unexpected %#x\n", size);
626 ok(pos == 13, "unexpected %d\n", pos);
627
628 IStream_Release(clone);
629 IStream_Release(stream);
630
631 /* exploit GMEM_FIXED forced move for the same base streams */
632 orig_hmem = GlobalAlloc(GMEM_FIXED, 1);
633 ok(orig_hmem != 0, "unexpected %p\n", orig_hmem);
634 hr = CreateStreamOnHGlobal(orig_hmem, TRUE, &stream);
635 ok(hr == S_OK, "unexpected %#lx\n", hr);
636
637 hr = IStream_Clone(stream, &clone);
638 ok(hr == S_OK, "unexpected %#lx\n", hr);
639
640 stream_info(stream, &hmem, &size, &pos);
641 ok(hmem == orig_hmem, "handles should match\n");
642 ok(size == 1, "unexpected %d\n", size);
643 ok(pos == 0, "unexpected %d\n", pos);
644
645 stream_info(clone, &hmem_clone, &size, &pos);
646 ok(hmem_clone == hmem, "handles should match\n");
647 ok(size == 1, "unexpected %d\n", size);
648 ok(pos == 0, "unexpected %d\n", pos);
649
650 newsize.QuadPart = 0x8000;
651 hr = IStream_SetSize(stream, newsize);
652 ok(hr == S_OK, "unexpected %#lx\n", hr);
653
654 stream_info(stream, &hmem, &size, &pos);
655 ok(hmem != 0, "unexpected %p\n", hmem);
656 ok(hmem != orig_hmem, "unexpected %p\n", hmem);
657 ok(size == 0x8000, "unexpected %#x\n", size);
658 ok(pos == 0, "unexpected %d\n", pos);
659
660 stream_info(clone, &hmem_clone, &size, &pos);
661 ok(hmem_clone == hmem, "handles should match\n");
662 ok(size == 0x8000, "unexpected %#x\n", size);
663 ok(pos == 0, "unexpected %d\n", pos);
664
665 IStream_Release(stream);
666 IStream_Release(clone);
667
668 /* test Release of cloned stream */
670 ok(hr == S_OK, "unexpected %#lx\n", hr);
671
672 hr = IStream_Clone(stream, &clone);
673 ok(hr == S_OK, "unexpected %#lx\n", hr);
674
675 stream_info(stream, &hmem, &size, &pos);
676 ok(hmem != 0, "unexpected %p\n", hmem);
677 ok(size == 0, "unexpected %d\n", size);
678 ok(pos == 0, "unexpected %d\n", pos);
679
680 stream_info(clone, &hmem_clone, &size, &pos);
681 ok(hmem_clone == hmem, "handles should match\n");
682 ok(size == 0, "unexpected %#x\n", size);
683 ok(pos == 0, "unexpected %d\n", pos);
684
685 ret = IStream_Release(stream);
686 ok(ret == 0, "unexpected %d\n", ret);
687
688 newsize.QuadPart = 0x8000;
689 hr = IStream_SetSize(clone, newsize);
690 ok(hr == S_OK, "unexpected %#lx\n", hr);
691
692 stream_info(clone, &hmem_clone, &size, &pos);
693 ok(hmem_clone == hmem, "handles should match\n");
694 ok(size == 0x8000, "unexpected %#x\n", size);
695 ok(pos == 0, "unexpected %d\n", pos);
696
697 hr = IStream_Write(clone, hello, sizeof(hello), NULL);
698 ok(hr == S_OK, "unexpected %#lx\n", hr);
699
700 stream_info(clone, &hmem_clone, &size, &pos);
701 ok(hmem_clone == hmem, "handles should match\n");
702 ok(size == 0x8000, "unexpected %#x\n", size);
703 ok(pos == 13, "unexpected %d\n", pos);
704
705 offset.QuadPart = 0;
706 hr = IStream_Seek(clone, offset, STREAM_SEEK_SET, NULL);
707 ok(hr == S_OK, "unexpected %#lx\n", hr);
708
709 buf[0] = 0;
710 hr = IStream_Read(clone, buf, sizeof(buf), NULL);
711 ok(hr == S_OK, "unexpected %#lx\n", hr);
712 ok(!strcmp(buf, hello), "wrong stream contents\n");
713
714 stream_info(clone, &hmem_clone, &size, &pos);
715 ok(hmem_clone == hmem, "handles should match\n");
716 ok(size == 0x8000, "unexpected %#x\n", size);
717 ok(pos == 32, "unexpected %d\n", pos);
718
719 ret = IStream_Release(clone);
720 ok(ret == 0, "unexpected %d\n", ret);
721}
#define E_INVALIDARG
Definition: ddrawi.h:101
return ret
Definition: mutex.c:146
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: ctx.idl:7
static void stream_info(IStream *stream, HGLOBAL *hmem, int *size, int *pos)
#define GMEM_FIXED
Definition: winbase.h:317

Referenced by START_TEST().

◆ test_streamonhglobal()

static void test_streamonhglobal ( void  )
static

Definition at line 47 of file hglobalstream.c.

48{
49 const char data[] = "Test String";
51 IStream *pStream;
53 char buffer[128];
54 ULONG read;
55 STATSTG statstg;
56 HRESULT hr;
57
58 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
59 ok(hr == S_OK, "Failed to create a stream, hr %#lx.\n", hr);
60
61 ull.QuadPart = sizeof(data);
62 hr = IStream_SetSize(pStream, ull);
63 ok_ole_success(hr, "IStream_SetSize");
64
65 hr = IStream_Write(pStream, data, sizeof(data), NULL);
66 ok_ole_success(hr, "IStream_Write");
67
68 /* Seek beyond the end of the stream and read from it */
69 ll.QuadPart = sizeof(data) + 16;
70 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, NULL);
71 ok_ole_success(hr, "IStream_Seek");
72
73 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
74 ok_ole_success(hr, "IStream_Read");
75 ok(read == 0, "IStream_Read returned read %ld\n", read);
76
77 ull.u.HighPart = 0xCAFECAFE;
78 ull.u.LowPart = 0xCAFECAFE;
79 ll.u.HighPart = 0;
80 ll.u.LowPart = 0;
81 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
82 ok_ole_success(hr, "IStream_Seek");
83 ok(ull.u.LowPart == sizeof(data) + 16, "LowPart set to %ld\n", ull.u.LowPart);
84 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
85
86 /* Seek to the start of the stream and read from it */
87 ll.QuadPart = 0;
88 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, NULL);
89 ok_ole_success(hr, "IStream_Seek");
90
91 /* should return S_OK, not S_FALSE */
92 hr = IStream_Read(pStream, buffer, sizeof(buffer), &read);
93 ok_ole_success(hr, "IStream_Read");
94 ok(read == sizeof(data), "IStream_Read returned read %ld\n", read);
95
96 /* ignores HighPart */
97 ull.u.HighPart = -1;
98 ull.u.LowPart = 0;
99 hr = IStream_SetSize(pStream, ull);
100 ok_ole_success(hr, "IStream_SetSize");
101
102 /* IStream_Seek -- NULL position argument */
103 ll.u.HighPart = 0;
104 ll.u.LowPart = 0;
105 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, NULL);
106 ok_ole_success(hr, "IStream_Seek");
107
108 /* IStream_Seek -- valid position argument (seek from current position) */
109 ull.u.HighPart = 0xCAFECAFE;
110 ull.u.LowPart = 0xCAFECAFE;
111 ll.u.HighPart = 0;
112 ll.u.LowPart = 0;
113 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
114 ok_ole_success(hr, "IStream_Seek");
115 ok(ull.u.LowPart == sizeof(data), "LowPart set to %ld\n", ull.u.LowPart);
116 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
117
118 /* IStream_Seek -- invalid seek argument */
119 ull.u.HighPart = 0xCAFECAFE;
120 ull.u.LowPart = 0xCAFECAFE;
121 ll.u.HighPart = 0;
122 ll.u.LowPart = 123;
123 hr = IStream_Seek(pStream, ll, STREAM_SEEK_END+1, &ull);
124 ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08lx\n", hr);
125 ok(ull.u.LowPart == sizeof(data), "LowPart set to %ld\n", ull.u.LowPart);
126 ok(ull.u.HighPart == 0, "should not have changed HighPart, got %ld\n", ull.u.HighPart);
127
128 /* IStream_Seek -- valid position argument (seek to beginning) */
129 ull.u.HighPart = 0xCAFECAFE;
130 ull.u.LowPart = 0xCAFECAFE;
131 ll.u.HighPart = 0;
132 ll.u.LowPart = 0;
133 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
134 ok_ole_success(hr, "IStream_Seek");
135 ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %ld\n", ull.u.LowPart);
136 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
137
138 /* IStream_Seek -- valid position argument (seek to end) */
139 ull.u.HighPart = 0xCAFECAFE;
140 ull.u.LowPart = 0xCAFECAFE;
141 ll.u.HighPart = 0;
142 ll.u.LowPart = 0;
143 hr = IStream_Seek(pStream, ll, STREAM_SEEK_END, &ull);
144 ok_ole_success(hr, "IStream_Seek");
145 ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %ld\n", ull.u.LowPart);
146 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
147
148 /* IStream_Seek -- ignore HighPart in the move value (seek from current position) */
149 ll.u.HighPart = 0;
150 ll.u.LowPart = sizeof(data);
151 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
152 ok_ole_success(hr, "IStream_Seek");
153
154 ull.u.HighPart = 0xCAFECAFE;
155 ull.u.LowPart = 0xCAFECAFE;
156 ll.u.HighPart = -1;
157 ll.u.LowPart = 0;
158 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
159 ok_ole_success(hr, "IStream_Seek");
160 ok(ull.u.LowPart == sizeof(data), "LowPart set to %ld\n", ull.u.LowPart);
161 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
162
163 /* IStream_Seek -- ignore HighPart in the move value (seek to beginning) */
164 ll.u.HighPart = 0;
165 ll.u.LowPart = sizeof(data);
166 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
167 ok_ole_success(hr, "IStream_Seek");
168
169 ull.u.HighPart = 0xCAFECAFE;
170 ull.u.LowPart = 0xCAFECAFE;
171 ll.u.HighPart = -1;
172 ll.u.LowPart = 0;
173 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
174 ok_ole_success(hr, "IStream_Seek");
175 ok(ull.u.LowPart == 0, "should have set LowPart to 0 instead of %ld\n", ull.u.LowPart);
176 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
177
178 /* IStream_Seek -- invalid LowPart value (seek before start of stream) */
179 ll.u.HighPart = 0;
180 ll.u.LowPart = sizeof(data);
181 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
182 ok_ole_success(hr, "IStream_Seek");
183
184 ull.u.HighPart = 0xCAFECAFE;
185 ull.u.LowPart = 0xCAFECAFE;
186 ll.u.HighPart = 0;
187 ll.u.LowPart = 0x80000000;
188 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
189 ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08lx\n", hr);
190 ok(ull.u.LowPart == sizeof(data), "LowPart set to %ld\n", ull.u.LowPart);
191 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
192
193 /* IStream_Seek -- valid LowPart value (seek to start of stream) */
194 ll.u.HighPart = 0;
195 ll.u.LowPart = sizeof(data);
196 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
197 ok_ole_success(hr, "IStream_Seek");
198
199 ull.u.HighPart = 0xCAFECAFE;
200 ull.u.LowPart = 0xCAFECAFE;
201 ll.u.HighPart = 0;
202 ll.u.LowPart = -(DWORD)sizeof(data);
203 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
204 ok_ole_success(hr, "IStream_Seek");
205 ok(ull.u.LowPart == 0, "LowPart set to %ld\n", ull.u.LowPart);
206 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
207
208 /* IStream_Seek -- invalid LowPart value (seek to start of stream-1) */
209 ll.u.HighPart = 0;
210 ll.u.LowPart = sizeof(data);
211 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
212 ok_ole_success(hr, "IStream_Seek");
213
214 ull.u.HighPart = 0xCAFECAFE;
215 ull.u.LowPart = 0xCAFECAFE;
216 ll.u.HighPart = 0;
217 ll.u.LowPart = -(DWORD)sizeof(data)-1;
218 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
219 ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08lx\n", hr);
220 ok(ull.u.LowPart == sizeof(data), "LowPart set to %ld\n", ull.u.LowPart);
221 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
222
223 /* IStream_Seek -- valid LowPart value (seek forward to 0x80000000) */
224 ll.u.HighPart = 0;
225 ll.u.LowPart = sizeof(data);
226 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
227 ok_ole_success(hr, "IStream_Seek");
228
229 ull.u.HighPart = 0xCAFECAFE;
230 ull.u.LowPart = 0xCAFECAFE;
231 ll.u.HighPart = 0;
232 ll.u.LowPart = 0x80000000 - sizeof(data);
233 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
234 ok_ole_success(hr, "IStream_Seek");
235 ok(ull.u.LowPart == 0x80000000, "LowPart set to %ld\n", ull.u.LowPart);
236 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
237
238 /* IStream_Seek -- invalid LowPart value (seek to beginning) */
239 ll.u.HighPart = 0;
240 ll.u.LowPart = sizeof(data);
241 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
242 ok_ole_success(hr, "IStream_Seek");
243
244 ull.u.HighPart = 0xCAFECAFE;
245 ull.u.LowPart = 0xCAFECAFE;
246 ll.u.HighPart = 0;
247 ll.u.LowPart = 0x80000000;
248 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
249 ok(hr == STG_E_SEEKERROR, "IStream_Seek should have returned STG_E_SEEKERROR instead of 0x%08lx\n", hr);
250 ok(ull.u.LowPart == sizeof(data), "LowPart set to %ld\n", ull.u.LowPart);
251 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
252
253 /* IStream_Seek -- valid LowPart value (seek to beginning) */
254 ull.u.HighPart = 0xCAFECAFE;
255 ull.u.LowPart = 0xCAFECAFE;
256 ll.u.HighPart = 0;
257 ll.u.LowPart = 0x7FFFFFFF;
258 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
259 ok_ole_success(hr, "IStream_Seek");
260 ok(ull.u.LowPart == 0x7FFFFFFF, "should have set LowPart to 0x7FFFFFFF instead of %08lx\n", ull.u.LowPart);
261 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
262
263 /* IStream_Seek -- valid LowPart value (seek from current position) */
264 ll.u.HighPart = 0;
265 ll.u.LowPart = 0;
266 hr = IStream_Seek(pStream, ll, STREAM_SEEK_SET, &ull);
267 ok_ole_success(hr, "IStream_Seek");
268
269 ull.u.HighPart = 0xCAFECAFE;
270 ull.u.LowPart = 0xCAFECAFE;
271 ll.u.HighPart = 0;
272 ll.u.LowPart = 0x7FFFFFFF;
273 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
274 ok_ole_success(hr, "IStream_Seek");
275 ok(ull.u.LowPart == 0x7FFFFFFF, "should have set LowPart to 0x7FFFFFFF instead of %08lx\n", ull.u.LowPart);
276 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
277
278 /* IStream_Seek -- second seek allows you to go past 0x7FFFFFFF size */
279 ull.u.HighPart = 0xCAFECAFE;
280 ull.u.LowPart = 0xCAFECAFE;
281 ll.u.HighPart = 0;
282 ll.u.LowPart = 9;
283 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
284 ok_ole_success(hr, "IStream_Seek");
285 ok(ull.u.LowPart == 0x80000008, "should have set LowPart to 0x80000008 instead of %08lx\n", ull.u.LowPart);
286 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
287
288 /* IStream_Seek -- seek wraps position/size on integer overflow, but not on win8 */
289 ull.u.HighPart = 0xCAFECAFE;
290 ull.u.LowPart = 0xCAFECAFE;
291 ll.u.HighPart = 0;
292 ll.u.LowPart = 0x7FFFFFFF;
293 hr = IStream_Seek(pStream, ll, STREAM_SEEK_CUR, &ull);
294 ok(hr == S_OK || hr == STG_E_SEEKERROR /* win8 */, "IStream_Seek\n");
295 if (SUCCEEDED(hr))
296 ok(ull.u.LowPart == 0x00000007, "should have set LowPart to 0x00000007 instead of %08lx\n", ull.u.LowPart);
297 else
298 ok(ull.u.LowPart == 0x80000008, "should have set LowPart to 0x80000008 instead of %08lx\n", ull.u.LowPart);
299 ok(ull.u.HighPart == 0, "should have set HighPart to 0 instead of %ld\n", ull.u.HighPart);
300
301 hr = IStream_Commit(pStream, STGC_DEFAULT);
302 ok_ole_success(hr, "IStream_Commit");
303
304 hr = IStream_Revert(pStream);
305 ok_ole_success(hr, "IStream_Revert");
306
307 hr = IStream_LockRegion(pStream, ull, ull, LOCK_WRITE);
308 ok(hr == STG_E_INVALIDFUNCTION, "IStream_LockRegion should have returned STG_E_INVALIDFUNCTION instead of 0x%08lx\n", hr);
309
310 hr = IStream_Stat(pStream, &statstg, STATFLAG_DEFAULT);
311 ok_ole_success(hr, "IStream_Stat");
312 ok(statstg.type == STGTY_STREAM, "statstg.type should have been STGTY_STREAM instead of %ld\n", statstg.type);
313
314 /* test OOM condition */
315 ull.u.HighPart = -1;
316 ull.u.LowPart = 0;
317 hr = IStream_SetSize(pStream, ull);
318 ok(hr == S_OK, "IStream_SetSize with large size should have returned S_OK instead of 0x%08lx\n", hr);
319
320 IStream_Release(pStream);
321}
w ll
Definition: byte_order.h:167
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define DWORD
Definition: nt_native.h:44
struct _ULARGE_INTEGER::@4461 u
#define STG_E_SEEKERROR
Definition: winerror.h:3669
#define STG_E_INVALIDFUNCTION
Definition: winerror.h:3659

Referenced by START_TEST().

◆ TestStream_AddRef()

static ULONG WINAPI TestStream_AddRef ( IStream iface)
static

Definition at line 337 of file hglobalstream.c.

338{
339 return 2;
340}

◆ TestStream_Clone()

static HRESULT WINAPI TestStream_Clone ( IStream iface,
IStream **  pStream 
)
static

Definition at line 408 of file hglobalstream.c.

409{
410 CHECK_EXPECTED_METHOD("TestStream_Clone");
411 return E_NOTIMPL;
412}
#define E_NOTIMPL
Definition: ddrawi.h:99
#define CHECK_EXPECTED_METHOD(method_name)
Definition: hglobalstream.c:36

◆ TestStream_Commit()

static HRESULT WINAPI TestStream_Commit ( IStream iface,
DWORD  grfCommitFlags 
)
static

Definition at line 378 of file hglobalstream.c.

379{
380 CHECK_EXPECTED_METHOD("TestStream_Commit");
381 return E_NOTIMPL;
382}

◆ TestStream_CopyTo()

static HRESULT WINAPI TestStream_CopyTo ( IStream iface,
IStream pStream,
ULARGE_INTEGER  cb,
ULARGE_INTEGER pcbRead,
ULARGE_INTEGER pcbWritten 
)
static

Definition at line 372 of file hglobalstream.c.

373{
374 CHECK_EXPECTED_METHOD("TestStream_CopyTo");
375 return E_NOTIMPL;
376}

◆ TestStream_LockRegion()

static HRESULT WINAPI TestStream_LockRegion ( IStream iface,
ULARGE_INTEGER  libOffset,
ULARGE_INTEGER  cb,
DWORD  dwLockType 
)
static

Definition at line 390 of file hglobalstream.c.

391{
392 CHECK_EXPECTED_METHOD("TestStream_LockRegion");
393 return E_NOTIMPL;
394}

◆ TestStream_QueryInterface()

static HRESULT WINAPI TestStream_QueryInterface ( IStream iface,
REFIID  riid,
void **  ppv 
)
static

Definition at line 323 of file hglobalstream.c.

324{
326 IsEqualIID(riid, &IID_ISequentialStream) ||
327 IsEqualIID(riid, &IID_IStream))
328 {
329 *ppv = iface;
330 IStream_AddRef(iface);
331 return S_OK;
332 }
333 *ppv = NULL;
334 return E_NOINTERFACE;
335}
const GUID IID_IUnknown
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define E_NOINTERFACE
Definition: winerror.h:3479

◆ TestStream_Read()

static HRESULT WINAPI TestStream_Read ( IStream iface,
void pv,
ULONG  cb,
ULONG pcbRead 
)
static

Definition at line 347 of file hglobalstream.c.

348{
349 CHECK_EXPECTED_METHOD("TestStream_Read");
350 return E_NOTIMPL;
351}

◆ TestStream_Release()

static ULONG WINAPI TestStream_Release ( IStream iface)
static

Definition at line 342 of file hglobalstream.c.

343{
344 return 1;
345}

◆ TestStream_Revert()

static HRESULT WINAPI TestStream_Revert ( IStream iface)
static

Definition at line 384 of file hglobalstream.c.

385{
386 CHECK_EXPECTED_METHOD("TestStream_Revert");
387 return E_NOTIMPL;
388}

◆ TestStream_Seek()

static HRESULT WINAPI TestStream_Seek ( IStream iface,
LARGE_INTEGER  dlibMove,
DWORD  dwOrigin,
ULARGE_INTEGER plibNewPosition 
)
static

Definition at line 360 of file hglobalstream.c.

361{
362 CHECK_EXPECTED_METHOD("TestStream_Seek");
363 return E_NOTIMPL;
364}

◆ TestStream_SetSize()

static HRESULT WINAPI TestStream_SetSize ( IStream iface,
ULARGE_INTEGER  libNewSize 
)
static

Definition at line 366 of file hglobalstream.c.

367{
368 CHECK_EXPECTED_METHOD("TestStream_SetSize");
369 return E_NOTIMPL;
370}

◆ TestStream_Stat()

static HRESULT WINAPI TestStream_Stat ( IStream iface,
STATSTG *  pstatstg,
DWORD  grfStatFlag 
)
static

Definition at line 402 of file hglobalstream.c.

403{
404 CHECK_EXPECTED_METHOD("TestStream_Stat");
405 return E_NOTIMPL;
406}

◆ TestStream_UnlockRegion()

static HRESULT WINAPI TestStream_UnlockRegion ( IStream iface,
ULARGE_INTEGER  libOffset,
ULARGE_INTEGER  cb,
DWORD  dwLockType 
)
static

Definition at line 396 of file hglobalstream.c.

397{
398 CHECK_EXPECTED_METHOD("TestStream_UnlockRegion");
399 return E_NOTIMPL;
400}

◆ TestStream_Write()

static HRESULT WINAPI TestStream_Write ( IStream iface,
const void pv,
ULONG  cb,
ULONG pcbWritten 
)
static

Definition at line 353 of file hglobalstream.c.

354{
355 CHECK_EXPECTED_METHOD("TestStream_Write");
356 *pcbWritten = 5;
357 return S_OK;
358}

Variable Documentation

◆ expected_method_list

char const* const* expected_method_list
static

Definition at line 34 of file hglobalstream.c.

Referenced by test_copyto().

◆ StreamVtbl

IStreamVtbl StreamVtbl
static
Initial value:
=
{
}
static HRESULT WINAPI TestStream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
static HRESULT WINAPI TestStream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
static HRESULT WINAPI TestStream_Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
static HRESULT WINAPI TestStream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
static HRESULT WINAPI TestStream_CopyTo(IStream *iface, IStream *pStream, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
static HRESULT WINAPI TestStream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
static HRESULT WINAPI TestStream_Revert(IStream *iface)
static HRESULT WINAPI TestStream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
static HRESULT WINAPI TestStream_Commit(IStream *iface, DWORD grfCommitFlags)
static HRESULT WINAPI TestStream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
static ULONG WINAPI TestStream_Release(IStream *iface)
static HRESULT WINAPI TestStream_UnlockRegion(IStream *iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
static HRESULT WINAPI TestStream_Clone(IStream *iface, IStream **pStream)
static ULONG WINAPI TestStream_AddRef(IStream *iface)

Definition at line 414 of file hglobalstream.c.

◆ Test_Stream

IStream Test_Stream = { &StreamVtbl }
static

Definition at line 432 of file hglobalstream.c.

Referenced by test_copyto().