Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 1 | /* |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 2 | * Unit tests for file functions in Wine |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 3 | * |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 4 | * Copyright (c) 2002, 2004 Jakob Eriksson |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 19 | * |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 22 | #include <stdarg.h> |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 23 | #include <stdlib.h> |
| 24 | #include <time.h> |
| 25 | |
Francois Gouget | 4c31400 | 2002-05-23 02:40:07 +0000 | [diff] [blame] | 26 | #include "wine/test.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 27 | #include "windef.h" |
Francois Gouget | 4c31400 | 2002-05-23 02:40:07 +0000 | [diff] [blame] | 28 | #include "winbase.h" |
| 29 | #include "winerror.h" |
| 30 | |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 31 | static int dll_capable(const char *dll, const char *function) |
| 32 | { |
| 33 | HMODULE module = GetModuleHandleA(dll); |
| 34 | if (!module) return 0; |
| 35 | |
| 36 | return (GetProcAddress(module, function) != NULL); |
| 37 | } |
| 38 | |
| 39 | |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 40 | LPCSTR filename = "testfile.xxx"; |
| 41 | LPCSTR sillytext = |
| 42 | "en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bl\na.. bla bla." |
| 43 | "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3" |
| 44 | "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3" |
| 45 | "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3" |
| 46 | "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3" |
| 47 | "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3" |
| 48 | "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3" |
| 49 | "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3" |
| 50 | "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3" |
| 51 | "sdlkfjasdlkfj a dslkj adsklf \n \nasdklf askldfa sdlkf \nsadklf asdklf asdf "; |
| 52 | |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 53 | |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 54 | static void test__hread( void ) |
| 55 | { |
| 56 | HFILE filehandle; |
| 57 | char buffer[10000]; |
| 58 | long bytes_read; |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 59 | long bytes_wanted; |
Francois Gouget | 45d2613 | 2002-12-18 02:22:51 +0000 | [diff] [blame] | 60 | long i; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 61 | BOOL ret; |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 62 | |
Alexandre Julliard | 034e39b | 2002-06-05 00:47:38 +0000 | [diff] [blame] | 63 | SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL); /* be sure to remove stale files */ |
| 64 | DeleteFileA( filename ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 65 | filehandle = _lcreat( filename, 0 ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 66 | if (filehandle == HFILE_ERROR) |
| 67 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 68 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 69 | return; |
| 70 | } |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 71 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 72 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 73 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 74 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 75 | |
| 76 | filehandle = _lopen( filename, OF_READ ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 77 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 78 | ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError( ) ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 79 | |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 80 | bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 81 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 82 | ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 83 | |
Francois Gouget | 45d2613 | 2002-12-18 02:22:51 +0000 | [diff] [blame] | 84 | for (bytes_wanted = 0; bytes_wanted < lstrlenA( sillytext ); bytes_wanted++) |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 85 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 86 | ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" ); |
| 87 | ok( _hread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 88 | for (i = 0; i < bytes_wanted; i++) |
| 89 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 90 | ok( buffer[i] == sillytext[i], "that's not what's written\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 94 | ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 95 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 96 | ret = DeleteFileA( filename ); |
| 97 | ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 100 | |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 101 | static void test__hwrite( void ) |
| 102 | { |
| 103 | HFILE filehandle; |
| 104 | char buffer[10000]; |
| 105 | long bytes_read; |
Francois Gouget | 45d2613 | 2002-12-18 02:22:51 +0000 | [diff] [blame] | 106 | long bytes_written; |
| 107 | long blocks; |
| 108 | long i; |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 109 | char *contents; |
| 110 | HLOCAL memory_object; |
| 111 | char checksum[1]; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 112 | BOOL ret; |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 113 | |
| 114 | filehandle = _lcreat( filename, 0 ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 115 | if (filehandle == HFILE_ERROR) |
| 116 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 117 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 118 | return; |
| 119 | } |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 120 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 121 | ok( HFILE_ERROR != _hwrite( filehandle, "", 0 ), "_hwrite complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 122 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 123 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 124 | |
| 125 | filehandle = _lopen( filename, OF_READ ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 126 | |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 127 | bytes_read = _hread( filehandle, buffer, 1); |
| 128 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 129 | ok( 0 == bytes_read, "file read size error\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 130 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 131 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 132 | |
| 133 | filehandle = _lopen( filename, OF_READWRITE ); |
| 134 | |
| 135 | bytes_written = 0; |
| 136 | checksum[0] = '\0'; |
| 137 | srand( (unsigned)time( NULL ) ); |
| 138 | for (blocks = 0; blocks < 100; blocks++) |
| 139 | { |
Jon Griffiths | 7d75c14 | 2003-07-19 03:06:19 +0000 | [diff] [blame] | 140 | for (i = 0; i < (long)sizeof( buffer ); i++) |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 141 | { |
| 142 | buffer[i] = rand( ); |
| 143 | checksum[0] = checksum[0] + buffer[i]; |
| 144 | } |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 145 | ok( HFILE_ERROR != _hwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 146 | bytes_written = bytes_written + sizeof( buffer ); |
| 147 | } |
| 148 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 149 | ok( HFILE_ERROR != _hwrite( filehandle, checksum, 1 ), "_hwrite complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 150 | bytes_written++; |
| 151 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 152 | ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 153 | |
| 154 | memory_object = LocalAlloc( LPTR, bytes_written ); |
| 155 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 156 | ok( 0 != memory_object, "LocalAlloc fails. (Could be out of memory.)\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 157 | |
| 158 | contents = LocalLock( memory_object ); |
| 159 | |
| 160 | filehandle = _lopen( filename, OF_READ ); |
| 161 | |
| 162 | contents = LocalLock( memory_object ); |
| 163 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 164 | ok( NULL != contents, "LocalLock whines\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 165 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 166 | ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 167 | |
| 168 | checksum[0] = '\0'; |
| 169 | i = 0; |
| 170 | do |
| 171 | { |
| 172 | checksum[0] = checksum[0] + contents[i]; |
| 173 | i++; |
| 174 | } |
| 175 | while (i < bytes_written - 1); |
| 176 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 177 | ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 178 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 179 | ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 180 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 181 | ret = DeleteFileA( filename ); |
| 182 | ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 185 | |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 186 | static void test__lclose( void ) |
| 187 | { |
| 188 | HFILE filehandle; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 189 | BOOL ret; |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 190 | |
| 191 | filehandle = _lcreat( filename, 0 ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 192 | if (filehandle == HFILE_ERROR) |
| 193 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 194 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 195 | return; |
| 196 | } |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 197 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 198 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 199 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 200 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 201 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 202 | ret = DeleteFileA( filename ); |
| 203 | ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 207 | static void test__lcreat( void ) |
| 208 | { |
| 209 | HFILE filehandle; |
| 210 | char buffer[10000]; |
| 211 | WIN32_FIND_DATAA search_results; |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 212 | char slashname[] = "testfi/"; |
Ferenc Wagner | 4b28f0f | 2003-10-21 23:42:50 +0000 | [diff] [blame] | 213 | int err; |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 214 | HANDLE find; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 215 | BOOL ret; |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 216 | |
| 217 | filehandle = _lcreat( filename, 0 ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 218 | if (filehandle == HFILE_ERROR) |
| 219 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 220 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 221 | return; |
| 222 | } |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 223 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 224 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 225 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 226 | ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 227 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 228 | ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 229 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 230 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 231 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 232 | ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 233 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 234 | ret = DeleteFileA(filename); |
| 235 | ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError()); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 236 | |
Jakob Eriksson | 43b3177 | 2002-05-29 16:58:14 +0000 | [diff] [blame] | 237 | filehandle = _lcreat( filename, 1 ); /* readonly */ |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 238 | ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 239 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 240 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write never the less\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 241 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 242 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 243 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 244 | ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 245 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 246 | ok( 0 == DeleteFileA( filename ), "shouldn't be able to delete a readonly file\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 247 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 248 | ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file\n" ); |
Jakob Eriksson | 43b3177 | 2002-05-29 16:58:14 +0000 | [diff] [blame] | 249 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 250 | ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file!\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 251 | |
| 252 | filehandle = _lcreat( filename, 2 ); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 253 | ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 254 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 255 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 256 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 257 | ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 258 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 259 | ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 260 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 261 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 262 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 263 | ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 264 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 265 | ret = DeleteFileA( filename ); |
| 266 | ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 267 | |
Jakob Eriksson | 43b3177 | 2002-05-29 16:58:14 +0000 | [diff] [blame] | 268 | filehandle = _lcreat( filename, 4 ); /* SYSTEM file */ |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 269 | ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 270 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 271 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 272 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 273 | ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 274 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 275 | ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 276 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 277 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 278 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 279 | ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 280 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 281 | ret = DeleteFileA( filename ); |
| 282 | ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 283 | |
| 284 | filehandle=_lcreat (slashname, 0); /* illegal name */ |
Ferenc Wagner | 4b28f0f | 2003-10-21 23:42:50 +0000 | [diff] [blame] | 285 | if (HFILE_ERROR==filehandle) { |
| 286 | err=GetLastError (); |
| 287 | ok (err==ERROR_INVALID_NAME || err==ERROR_PATH_NOT_FOUND, |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 288 | "creating file \"%s\" failed with error %d\n", slashname, err); |
Ferenc Wagner | 4b28f0f | 2003-10-21 23:42:50 +0000 | [diff] [blame] | 289 | } else { /* only NT succeeds */ |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 290 | _lclose(filehandle); |
| 291 | find=FindFirstFileA (slashname, &search_results); |
Alexandre Julliard | 8f03216 | 2004-03-17 20:57:09 +0000 | [diff] [blame] | 292 | if (INVALID_HANDLE_VALUE!=find) |
| 293 | { |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 294 | ret = FindClose (find); |
| 295 | ok (0 != ret, "FindClose complains (%ld)\n", GetLastError ()); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 296 | slashname[strlen(slashname)-1]=0; |
| 297 | ok (!strcmp (slashname, search_results.cFileName), |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 298 | "found unexpected name \"%s\"\n", search_results.cFileName); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 299 | ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes, |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 300 | "attributes of file \"%s\" are 0x%04lx\n", search_results.cFileName, |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 301 | search_results.dwFileAttributes); |
| 302 | } |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 303 | ret = DeleteFileA( slashname ); |
| 304 | ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | filehandle=_lcreat (filename, 8); /* illegal attribute */ |
| 308 | if (HFILE_ERROR==filehandle) |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 309 | ok (0, "couldn't create volume label \"%s\"\n", filename); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 310 | else { |
| 311 | _lclose(filehandle); |
| 312 | find=FindFirstFileA (filename, &search_results); |
| 313 | if (INVALID_HANDLE_VALUE==find) |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 314 | ok (0, "file \"%s\" not found\n", filename); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 315 | else { |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 316 | ret = FindClose(find); |
| 317 | ok ( 0 != ret, "FindClose complains (%ld)\n", GetLastError ()); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 318 | ok (!strcmp (filename, search_results.cFileName), |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 319 | "found unexpected name \"%s\"\n", search_results.cFileName); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 320 | ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes, |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 321 | "attributes of file \"%s\" are 0x%04lx\n", search_results.cFileName, |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 322 | search_results.dwFileAttributes); |
| 323 | } |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 324 | ret = DeleteFileA( filename ); |
| 325 | ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Ferenc Wagner | 18f7bfb | 2003-05-19 21:50:32 +0000 | [diff] [blame] | 326 | } |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 330 | static void test__llseek( void ) |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 331 | { |
| 332 | INT i; |
| 333 | HFILE filehandle; |
| 334 | char buffer[1]; |
| 335 | long bytes_read; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 336 | BOOL ret; |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 337 | |
| 338 | filehandle = _lcreat( filename, 0 ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 339 | if (filehandle == HFILE_ERROR) |
| 340 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 341 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 342 | return; |
| 343 | } |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 344 | |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 345 | for (i = 0; i < 400; i++) |
| 346 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 347 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 348 | } |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 349 | ok( HFILE_ERROR != _llseek( filehandle, 400 * strlen( sillytext ), FILE_CURRENT ), "should be able to seek\n" ); |
| 350 | ok( HFILE_ERROR != _llseek( filehandle, 27 + 35 * strlen( sillytext ), FILE_BEGIN ), "should be able to seek\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 351 | |
| 352 | bytes_read = _hread( filehandle, buffer, 1); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 353 | ok( 1 == bytes_read, "file read size error\n" ); |
| 354 | ok( buffer[0] == sillytext[27], "_llseek error, it got lost seeking\n" ); |
| 355 | ok( HFILE_ERROR != _llseek( filehandle, -400 * strlen( sillytext ), FILE_END ), "should be able to seek\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 356 | |
| 357 | bytes_read = _hread( filehandle, buffer, 1); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 358 | ok( 1 == bytes_read, "file read size error\n" ); |
| 359 | ok( buffer[0] == sillytext[0], "_llseek error, it got lost seeking\n" ); |
| 360 | ok( HFILE_ERROR != _llseek( filehandle, 1000000, FILE_END ), "should be able to seek past file; poor, poor Windows programmers\n" ); |
| 361 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 362 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 363 | ret = DeleteFileA( filename ); |
| 364 | ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 367 | |
| 368 | static void test__llopen( void ) |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 369 | { |
| 370 | HFILE filehandle; |
| 371 | UINT bytes_read; |
| 372 | char buffer[10000]; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 373 | BOOL ret; |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 374 | |
| 375 | filehandle = _lcreat( filename, 0 ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 376 | if (filehandle == HFILE_ERROR) |
| 377 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 378 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 379 | return; |
| 380 | } |
| 381 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 382 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" ); |
| 383 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 384 | |
| 385 | filehandle = _lopen( filename, OF_READ ); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 386 | ok( HFILE_ERROR == _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write!\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 387 | bytes_read = _hread( filehandle, buffer, strlen( sillytext ) ); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 388 | ok( strlen( sillytext ) == bytes_read, "file read size error\n" ); |
| 389 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 390 | |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 391 | filehandle = _lopen( filename, OF_READWRITE ); |
| 392 | bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) ); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 393 | ok( strlen( sillytext ) == bytes_read, "file read size error\n" ); |
| 394 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" ); |
| 395 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 396 | |
| 397 | filehandle = _lopen( filename, OF_WRITE ); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 398 | ok( HFILE_ERROR == _hread( filehandle, buffer, 1 ), "you should only be able to write this file\n" ); |
| 399 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" ); |
| 400 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 401 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 402 | ret = DeleteFileA( filename ); |
| 403 | ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 404 | /* TODO - add tests for the SHARE modes - use two processes to pull this one off */ |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 407 | |
| 408 | static void test__lread( void ) |
| 409 | { |
| 410 | HFILE filehandle; |
| 411 | char buffer[10000]; |
| 412 | long bytes_read; |
| 413 | UINT bytes_wanted; |
| 414 | UINT i; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 415 | BOOL ret; |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 416 | |
| 417 | filehandle = _lcreat( filename, 0 ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 418 | if (filehandle == HFILE_ERROR) |
| 419 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 420 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 421 | return; |
| 422 | } |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 423 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 424 | ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 425 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 426 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 427 | |
| 428 | filehandle = _lopen( filename, OF_READ ); |
| 429 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 430 | ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 431 | |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 432 | bytes_read = _lread( filehandle, buffer, 2 * strlen( sillytext ) ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 433 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 434 | ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 435 | |
| 436 | for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++) |
| 437 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 438 | ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" ); |
| 439 | ok( _lread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 440 | for (i = 0; i < bytes_wanted; i++) |
| 441 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 442 | ok( buffer[i] == sillytext[i], "that's not what's written\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 446 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 447 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 448 | ret = DeleteFileA( filename ); |
| 449 | ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
| 453 | static void test__lwrite( void ) |
| 454 | { |
| 455 | HFILE filehandle; |
| 456 | char buffer[10000]; |
| 457 | long bytes_read; |
Francois Gouget | 45d2613 | 2002-12-18 02:22:51 +0000 | [diff] [blame] | 458 | long bytes_written; |
| 459 | long blocks; |
| 460 | long i; |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 461 | char *contents; |
| 462 | HLOCAL memory_object; |
| 463 | char checksum[1]; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 464 | BOOL ret; |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 465 | |
| 466 | filehandle = _lcreat( filename, 0 ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 467 | if (filehandle == HFILE_ERROR) |
| 468 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 469 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 470 | return; |
| 471 | } |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 472 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 473 | ok( HFILE_ERROR != _lwrite( filehandle, "", 0 ), "_hwrite complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 474 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 475 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 476 | |
| 477 | filehandle = _lopen( filename, OF_READ ); |
Francois Gouget | c949349 | 2002-05-23 16:29:37 +0000 | [diff] [blame] | 478 | |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 479 | bytes_read = _hread( filehandle, buffer, 1); |
| 480 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 481 | ok( 0 == bytes_read, "file read size error\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 482 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 483 | ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 484 | |
| 485 | filehandle = _lopen( filename, OF_READWRITE ); |
| 486 | |
| 487 | bytes_written = 0; |
| 488 | checksum[0] = '\0'; |
| 489 | srand( (unsigned)time( NULL ) ); |
| 490 | for (blocks = 0; blocks < 100; blocks++) |
| 491 | { |
Jon Griffiths | 7d75c14 | 2003-07-19 03:06:19 +0000 | [diff] [blame] | 492 | for (i = 0; i < (long)sizeof( buffer ); i++) |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 493 | { |
| 494 | buffer[i] = rand( ); |
| 495 | checksum[0] = checksum[0] + buffer[i]; |
| 496 | } |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 497 | ok( HFILE_ERROR != _lwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 498 | bytes_written = bytes_written + sizeof( buffer ); |
| 499 | } |
| 500 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 501 | ok( HFILE_ERROR != _lwrite( filehandle, checksum, 1 ), "_hwrite complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 502 | bytes_written++; |
| 503 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 504 | ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 505 | |
| 506 | memory_object = LocalAlloc( LPTR, bytes_written ); |
| 507 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 508 | ok( 0 != memory_object, "LocalAlloc fails, could be out of memory\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 509 | |
| 510 | contents = LocalLock( memory_object ); |
| 511 | |
| 512 | filehandle = _lopen( filename, OF_READ ); |
| 513 | |
| 514 | contents = LocalLock( memory_object ); |
| 515 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 516 | ok( NULL != contents, "LocalLock whines\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 517 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 518 | ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 519 | |
| 520 | checksum[0] = '\0'; |
| 521 | i = 0; |
| 522 | do |
| 523 | { |
Jakob Eriksson | 43b3177 | 2002-05-29 16:58:14 +0000 | [diff] [blame] | 524 | checksum[0] += contents[i]; |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 525 | i++; |
| 526 | } |
| 527 | while (i < bytes_written - 1); |
| 528 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 529 | ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" ); |
Alexandre Julliard | 8dc3a51 | 2002-05-10 01:10:04 +0000 | [diff] [blame] | 530 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 531 | ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 532 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 533 | ret = DeleteFileA( filename ); |
| 534 | ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 537 | static void test_CopyFileA(void) |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 538 | { |
| 539 | char temp_path[MAX_PATH]; |
| 540 | char source[MAX_PATH], dest[MAX_PATH]; |
| 541 | static const char prefix[] = "pfx"; |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 542 | HANDLE hfile; |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 543 | FILETIME ft1, ft2; |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 544 | char buf[10]; |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 545 | DWORD ret; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 546 | BOOL retok; |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 547 | |
| 548 | ret = GetTempPathA(MAX_PATH, temp_path); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 549 | ok(ret != 0, "GetTempPathA error %ld\n", GetLastError()); |
| 550 | ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n"); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 551 | |
| 552 | ret = GetTempFileNameA(temp_path, prefix, 0, source); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 553 | ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 554 | |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 555 | /* make the source have not zero size */ |
| 556 | hfile = CreateFileA(source, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 ); |
| 557 | ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n"); |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 558 | retok = WriteFile(hfile, prefix, sizeof(prefix), &ret, NULL ); |
| 559 | ok( retok && ret == sizeof(prefix), |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 560 | "WriteFile error %ld\n", GetLastError()); |
| 561 | ok(GetFileSize(hfile, NULL) == sizeof(prefix), "source file has wrong size\n"); |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 562 | /* get the file time and change it to prove the difference */ |
Rein Klazes | 7308f16 | 2005-03-31 19:07:08 +0000 | [diff] [blame] | 563 | ret = GetFileTime(hfile, NULL, NULL, &ft1); |
| 564 | ok( ret, "GetFileTime error %ld\n", GetLastError()); |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 565 | ft1.dwLowDateTime -= 600000000; /* 60 second */ |
Rein Klazes | 7308f16 | 2005-03-31 19:07:08 +0000 | [diff] [blame] | 566 | ret = SetFileTime(hfile, NULL, NULL, &ft1); |
| 567 | ok( ret, "SetFileTime error %ld\n", GetLastError()); |
Alexandre Julliard | 3ea748b | 2005-03-22 21:14:51 +0000 | [diff] [blame] | 568 | GetFileTime(hfile, NULL, NULL, &ft1); /* get the actual time back */ |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 569 | CloseHandle(hfile); |
| 570 | |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 571 | ret = GetTempFileNameA(temp_path, prefix, 0, dest); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 572 | ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 573 | |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 574 | SetLastError(0xdeadbeef); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 575 | ret = CopyFileA(source, dest, TRUE); |
| 576 | ok(!ret && GetLastError() == ERROR_FILE_EXISTS, |
| 577 | "CopyFileA: unexpected error %ld\n", GetLastError()); |
| 578 | |
| 579 | ret = CopyFileA(source, dest, FALSE); |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 580 | ok(ret, "CopyFileA: error %ld\n", GetLastError()); |
| 581 | |
| 582 | /* make sure that destination has correct size */ |
| 583 | hfile = CreateFileA(dest, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); |
| 584 | ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n"); |
| 585 | ret = GetFileSize(hfile, NULL); |
| 586 | ok(ret == sizeof(prefix), "destination file has wrong size %ld\n", ret); |
| 587 | |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 588 | /* make sure that destination has the same filetime */ |
Rein Klazes | 7308f16 | 2005-03-31 19:07:08 +0000 | [diff] [blame] | 589 | ret = GetFileTime(hfile, NULL, NULL, &ft2); |
| 590 | ok( ret, "GetFileTime error %ld\n", GetLastError()); |
Francois Gouget | fbb3343 | 2005-03-02 13:53:50 +0000 | [diff] [blame] | 591 | ok(CompareFileTime(&ft1, &ft2) == 0, "destination file has wrong filetime\n"); |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 592 | |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 593 | SetLastError(0xdeadbeef); |
| 594 | ret = CopyFileA(source, dest, FALSE); |
| 595 | ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, |
| 596 | "CopyFileA: ret = %ld, unexpected error %ld\n", ret, GetLastError()); |
| 597 | |
| 598 | /* make sure that destination still has correct size */ |
| 599 | ret = GetFileSize(hfile, NULL); |
| 600 | ok(ret == sizeof(prefix), "destination file has wrong size %ld\n", ret); |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 601 | retok = ReadFile(hfile, buf, sizeof(buf), &ret, NULL); |
| 602 | ok( retok && ret == sizeof(prefix), |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 603 | "ReadFile: error %ld\n", GetLastError()); |
| 604 | ok(!memcmp(prefix, buf, sizeof(prefix)), "buffer contents mismatch\n"); |
| 605 | CloseHandle(hfile); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 606 | |
| 607 | ret = DeleteFileA(source); |
| 608 | ok(ret, "DeleteFileA: error %ld\n", GetLastError()); |
| 609 | ret = DeleteFileA(dest); |
| 610 | ok(ret, "DeleteFileA: error %ld\n", GetLastError()); |
| 611 | } |
| 612 | |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 613 | static void test_CopyFileW(void) |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 614 | { |
| 615 | WCHAR temp_path[MAX_PATH]; |
| 616 | WCHAR source[MAX_PATH], dest[MAX_PATH]; |
| 617 | static const WCHAR prefix[] = {'p','f','x',0}; |
| 618 | DWORD ret; |
| 619 | |
| 620 | ret = GetTempPathW(MAX_PATH, temp_path); |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 621 | if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) |
| 622 | return; |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 623 | ok(ret != 0, "GetTempPathW error %ld\n", GetLastError()); |
| 624 | ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n"); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 625 | |
| 626 | ret = GetTempFileNameW(temp_path, prefix, 0, source); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 627 | ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 628 | |
| 629 | ret = GetTempFileNameW(temp_path, prefix, 0, dest); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 630 | ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 631 | |
| 632 | ret = CopyFileW(source, dest, TRUE); |
| 633 | ok(!ret && GetLastError() == ERROR_FILE_EXISTS, |
| 634 | "CopyFileW: unexpected error %ld\n", GetLastError()); |
| 635 | |
| 636 | ret = CopyFileW(source, dest, FALSE); |
Dmitry Timoshkov | 8811628 | 2004-05-22 03:14:17 +0000 | [diff] [blame] | 637 | ok(ret, "CopyFileW: error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 638 | |
| 639 | ret = DeleteFileW(source); |
| 640 | ok(ret, "DeleteFileW: error %ld\n", GetLastError()); |
| 641 | ret = DeleteFileW(dest); |
| 642 | ok(ret, "DeleteFileW: error %ld\n", GetLastError()); |
| 643 | } |
| 644 | |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 645 | static void test_CreateFileA(void) |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 646 | { |
| 647 | HANDLE hFile; |
| 648 | char temp_path[MAX_PATH]; |
| 649 | char filename[MAX_PATH]; |
| 650 | static const char prefix[] = "pfx"; |
| 651 | DWORD ret; |
| 652 | |
| 653 | ret = GetTempPathA(MAX_PATH, temp_path); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 654 | ok(ret != 0, "GetTempPathA error %ld\n", GetLastError()); |
| 655 | ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n"); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 656 | |
| 657 | ret = GetTempFileNameA(temp_path, prefix, 0, filename); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 658 | ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 659 | |
| 660 | hFile = CreateFileA(filename, GENERIC_READ, 0, NULL, |
| 661 | CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0); |
| 662 | ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS, |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 663 | "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n"); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 664 | |
| 665 | ret = DeleteFileA(filename); |
| 666 | ok(ret, "DeleteFileA: error %ld\n", GetLastError()); |
| 667 | } |
| 668 | |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 669 | static void test_CreateFileW(void) |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 670 | { |
| 671 | HANDLE hFile; |
| 672 | WCHAR temp_path[MAX_PATH]; |
| 673 | WCHAR filename[MAX_PATH]; |
Francois Gouget | 52c0832 | 2004-04-20 01:12:17 +0000 | [diff] [blame] | 674 | static const WCHAR emptyW[]={'\0'}; |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 675 | static const WCHAR prefix[] = {'p','f','x',0}; |
Mike Hearn | 9501215 | 2004-07-06 21:31:24 +0000 | [diff] [blame] | 676 | static const WCHAR bogus[] = { '\\', '\\', '.', '\\', 'B', 'O', 'G', 'U', 'S', 0 }; |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 677 | DWORD ret; |
| 678 | |
| 679 | ret = GetTempPathW(MAX_PATH, temp_path); |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 680 | if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) |
| 681 | return; |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 682 | ok(ret != 0, "GetTempPathW error %ld\n", GetLastError()); |
| 683 | ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n"); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 684 | |
| 685 | ret = GetTempFileNameW(temp_path, prefix, 0, filename); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 686 | ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 687 | |
| 688 | hFile = CreateFileW(filename, GENERIC_READ, 0, NULL, |
| 689 | CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0); |
| 690 | ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS, |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 691 | "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n"); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 692 | |
| 693 | ret = DeleteFileW(filename); |
| 694 | ok(ret, "DeleteFileW: error %ld\n", GetLastError()); |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 695 | |
Stefan Leichter | e41bd72 | 2005-04-19 11:59:46 +0000 | [diff] [blame] | 696 | #if 0 /* this test crashes on NT4.0 */ |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 697 | hFile = CreateFileW(NULL, GENERIC_READ, 0, NULL, |
| 698 | CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0); |
| 699 | ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PATH_NOT_FOUND, |
| 700 | "CreateFileW(NULL) returned ret=%p error=%ld\n",hFile,GetLastError()); |
Stefan Leichter | e41bd72 | 2005-04-19 11:59:46 +0000 | [diff] [blame] | 701 | #endif |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 702 | |
| 703 | hFile = CreateFileW(emptyW, GENERIC_READ, 0, NULL, |
| 704 | CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0); |
| 705 | ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PATH_NOT_FOUND, |
| 706 | "CreateFileW(\"\") returned ret=%p error=%ld\n",hFile,GetLastError()); |
Mike Hearn | 9501215 | 2004-07-06 21:31:24 +0000 | [diff] [blame] | 707 | |
Francois Gouget | 4d801b6 | 2005-02-10 19:19:35 +0000 | [diff] [blame] | 708 | /* test the result of opening a nonexistent driver name */ |
Mike Hearn | 9501215 | 2004-07-06 21:31:24 +0000 | [diff] [blame] | 709 | hFile = CreateFileW(bogus, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
| 710 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 711 | ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND, |
| 712 | "CreateFileW on invalid VxD name returned ret=%p error=%ld\n",hFile,GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Stefan Huehner | ac6f562 | 2005-06-20 14:18:03 +0000 | [diff] [blame^] | 715 | static void test_GetTempFileNameA(void) |
Jakob Eriksson | 960104b | 2004-04-22 23:44:14 +0000 | [diff] [blame] | 716 | { |
Mike Hearn | 517248d | 2004-01-16 04:49:13 +0000 | [diff] [blame] | 717 | UINT result; |
| 718 | char out[MAX_PATH]; |
Jakob Eriksson | 960104b | 2004-04-22 23:44:14 +0000 | [diff] [blame] | 719 | char expected[MAX_PATH + 10]; |
| 720 | char windowsdir[MAX_PATH + 10]; |
| 721 | char windowsdrive[3]; |
Mike Hearn | 517248d | 2004-01-16 04:49:13 +0000 | [diff] [blame] | 722 | |
Jakob Eriksson | 960104b | 2004-04-22 23:44:14 +0000 | [diff] [blame] | 723 | result = GetWindowsDirectory(windowsdir, sizeof(windowsdir)); |
| 724 | ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n"); |
| 725 | ok(result != 0, "GetWindowsDirectory: error %ld\n", GetLastError()); |
Mike Hearn | 517248d | 2004-01-16 04:49:13 +0000 | [diff] [blame] | 726 | |
Jakob Eriksson | 960104b | 2004-04-22 23:44:14 +0000 | [diff] [blame] | 727 | /* If the Windows directory is the root directory, it ends in backslash, not else. */ |
| 728 | if (strlen(windowsdir) != 3) /* As in "C:\" or "F:\" */ |
| 729 | { |
| 730 | strcat(windowsdir, "\\"); |
| 731 | } |
| 732 | |
| 733 | windowsdrive[0] = windowsdir[0]; |
| 734 | windowsdrive[1] = windowsdir[1]; |
| 735 | windowsdrive[2] = '\0'; |
| 736 | |
| 737 | result = GetTempFileNameA(windowsdrive, "abc", 1, out); |
| 738 | ok(result != 0, "GetTempFileNameA: error %ld\n", GetLastError()); |
| 739 | ok(((out[0] == windowsdrive[0]) && (out[1] == ':')) && (out[2] == '\\'), |
| 740 | "GetTempFileNameA: first three characters should be %c:\\, string was actually %s\n", |
| 741 | windowsdrive[0], out); |
| 742 | |
| 743 | result = GetTempFileNameA(windowsdir, "abc", 2, out); |
| 744 | ok(result != 0, "GetTempFileNameA: error %ld\n", GetLastError()); |
| 745 | expected[0] = '\0'; |
| 746 | strcat(expected, windowsdir); |
| 747 | strcat(expected, "abc2.tmp"); |
| 748 | ok(lstrcmpiA(out, expected) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n", |
| 749 | out, expected); |
Mike Hearn | 517248d | 2004-01-16 04:49:13 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Ryan Cumming | c4aa073 | 2002-11-12 02:11:52 +0000 | [diff] [blame] | 752 | static void test_DeleteFileA( void ) |
| 753 | { |
| 754 | BOOL ret; |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 755 | |
| 756 | ret = DeleteFileA(NULL); |
| 757 | ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER || |
| 758 | GetLastError() == ERROR_PATH_NOT_FOUND), |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 759 | "DeleteFileA(NULL) returned ret=%d error=%ld\n",ret,GetLastError()); |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 760 | |
Ryan Cumming | c4aa073 | 2002-11-12 02:11:52 +0000 | [diff] [blame] | 761 | ret = DeleteFileA(""); |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 762 | ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND || |
| 763 | GetLastError() == ERROR_BAD_PATHNAME), |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 764 | "DeleteFileA(\"\") returned ret=%d error=%ld\n",ret,GetLastError()); |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 765 | |
| 766 | ret = DeleteFileA("nul"); |
| 767 | ok(!ret && (GetLastError() == ERROR_FILE_NOT_FOUND || |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 768 | GetLastError() == ERROR_INVALID_PARAMETER || |
| 769 | GetLastError() == ERROR_ACCESS_DENIED), |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 770 | "DeleteFileA(\"nul\") returned ret=%d error=%ld\n",ret,GetLastError()); |
Ryan Cumming | c4aa073 | 2002-11-12 02:11:52 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 773 | static void test_DeleteFileW( void ) |
| 774 | { |
| 775 | BOOL ret; |
Francois Gouget | 52c0832 | 2004-04-20 01:12:17 +0000 | [diff] [blame] | 776 | static const WCHAR emptyW[]={'\0'}; |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 777 | |
| 778 | ret = DeleteFileW(NULL); |
| 779 | if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) |
| 780 | return; |
| 781 | ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND, |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 782 | "DeleteFileW(NULL) returned ret=%d error=%ld\n",ret,GetLastError()); |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 783 | |
| 784 | ret = DeleteFileW(emptyW); |
| 785 | ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND, |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 786 | "DeleteFileW(\"\") returned ret=%d error=%ld\n",ret,GetLastError()); |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 789 | #define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0)))) |
| 790 | |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 791 | static void test_MoveFileA(void) |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 792 | { |
| 793 | char tempdir[MAX_PATH]; |
| 794 | char source[MAX_PATH], dest[MAX_PATH]; |
| 795 | static const char prefix[] = "pfx"; |
| 796 | DWORD ret; |
| 797 | |
| 798 | ret = GetTempPathA(MAX_PATH, tempdir); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 799 | ok(ret != 0, "GetTempPathA error %ld\n", GetLastError()); |
| 800 | ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n"); |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 801 | |
| 802 | ret = GetTempFileNameA(tempdir, prefix, 0, source); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 803 | ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError()); |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 804 | |
| 805 | ret = GetTempFileNameA(tempdir, prefix, 0, dest); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 806 | ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError()); |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 807 | |
| 808 | ret = MoveFileA(source, dest); |
Hans Leidekker | 5136705 | 2003-12-15 20:15:20 +0000 | [diff] [blame] | 809 | ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS, |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 810 | "MoveFileA: unexpected error %ld\n", GetLastError()); |
| 811 | |
| 812 | ret = DeleteFileA(dest); |
| 813 | ok(ret, "DeleteFileA: error %ld\n", GetLastError()); |
| 814 | |
| 815 | ret = MoveFileA(source, dest); |
| 816 | ok(ret, "MoveFileA: failed, error %ld\n", GetLastError()); |
| 817 | |
| 818 | lstrcatA(tempdir, "Remove Me"); |
| 819 | ret = CreateDirectoryA(tempdir, NULL); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 820 | ok(ret == TRUE, "CreateDirectoryA failed\n"); |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 821 | |
| 822 | lstrcpyA(source, dest); |
| 823 | lstrcpyA(dest, tempdir); |
| 824 | lstrcatA(dest, "\\wild?.*"); |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 825 | /* FIXME: if we create a file with wildcards we can't delete it now that DeleteFile works correctly */ |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 826 | ret = MoveFileA(source, dest); |
Alexandre Julliard | 1158621 | 2004-04-27 02:27:47 +0000 | [diff] [blame] | 827 | ok(!ret, "MoveFileA: shouldn't move to wildcard file\n"); |
Dmitry Timoshkov | b6dae78 | 2004-05-25 00:20:50 +0000 | [diff] [blame] | 828 | ok(GetLastError() == ERROR_INVALID_NAME || /* NT */ |
| 829 | GetLastError() == ERROR_FILE_NOT_FOUND, /* Win9x */ |
Alexandre Julliard | 1158621 | 2004-04-27 02:27:47 +0000 | [diff] [blame] | 830 | "MoveFileA: with wildcards, unexpected error %ld\n", GetLastError()); |
| 831 | if (ret || (GetLastError() != ERROR_INVALID_NAME)) |
| 832 | { |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 833 | WIN32_FIND_DATAA fd; |
| 834 | char temppath[MAX_PATH]; |
| 835 | HANDLE hFind; |
Jon Griffiths | 90535ce | 2003-09-25 20:29:40 +0000 | [diff] [blame] | 836 | |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 837 | lstrcpyA(temppath, tempdir); |
| 838 | lstrcatA(temppath, "\\*.*"); |
| 839 | hFind = FindFirstFileA(temppath, &fd); |
| 840 | if (INVALID_HANDLE_VALUE != hFind) |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 841 | { |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 842 | LPSTR lpName; |
| 843 | do |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 844 | { |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 845 | lpName = fd.cAlternateFileName; |
| 846 | if (!lpName[0]) |
| 847 | lpName = fd.cFileName; |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 848 | ok(IsDotDir(lpName), "MoveFileA: wildcards file created!\n"); |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 849 | } |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 850 | while (FindNextFileA(hFind, &fd)); |
| 851 | FindClose(hFind); |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 852 | } |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 853 | } |
Alexandre Julliard | 1158621 | 2004-04-27 02:27:47 +0000 | [diff] [blame] | 854 | ret = DeleteFileA(source); |
| 855 | ok(ret, "DeleteFileA: error %ld\n", GetLastError()); |
| 856 | ret = DeleteFileA(dest); |
| 857 | ok(!ret, "DeleteFileA: error %ld\n", GetLastError()); |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 858 | ret = RemoveDirectoryA(tempdir); |
| 859 | ok(ret, "DeleteDirectoryA: error %ld\n", GetLastError()); |
| 860 | } |
| 861 | |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 862 | static void test_MoveFileW(void) |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 863 | { |
| 864 | WCHAR temp_path[MAX_PATH]; |
| 865 | WCHAR source[MAX_PATH], dest[MAX_PATH]; |
| 866 | static const WCHAR prefix[] = {'p','f','x',0}; |
| 867 | DWORD ret; |
| 868 | |
| 869 | ret = GetTempPathW(MAX_PATH, temp_path); |
| 870 | if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) |
| 871 | return; |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 872 | ok(ret != 0, "GetTempPathW error %ld\n", GetLastError()); |
| 873 | ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n"); |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 874 | |
| 875 | ret = GetTempFileNameW(temp_path, prefix, 0, source); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 876 | ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError()); |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 877 | |
| 878 | ret = GetTempFileNameW(temp_path, prefix, 0, dest); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 879 | ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError()); |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 880 | |
| 881 | ret = MoveFileW(source, dest); |
Hans Leidekker | 5136705 | 2003-12-15 20:15:20 +0000 | [diff] [blame] | 882 | ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS, |
Rolf Kalbermatter | d4f1381 | 2003-09-16 01:19:21 +0000 | [diff] [blame] | 883 | "CopyFileW: unexpected error %ld\n", GetLastError()); |
| 884 | |
| 885 | ret = DeleteFileW(source); |
| 886 | ok(ret, "DeleteFileW: error %ld\n", GetLastError()); |
| 887 | ret = DeleteFileW(dest); |
| 888 | ok(ret, "DeleteFileW: error %ld\n", GetLastError()); |
| 889 | } |
| 890 | |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 891 | #define PATTERN_OFFSET 0x10 |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 892 | |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 893 | static void test_offset_in_overlapped_structure(void) |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 894 | { |
| 895 | HANDLE hFile; |
| 896 | OVERLAPPED ov; |
| 897 | DWORD done; |
Alexandre Julliard | b7a8eef | 2003-02-11 22:11:56 +0000 | [diff] [blame] | 898 | BOOL rc; |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 899 | BYTE buf[256], pattern[] = "TeSt"; |
| 900 | UINT i; |
| 901 | char temp_path[MAX_PATH], temp_fname[MAX_PATH]; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 902 | BOOL ret; |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 903 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 904 | ret =GetTempPathA(MAX_PATH, temp_path); |
| 905 | ok( ret, "GetTempPathA error %ld\n", GetLastError()); |
| 906 | ret =GetTempFileNameA(temp_path, "pfx", 0, temp_fname); |
| 907 | ok( ret, "GetTempFileNameA error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 908 | |
| 909 | /*** Write File *****************************************************/ |
| 910 | |
| 911 | hFile = CreateFileA(temp_fname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 912 | ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 913 | |
| 914 | for(i = 0; i < sizeof(buf); i++) buf[i] = i; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 915 | ret = WriteFile(hFile, buf, sizeof(buf), &done, NULL); |
| 916 | ok( ret, "WriteFile error %ld\n", GetLastError()); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 917 | ok(done == sizeof(buf), "expected number of bytes written %lu\n", done); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 918 | |
| 919 | memset(&ov, 0, sizeof(ov)); |
Dmitry Timoshkov | 75b93ff | 2005-03-17 19:00:08 +0000 | [diff] [blame] | 920 | S(U(ov)).Offset = PATTERN_OFFSET; |
| 921 | S(U(ov)).OffsetHigh = 0; |
Alexandre Julliard | b7a8eef | 2003-02-11 22:11:56 +0000 | [diff] [blame] | 922 | rc=WriteFile(hFile, pattern, sizeof(pattern), &done, &ov); |
| 923 | /* Win 9x does not support the overlapped I/O on files */ |
| 924 | if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 925 | ok(rc, "WriteFile error %ld\n", GetLastError()); |
| 926 | ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done); |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 927 | /*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/ |
Alexandre Julliard | b7a8eef | 2003-02-11 22:11:56 +0000 | [diff] [blame] | 928 | ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)), |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 929 | "expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern)); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 930 | |
Dmitry Timoshkov | 75b93ff | 2005-03-17 19:00:08 +0000 | [diff] [blame] | 931 | S(U(ov)).Offset = sizeof(buf) * 2; |
| 932 | S(U(ov)).OffsetHigh = 0; |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 933 | ret = WriteFile(hFile, pattern, sizeof(pattern), &done, &ov); |
| 934 | ok( ret, "WriteFile error %ld\n", GetLastError()); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 935 | ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done); |
Alexandre Julliard | b7a8eef | 2003-02-11 22:11:56 +0000 | [diff] [blame] | 936 | /*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/ |
| 937 | ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (sizeof(buf) * 2 + sizeof(pattern)), |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 938 | "expected file offset %d\n", sizeof(buf) * 2 + sizeof(pattern)); |
Alexandre Julliard | b7a8eef | 2003-02-11 22:11:56 +0000 | [diff] [blame] | 939 | } |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 940 | |
| 941 | CloseHandle(hFile); |
| 942 | |
| 943 | /*** Read File *****************************************************/ |
| 944 | |
| 945 | hFile = CreateFileA(temp_fname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 946 | ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 947 | |
| 948 | memset(buf, 0, sizeof(buf)); |
| 949 | memset(&ov, 0, sizeof(ov)); |
Dmitry Timoshkov | 75b93ff | 2005-03-17 19:00:08 +0000 | [diff] [blame] | 950 | S(U(ov)).Offset = PATTERN_OFFSET; |
| 951 | S(U(ov)).OffsetHigh = 0; |
Alexandre Julliard | b7a8eef | 2003-02-11 22:11:56 +0000 | [diff] [blame] | 952 | rc=ReadFile(hFile, buf, sizeof(pattern), &done, &ov); |
| 953 | /* Win 9x does not support the overlapped I/O on files */ |
| 954 | if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 955 | ok(rc, "ReadFile error %ld\n", GetLastError()); |
| 956 | ok(done == sizeof(pattern), "expected number of bytes read %lu\n", done); |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 957 | /*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/ |
Alexandre Julliard | b7a8eef | 2003-02-11 22:11:56 +0000 | [diff] [blame] | 958 | ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)), |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 959 | "expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern)); |
| 960 | ok(!memcmp(buf, pattern, sizeof(pattern)), "pattern match failed\n"); |
Alexandre Julliard | b7a8eef | 2003-02-11 22:11:56 +0000 | [diff] [blame] | 961 | } |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 962 | |
| 963 | CloseHandle(hFile); |
| 964 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 965 | ret = DeleteFileA(temp_fname); |
| 966 | ok( ret, "DeleteFileA error %ld\n", GetLastError()); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 967 | } |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 968 | |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 969 | static void test_LockFile(void) |
| 970 | { |
| 971 | HANDLE handle; |
| 972 | DWORD written; |
| 973 | OVERLAPPED overlapped; |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 974 | int limited_LockFile; |
| 975 | int limited_UnLockFile; |
| 976 | int lockfileex_capable; |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 977 | |
| 978 | handle = CreateFileA( filename, GENERIC_READ | GENERIC_WRITE, |
| 979 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
| 980 | CREATE_ALWAYS, 0, 0 ); |
| 981 | if (handle == INVALID_HANDLE_VALUE) |
| 982 | { |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 983 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 984 | return; |
| 985 | } |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 986 | ok( WriteFile( handle, sillytext, strlen(sillytext), &written, NULL ), "write failed\n" ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 987 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 988 | ok( LockFile( handle, 0, 0, 0, 0 ), "LockFile failed\n" ); |
| 989 | ok( UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile failed\n" ); |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 990 | |
| 991 | limited_UnLockFile = 0; |
| 992 | if (UnlockFile( handle, 0, 0, 0, 0 )) |
| 993 | { |
| 994 | limited_UnLockFile = 1; |
| 995 | } |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 996 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 997 | ok( LockFile( handle, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 998 | /* overlapping locks must fail */ |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 999 | ok( !LockFile( handle, 12, 0, 10, 0 ), "LockFile 12,10 succeeded\n" ); |
| 1000 | ok( !LockFile( handle, 5, 0, 6, 0 ), "LockFile 5,6 succeeded\n" ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1001 | /* non-overlapping locks must succeed */ |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1002 | ok( LockFile( handle, 5, 0, 5, 0 ), "LockFile 5,5 failed\n" ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1003 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1004 | ok( !UnlockFile( handle, 10, 0, 10, 0 ), "UnlockFile 10,10 succeeded\n" ); |
| 1005 | ok( UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 failed\n" ); |
| 1006 | ok( !UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 again succeeded\n" ); |
| 1007 | ok( UnlockFile( handle, 5, 0, 5, 0 ), "UnlockFile 5,5 failed\n" ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1008 | |
Dmitry Timoshkov | 75b93ff | 2005-03-17 19:00:08 +0000 | [diff] [blame] | 1009 | S(U(overlapped)).Offset = 100; |
| 1010 | S(U(overlapped)).OffsetHigh = 0; |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1011 | overlapped.hEvent = 0; |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1012 | |
| 1013 | lockfileex_capable = dll_capable("kernel32", "LockFileEx"); |
| 1014 | if (lockfileex_capable) |
| 1015 | { |
| 1016 | /* Test for broken LockFileEx a la Windows 95 OSR2. */ |
| 1017 | if (LockFileEx( handle, 0, 0, 100, 0, &overlapped )) |
| 1018 | { |
| 1019 | /* LockFileEx is probably OK, test it more. */ |
| 1020 | ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), |
| 1021 | "LockFileEx 100,100 failed\n" ); |
| 1022 | } |
| 1023 | } |
| 1024 | |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1025 | /* overlapping shared locks are OK */ |
Dmitry Timoshkov | 75b93ff | 2005-03-17 19:00:08 +0000 | [diff] [blame] | 1026 | S(U(overlapped)).Offset = 150; |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1027 | limited_UnLockFile || ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 150,100 failed\n" ); |
| 1028 | |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1029 | /* but exclusive is not */ |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1030 | if (lockfileex_capable) |
| 1031 | { |
| 1032 | ok( !LockFileEx( handle, LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY, |
| 1033 | 0, 50, 0, &overlapped ), |
| 1034 | "LockFileEx exclusive 150,50 succeeded\n" ); |
| 1035 | if (dll_capable("kernel32.dll", "UnlockFileEx")) |
| 1036 | { |
| 1037 | if (!UnlockFileEx( handle, 0, 100, 0, &overlapped )) |
| 1038 | { /* UnLockFile is capable. */ |
Dmitry Timoshkov | 75b93ff | 2005-03-17 19:00:08 +0000 | [diff] [blame] | 1039 | S(U(overlapped)).Offset = 100; |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1040 | ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ), |
| 1041 | "UnlockFileEx 150,100 again succeeded\n" ); |
| 1042 | } |
| 1043 | } |
| 1044 | } |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1045 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1046 | ok( LockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "LockFile failed\n" ); |
| 1047 | ok( !LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 succeeded\n" ); |
| 1048 | ok( !LockFile( handle, 0, 0x20000000, 20, 0 ), "LockFile 0x20000000,20 succeeded\n" ); |
| 1049 | ok( UnlockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "UnlockFile failed\n" ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1050 | |
| 1051 | /* wrap-around lock should not do anything */ |
| 1052 | /* (but still succeeds on NT4 so we don't check result) */ |
| 1053 | LockFile( handle, 0, 0x10000000, 0, 0xf0000001 ); |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1054 | |
| 1055 | limited_LockFile = 0; |
| 1056 | if (!LockFile( handle, ~0, ~0, 1, 0 )) |
| 1057 | { |
| 1058 | limited_LockFile = 1; |
| 1059 | } |
| 1060 | |
| 1061 | limited_UnLockFile || ok( UnlockFile( handle, ~0, ~0, 1, 0 ), "Unlockfile ~0,1 failed\n" ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1062 | |
| 1063 | /* zero-byte lock */ |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1064 | ok( LockFile( handle, 100, 0, 0, 0 ), "LockFile 100,0 failed\n" ); |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1065 | limited_LockFile || ok( !LockFile( handle, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" ); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1066 | ok( LockFile( handle, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" ); |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1067 | limited_LockFile || ok( !LockFile( handle, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" ); |
| 1068 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1069 | ok( UnlockFile( handle, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" ); |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1070 | !ok( UnlockFile( handle, 100, 0, 10, 0 ), "UnlockFile 100,10 failed\n" ); |
| 1071 | |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1072 | ok( UnlockFile( handle, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" ); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1073 | |
| 1074 | CloseHandle( handle ); |
| 1075 | DeleteFileA( filename ); |
| 1076 | } |
| 1077 | |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1078 | static inline int is_sharing_compatible( DWORD access1, DWORD sharing1, DWORD access2, DWORD sharing2 ) |
| 1079 | { |
| 1080 | if (!access1 || !access2) return 1; |
| 1081 | if ((access1 & GENERIC_READ) && !(sharing2 & FILE_SHARE_READ)) return 0; |
| 1082 | if ((access1 & GENERIC_WRITE) && !(sharing2 & FILE_SHARE_WRITE)) return 0; |
| 1083 | if ((access2 & GENERIC_READ) && !(sharing1 & FILE_SHARE_READ)) return 0; |
| 1084 | if ((access2 & GENERIC_WRITE) && !(sharing1 & FILE_SHARE_WRITE)) return 0; |
| 1085 | return 1; |
| 1086 | } |
| 1087 | |
| 1088 | static void test_file_sharing(void) |
| 1089 | { |
| 1090 | static const DWORD access_modes[4] = { 0, GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE }; |
| 1091 | static const DWORD sharing_modes[4] = { 0, FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE }; |
| 1092 | int a1, s1, a2, s2; |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1093 | int ret; |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 1094 | HANDLE h, h2; |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1095 | |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 1096 | /* make sure the file exists */ |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 1097 | h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 ); |
| 1098 | if (h == INVALID_HANDLE_VALUE) |
| 1099 | { |
| 1100 | ok(0, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError()); |
| 1101 | return; |
| 1102 | } |
Alexandre Julliard | c4c4da4 | 2004-04-03 00:05:24 +0000 | [diff] [blame] | 1103 | CloseHandle( h ); |
| 1104 | |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1105 | for (a1 = 0; a1 < 4; a1++) |
| 1106 | { |
| 1107 | for (s1 = 0; s1 < 4; s1++) |
| 1108 | { |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 1109 | h = CreateFileA( filename, access_modes[a1], sharing_modes[s1], |
| 1110 | NULL, OPEN_EXISTING, 0, 0 ); |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1111 | if (h == INVALID_HANDLE_VALUE) |
| 1112 | { |
| 1113 | ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError()); |
| 1114 | return; |
| 1115 | } |
| 1116 | for (a2 = 0; a2 < 4; a2++) |
| 1117 | { |
| 1118 | for (s2 = 0; s2 < 4; s2++) |
| 1119 | { |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 1120 | SetLastError(0xdeadbeef); |
| 1121 | h2 = CreateFileA( filename, access_modes[a2], sharing_modes[s2], |
| 1122 | NULL, OPEN_EXISTING, 0, 0 ); |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1123 | if (is_sharing_compatible( access_modes[a1], sharing_modes[s1], |
| 1124 | access_modes[a2], sharing_modes[s2] )) |
| 1125 | { |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1126 | ret = GetLastError(); |
| 1127 | ok( ERROR_SHARING_VIOLATION == ret || 0 == ret, |
| 1128 | "Windows 95 sets GetLastError() = ERROR_SHARING_VIOLATION and\n" |
| 1129 | " Windows XP GetLastError() = 0, but now it is %d.\n" |
| 1130 | " indexes = %d, %d, %d, %d\n" |
| 1131 | " modes =\n %lx/%lx/%lx/%lx\n", |
| 1132 | ret, |
| 1133 | a1, s1, a2, s2, |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1134 | access_modes[a1], sharing_modes[s1], |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1135 | access_modes[a2], sharing_modes[s2] |
| 1136 | ); |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1137 | } |
| 1138 | else |
| 1139 | { |
| 1140 | ok( h2 == INVALID_HANDLE_VALUE, |
| 1141 | "open succeeded for modes %lx/%lx/%lx/%lx\n", |
| 1142 | access_modes[a1], sharing_modes[s1], |
| 1143 | access_modes[a2], sharing_modes[s2] ); |
| 1144 | if (h2 == INVALID_HANDLE_VALUE) |
| 1145 | ok( GetLastError() == ERROR_SHARING_VIOLATION, |
| 1146 | "wrong error code %ld\n", GetLastError() ); |
| 1147 | } |
| 1148 | if (h2 != INVALID_HANDLE_VALUE) CloseHandle( h2 ); |
| 1149 | } |
| 1150 | } |
| 1151 | CloseHandle( h ); |
| 1152 | } |
| 1153 | } |
Dmitry Timoshkov | 405367a | 2005-03-01 10:42:04 +0000 | [diff] [blame] | 1154 | |
| 1155 | SetLastError(0xdeadbeef); |
| 1156 | h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, 0 ); |
| 1157 | ok( h != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError() ); |
| 1158 | |
| 1159 | SetLastError(0xdeadbeef); |
| 1160 | h2 = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 ); |
| 1161 | ok( h2 == INVALID_HANDLE_VALUE, "CreateFileA should fail\n"); |
| 1162 | ok( GetLastError() == ERROR_SHARING_VIOLATION, "wrong error code %ld\n", GetLastError() ); |
| 1163 | |
| 1164 | h2 = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); |
| 1165 | ok( h2 != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError() ); |
| 1166 | |
| 1167 | CloseHandle(h); |
| 1168 | CloseHandle(h2); |
| 1169 | |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1170 | DeleteFileA( filename ); |
| 1171 | } |
| 1172 | |
Stefan Huehner | ac6f562 | 2005-06-20 14:18:03 +0000 | [diff] [blame^] | 1173 | static char get_windows_drive(void) |
Filip Navara | c880c41 | 2004-08-30 18:40:20 +0000 | [diff] [blame] | 1174 | { |
| 1175 | char windowsdir[MAX_PATH]; |
| 1176 | GetWindowsDirectory(windowsdir, sizeof(windowsdir)); |
| 1177 | return windowsdir[0]; |
| 1178 | } |
| 1179 | |
Stefan Huehner | ac6f562 | 2005-06-20 14:18:03 +0000 | [diff] [blame^] | 1180 | static void test_FindFirstFileA(void) |
Uwe Bonnes | 0de21b6 | 2003-04-17 02:10:04 +0000 | [diff] [blame] | 1181 | { |
| 1182 | HANDLE handle; |
| 1183 | WIN32_FIND_DATAA search_results; |
| 1184 | int err; |
Filip Navara | c880c41 | 2004-08-30 18:40:20 +0000 | [diff] [blame] | 1185 | char buffer[5] = "C:\\"; |
Uwe Bonnes | 0de21b6 | 2003-04-17 02:10:04 +0000 | [diff] [blame] | 1186 | |
Filip Navara | c880c41 | 2004-08-30 18:40:20 +0000 | [diff] [blame] | 1187 | /* try FindFirstFileA on "C:\" */ |
| 1188 | buffer[0] = get_windows_drive(); |
| 1189 | handle = FindFirstFileA(buffer,&search_results); |
Uwe Bonnes | 0de21b6 | 2003-04-17 02:10:04 +0000 | [diff] [blame] | 1190 | err = GetLastError(); |
Filip Navara | c880c41 | 2004-08-30 18:40:20 +0000 | [diff] [blame] | 1191 | ok ( handle == INVALID_HANDLE_VALUE , "FindFirstFile on root directory should Fail\n"); |
Uwe Bonnes | 0de21b6 | 2003-04-17 02:10:04 +0000 | [diff] [blame] | 1192 | if (handle == INVALID_HANDLE_VALUE) |
Ferenc Wagner | 4b28f0f | 2003-10-21 23:42:50 +0000 | [diff] [blame] | 1193 | ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err); |
Filip Navara | c880c41 | 2004-08-30 18:40:20 +0000 | [diff] [blame] | 1194 | |
| 1195 | /* try FindFirstFileA on "C:\*" */ |
| 1196 | strcat(buffer, "*"); |
| 1197 | handle = FindFirstFileA(buffer,&search_results); |
| 1198 | ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s should succeed\n", buffer ); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1199 | ok ( FindClose(handle) == TRUE, "Failed to close handle\n"); |
Uwe Bonnes | 0de21b6 | 2003-04-17 02:10:04 +0000 | [diff] [blame] | 1200 | } |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1201 | |
Stefan Huehner | ac6f562 | 2005-06-20 14:18:03 +0000 | [diff] [blame^] | 1202 | static void test_FindNextFileA(void) |
Alex Pasadyn | 33854af | 2003-09-16 01:22:05 +0000 | [diff] [blame] | 1203 | { |
| 1204 | HANDLE handle; |
| 1205 | WIN32_FIND_DATAA search_results; |
| 1206 | int err; |
Filip Navara | c880c41 | 2004-08-30 18:40:20 +0000 | [diff] [blame] | 1207 | char buffer[5] = "C:\\*"; |
Alex Pasadyn | 33854af | 2003-09-16 01:22:05 +0000 | [diff] [blame] | 1208 | |
Filip Navara | c880c41 | 2004-08-30 18:40:20 +0000 | [diff] [blame] | 1209 | buffer[0] = get_windows_drive(); |
| 1210 | handle = FindFirstFileA(buffer,&search_results); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1211 | ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on C:\\* should succeed\n" ); |
Alex Pasadyn | 33854af | 2003-09-16 01:22:05 +0000 | [diff] [blame] | 1212 | while (FindNextFile(handle, &search_results)) |
| 1213 | { |
| 1214 | /* get to the end of the files */ |
| 1215 | } |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1216 | ok ( FindClose(handle) == TRUE, "Failed to close handle\n"); |
Alex Pasadyn | 33854af | 2003-09-16 01:22:05 +0000 | [diff] [blame] | 1217 | err = GetLastError(); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1218 | ok ( err == ERROR_NO_MORE_FILES, "GetLastError should return ERROR_NO_MORE_FILES\n"); |
Alex Pasadyn | 33854af | 2003-09-16 01:22:05 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1221 | static int test_Mapfile_createtemp(HANDLE *handle) |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1222 | { |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1223 | SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL); |
| 1224 | DeleteFile(filename); |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1225 | *handle = CreateFile(filename, GENERIC_READ|GENERIC_WRITE, 0, 0, |
| 1226 | CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 1227 | if (*handle != INVALID_HANDLE_VALUE) { |
| 1228 | |
| 1229 | return 1; |
| 1230 | } |
| 1231 | |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
Stefan Huehner | ac6f562 | 2005-06-20 14:18:03 +0000 | [diff] [blame^] | 1235 | static void test_MapFile(void) |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1236 | { |
| 1237 | HANDLE handle; |
| 1238 | HANDLE hmap; |
| 1239 | |
| 1240 | ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n"); |
| 1241 | |
| 1242 | hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0x1000, "named_file_map" ); |
| 1243 | ok( hmap != NULL, "mapping should work, I named it!\n" ); |
| 1244 | |
| 1245 | ok( CloseHandle( hmap ), "can't close mapping handle\n"); |
| 1246 | |
| 1247 | /* We have to close file before we try new stuff with mapping again. |
| 1248 | Else we would always succeed on XP or block descriptors on 95. */ |
| 1249 | hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL ); |
| 1250 | ok( hmap != NULL, "We should still be able to map!\n" ); |
| 1251 | ok( CloseHandle( hmap ), "can't close mapping handle\n"); |
| 1252 | ok( CloseHandle( handle ), "can't close file handle\n"); |
| 1253 | handle = NULL; |
| 1254 | |
| 1255 | ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n"); |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1256 | |
| 1257 | hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL ); |
| 1258 | ok( hmap == NULL, "mapped zero size file\n"); |
| 1259 | ok( GetLastError() == ERROR_FILE_INVALID, "not ERROR_FILE_INVALID\n"); |
| 1260 | |
| 1261 | hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0, NULL ); |
| 1262 | ok( hmap == NULL, "mapping should fail\n"); |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1263 | /* GetLastError() varies between win9x and WinNT and also depends on the filesystem */ |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1264 | |
| 1265 | hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0x10000, NULL ); |
| 1266 | ok( hmap == NULL, "mapping should fail\n"); |
Jakob Eriksson | c49b948 | 2004-04-28 03:52:02 +0000 | [diff] [blame] | 1267 | /* GetLastError() varies between win9x and WinNT and also depends on the filesystem */ |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1268 | |
Francois Gouget | f5c9da6 | 2005-05-06 15:44:31 +0000 | [diff] [blame] | 1269 | /* On XP you can now map again, on Win 95 you cannot. */ |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1270 | |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1271 | ok( CloseHandle( handle ), "can't close file handle\n"); |
Francois Gouget | ce7c3b5 | 2004-01-27 20:13:03 +0000 | [diff] [blame] | 1272 | ok( DeleteFileA( filename ), "DeleteFile failed after map\n" ); |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
Alexandre Julliard | 743997f | 2004-04-08 04:39:59 +0000 | [diff] [blame] | 1275 | static void test_GetFileType(void) |
| 1276 | { |
| 1277 | DWORD type; |
| 1278 | HANDLE h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 ); |
| 1279 | ok( h != INVALID_HANDLE_VALUE, "open %s failed\n", filename ); |
| 1280 | type = GetFileType(h); |
| 1281 | ok( type == FILE_TYPE_DISK, "expected type disk got %ld\n", type ); |
| 1282 | CloseHandle( h ); |
| 1283 | h = CreateFileA( "nul", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 ); |
| 1284 | ok( h != INVALID_HANDLE_VALUE, "open nul failed\n" ); |
| 1285 | type = GetFileType(h); |
| 1286 | ok( type == FILE_TYPE_CHAR, "expected type char for nul got %ld\n", type ); |
| 1287 | CloseHandle( h ); |
| 1288 | DeleteFileA( filename ); |
| 1289 | } |
| 1290 | |
Robert Shearman | eee6adc | 2004-08-19 02:34:51 +0000 | [diff] [blame] | 1291 | static int completion_count; |
| 1292 | |
| 1293 | static void CALLBACK FileIOComplete(DWORD dwError, DWORD dwBytes, LPOVERLAPPED ovl) |
| 1294 | { |
| 1295 | /* printf("(%ld, %ld, %p { %ld, %ld, %ld, %ld, %p })\n", dwError, dwBytes, ovl, ovl->Internal, ovl->InternalHigh, ovl->Offset, ovl->OffsetHigh, ovl->hEvent);*/ |
| 1296 | ReleaseSemaphore(ovl->hEvent, 1, NULL); |
| 1297 | completion_count++; |
| 1298 | } |
| 1299 | |
| 1300 | static void test_async_file_errors(void) |
| 1301 | { |
| 1302 | char szFile[MAX_PATH]; |
| 1303 | HANDLE hSem = CreateSemaphoreW(NULL, 1, 1, NULL); |
| 1304 | HANDLE hFile; |
| 1305 | LPVOID lpBuffer = HeapAlloc(GetProcessHeap(), 0, 4096); |
| 1306 | OVERLAPPED ovl; |
Dmitry Timoshkov | 75b93ff | 2005-03-17 19:00:08 +0000 | [diff] [blame] | 1307 | S(U(ovl)).Offset = 0; |
| 1308 | S(U(ovl)).OffsetHigh = 0; |
Robert Shearman | eee6adc | 2004-08-19 02:34:51 +0000 | [diff] [blame] | 1309 | ovl.hEvent = hSem; |
| 1310 | completion_count = 0; |
| 1311 | szFile[0] = '\0'; |
| 1312 | GetWindowsDirectoryA(szFile, sizeof(szFile)/sizeof(szFile[0])-1-strlen("\\win.ini")); |
| 1313 | strcat(szFile, "\\win.ini"); |
| 1314 | hFile = CreateFileA(szFile, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_FLAG_OVERLAPPED, NULL); |
| 1315 | ok(hFile != NULL, "CreateFileA(%s ...) failed\n", szFile); |
| 1316 | while (TRUE) |
| 1317 | { |
| 1318 | BOOL res; |
| 1319 | while (WaitForSingleObjectEx(hSem, INFINITE, TRUE) == WAIT_IO_COMPLETION) |
| 1320 | ; |
| 1321 | res = ReadFileEx(hFile, lpBuffer, 4096, &ovl, FileIOComplete); |
| 1322 | /*printf("Offset = %ld, result = %s\n", ovl.Offset, res ? "TRUE" : "FALSE");*/ |
| 1323 | if (!res) |
| 1324 | break; |
Dmitry Timoshkov | 75b93ff | 2005-03-17 19:00:08 +0000 | [diff] [blame] | 1325 | S(U(ovl)).Offset += 4096; |
Robert Shearman | eee6adc | 2004-08-19 02:34:51 +0000 | [diff] [blame] | 1326 | /* i/o completion routine only called if ReadFileEx returned success. |
| 1327 | * we only care about violations of this rule so undo what should have |
| 1328 | * been done */ |
| 1329 | completion_count--; |
| 1330 | } |
| 1331 | ok(completion_count == 0, "completion routine should only be called when ReadFileEx succeeds (this rule was violated %d times)\n", completion_count); |
| 1332 | /*printf("Error = %ld\n", GetLastError());*/ |
| 1333 | } |
| 1334 | |
Dmitry Timoshkov | e04da6b | 2004-11-28 14:58:11 +0000 | [diff] [blame] | 1335 | static void test_read_write(void) |
| 1336 | { |
| 1337 | DWORD bytes, ret; |
| 1338 | HANDLE hFile; |
| 1339 | char temp_path[MAX_PATH]; |
| 1340 | char filename[MAX_PATH]; |
| 1341 | static const char prefix[] = "pfx"; |
| 1342 | |
| 1343 | ret = GetTempPathA(MAX_PATH, temp_path); |
| 1344 | ok(ret != 0, "GetTempPathA error %ld\n", GetLastError()); |
| 1345 | ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n"); |
| 1346 | |
| 1347 | ret = GetTempFileNameA(temp_path, prefix, 0, filename); |
| 1348 | ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError()); |
| 1349 | |
| 1350 | hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, |
| 1351 | CREATE_ALWAYS, FILE_FLAG_RANDOM_ACCESS, 0); |
| 1352 | ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %ld\n", GetLastError()); |
| 1353 | |
| 1354 | SetLastError(12345678); |
| 1355 | bytes = 12345678; |
| 1356 | ret = WriteFile(hFile, NULL, 0, &bytes, NULL); |
| 1357 | ok(ret && GetLastError() == 12345678, |
| 1358 | "ret = %ld, error %ld\n", ret, GetLastError()); |
| 1359 | ok(!bytes, "bytes = %ld\n", bytes); |
| 1360 | |
| 1361 | SetLastError(12345678); |
| 1362 | bytes = 12345678; |
| 1363 | ret = WriteFile(hFile, NULL, 10, &bytes, NULL); |
| 1364 | ok((!ret && GetLastError() == ERROR_INVALID_USER_BUFFER) || /* Win2k */ |
| 1365 | (ret && GetLastError() == 12345678), /* Win9x */ |
| 1366 | "ret = %ld, error %ld\n", ret, GetLastError()); |
| 1367 | ok(!bytes || /* Win2k */ |
| 1368 | bytes == 10, /* Win9x */ |
| 1369 | "bytes = %ld\n", bytes); |
| 1370 | |
| 1371 | SetLastError(12345678); |
| 1372 | bytes = 12345678; |
| 1373 | ret = ReadFile(hFile, NULL, 0, &bytes, NULL); |
| 1374 | ok(ret && GetLastError() == 12345678, |
| 1375 | "ret = %ld, error %ld\n", ret, GetLastError()); |
| 1376 | ok(!bytes, "bytes = %ld\n", bytes); |
| 1377 | |
| 1378 | SetLastError(12345678); |
| 1379 | bytes = 12345678; |
| 1380 | ret = ReadFile(hFile, NULL, 10, &bytes, NULL); |
| 1381 | ok(!ret && (GetLastError() == ERROR_NOACCESS || /* Win2k */ |
| 1382 | GetLastError() == ERROR_INVALID_PARAMETER), /* Win9x */ |
| 1383 | "ret = %ld, error %ld\n", ret, GetLastError()); |
| 1384 | ok(!bytes, "bytes = %ld\n", bytes); |
| 1385 | |
Rein Klazes | 3714a39 | 2004-12-27 17:26:37 +0000 | [diff] [blame] | 1386 | ret = CloseHandle(hFile); |
| 1387 | ok( ret, "CloseHandle: error %ld\n", GetLastError()); |
| 1388 | ret = DeleteFileA(filename); |
| 1389 | ok( ret, "DeleteFileA: error %ld\n", GetLastError()); |
Dmitry Timoshkov | e04da6b | 2004-11-28 14:58:11 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 1392 | START_TEST(file) |
| 1393 | { |
| 1394 | test__hread( ); |
| 1395 | test__hwrite( ); |
| 1396 | test__lclose( ); |
Jakob Eriksson | b02f094 | 2002-05-06 20:12:55 +0000 | [diff] [blame] | 1397 | test__lcreat( ); |
| 1398 | test__llseek( ); |
| 1399 | test__llopen( ); |
Jakob Eriksson | e8449e6 | 2002-05-09 20:29:15 +0000 | [diff] [blame] | 1400 | test__lread( ); |
| 1401 | test__lwrite( ); |
Mike Hearn | 517248d | 2004-01-16 04:49:13 +0000 | [diff] [blame] | 1402 | test_GetTempFileNameA(); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 1403 | test_CopyFileA(); |
| 1404 | test_CopyFileW(); |
| 1405 | test_CreateFileA(); |
| 1406 | test_CreateFileW(); |
Ryan Cumming | c4aa073 | 2002-11-12 02:11:52 +0000 | [diff] [blame] | 1407 | test_DeleteFileA(); |
Francois Gouget | e948ad1 | 2002-12-12 03:54:01 +0000 | [diff] [blame] | 1408 | test_DeleteFileW(); |
Hans Leidekker | 7499242 | 2003-12-08 22:21:20 +0000 | [diff] [blame] | 1409 | test_MoveFileA(); |
| 1410 | test_MoveFileW(); |
Uwe Bonnes | 0de21b6 | 2003-04-17 02:10:04 +0000 | [diff] [blame] | 1411 | test_FindFirstFileA(); |
Alex Pasadyn | 33854af | 2003-09-16 01:22:05 +0000 | [diff] [blame] | 1412 | test_FindNextFileA(); |
Alexandre Julliard | ce61349 | 2003-03-18 05:04:33 +0000 | [diff] [blame] | 1413 | test_LockFile(); |
Alexandre Julliard | 74bd1e4 | 2004-03-27 20:48:42 +0000 | [diff] [blame] | 1414 | test_file_sharing(); |
Dmitry Timoshkov | 160ab19 | 2002-08-27 01:56:08 +0000 | [diff] [blame] | 1415 | test_offset_in_overlapped_structure(); |
Mike McCormack | f7b47f7 | 2004-01-09 00:34:37 +0000 | [diff] [blame] | 1416 | test_MapFile(); |
Alexandre Julliard | 743997f | 2004-04-08 04:39:59 +0000 | [diff] [blame] | 1417 | test_GetFileType(); |
Robert Shearman | eee6adc | 2004-08-19 02:34:51 +0000 | [diff] [blame] | 1418 | test_async_file_errors(); |
Dmitry Timoshkov | e04da6b | 2004-11-28 14:58:11 +0000 | [diff] [blame] | 1419 | test_read_write(); |
Jakob Eriksson | 3315199 | 2002-04-29 17:14:50 +0000 | [diff] [blame] | 1420 | } |