| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- MODULE test_gerror ;
- (*
- m2-GTK4 test - GError handling and ownership helpers.
- Triggers a real GError by deleting a non-existent file, checks the
- message and the GIO error domain/code, copies/frees it, then clears
- it with GtkUtils.ClearError. Needs no display.
- *)
- FROM GioError IMPORT g_io_error_quark, GIOErrorNotFound;
- FROM GError IMPORT GError, g_error_matches, g_error_copy, g_error_free;
- FROM GFile IMPORT g_file_new_for_path, g_file_delete;
- FROM GtkUtils IMPORT ErrorMessage, ClearError, Unref;
- FROM SYSTEM IMPORT ADDRESS, ADR;
- FROM libc IMPORT printf;
- VAR
- failed: BOOLEAN;
- PROCEDURE Check (condition: BOOLEAN; what: ARRAY OF CHAR);
- BEGIN
- IF NOT condition THEN
- printf("FAIL: %s\n", what);
- failed := TRUE
- END
- END Check;
- VAR
- file: ADDRESS;
- err, copy: GError;
- buf: ARRAY [0..255] OF CHAR;
- BEGIN
- failed := FALSE;
- file := g_file_new_for_path("/no/such/m2gtk4/error/path");
- err := NIL;
- IF g_file_delete(file, NIL, ADR(err)) # 0 THEN
- Check(FALSE, "delete unexpectedly succeeded")
- END;
- Check(err # NIL, "error was set");
- IF err # NIL THEN
- ErrorMessage(err, buf);
- Check(buf[0] # 0C, "error message non-empty");
- Check(g_error_matches(err, g_io_error_quark(), GIOErrorNotFound) # 0,
- "error matches GIO_ERROR_NOT_FOUND");
- copy := g_error_copy(err);
- Check(copy # NIL, "g_error_copy");
- IF copy # NIL THEN g_error_free(copy) END;
- ClearError(err);
- Check(err = NIL, "ClearError set the variable to NIL")
- END;
- Unref(file);
- IF failed THEN
- printf("test_gerror: FAIL\n");
- HALT(1)
- ELSE
- printf("test_gerror: PASS\n");
- HALT(0)
- END
- END test_gerror.
|