[MSVCRT_WINETEST]
authorChristoph von Wittich <christoph_vw@reactos.org>
Sun, 7 Feb 2010 00:13:49 +0000 (00:13 +0000)
committerChristoph von Wittich <christoph_vw@reactos.org>
Sun, 7 Feb 2010 00:13:49 +0000 (00:13 +0000)
sync msvcrt_winetest to wine 1.1.38

svn path=/trunk/; revision=45478

rostests/winetests/msvcrt/cpp.c
rostests/winetests/msvcrt/file.c
rostests/winetests/msvcrt/misc.c [new file with mode: 0644]
rostests/winetests/msvcrt/msvcrt.rbuild
rostests/winetests/msvcrt/testlist.c

index 106ef73..40e11e1 100644 (file)
@@ -1034,6 +1034,10 @@ static void test_demangle(void)
 /* 113 */ {"?f@T@@QAEHQAY1BE@BO@$$CBD@Z", "public: int __thiscall T::f(char const (* const)[20][30])"},
 /* 114 */ {"??0?$Foo@U?$vector_c@H$00$01$0?1$0A@$0A@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@@mpl@boost@@@@QAE@XZ",
            "public: __thiscall Foo<struct boost::mpl::vector_c<int,1,2,-2,0,0,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647> >::Foo<struct boost::mpl::vector_c<int,1,2,-2,0,0,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647> >(void)"},
 /* 113 */ {"?f@T@@QAEHQAY1BE@BO@$$CBD@Z", "public: int __thiscall T::f(char const (* const)[20][30])"},
 /* 114 */ {"??0?$Foo@U?$vector_c@H$00$01$0?1$0A@$0A@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@$0HPPPPPPP@@mpl@boost@@@@QAE@XZ",
            "public: __thiscall Foo<struct boost::mpl::vector_c<int,1,2,-2,0,0,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647> >::Foo<struct boost::mpl::vector_c<int,1,2,-2,0,0,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647,2147483647> >(void)"},
+/* 115 */ {"?swprintf@@YAHPAGIPBGZZ", "int __cdecl swprintf(unsigned short *,unsigned int,unsigned short const *,...)"},
+/* 116 */ {"?vswprintf@@YAHPAGIPBGPAD@Z", "int __cdecl vswprintf(unsigned short *,unsigned int,unsigned short const *,char *)"},
+/* 117 */ {"?vswprintf@@YAHPA_WIPB_WPAD@Z", "int __cdecl vswprintf(wchar_t *,unsigned int,wchar_t const *,char *)"},
+/* 118 */ {"?swprintf@@YAHPA_WIPB_WZZ", "int __cdecl swprintf(wchar_t *,unsigned int,wchar_t const *,...)"},
 
     };
     int i, num_test = (sizeof(test)/sizeof(test[0]));
 
     };
     int i, num_test = (sizeof(test)/sizeof(test[0]));
index e164555..5afdfcb 100644 (file)
@@ -422,6 +422,35 @@ static WCHAR* AtoW( const char* p )
     return buffer;
 }
 
     return buffer;
 }
 
+/* Test reading in text mode when the 512'th character read is \r*/
+static void test_readboundary(void)
+{
+  FILE *fp;
+  char buf[513], rbuf[513];
+  int i, j;
+  for (i = 0; i < 511; i++)
+    {
+      j = (i%('~' - ' ')+ ' ');
+      buf[i] = j;
+    }
+  buf[511] = '\n';
+  buf[512] =0;
+  fp = fopen("boundary.tst", "wt");
+  fwrite(buf, 512,1,fp);
+  fclose(fp);
+  fp = fopen("boundary.tst", "rt");
+  for(i=0; i<512; i++)
+    {
+      fseek(fp,0 , SEEK_CUR);
+      rbuf[i] = fgetc(fp);
+    }
+  rbuf[512] =0;
+  fclose(fp);
+  unlink("boundary.tst");
+
+  ok(strcmp(buf, rbuf) == 0,"CRLF on buffer boundary failure\n");
+  }
+
 static void test_fgetc( void )
 {
   char* tempf;
 static void test_fgetc( void )
 {
   char* tempf;
@@ -438,6 +467,14 @@ static void test_fgetc( void )
   ret = fgetc(tempfh);
   ok(ich == ret, "Second fgetc expected %x got %x\n", ich, ret);
   fclose(tempfh);
   ret = fgetc(tempfh);
   ok(ich == ret, "Second fgetc expected %x got %x\n", ich, ret);
   fclose(tempfh);
+  tempfh = fopen(tempf,"wt");
+  fputc('\n', tempfh);
+  fclose(tempfh);
+  tempfh = fopen(tempf,"wt");
+  setbuf(tempfh, NULL);
+  ret = fgetc(tempfh);
+  ok(ret == -1, "Unbuffered fgetc in text mode must failed on \\r\\n\n");
+  fclose(tempfh);
   unlink(tempf);
   free(tempf);
 }
   unlink(tempf);
   free(tempf);
 }
@@ -800,15 +837,23 @@ static void test_file_write_read( void )
   tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
   _lseek(tempfd, -1, FILE_END);
   ret = _read(tempfd,btext,LLEN);
   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);
+  ok(ret == 1 && *btext == '\n', "_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);
   _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,1);
+  ok(ret == 1 && *btext == 'e', "_read expected 'e' got \"%.*s\" bad length: %d\n", ret, btext, ret);
+  ok(tell(tempfd) == 41, "bad position %u expecting 41\n", tell(tempfd));
+  _lseek(tempfd, -3, FILE_END);
   ret = _read(tempfd,btext,2);
   ok(ret == 1 && *btext == 'e', "_read expected 'e' got \"%.*s\" bad length: %d\n", ret, btext, ret);
   ok(tell(tempfd) == 42, "bad position %u expecting 42\n", tell(tempfd));
   ret = _read(tempfd,btext,2);
   ok(ret == 1 && *btext == 'e', "_read expected 'e' got \"%.*s\" bad length: %d\n", ret, btext, ret);
   ok(tell(tempfd) == 42, "bad position %u expecting 42\n", tell(tempfd));
-  _close(tempfd);
+  _lseek(tempfd, -3, FILE_END);
+  ret = _read(tempfd,btext,3);
+  ok(ret == 2 && *btext == 'e', "_read expected 'e' got \"%.*s\" bad length: %d\n", ret, btext, ret);
+  ok(tell(tempfd) == 43, "bad position %u expecting 43\n", tell(tempfd));
+   _close(tempfd);
 
   ret = unlink(tempf);
   ok( ret == 0 ,"Can't unlink '%s': %d\n", tempf, errno);
 
   ret = unlink(tempf);
   ok( ret == 0 ,"Can't unlink '%s': %d\n", tempf, errno);
@@ -835,7 +880,23 @@ static void test_file_write_read( void )
       "problems with _O_BINARY _write / _O_TEXT _read\n");
   _close(tempfd);
 
       "problems with _O_BINARY _write / _O_TEXT _read\n");
   _close(tempfd);
 
-   ret =_chmod (tempf, _S_IREAD | _S_IWRITE);
+  /* test _read with single bytes. CR should be skipped and LF pulled in */
+  tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
+  for (i=0; i<strlen(mytext); i++)  /* */
+    {
+      _read(tempfd,btext, 1);
+      ok(btext[0] ==  mytext[i],"_read failed at pos %d 0x%02x vs 0x%02x\n", i, btext[0], mytext[i]);
+    }
+  while (_read(tempfd,btext, 1));
+  _close(tempfd);
+
+  /* test _read in buffered mode. Last CR should be skipped but  LF not pulled in */
+  tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
+  i = _read(tempfd,btext, strlen(mytext));
+  ok(i == strlen(mytext)-1, "_read_i %d vs %d\n", i, strlen(mytext));
+  _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 == 0,
      "Can't chmod '%s' to read-write: %d\n", tempf, errno);
   ret = unlink(tempf);
@@ -1353,6 +1414,11 @@ static void test_unlink(void)
     rmdir("test_unlink");
 }
 
     rmdir("test_unlink");
 }
 
+void test_dup2(void)
+{
+    ok(-1 == _dup2(0, -1), "expected _dup2 to fail when second arg is negative\n" );
+}
+
 START_TEST(file)
 {
     int arg_c;
 START_TEST(file)
 {
     int arg_c;
@@ -1373,6 +1439,7 @@ START_TEST(file)
             ok(0, "invalid argument '%s'\n", arg_v[2]);
         return;
     }
             ok(0, "invalid argument '%s'\n", arg_v[2]);
         return;
     }
+    test_dup2();
     test_file_inherit(arg_v[0]);
     test_file_write_read();
     test_chsize();
     test_file_inherit(arg_v[0]);
     test_file_write_read();
     test_chsize();
@@ -1388,6 +1455,7 @@ START_TEST(file)
     test_asciimode2();
     test_readmode(FALSE); /* binary mode */
     test_readmode(TRUE);  /* ascii mode */
     test_asciimode2();
     test_readmode(FALSE); /* binary mode */
     test_readmode(TRUE);  /* ascii mode */
+    test_readboundary();
     test_fgetc();
     test_fputc();
     test_flsbuf();
     test_fgetc();
     test_fputc();
     test_flsbuf();
diff --git a/rostests/winetests/msvcrt/misc.c b/rostests/winetests/msvcrt/misc.c
new file mode 100644 (file)
index 0000000..1f069fa
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Unit tests for miscellaneous msvcrt functions
+ *
+ * Copyright 2010 Andrew Nguyen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "wine/test.h"
+#include <errno.h>
+
+static int (__cdecl *prand_s)(unsigned int *);
+
+static void init(void)
+{
+    HMODULE hmod = GetModuleHandleA("msvcrt.dll");
+
+    prand_s = (void *)GetProcAddress(hmod, "rand_s");
+}
+
+static void test_rand_s(void)
+{
+    int ret;
+    unsigned int rand;
+
+    if (!prand_s)
+    {
+        win_skip("rand_s is not available\n");
+        return;
+    }
+
+    errno = EBADF;
+    ret = prand_s(NULL);
+    ok(ret == EINVAL, "Expected rand_s to return EINVAL, got %d\n", ret);
+    ok(errno == EINVAL, "Expected errno to return EINVAL, got %d\n", errno);
+
+    ret = prand_s(&rand);
+    ok(ret == 0, "Expected rand_s to return 0, got %d\n", ret);
+}
+
+START_TEST(misc)
+{
+    init();
+
+    test_rand_s();
+}
index 1657252..12c4a53 100644 (file)
@@ -27,6 +27,7 @@
        <file>file.c</file>
        <file>headers.c</file>
        <file>heap.c</file>
        <file>file.c</file>
        <file>headers.c</file>
        <file>heap.c</file>
+       <file>misc.c</file>
        <file>printf.c</file>
        <file>scanf.c</file>
        <file>signal.c</file>
        <file>printf.c</file>
        <file>scanf.c</file>
        <file>signal.c</file>
index 4bd436d..80259df 100644 (file)
@@ -13,6 +13,7 @@ extern void func_environ(void);
 extern void func_file(void);
 extern void func_headers(void);
 extern void func_heap(void);
 extern void func_file(void);
 extern void func_headers(void);
 extern void func_heap(void);
+extern void func_misc(void);
 extern void func_printf(void);
 extern void func_scanf(void);
 extern void func_signal(void);
 extern void func_printf(void);
 extern void func_scanf(void);
 extern void func_signal(void);
@@ -28,6 +29,7 @@ const struct test winetest_testlist[] =
     { "file", func_file },
     { "headers", func_headers },
     { "heap", func_heap },
     { "file", func_file },
     { "headers", func_headers },
     { "heap", func_heap },
+    { "misc", func_misc },
     { "printf", func_printf },
     { "scanf", func_scanf },
        { "signal", func_signal },
     { "printf", func_printf },
     { "scanf", func_scanf },
        { "signal", func_signal },