1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11)
12
13// The type used for test case functions that take an extra pointer
14// argument.
15type TestDataFunc func(uintptr)
16
17// The type used for functions that operate on test fixtures.
18//
19// This is used for the fixture setup and teardown functions
20// as well as for the testcases themselves.
21//
22// @user_data is a pointer to the data that was given when
23// registering the test case.
24//
25// @fixture will be a pointer to the area of memory allocated by the
26// test framework, of the size requested. If the requested size was
27// zero then @fixture will be equal to @user_data.
28type TestFixtureFunc func(uintptr, uintptr)
29
30// The type used for test case functions.
31type TestFunc func()
32
33// Specifies the prototype of fatal log handler functions.
34type TestLogFatalFunc func(string, LogLevelFlags, string, uintptr) bool
35
36// An opaque structure representing a test case.
37type TestCase struct {
38 _ structs.HostLayout
39}
40
41func (x *TestCase) GoPointer() uintptr {
42 return uintptr(unsafe.Pointer(x))
43}
44
45var xTestCaseFree func(uintptr)
46
47// Free the @test_case.
48func (x *TestCase) Free() {
49
50 xTestCaseFree(x.GoPointer())
51
52}
53
54type TestConfig struct {
55 _ structs.HostLayout
56
57 TestInitialized bool
58
59 TestQuick bool
60
61 TestPerf bool
62
63 TestVerbose bool
64
65 TestQuiet bool
66
67 TestUndefined bool
68}
69
70func (x *TestConfig) GoPointer() uintptr {
71 return uintptr(unsafe.Pointer(x))
72}
73
74type TestLogBuffer struct {
75 _ structs.HostLayout
76
77 Data *String
78
79 Msgs *SList
80}
81
82func (x *TestLogBuffer) GoPointer() uintptr {
83 return uintptr(unsafe.Pointer(x))
84}
85
86var xTestLogBufferFree func(uintptr)
87
88// Internal function for gtester to free test log messages, no ABI guarantees provided.
89func (x *TestLogBuffer) Free() {
90
91 xTestLogBufferFree(x.GoPointer())
92
93}
94
95var xTestLogBufferPop func(uintptr) *TestLogMsg
96
97// Internal function for gtester to retrieve test log messages, no ABI guarantees provided.
98func (x *TestLogBuffer) Pop() *TestLogMsg {
99
100 cret := xTestLogBufferPop(x.GoPointer())
101 return cret
102}
103
104var xTestLogBufferPush func(uintptr, uint, byte)
105
106// Internal function for gtester to decode test log messages, no ABI guarantees provided.
107func (x *TestLogBuffer) Push(NBytesVar uint, BytesVar byte) {
108
109 xTestLogBufferPush(x.GoPointer(), NBytesVar, BytesVar)
110
111}
112
113type TestLogMsg struct {
114 _ structs.HostLayout
115
116 LogType TestLogType
117
118 NStrings uint
119
120 Strings uintptr
121
122 NNums uint
123
124 Nums float64
125}
126
127func (x *TestLogMsg) GoPointer() uintptr {
128 return uintptr(unsafe.Pointer(x))
129}
130
131var xTestLogMsgFree func(uintptr)
132
133// Internal function for gtester to free test log messages, no ABI guarantees provided.
134func (x *TestLogMsg) Free() {
135
136 xTestLogMsgFree(x.GoPointer())
137
138}
139
140// An opaque structure representing a test suite.
141type TestSuite struct {
142 _ structs.HostLayout
143}
144
145func (x *TestSuite) GoPointer() uintptr {
146 return uintptr(unsafe.Pointer(x))
147}
148
149var xTestSuiteAdd func(uintptr, *TestCase)
150
151// Adds @test_case to @suite.
152func (x *TestSuite) Add(TestCaseVar *TestCase) {
153
154 xTestSuiteAdd(x.GoPointer(), TestCaseVar)
155
156}
157
158var xTestSuiteAddSuite func(uintptr, *TestSuite)
159
160// Adds @nestedsuite to @suite.
161func (x *TestSuite) AddSuite(NestedsuiteVar *TestSuite) {
162
163 xTestSuiteAddSuite(x.GoPointer(), NestedsuiteVar)
164
165}
166
167var xTestSuiteFree func(uintptr)
168
169// Frees the @suite and all nested suites.
170func (x *TestSuite) Free() {
171
172 xTestSuiteFree(x.GoPointer())
173
174}
175
176const (
177 // A value that can be passed as an option to [func@GLib.test_init].
178 //
179 // Creates a unique temporary directory for each unit test and uses sets
180 // XDG directories to point into subdirectories of it for the duration of
181 // the unit test. The directory tree is cleaned up after the test finishes
182 // successfully.
183 //
184 // Note that this doesn’t take effect until [func@GLib.test_run] is called,
185 // so calls to (for example) [func@GLib.get_home_dir] will return the
186 // system-wide value when made in a test program’s main() function.
187 //
188 // The following functions will return subdirectories of the temporary directory
189 // when this option is used. The specific subdirectory paths in use are not
190 // guaranteed to be stable API — always use a getter function to retrieve them.
191 //
192 // - [func@GLib.get_home_dir]
193 // - [func@GLib.get_user_cache_dir]
194 // - [func@GLib.get_system_config_dirs]
195 // - [func@GLib.get_user_config_dir]
196 // - [func@GLib.get_system_data_dirs]
197 // - [func@GLib.get_user_data_dir]
198 // - [func@GLib.get_user_state_dir]
199 // - [func@GLib.get_user_runtime_dir]
200 //
201 // The subdirectories may not be created by the test harness; as with normal
202 // calls to functions like [func@GLib.get_user_cache_dir], the caller must
203 // be prepared to create the directory if it doesn’t exist.
204 TEST_OPTION_ISOLATE_DIRS string = "isolate_dirs"
205 // A value that can be passed as an option to [func@GLib.test_init].
206 //
207 // If this option is given, assertions will not abort the process, but
208 // call [func@GLib.test_fail]. Equivalent to [func@GLib.test_set_nonfatal_assertions].
209 TEST_OPTION_NONFATAL_ASSERTIONS string = "nonfatal-assertions"
210 // A value that can be passed as an option to [func@GLib.test_init].
211 //
212 // If this option is given, [func@GLib.test_init] will not call [func@GLib.set_prgname].
213 TEST_OPTION_NO_PRGNAME string = "no_g_set_prgname"
214)
215
216// Flags to pass to [func@GLib.test_trap_subprocess] to control input and output.
217//
218// Note that in contrast with [func@GLib.test_trap_fork], the default
219// behavior of [func@GLib.test_trap_subprocess] is to not show stdout
220// and stderr.
221type TestSubprocessFlags int
222
223const (
224
225 // Default behaviour. Since: 2.74
226 GTestSubprocessDefaultValue TestSubprocessFlags = 0
227 // If this flag is given, the child
228 // process will inherit the parent's stdin. Otherwise, the child's
229 // stdin is redirected to `/dev/null`.
230 GTestSubprocessInheritStdinValue TestSubprocessFlags = 1
231 // If this flag is given, the child
232 // process will inherit the parent's stdout. Otherwise, the child's
233 // stdout will not be visible, but it will be captured to allow
234 // later tests with [func@GLib.test_trap_assert_stdout].
235 GTestSubprocessInheritStdoutValue TestSubprocessFlags = 2
236 // If this flag is given, the child
237 // process will inherit the parent's stderr. Otherwise, the child's
238 // stderr will not be visible, but it will be captured to allow
239 // later tests with [func@GLib.test_trap_assert_stderr].
240 GTestSubprocessInheritStderrValue TestSubprocessFlags = 4
241)
242
243// Flags to pass to [func@GLib.test_trap_fork] to control input and output.
244//
245// Test traps are guards around forked tests. These flags determine what traps to set.
246type TestTrapFlags int
247
248const (
249
250 // Default behaviour. Since: 2.74
251 GTestTrapDefaultValue TestTrapFlags = 0
252 // Redirect stdout of the test child to
253 // `/dev/null` so it cannot be observed on the console during test
254 // runs. The actual output is still captured though to allow later
255 // tests with g_test_trap_assert_stdout().
256 GTestTrapSilenceStdoutValue TestTrapFlags = 128
257 // Redirect stderr of the test child to
258 // `/dev/null` so it cannot be observed on the console during test
259 // runs. The actual output is still captured though to allow later
260 // tests with g_test_trap_assert_stderr().
261 GTestTrapSilenceStderrValue TestTrapFlags = 256
262 // If this flag is given, stdin of the
263 // child process is shared with stdin of its parent process.
264 // It is redirected to `/dev/null` otherwise.
265 GTestTrapInheritStdinValue TestTrapFlags = 512
266)
267
268// The type of file to return the filename for, when used with
269// [func@GLib.test_build_filename].
270//
271// These two options correspond rather directly to the 'dist' and
272// 'built' terminology that automake uses and are explicitly used to
273// distinguish between the 'srcdir' and 'builddir' being separate. All
274// files in your project should either be dist (in the `EXTRA_DIST` or
275// `dist_schema_DATA` sense, in which case they will always be in the
276// srcdir) or built (in the `BUILT_SOURCES` sense, in which case they
277// will always be in the builddir).
278//
279// Note: As a general rule of automake, files that are generated only as
280// part of the build-from-git process (but then are distributed with the
281// tarball) always go in srcdir (even if doing a srcdir != builddir
282// build from git) and are considered as distributed files.
283//
284// The same principles apply for other build systems, such as meson.
285type TestFileType int
286
287const (
288
289 // a file that was included in the distribution tarball
290 GTestDistValue TestFileType = 0
291 // a file that was built on the compiling machine
292 GTestBuiltValue TestFileType = 1
293)
294
295type TestLogType int
296
297const (
298 GTestLogNoneValue TestLogType = 0
299
300 GTestLogErrorValue TestLogType = 1
301
302 GTestLogStartBinaryValue TestLogType = 2
303
304 GTestLogListCaseValue TestLogType = 3
305
306 GTestLogSkipCaseValue TestLogType = 4
307
308 GTestLogStartCaseValue TestLogType = 5
309
310 GTestLogStopCaseValue TestLogType = 6
311
312 GTestLogMinResultValue TestLogType = 7
313
314 GTestLogMaxResultValue TestLogType = 8
315
316 GTestLogMessageValue TestLogType = 9
317
318 GTestLogStartSuiteValue TestLogType = 10
319
320 GTestLogStopSuiteValue TestLogType = 11
321)
322
323type TestResult int
324
325const (
326 GTestRunSuccessValue TestResult = 0
327
328 GTestRunSkippedValue TestResult = 1
329
330 GTestRunFailureValue TestResult = 2
331
332 GTestRunIncompleteValue TestResult = 3
333)
334
335var xAssertionMessage func(string, string, int, string, string)
336
337func AssertionMessage(DomainVar string, FileVar string, LineVar int, FuncVar string, MessageVar string) {
338
339 xAssertionMessage(DomainVar, FileVar, LineVar, FuncVar, MessageVar)
340
341}
342
343var xAssertionMessageCmpint func(string, string, int, string, string, uint64, string, uint64, byte)
344
345func AssertionMessageCmpint(DomainVar string, FileVar string, LineVar int, FuncVar string, ExprVar string, Arg1Var uint64, CmpVar string, Arg2Var uint64, NumtypeVar byte) {
346
347 xAssertionMessageCmpint(DomainVar, FileVar, LineVar, FuncVar, ExprVar, Arg1Var, CmpVar, Arg2Var, NumtypeVar)
348
349}
350
351var xAssertionMessageCmpnum func(string, string, int, string, string, float64, string, float64, byte)
352
353func AssertionMessageCmpnum(DomainVar string, FileVar string, LineVar int, FuncVar string, ExprVar string, Arg1Var float64, CmpVar string, Arg2Var float64, NumtypeVar byte) {
354
355 xAssertionMessageCmpnum(DomainVar, FileVar, LineVar, FuncVar, ExprVar, Arg1Var, CmpVar, Arg2Var, NumtypeVar)
356
357}
358
359var xAssertionMessageCmpstr func(string, string, int, string, string, string, string, string)
360
361func AssertionMessageCmpstr(DomainVar string, FileVar string, LineVar int, FuncVar string, ExprVar string, Arg1Var string, CmpVar string, Arg2Var string) {
362
363 xAssertionMessageCmpstr(DomainVar, FileVar, LineVar, FuncVar, ExprVar, Arg1Var, CmpVar, Arg2Var)
364
365}
366
367var xAssertionMessageCmpstrv func(string, string, int, string, string, string, string, uint)
368
369func AssertionMessageCmpstrv(DomainVar string, FileVar string, LineVar int, FuncVar string, ExprVar string, Arg1Var string, Arg2Var string, FirstWrongIdxVar uint) {
370
371 xAssertionMessageCmpstrv(DomainVar, FileVar, LineVar, FuncVar, ExprVar, Arg1Var, Arg2Var, FirstWrongIdxVar)
372
373}
374
375var xAssertionMessageError func(string, string, int, string, string, *Error, Quark, int)
376
377func AssertionMessageError(DomainVar string, FileVar string, LineVar int, FuncVar string, ExprVar string, ErrorVar *Error, ErrorDomainVar Quark, ErrorCodeVar int) {
378
379 xAssertionMessageError(DomainVar, FileVar, LineVar, FuncVar, ExprVar, ErrorVar, ErrorDomainVar, ErrorCodeVar)
380
381}
382
383var xAssertionMessageExpr func(uintptr, string, int, string, uintptr)
384
385// Internal function used to print messages from the public
386// g_assert() and g_assert_not_reached() macros.
387func AssertionMessageExpr(DomainVar *string, FileVar string, LineVar int, FuncVar string, ExprVar *string) {
388
389 DomainVarPtr := core.GStrdupNullable(DomainVar)
390 defer core.GFreeNullable(DomainVarPtr)
391
392 ExprVarPtr := core.GStrdupNullable(ExprVar)
393 defer core.GFreeNullable(ExprVarPtr)
394
395 xAssertionMessageExpr(DomainVarPtr, FileVar, LineVar, FuncVar, ExprVarPtr)
396
397}
398
399var xStrcmp0 func(uintptr, uintptr) int
400
401// Compares @str1 and @str2 like `strcmp()`.
402//
403// Handles `NULL` gracefully by sorting it before non-`NULL` strings.
404// Comparing two `NULL` pointers returns 0.
405func Strcmp0(Str1Var *string, Str2Var *string) int {
406
407 Str1VarPtr := core.GStrdupNullable(Str1Var)
408 defer core.GFreeNullable(Str1VarPtr)
409
410 Str2VarPtr := core.GStrdupNullable(Str2Var)
411 defer core.GFreeNullable(Str2VarPtr)
412
413 cret := xStrcmp0(Str1VarPtr, Str2VarPtr)
414
415 return cret
416}
417
418var xTestAddDataFunc func(string, uintptr, uintptr)
419
420// Creates a new test case.
421//
422// This function is similar to [func@GLib.test_create_case].
423// However the test is assumed to use no fixture, and test suites are
424// automatically created on the fly and added to the root fixture,
425// based on the /-separated portions of @testpath. The @test_data
426// argument will be passed as first argument to @test_func.
427//
428// If @testpath includes the component "subprocess" anywhere in it,
429// the test will be skipped by default, and only run if explicitly
430// required via the `-p` command-line option or [func@GLib.test_trap_subprocess].
431//
432// No component of @testpath may start with a dot (`.`) if the
433// [const@GLib.TEST_OPTION_ISOLATE_DIRS] option is being used;
434// and it is recommended to do so even if it isn’t.
435func TestAddDataFunc(TestpathVar string, TestDataVar uintptr, TestFuncVar *TestDataFunc) {
436
437 var TestFuncVarRef uintptr
438 if TestFuncVar != nil {
439 TestFuncVarPtr := uintptr(unsafe.Pointer(TestFuncVar))
440 if cbRefPtr, ok := GetCallback(TestFuncVarPtr); ok {
441 TestFuncVarRef = cbRefPtr
442 } else {
443 fcb := func(arg0 uintptr) {
444 cbFn := *TestFuncVar
445 cbFn(arg0)
446 }
447 TestFuncVarRef = purego.NewCallback(fcb)
448 SaveCallbackWithClosure(TestFuncVarPtr, TestFuncVarRef, TestFuncVar)
449 }
450 }
451
452 xTestAddDataFunc(TestpathVar, TestDataVar, TestFuncVarRef)
453
454}
455
456var xTestAddDataFuncFull func(string, uintptr, uintptr, uintptr)
457
458// Creates a new test case.
459//
460// In contrast to [func@GLib.test_add_data_func], this function
461// is freeing @test_data after the test run is complete.
462func TestAddDataFuncFull(TestpathVar string, TestDataVar uintptr, TestFuncVar *TestDataFunc, DataFreeFuncVar *DestroyNotify) {
463
464 var TestFuncVarRef uintptr
465 if TestFuncVar != nil {
466 TestFuncVarPtr := uintptr(unsafe.Pointer(TestFuncVar))
467 if cbRefPtr, ok := GetCallback(TestFuncVarPtr); ok {
468 TestFuncVarRef = cbRefPtr
469 } else {
470 fcb := func(arg0 uintptr) {
471 cbFn := *TestFuncVar
472 cbFn(arg0)
473 }
474 TestFuncVarRef = purego.NewCallback(fcb)
475 SaveCallbackWithClosure(TestFuncVarPtr, TestFuncVarRef, TestFuncVar)
476 }
477 }
478
479 var DataFreeFuncVarRef uintptr
480 if DataFreeFuncVar != nil {
481 DataFreeFuncVarPtr := uintptr(unsafe.Pointer(DataFreeFuncVar))
482 if cbRefPtr, ok := GetCallback(DataFreeFuncVarPtr); ok {
483 DataFreeFuncVarRef = cbRefPtr
484 } else {
485 fcb := func(arg0 uintptr) {
486 cbFn := *DataFreeFuncVar
487 cbFn(arg0)
488 }
489 DataFreeFuncVarRef = purego.NewCallback(fcb)
490 SaveCallbackWithClosure(DataFreeFuncVarPtr, DataFreeFuncVarRef, DataFreeFuncVar)
491 }
492 }
493
494 xTestAddDataFuncFull(TestpathVar, TestDataVar, TestFuncVarRef, DataFreeFuncVarRef)
495
496}
497
498var xTestAddFunc func(string, uintptr)
499
500// Creates a new test case.
501//
502// This function is similar to [func@GLib.test_create_case].
503// However the test is assumed to use no fixture, and test suites are
504// automatically created on the fly and added to the root fixture,
505// based on the /-separated portions of @testpath.
506//
507// If @testpath includes the component "subprocess" anywhere in it,
508// the test will be skipped by default, and only run if explicitly
509// required via the `-p` command-line option or [func@GLib.test_trap_subprocess].
510//
511// No component of @testpath may start with a dot (`.`) if the
512// [const@GLib.TEST_OPTION_ISOLATE_DIRS] option is being used; and
513// it is recommended to do so even if it isn’t.
514func TestAddFunc(TestpathVar string, TestFuncVar *TestFunc) {
515
516 var TestFuncVarRef uintptr
517 if TestFuncVar != nil {
518 TestFuncVarPtr := uintptr(unsafe.Pointer(TestFuncVar))
519 if cbRefPtr, ok := GetCallback(TestFuncVarPtr); ok {
520 TestFuncVarRef = cbRefPtr
521 } else {
522 fcb := func() {
523 cbFn := *TestFuncVar
524 cbFn()
525 }
526 TestFuncVarRef = purego.NewCallback(fcb)
527 SaveCallbackWithClosure(TestFuncVarPtr, TestFuncVarRef, TestFuncVar)
528 }
529 }
530
531 xTestAddFunc(TestpathVar, TestFuncVarRef)
532
533}
534
535var xTestAddVtable func(string, uint, uintptr, uintptr, uintptr, uintptr)
536
537func TestAddVtable(TestpathVar string, DataSizeVar uint, TestDataVar uintptr, DataSetupVar *TestFixtureFunc, DataTestVar *TestFixtureFunc, DataTeardownVar *TestFixtureFunc) {
538
539 var DataSetupVarRef uintptr
540 if DataSetupVar != nil {
541 DataSetupVarPtr := uintptr(unsafe.Pointer(DataSetupVar))
542 if cbRefPtr, ok := GetCallback(DataSetupVarPtr); ok {
543 DataSetupVarRef = cbRefPtr
544 } else {
545 fcb := func(arg0 uintptr, arg1 uintptr) {
546 cbFn := *DataSetupVar
547 cbFn(arg0, arg1)
548 }
549 DataSetupVarRef = purego.NewCallback(fcb)
550 SaveCallbackWithClosure(DataSetupVarPtr, DataSetupVarRef, DataSetupVar)
551 }
552 }
553
554 var DataTestVarRef uintptr
555 if DataTestVar != nil {
556 DataTestVarPtr := uintptr(unsafe.Pointer(DataTestVar))
557 if cbRefPtr, ok := GetCallback(DataTestVarPtr); ok {
558 DataTestVarRef = cbRefPtr
559 } else {
560 fcb := func(arg0 uintptr, arg1 uintptr) {
561 cbFn := *DataTestVar
562 cbFn(arg0, arg1)
563 }
564 DataTestVarRef = purego.NewCallback(fcb)
565 SaveCallbackWithClosure(DataTestVarPtr, DataTestVarRef, DataTestVar)
566 }
567 }
568
569 var DataTeardownVarRef uintptr
570 if DataTeardownVar != nil {
571 DataTeardownVarPtr := uintptr(unsafe.Pointer(DataTeardownVar))
572 if cbRefPtr, ok := GetCallback(DataTeardownVarPtr); ok {
573 DataTeardownVarRef = cbRefPtr
574 } else {
575 fcb := func(arg0 uintptr, arg1 uintptr) {
576 cbFn := *DataTeardownVar
577 cbFn(arg0, arg1)
578 }
579 DataTeardownVarRef = purego.NewCallback(fcb)
580 SaveCallbackWithClosure(DataTeardownVarPtr, DataTeardownVarRef, DataTeardownVar)
581 }
582 }
583
584 xTestAddVtable(TestpathVar, DataSizeVar, TestDataVar, DataSetupVarRef, DataTestVarRef, DataTeardownVarRef)
585
586}
587
588var xTestAssertExpectedMessagesInternal func(string, string, int, string)
589
590func TestAssertExpectedMessagesInternal(DomainVar string, FileVar string, LineVar int, FuncVar string) {
591
592 xTestAssertExpectedMessagesInternal(DomainVar, FileVar, LineVar, FuncVar)
593
594}
595
596var xTestBug func(string)
597
598// Adds a message to test reports that associates a bug URI with a test case.
599//
600// Bug URIs are constructed from a base URI set with [func@GLib.test_bug_base]
601// and @bug_uri_snippet. If [func@GLib.test_bug_base] has not been called, it is
602// assumed to be the empty string, so a full URI can be provided to
603// [func@GLib.test_bug] instead.
604//
605// See also [func@GLib.test_summary].
606//
607// Since GLib 2.70, the base URI is not prepended to @bug_uri_snippet
608// if it is already a valid URI.
609func TestBug(BugUriSnippetVar string) {
610
611 xTestBug(BugUriSnippetVar)
612
613}
614
615var xTestBugBase func(string)
616
617// Specifies the base URI for bug reports.
618//
619// The base URI is used to construct bug report messages for
620// [func@GLib.test_message] when [func@GLib.test_bug] is called.
621// Calling this function outside of a test case sets the
622// default base URI for all test cases. Calling it from within
623// a test case changes the base URI for the scope of the test
624// case only.
625// Bug URIs are constructed by appending a bug specific URI
626// portion to @uri_pattern, or by replacing the special string
627// `%s` within @uri_pattern if that is present.
628//
629// If [func@GLib.test_bug_base] is not called, bug URIs are formed
630// solely from the value provided by [func@GLib.test_bug].
631func TestBugBase(UriPatternVar string) {
632
633 xTestBugBase(UriPatternVar)
634
635}
636
637var xTestBuildFilename func(TestFileType, string, ...interface{}) string
638
639// Creates the pathname to a data file that is required for a test.
640//
641// This function is conceptually similar to [func@GLib.build_filename]
642// except that the first argument has been replaced with a
643// [enum@GLib.TestFileType] argument.
644//
645// The data file should either have been distributed with the module
646// containing the test ([enum@GLib.TestFileType.dist] or built as part of the
647// buildcsystem of that module ([enum@GLib.TestFileType.built]).
648//
649// In order for this function to work in srcdir != builddir situations,
650// the `G_TEST_SRCDIR` and `G_TEST_BUILDDIR` environment variables need
651// to have been defined. As of 2.38, this is done by the glib.mk that is
652// included in GLib. Please ensure that your copy is up to date before
653// using this function.
654//
655// In case neither variable is set, this function will fall back to
656// using the dirname portion of `argv[0]`, possibly removing ".libs".
657// This allows for casual running of tests directly from the commandline
658// in the srcdir == builddir case and should also support running of
659// installed tests, assuming the data files have been installed in the
660// same relative path as the test binary.
661func TestBuildFilename(FileTypeVar TestFileType, FirstPathVar string, varArgs ...interface{}) string {
662
663 cret := xTestBuildFilename(FileTypeVar, FirstPathVar, varArgs...)
664
665 return cret
666}
667
668var xTestCreateCase func(string, uint, uintptr, uintptr, uintptr, uintptr) *TestCase
669
670// Creates a new [struct@GLib.TestCase].
671//
672// This API is fairly low level, and calling [func@GLib.test_add] or
673// [func@GLib.test_add_func] is preferable.
674//
675// When this test is executed, a fixture structure of size @data_size
676// will be automatically allocated and filled with zeros. Then @data_setup
677// is called to initialize the fixture. After fixture setup, the actual test
678// function @data_test is called. Once the test run completes, the
679// fixture structure is torn down by calling @data_teardown and after
680// that the memory is automatically released by the test framework.
681//
682// Splitting up a test run into fixture setup, test function and
683// fixture teardown is most useful if the same fixture type is used for
684// multiple tests. In this cases, [func@GLib.test_create_case] will be
685// called with the same type of fixture (the @data_size argument), but
686// varying @test_name and @data_test arguments.
687func TestCreateCase(TestNameVar string, DataSizeVar uint, TestDataVar uintptr, DataSetupVar *TestFixtureFunc, DataTestVar *TestFixtureFunc, DataTeardownVar *TestFixtureFunc) *TestCase {
688
689 var DataSetupVarRef uintptr
690 if DataSetupVar != nil {
691 DataSetupVarPtr := uintptr(unsafe.Pointer(DataSetupVar))
692 if cbRefPtr, ok := GetCallback(DataSetupVarPtr); ok {
693 DataSetupVarRef = cbRefPtr
694 } else {
695 fcb := func(arg0 uintptr, arg1 uintptr) {
696 cbFn := *DataSetupVar
697 cbFn(arg0, arg1)
698 }
699 DataSetupVarRef = purego.NewCallback(fcb)
700 SaveCallbackWithClosure(DataSetupVarPtr, DataSetupVarRef, DataSetupVar)
701 }
702 }
703
704 var DataTestVarRef uintptr
705 if DataTestVar != nil {
706 DataTestVarPtr := uintptr(unsafe.Pointer(DataTestVar))
707 if cbRefPtr, ok := GetCallback(DataTestVarPtr); ok {
708 DataTestVarRef = cbRefPtr
709 } else {
710 fcb := func(arg0 uintptr, arg1 uintptr) {
711 cbFn := *DataTestVar
712 cbFn(arg0, arg1)
713 }
714 DataTestVarRef = purego.NewCallback(fcb)
715 SaveCallbackWithClosure(DataTestVarPtr, DataTestVarRef, DataTestVar)
716 }
717 }
718
719 var DataTeardownVarRef uintptr
720 if DataTeardownVar != nil {
721 DataTeardownVarPtr := uintptr(unsafe.Pointer(DataTeardownVar))
722 if cbRefPtr, ok := GetCallback(DataTeardownVarPtr); ok {
723 DataTeardownVarRef = cbRefPtr
724 } else {
725 fcb := func(arg0 uintptr, arg1 uintptr) {
726 cbFn := *DataTeardownVar
727 cbFn(arg0, arg1)
728 }
729 DataTeardownVarRef = purego.NewCallback(fcb)
730 SaveCallbackWithClosure(DataTeardownVarPtr, DataTeardownVarRef, DataTeardownVar)
731 }
732 }
733
734 cret := xTestCreateCase(TestNameVar, DataSizeVar, TestDataVar, DataSetupVarRef, DataTestVarRef, DataTeardownVarRef)
735
736 return cret
737}
738
739var xTestCreateSuite func(string) *TestSuite
740
741// Creates a new test suite with the name @suite_name.
742func TestCreateSuite(SuiteNameVar string) *TestSuite {
743
744 cret := xTestCreateSuite(SuiteNameVar)
745
746 return cret
747}
748
749var xTestDisableCrashReporting func()
750
751// Attempts to disable system crash reporting infrastructure.
752//
753// This function should be called before exercising code paths that are
754// expected or intended to crash, to avoid wasting resources in system-wide
755// crash collection infrastructure such as systemd-coredump or abrt.
756func TestDisableCrashReporting() {
757
758 xTestDisableCrashReporting()
759
760}
761
762var xTestExpectMessage func(uintptr, LogLevelFlags, string)
763
764// Indicates that a message with the given @log_domain and @log_level,
765// with text matching @pattern, is expected to be logged.
766//
767// When this message is logged, it will not be printed, and the test case will
768// not abort.
769//
770// This API may only be used with the old logging API ([func@GLib.log] without
771// `G_LOG_USE_STRUCTURED` defined). It will not work with the structured logging
772// API. See [Testing for Messages](logging.html#testing-for-messages).
773//
774// Use [func@GLib.test_assert_expected_messages] to assert that all
775// previously-expected messages have been seen and suppressed.
776//
777// You can call this multiple times in a row, if multiple messages are
778// expected as a result of a single call. (The messages must appear in
779// the same order as the calls to [func@GLib.test_expect_message].)
780//
781// For example:
782//
783// ```c
784// // g_main_context_push_thread_default() should fail if the
785// // context is already owned by another thread.
786// g_test_expect_message (G_LOG_DOMAIN,
787//
788// G_LOG_LEVEL_CRITICAL,
789// "assertion*acquired_context*failed");
790//
791// g_main_context_push_thread_default (bad_context);
792// g_test_assert_expected_messages ();
793// ```
794//
795// Note that you cannot use this to test [func@GLib.error] messages, since
796// [func@GLib.error] intentionally never returns even if the program doesn’t
797// abort; use [func@GLib.test_trap_subprocess] in this case.
798//
799// If messages at [flags@GLib.LogLevelFlags.LEVEL_DEBUG] are emitted, but not explicitly
800// expected via [func@GLib.test_expect_message] then they will be ignored.
801func TestExpectMessage(LogDomainVar *string, LogLevelVar LogLevelFlags, PatternVar string) {
802
803 LogDomainVarPtr := core.GStrdupNullable(LogDomainVar)
804 defer core.GFreeNullable(LogDomainVarPtr)
805
806 xTestExpectMessage(LogDomainVarPtr, LogLevelVar, PatternVar)
807
808}
809
810var xTestFail func()
811
812// Indicates that a test failed.
813//
814// This function can be called multiple times from the same test.
815// You can use this function if your test failed in a recoverable way.
816//
817// Do not use this function if the failure of a test could cause
818// other tests to malfunction.
819//
820// Calling this function will not stop the test from running, you
821// need to return from the test function yourself. So you can
822// produce additional diagnostic messages or even continue running
823// the test.
824//
825// If not called from inside a test, this function does nothing.
826//
827// Note that unlike [func@GLib.test_skip] and [func@GLib.test_incomplete],
828// this function does not log a message alongside the test failure.
829// If details of the test failure are available, either log them with
830// [func@GLib.test_message] before [func@GLib.test_fail], or use
831// [func@GLib.test_fail_printf] instead.
832func TestFail() {
833
834 xTestFail()
835
836}
837
838var xTestFailPrintf func(string, ...interface{})
839
840// Indicates that a test failed and records a message.
841//
842// Also see [func@GLib.test_fail].
843//
844// The message is formatted as if by [func@GLib.strdup_printf].
845func TestFailPrintf(FormatVar string, varArgs ...interface{}) {
846
847 xTestFailPrintf(FormatVar, varArgs...)
848
849}
850
851var xTestFailed func() bool
852
853// Returns whether a test has already failed.
854//
855// This will be the case when [func@GLib.test_fail],
856// [func@GLib.test_incomplete] or [func@GLib.test_skip] have
857// been called, but also if an assertion has failed.
858//
859// This can be useful to return early from a test if
860// continuing after a failed assertion might be harmful.
861//
862// The return value of this function is only meaningful
863// if it is called from inside a test function.
864func TestFailed() bool {
865
866 cret := xTestFailed()
867
868 return cret
869}
870
871var xTestGetDir func(TestFileType) string
872
873// Gets the pathname of the directory containing test files of the type
874// specified by @file_type.
875//
876// This is approximately the same as calling `g_test_build_filename(".")`,
877// but you don't need to free the return value.
878func TestGetDir(FileTypeVar TestFileType) string {
879
880 cret := xTestGetDir(FileTypeVar)
881
882 return cret
883}
884
885var xTestGetFilename func(TestFileType, string, ...interface{}) string
886
887// Gets the pathname to a data file that is required for a test.
888//
889// This is the same as [func@GLib.test_build_filename] with two differences.
890// The first difference is that you must only use this function from within
891// a testcase function. The second difference is that you need not free
892// the return value — it will be automatically freed when the testcase
893// finishes running.
894//
895// It is safe to use this function from a thread inside of a testcase
896// but you must ensure that all such uses occur before the main testcase
897// function returns (ie: it is best to ensure that all threads have been
898// joined).
899func TestGetFilename(FileTypeVar TestFileType, FirstPathVar string, varArgs ...interface{}) string {
900
901 cret := xTestGetFilename(FileTypeVar, FirstPathVar, varArgs...)
902
903 return cret
904}
905
906var xTestGetPath func() string
907
908// Gets the test path for the test currently being run.
909//
910// In essence, it will be the same string passed as the first argument
911// to e.g. [func@GLib.test_add] when the test was added.
912//
913// This function returns a valid string only within a test function.
914//
915// Note that this is a test path, not a file system path.
916func TestGetPath() string {
917
918 cret := xTestGetPath()
919
920 return cret
921}
922
923var xTestGetRoot func() *TestSuite
924
925// Gets the toplevel test suite for the test path API.
926func TestGetRoot() *TestSuite {
927
928 cret := xTestGetRoot()
929
930 return cret
931}
932
933var xTestIncomplete func(uintptr)
934
935// Indicates that a test failed because of some incomplete
936// functionality.
937//
938// This function can be called multiple times from the same test.
939//
940// Calling this function will not stop the test from running, you
941// need to return from the test function yourself. So you can
942// produce additional diagnostic messages or even continue running
943// the test.
944//
945// If not called from inside a test, this function does nothing.
946func TestIncomplete(MsgVar *string) {
947
948 MsgVarPtr := core.GStrdupNullable(MsgVar)
949 defer core.GFreeNullable(MsgVarPtr)
950
951 xTestIncomplete(MsgVarPtr)
952
953}
954
955var xTestIncompletePrintf func(string, ...interface{})
956
957// Indicates that a test failed because of some incomplete
958// functionality.
959//
960// Equivalent to [func@GLib.test_incomplete], but the explanation
961// is formatted as if by [func@GLib.strdup_printf].
962func TestIncompletePrintf(FormatVar string, varArgs ...interface{}) {
963
964 xTestIncompletePrintf(FormatVar, varArgs...)
965
966}
967
968var xTestInit func(int, string, ...interface{})
969
970// Initializes the GLib testing framework.
971//
972// This includes seeding the test random number generator,
973// setting the program name, and parsing test-related commandline args.
974//
975// This should be called before calling any other `g_test_*()` functions.
976//
977// The following arguments are understood:
978//
979// - `-l`: List test cases available in a test executable.
980//
981// - `--seed=SEED`: Provide a random seed to reproduce test
982// runs using random numbers.
983//
984// - `--verbose`: Run tests verbosely.
985//
986// - `-q`, `--quiet`: Run tests quietly.
987//
988// - `-p PATH`: Execute all tests matching the given path.
989//
990// - `-s PATH`: Skip all tests matching the given path.
991// This can also be used to force a test to run that would otherwise
992// be skipped (ie, a test whose name contains "/subprocess").
993//
994// - `-m {perf|slow|thorough|quick|undefined|no-undefined}`: Execute tests according
995// to these test modes:
996//
997// `perf`: Performance tests, may take long and report results (off by default).
998//
999// `slow`, `thorough`: Slow and thorough tests, may take quite long and maximize
1000// coverage (off by default).
1001//
1002// `quick`: Quick tests, should run really quickly and give good coverage (the default).
1003//
1004// `undefined`: Tests for undefined behaviour, may provoke programming errors
1005// under [func@GLib.test_trap_subprocess] or [func@GLib.test_expect_message]
1006// to check that appropriate assertions or warnings are given (the default).
1007//
1008// `no-undefined`: Avoid tests for undefined behaviour.
1009//
1010// - `--debug-log`: Debug test logging output.
1011//
1012// Any parsed arguments are removed from @argv, and @argc is adjust accordingly.
1013//
1014// The following options are supported:
1015//
1016// - `G_TEST_OPTION_NO_PRGNAME`: Causes g_test_init() to not call
1017// [func@GLib.set_prgname]. Since. 2.84
1018// - `G_TEST_OPTION_ISOLATE_DIRS`: Creates a unique temporary directory for each
1019// unit test and sets XDG directories to point there for the duration of the unit
1020// test. See [const@GLib.TEST_OPTION_ISOLATE_DIRS].
1021// - `G_TEST_OPTION_NONFATAL_ASSERTIONS`: This has the same effect as
1022// [func@GLib.test_set_nonfatal_assertions]. Since 2.84
1023//
1024// Since 2.58, if tests are compiled with `G_DISABLE_ASSERT` defined, `g_test_init()`
1025// will print an error and exit. This is to prevent no-op tests from being executed,
1026// as [func@GLib.assert] is commonly (erroneously) used in unit tests, and is a no-op
1027// when compiled with `G_DISABLE_ASSERT`. Ensure your tests are compiled without
1028// `G_DISABLE_ASSERT` defined.
1029func TestInit(ArgcVar int, ArgvVar string, varArgs ...interface{}) {
1030
1031 xTestInit(ArgcVar, ArgvVar, varArgs...)
1032
1033}
1034
1035var xTestLogSetFatalHandler func(uintptr, uintptr)
1036
1037// Installs a non-error fatal log handler which can be
1038// used to decide whether log messages which are counted
1039// as fatal abort the program.
1040//
1041// The use case here is that you are running a test case
1042// that depends on particular libraries or circumstances
1043// and cannot prevent certain known critical or warning
1044// messages. So you install a handler that compares the
1045// domain and message to precisely not abort in such a case.
1046//
1047// Note that the handler is reset at the beginning of
1048// any test case, so you have to set it inside each test
1049// function which needs the special behavior.
1050//
1051// This handler has no effect on g_error messages.
1052//
1053// This handler also has no effect on structured log messages (using
1054// [func@GLib.log_structured] or [func@GLib.log_structured_array]). To change the fatal
1055// behaviour for specific log messages, programs must install a custom log
1056// writer function using [func@GLib.log_set_writer_func].See
1057// [Using Structured Logging](logging.html#using-structured-logging).
1058func TestLogSetFatalHandler(LogFuncVar *TestLogFatalFunc, UserDataVar uintptr) {
1059
1060 var LogFuncVarRef uintptr
1061 if LogFuncVar != nil {
1062 LogFuncVarPtr := uintptr(unsafe.Pointer(LogFuncVar))
1063 if cbRefPtr, ok := GetCallback(LogFuncVarPtr); ok {
1064 LogFuncVarRef = cbRefPtr
1065 } else {
1066 fcb := func(arg0 uintptr, arg1 LogLevelFlags, arg2 uintptr, arg3 uintptr) bool {
1067 cbFn := *LogFuncVar
1068 return cbFn(core.GoString(arg0), arg1, core.GoString(arg2), arg3)
1069 }
1070 LogFuncVarRef = purego.NewCallback(fcb)
1071 SaveCallbackWithClosure(LogFuncVarPtr, LogFuncVarRef, LogFuncVar)
1072 }
1073 }
1074
1075 xTestLogSetFatalHandler(LogFuncVarRef, UserDataVar)
1076
1077}
1078
1079var xTestLogTypeName func(TestLogType) string
1080
1081func TestLogTypeName(LogTypeVar TestLogType) string {
1082
1083 cret := xTestLogTypeName(LogTypeVar)
1084
1085 return cret
1086}
1087
1088var xTestMaximizedResult func(float64, string, ...interface{})
1089
1090// Reports the result of a performance or measurement test.
1091//
1092// The test should generally strive to maximize the reported
1093// quantities (larger values are better than smaller ones),
1094// this and @maximized_quantity can determine sorting
1095// order for test result reports.
1096func TestMaximizedResult(MaximizedQuantityVar float64, FormatVar string, varArgs ...interface{}) {
1097
1098 xTestMaximizedResult(MaximizedQuantityVar, FormatVar, varArgs...)
1099
1100}
1101
1102var xTestMessage func(string, ...interface{})
1103
1104// Adds a message to the test report.
1105func TestMessage(FormatVar string, varArgs ...interface{}) {
1106
1107 xTestMessage(FormatVar, varArgs...)
1108
1109}
1110
1111var xTestMinimizedResult func(float64, string, ...interface{})
1112
1113// Reports the result of a performance or measurement test.
1114//
1115// The test should generally strive to minimize the reported
1116// quantities (smaller values are better than larger ones),
1117// this and @minimized_quantity can determine sorting
1118// order for test result reports.
1119func TestMinimizedResult(MinimizedQuantityVar float64, FormatVar string, varArgs ...interface{}) {
1120
1121 xTestMinimizedResult(MinimizedQuantityVar, FormatVar, varArgs...)
1122
1123}
1124
1125var xTestQueueDestroy func(uintptr, uintptr)
1126
1127// Enqueues a callback @destroy_func to be executed during the next test case
1128// teardown phase.
1129//
1130// This is most useful to auto destroy allocated test resources at the end
1131// of a test run. Resources are released in reverse queue order, that means
1132// enqueueing callback `A` before callback `B` will cause `B()` to be called
1133// before `A()` during teardown.
1134func TestQueueDestroy(DestroyFuncVar *DestroyNotify, DestroyDataVar uintptr) {
1135
1136 var DestroyFuncVarRef uintptr
1137 if DestroyFuncVar != nil {
1138 DestroyFuncVarPtr := uintptr(unsafe.Pointer(DestroyFuncVar))
1139 if cbRefPtr, ok := GetCallback(DestroyFuncVarPtr); ok {
1140 DestroyFuncVarRef = cbRefPtr
1141 } else {
1142 fcb := func(arg0 uintptr) {
1143 cbFn := *DestroyFuncVar
1144 cbFn(arg0)
1145 }
1146 DestroyFuncVarRef = purego.NewCallback(fcb)
1147 SaveCallbackWithClosure(DestroyFuncVarPtr, DestroyFuncVarRef, DestroyFuncVar)
1148 }
1149 }
1150
1151 xTestQueueDestroy(DestroyFuncVarRef, DestroyDataVar)
1152
1153}
1154
1155var xTestQueueFree func(uintptr)
1156
1157// Enqueues a pointer to be released with [func@GLib.free]
1158// during the next teardown phase.
1159//
1160// This is equivalent to calling [func@GLib.test_queue_destroy]
1161// with a destroy callback of [func@GLib.free].
1162func TestQueueFree(GfreePointerVar uintptr) {
1163
1164 xTestQueueFree(GfreePointerVar)
1165
1166}
1167
1168var xTestRandDouble func() float64
1169
1170// Gets a reproducible random floating point number.
1171//
1172// See [func@GLib.test_rand_int] for details on test case random numbers.
1173func TestRandDouble() float64 {
1174
1175 cret := xTestRandDouble()
1176
1177 return cret
1178}
1179
1180var xTestRandDoubleRange func(float64, float64) float64
1181
1182// Gets a reproducible random floating point number out of a specified range.
1183//
1184// See [func@GLib.test_rand_int] for details on test case random numbers.
1185func TestRandDoubleRange(RangeStartVar float64, RangeEndVar float64) float64 {
1186
1187 cret := xTestRandDoubleRange(RangeStartVar, RangeEndVar)
1188
1189 return cret
1190}
1191
1192var xTestRandInt func() int32
1193
1194// Gets a reproducible random integer number.
1195//
1196// The random numbers generated by the g_test_rand_*() family of functions
1197// change with every new test program start, unless the --seed option is
1198// given when starting test programs.
1199//
1200// For individual test cases however, the random number generator is
1201// reseeded, to avoid dependencies between tests and to make --seed
1202// effective for all test cases.
1203func TestRandInt() int32 {
1204
1205 cret := xTestRandInt()
1206
1207 return cret
1208}
1209
1210var xTestRandIntRange func(int32, int32) int32
1211
1212// Gets a reproducible random integer number out of a specified range.
1213//
1214// See [func@GLib.test_rand_int] for details on test case random numbers.
1215func TestRandIntRange(BeginVar int32, EndVar int32) int32 {
1216
1217 cret := xTestRandIntRange(BeginVar, EndVar)
1218
1219 return cret
1220}
1221
1222var xTestRun func() int
1223
1224// Runs all tests under the toplevel suite.
1225//
1226// The toplevel suite can be retrieved with [func@GLib.test_get_root].
1227//
1228// Similar to [func@GLib.test_run_suite], the test cases to be run are
1229// filtered according to test path arguments (`-p testpath` and `-s testpath`)
1230// as parsed by [func@GLib.test_init]. [func@GLib.test_run_suite] or
1231// [func@GLib.test_run] may only be called once in a program.
1232//
1233// In general, the tests and sub-suites within each suite are run in
1234// the order in which they are defined. However, note that prior to
1235// GLib 2.36, there was a bug in the `g_test_add_*`
1236// functions which caused them to create multiple suites with the same
1237// name, meaning that if you created tests "/foo/simple",
1238// "/bar/simple", and "/foo/using-bar" in that order, they would get
1239// run in that order (since [func@GLib.test_run] would run the first "/foo"
1240// suite, then the "/bar" suite, then the second "/foo" suite). As of
1241// 2.36, this bug is fixed, and adding the tests in that order would
1242// result in a running order of "/foo/simple", "/foo/using-bar",
1243// "/bar/simple". If this new ordering is sub-optimal (because it puts
1244// more-complicated tests before simpler ones, making it harder to
1245// figure out exactly what has failed), you can fix it by changing the
1246// test paths to group tests by suite in a way that will result in the
1247// desired running order. Eg, "/simple/foo", "/simple/bar",
1248// "/complex/foo-using-bar".
1249//
1250// However, you should never make the actual result of a test depend
1251// on the order that tests are run in. If you need to ensure that some
1252// particular code runs before or after a given test case, use
1253// [func@GLib.test_add], which lets you specify setup and teardown functions.
1254//
1255// If all tests are skipped or marked as incomplete (expected failures),
1256// this function will return 0 if producing TAP output, or 77 (treated
1257// as "skip test" by Automake) otherwise.
1258func TestRun() int {
1259
1260 cret := xTestRun()
1261
1262 return cret
1263}
1264
1265var xTestRunSuite func(*TestSuite) int
1266
1267// Executes the tests within @suite and all nested test suites.
1268//
1269// The test suites to be executed are filtered according to
1270// test path arguments (`-p testpath` and `-s testpath`) as parsed by
1271// [func@GLib.test_init]. See the [func@GLib.test_run] documentation
1272// for more information on the order that tests are run in.
1273//
1274// [func@GLib.test_run_suite] or [func@GLib.test_run] may only be
1275// called once in a program.
1276func TestRunSuite(SuiteVar *TestSuite) int {
1277
1278 cret := xTestRunSuite(SuiteVar)
1279
1280 return cret
1281}
1282
1283var xTestSetNonfatalAssertions func()
1284
1285// Changes the behaviour of the various assertion macros.
1286//
1287// The `g_assert_*()` macros, `g_test_assert_expected_messages()`
1288// and the various `g_test_trap_assert_*()` macros are changed
1289// to not abort to program.
1290//
1291// Instead, they will call [func@GLib.test_fail] and continue.
1292// (This also changes the behavior of [func@GLib.test_fail] so that
1293// it will not cause the test program to abort after completing
1294// the failed test.)
1295//
1296// Note that the [func@GLib.assert_not_reached] and [func@GLib.assert]
1297// macros are not affected by this.
1298//
1299// This function can only be called after [func@GLib.test_init].
1300func TestSetNonfatalAssertions() {
1301
1302 xTestSetNonfatalAssertions()
1303
1304}
1305
1306var xTestSkip func(uintptr)
1307
1308// Indicates that a test was skipped.
1309//
1310// Calling this function will not stop the test from running, you
1311// need to return from the test function yourself. So you can
1312// produce additional diagnostic messages or even continue running
1313// the test.
1314//
1315// If not called from inside a test, this function does nothing.
1316func TestSkip(MsgVar *string) {
1317
1318 MsgVarPtr := core.GStrdupNullable(MsgVar)
1319 defer core.GFreeNullable(MsgVarPtr)
1320
1321 xTestSkip(MsgVarPtr)
1322
1323}
1324
1325var xTestSkipPrintf func(string, ...interface{})
1326
1327// Indicates that a test was skipped.
1328//
1329// Equivalent to [func@GLib.test_skip], but the explanation
1330// is formatted as if by [func@GLib.strdup_printf].
1331func TestSkipPrintf(FormatVar string, varArgs ...interface{}) {
1332
1333 xTestSkipPrintf(FormatVar, varArgs...)
1334
1335}
1336
1337var xTestSubprocess func() bool
1338
1339// Returns true if the test program is running under [func@GLib.test_trap_subprocess].
1340func TestSubprocess() bool {
1341
1342 cret := xTestSubprocess()
1343
1344 return cret
1345}
1346
1347var xTestSummary func(string)
1348
1349// Sets the summary for a test.
1350//
1351// This may be included in test report output, and is useful documentation for
1352// anyone reading the source code or modifying a test in future. It must be a
1353// single line, and it should summarise what the test checks, and how.
1354//
1355// This should be called at the top of a test function.
1356//
1357// For example:
1358//
1359// ```c
1360// static void
1361// test_array_sort (void)
1362//
1363// {
1364// g_test_summary ("Test my_array_sort() sorts the array correctly and stably, "
1365// "including testing zero length and one-element arrays.");
1366//
1367// // ...
1368// }
1369//
1370// ```
1371//
1372// See also [func@GLib.test_bug].
1373func TestSummary(SummaryVar string) {
1374
1375 xTestSummary(SummaryVar)
1376
1377}
1378
1379var xTestTimerElapsed func() float64
1380
1381// Gets the number of seconds since the last start of the timer with
1382// [func@GLib.test_timer_start].
1383func TestTimerElapsed() float64 {
1384
1385 cret := xTestTimerElapsed()
1386
1387 return cret
1388}
1389
1390var xTestTimerLast func() float64
1391
1392// Reports the last result of [func@GLib.test_timer_elapsed].
1393func TestTimerLast() float64 {
1394
1395 cret := xTestTimerLast()
1396
1397 return cret
1398}
1399
1400var xTestTimerStart func()
1401
1402// Starts a timing test.
1403//
1404// Call [func@GLib.test_timer_elapsed] when the task is supposed
1405// to be done. Call this function again to restart the timer.
1406func TestTimerStart() {
1407
1408 xTestTimerStart()
1409
1410}
1411
1412var xTestTrapAssertions func(string, string, int, string, uint64, string)
1413
1414func TestTrapAssertions(DomainVar string, FileVar string, LineVar int, FuncVar string, AssertionFlagsVar uint64, PatternVar string) {
1415
1416 xTestTrapAssertions(DomainVar, FileVar, LineVar, FuncVar, AssertionFlagsVar, PatternVar)
1417
1418}
1419
1420var xTestTrapFork func(uint64, TestTrapFlags) bool
1421
1422// Forks the current test program to execute a test case that might
1423// not return or that might abort.
1424//
1425// If @usec_timeout is non-0, the forked test case is aborted and
1426// considered failing if its run time exceeds it.
1427//
1428// The forking behavior can be configured with [flags@GLib.TestTrapFlags]
1429// flags.
1430//
1431// In the following example, the test code forks, the forked child
1432// process produces some sample output and exits successfully.
1433// The forking parent process then asserts successful child program
1434// termination and validates child program outputs.
1435//
1436// ```c
1437//
1438// static void
1439// test_fork_patterns (void)
1440// {
1441// if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
1442// {
1443// g_print ("some stdout text: somagic17
1444//
1445// ");
1446//
1447// g_printerr ("some stderr text: semagic43
1448//
1449// ");
1450//
1451// exit (0); // successful test run
1452// }
1453// g_test_trap_assert_passed ();
1454// g_test_trap_assert_stdout ("*somagic17*");
1455// g_test_trap_assert_stderr ("*semagic43*");
1456// }
1457//
1458// ```
1459func TestTrapFork(UsecTimeoutVar uint64, TestTrapFlagsVar TestTrapFlags) bool {
1460
1461 cret := xTestTrapFork(UsecTimeoutVar, TestTrapFlagsVar)
1462
1463 return cret
1464}
1465
1466var xTestTrapHasPassed func() bool
1467
1468// Checks the result of the last [func@GLib.test_trap_subprocess] call.
1469func TestTrapHasPassed() bool {
1470
1471 cret := xTestTrapHasPassed()
1472
1473 return cret
1474}
1475
1476var xTestTrapReachedTimeout func() bool
1477
1478// Checks the result of the last [func@GLib.test_trap_subprocess] call.
1479func TestTrapReachedTimeout() bool {
1480
1481 cret := xTestTrapReachedTimeout()
1482
1483 return cret
1484}
1485
1486var xTestTrapSubprocess func(uintptr, uint64, TestSubprocessFlags)
1487
1488// Respawns the test program to run only @test_path in a subprocess.
1489//
1490// This is equivalent to calling [func@GLib.test_trap_subprocess_with_envp]
1491// with `envp` set to `NULL`. See the documentation for that function
1492// for full details.
1493func TestTrapSubprocess(TestPathVar *string, UsecTimeoutVar uint64, TestFlagsVar TestSubprocessFlags) {
1494
1495 TestPathVarPtr := core.GStrdupNullable(TestPathVar)
1496 defer core.GFreeNullable(TestPathVarPtr)
1497
1498 xTestTrapSubprocess(TestPathVarPtr, UsecTimeoutVar, TestFlagsVar)
1499
1500}
1501
1502var xTestTrapSubprocessWithEnvp func(uintptr, []string, uint64, TestSubprocessFlags)
1503
1504// Respawns the test program to run only @test_path in a subprocess with
1505// a given environment.
1506//
1507// This can be used for a test case that might not return, or that
1508// might abort.
1509//
1510// If @test_path is `NULL` then the same test is re-run in a subprocess.
1511// You can use [func@GLib.test_subprocess] to determine whether the test
1512// is in a subprocess or not.
1513//
1514// @test_path can also be the name of the parent test, followed by
1515// "`/subprocess/`" and then a name for the specific subtest (or just
1516// ending with "`/subprocess`" if the test only has one child test);
1517// tests with names of this form will automatically be skipped in the
1518// parent process.
1519//
1520// If @envp is `NULL`, the parent process’ environment will be inherited.
1521//
1522// If @usec_timeout is non-0, the test subprocess is aborted and
1523// considered failing if its run time exceeds it.
1524//
1525// The subprocess behavior can be configured with [flags@GLib.TestSubprocessFlags]
1526// flags.
1527//
1528// You can use methods such as [func@GLib.test_trap_assert_passed],
1529// [func@GLib.test_trap_assert_failed], and [func@GLib.test_trap_assert_stderr] to
1530// check the results of the subprocess. (But note that
1531// [func@GLib.test_trap_assert_stdout] and [func@GLib.test_trap_assert_stderr]
1532// cannot be used if @test_flags specifies that the child should
1533// inherit the parent stdout/stderr.)
1534//
1535// If your `main ()` needs to behave differently in the subprocess, you can
1536// call [func@GLib.test_subprocess] (after calling [func@GLib.test_init])
1537// to see whether you are in a subprocess.
1538//
1539// Internally, this function tracks the child process using
1540// [func@GLib.child_watch_source_new], so your process must not ignore
1541// `SIGCHLD`, and must not attempt to watch or wait for the child process
1542// via another mechanism.
1543//
1544// The following example tests that calling `my_object_new(1000000)` will
1545// abort with an error message.
1546//
1547// ```c
1548//
1549// static void
1550// test_create_large_object (void)
1551// {
1552// if (g_test_subprocess ())
1553// {
1554// my_object_new (1000000);
1555// return;
1556// }
1557//
1558// // Reruns this same test in a subprocess
1559// g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
1560// g_test_trap_assert_failed ();
1561// g_test_trap_assert_stderr ("*ERROR*too large*");
1562// }
1563//
1564// static void
1565// test_different_username (void)
1566// {
1567// if (g_test_subprocess ())
1568// {
1569// // Code under test goes here
1570// g_message ("Username is now simulated as %s", g_getenv ("USER"));
1571// return;
1572// }
1573//
1574// // Reruns this same test in a subprocess
1575// g_auto(GStrv) envp = g_get_environ ();
1576// envp = g_environ_setenv (g_steal_pointer (&envp), "USER", "charlie", TRUE);
1577// g_test_trap_subprocess_with_envp (NULL, envp, 0, G_TEST_SUBPROCESS_DEFAULT);
1578// g_test_trap_assert_passed ();
1579// g_test_trap_assert_stdout ("Username is now simulated as charlie");
1580// }
1581//
1582// int
1583// main (int argc, char **argv)
1584// {
1585// g_test_init (&argc, &argv, NULL);
1586//
1587// g_test_add_func ("/myobject/create-large-object",
1588// test_create_large_object);
1589// g_test_add_func ("/myobject/different-username",
1590// test_different_username);
1591// return g_test_run ();
1592// }
1593//
1594// ```
1595func TestTrapSubprocessWithEnvp(TestPathVar *string, EnvpVar []string, UsecTimeoutVar uint64, TestFlagsVar TestSubprocessFlags) {
1596
1597 TestPathVarPtr := core.GStrdupNullable(TestPathVar)
1598 defer core.GFreeNullable(TestPathVarPtr)
1599
1600 xTestTrapSubprocessWithEnvp(TestPathVarPtr, EnvpVar, UsecTimeoutVar, TestFlagsVar)
1601
1602}
1603
1604func init() {
1605 core.SetPackageName("GLIB", "glib-2.0")
1606 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
1607 var libs []uintptr
1608 for _, libPath := range core.GetPaths("GLIB") {
1609 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
1610 if err != nil {
1611 panic(err)
1612 }
1613 libs = append(libs, lib)
1614 }
1615
1616 core.PuregoSafeRegister(&xAssertionMessage, libs, "g_assertion_message")
1617 core.PuregoSafeRegister(&xAssertionMessageCmpint, libs, "g_assertion_message_cmpint")
1618 core.PuregoSafeRegister(&xAssertionMessageCmpnum, libs, "g_assertion_message_cmpnum")
1619 core.PuregoSafeRegister(&xAssertionMessageCmpstr, libs, "g_assertion_message_cmpstr")
1620 core.PuregoSafeRegister(&xAssertionMessageCmpstrv, libs, "g_assertion_message_cmpstrv")
1621 core.PuregoSafeRegister(&xAssertionMessageError, libs, "g_assertion_message_error")
1622 core.PuregoSafeRegister(&xAssertionMessageExpr, libs, "g_assertion_message_expr")
1623 core.PuregoSafeRegister(&xStrcmp0, libs, "g_strcmp0")
1624 core.PuregoSafeRegister(&xTestAddDataFunc, libs, "g_test_add_data_func")
1625 core.PuregoSafeRegister(&xTestAddDataFuncFull, libs, "g_test_add_data_func_full")
1626 core.PuregoSafeRegister(&xTestAddFunc, libs, "g_test_add_func")
1627 core.PuregoSafeRegister(&xTestAddVtable, libs, "g_test_add_vtable")
1628 core.PuregoSafeRegister(&xTestAssertExpectedMessagesInternal, libs, "g_test_assert_expected_messages_internal")
1629 core.PuregoSafeRegister(&xTestBug, libs, "g_test_bug")
1630 core.PuregoSafeRegister(&xTestBugBase, libs, "g_test_bug_base")
1631 core.PuregoSafeRegister(&xTestBuildFilename, libs, "g_test_build_filename")
1632 core.PuregoSafeRegister(&xTestCreateCase, libs, "g_test_create_case")
1633 core.PuregoSafeRegister(&xTestCreateSuite, libs, "g_test_create_suite")
1634 core.PuregoSafeRegister(&xTestDisableCrashReporting, libs, "g_test_disable_crash_reporting")
1635 core.PuregoSafeRegister(&xTestExpectMessage, libs, "g_test_expect_message")
1636 core.PuregoSafeRegister(&xTestFail, libs, "g_test_fail")
1637 core.PuregoSafeRegister(&xTestFailPrintf, libs, "g_test_fail_printf")
1638 core.PuregoSafeRegister(&xTestFailed, libs, "g_test_failed")
1639 core.PuregoSafeRegister(&xTestGetDir, libs, "g_test_get_dir")
1640 core.PuregoSafeRegister(&xTestGetFilename, libs, "g_test_get_filename")
1641 core.PuregoSafeRegister(&xTestGetPath, libs, "g_test_get_path")
1642 core.PuregoSafeRegister(&xTestGetRoot, libs, "g_test_get_root")
1643 core.PuregoSafeRegister(&xTestIncomplete, libs, "g_test_incomplete")
1644 core.PuregoSafeRegister(&xTestIncompletePrintf, libs, "g_test_incomplete_printf")
1645 core.PuregoSafeRegister(&xTestInit, libs, "g_test_init")
1646 core.PuregoSafeRegister(&xTestLogSetFatalHandler, libs, "g_test_log_set_fatal_handler")
1647 core.PuregoSafeRegister(&xTestLogTypeName, libs, "g_test_log_type_name")
1648 core.PuregoSafeRegister(&xTestMaximizedResult, libs, "g_test_maximized_result")
1649 core.PuregoSafeRegister(&xTestMessage, libs, "g_test_message")
1650 core.PuregoSafeRegister(&xTestMinimizedResult, libs, "g_test_minimized_result")
1651 core.PuregoSafeRegister(&xTestQueueDestroy, libs, "g_test_queue_destroy")
1652 core.PuregoSafeRegister(&xTestQueueFree, libs, "g_test_queue_free")
1653 core.PuregoSafeRegister(&xTestRandDouble, libs, "g_test_rand_double")
1654 core.PuregoSafeRegister(&xTestRandDoubleRange, libs, "g_test_rand_double_range")
1655 core.PuregoSafeRegister(&xTestRandInt, libs, "g_test_rand_int")
1656 core.PuregoSafeRegister(&xTestRandIntRange, libs, "g_test_rand_int_range")
1657 core.PuregoSafeRegister(&xTestRun, libs, "g_test_run")
1658 core.PuregoSafeRegister(&xTestRunSuite, libs, "g_test_run_suite")
1659 core.PuregoSafeRegister(&xTestSetNonfatalAssertions, libs, "g_test_set_nonfatal_assertions")
1660 core.PuregoSafeRegister(&xTestSkip, libs, "g_test_skip")
1661 core.PuregoSafeRegister(&xTestSkipPrintf, libs, "g_test_skip_printf")
1662 core.PuregoSafeRegister(&xTestSubprocess, libs, "g_test_subprocess")
1663 core.PuregoSafeRegister(&xTestSummary, libs, "g_test_summary")
1664 core.PuregoSafeRegister(&xTestTimerElapsed, libs, "g_test_timer_elapsed")
1665 core.PuregoSafeRegister(&xTestTimerLast, libs, "g_test_timer_last")
1666 core.PuregoSafeRegister(&xTestTimerStart, libs, "g_test_timer_start")
1667 core.PuregoSafeRegister(&xTestTrapAssertions, libs, "g_test_trap_assertions")
1668 core.PuregoSafeRegister(&xTestTrapFork, libs, "g_test_trap_fork")
1669 core.PuregoSafeRegister(&xTestTrapHasPassed, libs, "g_test_trap_has_passed")
1670 core.PuregoSafeRegister(&xTestTrapReachedTimeout, libs, "g_test_trap_reached_timeout")
1671 core.PuregoSafeRegister(&xTestTrapSubprocess, libs, "g_test_trap_subprocess")
1672 core.PuregoSafeRegister(&xTestTrapSubprocessWithEnvp, libs, "g_test_trap_subprocess_with_envp")
1673
1674 core.PuregoSafeRegister(&xTestCaseFree, libs, "g_test_case_free")
1675
1676 core.PuregoSafeRegister(&xTestLogBufferFree, libs, "g_test_log_buffer_free")
1677 core.PuregoSafeRegister(&xTestLogBufferPop, libs, "g_test_log_buffer_pop")
1678 core.PuregoSafeRegister(&xTestLogBufferPush, libs, "g_test_log_buffer_push")
1679
1680 core.PuregoSafeRegister(&xTestLogMsgFree, libs, "g_test_log_msg_free")
1681
1682 core.PuregoSafeRegister(&xTestSuiteAdd, libs, "g_test_suite_add")
1683 core.PuregoSafeRegister(&xTestSuiteAddSuite, libs, "g_test_suite_add_suite")
1684 core.PuregoSafeRegister(&xTestSuiteFree, libs, "g_test_suite_free")
1685
1686}