regress.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225
  1. /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
  2. /* This file gets installed, so we can't assume config.h is available */
  3. #ifdef HAVE_CONFIG_H
  4. #include "config.h"
  5. #endif
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <glib-object.h>
  9. #include <gobject/gvaluecollector.h>
  10. #include "regress.h"
  11. static gboolean abort_on_error = TRUE;
  12. #define ASSERT_VALUE(condition) \
  13. if (abort_on_error) \
  14. g_assert (condition); \
  15. else \
  16. g_warn_if_fail (condition); \
  17. void
  18. regress_set_abort_on_error (gboolean in)
  19. {
  20. abort_on_error = in;
  21. }
  22. /* return annotations */
  23. /**
  24. * regress_test_return_allow_none:
  25. *
  26. * Returns: (allow-none):
  27. */
  28. char *
  29. regress_test_return_allow_none (void)
  30. {
  31. return NULL;
  32. }
  33. /**
  34. * regress_test_return_nullable:
  35. *
  36. * Returns: (nullable):
  37. */
  38. char *
  39. regress_test_return_nullable (void)
  40. {
  41. return NULL;
  42. }
  43. /* basic types */
  44. gboolean
  45. regress_test_boolean (gboolean in)
  46. {
  47. return in;
  48. }
  49. gboolean
  50. regress_test_boolean_true (gboolean in)
  51. {
  52. ASSERT_VALUE (in == TRUE);
  53. return in;
  54. }
  55. gboolean
  56. regress_test_boolean_false (gboolean in)
  57. {
  58. ASSERT_VALUE (in == FALSE);
  59. return in;
  60. }
  61. gint8
  62. regress_test_int8 (gint8 in)
  63. {
  64. return in;
  65. }
  66. guint8
  67. regress_test_uint8 (guint8 in)
  68. {
  69. return in;
  70. }
  71. gint16
  72. regress_test_int16 (gint16 in)
  73. {
  74. return in;
  75. }
  76. guint16
  77. regress_test_uint16 (guint16 in)
  78. {
  79. return in;
  80. }
  81. gint32
  82. regress_test_int32 (gint32 in)
  83. {
  84. return in;
  85. }
  86. guint32
  87. regress_test_uint32 (guint32 in)
  88. {
  89. return in;
  90. }
  91. gint64
  92. regress_test_int64 (gint64 in)
  93. {
  94. return in;
  95. }
  96. guint64
  97. regress_test_uint64 (guint64 in)
  98. {
  99. return in;
  100. }
  101. gshort
  102. regress_test_short (gshort in)
  103. {
  104. return in;
  105. }
  106. gushort
  107. regress_test_ushort (gushort in)
  108. {
  109. return in;
  110. }
  111. gint
  112. regress_test_int (gint in)
  113. {
  114. return in;
  115. }
  116. guint
  117. regress_test_uint (guint in)
  118. {
  119. return in;
  120. }
  121. glong
  122. regress_test_long (glong in)
  123. {
  124. return in;
  125. }
  126. gulong
  127. regress_test_ulong (gulong in)
  128. {
  129. return in;
  130. }
  131. gssize
  132. regress_test_ssize (gssize in)
  133. {
  134. return in;
  135. }
  136. gsize
  137. regress_test_size (gsize in)
  138. {
  139. return in;
  140. }
  141. gfloat
  142. regress_test_float (gfloat in)
  143. {
  144. return in;
  145. }
  146. gdouble
  147. regress_test_double (gdouble in)
  148. {
  149. return in;
  150. }
  151. gunichar
  152. regress_test_unichar (gunichar in)
  153. {
  154. return in;
  155. }
  156. time_t
  157. regress_test_timet (time_t in)
  158. {
  159. return in;
  160. }
  161. GType
  162. regress_test_gtype (GType in)
  163. {
  164. return in;
  165. }
  166. int
  167. regress_test_closure (GClosure *closure)
  168. {
  169. GValue return_value = {0, };
  170. int ret;
  171. g_value_init (&return_value, G_TYPE_INT);
  172. g_closure_invoke (closure,
  173. &return_value,
  174. 0, NULL,
  175. NULL);
  176. ret = g_value_get_int (&return_value);
  177. g_value_unset(&return_value);
  178. return ret;
  179. }
  180. int
  181. regress_test_closure_one_arg (GClosure *closure, int arg)
  182. {
  183. GValue return_value = {0, };
  184. GValue arguments[1];
  185. int ret;
  186. g_value_init (&return_value, G_TYPE_INT);
  187. memset (&arguments[0], 0, sizeof (arguments));
  188. g_value_init (&arguments[0], G_TYPE_INT);
  189. g_value_set_int (&arguments[0], arg);
  190. g_closure_invoke (closure,
  191. &return_value,
  192. 1, arguments,
  193. NULL);
  194. ret = g_value_get_int (&return_value);
  195. g_value_unset(&return_value);
  196. g_value_unset(&arguments[0]);
  197. return ret;
  198. }
  199. /**
  200. * regress_test_closure_variant:
  201. * @closure: GClosure which takes one GVariant and returns a GVariant
  202. * @arg: (allow-none) (transfer none): a GVariant passed as argument to @closure
  203. *
  204. * Return value: (transfer full): the return value of @closure
  205. */
  206. GVariant*
  207. regress_test_closure_variant (GClosure *closure, GVariant* arg)
  208. {
  209. GValue return_value = {0, };
  210. GValue arguments[1] = {{0,} };
  211. GVariant *ret;
  212. g_value_init (&return_value, G_TYPE_VARIANT);
  213. g_value_init (&arguments[0], G_TYPE_VARIANT);
  214. g_value_set_variant (&arguments[0], arg);
  215. g_closure_invoke (closure,
  216. &return_value,
  217. 1, arguments,
  218. NULL);
  219. ret = g_value_get_variant (&return_value);
  220. if (ret != NULL)
  221. g_variant_ref (ret);
  222. g_value_unset (&return_value);
  223. g_value_unset (&arguments[0]);
  224. return ret;
  225. }
  226. /**
  227. * regress_test_value_arg:
  228. * @v: (transfer none): a GValue expected to contain an int
  229. *
  230. * Return value: the int contained in the GValue.
  231. */
  232. int
  233. regress_test_int_value_arg(const GValue *v)
  234. {
  235. int i;
  236. i = g_value_get_int (v);
  237. return i;
  238. }
  239. static GValue value;
  240. /**
  241. * regress_test_value_return:
  242. * @i: an int
  243. *
  244. * Return value: (transfer none): the int wrapped in a GValue.
  245. */
  246. const GValue *
  247. regress_test_value_return(int i)
  248. {
  249. memset(&value, '\0', sizeof(GValue));
  250. g_value_init (&value, G_TYPE_INT);
  251. g_value_set_int (&value, i);
  252. return &value;
  253. }
  254. /************************************************************************/
  255. /* foreign structs */
  256. #ifndef _GI_DISABLE_CAIRO
  257. /**
  258. * regress_test_cairo_context_full_return:
  259. *
  260. * Returns: (transfer full):
  261. */
  262. cairo_t *
  263. regress_test_cairo_context_full_return (void)
  264. {
  265. cairo_surface_t *surface;
  266. cairo_t *cr;
  267. surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
  268. cr = cairo_create (surface);
  269. cairo_surface_destroy (surface);
  270. return cr;
  271. }
  272. /**
  273. * regress_test_cairo_context_none_in:
  274. * @context: (transfer none):
  275. */
  276. void
  277. regress_test_cairo_context_none_in (cairo_t *context)
  278. {
  279. cairo_surface_t *surface = cairo_get_target (context);
  280. g_assert (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32);
  281. g_assert (cairo_image_surface_get_width (surface) == 10);
  282. g_assert (cairo_image_surface_get_height (surface) == 10);
  283. }
  284. /**
  285. * regress_test_cairo_surface_none_return:
  286. *
  287. * Returns: (transfer none):
  288. */
  289. cairo_surface_t *
  290. regress_test_cairo_surface_none_return (void)
  291. {
  292. static cairo_surface_t *surface;
  293. if (surface == NULL) {
  294. surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
  295. }
  296. return surface;
  297. }
  298. /**
  299. * regress_test_cairo_surface_full_return:
  300. *
  301. * Returns: (transfer full):
  302. */
  303. cairo_surface_t *
  304. regress_test_cairo_surface_full_return (void)
  305. {
  306. return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
  307. }
  308. /**
  309. * regress_test_cairo_surface_none_in:
  310. * @surface: (transfer none):
  311. */
  312. void
  313. regress_test_cairo_surface_none_in (cairo_surface_t *surface)
  314. {
  315. g_assert (cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32);
  316. g_assert (cairo_image_surface_get_width (surface) == 10);
  317. g_assert (cairo_image_surface_get_height (surface) == 10);
  318. }
  319. /**
  320. * regress_test_cairo_surface_full_out:
  321. * @surface: (out) (transfer full):
  322. */
  323. void
  324. regress_test_cairo_surface_full_out (cairo_surface_t **surface)
  325. {
  326. *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10);
  327. }
  328. #endif
  329. /**
  330. * regress_test_gvariant_i:
  331. *
  332. * Returns: (transfer none): New variant
  333. */
  334. GVariant *
  335. regress_test_gvariant_i (void)
  336. {
  337. return g_variant_new_int32 (1);
  338. }
  339. /**
  340. * regress_test_gvariant_s:
  341. *
  342. * Returns: (transfer none): New variant
  343. */
  344. GVariant *
  345. regress_test_gvariant_s (void)
  346. {
  347. return g_variant_new_string ("one");
  348. }
  349. /**
  350. * regress_test_gvariant_asv:
  351. *
  352. * Returns: (transfer none): New variant
  353. */
  354. GVariant *
  355. regress_test_gvariant_asv (void)
  356. {
  357. GVariantBuilder b;
  358. g_variant_builder_init (&b, G_VARIANT_TYPE ("a{sv}"));
  359. g_variant_builder_add (&b, "{sv}", "name", g_variant_new_string ("foo"));
  360. g_variant_builder_add (&b, "{sv}", "timeout", g_variant_new_int32 (10));
  361. return g_variant_builder_end (&b);
  362. }
  363. /**
  364. * regress_test_gvariant_v:
  365. *
  366. * Returns: (transfer none): New variant
  367. */
  368. GVariant *
  369. regress_test_gvariant_v (void)
  370. {
  371. return g_variant_new_variant (g_variant_new_string ("contents"));
  372. }
  373. /**
  374. * regress_test_gvariant_as:
  375. *
  376. * Returns: (transfer none): New variant
  377. */
  378. GVariant *
  379. regress_test_gvariant_as (void)
  380. {
  381. const char *as[] = { "one", "two", "three", NULL };
  382. return g_variant_new_strv (as, -1);
  383. }
  384. /************************************************************************/
  385. /* utf8 */
  386. /* insert BLACK HEART SUIT to ensure UTF-8 doesn't get mangled */
  387. static const char utf8_const[] = "const \xe2\x99\xa5 utf8";
  388. static const char utf8_nonconst[] = "nonconst \xe2\x99\xa5 utf8";
  389. /**
  390. * regress_test_utf8_const_return:
  391. *
  392. * Return value: UTF-8 string
  393. */
  394. const char *
  395. regress_test_utf8_const_return (void)
  396. {
  397. /* transfer mode none */
  398. return utf8_const;
  399. }
  400. /**
  401. * regress_test_utf8_nonconst_return:
  402. *
  403. * Return value: (transfer full): UTF-8 string
  404. */
  405. char *
  406. regress_test_utf8_nonconst_return (void)
  407. {
  408. return g_strdup (utf8_nonconst);
  409. }
  410. /**
  411. * regress_test_utf8_const_in:
  412. *
  413. */
  414. void
  415. regress_test_utf8_const_in (const char *in)
  416. {
  417. /* transfer mode none */
  418. g_assert (strcmp (in, utf8_const) == 0);
  419. }
  420. /**
  421. * regress_test_utf8_out:
  422. * @out: (out) (transfer full):
  423. */
  424. void
  425. regress_test_utf8_out (char **out)
  426. {
  427. /* out parameter, transfer mode full */
  428. *out = g_strdup (utf8_nonconst);
  429. }
  430. /**
  431. * regress_test_utf8_inout:
  432. * @inout: (inout) (transfer full):
  433. */
  434. void
  435. regress_test_utf8_inout (char **inout)
  436. {
  437. /* inout parameter, transfer mode full */
  438. g_assert (strcmp (*inout, utf8_const) == 0);
  439. g_free (*inout);
  440. *inout = g_strdup (utf8_nonconst);
  441. }
  442. /**
  443. * regress_test_filename_return:
  444. *
  445. * Return value: (element-type filename) (transfer full): list of strings
  446. */
  447. GSList *
  448. regress_test_filename_return (void)
  449. {
  450. GSList *filenames = NULL;
  451. filenames = g_slist_prepend (filenames, g_filename_from_utf8("/etc/fstab", -1, NULL, NULL, NULL));
  452. filenames = g_slist_prepend (filenames, g_filename_from_utf8("åäö", -1, NULL, NULL, NULL));
  453. return filenames;
  454. }
  455. /* in arguments after out arguments */
  456. /**
  457. * regress_test_int_out_utf8:
  458. * @length: (out):
  459. * @in:
  460. */
  461. void
  462. regress_test_int_out_utf8 (int *length, const char *in)
  463. {
  464. *length = g_utf8_strlen(in, -1);
  465. }
  466. /* multiple output arguments */
  467. /**
  468. * regress_test_multi_double_args:
  469. * @in:
  470. * @one: (out):
  471. * @two: (out):
  472. */
  473. void
  474. regress_test_multi_double_args (gdouble in, gdouble *one, gdouble *two)
  475. {
  476. *one = in * 2;
  477. *two = in * 3;
  478. }
  479. /**
  480. * regress_test_utf8_out_out:
  481. * @out0: (out) (transfer full): a copy of "first"
  482. * @out1: (out) (transfer full): a copy of "second"
  483. */
  484. void
  485. regress_test_utf8_out_out (char **out0, char **out1)
  486. {
  487. *out0 = g_strdup ("first");
  488. *out1 = g_strdup ("second");
  489. }
  490. /**
  491. * regress_test_utf8_out_nonconst_return:
  492. * @out: (out) (transfer full): a copy of "second"
  493. *
  494. * Returns: (transfer full): a copy of "first"
  495. */
  496. char *
  497. regress_test_utf8_out_nonconst_return (char **out)
  498. {
  499. *out = g_strdup ("second");
  500. return g_strdup ("first");
  501. }
  502. /**
  503. * regress_test_utf8_null_in:
  504. * @in: (allow-none):
  505. */
  506. void
  507. regress_test_utf8_null_in (char *in)
  508. {
  509. g_assert (in == NULL);
  510. }
  511. /**
  512. * regress_test_utf8_null_out:
  513. * @char_out: (allow-none) (out):
  514. */
  515. void regress_test_utf8_null_out (char **char_out)
  516. {
  517. *char_out = NULL;
  518. }
  519. /* non-basic-types */
  520. static const char *test_sequence[] = {"1", "2", "3"};
  521. /* array */
  522. /**
  523. * regress_test_array_int_in:
  524. * @n_ints:
  525. * @ints: (array length=n_ints): List of ints
  526. */
  527. int
  528. regress_test_array_int_in (int n_ints, int *ints)
  529. {
  530. int i, sum = 0;
  531. for (i = 0; i < n_ints; i++)
  532. sum += ints[i];
  533. return sum;
  534. }
  535. /**
  536. * regress_test_array_int_out:
  537. * @n_ints: (out): the length of @ints
  538. * @ints: (out) (array length=n_ints) (transfer full): a list of 5 integers, from 0 to 4 in consecutive order
  539. */
  540. void
  541. regress_test_array_int_out (int *n_ints, int **ints)
  542. {
  543. int i;
  544. *n_ints = 5;
  545. *ints = g_malloc0(sizeof(**ints) * *n_ints);
  546. for (i = 1; i < *n_ints; i++)
  547. (*ints)[i] = (*ints)[i-1] + 1;
  548. }
  549. /**
  550. * regress_test_array_int_inout:
  551. * @n_ints: (inout): the length of @ints
  552. * @ints: (inout) (array length=n_ints) (transfer full): a list of integers whose items will be increased by 1, except the first that will be dropped
  553. */
  554. void
  555. regress_test_array_int_inout (int *n_ints, int **ints)
  556. {
  557. int i;
  558. int *new_ints;
  559. if (0 < *n_ints)
  560. {
  561. *n_ints -= 1;
  562. new_ints = g_malloc(sizeof(**ints) * *n_ints);
  563. for (i = 0; i < *n_ints; i++)
  564. new_ints[i] = (*ints)[i + 1] + 1;
  565. g_free (*ints);
  566. *ints = new_ints;
  567. }
  568. }
  569. /**
  570. * regress_test_array_gint8_in:
  571. * @n_ints:
  572. * @ints: (array length=n_ints): List of ints
  573. */
  574. int
  575. regress_test_array_gint8_in (int n_ints, gint8 *ints)
  576. {
  577. int i, sum = 0;
  578. for (i = 0; i < n_ints; i++)
  579. sum += ints[i];
  580. return sum;
  581. }
  582. /**
  583. * regress_test_array_gint16_in:
  584. * @n_ints:
  585. * @ints: (array length=n_ints): List of ints
  586. */
  587. int
  588. regress_test_array_gint16_in (int n_ints, gint16 *ints)
  589. {
  590. int i, sum = 0;
  591. for (i = 0; i < n_ints; i++)
  592. sum += ints[i];
  593. return sum;
  594. }
  595. /**
  596. * regress_test_array_gint32_in:
  597. * @n_ints:
  598. * @ints: (array length=n_ints): List of ints
  599. */
  600. gint32
  601. regress_test_array_gint32_in (int n_ints, gint32 *ints)
  602. {
  603. int i;
  604. gint32 sum = 0;
  605. for (i = 0; i < n_ints; i++)
  606. sum += ints[i];
  607. return sum;
  608. }
  609. /**
  610. * regress_test_array_gint64_in:
  611. * @n_ints:
  612. * @ints: (array length=n_ints): List of ints
  613. */
  614. gint64
  615. regress_test_array_gint64_in (int n_ints, gint64 *ints)
  616. {
  617. int i;
  618. gint64 sum = 0;
  619. for (i = 0; i < n_ints; i++)
  620. sum += ints[i];
  621. return sum;
  622. }
  623. /**
  624. * regress_test_strv_in:
  625. * @arr: (array zero-terminated=1) (transfer none):
  626. */
  627. gboolean
  628. regress_test_strv_in (char **arr)
  629. {
  630. if (g_strv_length (arr) != 3)
  631. return FALSE;
  632. if (strcmp (arr[0], "1") != 0)
  633. return FALSE;
  634. if (strcmp (arr[1], "2") != 0)
  635. return FALSE;
  636. if (strcmp (arr[2], "3") != 0)
  637. return FALSE;
  638. return TRUE;
  639. }
  640. /**
  641. * regress_test_array_gtype_in:
  642. * @n_types:
  643. * @types: (array length=n_types): List of types
  644. *
  645. * Return value: (transfer full): string representation of provided types
  646. */
  647. char *
  648. regress_test_array_gtype_in (int n_types, GType *types)
  649. {
  650. GString *string;
  651. int i;
  652. string = g_string_new ("[");
  653. for (i = 0; i < n_types; i++)
  654. {
  655. g_string_append (string, g_type_name (types[i]));
  656. g_string_append_c (string, ',');
  657. }
  658. g_string_append_c (string, ']');
  659. return g_string_free (string, FALSE);
  660. }
  661. /**
  662. * regress_test_strv_out:
  663. *
  664. * Returns: (transfer full):
  665. */
  666. char **
  667. regress_test_strv_out (void)
  668. {
  669. int i = 0;
  670. int n = 6;
  671. char **ret = g_new (char *, n);
  672. ret[i++] = g_strdup ("thanks");
  673. ret[i++] = g_strdup ("for");
  674. ret[i++] = g_strdup ("all");
  675. ret[i++] = g_strdup ("the");
  676. ret[i++] = g_strdup ("fish");
  677. ret[i++] = NULL;
  678. g_assert (i == n);
  679. return ret;
  680. }
  681. /**
  682. * regress_test_strv_out_container:
  683. *
  684. * Return value: (array zero-terminated=1) (transfer container):
  685. */
  686. char **
  687. regress_test_strv_out_container (void)
  688. {
  689. char **ret = g_new (char *, 4);
  690. ret[0] = "1";
  691. ret[1] = "2";
  692. ret[2] = "3";
  693. ret[3] = NULL;
  694. return ret;
  695. }
  696. /**
  697. * regress_test_strv_outarg:
  698. * @retp: (array zero-terminated=1) (out) (transfer container):
  699. */
  700. void
  701. regress_test_strv_outarg (char ***retp)
  702. {
  703. char **ret = g_new (char *, 4);
  704. ret[0] = "1";
  705. ret[1] = "2";
  706. ret[2] = "3";
  707. ret[3] = NULL;
  708. *retp = ret;
  709. }
  710. /**
  711. * regress_test_array_fixed_size_int_in:
  712. * @ints: (array fixed-size=5): a list of 5 integers
  713. *
  714. * Returns: the sum of the items in @ints
  715. */
  716. int
  717. regress_test_array_fixed_size_int_in (int *ints)
  718. {
  719. int i, sum = 0;
  720. for (i = 0; i < 5; i++)
  721. sum += ints[i];
  722. return sum;
  723. }
  724. /**
  725. * regress_test_array_fixed_size_int_out:
  726. * @ints: (out) (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
  727. */
  728. void
  729. regress_test_array_fixed_size_int_out (int **ints)
  730. {
  731. int i;
  732. *ints = g_malloc0(sizeof(**ints) * 5);
  733. for (i = 1; i < 5; i++)
  734. (*ints)[i] = (*ints)[i-1] + 1;
  735. }
  736. /**
  737. * regress_test_array_fixed_size_int_return:
  738. *
  739. * Returns: (array fixed-size=5) (transfer full): a list of 5 integers ranging from 0 to 4
  740. */
  741. int *
  742. regress_test_array_fixed_size_int_return (void)
  743. {
  744. int i, *ints;
  745. ints = g_malloc0(sizeof(*ints) * 5);
  746. for (i = 1; i < 5; i++)
  747. ints[i] = ints[i-1] + 1;
  748. return ints;
  749. }
  750. /**
  751. * regress_test_strv_out_c:
  752. *
  753. * Returns: (transfer none):
  754. */
  755. const char * const*
  756. regress_test_strv_out_c (void)
  757. {
  758. static char **ret = NULL;
  759. if (ret == NULL)
  760. ret = regress_test_strv_out ();
  761. return (const char * const *) ret;
  762. }
  763. /**
  764. * regress_test_array_int_full_out:
  765. * @len: length of the returned array.
  766. *
  767. * Returns: (array length=len) (transfer full): a new array of integers.
  768. */
  769. int *
  770. regress_test_array_int_full_out(int *len)
  771. {
  772. int *result, i;
  773. *len = 5;
  774. result = g_malloc0(sizeof(*result) * (*len));
  775. for (i=1; i < (*len); i++)
  776. result[i] = result[i-1] + 1;
  777. return result;
  778. }
  779. /**
  780. * regress_test_array_int_none_out:
  781. * @len: length of the returned array.
  782. *
  783. * Returns: (array length=len) (transfer none): a static array of integers.
  784. */
  785. int *
  786. regress_test_array_int_none_out(int *len)
  787. {
  788. static int result[5] = { 1, 2, 3, 4, 5 };
  789. *len = 5;
  790. return result;
  791. }
  792. /**
  793. * regress_test_array_int_null_in:
  794. * @arr: (array length=len) (allow-none):
  795. * @len: length
  796. */
  797. void
  798. regress_test_array_int_null_in (int *arr, int len)
  799. {
  800. g_assert (arr == NULL);
  801. }
  802. /**
  803. * regress_test_array_int_null_out:
  804. * @arr: (out) (array length=len) (allow-none):
  805. * @len: (out) : length
  806. */
  807. void
  808. regress_test_array_int_null_out (int **arr, int *len)
  809. {
  810. *arr = NULL;
  811. *len = 0;
  812. }
  813. /* interface */
  814. /************************************************************************/
  815. /* GList */
  816. static /*const*/ GList *
  817. regress_test_sequence_list (void)
  818. {
  819. static GList *list = NULL;
  820. if (!list) {
  821. gsize i;
  822. for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
  823. list = g_list_prepend (list, (gpointer)test_sequence[i]);
  824. }
  825. list = g_list_reverse (list);
  826. }
  827. return list;
  828. }
  829. /**
  830. * regress_test_glist_nothing_return:
  831. *
  832. * Return value: (element-type utf8) (transfer none):
  833. */
  834. const GList *
  835. regress_test_glist_nothing_return (void)
  836. {
  837. return regress_test_sequence_list ();
  838. }
  839. /**
  840. * regress_test_glist_nothing_return2:
  841. *
  842. * Return value: (element-type utf8) (transfer none):
  843. */
  844. GList *
  845. regress_test_glist_nothing_return2 (void)
  846. {
  847. return regress_test_sequence_list ();
  848. }
  849. /**
  850. * regress_test_glist_container_return:
  851. *
  852. * Return value: (element-type utf8) (transfer container):
  853. */
  854. GList *
  855. regress_test_glist_container_return (void)
  856. {
  857. return g_list_copy (regress_test_sequence_list ());
  858. }
  859. /**
  860. * regress_test_glist_everything_return:
  861. *
  862. * Return value: (element-type utf8) (transfer full):
  863. */
  864. GList *
  865. regress_test_glist_everything_return (void)
  866. {
  867. GList *list;
  868. GList *l;
  869. list = g_list_copy (regress_test_sequence_list ());
  870. for (l = list; l != NULL; l = l->next)
  871. l->data = g_strdup (l->data);
  872. return list;
  873. }
  874. static void
  875. regress_assert_test_sequence_list (const GList *in)
  876. {
  877. const GList *l;
  878. gsize i;
  879. for (i = 0, l = in; l != NULL; ++i, l = l->next) {
  880. g_assert (i < G_N_ELEMENTS(test_sequence));
  881. g_assert (strcmp (l->data, test_sequence[i]) == 0);
  882. }
  883. g_assert (i == G_N_ELEMENTS(test_sequence));
  884. }
  885. /**
  886. * regress_test_glist_gtype_container_in:
  887. * @in: (element-type GType) (transfer container):
  888. */
  889. void
  890. regress_test_glist_gtype_container_in (GList *in)
  891. {
  892. GList *l = in;
  893. g_assert (GPOINTER_TO_SIZE (l->data) == REGRESS_TEST_TYPE_OBJ);
  894. l = l->next;
  895. g_assert (GPOINTER_TO_SIZE (l->data) == REGRESS_TEST_TYPE_SUB_OBJ);
  896. l = l->next;
  897. g_assert (l == NULL);
  898. g_list_free (in);
  899. }
  900. /**
  901. * regress_test_glist_nothing_in:
  902. * @in: (element-type utf8):
  903. */
  904. void
  905. regress_test_glist_nothing_in (const GList *in)
  906. {
  907. regress_assert_test_sequence_list (in);
  908. }
  909. /**
  910. * regress_test_glist_nothing_in2:
  911. * @in: (element-type utf8):
  912. */
  913. void
  914. regress_test_glist_nothing_in2 (GList *in)
  915. {
  916. regress_assert_test_sequence_list (in);
  917. }
  918. /**
  919. * regress_test_glist_null_in:
  920. * @in: (element-type utf8) (allow-none):
  921. */
  922. void
  923. regress_test_glist_null_in (GSList *in)
  924. {
  925. g_assert (in == NULL);
  926. }
  927. /**
  928. * regress_test_glist_null_out:
  929. * @out_list: (out) (element-type utf8) (allow-none):
  930. */
  931. void
  932. regress_test_glist_null_out (GSList **out_list)
  933. {
  934. *out_list = NULL;
  935. }
  936. /************************************************************************/
  937. /* GSList */
  938. static /*const*/ GSList *
  939. regress_test_sequence_slist (void)
  940. {
  941. static GSList *list = NULL;
  942. if (!list) {
  943. gsize i;
  944. for (i = 0; i < G_N_ELEMENTS(test_sequence); ++i) {
  945. list = g_slist_prepend (list, (gpointer)test_sequence[i]);
  946. }
  947. list = g_slist_reverse (list);
  948. }
  949. return list;
  950. }
  951. /**
  952. * regress_test_gslist_nothing_return:
  953. *
  954. * Return value: (element-type utf8) (transfer none):
  955. */
  956. const GSList *
  957. regress_test_gslist_nothing_return (void)
  958. {
  959. return regress_test_sequence_slist ();
  960. }
  961. /**
  962. * regress_test_gslist_nothing_return2:
  963. *
  964. * Return value: (element-type utf8) (transfer none):
  965. */
  966. GSList *
  967. regress_test_gslist_nothing_return2 (void)
  968. {
  969. return regress_test_sequence_slist ();
  970. }
  971. /**
  972. * regress_test_gslist_container_return:
  973. *
  974. * Return value: (element-type utf8) (transfer container):
  975. */
  976. GSList *
  977. regress_test_gslist_container_return (void)
  978. {
  979. return g_slist_copy (regress_test_sequence_slist ());
  980. }
  981. /**
  982. * regress_test_gslist_everything_return:
  983. *
  984. * Return value: (element-type utf8) (transfer full):
  985. */
  986. GSList *
  987. regress_test_gslist_everything_return (void)
  988. {
  989. GSList *list;
  990. GSList *l;
  991. list = g_slist_copy (regress_test_sequence_slist ());
  992. for (l = list; l != NULL; l = l->next)
  993. l->data = g_strdup (l->data);
  994. return list;
  995. }
  996. static void
  997. regress_assert_test_sequence_slist (const GSList *in)
  998. {
  999. const GSList *l;
  1000. gsize i;
  1001. for (i = 0, l = in; l != NULL; ++i, l = l->next) {
  1002. g_assert (i < G_N_ELEMENTS(test_sequence));
  1003. g_assert (strcmp (l->data, test_sequence[i]) == 0);
  1004. }
  1005. g_assert (i == G_N_ELEMENTS(test_sequence));
  1006. }
  1007. /**
  1008. * regress_test_gslist_nothing_in:
  1009. * @in: (element-type utf8):
  1010. */
  1011. void
  1012. regress_test_gslist_nothing_in (const GSList *in)
  1013. {
  1014. regress_assert_test_sequence_slist (in);
  1015. }
  1016. /**
  1017. * regress_test_gslist_nothing_in2:
  1018. * @in: (element-type utf8):
  1019. */
  1020. void
  1021. regress_test_gslist_nothing_in2 (GSList *in)
  1022. {
  1023. regress_assert_test_sequence_slist (in);
  1024. }
  1025. /**
  1026. * regress_test_gslist_null_in:
  1027. * @in: (element-type utf8) (allow-none):
  1028. */
  1029. void
  1030. regress_test_gslist_null_in (GSList *in)
  1031. {
  1032. g_assert (in == NULL);
  1033. }
  1034. /**
  1035. * regress_test_gslist_null_out:
  1036. * @out_list: (out) (element-type utf8) (allow-none):
  1037. */
  1038. void
  1039. regress_test_gslist_null_out (GSList **out_list)
  1040. {
  1041. *out_list = NULL;
  1042. }
  1043. /************************************************************************/
  1044. /* GHash */
  1045. static char *table_data[3][2] = {
  1046. { "foo", "bar" }, { "baz", "bat" }, { "qux", "quux" }
  1047. };
  1048. static GHashTable *
  1049. regress_test_table_ghash_new_container (void)
  1050. {
  1051. GHashTable *hash;
  1052. int i;
  1053. hash = g_hash_table_new(g_str_hash, g_str_equal);
  1054. for (i=0; i<3; i++)
  1055. g_hash_table_insert(hash, table_data[i][0], table_data[i][1]);
  1056. return hash;
  1057. }
  1058. static GHashTable *
  1059. regress_test_table_ghash_new_full (void)
  1060. {
  1061. GHashTable *hash;
  1062. int i;
  1063. hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
  1064. for (i=0; i<3; i++)
  1065. g_hash_table_insert(hash,
  1066. g_strdup(table_data[i][0]),
  1067. g_strdup(table_data[i][1]));
  1068. return hash;
  1069. }
  1070. static /*const*/ GHashTable *
  1071. regress_test_table_ghash_const (void)
  1072. {
  1073. static GHashTable *hash = NULL;
  1074. if (!hash) {
  1075. hash = regress_test_table_ghash_new_container();
  1076. }
  1077. return hash;
  1078. }
  1079. /**
  1080. * regress_test_ghash_null_return:
  1081. *
  1082. * Return value: (element-type utf8 utf8) (transfer none) (allow-none):
  1083. */
  1084. const GHashTable *
  1085. regress_test_ghash_null_return (void)
  1086. {
  1087. return NULL;
  1088. }
  1089. /**
  1090. * regress_test_ghash_nothing_return:
  1091. *
  1092. * Return value: (element-type utf8 utf8) (transfer none):
  1093. */
  1094. const GHashTable *
  1095. regress_test_ghash_nothing_return (void)
  1096. {
  1097. return regress_test_table_ghash_const ();
  1098. }
  1099. /**
  1100. * regress_test_ghash_nothing_return2:
  1101. *
  1102. * Return value: (element-type utf8 utf8) (transfer none):
  1103. */
  1104. GHashTable *
  1105. regress_test_ghash_nothing_return2 (void)
  1106. {
  1107. return regress_test_table_ghash_const ();
  1108. }
  1109. static GValue *
  1110. g_value_new (GType type)
  1111. {
  1112. GValue *value = g_slice_new0(GValue);
  1113. g_value_init(value, type);
  1114. return value;
  1115. }
  1116. static void
  1117. g_value_free (GValue *value)
  1118. {
  1119. g_value_unset(value);
  1120. g_slice_free(GValue, value);
  1121. }
  1122. static const gchar *string_array[] = {
  1123. "first",
  1124. "second",
  1125. "third",
  1126. NULL
  1127. };
  1128. /**
  1129. * regress_test_ghash_gvalue_return:
  1130. *
  1131. * Return value: (element-type utf8 GValue) (transfer none):
  1132. */
  1133. GHashTable *
  1134. regress_test_ghash_gvalue_return (void)
  1135. {
  1136. static GHashTable *hash = NULL;
  1137. if (hash == NULL)
  1138. {
  1139. GValue *value;
  1140. hash = g_hash_table_new_full(g_str_hash, g_str_equal,
  1141. g_free, (GDestroyNotify)g_value_free);
  1142. value = g_value_new(G_TYPE_INT);
  1143. g_value_set_int(value, 12);
  1144. g_hash_table_insert(hash, g_strdup("integer"), value);
  1145. value = g_value_new(G_TYPE_BOOLEAN);
  1146. g_value_set_boolean(value, TRUE);
  1147. g_hash_table_insert(hash, g_strdup("boolean"), value);
  1148. value = g_value_new(G_TYPE_STRING);
  1149. g_value_set_string(value, "some text");
  1150. g_hash_table_insert(hash, g_strdup("string"), value);
  1151. value = g_value_new(G_TYPE_STRV);
  1152. g_value_set_boxed(value, string_array);
  1153. g_hash_table_insert(hash, g_strdup("strings"), value);
  1154. value = g_value_new(REGRESS_TEST_TYPE_FLAGS);
  1155. g_value_set_flags(value, REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3);
  1156. g_hash_table_insert(hash, g_strdup("flags"), value);
  1157. value = g_value_new(regress_test_enum_get_type());
  1158. g_value_set_enum(value, REGRESS_TEST_VALUE2);
  1159. g_hash_table_insert(hash, g_strdup("enum"), value);
  1160. }
  1161. return hash;
  1162. }
  1163. /**
  1164. * regress_test_ghash_gvalue_in:
  1165. * @hash: (element-type utf8 GValue): the hash table returned by
  1166. * regress_test_ghash_gvalue_return().
  1167. */
  1168. void
  1169. regress_test_ghash_gvalue_in (GHashTable *hash)
  1170. {
  1171. GValue *value;
  1172. const gchar **strings;
  1173. int i;
  1174. g_assert(hash != NULL);
  1175. value = g_hash_table_lookup(hash, "integer");
  1176. g_assert(value != NULL);
  1177. g_assert(G_VALUE_HOLDS_INT(value));
  1178. g_assert(g_value_get_int(value) == 12);
  1179. value = g_hash_table_lookup(hash, "boolean");
  1180. g_assert(value != NULL);
  1181. g_assert(G_VALUE_HOLDS_BOOLEAN(value));
  1182. g_assert(g_value_get_boolean(value) == TRUE);
  1183. value = g_hash_table_lookup(hash, "string");
  1184. g_assert(value != NULL);
  1185. g_assert(G_VALUE_HOLDS_STRING(value));
  1186. g_assert(strcmp(g_value_get_string(value), "some text") == 0);
  1187. value = g_hash_table_lookup(hash, "strings");
  1188. g_assert(value != NULL);
  1189. g_assert(G_VALUE_HOLDS(value, G_TYPE_STRV));
  1190. strings = g_value_get_boxed(value);
  1191. g_assert(strings != NULL);
  1192. for (i = 0; string_array[i] != NULL; i++)
  1193. g_assert(strcmp(strings[i], string_array[i]) == 0);
  1194. value = g_hash_table_lookup(hash, "flags");
  1195. g_assert(value != NULL);
  1196. g_assert(G_VALUE_HOLDS_FLAGS(value));
  1197. g_assert(g_value_get_flags(value) == (REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3));
  1198. value = g_hash_table_lookup(hash, "enum");
  1199. g_assert(value != NULL);
  1200. g_assert(G_VALUE_HOLDS_ENUM(value));
  1201. g_assert(g_value_get_enum(value) == REGRESS_TEST_VALUE2);
  1202. }
  1203. /**
  1204. * regress_test_ghash_container_return:
  1205. *
  1206. * Return value: (element-type utf8 utf8) (transfer container):
  1207. */
  1208. GHashTable *
  1209. regress_test_ghash_container_return (void)
  1210. {
  1211. return regress_test_table_ghash_new_container ();
  1212. }
  1213. /**
  1214. * regress_test_ghash_everything_return:
  1215. *
  1216. * Return value: (element-type utf8 utf8) (transfer full):
  1217. */
  1218. GHashTable *
  1219. regress_test_ghash_everything_return (void)
  1220. {
  1221. return regress_test_table_ghash_new_full ();
  1222. }
  1223. static void
  1224. assert_test_table_ghash (const GHashTable *in)
  1225. {
  1226. GHashTable *h = regress_test_table_ghash_const();
  1227. GHashTableIter iter;
  1228. gpointer key, value;
  1229. g_assert(g_hash_table_size(h) ==
  1230. g_hash_table_size((GHashTable*)in));
  1231. g_hash_table_iter_init(&iter, (GHashTable*)in);
  1232. while (g_hash_table_iter_next (&iter, &key, &value))
  1233. g_assert( strcmp(g_hash_table_lookup(h, (char*)key), (char*)value) == 0);
  1234. }
  1235. /**
  1236. * regress_test_ghash_null_in:
  1237. * @in: (element-type utf8 utf8) (allow-none):
  1238. */
  1239. void
  1240. regress_test_ghash_null_in (const GHashTable *in)
  1241. {
  1242. g_assert (in == NULL);
  1243. }
  1244. /**
  1245. * regress_test_ghash_null_out:
  1246. * @out: (element-type utf8 utf8) (allow-none) (out):
  1247. */
  1248. void
  1249. regress_test_ghash_null_out (const GHashTable **out)
  1250. {
  1251. *out = NULL;
  1252. }
  1253. /**
  1254. * regress_test_ghash_nothing_in:
  1255. * @in: (element-type utf8 utf8):
  1256. */
  1257. void
  1258. regress_test_ghash_nothing_in (const GHashTable *in)
  1259. {
  1260. assert_test_table_ghash (in);
  1261. }
  1262. /**
  1263. * regress_test_ghash_nothing_in2:
  1264. * @in: (element-type utf8 utf8):
  1265. */
  1266. void
  1267. regress_test_ghash_nothing_in2 (GHashTable *in)
  1268. {
  1269. assert_test_table_ghash (in);
  1270. }
  1271. /* Nested collection types */
  1272. /**
  1273. * regress_test_ghash_nested_everything_return:
  1274. *
  1275. * Specify nested parameterized types directly with the (type ) annotation.
  1276. *
  1277. * Return value: (type GLib.HashTable<utf8,GLib.HashTable<utf8,utf8>>) (transfer full):
  1278. */
  1279. GHashTable *
  1280. regress_test_ghash_nested_everything_return (void)
  1281. {
  1282. GHashTable *hash;
  1283. hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
  1284. (void (*) (gpointer)) g_hash_table_destroy);
  1285. g_hash_table_insert(hash, g_strdup("wibble"), regress_test_table_ghash_new_full());
  1286. return hash;
  1287. }
  1288. /**
  1289. * regress_test_ghash_nested_everything_return2:
  1290. *
  1291. * Another way of specifying nested parameterized types: using the
  1292. * element-type annotation.
  1293. *
  1294. * Return value: (element-type utf8 GLib.HashTable<utf8,utf8>) (transfer full):
  1295. */
  1296. GHashTable *
  1297. regress_test_ghash_nested_everything_return2 (void)
  1298. {
  1299. return regress_test_ghash_nested_everything_return();
  1300. }
  1301. /************************************************************************/
  1302. /**
  1303. * regress_test_garray_container_return:
  1304. *
  1305. * Returns: (transfer container) (type GLib.PtrArray) (element-type utf8):
  1306. */
  1307. GPtrArray *
  1308. regress_test_garray_container_return (void)
  1309. {
  1310. GPtrArray *array;
  1311. array = g_ptr_array_new_with_free_func (g_free);
  1312. g_ptr_array_add (array, g_strdup ("regress"));
  1313. return array;
  1314. }
  1315. /**
  1316. * regress_test_garray_full_return:
  1317. *
  1318. * Returns: (transfer full) (type GLib.PtrArray) (element-type utf8):
  1319. */
  1320. GPtrArray *
  1321. regress_test_garray_full_return (void)
  1322. {
  1323. GPtrArray *array;
  1324. array = g_ptr_array_new ();
  1325. g_ptr_array_add (array, g_strdup ("regress"));
  1326. return array;
  1327. }
  1328. /************************************************************************/
  1329. /* error? */
  1330. /* enums / flags */
  1331. /**
  1332. * NUM_REGRESS_FOO: (skip)
  1333. *
  1334. * num of elements in RegressFoo
  1335. */
  1336. GType
  1337. regress_test_enum_get_type (void)
  1338. {
  1339. static GType etype = 0;
  1340. if (G_UNLIKELY(etype == 0)) {
  1341. static const GEnumValue values[] = {
  1342. { REGRESS_TEST_VALUE1, "REGRESS_TEST_VALUE1", "value1" },
  1343. { REGRESS_TEST_VALUE2, "REGRESS_TEST_VALUE2", "value2" },
  1344. { REGRESS_TEST_VALUE3, "REGRESS_TEST_VALUE3", "value3" },
  1345. { REGRESS_TEST_VALUE4, "REGRESS_TEST_VALUE4", "value4" },
  1346. { 0, NULL, NULL }
  1347. };
  1348. etype = g_enum_register_static (g_intern_static_string ("RegressTestEnum"), values);
  1349. }
  1350. return etype;
  1351. }
  1352. GType
  1353. regress_test_enum_unsigned_get_type (void)
  1354. {
  1355. static GType etype = 0;
  1356. if (G_UNLIKELY(etype == 0)) {
  1357. static const GEnumValue values[] = {
  1358. { REGRESS_TEST_UNSIGNED_VALUE1, "REGRESS_TEST_UNSIGNED_VALUE1", "value1" },
  1359. { REGRESS_TEST_UNSIGNED_VALUE2, "REGRESS_TEST_UNSIGNED_VALUE2", "value2" },
  1360. { 0, NULL, NULL }
  1361. };
  1362. etype = g_enum_register_static (g_intern_static_string ("RegressTestEnumUnsigned"), values);
  1363. }
  1364. return etype;
  1365. }
  1366. GType
  1367. regress_test_flags_get_type (void)
  1368. {
  1369. static GType etype = 0;
  1370. if (G_UNLIKELY(etype == 0)) {
  1371. static const GFlagsValue values[] = {
  1372. { REGRESS_TEST_FLAG1, "TEST_FLAG1", "flag1" },
  1373. { REGRESS_TEST_FLAG2, "TEST_FLAG2", "flag2" },
  1374. { REGRESS_TEST_FLAG3, "TEST_FLAG3", "flag3" },
  1375. { 0, NULL, NULL }
  1376. };
  1377. etype = g_flags_register_static (g_intern_static_string ("RegressTestFlags"), values);
  1378. }
  1379. return etype;
  1380. }
  1381. const gchar *
  1382. regress_test_enum_param(RegressTestEnum e)
  1383. {
  1384. GEnumValue *ev;
  1385. GEnumClass *ec;
  1386. ec = g_type_class_ref (regress_test_enum_get_type ());
  1387. ev = g_enum_get_value (ec, e);
  1388. g_type_class_unref (ec);
  1389. return ev->value_nick;
  1390. }
  1391. const gchar *
  1392. regress_test_unsigned_enum_param(RegressTestEnumUnsigned e)
  1393. {
  1394. GEnumValue *ev;
  1395. GEnumClass *ec;
  1396. ec = g_type_class_ref (regress_test_enum_unsigned_get_type ());
  1397. ev = g_enum_get_value (ec, e);
  1398. g_type_class_unref (ec);
  1399. return ev->value_nick;
  1400. }
  1401. /**
  1402. * regress_global_get_flags_out:
  1403. * @v: (out): A flags value
  1404. *
  1405. */
  1406. void
  1407. regress_global_get_flags_out (RegressTestFlags *v)
  1408. {
  1409. *v = REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3;
  1410. }
  1411. /* error domains */
  1412. GType
  1413. regress_test_error_get_type (void)
  1414. {
  1415. static GType etype = 0;
  1416. if (G_UNLIKELY(etype == 0)) {
  1417. static const GEnumValue values[] = {
  1418. { REGRESS_TEST_ERROR_CODE1, "REGRESS_TEST_ERROR_CODE1", "code1" },
  1419. { REGRESS_TEST_ERROR_CODE2, "REGRESS_TEST_ERROR_CODE2", "code2" },
  1420. { REGRESS_TEST_ERROR_CODE3, "REGRESS_TEST_ERROR_CODE3", "code3" },
  1421. { 0, NULL, NULL }
  1422. };
  1423. etype = g_enum_register_static (g_intern_static_string ("RegressTestError"), values);
  1424. }
  1425. return etype;
  1426. }
  1427. GQuark
  1428. regress_test_error_quark (void)
  1429. {
  1430. return g_quark_from_static_string ("regress-test-error");
  1431. }
  1432. GType
  1433. regress_test_abc_error_get_type (void)
  1434. {
  1435. static GType etype = 0;
  1436. if (G_UNLIKELY(etype == 0)) {
  1437. static const GEnumValue values[] = {
  1438. { REGRESS_TEST_ABC_ERROR_CODE1, "REGRESS_TEST_ABC_ERROR_CODE1", "code1" },
  1439. { REGRESS_TEST_ABC_ERROR_CODE2, "REGRESS_TEST_ABC_ERROR_CODE2", "code2" },
  1440. { REGRESS_TEST_ABC_ERROR_CODE3, "REGRESS_TEST_ABC_ERROR_CODE3", "code3" },
  1441. { 0, NULL, NULL }
  1442. };
  1443. etype = g_enum_register_static (g_intern_static_string ("RegressTestABCError"), values);
  1444. }
  1445. return etype;
  1446. }
  1447. GQuark
  1448. regress_test_abc_error_quark (void)
  1449. {
  1450. return g_quark_from_static_string ("regress-test-abc-error");
  1451. }
  1452. GType
  1453. regress_test_unconventional_error_get_type (void)
  1454. {
  1455. static GType etype = 0;
  1456. if (G_UNLIKELY(etype == 0)) {
  1457. static const GEnumValue values[] = {
  1458. { REGRESS_TEST_OTHER_ERROR_CODE1, "REGRESS_TEST_OTHER_ERROR_CODE1", "code1" },
  1459. { REGRESS_TEST_OTHER_ERROR_CODE2, "REGRESS_TEST_OTHER_ERROR_CODE2", "code2" },
  1460. { REGRESS_TEST_OTHER_ERROR_CODE3, "REGRESS_TEST_OTHER_ERROR_CODE3", "code3" },
  1461. { 0, NULL, NULL }
  1462. };
  1463. etype = g_enum_register_static (g_intern_static_string ("RegressTestOtherError"), values);
  1464. }
  1465. return etype;
  1466. }
  1467. GQuark
  1468. regress_test_unconventional_error_quark (void)
  1469. {
  1470. return g_quark_from_static_string ("regress-test-other-error");
  1471. }
  1472. GQuark
  1473. regress_test_def_error_quark (void)
  1474. {
  1475. return g_quark_from_static_string ("regress-test-def-error");
  1476. }
  1477. GQuark
  1478. regress_atest_error_quark (void)
  1479. {
  1480. return g_quark_from_static_string ("regress-atest-error");
  1481. }
  1482. /* structures */
  1483. /**
  1484. * regress_test_struct_a_clone:
  1485. * @a: the structure
  1486. * @a_out: (out caller-allocates): the cloned structure
  1487. *
  1488. * Make a copy of a RegressTestStructA
  1489. */
  1490. void
  1491. regress_test_struct_a_clone (RegressTestStructA *a,
  1492. RegressTestStructA *a_out)
  1493. {
  1494. *a_out = *a;
  1495. }
  1496. /**
  1497. * regress_test_struct_a_parse:
  1498. * @a_out: (out caller-allocates): the structure that is to be filled
  1499. * @string: ignored
  1500. */
  1501. void
  1502. regress_test_struct_a_parse (RegressTestStructA *a_out,
  1503. const gchar *string)
  1504. {
  1505. a_out->some_int = 23;
  1506. }
  1507. /**
  1508. * regress_test_array_struct_out:
  1509. * @arr: (out) (array length=len) (transfer full):
  1510. * @len: (out)
  1511. *
  1512. * This is similar to gdk_keymap_get_entries_for_keyval().
  1513. */
  1514. void
  1515. regress_test_array_struct_out (RegressTestStructA **arr, int *len)
  1516. {
  1517. *arr = g_new0(RegressTestStructA, 3);
  1518. (*arr)[0].some_int = 22;
  1519. (*arr)[1].some_int = 33;
  1520. (*arr)[2].some_int = 44;
  1521. *len = 3;
  1522. }
  1523. /**
  1524. * regress_test_struct_b_clone:
  1525. * @b: the structure
  1526. * @b_out: (out): the cloned structure
  1527. *
  1528. * Make a copy of a RegressTestStructB
  1529. */
  1530. void
  1531. regress_test_struct_b_clone (RegressTestStructB *b,
  1532. RegressTestStructB *b_out)
  1533. {
  1534. *b_out = *b;
  1535. }
  1536. /* plain-old-data boxed types */
  1537. RegressTestSimpleBoxedA *
  1538. regress_test_simple_boxed_a_copy (RegressTestSimpleBoxedA *a)
  1539. {
  1540. RegressTestSimpleBoxedA *new_a = g_slice_new (RegressTestSimpleBoxedA);
  1541. *new_a = *a;
  1542. return new_a;
  1543. }
  1544. static void
  1545. regress_test_simple_boxed_a_free (RegressTestSimpleBoxedA *a)
  1546. {
  1547. g_slice_free (RegressTestSimpleBoxedA, a);
  1548. }
  1549. GType
  1550. regress_test_simple_boxed_a_get_gtype (void)
  1551. {
  1552. static GType our_type = 0;
  1553. if (our_type == 0)
  1554. our_type = g_boxed_type_register_static (g_intern_static_string ("RegressTestSimpleBoxedA"),
  1555. (GBoxedCopyFunc)regress_test_simple_boxed_a_copy,
  1556. (GBoxedFreeFunc)regress_test_simple_boxed_a_free);
  1557. return our_type;
  1558. }
  1559. RegressTestSimpleBoxedB *
  1560. regress_test_simple_boxed_b_copy (RegressTestSimpleBoxedB *b)
  1561. {
  1562. RegressTestSimpleBoxedB *new_b = g_slice_new (RegressTestSimpleBoxedB);
  1563. *new_b = *b;
  1564. return new_b;
  1565. }
  1566. gboolean
  1567. regress_test_simple_boxed_a_equals (RegressTestSimpleBoxedA *a,
  1568. RegressTestSimpleBoxedA *other_a)
  1569. {
  1570. return (a->some_int == other_a->some_int &&
  1571. a->some_int8 == other_a->some_int8 &&
  1572. a->some_double == other_a->some_double);
  1573. }
  1574. const RegressTestSimpleBoxedA*
  1575. regress_test_simple_boxed_a_const_return (void)
  1576. {
  1577. static RegressTestSimpleBoxedA simple_a = {
  1578. 5, 6, 7.0
  1579. };
  1580. return &simple_a;
  1581. }
  1582. static void
  1583. regress_test_simple_boxed_b_free (RegressTestSimpleBoxedB *a)
  1584. {
  1585. g_slice_free (RegressTestSimpleBoxedB, a);
  1586. }
  1587. GType
  1588. regress_test_simple_boxed_b_get_type (void)
  1589. {
  1590. static GType our_type = 0;
  1591. if (our_type == 0)
  1592. our_type = g_boxed_type_register_static (g_intern_static_string ("RegressTestSimpleBoxedB"),
  1593. (GBoxedCopyFunc)regress_test_simple_boxed_b_copy,
  1594. (GBoxedFreeFunc)regress_test_simple_boxed_b_free);
  1595. return our_type;
  1596. }
  1597. /* opaque boxed */
  1598. struct _RegressTestBoxedPrivate
  1599. {
  1600. guint magic;
  1601. };
  1602. /**
  1603. * regress_test_boxed_new:
  1604. *
  1605. * Returns: (transfer full):
  1606. */
  1607. RegressTestBoxed *
  1608. regress_test_boxed_new (void)
  1609. {
  1610. RegressTestBoxed *boxed = g_slice_new0(RegressTestBoxed);
  1611. boxed->priv = g_slice_new0(RegressTestBoxedPrivate);
  1612. boxed->priv->magic = 0xdeadbeef;
  1613. return boxed;
  1614. }
  1615. /**
  1616. * regress_test_boxed_new_alternative_constructor1:
  1617. *
  1618. * Returns: (transfer full):
  1619. */
  1620. RegressTestBoxed *
  1621. regress_test_boxed_new_alternative_constructor1 (int i)
  1622. {
  1623. RegressTestBoxed *boxed = g_slice_new0(RegressTestBoxed);
  1624. boxed->priv = g_slice_new0(RegressTestBoxedPrivate);
  1625. boxed->priv->magic = 0xdeadbeef;
  1626. boxed->some_int8 = i;
  1627. return boxed;
  1628. }
  1629. /**
  1630. * regress_test_boxed_new_alternative_constructor2:
  1631. *
  1632. * Returns: (transfer full):
  1633. */
  1634. RegressTestBoxed *
  1635. regress_test_boxed_new_alternative_constructor2 (int i, int j)
  1636. {
  1637. RegressTestBoxed *boxed = g_slice_new0(RegressTestBoxed);
  1638. boxed->priv = g_slice_new0(RegressTestBoxedPrivate);
  1639. boxed->priv->magic = 0xdeadbeef;
  1640. boxed->some_int8 = i + j;
  1641. return boxed;
  1642. }
  1643. /**
  1644. * regress_test_boxed_new_alternative_constructor3:
  1645. *
  1646. * Returns: (transfer full):
  1647. */
  1648. RegressTestBoxed *
  1649. regress_test_boxed_new_alternative_constructor3 (char *s)
  1650. {
  1651. RegressTestBoxed *boxed = g_slice_new0(RegressTestBoxed);
  1652. boxed->priv = g_slice_new0(RegressTestBoxedPrivate);
  1653. boxed->priv->magic = 0xdeadbeef;
  1654. boxed->some_int8 = atoi(s);
  1655. return boxed;
  1656. }
  1657. /**
  1658. * regress_test_boxed_copy:
  1659. *
  1660. * Returns: (transfer full):
  1661. */
  1662. RegressTestBoxed *
  1663. regress_test_boxed_copy (RegressTestBoxed *boxed)
  1664. {
  1665. RegressTestBoxed *new_boxed = regress_test_boxed_new();
  1666. RegressTestBoxedPrivate *save;
  1667. save = new_boxed->priv;
  1668. *new_boxed = *boxed;
  1669. new_boxed->priv = save;
  1670. return new_boxed;
  1671. }
  1672. gboolean
  1673. regress_test_boxed_equals (RegressTestBoxed *boxed,
  1674. RegressTestBoxed *other)
  1675. {
  1676. return (other->some_int8 == boxed->some_int8 &&
  1677. regress_test_simple_boxed_a_equals(&other->nested_a, &boxed->nested_a));
  1678. }
  1679. void
  1680. regress_test_boxeds_not_a_method (RegressTestBoxed *boxed)
  1681. {
  1682. }
  1683. void
  1684. regress_test_boxeds_not_a_static (void)
  1685. {
  1686. }
  1687. static void
  1688. regress_test_boxed_free (RegressTestBoxed *boxed)
  1689. {
  1690. g_assert (boxed->priv->magic == 0xdeadbeef);
  1691. g_slice_free (RegressTestBoxedPrivate, boxed->priv);
  1692. g_slice_free (RegressTestBoxed, boxed);
  1693. }
  1694. GType
  1695. regress_test_boxed_get_type (void)
  1696. {
  1697. static GType our_type = 0;
  1698. if (our_type == 0)
  1699. our_type = g_boxed_type_register_static (g_intern_static_string ("RegressTestBoxed"),
  1700. (GBoxedCopyFunc)regress_test_boxed_copy,
  1701. (GBoxedFreeFunc)regress_test_boxed_free);
  1702. return our_type;
  1703. }
  1704. RegressTestBoxedB *
  1705. regress_test_boxed_b_new (gint8 some_int8, glong some_long)
  1706. {
  1707. RegressTestBoxedB *boxed;
  1708. boxed = g_slice_new (RegressTestBoxedB);
  1709. boxed->some_int8 = some_int8;
  1710. boxed->some_long = some_long;
  1711. return boxed;
  1712. }
  1713. RegressTestBoxedB *
  1714. regress_test_boxed_b_copy (RegressTestBoxedB *boxed)
  1715. {
  1716. return regress_test_boxed_b_new (boxed->some_int8, boxed->some_long);
  1717. }
  1718. static void
  1719. regress_test_boxed_b_free (RegressTestBoxedB *boxed)
  1720. {
  1721. g_slice_free (RegressTestBoxedB, boxed);
  1722. }
  1723. G_DEFINE_BOXED_TYPE(RegressTestBoxedB,
  1724. regress_test_boxed_b,
  1725. regress_test_boxed_b_copy,
  1726. regress_test_boxed_b_free);
  1727. RegressTestBoxedC *
  1728. regress_test_boxed_c_new (void)
  1729. {
  1730. RegressTestBoxedC *boxed;
  1731. boxed = g_slice_new (RegressTestBoxedC);
  1732. boxed->refcount = 1;
  1733. boxed->another_thing = 42; /* what else */
  1734. return boxed;
  1735. }
  1736. static RegressTestBoxedC *
  1737. regress_test_boxed_c_ref (RegressTestBoxedC *boxed)
  1738. {
  1739. g_atomic_int_inc (&boxed->refcount);
  1740. return boxed;
  1741. }
  1742. static void
  1743. regress_test_boxed_c_unref (RegressTestBoxedC *boxed)
  1744. {
  1745. if (g_atomic_int_dec_and_test (&boxed->refcount)) {
  1746. g_slice_free (RegressTestBoxedC, boxed);
  1747. }
  1748. }
  1749. G_DEFINE_BOXED_TYPE(RegressTestBoxedC,
  1750. regress_test_boxed_c,
  1751. regress_test_boxed_c_ref,
  1752. regress_test_boxed_c_unref);
  1753. struct _RegressTestBoxedD {
  1754. char *a_string;
  1755. gint a_int;
  1756. };
  1757. RegressTestBoxedD *
  1758. regress_test_boxed_d_new (const char *a_string, int a_int)
  1759. {
  1760. RegressTestBoxedD *boxed;
  1761. boxed = g_slice_new (RegressTestBoxedD);
  1762. boxed->a_string = g_strdup (a_string);
  1763. boxed->a_int = a_int;
  1764. return boxed;
  1765. }
  1766. RegressTestBoxedD *
  1767. regress_test_boxed_d_copy (RegressTestBoxedD *boxed)
  1768. {
  1769. RegressTestBoxedD *ret;
  1770. ret = g_slice_new (RegressTestBoxedD);
  1771. ret->a_string = g_strdup (boxed->a_string);
  1772. ret->a_int = boxed->a_int;
  1773. return ret;
  1774. }
  1775. void
  1776. regress_test_boxed_d_free (RegressTestBoxedD *boxed)
  1777. {
  1778. g_free (boxed->a_string);
  1779. g_slice_free (RegressTestBoxedD, boxed);
  1780. }
  1781. int
  1782. regress_test_boxed_d_get_magic (RegressTestBoxedD *boxed)
  1783. {
  1784. return strlen (boxed->a_string) + boxed->a_int;
  1785. }
  1786. G_DEFINE_BOXED_TYPE(RegressTestBoxedD,
  1787. regress_test_boxed_d,
  1788. regress_test_boxed_d_copy,
  1789. regress_test_boxed_d_free);
  1790. G_DEFINE_TYPE(RegressTestObj, regress_test_obj, G_TYPE_OBJECT);
  1791. enum
  1792. {
  1793. PROP_TEST_OBJ_BARE = 1,
  1794. PROP_TEST_OBJ_BOXED,
  1795. PROP_TEST_OBJ_HASH_TABLE,
  1796. PROP_TEST_OBJ_LIST,
  1797. PROP_TEST_OBJ_PPTRARRAY,
  1798. PROP_TEST_OBJ_HASH_TABLE_OLD,
  1799. PROP_TEST_OBJ_LIST_OLD,
  1800. PROP_TEST_OBJ_INT,
  1801. PROP_TEST_OBJ_FLOAT,
  1802. PROP_TEST_OBJ_DOUBLE,
  1803. PROP_TEST_OBJ_STRING,
  1804. PROP_TEST_OBJ_GTYPE
  1805. };
  1806. static void
  1807. regress_test_obj_set_property (GObject *object,
  1808. guint property_id,
  1809. const GValue *value,
  1810. GParamSpec *pspec)
  1811. {
  1812. RegressTestObj *self = REGRESS_TEST_OBJECT (object);
  1813. GList *list;
  1814. switch (property_id)
  1815. {
  1816. case PROP_TEST_OBJ_BARE:
  1817. regress_test_obj_set_bare (self, g_value_get_object (value));
  1818. break;
  1819. case PROP_TEST_OBJ_BOXED:
  1820. if (self->boxed)
  1821. regress_test_boxed_free (self->boxed);
  1822. self->boxed = g_value_dup_boxed (value);
  1823. break;
  1824. case PROP_TEST_OBJ_HASH_TABLE:
  1825. case PROP_TEST_OBJ_HASH_TABLE_OLD:
  1826. if (self->hash_table)
  1827. g_hash_table_unref (self->hash_table);
  1828. self->hash_table = g_hash_table_ref (g_value_get_boxed (value));
  1829. break;
  1830. case PROP_TEST_OBJ_LIST:
  1831. case PROP_TEST_OBJ_LIST_OLD:
  1832. if (self->list != NULL)
  1833. {
  1834. for (list = self->list; list != NULL; list = g_list_next (list))
  1835. g_free (list->data);
  1836. g_list_free (self->list);
  1837. }
  1838. self->list = NULL;
  1839. for (list = g_value_get_pointer (value); list != NULL; list = g_list_next (list))
  1840. self->list = g_list_append (self->list, g_strdup (list->data));
  1841. break;
  1842. case PROP_TEST_OBJ_INT:
  1843. self->some_int8 = g_value_get_int (value);
  1844. break;
  1845. case PROP_TEST_OBJ_FLOAT:
  1846. self->some_float = g_value_get_float (value);
  1847. break;
  1848. case PROP_TEST_OBJ_DOUBLE:
  1849. self->some_double = g_value_get_double (value);
  1850. break;
  1851. case PROP_TEST_OBJ_STRING:
  1852. self->string = g_value_dup_string (value);
  1853. break;
  1854. case PROP_TEST_OBJ_GTYPE:
  1855. self->gtype = g_value_get_gtype (value);
  1856. break;
  1857. default:
  1858. /* We don't have any other property... */
  1859. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  1860. break;
  1861. }
  1862. }
  1863. static void
  1864. regress_test_obj_get_property (GObject *object,
  1865. guint property_id,
  1866. GValue *value,
  1867. GParamSpec *pspec)
  1868. {
  1869. RegressTestObj *self = REGRESS_TEST_OBJECT (object);
  1870. switch (property_id)
  1871. {
  1872. case PROP_TEST_OBJ_BARE:
  1873. g_value_set_object (value, self->bare);
  1874. break;
  1875. case PROP_TEST_OBJ_BOXED:
  1876. g_value_set_boxed (value, self->boxed);
  1877. break;
  1878. case PROP_TEST_OBJ_HASH_TABLE:
  1879. case PROP_TEST_OBJ_HASH_TABLE_OLD:
  1880. if (self->hash_table != NULL)
  1881. g_hash_table_ref (self->hash_table);
  1882. g_value_set_boxed (value, self->hash_table);
  1883. break;
  1884. case PROP_TEST_OBJ_LIST:
  1885. case PROP_TEST_OBJ_LIST_OLD:
  1886. g_value_set_pointer (value, self->list);
  1887. break;
  1888. case PROP_TEST_OBJ_INT:
  1889. g_value_set_int (value, self->some_int8);
  1890. break;
  1891. case PROP_TEST_OBJ_FLOAT:
  1892. g_value_set_float (value, self->some_float);
  1893. break;
  1894. case PROP_TEST_OBJ_DOUBLE:
  1895. g_value_set_double (value, self->some_double);
  1896. break;
  1897. case PROP_TEST_OBJ_STRING:
  1898. g_value_set_string (value, self->string);
  1899. break;
  1900. case PROP_TEST_OBJ_GTYPE:
  1901. g_value_set_gtype (value, self->gtype);
  1902. break;
  1903. default:
  1904. /* We don't have any other property... */
  1905. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  1906. break;
  1907. }
  1908. }
  1909. static void
  1910. regress_test_obj_dispose (GObject *gobject)
  1911. {
  1912. RegressTestObj *self = REGRESS_TEST_OBJECT (gobject);
  1913. if (self->bare)
  1914. {
  1915. g_object_unref (self->bare);
  1916. self->bare = NULL;
  1917. }
  1918. if (self->boxed)
  1919. {
  1920. regress_test_boxed_free (self->boxed);
  1921. self->boxed = NULL;
  1922. }
  1923. /* Chain up to the parent class */
  1924. G_OBJECT_CLASS (regress_test_obj_parent_class)->dispose (gobject);
  1925. }
  1926. static int
  1927. regress_test_obj_default_matrix (RegressTestObj *obj, const char *somestr)
  1928. {
  1929. return 42;
  1930. }
  1931. enum {
  1932. REGRESS_TEST_OBJ_SIGNAL_SIG_NEW_WITH_ARRAY_PROP,
  1933. REGRESS_TEST_OBJ_SIGNAL_SIG_NEW_WITH_ARRAY_LEN_PROP,
  1934. REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_HASH_PROP,
  1935. REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_STRV,
  1936. REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_OBJ,
  1937. REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_FOREIGN_STRUCT,
  1938. REGRESS_TEST_OBJ_SIGNAL_FIRST,
  1939. REGRESS_TEST_OBJ_SIGNAL_CLEANUP,
  1940. REGRESS_TEST_OBJ_SIGNAL_ALL,
  1941. REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INT64_PROP,
  1942. REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_UINT64_PROP,
  1943. REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INTARRAY_RET,
  1944. N_REGRESS_TEST_OBJ_SIGNALS
  1945. };
  1946. static guint regress_test_obj_signals[N_REGRESS_TEST_OBJ_SIGNALS] = { 0 };
  1947. static void
  1948. regress_test_obj_class_init (RegressTestObjClass *klass)
  1949. {
  1950. GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  1951. GParamSpec *pspec;
  1952. GType param_types[1];
  1953. klass->test_signal =
  1954. g_signal_newv ("test",
  1955. G_TYPE_FROM_CLASS (gobject_class),
  1956. G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
  1957. NULL /* closure */,
  1958. NULL /* accumulator */,
  1959. NULL /* accumulator data */,
  1960. g_cclosure_marshal_VOID__VOID,
  1961. G_TYPE_NONE /* return_type */,
  1962. 0 /* n_params */,
  1963. NULL /* param_types */);
  1964. param_types[0] = regress_test_simple_boxed_a_get_gtype() | G_SIGNAL_TYPE_STATIC_SCOPE;
  1965. klass->test_signal_with_static_scope_arg =
  1966. g_signal_newv ("test-with-static-scope-arg",
  1967. G_TYPE_FROM_CLASS (gobject_class),
  1968. G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
  1969. NULL /* closure */,
  1970. NULL /* accumulator */,
  1971. NULL /* accumulator data */,
  1972. g_cclosure_marshal_VOID__BOXED,
  1973. G_TYPE_NONE /* return_type */,
  1974. 1 /* n_params */,
  1975. param_types);
  1976. /**
  1977. * RegressTestObj::sig-with-array-prop:
  1978. * @self: an object
  1979. * @arr: (type GArray) (element-type uint): numbers
  1980. *
  1981. * This test signal is like TelepathyGlib's
  1982. * TpChannel:: group-members-changed-detailed:
  1983. */
  1984. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_NEW_WITH_ARRAY_PROP] =
  1985. g_signal_new ("sig-with-array-prop",
  1986. G_TYPE_FROM_CLASS (gobject_class),
  1987. G_SIGNAL_RUN_LAST,
  1988. 0,
  1989. NULL,
  1990. NULL,
  1991. g_cclosure_marshal_VOID__BOXED,
  1992. G_TYPE_NONE,
  1993. 1,
  1994. G_TYPE_ARRAY);
  1995. /**
  1996. * RegressTestObj::sig-with-array-len-prop:
  1997. * @self: an object
  1998. * @arr: (array length=len) (element-type uint) (allow-none): numbers, or %NULL
  1999. * @len: length of @arr, or 0
  2000. *
  2001. * This test signal similar to GSettings::change-event.
  2002. * You can use this with regress_test_obj_emit_sig_with_array_len_prop(), or
  2003. * raise from the introspection client language.
  2004. */
  2005. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_NEW_WITH_ARRAY_LEN_PROP] =
  2006. g_signal_new ("sig-with-array-len-prop",
  2007. G_TYPE_FROM_CLASS (gobject_class),
  2008. G_SIGNAL_RUN_LAST,
  2009. 0,
  2010. NULL,
  2011. NULL,
  2012. NULL,
  2013. G_TYPE_NONE,
  2014. 2,
  2015. G_TYPE_POINTER,
  2016. G_TYPE_INT);
  2017. /**
  2018. * RegressTestObj::sig-with-hash-prop:
  2019. * @self: an object
  2020. * @hash: (element-type utf8 GObject.Value):
  2021. *
  2022. * This test signal is like TelepathyGlib's
  2023. * TpAccount::status-changed
  2024. */
  2025. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_HASH_PROP] =
  2026. g_signal_new ("sig-with-hash-prop",
  2027. G_TYPE_FROM_CLASS (gobject_class),
  2028. G_SIGNAL_RUN_LAST,
  2029. 0,
  2030. NULL,
  2031. NULL,
  2032. g_cclosure_marshal_VOID__BOXED,
  2033. G_TYPE_NONE,
  2034. 1,
  2035. G_TYPE_HASH_TABLE);
  2036. /**
  2037. * RegressTestObj::sig-with-strv:
  2038. * @self: an object
  2039. * @strs: strings
  2040. *
  2041. * Test GStrv as a param.
  2042. */
  2043. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_STRV] =
  2044. g_signal_new ("sig-with-strv",
  2045. G_TYPE_FROM_CLASS (gobject_class),
  2046. G_SIGNAL_RUN_LAST,
  2047. 0,
  2048. NULL,
  2049. NULL,
  2050. g_cclosure_marshal_VOID__BOXED,
  2051. G_TYPE_NONE,
  2052. 1,
  2053. G_TYPE_STRV);
  2054. /**
  2055. * RegressTestObj::sig-with-obj:
  2056. * @self: an object
  2057. * @obj: (transfer none): A newly created RegressTestObj
  2058. *
  2059. * Test transfer none GObject as a param (tests refcounting).
  2060. * Use with regress_test_obj_emit_sig_with_obj
  2061. */
  2062. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_OBJ] =
  2063. g_signal_new ("sig-with-obj",
  2064. G_TYPE_FROM_CLASS (gobject_class),
  2065. G_SIGNAL_RUN_LAST,
  2066. 0,
  2067. NULL,
  2068. NULL,
  2069. g_cclosure_marshal_VOID__OBJECT,
  2070. G_TYPE_NONE,
  2071. 1,
  2072. G_TYPE_OBJECT);
  2073. #ifndef _GI_DISABLE_CAIRO
  2074. /**
  2075. * RegressTestObj::sig-with-foreign-struct:
  2076. * @self: an object
  2077. * @cr: (transfer none): A cairo context.
  2078. */
  2079. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_FOREIGN_STRUCT] =
  2080. g_signal_new ("sig-with-foreign-struct",
  2081. G_TYPE_FROM_CLASS (gobject_class),
  2082. G_SIGNAL_RUN_LAST,
  2083. 0,
  2084. NULL,
  2085. NULL,
  2086. NULL,
  2087. G_TYPE_NONE,
  2088. 1,
  2089. CAIRO_GOBJECT_TYPE_CONTEXT);
  2090. #endif
  2091. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_FIRST] =
  2092. g_signal_new ("first",
  2093. G_TYPE_FROM_CLASS (gobject_class),
  2094. G_SIGNAL_RUN_FIRST,
  2095. 0,
  2096. NULL,
  2097. NULL,
  2098. g_cclosure_marshal_VOID__VOID,
  2099. G_TYPE_NONE,
  2100. 0);
  2101. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_CLEANUP] =
  2102. g_signal_new ("cleanup",
  2103. G_TYPE_FROM_CLASS (gobject_class),
  2104. G_SIGNAL_RUN_CLEANUP,
  2105. 0,
  2106. NULL,
  2107. NULL,
  2108. g_cclosure_marshal_VOID__VOID,
  2109. G_TYPE_NONE,
  2110. 0);
  2111. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_ALL] =
  2112. g_signal_new ("all",
  2113. G_TYPE_FROM_CLASS (gobject_class),
  2114. G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_ACTION | G_SIGNAL_NO_HOOKS,
  2115. 0,
  2116. NULL,
  2117. NULL,
  2118. g_cclosure_marshal_VOID__VOID,
  2119. G_TYPE_NONE,
  2120. 0);
  2121. /**
  2122. * RegressTestObj::sig-with-int64-prop:
  2123. * @self: an object
  2124. * @i: an integer
  2125. *
  2126. * You can use this with regress_test_obj_emit_sig_with_int64, or raise from
  2127. * the introspection client langage.
  2128. */
  2129. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INT64_PROP] =
  2130. g_signal_new ("sig-with-int64-prop",
  2131. G_TYPE_FROM_CLASS (gobject_class),
  2132. G_SIGNAL_RUN_LAST,
  2133. 0,
  2134. NULL,
  2135. NULL,
  2136. g_cclosure_marshal_VOID__BOXED,
  2137. G_TYPE_INT64,
  2138. 1,
  2139. G_TYPE_INT64);
  2140. /**
  2141. * RegressTestObj::sig-with-uint64-prop:
  2142. * @self: an object
  2143. * @i: an integer
  2144. *
  2145. * You can use this with regress_test_obj_emit_sig_with_uint64, or raise from
  2146. * the introspection client langage.
  2147. */
  2148. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_UINT64_PROP] =
  2149. g_signal_new ("sig-with-uint64-prop",
  2150. G_TYPE_FROM_CLASS (gobject_class),
  2151. G_SIGNAL_RUN_LAST,
  2152. 0,
  2153. NULL,
  2154. NULL,
  2155. g_cclosure_marshal_VOID__BOXED,
  2156. G_TYPE_UINT64,
  2157. 1,
  2158. G_TYPE_UINT64);
  2159. /**
  2160. * RegressTestObj::sig-with-intarray-ret:
  2161. * @self: an object
  2162. * @i: an integer
  2163. *
  2164. * Returns: (array zero-terminated=1) (element-type gint) (transfer full):
  2165. */
  2166. regress_test_obj_signals[REGRESS_TEST_OBJ_SIGNAL_SIG_WITH_INTARRAY_RET] =
  2167. g_signal_new ("sig-with-intarray-ret",
  2168. G_TYPE_FROM_CLASS (gobject_class),
  2169. G_SIGNAL_RUN_LAST,
  2170. 0,
  2171. NULL,
  2172. NULL,
  2173. g_cclosure_marshal_VOID__BOXED,
  2174. G_TYPE_ARRAY,
  2175. 1,
  2176. G_TYPE_INT);
  2177. gobject_class->set_property = regress_test_obj_set_property;
  2178. gobject_class->get_property = regress_test_obj_get_property;
  2179. gobject_class->dispose = regress_test_obj_dispose;
  2180. pspec = g_param_spec_object ("bare",
  2181. "Bare property",
  2182. "A contained object",
  2183. G_TYPE_OBJECT,
  2184. G_PARAM_READWRITE);
  2185. g_object_class_install_property (gobject_class,
  2186. PROP_TEST_OBJ_BARE,
  2187. pspec);
  2188. pspec = g_param_spec_boxed ("boxed",
  2189. "Boxed property",
  2190. "A contained boxed struct",
  2191. REGRESS_TEST_TYPE_BOXED,
  2192. G_PARAM_READWRITE);
  2193. g_object_class_install_property (gobject_class,
  2194. PROP_TEST_OBJ_BOXED,
  2195. pspec);
  2196. /**
  2197. * RegressTestObj:hash-table: (type GLib.HashTable(utf8,gint8)) (transfer container)
  2198. */
  2199. pspec = g_param_spec_boxed ("hash-table",
  2200. "GHashTable property",
  2201. "A contained GHashTable",
  2202. G_TYPE_HASH_TABLE,
  2203. G_PARAM_READWRITE);
  2204. g_object_class_install_property (gobject_class,
  2205. PROP_TEST_OBJ_HASH_TABLE,
  2206. pspec);
  2207. /**
  2208. * RegressTestObj:list: (type GLib.List(utf8)) (transfer none)
  2209. */
  2210. pspec = g_param_spec_pointer ("list",
  2211. "GList property",
  2212. "A contained GList",
  2213. G_PARAM_READWRITE);
  2214. g_object_class_install_property (gobject_class,
  2215. PROP_TEST_OBJ_LIST,
  2216. pspec);
  2217. /**
  2218. * RegressTestObj:pptrarray: (type GLib.PtrArray(utf8)) (transfer none)
  2219. */
  2220. pspec = g_param_spec_pointer ("pptrarray",
  2221. "PtrArray property as a pointer",
  2222. "Test annotating with GLib.PtrArray",
  2223. G_PARAM_READWRITE);
  2224. g_object_class_install_property (gobject_class,
  2225. PROP_TEST_OBJ_PPTRARRAY,
  2226. pspec);
  2227. /**
  2228. * RegressTestObj:hash-table-old: (type GLib.HashTable<utf8,gint8>) (transfer container)
  2229. */
  2230. pspec = g_param_spec_boxed ("hash-table-old",
  2231. "GHashTable property with <>",
  2232. "A contained GHashTable with <>",
  2233. G_TYPE_HASH_TABLE,
  2234. G_PARAM_READWRITE);
  2235. g_object_class_install_property (gobject_class,
  2236. PROP_TEST_OBJ_HASH_TABLE_OLD,
  2237. pspec);
  2238. /**
  2239. * RegressTestObj:list-old: (type GLib.List<utf8>) (transfer none)
  2240. */
  2241. pspec = g_param_spec_pointer ("list-old",
  2242. "GList property with ()",
  2243. "A contained GList with <>",
  2244. G_PARAM_READWRITE);
  2245. g_object_class_install_property (gobject_class,
  2246. PROP_TEST_OBJ_LIST_OLD,
  2247. pspec);
  2248. /**
  2249. * TestObj:int:
  2250. */
  2251. pspec = g_param_spec_int ("int",
  2252. "int property",
  2253. "A contained int",
  2254. G_MININT,
  2255. G_MAXINT,
  2256. 0,
  2257. G_PARAM_READWRITE);
  2258. g_object_class_install_property (gobject_class,
  2259. PROP_TEST_OBJ_INT,
  2260. pspec);
  2261. /**
  2262. * TestObj:float:
  2263. */
  2264. pspec = g_param_spec_float ("float",
  2265. "float property",
  2266. "A contained float",
  2267. G_MINFLOAT,
  2268. G_MAXFLOAT,
  2269. 1.0f,
  2270. G_PARAM_READWRITE);
  2271. g_object_class_install_property (gobject_class,
  2272. PROP_TEST_OBJ_FLOAT,
  2273. pspec);
  2274. /**
  2275. * TestObj:double:
  2276. */
  2277. pspec = g_param_spec_double ("double",
  2278. "double property",
  2279. "A contained double",
  2280. G_MINDOUBLE,
  2281. G_MAXDOUBLE,
  2282. 1.0f,
  2283. G_PARAM_READWRITE);
  2284. g_object_class_install_property (gobject_class,
  2285. PROP_TEST_OBJ_DOUBLE,
  2286. pspec);
  2287. /**
  2288. * TestObj:string:
  2289. */
  2290. pspec = g_param_spec_string ("string",
  2291. "string property",
  2292. "A contained string",
  2293. NULL,
  2294. G_PARAM_READWRITE);
  2295. g_object_class_install_property (gobject_class,
  2296. PROP_TEST_OBJ_STRING,
  2297. pspec);
  2298. /**
  2299. * TestObj:gtype:
  2300. */
  2301. pspec = g_param_spec_gtype ("gtype",
  2302. "GType property",
  2303. "A GType property",
  2304. G_TYPE_NONE,
  2305. G_PARAM_READWRITE);
  2306. g_object_class_install_property (gobject_class,
  2307. PROP_TEST_OBJ_GTYPE,
  2308. pspec);
  2309. klass->matrix = regress_test_obj_default_matrix;
  2310. }
  2311. static void
  2312. regress_test_obj_init (RegressTestObj *obj)
  2313. {
  2314. obj->bare = NULL;
  2315. obj->boxed = NULL;
  2316. obj->hash_table = NULL;
  2317. obj->gtype = G_TYPE_INVALID;
  2318. }
  2319. /**
  2320. * regress_test_obj_new: (constructor)
  2321. * @obj: A #RegressTestObj
  2322. */
  2323. RegressTestObj *
  2324. regress_test_obj_new (RegressTestObj *obj)
  2325. {
  2326. return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
  2327. }
  2328. /**
  2329. * regress_constructor: (constructor)
  2330. *
  2331. */
  2332. RegressTestObj *
  2333. regress_constructor (void)
  2334. {
  2335. return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
  2336. }
  2337. /**
  2338. * regress_test_obj_new_from_file:
  2339. */
  2340. RegressTestObj *
  2341. regress_test_obj_new_from_file (const char *x, GError **error)
  2342. {
  2343. return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
  2344. }
  2345. /**
  2346. * regress_test_obj_set_bare:
  2347. * @bare: (allow-none):
  2348. */
  2349. void
  2350. regress_test_obj_set_bare (RegressTestObj *obj, GObject *bare)
  2351. {
  2352. if (obj->bare)
  2353. g_object_unref (obj->bare);
  2354. obj->bare = bare;
  2355. if (obj->bare)
  2356. g_object_ref (obj->bare);
  2357. }
  2358. void
  2359. regress_test_obj_emit_sig_with_obj (RegressTestObj *obj)
  2360. {
  2361. RegressTestObj *obj_param = regress_constructor ();
  2362. g_object_set (obj_param, "int", 3, NULL);
  2363. g_signal_emit_by_name (obj, "sig-with-obj", obj_param);
  2364. g_object_unref (obj_param);
  2365. }
  2366. #ifndef _GI_DISABLE_CAIRO
  2367. void
  2368. regress_test_obj_emit_sig_with_foreign_struct (RegressTestObj *obj)
  2369. {
  2370. cairo_t *cr = regress_test_cairo_context_full_return ();
  2371. g_signal_emit_by_name (obj, "sig-with-foreign-struct", cr);
  2372. cairo_destroy (cr);
  2373. }
  2374. #endif
  2375. void
  2376. regress_test_obj_emit_sig_with_int64 (RegressTestObj *obj)
  2377. {
  2378. gint64 ret = 0;
  2379. RegressTestObj *obj_param = regress_constructor ();
  2380. g_signal_emit_by_name (obj, "sig-with-int64-prop", G_MAXINT64, &ret);
  2381. g_object_unref (obj_param);
  2382. g_assert (ret == G_MAXINT64);
  2383. }
  2384. void
  2385. regress_test_obj_emit_sig_with_uint64 (RegressTestObj *obj)
  2386. {
  2387. guint64 ret = 0;
  2388. RegressTestObj *obj_param = regress_constructor ();
  2389. g_signal_emit_by_name (obj, "sig-with-uint64-prop", G_MAXUINT64, &ret);
  2390. g_object_unref (obj_param);
  2391. g_assert (ret == G_MAXUINT64);
  2392. }
  2393. /**
  2394. * regress_test_obj_emit_sig_with_array_len_prop:
  2395. */
  2396. void
  2397. regress_test_obj_emit_sig_with_array_len_prop (RegressTestObj *obj)
  2398. {
  2399. int arr[] = { 0, 1, 2, 3, 4 };
  2400. g_signal_emit_by_name (obj, "sig-with-array-len-prop", &arr, 5);
  2401. }
  2402. int
  2403. regress_test_obj_instance_method (RegressTestObj *obj)
  2404. {
  2405. return -1;
  2406. }
  2407. /**
  2408. * regress_test_obj_instance_method_full:
  2409. * @obj: (transfer full):
  2410. *
  2411. */
  2412. void
  2413. regress_test_obj_instance_method_full (RegressTestObj *obj)
  2414. {
  2415. g_object_unref (obj);
  2416. }
  2417. double
  2418. regress_test_obj_static_method (int x)
  2419. {
  2420. return x;
  2421. }
  2422. /**
  2423. * regress_forced_method: (method)
  2424. * @obj: A #RegressTestObj
  2425. *
  2426. */
  2427. void
  2428. regress_forced_method (RegressTestObj *obj)
  2429. {
  2430. }
  2431. /**
  2432. * regress_test_obj_torture_signature_0:
  2433. * @obj: A #RegressTestObj
  2434. * @x:
  2435. * @y: (out):
  2436. * @z: (out):
  2437. * @foo:
  2438. * @q: (out):
  2439. * @m:
  2440. *
  2441. */
  2442. void
  2443. regress_test_obj_torture_signature_0 (RegressTestObj *obj,
  2444. int x,
  2445. double *y,
  2446. int *z,
  2447. const char *foo,
  2448. int *q,
  2449. guint m)
  2450. {
  2451. *y = x;
  2452. *z = x * 2;
  2453. *q = g_utf8_strlen (foo, -1) + m;
  2454. }
  2455. /**
  2456. * regress_test_obj_torture_signature_1:
  2457. * @obj: A #RegressTestObj
  2458. * @x:
  2459. * @y: (out):
  2460. * @z: (out):
  2461. * @foo:
  2462. * @q: (out):
  2463. * @m:
  2464. * @error: A #GError
  2465. *
  2466. * This function throws an error if m is odd.
  2467. */
  2468. gboolean
  2469. regress_test_obj_torture_signature_1 (RegressTestObj *obj,
  2470. int x,
  2471. double *y,
  2472. int *z,
  2473. const char *foo,
  2474. int *q,
  2475. guint m,
  2476. GError **error)
  2477. {
  2478. *y = x;
  2479. *z = x * 2;
  2480. *q = g_utf8_strlen (foo, -1) + m;
  2481. if (m % 2 == 0)
  2482. return TRUE;
  2483. g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "m is odd");
  2484. return FALSE;
  2485. }
  2486. /**
  2487. * regress_test_obj_skip_return_val:
  2488. * @obj: a #RegressTestObj
  2489. * @a: Parameter.
  2490. * @out_b: (out): A return value.
  2491. * @c: Other parameter.
  2492. * @inout_d: (inout): Will be incremented.
  2493. * @out_sum: (out): Return value.
  2494. * @num1: Number.
  2495. * @num2: Number.
  2496. * @error: Return location for error.
  2497. *
  2498. * Check that the return value is skipped
  2499. *
  2500. * Returns: (skip): %TRUE if the call succeeds, %FALSE if @error is set.
  2501. */
  2502. gboolean
  2503. regress_test_obj_skip_return_val (RegressTestObj *obj,
  2504. gint a,
  2505. gint *out_b,
  2506. gdouble c,
  2507. gint *inout_d,
  2508. gint *out_sum,
  2509. gint num1,
  2510. gint num2,
  2511. GError **error)
  2512. {
  2513. if (out_b != NULL)
  2514. *out_b = a + 1;
  2515. if (inout_d != NULL)
  2516. *inout_d = *inout_d + 1;
  2517. if (out_sum != NULL)
  2518. *out_sum = num1 + 10*num2;
  2519. return TRUE;
  2520. }
  2521. /**
  2522. * regress_test_obj_skip_return_val_no_out:
  2523. * @obj: a #RegressTestObj
  2524. * @a: Parameter.
  2525. * @error: Return location for error.
  2526. *
  2527. * Check that the return value is skipped. Succeed if a is nonzero, otherwise
  2528. * raise an error.
  2529. *
  2530. * Returns: (skip): %TRUE if the call succeeds, %FALSE if @error is set.
  2531. */
  2532. gboolean
  2533. regress_test_obj_skip_return_val_no_out (RegressTestObj *obj,
  2534. gint a,
  2535. GError **error)
  2536. {
  2537. if (a == 0) {
  2538. g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "a is zero");
  2539. return FALSE;
  2540. } else {
  2541. return TRUE;
  2542. }
  2543. }
  2544. /**
  2545. * regress_test_obj_skip_param:
  2546. * @obj: A #RegressTestObj.
  2547. * @a: Parameter.
  2548. * @out_b: (out): Return value.
  2549. * @c: (skip): Other parameter.
  2550. * @inout_d: (inout): Will be incremented.
  2551. * @out_sum: (out): Return value.
  2552. * @num1: Number.
  2553. * @num2: Number.
  2554. * @error: Return location for error.
  2555. *
  2556. * Check that a parameter is skipped
  2557. *
  2558. * Returns: %TRUE if the call succeeds, %FALSE if @error is set.
  2559. */
  2560. gboolean
  2561. regress_test_obj_skip_param (RegressTestObj *obj,
  2562. gint a,
  2563. gint *out_b,
  2564. gdouble c,
  2565. gint *inout_d,
  2566. gint *out_sum,
  2567. gint num1,
  2568. gint num2,
  2569. GError **error)
  2570. {
  2571. if (out_b != NULL)
  2572. *out_b = a + 1;
  2573. if (inout_d != NULL)
  2574. *inout_d = *inout_d + 1;
  2575. if (out_sum != NULL)
  2576. *out_sum = num1 + 10*num2;
  2577. return TRUE;
  2578. }
  2579. /**
  2580. * regress_test_obj_skip_out_param:
  2581. * @obj: A #RegressTestObj.
  2582. * @a: Parameter.
  2583. * @out_b: (out) (skip): Return value.
  2584. * @c: Other parameter.
  2585. * @inout_d: (inout): Will be incremented.
  2586. * @out_sum: (out): Return value.
  2587. * @num1: Number.
  2588. * @num2: Number.
  2589. * @error: Return location for error.
  2590. *
  2591. * Check that the out value is skipped
  2592. *
  2593. * Returns: %TRUE if the call succeeds, %FALSE if @error is set.
  2594. */
  2595. gboolean
  2596. regress_test_obj_skip_out_param (RegressTestObj *obj,
  2597. gint a,
  2598. gint *out_b,
  2599. gdouble c,
  2600. gint *inout_d,
  2601. gint *out_sum,
  2602. gint num1,
  2603. gint num2,
  2604. GError **error)
  2605. {
  2606. if (out_b != NULL)
  2607. *out_b = a + 1;
  2608. if (inout_d != NULL)
  2609. *inout_d = *inout_d + 1;
  2610. if (out_sum != NULL)
  2611. *out_sum = num1 + 10*num2;
  2612. return TRUE;
  2613. }
  2614. /**
  2615. * regress_test_obj_skip_inout_param:
  2616. * @obj: A #RegressTestObj.
  2617. * @a: Parameter.
  2618. * @out_b: (out): Return value.
  2619. * @c: Other parameter.
  2620. * @inout_d: (inout) (skip): Will be incremented.
  2621. * @out_sum: (out): Return value.
  2622. * @num1: Number.
  2623. * @num2: Number.
  2624. * @error: Return location for error.
  2625. *
  2626. * Check that the out value is skipped
  2627. *
  2628. * Returns: %TRUE if the call succeeds, %FALSE if @error is set.
  2629. */
  2630. gboolean
  2631. regress_test_obj_skip_inout_param (RegressTestObj *obj,
  2632. gint a,
  2633. gint *out_b,
  2634. gdouble c,
  2635. gint *inout_d,
  2636. gint *out_sum,
  2637. gint num1,
  2638. gint num2,
  2639. GError **error)
  2640. {
  2641. if (out_b != NULL)
  2642. *out_b = a + 1;
  2643. if (inout_d != NULL)
  2644. *inout_d = *inout_d + 1;
  2645. if (out_sum != NULL)
  2646. *out_sum = num1 + 10*num2;
  2647. return TRUE;
  2648. }
  2649. /**
  2650. * regress_test_obj_do_matrix: (virtual matrix)
  2651. * @obj: A #RegressTestObj
  2652. * @somestr: Meaningless string
  2653. *
  2654. * This method is virtual. Notably its name differs from the virtual
  2655. * slot name, which makes it useful for testing bindings handle this
  2656. * case.
  2657. */
  2658. int
  2659. regress_test_obj_do_matrix (RegressTestObj *obj, const char *somestr)
  2660. {
  2661. return REGRESS_TEST_OBJ_GET_CLASS (obj)->matrix (obj, somestr);
  2662. }
  2663. /**
  2664. * regress_func_obj_null_in:
  2665. * @obj: (allow-none): A #RegressTestObj
  2666. */
  2667. void
  2668. regress_func_obj_null_in (RegressTestObj *obj)
  2669. {
  2670. }
  2671. /**
  2672. * regress_test_obj_null_out:
  2673. * @obj: (allow-none) (out): A #RegressTestObj
  2674. */
  2675. void
  2676. regress_test_obj_null_out (RegressTestObj **obj)
  2677. {
  2678. if (obj)
  2679. *obj = NULL;
  2680. }
  2681. /**
  2682. * regress_func_obj_nullable_in:
  2683. * @obj: (nullable): A #RegressTestObj
  2684. */
  2685. void
  2686. regress_func_obj_nullable_in (RegressTestObj *obj)
  2687. {
  2688. }
  2689. /**
  2690. * regress_test_obj_not_nullable_typed_gpointer_in:
  2691. * @obj: A #RegressTestObj
  2692. * @input: (type GObject): some #GObject
  2693. */
  2694. void
  2695. regress_test_obj_not_nullable_typed_gpointer_in (RegressTestObj *obj,
  2696. gpointer input)
  2697. {
  2698. }
  2699. /**
  2700. * regress_test_obj_not_nullable_element_typed_gpointer_in:
  2701. * @obj: A #RegressTestObj
  2702. * @input: (element-type guint8) (array length=count): some uint8 array
  2703. * @count: length of @input
  2704. */
  2705. void
  2706. regress_test_obj_not_nullable_element_typed_gpointer_in (RegressTestObj *obj,
  2707. gpointer input,
  2708. guint count)
  2709. {
  2710. }
  2711. /**
  2712. * regress_test_array_fixed_out_objects:
  2713. * @objs: (out) (array fixed-size=2) (transfer full): An array of #RegressTestObj
  2714. */
  2715. void
  2716. regress_test_array_fixed_out_objects (RegressTestObj ***objs)
  2717. {
  2718. RegressTestObj **values = (RegressTestObj**)g_new(gpointer, 2);
  2719. values[0] = regress_constructor();
  2720. values[1] = regress_constructor();
  2721. *objs = values;
  2722. }
  2723. typedef struct _CallbackInfo CallbackInfo;
  2724. struct _CallbackInfo
  2725. {
  2726. RegressTestCallbackUserData callback;
  2727. GDestroyNotify notify;
  2728. gpointer user_data;
  2729. };
  2730. G_DEFINE_TYPE(RegressTestSubObj, regress_test_sub_obj, REGRESS_TEST_TYPE_OBJ);
  2731. static void
  2732. regress_test_sub_obj_class_init (RegressTestSubObjClass *klass)
  2733. {
  2734. }
  2735. static void
  2736. regress_test_sub_obj_init (RegressTestSubObj *obj)
  2737. {
  2738. }
  2739. RegressTestObj*
  2740. regress_test_sub_obj_new ()
  2741. {
  2742. return g_object_new (REGRESS_TEST_TYPE_SUB_OBJ, NULL);
  2743. }
  2744. int
  2745. regress_test_sub_obj_instance_method (RegressTestSubObj *obj)
  2746. {
  2747. return 0;
  2748. }
  2749. void
  2750. regress_test_sub_obj_unset_bare (RegressTestSubObj *obj)
  2751. {
  2752. regress_test_obj_set_bare(REGRESS_TEST_OBJECT(obj), NULL);
  2753. }
  2754. /* RegressTestFundamental */
  2755. /**
  2756. * regress_test_fundamental_object_ref:
  2757. *
  2758. * Returns: (transfer full): A new #RegressTestFundamentalObject
  2759. */
  2760. RegressTestFundamentalObject *
  2761. regress_test_fundamental_object_ref (RegressTestFundamentalObject * fundamental_object)
  2762. {
  2763. g_return_val_if_fail (fundamental_object != NULL, NULL);
  2764. g_atomic_int_inc (&fundamental_object->refcount);
  2765. return fundamental_object;
  2766. }
  2767. static void
  2768. regress_test_fundamental_object_free (RegressTestFundamentalObject * fundamental_object)
  2769. {
  2770. RegressTestFundamentalObjectClass *mo_class;
  2771. regress_test_fundamental_object_ref (fundamental_object);
  2772. mo_class = REGRESS_TEST_FUNDAMENTAL_OBJECT_GET_CLASS (fundamental_object);
  2773. mo_class->finalize (fundamental_object);
  2774. if (G_LIKELY (g_atomic_int_dec_and_test (&fundamental_object->refcount))) {
  2775. g_type_free_instance ((GTypeInstance *) fundamental_object);
  2776. }
  2777. }
  2778. void
  2779. regress_test_fundamental_object_unref (RegressTestFundamentalObject * fundamental_object)
  2780. {
  2781. g_return_if_fail (fundamental_object != NULL);
  2782. g_return_if_fail (fundamental_object->refcount > 0);
  2783. if (G_UNLIKELY (g_atomic_int_dec_and_test (&fundamental_object->refcount))) {
  2784. regress_test_fundamental_object_free (fundamental_object);
  2785. }
  2786. }
  2787. static void
  2788. regress_test_fundamental_object_replace (RegressTestFundamentalObject ** olddata, RegressTestFundamentalObject * newdata)
  2789. {
  2790. RegressTestFundamentalObject *olddata_val;
  2791. g_return_if_fail (olddata != NULL);
  2792. olddata_val = g_atomic_pointer_get ((gpointer *) olddata);
  2793. if (olddata_val == newdata)
  2794. return;
  2795. if (newdata)
  2796. regress_test_fundamental_object_ref (newdata);
  2797. while (!g_atomic_pointer_compare_and_exchange ((gpointer *) olddata,
  2798. olddata_val, newdata)) {
  2799. olddata_val = g_atomic_pointer_get ((gpointer *) olddata);
  2800. }
  2801. if (olddata_val)
  2802. regress_test_fundamental_object_unref (olddata_val);
  2803. }
  2804. static void
  2805. regress_test_value_fundamental_object_init (GValue * value)
  2806. {
  2807. value->data[0].v_pointer = NULL;
  2808. }
  2809. static void
  2810. regress_test_value_fundamental_object_free (GValue * value)
  2811. {
  2812. if (value->data[0].v_pointer) {
  2813. regress_test_fundamental_object_unref (REGRESS_TEST_FUNDAMENTAL_OBJECT_CAST (value->data[0].v_pointer));
  2814. }
  2815. }
  2816. static void
  2817. regress_test_value_fundamental_object_copy (const GValue * src_value, GValue * dest_value)
  2818. {
  2819. if (src_value->data[0].v_pointer) {
  2820. dest_value->data[0].v_pointer =
  2821. regress_test_fundamental_object_ref (REGRESS_TEST_FUNDAMENTAL_OBJECT_CAST (src_value->data[0].
  2822. v_pointer));
  2823. } else {
  2824. dest_value->data[0].v_pointer = NULL;
  2825. }
  2826. }
  2827. static gpointer
  2828. regress_test_value_fundamental_object_peek_pointer (const GValue * value)
  2829. {
  2830. return value->data[0].v_pointer;
  2831. }
  2832. static gchar *
  2833. regress_test_value_fundamental_object_collect (GValue * value,
  2834. guint n_collect_values,
  2835. GTypeCValue * collect_values,
  2836. guint collect_flags)
  2837. {
  2838. if (collect_values[0].v_pointer) {
  2839. value->data[0].v_pointer =
  2840. regress_test_fundamental_object_ref (collect_values[0].v_pointer);
  2841. } else {
  2842. value->data[0].v_pointer = NULL;
  2843. }
  2844. return NULL;
  2845. }
  2846. static gchar *
  2847. regress_test_value_fundamental_object_lcopy (const GValue * value,
  2848. guint n_collect_values,
  2849. GTypeCValue * collect_values,
  2850. guint collect_flags)
  2851. {
  2852. gpointer *fundamental_object_p = collect_values[0].v_pointer;
  2853. if (!fundamental_object_p) {
  2854. return g_strdup_printf ("value location for '%s' passed as NULL",
  2855. G_VALUE_TYPE_NAME (value));
  2856. }
  2857. if (!value->data[0].v_pointer)
  2858. *fundamental_object_p = NULL;
  2859. else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
  2860. *fundamental_object_p = value->data[0].v_pointer;
  2861. else
  2862. *fundamental_object_p = regress_test_fundamental_object_ref (value->data[0].v_pointer);
  2863. return NULL;
  2864. }
  2865. static void
  2866. regress_test_fundamental_object_finalize (RegressTestFundamentalObject * obj)
  2867. {
  2868. }
  2869. static RegressTestFundamentalObject *
  2870. regress_test_fundamental_object_copy_default (const RegressTestFundamentalObject * obj)
  2871. {
  2872. g_warning ("RegressTestFundamentalObject classes must implement RegressTestFundamentalObject::copy");
  2873. return NULL;
  2874. }
  2875. static void
  2876. regress_test_fundamental_object_class_init (gpointer g_class, gpointer class_data)
  2877. {
  2878. RegressTestFundamentalObjectClass *mo_class = REGRESS_TEST_FUNDAMENTAL_OBJECT_CLASS (g_class);
  2879. mo_class->copy = regress_test_fundamental_object_copy_default;
  2880. mo_class->finalize = regress_test_fundamental_object_finalize;
  2881. }
  2882. static void
  2883. regress_test_fundamental_object_init (GTypeInstance * instance, gpointer klass)
  2884. {
  2885. RegressTestFundamentalObject *fundamental_object = REGRESS_TEST_FUNDAMENTAL_OBJECT_CAST (instance);
  2886. fundamental_object->refcount = 1;
  2887. }
  2888. /**
  2889. * RegressTestFundamentalObject: (ref-func regress_test_fundamental_object_ref) (unref-func regress_test_fundamental_object_unref) (set-value-func regress_test_value_set_fundamental_object) (get-value-func regress_test_value_get_fundamental_object)
  2890. */
  2891. GType
  2892. regress_test_fundamental_object_get_type (void)
  2893. {
  2894. static GType _test_fundamental_object_type = 0;
  2895. if (G_UNLIKELY (_test_fundamental_object_type == 0)) {
  2896. static const GTypeValueTable value_table = {
  2897. regress_test_value_fundamental_object_init,
  2898. regress_test_value_fundamental_object_free,
  2899. regress_test_value_fundamental_object_copy,
  2900. regress_test_value_fundamental_object_peek_pointer,
  2901. (char *) "p",
  2902. regress_test_value_fundamental_object_collect,
  2903. (char *) "p",
  2904. regress_test_value_fundamental_object_lcopy
  2905. };
  2906. static const GTypeInfo fundamental_object_info = {
  2907. sizeof (RegressTestFundamentalObjectClass),
  2908. NULL, NULL,
  2909. regress_test_fundamental_object_class_init,
  2910. NULL,
  2911. NULL,
  2912. sizeof (RegressTestFundamentalObject),
  2913. 0,
  2914. (GInstanceInitFunc) regress_test_fundamental_object_init,
  2915. &value_table
  2916. };
  2917. static const GTypeFundamentalInfo fundamental_object_fundamental_info = {
  2918. (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE |
  2919. G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE)
  2920. };
  2921. _test_fundamental_object_type = g_type_fundamental_next ();
  2922. g_type_register_fundamental (_test_fundamental_object_type, "RegressTestFundamentalObject",
  2923. &fundamental_object_info, &fundamental_object_fundamental_info, G_TYPE_FLAG_ABSTRACT);
  2924. }
  2925. return _test_fundamental_object_type;
  2926. }
  2927. /**
  2928. * regress_test_value_set_fundamental_object: (skip)
  2929. * @value:
  2930. * @fundamental_object:
  2931. */
  2932. void
  2933. regress_test_value_set_fundamental_object (GValue * value, RegressTestFundamentalObject * fundamental_object)
  2934. {
  2935. gpointer *pointer_p;
  2936. g_return_if_fail (REGRESS_TEST_VALUE_HOLDS_FUNDAMENTAL_OBJECT (value));
  2937. g_return_if_fail (fundamental_object == NULL || REGRESS_TEST_IS_FUNDAMENTAL_OBJECT (fundamental_object));
  2938. pointer_p = &value->data[0].v_pointer;
  2939. regress_test_fundamental_object_replace ((RegressTestFundamentalObject **) pointer_p, fundamental_object);
  2940. }
  2941. /**
  2942. * regress_test_value_get_fundamental_object: (skip)
  2943. * @value:
  2944. */
  2945. RegressTestFundamentalObject *
  2946. regress_test_value_get_fundamental_object (const GValue * value)
  2947. {
  2948. g_return_val_if_fail (REGRESS_TEST_VALUE_HOLDS_FUNDAMENTAL_OBJECT (value), NULL);
  2949. return value->data[0].v_pointer;
  2950. }
  2951. static RegressTestFundamentalObjectClass *parent_class = NULL;
  2952. G_DEFINE_TYPE (RegressTestFundamentalSubObject, regress_test_fundamental_sub_object, REGRESS_TEST_TYPE_FUNDAMENTAL_OBJECT);
  2953. static RegressTestFundamentalSubObject *
  2954. _regress_test_fundamental_sub_object_copy (RegressTestFundamentalSubObject * fundamental_sub_object)
  2955. {
  2956. RegressTestFundamentalSubObject *copy;
  2957. copy = regress_test_fundamental_sub_object_new(NULL);
  2958. copy->data = g_strdup(fundamental_sub_object->data);
  2959. return copy;
  2960. }
  2961. static void
  2962. regress_test_fundamental_sub_object_finalize (RegressTestFundamentalSubObject * fundamental_sub_object)
  2963. {
  2964. g_return_if_fail (fundamental_sub_object != NULL);
  2965. g_free(fundamental_sub_object->data);
  2966. regress_test_fundamental_object_finalize (REGRESS_TEST_FUNDAMENTAL_OBJECT (fundamental_sub_object));
  2967. }
  2968. static void
  2969. regress_test_fundamental_sub_object_class_init (RegressTestFundamentalSubObjectClass * klass)
  2970. {
  2971. parent_class = g_type_class_peek_parent (klass);
  2972. klass->fundamental_object_class.copy = (RegressTestFundamentalObjectCopyFunction) _regress_test_fundamental_sub_object_copy;
  2973. klass->fundamental_object_class.finalize =
  2974. (RegressTestFundamentalObjectFinalizeFunction) regress_test_fundamental_sub_object_finalize;
  2975. }
  2976. static void
  2977. regress_test_fundamental_sub_object_init(RegressTestFundamentalSubObject *object)
  2978. {
  2979. }
  2980. /**
  2981. * regress_test_fundamental_sub_object_new:
  2982. */
  2983. RegressTestFundamentalSubObject *
  2984. regress_test_fundamental_sub_object_new (const char * data)
  2985. {
  2986. RegressTestFundamentalSubObject *object;
  2987. object = (RegressTestFundamentalSubObject *) g_type_create_instance (regress_test_fundamental_sub_object_get_type());
  2988. object->data = g_strdup(data);
  2989. return object;
  2990. }
  2991. /**
  2992. * regress_test_callback:
  2993. * @callback: (scope call) (allow-none):
  2994. *
  2995. **/
  2996. int
  2997. regress_test_callback (RegressTestCallback callback)
  2998. {
  2999. if (callback != NULL)
  3000. return callback();
  3001. return 0;
  3002. }
  3003. /**
  3004. * regress_test_multi_callback:
  3005. * @callback: (scope call) (allow-none):
  3006. *
  3007. **/
  3008. int
  3009. regress_test_multi_callback (RegressTestCallback callback)
  3010. {
  3011. int sum = 0;
  3012. if (callback != NULL) {
  3013. sum += callback();
  3014. sum += callback();
  3015. }
  3016. return sum;
  3017. }
  3018. /**
  3019. * regress_test_array_callback:
  3020. * @callback: (scope call):
  3021. *
  3022. **/
  3023. int regress_test_array_callback (RegressTestCallbackArray callback)
  3024. {
  3025. static const char *strings[] = { "one", "two", "three" };
  3026. static int ints[] = { -1, 0, 1, 2 };
  3027. int sum = 0;
  3028. sum += callback(ints, 4, strings, 3);
  3029. sum += callback(ints, 4, strings, 3);
  3030. return sum;
  3031. }
  3032. /**
  3033. * regress_test_array_inout_callback:
  3034. * @callback: (scope call):
  3035. *
  3036. */
  3037. int
  3038. regress_test_array_inout_callback (RegressTestCallbackArrayInOut callback)
  3039. {
  3040. int *ints;
  3041. int length;
  3042. ints = g_new (int, 5);
  3043. for (length = 0; length < 5; ++length)
  3044. ints[length] = length - 2;
  3045. callback (&ints, &length);
  3046. g_assert_cmpint (length, ==, 4);
  3047. for (length = 0; length < 4; ++length)
  3048. g_assert_cmpint (ints[length], ==, length - 1);
  3049. callback (&ints, &length);
  3050. g_assert_cmpint (length, ==, 3);
  3051. for (length = 0; length < 3; ++length)
  3052. g_assert_cmpint (ints[length], ==, length);
  3053. g_free (ints);
  3054. return length;
  3055. }
  3056. /**
  3057. * regress_test_simple_callback:
  3058. * @callback: (scope call) (allow-none):
  3059. *
  3060. **/
  3061. void
  3062. regress_test_simple_callback (RegressTestSimpleCallback callback)
  3063. {
  3064. if (callback != NULL)
  3065. callback();
  3066. return;
  3067. }
  3068. /**
  3069. * regress_test_noptr_callback:
  3070. * @callback: (scope call) (allow-none):
  3071. *
  3072. **/
  3073. void
  3074. regress_test_noptr_callback (RegressTestNoPtrCallback callback)
  3075. {
  3076. if (callback != NULL)
  3077. callback();
  3078. return;
  3079. }
  3080. /**
  3081. * regress_test_callback_user_data:
  3082. * @callback: (scope call):
  3083. * @user_data: (not nullable):
  3084. *
  3085. * Call - callback parameter persists for the duration of the method
  3086. * call and can be released on return.
  3087. **/
  3088. int
  3089. regress_test_callback_user_data (RegressTestCallbackUserData callback,
  3090. gpointer user_data)
  3091. {
  3092. return callback(user_data);
  3093. }
  3094. /**
  3095. * regress_test_callback_return_full:
  3096. * @callback: (scope call):
  3097. *
  3098. **/
  3099. void
  3100. regress_test_callback_return_full (RegressTestCallbackReturnFull callback)
  3101. {
  3102. RegressTestObj *obj;
  3103. obj = callback ();
  3104. g_object_unref (obj);
  3105. }
  3106. static GSList *notified_callbacks = NULL;
  3107. /**
  3108. * regress_test_callback_destroy_notify:
  3109. * @callback: (scope notified):
  3110. *
  3111. * Notified - callback persists until a DestroyNotify delegate
  3112. * is invoked.
  3113. **/
  3114. int
  3115. regress_test_callback_destroy_notify (RegressTestCallbackUserData callback,
  3116. gpointer user_data,
  3117. GDestroyNotify notify)
  3118. {
  3119. int retval;
  3120. CallbackInfo *info;
  3121. retval = callback(user_data);
  3122. info = g_slice_new(CallbackInfo);
  3123. info->callback = callback;
  3124. info->notify = notify;
  3125. info->user_data = user_data;
  3126. notified_callbacks = g_slist_prepend(notified_callbacks, info);
  3127. return retval;
  3128. }
  3129. /**
  3130. * regress_test_callback_destroy_notify_no_user_data:
  3131. * @callback: (scope notified):
  3132. *
  3133. * Adds a scope notified callback with no user data. This can invoke an error
  3134. * condition in bindings which needs to be tested.
  3135. **/
  3136. int
  3137. regress_test_callback_destroy_notify_no_user_data (RegressTestCallbackUserData callback,
  3138. GDestroyNotify notify)
  3139. {
  3140. return regress_test_callback_destroy_notify(callback, NULL, notify);
  3141. }
  3142. /**
  3143. * regress_test_callback_thaw_notifications:
  3144. *
  3145. * Invokes all callbacks installed by #test_callback_destroy_notify(),
  3146. * adding up their return values, and removes them, invoking the
  3147. * corresponding destroy notfications.
  3148. *
  3149. * Return value: Sum of the return values of the invoked callbacks.
  3150. */
  3151. int
  3152. regress_test_callback_thaw_notifications (void)
  3153. {
  3154. int retval = 0;
  3155. GSList *node;
  3156. for (node = notified_callbacks; node != NULL; node = node->next)
  3157. {
  3158. CallbackInfo *info = node->data;
  3159. retval += info->callback (info->user_data);
  3160. if (info->notify)
  3161. info->notify (info->user_data);
  3162. g_slice_free (CallbackInfo, info);
  3163. }
  3164. g_slist_free (notified_callbacks);
  3165. notified_callbacks = NULL;
  3166. return retval;
  3167. }
  3168. static GSList *async_callbacks = NULL;
  3169. /**
  3170. * regress_test_callback_async:
  3171. * @callback: (scope async):
  3172. *
  3173. **/
  3174. void
  3175. regress_test_callback_async (RegressTestCallbackUserData callback,
  3176. gpointer user_data)
  3177. {
  3178. CallbackInfo *info;
  3179. info = g_slice_new(CallbackInfo);
  3180. info->callback = callback;
  3181. info->user_data = user_data;
  3182. async_callbacks = g_slist_prepend(async_callbacks, info);
  3183. }
  3184. /**
  3185. * regress_test_callback_thaw_async:
  3186. */
  3187. int
  3188. regress_test_callback_thaw_async (void)
  3189. {
  3190. int retval = 0;
  3191. GSList *node;
  3192. for (node = async_callbacks; node != NULL; node = node->next)
  3193. {
  3194. CallbackInfo *info = node->data;
  3195. retval = info->callback (info->user_data);
  3196. g_slice_free (CallbackInfo, info);
  3197. }
  3198. g_slist_free (async_callbacks);
  3199. async_callbacks = NULL;
  3200. return retval;
  3201. }
  3202. void
  3203. regress_test_async_ready_callback (GAsyncReadyCallback callback)
  3204. {
  3205. G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  3206. GSimpleAsyncResult *result = g_simple_async_result_new (NULL, callback, NULL,
  3207. regress_test_async_ready_callback);
  3208. g_simple_async_result_complete_in_idle (result);
  3209. g_object_unref (result);
  3210. G_GNUC_END_IGNORE_DEPRECATIONS
  3211. }
  3212. /**
  3213. * regress_test_obj_instance_method_callback:
  3214. * @callback: (scope call) (allow-none):
  3215. *
  3216. **/
  3217. void
  3218. regress_test_obj_instance_method_callback (RegressTestObj *obj, RegressTestCallback callback)
  3219. {
  3220. if (callback != NULL)
  3221. callback();
  3222. }
  3223. /**
  3224. * regress_test_obj_static_method_callback:
  3225. * @callback: (scope call) (allow-none):
  3226. *
  3227. **/
  3228. void
  3229. regress_test_obj_static_method_callback (RegressTestCallback callback)
  3230. {
  3231. if (callback != NULL)
  3232. callback();
  3233. }
  3234. /**
  3235. * regress_test_obj_new_callback:
  3236. * @callback: (scope notified):
  3237. **/
  3238. RegressTestObj *
  3239. regress_test_obj_new_callback (RegressTestCallbackUserData callback, gpointer user_data,
  3240. GDestroyNotify notify)
  3241. {
  3242. CallbackInfo *info;
  3243. callback(user_data);
  3244. info = g_slice_new(CallbackInfo);
  3245. info->callback = callback;
  3246. info->notify = notify;
  3247. info->user_data = user_data;
  3248. notified_callbacks = g_slist_prepend(notified_callbacks, info);
  3249. return g_object_new (REGRESS_TEST_TYPE_OBJ, NULL);
  3250. }
  3251. /**
  3252. * regress_test_hash_table_callback:
  3253. * @data: (element-type utf8 gint): GHashTable that gets passed to callback
  3254. * @callback: (scope call):
  3255. **/
  3256. void
  3257. regress_test_hash_table_callback (GHashTable *data, RegressTestCallbackHashtable callback)
  3258. {
  3259. callback (data);
  3260. }
  3261. /**
  3262. * regress_test_gerror_callback:
  3263. * @callback: (scope call):
  3264. **/
  3265. void
  3266. regress_test_gerror_callback (RegressTestCallbackGError callback)
  3267. {
  3268. GError *error;
  3269. error = g_error_new_literal (G_IO_ERROR,
  3270. G_IO_ERROR_NOT_SUPPORTED,
  3271. "regression test error");
  3272. callback (error);
  3273. g_error_free (error);
  3274. }
  3275. /**
  3276. * regress_test_null_gerror_callback:
  3277. * @callback: (scope call):
  3278. **/
  3279. void
  3280. regress_test_null_gerror_callback (RegressTestCallbackGError callback)
  3281. {
  3282. callback (NULL);
  3283. }
  3284. /**
  3285. * regress_test_owned_gerror_callback:
  3286. * @callback: (scope call):
  3287. **/
  3288. void
  3289. regress_test_owned_gerror_callback (RegressTestCallbackOwnedGError callback)
  3290. {
  3291. GError *error;
  3292. error = g_error_new_literal (G_IO_ERROR,
  3293. G_IO_ERROR_PERMISSION_DENIED,
  3294. "regression test owned error");
  3295. callback (error);
  3296. }
  3297. /**
  3298. * regress_test_skip_unannotated_callback: (skip)
  3299. * @callback: No annotation here
  3300. *
  3301. * Should not emit a warning:
  3302. * https://bugzilla.gnome.org/show_bug.cgi?id=685399
  3303. */
  3304. void
  3305. regress_test_skip_unannotated_callback (RegressTestCallback callback)
  3306. {
  3307. }
  3308. /* interface */
  3309. static void
  3310. regress_test_interface_default_init(RegressTestInterfaceIface *iface)
  3311. {
  3312. }
  3313. typedef RegressTestInterfaceIface RegressTestInterfaceInterface;
  3314. G_DEFINE_INTERFACE (RegressTestInterface, regress_test_interface, G_TYPE_OBJECT)
  3315. /* gobject with non-standard prefix */
  3316. G_DEFINE_TYPE(RegressTestWi8021x, regress_test_wi_802_1x, G_TYPE_OBJECT);
  3317. enum
  3318. {
  3319. PROP_TEST_WI_802_1X_TESTBOOL = 1
  3320. };
  3321. static void
  3322. regress_test_wi_802_1x_set_property (GObject *object,
  3323. guint property_id,
  3324. const GValue *value,
  3325. GParamSpec *pspec)
  3326. {
  3327. RegressTestWi8021x *self = REGRESS_TEST_WI_802_1X (object);
  3328. switch (property_id)
  3329. {
  3330. case PROP_TEST_WI_802_1X_TESTBOOL:
  3331. regress_test_wi_802_1x_set_testbool (self, g_value_get_boolean (value));
  3332. break;
  3333. default:
  3334. /* We don't have any other property... */
  3335. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  3336. break;
  3337. }
  3338. }
  3339. static void
  3340. regress_test_wi_802_1x_get_property (GObject *object,
  3341. guint property_id,
  3342. GValue *value,
  3343. GParamSpec *pspec)
  3344. {
  3345. RegressTestWi8021x *self = REGRESS_TEST_WI_802_1X (object);
  3346. switch (property_id)
  3347. {
  3348. case PROP_TEST_WI_802_1X_TESTBOOL:
  3349. g_value_set_boolean (value, regress_test_wi_802_1x_get_testbool (self));
  3350. break;
  3351. default:
  3352. /* We don't have any other property... */
  3353. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  3354. break;
  3355. }
  3356. }
  3357. static void
  3358. regress_test_wi_802_1x_dispose (GObject *gobject)
  3359. {
  3360. /* Chain up to the parent class */
  3361. G_OBJECT_CLASS (regress_test_wi_802_1x_parent_class)->dispose (gobject);
  3362. }
  3363. static void
  3364. regress_test_wi_802_1x_class_init (RegressTestWi8021xClass *klass)
  3365. {
  3366. GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  3367. GParamSpec *pspec;
  3368. gobject_class->set_property = regress_test_wi_802_1x_set_property;
  3369. gobject_class->get_property = regress_test_wi_802_1x_get_property;
  3370. gobject_class->dispose = regress_test_wi_802_1x_dispose;
  3371. pspec = g_param_spec_boolean ("testbool",
  3372. "Nick for testbool",
  3373. "Blurb for testbool",
  3374. TRUE,
  3375. G_PARAM_READWRITE);
  3376. g_object_class_install_property (gobject_class,
  3377. PROP_TEST_WI_802_1X_TESTBOOL,
  3378. pspec);
  3379. }
  3380. static void
  3381. regress_test_wi_802_1x_init (RegressTestWi8021x *obj)
  3382. {
  3383. obj->testbool = TRUE;
  3384. }
  3385. RegressTestWi8021x *
  3386. regress_test_wi_802_1x_new (void)
  3387. {
  3388. return g_object_new (REGRESS_TEST_TYPE_WI_802_1X, NULL);
  3389. }
  3390. void
  3391. regress_test_wi_802_1x_set_testbool (RegressTestWi8021x *obj, gboolean val)
  3392. {
  3393. obj->testbool = val;
  3394. }
  3395. gboolean
  3396. regress_test_wi_802_1x_get_testbool (RegressTestWi8021x *obj)
  3397. {
  3398. return obj->testbool;
  3399. }
  3400. int
  3401. regress_test_wi_802_1x_static_method (int x)
  3402. {
  3403. return 2*x;
  3404. }
  3405. /* floating gobject */
  3406. G_DEFINE_TYPE(RegressTestFloating, regress_test_floating, G_TYPE_INITIALLY_UNOWNED);
  3407. static void
  3408. regress_test_floating_finalize(GObject *object)
  3409. {
  3410. g_assert(!g_object_is_floating (object));
  3411. G_OBJECT_CLASS(regress_test_floating_parent_class)->finalize(object);
  3412. }
  3413. static void
  3414. regress_test_floating_class_init (RegressTestFloatingClass *klass)
  3415. {
  3416. GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  3417. gobject_class->finalize = regress_test_floating_finalize;
  3418. }
  3419. static void
  3420. regress_test_floating_init (RegressTestFloating *obj)
  3421. {
  3422. }
  3423. /**
  3424. * regress_test_floating_new:
  3425. *
  3426. * Returns:: A new floating #RegressTestFloating
  3427. */
  3428. RegressTestFloating *
  3429. regress_test_floating_new (void)
  3430. {
  3431. return g_object_new (REGRESS_TEST_TYPE_FLOATING, NULL);
  3432. }
  3433. /**
  3434. * regress_test_torture_signature_0:
  3435. * @x:
  3436. * @y: (out):
  3437. * @z: (out):
  3438. * @foo:
  3439. * @q: (out):
  3440. * @m:
  3441. *
  3442. */
  3443. void
  3444. regress_test_torture_signature_0 (int x,
  3445. double *y,
  3446. int *z,
  3447. const char *foo,
  3448. int *q,
  3449. guint m)
  3450. {
  3451. *y = x;
  3452. *z = x * 2;
  3453. *q = g_utf8_strlen (foo, -1) + m;
  3454. }
  3455. /**
  3456. * regress_test_torture_signature_1:
  3457. * @x:
  3458. * @y: (out):
  3459. * @z: (out):
  3460. * @foo:
  3461. * @q: (out):
  3462. * @m:
  3463. * @error: A #GError
  3464. *
  3465. * This function throws an error if m is odd.
  3466. */
  3467. gboolean
  3468. regress_test_torture_signature_1 (int x,
  3469. double *y,
  3470. int *z,
  3471. const char *foo,
  3472. int *q,
  3473. guint m,
  3474. GError **error)
  3475. {
  3476. *y = x;
  3477. *z = x * 2;
  3478. *q = g_utf8_strlen (foo, -1) + m;
  3479. if (m % 2 == 0)
  3480. return TRUE;
  3481. g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "m is odd");
  3482. return FALSE;
  3483. }
  3484. /**
  3485. * regress_test_torture_signature_2:
  3486. * @x:
  3487. * @callback:
  3488. * @user_data:
  3489. * @notify:
  3490. * @y: (out):
  3491. * @z: (out):
  3492. * @foo:
  3493. * @q: (out):
  3494. * @m:
  3495. *
  3496. */
  3497. void
  3498. regress_test_torture_signature_2 (int x,
  3499. RegressTestCallbackUserData callback,
  3500. gpointer user_data,
  3501. GDestroyNotify notify,
  3502. double *y,
  3503. int *z,
  3504. const char *foo,
  3505. int *q,
  3506. guint m)
  3507. {
  3508. *y = x;
  3509. *z = x * 2;
  3510. *q = g_utf8_strlen (foo, -1) + m;
  3511. callback(user_data);
  3512. notify (user_data);
  3513. }
  3514. /**
  3515. * regress_test_date_in_gvalue:
  3516. *
  3517. * Returns: (transfer full):
  3518. */
  3519. GValue *
  3520. regress_test_date_in_gvalue (void)
  3521. {
  3522. GValue *value = g_new0 (GValue, 1);
  3523. GDate *date = g_date_new_dmy (5, 12, 1984);
  3524. g_value_init (value, G_TYPE_DATE);
  3525. g_value_take_boxed (value, date);
  3526. return value;
  3527. }
  3528. /**
  3529. * regress_test_strv_in_gvalue:
  3530. *
  3531. * Returns: (transfer full):
  3532. */
  3533. GValue *
  3534. regress_test_strv_in_gvalue (void)
  3535. {
  3536. GValue *value = g_new0 (GValue, 1);
  3537. const char *strv[] = { "one", "two", "three", NULL };
  3538. g_value_init (value, G_TYPE_STRV);
  3539. g_value_set_boxed (value, strv);
  3540. return value;
  3541. }
  3542. /**
  3543. * regress_test_multiline_doc_comments:
  3544. *
  3545. * This is a function.
  3546. *
  3547. * It has multiple lines in the documentation.
  3548. *
  3549. * The sky is blue.
  3550. *
  3551. * You will give me your credit card number.
  3552. */
  3553. void
  3554. regress_test_multiline_doc_comments (void)
  3555. {
  3556. }
  3557. /**
  3558. * regress_test_nested_parameter:
  3559. * @a: An integer
  3560. *
  3561. * <informaltable>
  3562. * <tgroup cols="3">
  3563. * <thead>
  3564. * <row>
  3565. * <entry>Syntax</entry>
  3566. * <entry>Explanation</entry>
  3567. * <entry>Examples</entry>
  3568. * </row>
  3569. * </thead>
  3570. * <tbody>
  3571. * <row>
  3572. * <entry>rgb(@r, @g, @b)</entry>
  3573. * <entry>An opaque color; @r, @g, @b can be either integers between
  3574. * 0 and 255 or percentages</entry>
  3575. * <entry><literallayout>rgb(128, 10, 54)
  3576. * rgb(20%, 30%, 0%)</literallayout></entry>
  3577. * </row>
  3578. * <row>
  3579. * <entry>rgba(@r, @g, @b, @a)</entry>
  3580. * <entry>A translucent color; @r, @g, @b are as in the previous row,
  3581. * @a is a floating point number between 0 and 1</entry>
  3582. * <entry><literallayout>rgba(255, 255, 0, 0.5)</literallayout></entry>
  3583. * </row>
  3584. * </tbody>
  3585. * </tgroup>
  3586. * </informaltable>
  3587. *
  3588. * What we're testing here is that the scanner ignores the @a nested inside XML.
  3589. */
  3590. void
  3591. regress_test_nested_parameter (int a)
  3592. {
  3593. }
  3594. /**
  3595. * regress_introspectable_via_alias:
  3596. *
  3597. */
  3598. void
  3599. regress_introspectable_via_alias (RegressPtrArrayAlias *data)
  3600. {
  3601. }
  3602. /**
  3603. * regress_not_introspectable_via_alias:
  3604. *
  3605. */
  3606. void
  3607. regress_not_introspectable_via_alias (RegressVaListAlias ok)
  3608. {
  3609. }
  3610. /**
  3611. * regress_aliased_caller_alloc:
  3612. * @boxed: (out):
  3613. */
  3614. void regress_aliased_caller_alloc (RegressAliasedTestBoxed *boxed)
  3615. {
  3616. boxed->priv = g_slice_new0 (RegressTestBoxedPrivate);
  3617. boxed->priv->magic = 0xdeadbeef;
  3618. }
  3619. void
  3620. regress_test_struct_fixed_array_frob (RegressTestStructFixedArray *str)
  3621. {
  3622. guint i;
  3623. str->just_int = 7;
  3624. for (i = 0; i < G_N_ELEMENTS(str->array); i++)
  3625. str->array[i] = 42 + i;
  3626. }
  3627. /**
  3628. * regress_has_parameter_named_attrs:
  3629. * @foo: some int
  3630. * @attributes: (type guint32) (array fixed-size=32): list of attributes
  3631. *
  3632. * This test case mirrors GnomeKeyringPasswordSchema from
  3633. * libgnome-keyring.
  3634. */
  3635. void
  3636. regress_has_parameter_named_attrs (int foo,
  3637. gpointer attributes)
  3638. {
  3639. }
  3640. /**
  3641. * regress_test_versioning:
  3642. *
  3643. * Since: 1.32.1: Actually, this function was introduced earlier
  3644. * than this, but it didn't do anything before this version.
  3645. * Deprecated: 1.33.3: This function has been deprecated,
  3646. * because it sucks. Use foobar instead.
  3647. * Stability: Unstable: Maybe someday we will find the time
  3648. * to stabilize this function. Who knows?
  3649. */
  3650. void
  3651. regress_test_versioning (void)
  3652. {
  3653. }
  3654. void
  3655. regress_like_xkl_config_item_set_name (RegressLikeXklConfigItem *self,
  3656. const char *name)
  3657. {
  3658. strncpy (self->name, name, sizeof (self->name) - 1);
  3659. self->name[sizeof(self->name)-1] = '\0';
  3660. }
  3661. /**
  3662. * regress_get_variant:
  3663. *
  3664. * Returns: (transfer floating): A new variant
  3665. */
  3666. GVariant *
  3667. regress_get_variant (void)
  3668. {
  3669. return g_variant_new_int32 (42);
  3670. }