1 /* Unit tests for gioerror
2 * GIO - GLib Input, Output and Streaming Library
3 *
4 * Copyright (C) 2022 Marco Trevisan
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General
19 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 *
21 * Author: Marco Trevisan <marco.trevisan@canonical.com>
22 */
23
24 #include "config.h"
25 #include <errno.h>
26
27 #include <gio/gio.h>
28
29 #ifdef G_OS_WIN32
30 #include <winsock2.h>
31 #endif
32
33 /* We are testing some deprecated APIs here */
34 #ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
35 #define GLIB_DISABLE_DEPRECATION_WARNINGS
36 #endif
37
38 static void
39 test_error_from_errno (void)
40 {
41 g_assert_cmpint (g_io_error_from_errno (-1), ==, G_IO_ERROR_FAILED);
42
43 #ifdef EEXIST
44 g_assert_cmpint (g_io_error_from_errno (EEXIST), ==,
45 G_IO_ERROR_EXISTS);
46 #endif
47
48 #ifdef EISDIR
49 g_assert_cmpint (g_io_error_from_errno (EISDIR), ==,
50 G_IO_ERROR_IS_DIRECTORY);
51 #endif
52
53 #ifdef EACCES
54 g_assert_cmpint (g_io_error_from_errno (EACCES), ==,
55 G_IO_ERROR_PERMISSION_DENIED);
56 #endif
57
58 #ifdef ENAMETOOLONG
59 g_assert_cmpint (g_io_error_from_errno (ENAMETOOLONG), ==,
60 G_IO_ERROR_FILENAME_TOO_LONG);
61 #endif
62
63 #ifdef ENOENT
64 g_assert_cmpint (g_io_error_from_errno (ENOENT), ==,
65 G_IO_ERROR_NOT_FOUND);
66 #endif
67
68 #ifdef ENOTDIR
69 g_assert_cmpint (g_io_error_from_errno (ENOTDIR), ==,
70 G_IO_ERROR_NOT_DIRECTORY);
71 #endif
72
73 #ifdef ENXIO
74 g_assert_cmpint (g_io_error_from_errno (ENXIO), ==,
75 G_IO_ERROR_NOT_REGULAR_FILE);
76 #endif
77
78 #ifdef EROFS
79 g_assert_cmpint (g_io_error_from_errno (EROFS), ==,
80 G_IO_ERROR_READ_ONLY);
81 #endif
82
83 #ifdef ELOOP
84 g_assert_cmpint (g_io_error_from_errno (ELOOP), ==,
85 G_IO_ERROR_TOO_MANY_LINKS);
86 #endif
87
88 #ifdef EMLINK
89 g_assert_cmpint (g_io_error_from_errno (EMLINK), ==,
90 G_IO_ERROR_TOO_MANY_LINKS);
91 #endif
92
93 #ifdef ENOSPC
94 g_assert_cmpint (g_io_error_from_errno (ENOSPC), ==,
95 G_IO_ERROR_NO_SPACE);
96 #endif
97
98 #ifdef ENOMEM
99 g_assert_cmpint (g_io_error_from_errno (ENOMEM), ==,
100 G_IO_ERROR_NO_SPACE);
101 #endif
102
103 #ifdef EINVAL
104 g_assert_cmpint (g_io_error_from_errno (EINVAL), ==,
105 G_IO_ERROR_INVALID_ARGUMENT);
106 #endif
107
108 #ifdef EPERM
109 g_assert_cmpint (g_io_error_from_errno (EPERM), ==,
110 G_IO_ERROR_PERMISSION_DENIED);
111 #endif
112
113 #ifdef ECANCELED
114 g_assert_cmpint (g_io_error_from_errno (ECANCELED), ==,
115 G_IO_ERROR_CANCELLED);
116 #endif
117
118 #ifdef ENOTEMPTY
119 g_assert_cmpint (g_io_error_from_errno (ENOTEMPTY), ==,
120 G_IO_ERROR_NOT_EMPTY);
121 #endif
122
123 #ifdef ENOTSUP
124 g_assert_cmpint (g_io_error_from_errno (ENOTSUP), ==,
125 G_IO_ERROR_NOT_SUPPORTED);
126 #endif
127
128 #ifdef EOPNOTSUPP
129 g_assert_cmpint (g_io_error_from_errno (EOPNOTSUPP), ==,
130 G_IO_ERROR_NOT_SUPPORTED);
131 #endif
132
133 #ifdef EPROTONOSUPPORT
134 g_assert_cmpint (g_io_error_from_errno (EPROTONOSUPPORT), ==,
135 G_IO_ERROR_NOT_SUPPORTED);
136 #endif
137
138 #ifdef ESOCKTNOSUPPORT
139 g_assert_cmpint (g_io_error_from_errno (ESOCKTNOSUPPORT), ==,
140 G_IO_ERROR_NOT_SUPPORTED);
141 #endif
142
143 #ifdef EPFNOSUPPORT
144 g_assert_cmpint (g_io_error_from_errno (EPFNOSUPPORT), ==,
145 G_IO_ERROR_NOT_SUPPORTED);
146 #endif
147
148 #ifdef EAFNOSUPPORT
149 g_assert_cmpint (g_io_error_from_errno (EAFNOSUPPORT), ==,
150 G_IO_ERROR_NOT_SUPPORTED);
151 #endif
152
153 #ifdef ETIMEDOUT
154 g_assert_cmpint (g_io_error_from_errno (ETIMEDOUT), ==,
155 G_IO_ERROR_TIMED_OUT);
156 #endif
157
158 #ifdef EBUSY
159 g_assert_cmpint (g_io_error_from_errno (EBUSY), ==,
160 G_IO_ERROR_BUSY);
161 #endif
162
163 #ifdef EWOULDBLOCK
164 g_assert_cmpint (g_io_error_from_errno (EWOULDBLOCK), ==,
165 G_IO_ERROR_WOULD_BLOCK);
166 #endif
167
168 #ifdef EAGAIN
169 g_assert_cmpint (g_io_error_from_errno (EAGAIN), ==,
170 G_IO_ERROR_WOULD_BLOCK);
171 #endif
172
173 #ifdef EMFILE
174 g_assert_cmpint (g_io_error_from_errno (EMFILE), ==,
175 G_IO_ERROR_TOO_MANY_OPEN_FILES);
176 #endif
177
178 #ifdef EADDRINUSE
179 g_assert_cmpint (g_io_error_from_errno (EADDRINUSE), ==,
180 G_IO_ERROR_ADDRESS_IN_USE);
181 #endif
182
183 #ifdef EHOSTUNREACH
184 g_assert_cmpint (g_io_error_from_errno (EHOSTUNREACH), ==,
185 G_IO_ERROR_HOST_UNREACHABLE);
186 #endif
187
188 #ifdef ENETUNREACH
189 g_assert_cmpint (g_io_error_from_errno (ENETUNREACH), ==,
190 G_IO_ERROR_NETWORK_UNREACHABLE);
191 #endif
192
193 #ifdef ECONNREFUSED
194 g_assert_cmpint (g_io_error_from_errno (ECONNREFUSED), ==,
195 G_IO_ERROR_CONNECTION_REFUSED);
196 #endif
197
198 #ifdef EPIPE
199 g_assert_cmpint (g_io_error_from_errno (EPIPE), ==,
200 G_IO_ERROR_BROKEN_PIPE);
201 #endif
202
203 #ifdef ECONNRESET
204 g_assert_cmpint (g_io_error_from_errno (ECONNRESET), ==,
205 G_IO_ERROR_CONNECTION_CLOSED);
206 #endif
207
208 #ifdef ENOTCONN
209 g_assert_cmpint (g_io_error_from_errno (ENOTCONN), ==,
210 G_IO_ERROR_NOT_CONNECTED);
211 #endif
212
213 #ifdef EMSGSIZE
214 g_assert_cmpint (g_io_error_from_errno (EMSGSIZE), ==,
215 G_IO_ERROR_MESSAGE_TOO_LARGE);
216 #endif
217
218 #ifdef ENOTSOCK
219 g_assert_cmpint (g_io_error_from_errno (ENOTSOCK), ==,
220 G_IO_ERROR_INVALID_ARGUMENT);
221 #endif
222
223 #ifdef ESRCH
224 g_assert_cmpint (g_io_error_from_errno (ESRCH), ==,
225 G_IO_ERROR_FAILED);
226 #endif
227
228 #ifdef EINTR
229 g_assert_cmpint (g_io_error_from_errno (EINTR), ==,
230 G_IO_ERROR_FAILED);
231 #endif
232
233 #ifdef EIO
234 g_assert_cmpint (g_io_error_from_errno (EIO), ==,
235 G_IO_ERROR_FAILED);
236 #endif
237
238 #ifdef E2BIG
239 g_assert_cmpint (g_io_error_from_errno (E2BIG), ==,
240 G_IO_ERROR_FAILED);
241 #endif
242
243 #ifdef ENOEXEC
244 g_assert_cmpint (g_io_error_from_errno (ENOEXEC), ==,
245 G_IO_ERROR_FAILED);
246 #endif
247
248 #ifdef EBADF
249 g_assert_cmpint (g_io_error_from_errno (EBADF), ==,
250 G_IO_ERROR_FAILED);
251 #endif
252
253 #ifdef ECHILD
254 g_assert_cmpint (g_io_error_from_errno (ECHILD), ==,
255 G_IO_ERROR_FAILED);
256 #endif
257
258 #ifdef EFAULT
259 g_assert_cmpint (g_io_error_from_errno (EFAULT), ==,
260 G_IO_ERROR_FAILED);
261 #endif
262
263 #ifdef ENOTBLK
264 g_assert_cmpint (g_io_error_from_errno (ENOTBLK), ==,
265 G_IO_ERROR_FAILED);
266 #endif
267
268 #ifdef EXDEV
269 g_assert_cmpint (g_io_error_from_errno (EXDEV), ==,
270 G_IO_ERROR_FAILED);
271 #endif
272
273 #ifdef ENODEV
274 g_assert_cmpint (g_io_error_from_errno (ENODEV), ==,
275 G_IO_ERROR_NO_SUCH_DEVICE);
276 #endif
277
278 #ifdef ENFILE
279 g_assert_cmpint (g_io_error_from_errno (ENFILE), ==,
280 G_IO_ERROR_TOO_MANY_OPEN_FILES);
281 #endif
282
283 #ifdef ENOTTY
284 g_assert_cmpint (g_io_error_from_errno (ENOTTY), ==,
285 G_IO_ERROR_FAILED);
286 #endif
287
288 #ifdef ETXTBSY
289 g_assert_cmpint (g_io_error_from_errno (ETXTBSY), ==,
290 G_IO_ERROR_BUSY);
291 #endif
292
293 #ifdef EFBIG
294 g_assert_cmpint (g_io_error_from_errno (EFBIG), ==,
295 G_IO_ERROR_FAILED);
296 #endif
297
298 #ifdef ESPIPE
299 g_assert_cmpint (g_io_error_from_errno (ESPIPE), ==,
300 G_IO_ERROR_FAILED);
301 #endif
302
303 #ifdef EDOM
304 g_assert_cmpint (g_io_error_from_errno (EDOM), ==,
305 G_IO_ERROR_FAILED);
306 #endif
307
308 #ifdef ERANGE
309 g_assert_cmpint (g_io_error_from_errno (ERANGE), ==,
310 G_IO_ERROR_FAILED);
311 #endif
312
313 #ifdef EDEADLK
314 g_assert_cmpuint (g_io_error_from_errno (EDEADLK), ==,
315 G_IO_ERROR_FAILED);
316 #endif
317
318 #ifdef ENOLCK
319 g_assert_cmpuint (g_io_error_from_errno (ENOLCK), ==,
320 G_IO_ERROR_FAILED);
321 #endif
322
323 #ifdef ENOSYS
324 g_assert_cmpuint (g_io_error_from_errno (ENOSYS), ==,
325 G_IO_ERROR_NOT_SUPPORTED);
326 #endif
327
328 #ifdef ENOMSG
329 g_assert_cmpuint (g_io_error_from_errno (ENOMSG), ==,
330 G_IO_ERROR_INVALID_DATA);
331 #endif
332
333 #ifdef EIDRM
334 g_assert_cmpuint (g_io_error_from_errno (EIDRM), ==,
335 G_IO_ERROR_FAILED);
336 #endif
337
338 #ifdef ECHRNG
339 g_assert_cmpuint (g_io_error_from_errno (ECHRNG), ==,
340 G_IO_ERROR_FAILED);
341 #endif
342
343 #ifdef EL2NSYNC
344 g_assert_cmpuint (g_io_error_from_errno (EL2NSYNC), ==,
345 G_IO_ERROR_FAILED);
346 #endif
347
348 #ifdef EL3HLT
349 g_assert_cmpuint (g_io_error_from_errno (EL3HLT), ==,
350 G_IO_ERROR_FAILED);
351 #endif
352
353 #ifdef EL3RST
354 g_assert_cmpuint (g_io_error_from_errno (EL3RST), ==,
355 G_IO_ERROR_FAILED);
356 #endif
357
358 #ifdef ELNRNG
359 g_assert_cmpuint (g_io_error_from_errno (ELNRNG), ==,
360 G_IO_ERROR_FAILED);
361 #endif
362
363 #ifdef EUNATCH
364 g_assert_cmpuint (g_io_error_from_errno (EUNATCH), ==,
365 G_IO_ERROR_FAILED);
366 #endif
367
368 #ifdef ENOCSI
369 g_assert_cmpuint (g_io_error_from_errno (ENOCSI), ==,
370 G_IO_ERROR_FAILED);
371 #endif
372
373 #ifdef EL2HLT
374 g_assert_cmpuint (g_io_error_from_errno (EL2HLT), ==,
375 G_IO_ERROR_FAILED);
376 #endif
377
378 #ifdef EBADE
379 g_assert_cmpuint (g_io_error_from_errno (EBADE), ==,
380 G_IO_ERROR_FAILED);
381 #endif
382
383 #ifdef EBADR
384 g_assert_cmpuint (g_io_error_from_errno (EBADR), ==,
385 G_IO_ERROR_FAILED);
386 #endif
387
388 #ifdef EXFULL
389 g_assert_cmpuint (g_io_error_from_errno (EXFULL), ==,
390 G_IO_ERROR_FAILED);
391 #endif
392
393 #ifdef ENOANO
394 g_assert_cmpuint (g_io_error_from_errno (ENOANO), ==,
395 G_IO_ERROR_FAILED);
396 #endif
397
398 #ifdef EBADRQC
399 g_assert_cmpuint (g_io_error_from_errno (EBADRQC), ==,
400 G_IO_ERROR_FAILED);
401 #endif
402
403 #ifdef EBADSLT
404 g_assert_cmpuint (g_io_error_from_errno (EBADSLT), ==,
405 G_IO_ERROR_FAILED);
406 #endif
407
408 #ifdef EDEADLOCK
409 g_assert_cmpuint (g_io_error_from_errno (EDEADLOCK), ==,
410 G_IO_ERROR_FAILED);
411 #endif
412
413 #ifdef EBFONT
414 g_assert_cmpuint (g_io_error_from_errno (EBFONT), ==,
415 G_IO_ERROR_FAILED);
416 #endif
417
418 #ifdef ENOSTR
419 g_assert_cmpuint (g_io_error_from_errno (ENOSTR), ==,
420 G_IO_ERROR_FAILED);
421 #endif
422
423 #ifdef ENODATA
424 g_assert_cmpuint (g_io_error_from_errno (ENODATA), ==,
425 G_IO_ERROR_INVALID_DATA);
426 #endif
427
428 #ifdef ETIME
429 g_assert_cmpuint (g_io_error_from_errno (ETIME), ==,
430 G_IO_ERROR_FAILED);
431 #endif
432
433 #ifdef ENOSR
434 g_assert_cmpuint (g_io_error_from_errno (ENOSR), ==,
435 G_IO_ERROR_FAILED);
436 #endif
437
438 #ifdef ENONET
439 g_assert_cmpuint (g_io_error_from_errno (ENONET), ==,
440 G_IO_ERROR_FAILED);
441 #endif
442
443 #ifdef ENOPKG
444 g_assert_cmpuint (g_io_error_from_errno (ENOPKG), ==,
445 G_IO_ERROR_FAILED);
446 #endif
447
448 #ifdef EREMOTE
449 g_assert_cmpuint (g_io_error_from_errno (EREMOTE), ==,
450 G_IO_ERROR_FAILED);
451 #endif
452
453 #ifdef ENOLINK
454 g_assert_cmpuint (g_io_error_from_errno (ENOLINK), ==,
455 G_IO_ERROR_FAILED);
456 #endif
457
458 #ifdef EADV
459 g_assert_cmpuint (g_io_error_from_errno (EADV), ==,
460 G_IO_ERROR_FAILED);
461 #endif
462
463 #ifdef ESRMNT
464 g_assert_cmpuint (g_io_error_from_errno (ESRMNT), ==,
465 G_IO_ERROR_FAILED);
466 #endif
467
468 #ifdef ECOMM
469 g_assert_cmpuint (g_io_error_from_errno (ECOMM), ==,
470 G_IO_ERROR_FAILED);
471 #endif
472
473 #ifdef EPROTO
474 g_assert_cmpuint (g_io_error_from_errno (EPROTO), ==,
475 G_IO_ERROR_FAILED);
476 #endif
477
478 #ifdef EMULTIHOP
479 g_assert_cmpuint (g_io_error_from_errno (EMULTIHOP), ==,
480 G_IO_ERROR_FAILED);
481 #endif
482
483 #ifdef EDOTDOT
484 g_assert_cmpuint (g_io_error_from_errno (EDOTDOT), ==,
485 G_IO_ERROR_FAILED);
486 #endif
487
488 #ifdef EBADMSG
489 g_assert_cmpuint (g_io_error_from_errno (EBADMSG), ==,
490 G_IO_ERROR_INVALID_DATA);
491 #endif
492
493 #ifdef EOVERFLOW
494 g_assert_cmpuint (g_io_error_from_errno (EOVERFLOW), ==,
495 G_IO_ERROR_FAILED);
496 #endif
497
498 #ifdef ENOTUNIQ
499 g_assert_cmpuint (g_io_error_from_errno (ENOTUNIQ), ==,
500 G_IO_ERROR_FAILED);
501 #endif
502
503 #ifdef EBADFD
504 g_assert_cmpuint (g_io_error_from_errno (EBADFD), ==,
505 G_IO_ERROR_FAILED);
506 #endif
507
508 #ifdef EREMCHG
509 g_assert_cmpuint (g_io_error_from_errno (EREMCHG), ==,
510 G_IO_ERROR_FAILED);
511 #endif
512
513 #ifdef ELIBACC
514 g_assert_cmpuint (g_io_error_from_errno (ELIBACC), ==,
515 G_IO_ERROR_FAILED);
516 #endif
517
518 #ifdef ELIBBAD
519 g_assert_cmpuint (g_io_error_from_errno (ELIBBAD), ==,
520 G_IO_ERROR_FAILED);
521 #endif
522
523 #ifdef ELIBSCN
524 g_assert_cmpuint (g_io_error_from_errno (ELIBSCN), ==,
525 G_IO_ERROR_FAILED);
526 #endif
527
528 #ifdef ELIBMAX
529 g_assert_cmpuint (g_io_error_from_errno (ELIBMAX), ==,
530 G_IO_ERROR_FAILED);
531 #endif
532
533 #ifdef ELIBEXEC
534 g_assert_cmpuint (g_io_error_from_errno (ELIBEXEC), ==,
535 G_IO_ERROR_FAILED);
536 #endif
537
538 #ifdef EILSEQ
539 g_assert_cmpuint (g_io_error_from_errno (EILSEQ), ==,
540 G_IO_ERROR_FAILED);
541 #endif
542
543 #ifdef ERESTART
544 g_assert_cmpuint (g_io_error_from_errno (ERESTART), ==,
545 G_IO_ERROR_FAILED);
546 #endif
547
548 #ifdef ESTRPIPE
549 g_assert_cmpuint (g_io_error_from_errno (ESTRPIPE), ==,
550 G_IO_ERROR_FAILED);
551 #endif
552
553 #ifdef EUSERS
554 g_assert_cmpuint (g_io_error_from_errno (EUSERS), ==,
555 G_IO_ERROR_FAILED);
556 #endif
557
558 #ifdef EDESTADDRREQ
559 g_assert_cmpuint (g_io_error_from_errno (EDESTADDRREQ), ==,
560 G_IO_ERROR_DESTINATION_UNSET);
561 #endif
562
563 #ifdef EPROTOTYPE
564 g_assert_cmpuint (g_io_error_from_errno (EPROTOTYPE), ==,
565 G_IO_ERROR_FAILED);
566 #endif
567
568 #ifdef ENOPROTOOPT
569 g_assert_cmpuint (g_io_error_from_errno (ENOPROTOOPT), ==,
570 G_IO_ERROR_FAILED);
571 #endif
572
573 #ifdef EADDRNOTAVAIL
574 g_assert_cmpuint (g_io_error_from_errno (EADDRNOTAVAIL), ==,
575 G_IO_ERROR_FAILED);
576 #endif
577
578 #ifdef ENETDOWN
579 g_assert_cmpuint (g_io_error_from_errno (ENETDOWN), ==,
580 G_IO_ERROR_NETWORK_UNREACHABLE);
581 #endif
582
583 #ifdef ECONNABORTED
584 g_assert_cmpuint (g_io_error_from_errno (ECONNABORTED), ==,
585 G_IO_ERROR_FAILED);
586 #endif
587
588 #ifdef ENOBUFS
589 g_assert_cmpuint (g_io_error_from_errno (ENOBUFS), ==,
590 G_IO_ERROR_FAILED);
591 #endif
592
593 #ifdef EISCONN
594 g_assert_cmpuint (g_io_error_from_errno (EISCONN), ==,
595 G_IO_ERROR_FAILED);
596 #endif
597
598 #ifdef ESHUTDOWN
599 g_assert_cmpuint (g_io_error_from_errno (ESHUTDOWN), ==,
600 G_IO_ERROR_FAILED);
601 #endif
602
603 #ifdef ETOOMANYREFS
604 g_assert_cmpuint (g_io_error_from_errno (ETOOMANYREFS), ==,
605 G_IO_ERROR_FAILED);
606 #endif
607
608 #ifdef EHOSTDOWN
609 g_assert_cmpuint (g_io_error_from_errno (EHOSTDOWN), ==,
610 G_IO_ERROR_FAILED);
611 #endif
612
613 #ifdef EALREADY
614 g_assert_cmpuint (g_io_error_from_errno (EALREADY), ==,
615 G_IO_ERROR_FAILED);
616 #endif
617
618 #ifdef EINPROGRESS
619 g_assert_cmpuint (g_io_error_from_errno (EINPROGRESS), ==,
620 G_IO_ERROR_FAILED);
621 #endif
622
623 #ifdef ESTALE
624 g_assert_cmpuint (g_io_error_from_errno (ESTALE), ==,
625 G_IO_ERROR_FAILED);
626 #endif
627
628 #ifdef EUCLEAN
629 g_assert_cmpuint (g_io_error_from_errno (EUCLEAN), ==,
630 G_IO_ERROR_FAILED);
631 #endif
632
633 #ifdef ENOTNAM
634 g_assert_cmpuint (g_io_error_from_errno (ENOTNAM), ==,
635 G_IO_ERROR_FAILED);
636 #endif
637
638 #ifdef ENAVAIL
639 g_assert_cmpuint (g_io_error_from_errno (ENAVAIL), ==,
640 G_IO_ERROR_FAILED);
641 #endif
642
643 #ifdef EISNAM
644 g_assert_cmpuint (g_io_error_from_errno (EISNAM), ==,
645 G_IO_ERROR_FAILED);
646 #endif
647
648 #ifdef EREMOTEIO
649 g_assert_cmpuint (g_io_error_from_errno (EREMOTEIO), ==,
650 G_IO_ERROR_FAILED);
651 #endif
652
653 #ifdef EDQUOT
654 g_assert_cmpuint (g_io_error_from_errno (EDQUOT), ==,
655 G_IO_ERROR_FAILED);
656 #endif
657
658 #ifdef ENOMEDIUM
659 g_assert_cmpuint (g_io_error_from_errno (ENOMEDIUM), ==,
660 G_IO_ERROR_FAILED);
661 #endif
662
663 #ifdef EMEDIUMTYPE
664 g_assert_cmpuint (g_io_error_from_errno (EMEDIUMTYPE), ==,
665 G_IO_ERROR_FAILED);
666 #endif
667
668 #ifdef ENOKEY
669 g_assert_cmpuint (g_io_error_from_errno (ENOKEY), ==,
670 G_IO_ERROR_FAILED);
671 #endif
672
673 #ifdef EKEYEXPIRED
674 g_assert_cmpuint (g_io_error_from_errno (EKEYEXPIRED), ==,
675 G_IO_ERROR_FAILED);
676 #endif
677
678 #ifdef EKEYREVOKED
679 g_assert_cmpuint (g_io_error_from_errno (EKEYREVOKED), ==,
680 G_IO_ERROR_FAILED);
681 #endif
682
683 #ifdef EKEYREJECTED
684 g_assert_cmpuint (g_io_error_from_errno (EKEYREJECTED), ==,
685 G_IO_ERROR_FAILED);
686 #endif
687
688 #ifdef EOWNERDEAD
689 g_assert_cmpuint (g_io_error_from_errno (EOWNERDEAD), ==,
690 G_IO_ERROR_FAILED);
691 #endif
692
693 #ifdef ENOTRECOVERABLE
694 g_assert_cmpuint (g_io_error_from_errno (ENOTRECOVERABLE), ==,
695 G_IO_ERROR_FAILED);
696 #endif
697
698 #ifdef ERFKILL
699 g_assert_cmpuint (g_io_error_from_errno (ERFKILL), ==,
700 G_IO_ERROR_FAILED);
701 #endif
702
703 #ifdef EHWPOISON
704 g_assert_cmpuint (g_io_error_from_errno (EHWPOISON), ==,
705 G_IO_ERROR_FAILED);
706 #endif
707 }
708
709 static void
710 test_error_from_file_error (void)
711 {
712 g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
713 "*should not be reached*");
714 g_assert_cmpuint (g_io_error_from_file_error (-1), ==,
715 G_IO_ERROR_FAILED);
716 g_test_assert_expected_messages ();
717
718 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_EXIST), ==,
719 G_IO_ERROR_EXISTS);
720 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_ISDIR), ==,
721 G_IO_ERROR_IS_DIRECTORY);
722 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_ACCES), ==,
723 G_IO_ERROR_PERMISSION_DENIED);
724 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NAMETOOLONG), ==,
725 G_IO_ERROR_FILENAME_TOO_LONG);
726 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NOENT), ==,
727 G_IO_ERROR_NOT_FOUND);
728 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NOTDIR), ==,
729 G_IO_ERROR_NOT_DIRECTORY);
730 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NXIO), ==,
731 G_IO_ERROR_NOT_REGULAR_FILE);
732 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NODEV), ==,
733 G_IO_ERROR_NO_SUCH_DEVICE);
734 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_ROFS), ==,
735 G_IO_ERROR_READ_ONLY);
736 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_TXTBSY), ==,
737 G_IO_ERROR_BUSY);
738 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_LOOP), ==,
739 G_IO_ERROR_TOO_MANY_LINKS);
740 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NOSPC), ==,
741 G_IO_ERROR_NO_SPACE);
742 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NOMEM), ==,
743 G_IO_ERROR_NO_SPACE);
744 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_MFILE), ==,
745 G_IO_ERROR_TOO_MANY_OPEN_FILES);
746 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NFILE), ==,
747 G_IO_ERROR_TOO_MANY_OPEN_FILES);
748 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_INVAL), ==,
749 G_IO_ERROR_INVALID_ARGUMENT);
750 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_PIPE), ==,
751 G_IO_ERROR_BROKEN_PIPE);
752 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_AGAIN), ==,
753 G_IO_ERROR_WOULD_BLOCK);
754 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_PERM), ==,
755 G_IO_ERROR_PERMISSION_DENIED);
756 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_NOSYS), ==,
757 G_IO_ERROR_NOT_SUPPORTED);
758
759 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_BADF), ==,
760 G_IO_ERROR_FAILED);
761 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_FAILED), ==,
762 G_IO_ERROR_FAILED);
763 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_FAULT), ==,
764 G_IO_ERROR_FAILED);
765 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_INTR), ==,
766 G_IO_ERROR_FAILED);
767 g_assert_cmpuint (g_io_error_from_file_error (G_FILE_ERROR_IO), ==,
768 G_IO_ERROR_FAILED);
769 }
770
771 static void
772 test_error_from_win32_error (void)
773 {
774 #ifdef G_OS_WIN32
775 g_assert_cmpint (g_io_error_from_win32_error (-1), ==, G_IO_ERROR_FAILED);
776
777 g_assert_cmpint (g_io_error_from_win32_error (WSAEADDRINUSE), ==,
778 G_IO_ERROR_ADDRESS_IN_USE);
779
780 g_assert_cmpint (g_io_error_from_win32_error (WSAEWOULDBLOCK), ==,
781 G_IO_ERROR_WOULD_BLOCK);
782
783 g_assert_cmpint (g_io_error_from_win32_error (WSAEACCES), ==,
784 G_IO_ERROR_PERMISSION_DENIED);
785
786 g_assert_cmpint (g_io_error_from_win32_error (WSA_INVALID_HANDLE), ==,
787 G_IO_ERROR_INVALID_ARGUMENT);
788 g_assert_cmpint (g_io_error_from_win32_error (WSA_INVALID_PARAMETER), ==,
789 G_IO_ERROR_INVALID_ARGUMENT);
790 g_assert_cmpint (g_io_error_from_win32_error (WSAEINVAL), ==,
791 G_IO_ERROR_INVALID_ARGUMENT);
792 g_assert_cmpint (g_io_error_from_win32_error (WSAEBADF), ==,
793 G_IO_ERROR_INVALID_ARGUMENT);
794 g_assert_cmpint (g_io_error_from_win32_error (WSAENOTSOCK), ==,
795 G_IO_ERROR_INVALID_ARGUMENT);
796
797 g_assert_cmpint (g_io_error_from_win32_error (WSAEPROTONOSUPPORT), ==,
798 G_IO_ERROR_NOT_SUPPORTED);
799
800 g_assert_cmpint (g_io_error_from_win32_error (WSAECANCELLED), ==,
801 G_IO_ERROR_CANCELLED);
802
803 g_assert_cmpint (g_io_error_from_win32_error (WSAESOCKTNOSUPPORT), ==,
804 G_IO_ERROR_NOT_SUPPORTED);
805 g_assert_cmpint (g_io_error_from_win32_error (WSAEOPNOTSUPP), ==,
806 G_IO_ERROR_NOT_SUPPORTED);
807 g_assert_cmpint (g_io_error_from_win32_error (WSAEPFNOSUPPORT), ==,
808 G_IO_ERROR_NOT_SUPPORTED);
809 g_assert_cmpint (g_io_error_from_win32_error (WSAEAFNOSUPPORT), ==,
810 G_IO_ERROR_NOT_SUPPORTED);
811
812 g_assert_cmpint (g_io_error_from_win32_error (WSAECONNRESET), ==,
813 G_IO_ERROR_CONNECTION_CLOSED);
814 g_assert_cmpint (g_io_error_from_win32_error (WSAENETRESET), ==,
815 G_IO_ERROR_CONNECTION_CLOSED);
816 g_assert_cmpint (g_io_error_from_win32_error (WSAESHUTDOWN), ==,
817 G_IO_ERROR_CONNECTION_CLOSED);
818
819 g_assert_cmpint (g_io_error_from_win32_error (WSAEHOSTUNREACH), ==,
820 G_IO_ERROR_HOST_UNREACHABLE);
821
822 g_assert_cmpint (g_io_error_from_win32_error (WSAENETUNREACH), ==,
823 G_IO_ERROR_NETWORK_UNREACHABLE);
824
825 g_assert_cmpint (g_io_error_from_win32_error (WSAECONNREFUSED), ==,
826 G_IO_ERROR_CONNECTION_REFUSED);
827
828 g_assert_cmpint (g_io_error_from_win32_error (WSAETIMEDOUT), ==,
829 G_IO_ERROR_TIMED_OUT);
830
831 g_assert_cmpint (g_io_error_from_win32_error (WSAENOTCONN), ==,
832 G_IO_ERROR_NOT_CONNECTED);
833 g_assert_cmpint (g_io_error_from_win32_error (ERROR_PIPE_LISTENING), ==,
834 G_IO_ERROR_NOT_CONNECTED);
835
836 g_assert_cmpint (g_io_error_from_win32_error (WSAEMSGSIZE), ==,
837 G_IO_ERROR_MESSAGE_TOO_LARGE);
838 #else
839 g_test_skip ("Windows error codes can only be checked on Windows");
840 #endif /* G_OS_WIN32 */
841 }
842
843
844 int
845 main (int argc,
846 char *argv[])
847 {
848 g_setenv ("LC_ALL", "C", TRUE);
849 g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
850
851 g_test_add_func ("/error/from-errno", test_error_from_errno);
852 g_test_add_func ("/error/from-file-error", test_error_from_file_error);
853 g_test_add_func ("/error/from-win32-error", test_error_from_win32_error);
854
855 return g_test_run ();
856 }