msvcrt: Added fputwc tests.

This commit is contained in:
Piotr Caban 2013-01-11 11:18:57 +01:00 committed by Alexandre Julliard
parent ebfa653618
commit 77f3ce0b10
1 changed files with 58 additions and 0 deletions

View File

@ -792,6 +792,63 @@ static void test_fgetwc( void )
free(tempf);
}
static void test_fputwc(void)
{
char temppath[MAX_PATH];
char tempfile[MAX_PATH];
FILE *f;
char buf[1024];
int ret;
GetTempPath (MAX_PATH, temppath);
GetTempFileName (temppath, "", 0, tempfile);
f = fopen(tempfile, "w");
ret = fputwc('a', f);
ok(ret == 'a', "fputwc returned %x, expected 'a'\n", ret);
ret = fputwc('\n', f);
ok(ret == '\n', "fputwc returned %x, expected '\\n'\n", ret);
fclose(f);
f = fopen(tempfile, "rb");
ret = fread(buf, 1, sizeof(buf), f);
ok(ret == 3, "fread returned %d, expected 3\n", ret);
ok(!memcmp(buf, "a\r\n", 3), "incorrect file data\n");
fclose(f);
if(p_fopen_s) {
f = fopen(tempfile, "w,ccs=unicode");
ret = fputwc('a', f);
ok(ret == 'a', "fputwc returned %x, expected 'a'\n", ret);
ret = fputwc('\n', f);
ok(ret == '\n', "fputwc returned %x, expected '\\n'\n", ret);
fclose(f);
f = fopen(tempfile, "rb");
ret = fread(buf, 1, sizeof(buf), f);
ok(ret == 8, "fread returned %d, expected 8\n", ret);
ok(!memcmp(buf, "\xff\xfe\x61\x00\r\x00\n\x00", 8), "incorrect file data\n");
fclose(f);
f = fopen(tempfile, "w,ccs=utf-8");
ret = fputwc('a', f);
ok(ret == 'a', "fputwc returned %x, expected 'a'\n", ret);
ret = fputwc('\n', f);
ok(ret == '\n', "fputwc returned %x, expected '\\n'\n", ret);
fclose(f);
f = fopen(tempfile, "rb");
ret = fread(buf, 1, sizeof(buf), f);
ok(ret == 6, "fread returned %d, expected 6\n", ret);
ok(!memcmp(buf, "\xef\xbb\xbf\x61\r\n", 6), "incorrect file data\n");
fclose(f);
}else {
win_skip("fputwc tests on unicode files\n");
}
_unlink(tempfile);
}
static void test_ctrlz( void )
{
char* tempf;
@ -1955,6 +2012,7 @@ START_TEST(file)
test_flsbuf();
test_fflush();
test_fgetwc();
test_fputwc();
test_ctrlz();
test_file_put_get();
test_tmpnam();