MSVCRT/tests: no-op cleanup
Saulius Krasuckas
saulius2 at ar.fi.lt
Mon Nov 14 11:29:09 CST 2005
Log message:
Saulius Krasuckas <saulius.krasuckas at ieee.org>
- Rearrange tests so they can be split into two categories
(low-level and stream I/O).
- Use 4 spaces indentation.
Index: dlls/msvcrt/tests/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/tests/file.c,v
retrieving revision 1.19
diff -p -u -d -r1.19 file.c
--- dlls/msvcrt/tests/file.c 10 Oct 2005 10:29:24 -0000 1.19
+++ dlls/msvcrt/tests/file.c 14 Nov 2005 16:11:12 -0000
@@ -32,6 +32,191 @@
#include <process.h>
#include <errno.h>
+#define LLEN 512
+
+
+/* testing low-level I/O */
+
+static void test_file_write_read( void )
+{
+ char* tempf;
+ int tempfd;
+ static const char mytext[]= "This is test_file_write_read\nsecond line\n";
+ static const char dostext[]= "This is test_file_write_read\r\nsecond line\r\n";
+ char btext[LLEN];
+ int ret;
+
+ tempf=_tempnam(".","wne");
+ tempfd = _open(tempf,_O_CREAT|_O_TRUNC|_O_TEXT|_O_RDWR,
+ _S_IREAD | _S_IWRITE);
+ ok( tempfd != -1,
+ "Can't open '%s': %d\n", tempf, errno); /* open in TEXT mode */
+ ok(_write(tempfd,mytext,strlen(mytext)) == lstrlenA(mytext),
+ "_write _O_TEXT bad return value\n");
+ _close(tempfd);
+ tempfd = _open(tempf,_O_RDONLY|_O_BINARY,0); /* open in BINARY mode */
+ ok(_read(tempfd,btext,LLEN) == lstrlenA(dostext),
+ "_read _O_BINARY got bad length\n");
+ ok( memcmp(dostext,btext,strlen(dostext)) == 0,
+ "problems with _O_TEXT _write / _O_BINARY _read\n");
+ ok( btext[strlen(dostext)-2] == '\r', "CR not written or read\n");
+ _close(tempfd);
+ tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
+ ok(_read(tempfd,btext,LLEN) == lstrlenA(mytext),
+ "_read _O_TEXT got bad length\n");
+ ok( memcmp(mytext,btext,strlen(mytext)) == 0,
+ "problems with _O_TEXT _write / _read\n");
+ _close(tempfd);
+
+ memset(btext, 0, LLEN);
+ tempfd = _open(tempf,_O_APPEND|_O_RDWR); /* open for APPEND in default mode */
+ ok(tell(tempfd) == 0, "bad position %lu expecting 0\n", tell(tempfd));
+ ok(_read(tempfd,btext,LLEN) == lstrlenA(mytext), "_read _O_APPEND got bad length\n");
+ ok( memcmp(mytext,btext,strlen(mytext)) == 0, "problems with _O_APPEND _read\n");
+ _close(tempfd);
+
+ /* Test reading only \n or \r */
+ tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
+ _lseek(tempfd, -1, FILE_END);
+ ret = _read(tempfd,btext,LLEN);
+ ok(ret == 1, "_read expected 1 got bad length: %d\n", ret);
+ _lseek(tempfd, -2, FILE_END);
+ ret = _read(tempfd,btext,LLEN);
+ ok(ret == 1 && *btext == '\n', "_read expected '\\n' got bad length: %d\n", ret);
+ _lseek(tempfd, -3, FILE_END);
+ ret = _read(tempfd,btext,2);
+ todo_wine ok(ret == 1 && *btext == 'e',
+ "_read expected 'e' got \"%.*s\" bad length: %d\n", ret, btext, ret);
+ todo_wine ok(tell(tempfd) == 42, "bad position %lu expecting 42\n", tell(tempfd));
+ _close(tempfd);
+
+ ret = unlink(tempf);
+ ok( ret !=-1 ,"Can't unlink '%s': %d\n", tempf, errno);
+
+ tempf=_tempnam(".","wne");
+ tempfd = _open(tempf,_O_CREAT|_O_TRUNC|_O_BINARY|_O_RDWR,0);
+ ok( tempfd != -1,
+ "Can't open '%s': %d\n", tempf, errno); /* open in BINARY mode */
+ ok(_write(tempfd,dostext,strlen(dostext)) == lstrlenA(dostext),
+ "_write _O_BINARY bad return value\n");
+ _close(tempfd);
+ tempfd = _open(tempf,_O_RDONLY|_O_BINARY,0); /* open in BINARY mode */
+ ok(_read(tempfd,btext,LLEN) == lstrlenA(dostext),
+ "_read _O_BINARY got bad length\n");
+ ok( memcmp(dostext,btext,strlen(dostext)) == 0,
+ "problems with _O_BINARY _write / _read\n");
+ ok( btext[strlen(dostext)-2] == '\r', "CR not written or read\n");
+ _close(tempfd);
+ tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
+ ok(_read(tempfd,btext,LLEN) == lstrlenA(mytext),
+ "_read _O_TEXT got bad length\n");
+ ok( memcmp(mytext,btext,strlen(mytext)) == 0,
+ "problems with _O_BINARY _write / _O_TEXT _read\n");
+ _close(tempfd);
+
+ ret =_chmod (tempf, _S_IREAD | _S_IWRITE);
+ ok( ret == 0,
+ "Can't chmod '%s' to read-write: %d\n", tempf, errno);
+ ret = unlink(tempf);
+ ok( ret !=-1 ,"Can't unlink '%s': %d\n", tempf, errno);
+}
+
+static void test_file_inherit_child(const char* fd_s)
+{
+ int fd = atoi(fd_s);
+ char buffer[32];
+ int ret;
+
+ ret =write(fd, "Success", 8);
+ ok( ret == 8, "Couldn't write in child process on %d (%s)\n", fd, strerror(errno));
+ lseek(fd, 0, SEEK_SET);
+ ok(read(fd, buffer, sizeof (buffer)) == 8, "Couldn't read back the data\n");
+ ok(memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n");
+}
+
+static void test_file_inherit_child_no(const char* fd_s)
+{
+ int fd = atoi(fd_s);
+ int ret;
+
+ ret = write(fd, "Success", 8);
+ ok( ret == -1 && errno == EBADF,
+ "Wrong write result in child process on %d (%s)\n", fd, strerror(errno));
+}
+
+static void test_file_inherit( const char* selfname )
+{
+ int fd;
+ const char* arg_v[5];
+ char buffer[16];
+
+ fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE);
+ ok(fd != -1, "Couldn't create test file\n");
+ arg_v[0] = selfname;
+ arg_v[1] = "tests/file.c";
+ arg_v[2] = buffer; sprintf(buffer, "%d", fd);
+ arg_v[3] = 0;
+ _spawnvp(_P_WAIT, selfname, arg_v);
+ ok(tell(fd) == 8, "bad position %lu expecting 8\n", tell(fd));
+ lseek(fd, 0, SEEK_SET);
+ ok(read(fd, buffer, sizeof (buffer)) == 8 && memcmp(buffer, "Success", 8) == 0,
+ "Couldn't read back the data\n");
+ close (fd);
+ ok(unlink("fdopen.tst") != 1, "Couldn't unlink\n");
+
+ fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY | O_NOINHERIT, _S_IREAD |_S_IWRITE);
+ ok(fd != -1, "Couldn't create test file\n");
+ arg_v[0] = selfname;
+ arg_v[1] = "tests/file.c";
+ arg_v[2] = buffer; sprintf(buffer, "%d", fd);
+ arg_v[3] = buffer;
+ arg_v[4] = 0;
+ _spawnvp(_P_WAIT, selfname, arg_v);
+ ok(tell(fd) == 0, "bad position %lu expecting 0\n", tell(fd));
+ ok(read(fd, buffer, sizeof (buffer)) == 0, "Found unexpected data (%s)\n", buffer);
+ close (fd);
+ ok(unlink("fdopen.tst") != 1, "Couldn't unlink\n");
+}
+
+static void test_chsize( void )
+{
+ int fd;
+ long cur, pos, count;
+ char temptext[] = "012345678";
+ char *tempfile = _tempnam( ".", "tst" );
+
+ ok( tempfile != NULL, "Couldn't create test file: %s\n", tempfile );
+
+ fd = _open( tempfile, _O_CREAT|_O_TRUNC|_O_RDWR, _S_IREAD|_S_IWRITE );
+ ok( fd > 0, "Couldn't open test file\n" );
+
+ count = _write( fd, temptext, sizeof(temptext) );
+ ok( count > 0, "Couldn't write to test file\n" );
+
+ /* get current file pointer */
+ cur = _lseek( fd, 0, SEEK_CUR );
+
+ /* make the file smaller */
+ ok( _chsize( fd, sizeof(temptext) / 2 ) == 0, "_chsize() failed\n" );
+
+ pos = _lseek( fd, 0, SEEK_CUR );
+ ok( cur == pos, "File pointer changed from: %ld to: %ld\n", cur, pos );
+ ok( _filelength( fd ) == sizeof(temptext) / 2, "Wrong file size\n" );
+
+ /* enlarge the file */
+ ok( _chsize( fd, sizeof(temptext) * 2 ) == 0, "_chsize() failed\n" );
+
+ pos = _lseek( fd, 0, SEEK_CUR );
+ ok( cur == pos, "File pointer changed from: %ld to: %ld\n", cur, pos );
+ ok( _filelength( fd ) == sizeof(temptext) * 2, "Wrong file size\n" );
+
+ _close( fd );
+ _unlink( tempfile );
+}
+
+
+/* testing stream I/O */
+
static void test_fdopen( void )
{
static const char buffer[] = {0,1,2,3,4,5,6,7,8,9};
@@ -133,277 +318,100 @@ static WCHAR* AtoW( char* p )
static void test_fgetwc( void )
{
-#define LLEN 512
-
- char* tempf;
- FILE *tempfh;
- static const char mytext[]= "This is test_fgetwc\n";
- WCHAR wtextW[LLEN+1];
- WCHAR *mytextW = NULL, *aptr, *wptr;
- BOOL diff_found = FALSE;
- unsigned int i;
+ char* tempf;
+ FILE *tempfh;
+ static const char mytext[]= "This is test_fgetwc\n";
+ WCHAR wtextW[LLEN+1];
+ WCHAR *mytextW = NULL, *aptr, *wptr;
+ BOOL diff_found = FALSE;
+ unsigned int i;
- tempf=_tempnam(".","wne");
- tempfh = fopen(tempf,"wt"); /* open in TEXT mode */
- fputs(mytext,tempfh);
- fclose(tempfh);
- tempfh = fopen(tempf,"rt");
- fgetws(wtextW,LLEN,tempfh);
- mytextW = AtoW ((char*)mytext);
- aptr = mytextW;
- wptr = wtextW;
+ tempf=_tempnam(".","wne");
+ tempfh = fopen(tempf,"wt"); /* open in TEXT mode */
+ fputs(mytext,tempfh);
+ fclose(tempfh);
+ tempfh = fopen(tempf,"rt");
+ fgetws(wtextW,LLEN,tempfh);
+ mytextW = AtoW ((char*)mytext);
+ aptr = mytextW;
+ wptr = wtextW;
- for (i=0; i<strlen(mytext); i++, aptr++, wptr++)
+ for (i=0; i<strlen(mytext); i++, aptr++, wptr++)
{
- diff_found |= (*aptr != *wptr);
+ diff_found |= (*aptr != *wptr);
}
- ok(!(diff_found), "fgetwc difference found in TEXT mode\n");
- if(mytextW) free (mytextW);
- fclose(tempfh);
- unlink(tempf);
+ ok(!(diff_found), "fgetwc difference found in TEXT mode\n");
+ if(mytextW) free (mytextW);
+ fclose(tempfh);
+ unlink(tempf);
}
static void test_file_put_get( void )
{
- char* tempf;
- FILE *tempfh;
- static const char mytext[]= "This is a test_file_put_get\n";
- static const char dostext[]= "This is a test_file_put_get\r\n";
- char btext[LLEN];
- WCHAR wtextW[LLEN+1];
- WCHAR *mytextW = NULL, *aptr, *wptr;
- BOOL diff_found = FALSE;
- unsigned int i;
+ char* tempf;
+ FILE *tempfh;
+ static const char mytext[]= "This is a test_file_put_get\n";
+ static const char dostext[]= "This is a test_file_put_get\r\n";
+ char btext[LLEN];
+ WCHAR wtextW[LLEN+1];
+ WCHAR *mytextW = NULL, *aptr, *wptr;
+ BOOL diff_found = FALSE;
+ unsigned int i;
- tempf=_tempnam(".","wne");
- tempfh = fopen(tempf,"wt"); /* open in TEXT mode */
- fputs(mytext,tempfh);
- fclose(tempfh);
- tempfh = fopen(tempf,"rb"); /* open in TEXT mode */
- fgets(btext,LLEN,tempfh);
- ok( strlen(mytext) + 1 == strlen(btext),"TEXT/BINARY mode not handled for write\n");
- ok( btext[strlen(mytext)-1] == '\r', "CR not written\n");
- fclose(tempfh);
- tempfh = fopen(tempf,"wb"); /* open in BINARY mode */
- fputs(dostext,tempfh);
- fclose(tempfh);
- tempfh = fopen(tempf,"rt"); /* open in TEXT mode */
- fgets(btext,LLEN,tempfh);
- ok(strcmp(btext, mytext) == 0,"_O_TEXT read doesn't strip CR\n");
- fclose(tempfh);
- tempfh = fopen(tempf,"rb"); /* open in TEXT mode */
- fgets(btext,LLEN,tempfh);
- ok(strcmp(btext, dostext) == 0,"_O_BINARY read doesn't preserve CR\n");
+ tempf=_tempnam(".","wne");
+ tempfh = fopen(tempf,"wt"); /* open in TEXT mode */
+ fputs(mytext,tempfh);
+ fclose(tempfh);
+ tempfh = fopen(tempf,"rb"); /* open in TEXT mode */
+ fgets(btext,LLEN,tempfh);
+ ok( strlen(mytext) + 1 == strlen(btext),"TEXT/BINARY mode not handled for write\n");
+ ok( btext[strlen(mytext)-1] == '\r', "CR not written\n");
+ fclose(tempfh);
+ tempfh = fopen(tempf,"wb"); /* open in BINARY mode */
+ fputs(dostext,tempfh);
+ fclose(tempfh);
+ tempfh = fopen(tempf,"rt"); /* open in TEXT mode */
+ fgets(btext,LLEN,tempfh);
+ ok(strcmp(btext, mytext) == 0,"_O_TEXT read doesn't strip CR\n");
+ fclose(tempfh);
+ tempfh = fopen(tempf,"rb"); /* open in TEXT mode */
+ fgets(btext,LLEN,tempfh);
+ ok(strcmp(btext, dostext) == 0,"_O_BINARY read doesn't preserve CR\n");
- fclose(tempfh);
- tempfh = fopen(tempf,"rt"); /* open in TEXT mode */
- fgetws(wtextW,LLEN,tempfh);
- mytextW = AtoW ((char*)mytext);
- aptr = mytextW;
- wptr = wtextW;
+ fclose(tempfh);
+ tempfh = fopen(tempf,"rt"); /* open in TEXT mode */
+ fgetws(wtextW,LLEN,tempfh);
+ mytextW = AtoW ((char*)mytext);
+ aptr = mytextW;
+ wptr = wtextW;
- for (i=0; i<strlen(mytext); i++, aptr++, wptr++)
+ for (i=0; i<strlen(mytext); i++, aptr++, wptr++)
{
- diff_found |= (*aptr != *wptr);
+ diff_found |= (*aptr != *wptr);
}
- ok(!(diff_found), "fgetwc doesn't strip CR in TEXT mode\n");
- if(mytextW) free (mytextW);
- fclose(tempfh);
- unlink(tempf);
-}
-
-static void test_file_write_read( void )
-{
- char* tempf;
- int tempfd;
- static const char mytext[]= "This is test_file_write_read\nsecond line\n";
- static const char dostext[]= "This is test_file_write_read\r\nsecond line\r\n";
- char btext[LLEN];
- int ret;
-
- tempf=_tempnam(".","wne");
- tempfd = _open(tempf,_O_CREAT|_O_TRUNC|_O_TEXT|_O_RDWR,
- _S_IREAD | _S_IWRITE);
- ok( tempfd != -1,
- "Can't open '%s': %d\n", tempf, errno); /* open in TEXT mode */
- ok(_write(tempfd,mytext,strlen(mytext)) == lstrlenA(mytext),
- "_write _O_TEXT bad return value\n");
- _close(tempfd);
- tempfd = _open(tempf,_O_RDONLY|_O_BINARY,0); /* open in BINARY mode */
- ok(_read(tempfd,btext,LLEN) == lstrlenA(dostext),
- "_read _O_BINARY got bad length\n");
- ok( memcmp(dostext,btext,strlen(dostext)) == 0,
- "problems with _O_TEXT _write / _O_BINARY _read\n");
- ok( btext[strlen(dostext)-2] == '\r', "CR not written or read\n");
- _close(tempfd);
- tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
- ok(_read(tempfd,btext,LLEN) == lstrlenA(mytext),
- "_read _O_TEXT got bad length\n");
- ok( memcmp(mytext,btext,strlen(mytext)) == 0,
- "problems with _O_TEXT _write / _read\n");
- _close(tempfd);
-
- memset(btext, 0, LLEN);
- tempfd = _open(tempf,_O_APPEND|_O_RDWR); /* open for APPEND in default mode */
- ok(tell(tempfd) == 0, "bad position %lu expecting 0\n", tell(tempfd));
- ok(_read(tempfd,btext,LLEN) == lstrlenA(mytext), "_read _O_APPEND got bad length\n");
- ok( memcmp(mytext,btext,strlen(mytext)) == 0, "problems with _O_APPEND _read\n");
- _close(tempfd);
-
- /* Test reading only \n or \r */
- tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
- _lseek(tempfd, -1, FILE_END);
- ret = _read(tempfd,btext,LLEN);
- ok(ret == 1, "_read expected 1 got bad length: %d\n", ret);
- _lseek(tempfd, -2, FILE_END);
- ret = _read(tempfd,btext,LLEN);
- ok(ret == 1 && *btext == '\n', "_read expected '\\n' got bad length: %d\n", ret);
- _lseek(tempfd, -3, FILE_END);
- ret = _read(tempfd,btext,2);
- todo_wine ok(ret == 1 && *btext == 'e', "_read expected 'e' got \"%.*s\" bad length: %d\n", ret, btext, ret);
- todo_wine ok(tell(tempfd) == 42, "bad position %lu expecting 42\n", tell(tempfd));
- _close(tempfd);
-
- ret = unlink(tempf);
- ok( ret !=-1 ,"Can't unlink '%s': %d\n", tempf, errno);
-
- tempf=_tempnam(".","wne");
- tempfd = _open(tempf,_O_CREAT|_O_TRUNC|_O_BINARY|_O_RDWR,0);
- ok( tempfd != -1,
- "Can't open '%s': %d\n", tempf, errno); /* open in BINARY mode */
- ok(_write(tempfd,dostext,strlen(dostext)) == lstrlenA(dostext),
- "_write _O_BINARY bad return value\n");
- _close(tempfd);
- tempfd = _open(tempf,_O_RDONLY|_O_BINARY,0); /* open in BINARY mode */
- ok(_read(tempfd,btext,LLEN) == lstrlenA(dostext),
- "_read _O_BINARY got bad length\n");
- ok( memcmp(dostext,btext,strlen(dostext)) == 0,
- "problems with _O_BINARY _write / _read\n");
- ok( btext[strlen(dostext)-2] == '\r', "CR not written or read\n");
- _close(tempfd);
- tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
- ok(_read(tempfd,btext,LLEN) == lstrlenA(mytext),
- "_read _O_TEXT got bad length\n");
- ok( memcmp(mytext,btext,strlen(mytext)) == 0,
- "problems with _O_BINARY _write / _O_TEXT _read\n");
- _close(tempfd);
-
- ret =_chmod (tempf, _S_IREAD | _S_IWRITE);
- ok( ret == 0,
- "Can't chmod '%s' to read-write: %d\n", tempf, errno);
- ret = unlink(tempf);
- ok( ret !=-1 ,"Can't unlink '%s': %d\n", tempf, errno);
-}
-
-static void test_file_inherit_child(const char* fd_s)
-{
- int fd = atoi(fd_s);
- char buffer[32];
- int ret;
-
- ret =write(fd, "Success", 8);
- ok( ret == 8, "Couldn't write in child process on %d (%s)\n", fd, strerror(errno));
- lseek(fd, 0, SEEK_SET);
- ok(read(fd, buffer, sizeof (buffer)) == 8, "Couldn't read back the data\n");
- ok(memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n");
-}
-
-static void test_file_inherit_child_no(const char* fd_s)
-{
- int fd = atoi(fd_s);
- int ret;
-
- ret = write(fd, "Success", 8);
- ok( ret == -1 && errno == EBADF,
- "Wrong write result in child process on %d (%s)\n", fd, strerror(errno));
-}
-
-static void test_file_inherit( const char* selfname )
-{
- int fd;
- const char* arg_v[5];
- char buffer[16];
-
- fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE);
- ok(fd != -1, "Couldn't create test file\n");
- arg_v[0] = selfname;
- arg_v[1] = "tests/file.c";
- arg_v[2] = buffer; sprintf(buffer, "%d", fd);
- arg_v[3] = 0;
- _spawnvp(_P_WAIT, selfname, arg_v);
- ok(tell(fd) == 8, "bad position %lu expecting 8\n", tell(fd));
- lseek(fd, 0, SEEK_SET);
- ok(read(fd, buffer, sizeof (buffer)) == 8 && memcmp(buffer, "Success", 8) == 0, "Couldn't read back the data\n");
- close (fd);
- ok(unlink("fdopen.tst") != 1, "Couldn't unlink\n");
-
- fd = open ("fdopen.tst", O_CREAT | O_RDWR | O_BINARY | O_NOINHERIT, _S_IREAD |_S_IWRITE);
- ok(fd != -1, "Couldn't create test file\n");
- arg_v[0] = selfname;
- arg_v[1] = "tests/file.c";
- arg_v[2] = buffer; sprintf(buffer, "%d", fd);
- arg_v[3] = buffer;
- arg_v[4] = 0;
- _spawnvp(_P_WAIT, selfname, arg_v);
- ok(tell(fd) == 0, "bad position %lu expecting 0\n", tell(fd));
- ok(read(fd, buffer, sizeof (buffer)) == 0, "Found unexpected data (%s)\n", buffer);
- close (fd);
- ok(unlink("fdopen.tst") != 1, "Couldn't unlink\n");
+ ok(!(diff_found), "fgetwc doesn't strip CR in TEXT mode\n");
+ if(mytextW) free (mytextW);
+ fclose(tempfh);
+ unlink(tempf);
}
static void test_tmpnam( void )
{
- char name[MAX_PATH] = "abc";
- char *res;
-
- res = tmpnam(NULL);
- ok(res != NULL, "tmpnam returned NULL\n");
- ok(res[0] == '\\', "first character is not a backslash\n");
- ok(strchr(res+1, '\\') == 0, "file not in the root directory\n");
- ok(res[strlen(res)-1] == '.', "first call - last character is not a dot\n");
-
- res = tmpnam(name);
- ok(res != NULL, "tmpnam returned NULL\n");
- ok(res == name, "supplied buffer was not used\n");
- ok(res[0] == '\\', "first character is not a backslash\n");
- ok(strchr(res+1, '\\') == 0, "file not in the root directory\n");
- ok(res[strlen(res)-1] != '.', "second call - last character is a dot\n");
-}
-
-static void test_chsize( void )
-{
- int fd;
- long cur, pos, count;
- char temptext[] = "012345678";
- char *tempfile = _tempnam( ".", "tst" );
-
- ok( tempfile != NULL, "Couldn't create test file: %s\n", tempfile );
-
- fd = _open( tempfile, _O_CREAT|_O_TRUNC|_O_RDWR, _S_IREAD|_S_IWRITE );
- ok( fd > 0, "Couldn't open test file\n" );
-
- count = _write( fd, temptext, sizeof(temptext) );
- ok( count > 0, "Couldn't write to test file\n" );
-
- /* get current file pointer */
- cur = _lseek( fd, 0, SEEK_CUR );
-
- /* make the file smaller */
- ok( _chsize( fd, sizeof(temptext) / 2 ) == 0, "_chsize() failed\n" );
-
- pos = _lseek( fd, 0, SEEK_CUR );
- ok( cur == pos, "File pointer changed from: %ld to: %ld\n", cur, pos );
- ok( _filelength( fd ) == sizeof(temptext) / 2, "Wrong file size\n" );
-
- /* enlarge the file */
- ok( _chsize( fd, sizeof(temptext) * 2 ) == 0, "_chsize() failed\n" );
+ char name[MAX_PATH] = "abc";
+ char *res;
- pos = _lseek( fd, 0, SEEK_CUR );
- ok( cur == pos, "File pointer changed from: %ld to: %ld\n", cur, pos );
- ok( _filelength( fd ) == sizeof(temptext) * 2, "Wrong file size\n" );
+ res = tmpnam(NULL);
+ ok(res != NULL, "tmpnam returned NULL\n");
+ ok(res[0] == '\\', "first character is not a backslash\n");
+ ok(strchr(res+1, '\\') == 0, "file not in the root directory\n");
+ ok(res[strlen(res)-1] == '.', "first call - last character is not a dot\n");
- _close( fd );
- _unlink( tempfile );
+ res = tmpnam(name);
+ ok(res != NULL, "tmpnam returned NULL\n");
+ ok(res == name, "supplied buffer was not used\n");
+ ok(res[0] == '\\', "first character is not a backslash\n");
+ ok(strchr(res+1, '\\') == 0, "file not in the root directory\n");
+ ok(res[strlen(res)-1] != '.', "second call - last character is a dot\n");
}
START_TEST(file)
@@ -413,18 +421,22 @@ START_TEST(file)
arg_c = winetest_get_mainargs( &arg_v );
+ /* testing low-level I/O */
if (arg_c >= 3)
{
- if (arg_c == 3) test_file_inherit_child(arg_v[2]); else test_file_inherit_child_no(arg_v[2]);
+ if (arg_c == 3) test_file_inherit_child(arg_v[2]);
+ else test_file_inherit_child_no(arg_v[2]);
return;
}
+ test_file_inherit(arg_v[0]);
+ test_file_write_read();
+ test_chsize();
+
+ /* testing stream I/O */
test_fdopen();
test_fileops();
test_fgetwc();
test_file_put_get();
- test_file_write_read();
- test_file_inherit(arg_v[0]);
test_tmpnam();
- test_chsize();
}
More information about the wine-patches
mailing list