Commit 038438ad authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

scrrun: Implemented AtEndOfStream() property.

parent 18c350ae
......@@ -111,6 +111,7 @@ struct textstream {
IOMode mode;
BOOL unicode;
BOOL first_write;
LARGE_INTEGER size;
HANDLE file;
};
......@@ -332,8 +333,24 @@ static HRESULT WINAPI textstream_get_Column(ITextStream *iface, LONG *column)
static HRESULT WINAPI textstream_get_AtEndOfStream(ITextStream *iface, VARIANT_BOOL *eos)
{
struct textstream *This = impl_from_ITextStream(iface);
FIXME("(%p)->(%p): stub\n", This, eos);
return E_NOTIMPL;
LARGE_INTEGER pos, dist;
TRACE("(%p)->(%p)\n", This, eos);
if (!eos)
return E_POINTER;
if (textstream_check_iomode(This, IORead)) {
*eos = VARIANT_TRUE;
return CTL_E_BADFILEMODE;
}
dist.QuadPart = 0;
if (!SetFilePointerEx(This->file, dist, &pos, FILE_CURRENT))
return E_FAIL;
*eos = This->size.QuadPart == pos.QuadPart ? VARIANT_TRUE : VARIANT_FALSE;
return S_OK;
}
static HRESULT WINAPI textstream_get_AtEndOfLine(ITextStream *iface, VARIANT_BOOL *eol)
......@@ -548,6 +565,11 @@ static HRESULT create_textstream(const WCHAR *filename, DWORD disposition, IOMod
return hr;
}
if (mode == ForReading)
GetFileSizeEx(stream->file, &stream->size);
else
stream->size.QuadPart = 0;
*ret = &stream->ITextStream_iface;
return S_OK;
}
......
......@@ -154,9 +154,11 @@ static void test_textstream(void)
static const WCHAR testfileW[] = {'t','e','s','t','f','i','l','e','.','t','x','t',0};
ITextStream *stream;
VARIANT_BOOL b;
DWORD written;
HANDLE file;
HRESULT hr;
BSTR name, data;
BOOL ret;
file = CreateFileW(testfileW, GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(file);
......@@ -199,12 +201,14 @@ static void test_textstream(void)
hr = ITextStream_Write(stream, name);
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
hr = ITextStream_get_AtEndOfStream(stream, NULL);
ok(hr == E_POINTER, "got 0x%08x\n", hr);
b = 10;
hr = ITextStream_get_AtEndOfStream(stream, &b);
todo_wine {
ok(hr == S_FALSE || broken(hr == S_OK), "got 0x%08x\n", hr);
ok(hr == S_OK || broken(hr == S_FALSE), "got 0x%08x\n", hr);
ok(b == VARIANT_TRUE, "got 0x%x\n", b);
}
ITextStream_Release(stream);
hr = IFileSystem3_OpenTextFile(fs3, name, ForWriting, VARIANT_FALSE, TristateFalse, &stream);
......@@ -212,10 +216,9 @@ todo_wine {
b = 10;
hr = ITextStream_get_AtEndOfStream(stream, &b);
todo_wine {
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
ok(b == VARIANT_TRUE || broken(b == 10), "got 0x%x\n", b);
}
b = 10;
hr = ITextStream_get_AtEndOfLine(stream, &b);
todo_wine {
......@@ -235,14 +238,12 @@ todo_wine {
hr = IFileSystem3_OpenTextFile(fs3, name, ForAppending, VARIANT_FALSE, TristateFalse, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
SysFreeString(name);
b = 10;
hr = ITextStream_get_AtEndOfStream(stream, &b);
todo_wine {
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
ok(b == VARIANT_TRUE || broken(b == 10), "got 0x%x\n", b);
}
b = 10;
hr = ITextStream_get_AtEndOfLine(stream, &b);
todo_wine {
......@@ -260,6 +261,21 @@ todo_wine {
ITextStream_Release(stream);
/* now with non-empty file */
file = CreateFileW(testfileW, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
ret = WriteFile(file, testfileW, sizeof(testfileW), &written, NULL);
ok(ret && written == sizeof(testfileW), "got %d\n", ret);
CloseHandle(file);
hr = IFileSystem3_OpenTextFile(fs3, name, ForReading, VARIANT_FALSE, TristateFalse, &stream);
ok(hr == S_OK, "got 0x%08x\n", hr);
b = 10;
hr = ITextStream_get_AtEndOfStream(stream, &b);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(b == VARIANT_FALSE, "got 0x%x\n", b);
ITextStream_Release(stream);
SysFreeString(name);
DeleteFileW(testfileW);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment