cmocka.h 239 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092
  1. /*
  2. * Copyright 2008 Google Inc.
  3. * Copyright 2014-2022 Andreas Schneider <asn@cryptomilk.org>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #ifndef CMOCKA_H_
  18. #define CMOCKA_H_
  19. #ifdef _WIN32
  20. # ifdef _MSC_VER
  21. # ifndef CMOCKA_STATIC
  22. # ifdef CMOCKA_EXPORTS
  23. #define CMOCKA_DLLEXTERN __declspec(dllexport)
  24. # else
  25. #define CMOCKA_DLLEXTERN __declspec(dllimport)
  26. # endif /* CMOCKA_EXPORTS */
  27. # endif /* ndef CMOCKA_STATIC */
  28. #ifndef __func__
  29. #define __func__ __FUNCTION__
  30. #endif /* __func__ */
  31. #ifndef inline
  32. #define inline __inline
  33. #endif /* inline */
  34. # endif /* _MSC_VER */
  35. #endif /* _WIN32 */
  36. /**
  37. * @def CMOCKA_DLLEXTERN
  38. * This attribute is needed when dynamically linking to a data object in a DLL.
  39. * It's optional (but increases performance) for dynamically linking to
  40. * functions in a DLL.
  41. * @see
  42. * https://github.com/MicrosoftDocs/cpp-docs/blob/bd5a4fbd8ea3dd47b5c7a228c266cdddcaca0e00/docs/cpp/dllexport-dllimport.md
  43. */
  44. #ifndef CMOCKA_DLLEXTERN
  45. #define CMOCKA_DLLEXTERN // only needed on MSVC compiler when using a DLL
  46. #endif /* ndef CMOCKA_DLLEXTERN */
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * @defgroup cmocka 📚 The CMocka API
  52. * @brief Unit testing framework for C with support for mock objects.
  53. *
  54. * cmocka is an elegant unit testing framework for C with support for mock
  55. * objects. It only requires the standard C library, works on a lot of platforms
  56. * (including embedded) and with different compilers.
  57. *
  58. * @section cmocka-includes Standard includes
  59. *
  60. * CMocka requires the include of the following list of standard headers or
  61. * their equivalent.
  62. *
  63. * @code
  64. * #include <stdarg.h>
  65. * #include <stdbool.h>
  66. * #include <stddef.h>
  67. * #include <stdint.h>
  68. * #include <setjmp.h>
  69. * @endcode
  70. *
  71. * The header file 'cmocka.h' includes those headers already and in case your
  72. * platform does not provide those header files, you must
  73. * `#define CMOCKA_NO_STANDARD_INCLUDES` in order to prevent the include of
  74. * those files.
  75. *
  76. * An example of how your code which uses CMocka could look like is given below.
  77. *
  78. * @code
  79. * #include "path/to/cmocka_platform.h"
  80. * #define CMOCKA_NO_STANDARD_INCLUDES
  81. * #include <cmocka.h>
  82. * // ... your test code goes here ...
  83. * @endcode
  84. */
  85. #ifndef CMOCKA_NO_STANDARD_INCLUDES
  86. #include <stdarg.h>
  87. #include <stdbool.h>
  88. #include <stddef.h>
  89. #include <stdint.h>
  90. #include <setjmp.h>
  91. #endif
  92. /**
  93. * @defgroup cmocka_util 🔨 Utility Macros and Types
  94. * @ingroup cmocka
  95. * @brief Type conversions, casting helpers, and common data structures.
  96. *
  97. * Internal utilities and data types used throughout the CMocka API.
  98. *
  99. * @{
  100. */
  101. /* Perform an signed cast to intmax_t. */
  102. #define cast_to_intmax_type(value) \
  103. ((intmax_t)(value))
  104. /* Perform an unsigned cast to uintmax_t. */
  105. #define cast_to_uintmax_type(value) \
  106. ((uintmax_t)(value))
  107. /* Perform a safe cast from pointer to uintmax_t. */
  108. #define cast_ptr_to_uintmax_type(value) \
  109. ((uintmax_t)(uintptr_t)(value))
  110. /* Perform cast to double. */
  111. #define cast_to_double_type(value) \
  112. ((double)(value))
  113. /* Perform cast to float. */
  114. #define cast_to_float_type(value) \
  115. ((float)(value))
  116. /**
  117. * Perform cast to void pointer.
  118. *
  119. * ISO C forbids conversion between function pointers and void*. This macro
  120. * provides a portable way to perform such conversions by casting through
  121. * uintptr_t, which is allowed by POSIX and works on all practical platforms.
  122. */
  123. #define cast_to_void_pointer(ptr) \
  124. ((void *)(uintptr_t)(ptr))
  125. /**
  126. * Perform a cast from an integer to CMockaValueData.
  127. *
  128. * For backwards compatibility reasons, this explicitly casts to `uintmax_t`.
  129. * For most compilers, this will suppress warnings about passing float/intmax_t
  130. * to this macro.
  131. */
  132. #define cast_int_to_cmocka_value(value) \
  133. (CMockaValueData) \
  134. { \
  135. .uint_val = (uintmax_t)(value) \
  136. }
  137. /** Perform a cast from a pointer to CMockaValueData. */
  138. #define cast_ptr_to_cmocka_value(value) \
  139. (CMockaValueData) \
  140. { \
  141. .const_ptr = (value) \
  142. }
  143. /** Assign an integer value to CMockaValueData. */
  144. #define assign_int_to_cmocka_value(value) \
  145. (CMockaValueData) \
  146. { \
  147. .int_val = (value) \
  148. }
  149. /** Assign an unsigned integer value to CMockaValueData. */
  150. #define assign_uint_to_cmocka_value(value) \
  151. (CMockaValueData) \
  152. { \
  153. .uint_val = (value) \
  154. }
  155. /** Assign a floating point value to CMockaValueData. */
  156. #define assign_float_to_cmocka_value(value) \
  157. (CMockaValueData) \
  158. { \
  159. .float_val = ((float)(value)) \
  160. }
  161. /** Assign a double floating point value to CMockaValueData. */
  162. #define assign_double_to_cmocka_value(value) \
  163. (CMockaValueData) \
  164. { \
  165. .real_val = ((double)(value)) \
  166. }
  167. /* Nested macros are not expanded when they appear along with # or ## */
  168. #define cmocka_tostring(val) #val
  169. /** @cond INTERNAL */
  170. /* GCC have printf type attribute check. */
  171. #ifdef __GNUC__
  172. #define CMOCKA_PRINTF_ATTRIBUTE(a,b) \
  173. __attribute__ ((__format__ (__printf__, a, b)))
  174. #else
  175. #define CMOCKA_PRINTF_ATTRIBUTE(a,b)
  176. #endif /* __GNUC__ */
  177. #if defined(CMOCKA_DISABLE_DEPRECATION_WARNINGS) || defined(CMOCKA_DISABLE_DEPRECTATION_WARNINGS)
  178. #define CMOCKA_DEPRECATED
  179. #define CMOCKA_DEPRECATION_WARNING(msg)
  180. #else /* CMOCKA_DISABLE_DEPRECATION_WARNINGS */
  181. /* Deprecation warnings for functions */
  182. #if defined(__GNUC__)
  183. #define CMOCKA_DEPRECATED __attribute__ ((deprecated))
  184. #else
  185. /* MSVC requires __declspec(deprecated) before the function declaration,
  186. * not after it. Since we already use CMOCKA_DEPRECATION_WARNING() in
  187. * the macro wrappers, we don't need function-level deprecation for MSVC. */
  188. #define CMOCKA_DEPRECATED
  189. #endif
  190. /* Deprecation warnings for macros */
  191. #if defined(__GNUC__) || defined(__clang__)
  192. /* Use a deprecated typedef in a statement expression to generate warnings
  193. * that work even when the header is included as a system header (-isystem).
  194. */
  195. #define CMOCKA_DEPRECATION_WARNING(msg) \
  196. __extension__({ \
  197. typedef int cmocka_macro __attribute__((deprecated(msg))); \
  198. cmocka_macro cmocka_deprecated_var __attribute__((unused)) = 0; \
  199. (void)sizeof(cmocka_deprecated_var); \
  200. });
  201. #elif defined(_MSC_VER)
  202. #define CMOCKA_DEPRECATION_WARNING(msg) __pragma(message("warning: " msg))
  203. #else
  204. #define CMOCKA_DEPRECATION_WARNING(msg)
  205. #endif
  206. #endif /* CMOCKA_DISABLE_DEPRETATION_WARNINGS */
  207. #if defined(__GNUC__)
  208. #define CMOCKA_NORETURN __attribute__ ((noreturn))
  209. #elif defined(_MSC_VER)
  210. #define CMOCKA_NORETURN __declspec(noreturn)
  211. #else
  212. #define CMOCKA_NORETURN
  213. #endif
  214. /* Function attribute that tells the compiler that we never access the value
  215. * of a/b, just the pointer address.
  216. *
  217. * Without this, newer compilers like GCC-12 will print
  218. * `-Wmaybe-uninitialized` warnings.
  219. *
  220. * See:
  221. * https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes
  222. */
  223. #ifdef __has_attribute
  224. #if __has_attribute(access)
  225. #define CMOCKA_NO_ACCESS_ATTRIBUTE \
  226. __attribute__((access(none, 1), access(none, 2)))
  227. #endif
  228. #endif
  229. #ifndef CMOCKA_NO_ACCESS_ATTRIBUTE
  230. #define CMOCKA_NO_ACCESS_ATTRIBUTE
  231. #endif
  232. /** @endcond */
  233. /** @} */ /* cmocka_util */
  234. /**
  235. * @defgroup cmocka_mock 🎪 Mock Objects
  236. * @ingroup cmocka
  237. * @brief Simulate objects and control function return values in tests.
  238. *
  239. * Mock objects are simulated objects that mimic the behavior of
  240. * real objects. Instead of calling the real objects, the tested object calls a
  241. * mock object that merely asserts that the correct methods were called, with
  242. * the expected parameters, in the correct order.
  243. *
  244. * <ul>
  245. * <li><strong>will_return(function, value)</strong> - The will_return() macro
  246. * pushes a value onto a queue of mock values. This macro is intended to be
  247. * used by the unit test itself, while programming the behaviour of the mocked
  248. * object.</li>
  249. *
  250. * <li><strong>mock()</strong> - the mock macro pops a value from a queue of
  251. * test values. The user of the mock() macro is the mocked object that uses it
  252. * to learn how it should behave.</li>
  253. * </ul>
  254. *
  255. * Because the will_return() and mock() are intended to be used in pairs, the
  256. * cmocka library would fail the test if there are more values pushed onto the
  257. * queue using will_return() than consumed with mock() and vice-versa.
  258. *
  259. * The following unit test stub illustrates how would a unit test instruct the
  260. * mock object to return a particular value:
  261. *
  262. * @code
  263. * will_return_ptr_type(chef_cook, "hotdog", const char *);
  264. * will_return_int(chef_cook, 0);
  265. * @endcode
  266. *
  267. * Now the mock object can check if the parameter it received is the parameter
  268. * which is expected by the test driver. This can be done the following way:
  269. *
  270. * @code
  271. * int chef_cook(const char *order, char **dish_out)
  272. * {
  273. * *dish_out = mock_ptr_type(char *); // "hotdog"
  274. * int return_code = mock_int(); // 0
  275. * return return_code;
  276. * }
  277. * @endcode
  278. *
  279. * For a complete example please take a look
  280. * <a
  281. * href="https://git.cryptomilk.org/projects/cmocka.git/tree/example/mock">here</a>.
  282. *
  283. * @{
  284. */
  285. /**
  286. * @brief Return a value indefinitely when used with will_return_count().
  287. *
  288. * This constant can be passed as the count parameter to will_return_count()
  289. * and related functions to indicate that the specified value should be
  290. * returned every time the mocked function is called, without limit.
  291. *
  292. * @see will_return_count()
  293. * @see will_return_int_count()
  294. * @see will_return_uint_count()
  295. * @see will_return_ptr_count()
  296. */
  297. #define WILL_RETURN_ALWAYS -1
  298. /**
  299. * @brief Return a value once when used with will_return_count().
  300. *
  301. * This constant can be passed as the count parameter to will_return_count()
  302. * and related functions to indicate that the specified value should be
  303. * returned only the next time the mocked function is called. This is the
  304. * default behavior of will_return() and related macros.
  305. *
  306. * @see will_return_count()
  307. * @see will_return()
  308. */
  309. #define WILL_RETURN_ONCE -2
  310. /**
  311. * @brief Check a parameter every time when used with expect_check_data_count().
  312. *
  313. * This constant can be passed as the count parameter to expect_check_data_count()
  314. * to indicate that the parameter check should be performed every time the mocked
  315. * function is called. The test will fail if the function is never called.
  316. *
  317. * @see expect_check_data_count()
  318. */
  319. #define EXPECT_ALWAYS -1
  320. /**
  321. * @brief Optionally check a parameter when used with expect_check_data_count().
  322. *
  323. * This constant can be passed as the count parameter to expect_check_data_count()
  324. * to indicate that the parameter check is optional. The check will be performed
  325. * if the function is called, but the test will not fail if it's never called.
  326. *
  327. * @see expect_check_data_count()
  328. */
  329. #define EXPECT_MAYBE -2
  330. #ifdef DOXYGEN
  331. /**
  332. * @brief Retrieve a return value of the current function.
  333. *
  334. * @return The value which was stored to return by this function.
  335. *
  336. * @see will_return()
  337. */
  338. uintmax_t mock(void);
  339. #else
  340. #define mock() (_mock(__func__, __FILE__, __LINE__, NULL)).uint_val
  341. #endif
  342. #ifdef DOXYGEN
  343. /**
  344. * @brief Retrieve a value of the current function and cast it to given type.
  345. *
  346. * The value would be casted to type internally to avoid having the
  347. * caller to do the cast manually. Type safety checks are disabled with that
  348. * function.
  349. *
  350. * @param[in] #type The expected type of the return value
  351. *
  352. * @return The value which was stored to return by this function casted to the
  353. * specified type.
  354. *
  355. * @code
  356. * int param;
  357. *
  358. * param = mock_type(int);
  359. * @endcode
  360. *
  361. * @see will_return()
  362. */
  363. type mock_type(#type);
  364. #else
  365. #define mock_type(type) ((type) mock())
  366. #endif
  367. #ifdef DOXYGEN
  368. /**
  369. * @brief Check if data is available for the current mock function.
  370. *
  371. * This function checks if there is data available for the current mock function
  372. * which calls has_mock() without consuming it. This is useful when you want to
  373. * check if mock data has been set up before calling mock().
  374. *
  375. * @return true if mock data is available, false otherwise.
  376. *
  377. * @code
  378. * int example_mock_function(void)
  379. * {
  380. * if (has_mock()) {
  381. * return mock_int();
  382. * }
  383. * return default_value;
  384. * }
  385. * @endcode
  386. *
  387. * @see mock()
  388. * @see mock_int()
  389. * @see mock_uint()
  390. * @see mock_float()
  391. * @see will_return()
  392. */
  393. bool has_mock(void);
  394. #else
  395. #define has_mock() _has_mock(__func__)
  396. #endif
  397. #ifdef DOXYGEN
  398. /**
  399. * @brief Retrieve an integer return value of the current function.
  400. *
  401. * @return The value which was stored to return by this function.
  402. *
  403. * @code
  404. * intmax_t param;
  405. *
  406. * param = mock_int();
  407. * @endcode
  408. *
  409. * @see will_return_int()
  410. */
  411. intmax_t mock_int();
  412. #else
  413. /* TODO: Enable type safety check by passing intmax_t instead of NULL */
  414. #define mock_int() (_mock(__func__, __FILE__, __LINE__, NULL)).int_val
  415. #endif
  416. #ifdef DOXYGEN
  417. /**
  418. * @brief Retrieve an unsigned integer return value of the current function.
  419. *
  420. * @return The value which was stored to return by this function.
  421. *
  422. * @code
  423. * uintmax_t param;
  424. *
  425. * param = mock_uint();
  426. * @endcode
  427. *
  428. * @see will_return_uint()
  429. */
  430. uintmax_t mock_uint(void);
  431. #else
  432. #define mock_uint() (_mock(__func__, __FILE__, __LINE__, "uintmax_t")).uint_val
  433. #endif
  434. #ifdef DOXYGEN
  435. /**
  436. * @brief Retrieve a float return value of the current function.
  437. *
  438. * @return The float value which was stored to return by this function.
  439. *
  440. * @see will_return_float()
  441. */
  442. float mock_float(void);
  443. #else
  444. #define mock_float() (_mock(__func__, __FILE__, __LINE__, NULL)).float_val
  445. #endif
  446. #ifdef DOXYGEN
  447. /**
  448. * @brief Retrieve a double precision floating point return value of the
  449. * current function.
  450. *
  451. * @return The double value which was stored to return by this function.
  452. *
  453. * @see will_return_double()
  454. */
  455. double mock_double(void);
  456. #else
  457. #define mock_double() (_mock(__func__, __FILE__, __LINE__, NULL)).real_val
  458. #endif
  459. #ifdef DOXYGEN
  460. /**
  461. * @brief Retrieve a typed return value of the current function.
  462. *
  463. * The value would be casted to type internally to avoid having the
  464. * caller to do the cast manually. This macro does NOT perform type checking.
  465. * For type-safe pointer retrieval, use mock_ptr_type_checked() instead.
  466. *
  467. * @param[in] #type The expected type of the return value
  468. *
  469. * @return The value which was stored to return by this function.
  470. *
  471. * @code
  472. * char *param;
  473. *
  474. * param = mock_ptr_type(char *);
  475. * @endcode
  476. *
  477. * @see will_return_ptr()
  478. * @see mock_ptr_type_checked()
  479. */
  480. type mock_ptr_type(#type);
  481. #else
  482. #define mock_ptr_type(type) \
  483. ((type)(_mock(__func__, __FILE__, __LINE__, NULL)).ptr)
  484. #endif
  485. #ifdef DOXYGEN
  486. /**
  487. * @brief Retrieve a typed return value of the current function with type checking.
  488. *
  489. * The value would be casted to type internally to avoid having the
  490. * caller to do the cast manually. This macro DOES perform type checking
  491. * and will fail the test if the type used with will_return_ptr_type()
  492. * does not match the type passed to this macro.
  493. *
  494. * @param[in] #type The expected type of the return value
  495. *
  496. * @return The value which was stored to return by this function.
  497. *
  498. * @code
  499. * char *param;
  500. *
  501. * param = mock_ptr_type_checked(char *);
  502. * @endcode
  503. *
  504. * @see will_return_ptr_type()
  505. * @see mock_ptr_type()
  506. */
  507. type mock_ptr_type_checked(#type);
  508. #else
  509. #define mock_ptr_type_checked(type) \
  510. ((type)(_mock(__func__, __FILE__, __LINE__, #type)).ptr)
  511. #endif
  512. #ifdef DOXYGEN
  513. /**
  514. * @brief Retrieve a named value for the current function.
  515. *
  516. * @param[in] #name The name under which to look for the value
  517. *
  518. * @return The value which was stored under the given name for this function.
  519. *
  520. * @code
  521. * int param;
  522. * param = (int)mock_parameter(number);
  523. * @endcode
  524. *
  525. * @see mock()
  526. * @see mock_parameter_type()
  527. * @see mock_parameter_int()
  528. * @see mock_parameter_uint()
  529. * @see mock_parameter_float()
  530. * @see mock_parameter_ptr()
  531. * @see mock_parameter_ptr_type()
  532. * @see will_return()
  533. * @see will_set_parameter()
  534. * @see will_set_parameter_int()
  535. * @see will_set_parameter_uint()
  536. * @see will_set_parameter_float()
  537. * @see will_set_parameter_count()
  538. * @see will_set_parameter_always()
  539. * @see will_set_parameter_maybe()
  540. * @see will_set_parameter_ptr()
  541. * @see will_set_parameter_ptr_type()
  542. * @see will_set_parameter_ptr_count()
  543. * @see will_set_parameter_ptr_always()
  544. * @see will_set_parameter_ptr_maybe()
  545. */
  546. uintmax_t mock_parameter(#name);
  547. #else
  548. #define mock_parameter(name) \
  549. (_mock_parameter(__func__, #name, __FILE__, __LINE__, NULL)).uint_val
  550. #endif
  551. #ifdef DOXYGEN
  552. /**
  553. * @brief Retrieve a named value for the current function and cast it to given type.
  554. *
  555. * The value would be casted to type internally to avoid having the
  556. * caller to do the cast manually. Type safety checks are disabled with that
  557. * function.
  558. *
  559. * @param[in] #name The name under which to look for the value
  560. *
  561. * @param[in] #type The expected type of the named value
  562. *
  563. * @return The value which was stored under name for this function.
  564. *
  565. * @code
  566. * int param;
  567. *
  568. * param = mock_parameter_type(param, int);
  569. * @endcode
  570. *
  571. * @see mock_parameter()
  572. * @see will_set_parameter()
  573. */
  574. #type mock_parameter_type(#name, #type);
  575. #else
  576. #define mock_parameter_type(name, type) ((type) mock_parameter(#name))
  577. #endif
  578. #ifdef DOXYGEN
  579. /**
  580. * @brief Retrieve a named integer value for the current function.
  581. *
  582. * @param[in] #name The name under which to look for the value
  583. *
  584. * @return The integer value which was stored under the given name for this function.
  585. *
  586. * @code
  587. * intmax_t param;
  588. *
  589. * param = mock_parameter_int(param);
  590. * @endcode
  591. *
  592. * @see mock_parameter()
  593. * @see will_set_parameter()
  594. * @see will_set_parameter_int()
  595. */
  596. intmax_t mock_parameter_int(#name);
  597. #else
  598. #define mock_parameter_int(name) \
  599. (_mock_parameter(__func__, #name, __FILE__, __LINE__, "intmax_t")).int_val
  600. #endif
  601. #ifdef DOXYGEN
  602. /**
  603. * @brief Retrieve an unsigned integer return value of the current function.
  604. *
  605. * @param[in] #name The name under which to look for the value
  606. *
  607. * @return The value which was stored to return by this function.
  608. *
  609. * @code
  610. * uintmax_t param;
  611. *
  612. * param = mock_parameter_uint(param);
  613. * @endcode
  614. *
  615. * @see mock_parameter()
  616. * @see will_set_parameter()
  617. * @see will_set_parameter_uint()
  618. */
  619. uintmax_t mock_parameter_uint(#name);
  620. #else
  621. #define mock_parameter_uint(name) \
  622. (_mock_parameter(__func__, #name, __FILE__, __LINE__, "uintmax_t")).uint_val
  623. #endif
  624. #ifdef DOXYGEN
  625. /**
  626. * @brief Retrieve a named float value for the current function.
  627. *
  628. * @param[in] #name The name under which to look for the value
  629. *
  630. * @return The float value which was stored to return by this function.
  631. *
  632. * @code
  633. * float param;
  634. *
  635. * param = mock_parameter_float(param);
  636. * @endcode
  637. *
  638. * @see mock_parameter()
  639. * @see will_set_parameter()
  640. * @see will_set_parameter_float()
  641. */
  642. float mock_parameter_float(#name);
  643. #else
  644. #define mock_parameter_float(name) \
  645. (_mock_parameter(__func__, #name, __FILE__, __LINE__, "float")).float_val
  646. #endif
  647. #ifdef DOXYGEN
  648. /**
  649. * @brief Retrieve a named double precision floating point value for the
  650. * current function.
  651. *
  652. * @param[in] #name The name under which to look for the value
  653. *
  654. * @return The double value which was stored to return by this function.
  655. *
  656. * @code
  657. * double param;
  658. *
  659. * param = mock_parameter_double(param);
  660. * @endcode
  661. *
  662. * @see mock_parameter()
  663. * @see will_set_parameter_double()
  664. */
  665. double mock_parameter_double(#name);
  666. #else
  667. #define mock_parameter_double(name) \
  668. (_mock_parameter(__func__, #name, __FILE__, __LINE__, "double")).real_val
  669. #endif
  670. #ifdef DOXYGEN
  671. /**
  672. * @brief Retrieve a named pointer for the current function.
  673. *
  674. * @param[in] #name The name under which to look for the pointer
  675. *
  676. * @return The pointer which was stored to return by this function.
  677. *
  678. * @code
  679. * int *result
  680. * result = (int*)mock_parameter_ptr(result);
  681. * @endcode
  682. *
  683. * @see mock_parameter()
  684. * @see will_set_parameter()
  685. * @see will_set_parameter_ptr()
  686. */
  687. void *mock_parameter_ptr(#name);
  688. #else
  689. #define mock_parameter_ptr(name) \
  690. ((_mock_parameter(__func__, #name, __FILE__, __LINE__, NULL)).ptr)
  691. #endif
  692. #ifdef DOXYGEN
  693. /**
  694. * @brief Retrieve a named pointer for the current function.
  695. *
  696. * In addition it checks if if the type specified by the call to
  697. * will_return_ptr_type() is the same.
  698. * And casts it to that type.
  699. *
  700. * @param[in] #name The name under which to look for the pointer
  701. *
  702. * @return The pointer which was stored to return by this function.
  703. *
  704. * @code
  705. * int *result
  706. * result = mock_parameter_ptr_type(result, int*);
  707. * @endcode
  708. *
  709. * @see mock_parameter()
  710. * @see will_set_parameter()
  711. * @see will_set_parameter_ptr_type()
  712. */
  713. type mock_parameter_ptr_type(#name, #type);
  714. #else
  715. #define mock_parameter_ptr_type(name, type) \
  716. ((type)(_mock_parameter(__func__, #name, __FILE__, __LINE__, #type)).ptr)
  717. #endif
  718. #ifdef DOXYGEN
  719. /**
  720. * @brief set errno for the current function.
  721. *
  722. * @code
  723. * mock_errno();
  724. * @endcode
  725. */
  726. void mock_errno(void);
  727. #else
  728. #define mock_errno() \
  729. do { \
  730. intmax_t err = (_mock_parameter( \
  731. __func__, \
  732. "/errno", \
  733. __FILE__, \
  734. __LINE__, \
  735. "errno")).int_val; \
  736. if (err != 0) { \
  737. errno = err; \
  738. } \
  739. } while (0)
  740. #endif
  741. #ifdef DOXYGEN
  742. /**
  743. * @brief Store a value to be returned by mock() later.
  744. *
  745. * @param[in] #function The function which should return the given value.
  746. *
  747. * @param[in] value The value to be returned by mock().
  748. *
  749. * @code
  750. * int return_integer(void)
  751. * {
  752. * return (int)mock();
  753. * }
  754. *
  755. * static void test_integer_return(void **state)
  756. * {
  757. * will_return(return_integer, 42);
  758. *
  759. * assert_int_equal(my_function_calling_return_integer(), 42);
  760. * }
  761. * @endcode
  762. *
  763. * @see mock()
  764. * @see mock_int()
  765. * @see mock_uint()
  766. * @see mock_float()
  767. * @see will_return_int()
  768. * @see will_return_uint()
  769. * @see will_return_float()
  770. * @see will_return_ptr_type()
  771. * @see will_return_count()
  772. * @see will_return_always()
  773. * @see will_return_ptr_always()
  774. */
  775. void will_return(#function, uintmax_t value);
  776. #else
  777. #define will_return(function, value) \
  778. _will_return(cmocka_tostring(function), \
  779. __FILE__, \
  780. __LINE__, \
  781. NULL, \
  782. cast_int_to_cmocka_value(value), \
  783. 1)
  784. #endif
  785. #ifdef DOXYGEN
  786. /**
  787. * @brief Store an integer value to be returned by mock() later.
  788. *
  789. * @param[in] #function The function which should return the given value.
  790. *
  791. * @param[in] value The value to be returned by mock().
  792. *
  793. * @code
  794. * int32_t return_int32(void)
  795. * {
  796. * return (int32_t)mock_int();
  797. * }
  798. *
  799. * static void test_integer_return(void **state)
  800. * {
  801. * will_return_int(return_int32, -42);
  802. *
  803. * assert_int_equal(my_function_calling_return_int32(), -42);
  804. * }
  805. * @endcode
  806. *
  807. * @see mock_int()
  808. */
  809. void will_return_int(#function, intmax_t value);
  810. #else
  811. #define will_return_int(function, value) \
  812. _will_return(#function, \
  813. __FILE__, \
  814. __LINE__, \
  815. "intmax_t", \
  816. assign_int_to_cmocka_value(value), \
  817. 1)
  818. #endif
  819. #ifdef DOXYGEN
  820. /**
  821. * @brief Store an integer value to be returned a specified number of times by
  822. * mock() later.
  823. *
  824. * @param[in] #function The function which should return the given value.
  825. *
  826. * @param[in] value The value to be returned by mock().
  827. *
  828. * @param[in] count The parameter indicates the number of times the value
  829. * should be returned by mock_int(). If count is set to -1, the value will
  830. * always be returned but must be returned at least once. If count is set to -2,
  831. * the value will always be returned by mock_int(), but is not required to be
  832. * returned.
  833. *
  834. * @code
  835. * int32_t return_int32(void)
  836. * {
  837. * return (int32_t)mock_int();
  838. * }
  839. *
  840. * static void test_integer_return(void **state)
  841. * {
  842. * will_return_int_count(return_int32, -42, 3);
  843. *
  844. * assert_int_equal(my_function_calling_return_int32(), -42);
  845. * assert_int_equal(my_function_calling_return_int32(), -42);
  846. * assert_int_equal(my_function_calling_return_int32(), -42);
  847. * }
  848. * @endcode
  849. *
  850. * @see mock_int()
  851. * @see will_return_int()
  852. */
  853. void will_return_int_count(#function, intmax_t value, int count);
  854. #else
  855. #define will_return_int_count(function, value, count) \
  856. _will_return(#function, \
  857. __FILE__, \
  858. __LINE__, \
  859. "intmax_t", \
  860. assign_int_to_cmocka_value(value), \
  861. count)
  862. #endif
  863. #ifdef DOXYGEN
  864. /**
  865. * @brief Store a unsigned integer value to be returned by mock() later.
  866. *
  867. * @param[in] #function The function which should return the given value.
  868. *
  869. * @param[in] value The value to be returned by mock().
  870. *
  871. * @code
  872. * uint32_t return_uint32(void)
  873. * {
  874. * return (uint32_t)mock_uint();
  875. * }
  876. *
  877. * static void test_integer_return(void **state)
  878. * {
  879. * will_return_uint(return_uint32, 42);
  880. *
  881. * assert_uint_equal(my_function_calling_return_uint32(), 42);
  882. * }
  883. * @endcode
  884. *
  885. * @see mock_uint()
  886. * @see will_return_count()
  887. */
  888. void will_return_uint(#function, uintmax_t value);
  889. #else
  890. #define will_return_uint(function, value) \
  891. _will_return(#function, \
  892. __FILE__, \
  893. __LINE__, \
  894. "uintmax_t", \
  895. assign_uint_to_cmocka_value(value), \
  896. 1)
  897. #endif
  898. #ifdef DOXYGEN
  899. /**
  900. * @brief Store an unsigned integer value to be returned a specified number of
  901. * times by mock() later.
  902. *
  903. * @param[in] #function The function which should return the given value.
  904. *
  905. * @param[in] value The value to be returned by mock().
  906. *
  907. * @param[in] count The parameter indicates the number of times the value
  908. * should be returned by mock_uint(). If count is set to -1, the value will
  909. * always be returned but must be returned at least once. If count is set to -2,
  910. * the value will always be returned by mock_uint(), but is not required to be
  911. * returned.
  912. *
  913. * @code
  914. * uint32_t return_uint32(void)
  915. * {
  916. * return (uint32_t)mock_uint();
  917. * }
  918. *
  919. * static void test_integer_return(void **state)
  920. * {
  921. * will_return_uint_count(return_uint32, 42, 3);
  922. *
  923. * assert_uint_equal(my_function_calling_return_uint32(), 42);
  924. * assert_uint_equal(my_function_calling_return_uint32(), 42);
  925. * assert_uint_equal(my_function_calling_return_uint32(), 42);
  926. * }
  927. * @endcode
  928. *
  929. * @see mock_uint()
  930. * @see will_return_uint()
  931. */
  932. void will_return_uint_count(#function, uintmax_t value, int count);
  933. #else
  934. #define will_return_uint_count(function, value, count) \
  935. _will_return(#function, \
  936. __FILE__, \
  937. __LINE__, \
  938. "uintmax_t", \
  939. assign_uint_to_cmocka_value(value), \
  940. count)
  941. #endif
  942. #ifdef DOXYGEN
  943. /**
  944. * @brief Store a float value to be returned by mock() later.
  945. *
  946. * @param[in] #function The function which should return the given value.
  947. *
  948. * @param[in] value The float value to be returned by mock().
  949. *
  950. * @code
  951. * float return_float(void)
  952. * {
  953. * return mock_float();
  954. * }
  955. *
  956. * static void test_float_return(void **state)
  957. * {
  958. * will_return_float(return_float, 1.0f);
  959. *
  960. * assert_float_equal(my_function_calling_return_float(), 1.0f, 0.01f);
  961. * }
  962. * @endcode
  963. *
  964. * @see mock_float()
  965. * @see mock_double()
  966. */
  967. void will_return_float(#function, float value);
  968. #else
  969. #define will_return_float(function, value) \
  970. _will_return(#function, \
  971. __FILE__, \
  972. __LINE__, \
  973. "float", \
  974. assign_float_to_cmocka_value(value), \
  975. 1)
  976. #endif
  977. #ifdef DOXYGEN
  978. /**
  979. * @brief Store a float value to be returned a specified number of times by
  980. * mock() later.
  981. *
  982. * @param[in] #function The function which should return the given value.
  983. *
  984. * @param[in] value The float value to be returned by mock().
  985. *
  986. * @param[in] count The parameter indicates the number of times the value
  987. * should be returned by mock_float(). If count is set to -1, the value will
  988. * always be returned but must be returned at least once. If count is set to -2,
  989. * the value will always be returned by mock_float(), but is not required to be
  990. * returned.
  991. *
  992. * @code
  993. * float return_float(void)
  994. * {
  995. * return mock_float();
  996. * }
  997. *
  998. * static void test_float_return(void **state)
  999. * {
  1000. * will_return_float_count(return_float, 1.0f, 3);
  1001. *
  1002. * assert_float_equal(my_function_calling_return_float(), 1.0f, 0.01f);
  1003. * assert_float_equal(my_function_calling_return_float(), 1.0f, 0.01f);
  1004. * assert_float_equal(my_function_calling_return_float(), 1.0f, 0.01f);
  1005. * }
  1006. * @endcode
  1007. *
  1008. * @see mock_float()
  1009. * @see will_return_float()
  1010. */
  1011. void will_return_float_count(#function, float value, int count);
  1012. #else
  1013. #define will_return_float_count(function, value, count) \
  1014. _will_return(#function, \
  1015. __FILE__, \
  1016. __LINE__, \
  1017. "float", \
  1018. assign_float_to_cmocka_value(value), \
  1019. count)
  1020. #endif
  1021. #ifdef DOXYGEN
  1022. /**
  1023. * @brief Store a double precision floating point value to be returned by
  1024. * mock() later.
  1025. *
  1026. * @param[in] #function The function which should return the given value.
  1027. *
  1028. * @param[in] value The double value to be returned by mock().
  1029. *
  1030. * @code
  1031. * double return_double(void)
  1032. * {
  1033. * return mock_double();
  1034. * }
  1035. *
  1036. * static void test_double_return(void **state)
  1037. * {
  1038. * will_return_double(return_double, 2.5);
  1039. *
  1040. * assert_double_equal(my_function_calling_return_double(), 2.5, 0.01);
  1041. * }
  1042. * @endcode
  1043. *
  1044. * @see mock_double()
  1045. */
  1046. void will_return_double(#function, double value);
  1047. #else
  1048. #define will_return_double(function, value) \
  1049. _will_return(#function, \
  1050. __FILE__, \
  1051. __LINE__, \
  1052. "double", \
  1053. assign_double_to_cmocka_value(value), \
  1054. 1)
  1055. #endif
  1056. #ifdef DOXYGEN
  1057. /**
  1058. * @brief Store a double precision floating point value to be returned a
  1059. * specified number of times by mock() later.
  1060. *
  1061. * @param[in] #function The function which should return the given value.
  1062. *
  1063. * @param[in] value The double value to be returned by mock().
  1064. *
  1065. * @param[in] count The parameter indicates the number of times the value
  1066. * should be returned by mock_double(). If count is set to -1, the value will
  1067. * always be returned but must be returned at least once. If count is set to -2,
  1068. * the value will always be returned by mock_double(), but is not required to be
  1069. * returned.
  1070. *
  1071. * @code
  1072. * double return_double(void)
  1073. * {
  1074. * return mock_double();
  1075. * }
  1076. *
  1077. * static void test_double_return(void **state)
  1078. * {
  1079. * will_return_double_count(return_double, 2.5, 3);
  1080. *
  1081. * assert_double_equal(my_function_calling_return_double(), 2.5, 0.01);
  1082. * assert_double_equal(my_function_calling_return_double(), 2.5, 0.01);
  1083. * assert_double_equal(my_function_calling_return_double(), 2.5, 0.01);
  1084. * }
  1085. * @endcode
  1086. *
  1087. * @see mock_double()
  1088. * @see will_return_double()
  1089. */
  1090. void will_return_double_count(#function, double value, int count);
  1091. #else
  1092. #define will_return_double_count(function, value, count) \
  1093. _will_return(#function, \
  1094. __FILE__, \
  1095. __LINE__, \
  1096. "double", \
  1097. assign_double_to_cmocka_value(value), \
  1098. count)
  1099. #endif
  1100. #ifdef DOXYGEN
  1101. /**
  1102. * @brief Store an integer value that will always be returned by mock_int().
  1103. *
  1104. * @param[in] #function The function which should return the given value.
  1105. *
  1106. * @param[in] value The value to be returned by mock_int().
  1107. *
  1108. * This is equivalent to:
  1109. * @code
  1110. * will_return_int_count(function, value, -1);
  1111. * @endcode
  1112. *
  1113. * @see will_return_int_count()
  1114. * @see mock_int()
  1115. */
  1116. void will_return_int_always(#function, intmax_t value);
  1117. #else
  1118. #define will_return_int_always(function, value) \
  1119. will_return_int_count(function, (value), WILL_RETURN_ALWAYS)
  1120. #endif
  1121. #ifdef DOXYGEN
  1122. /**
  1123. * @brief Store an unsigned integer value that will always be returned by
  1124. * mock_uint().
  1125. *
  1126. * @param[in] #function The function which should return the given value.
  1127. *
  1128. * @param[in] value The value to be returned by mock_uint().
  1129. *
  1130. * This is equivalent to:
  1131. * @code
  1132. * will_return_uint_count(function, value, -1);
  1133. * @endcode
  1134. *
  1135. * @see will_return_uint_count()
  1136. * @see mock_uint()
  1137. */
  1138. void will_return_uint_always(#function, uintmax_t value);
  1139. #else
  1140. #define will_return_uint_always(function, value) \
  1141. will_return_uint_count(function, (value), WILL_RETURN_ALWAYS)
  1142. #endif
  1143. #ifdef DOXYGEN
  1144. /**
  1145. * @brief Store a float value that will always be returned by mock_float().
  1146. *
  1147. * @param[in] #function The function which should return the given value.
  1148. *
  1149. * @param[in] value The value to be returned by mock_float().
  1150. *
  1151. * This is equivalent to:
  1152. * @code
  1153. * will_return_float_count(function, value, -1);
  1154. * @endcode
  1155. *
  1156. * @see will_return_float_count()
  1157. * @see mock_float()
  1158. */
  1159. void will_return_float_always(#function, float value);
  1160. #else
  1161. #define will_return_float_always(function, value) \
  1162. will_return_float_count(function, (value), WILL_RETURN_ALWAYS)
  1163. #endif
  1164. #ifdef DOXYGEN
  1165. /**
  1166. * @brief Store a double value that will always be returned by mock_double().
  1167. *
  1168. * @param[in] #function The function which should return the given value.
  1169. *
  1170. * @param[in] value The value to be returned by mock_double().
  1171. *
  1172. * This is equivalent to:
  1173. * @code
  1174. * will_return_double_count(function, value, -1);
  1175. * @endcode
  1176. *
  1177. * @see will_return_double_count()
  1178. * @see mock_double()
  1179. */
  1180. void will_return_double_always(#function, double value);
  1181. #else
  1182. #define will_return_double_always(function, value) \
  1183. will_return_double_count(function, (value), WILL_RETURN_ALWAYS)
  1184. #endif
  1185. #ifdef DOXYGEN
  1186. /**
  1187. * @deprecated Use will_return_int_count() or will_return_uint_count()
  1188. */
  1189. void will_return_count(#function, uintmax_t value, int count);
  1190. #else
  1191. #define will_return_count(function, value, count) \
  1192. do { \
  1193. CMOCKA_DEPRECATION_WARNING( \
  1194. "will_return_count: use will_return_int_count or " \
  1195. "will_return_uint_count instead") \
  1196. _will_return(cmocka_tostring(function), \
  1197. __FILE__, \
  1198. __LINE__, \
  1199. NULL, \
  1200. cast_int_to_cmocka_value(value), \
  1201. count); \
  1202. } while (0)
  1203. #endif
  1204. #ifdef DOXYGEN
  1205. /**
  1206. * @deprecated Use will_return_int_always() or will_return_uint_always()
  1207. */
  1208. void will_return_always(#function, uintmax_t value);
  1209. #else
  1210. #define will_return_always(function, value) \
  1211. do { \
  1212. CMOCKA_DEPRECATION_WARNING( \
  1213. "will_return_always: use will_return_int_always or " \
  1214. "will_return_uint_always instead") \
  1215. will_return_count(function, (value), WILL_RETURN_ALWAYS); \
  1216. } while (0)
  1217. #endif
  1218. #ifdef DOXYGEN
  1219. /**
  1220. * @brief Store an integer value that may always be returned by mock_int().
  1221. *
  1222. * This stores a value which will always be returned by mock_int() but is not
  1223. * required to be returned by at least one call to mock_int(). Therefore,
  1224. * in contrast to will_return_int_always() which causes a test failure if it
  1225. * is not returned at least once, will_return_int_maybe() will never cause a
  1226. * test to fail if its value is not returned.
  1227. *
  1228. * @param[in] #function The function which should return the given value.
  1229. *
  1230. * @param[in] value The value to be returned by mock_int().
  1231. *
  1232. * This is equivalent to:
  1233. * @code
  1234. * will_return_int_count(function, value, -2);
  1235. * @endcode
  1236. *
  1237. * @see will_return_int_count()
  1238. * @see mock_int()
  1239. */
  1240. void will_return_int_maybe(#function, intmax_t value);
  1241. #else
  1242. #define will_return_int_maybe(function, value) \
  1243. will_return_int_count(function, (value), WILL_RETURN_ONCE)
  1244. #endif
  1245. #ifdef DOXYGEN
  1246. /**
  1247. * @brief Store an unsigned integer value that may always be returned by
  1248. * mock_uint().
  1249. *
  1250. * This stores a value which will always be returned by mock_uint() but is not
  1251. * required to be returned by at least one call to mock_uint(). Therefore,
  1252. * in contrast to will_return_uint_always() which causes a test failure if it
  1253. * is not returned at least once, will_return_uint_maybe() will never cause a
  1254. * test to fail if its value is not returned.
  1255. *
  1256. * @param[in] #function The function which should return the given value.
  1257. *
  1258. * @param[in] value The value to be returned by mock_uint().
  1259. *
  1260. * This is equivalent to:
  1261. * @code
  1262. * will_return_uint_count(function, value, -2);
  1263. * @endcode
  1264. *
  1265. * @see will_return_uint_count()
  1266. * @see mock_uint()
  1267. */
  1268. void will_return_uint_maybe(#function, uintmax_t value);
  1269. #else
  1270. #define will_return_uint_maybe(function, value) \
  1271. will_return_uint_count(function, (value), WILL_RETURN_ONCE)
  1272. #endif
  1273. #ifdef DOXYGEN
  1274. /**
  1275. * @brief Store a float value that may always be returned by mock_float().
  1276. *
  1277. * This stores a value which will always be returned by mock_float() but is not
  1278. * required to be returned by at least one call to mock_float(). Therefore,
  1279. * in contrast to will_return_float_always() which causes a test failure if it
  1280. * is not returned at least once, will_return_float_maybe() will never cause a
  1281. * test to fail if its value is not returned.
  1282. *
  1283. * @param[in] #function The function which should return the given value.
  1284. *
  1285. * @param[in] value The value to be returned by mock_float().
  1286. *
  1287. * This is equivalent to:
  1288. * @code
  1289. * will_return_float_count(function, value, -2);
  1290. * @endcode
  1291. *
  1292. * @see will_return_float_count()
  1293. * @see mock_float()
  1294. */
  1295. void will_return_float_maybe(#function, float value);
  1296. #else
  1297. #define will_return_float_maybe(function, value) \
  1298. will_return_float_count(function, (value), WILL_RETURN_ONCE)
  1299. #endif
  1300. #ifdef DOXYGEN
  1301. /**
  1302. * @brief Store a double value that may always be returned by mock_double().
  1303. *
  1304. * This stores a value which will always be returned by mock_double() but is not
  1305. * required to be returned by at least one call to mock_double(). Therefore,
  1306. * in contrast to will_return_double_always() which causes a test failure if it
  1307. * is not returned at least once, will_return_double_maybe() will never cause a
  1308. * test to fail if its value is not returned.
  1309. *
  1310. * @param[in] #function The function which should return the given value.
  1311. *
  1312. * @param[in] value The value to be returned by mock_double().
  1313. *
  1314. * This is equivalent to:
  1315. * @code
  1316. * will_return_double_count(function, value, -2);
  1317. * @endcode
  1318. *
  1319. * @see will_return_double_count()
  1320. * @see mock_double()
  1321. */
  1322. void will_return_double_maybe(#function, double value);
  1323. #else
  1324. #define will_return_double_maybe(function, value) \
  1325. will_return_double_count(function, (value), WILL_RETURN_ONCE)
  1326. #endif
  1327. #ifdef DOXYGEN
  1328. /**
  1329. * @deprecated Use will_return_int_maybe() or will_return_uint_maybe()
  1330. */
  1331. void will_return_maybe(#function, uintmax_t value);
  1332. #else
  1333. #define will_return_maybe(function, value) \
  1334. do { \
  1335. CMOCKA_DEPRECATION_WARNING( \
  1336. "will_return_maybe: use will_return_int_maybe or " \
  1337. "will_return_uint_maybe instead") \
  1338. will_return_count(function, (value), WILL_RETURN_ONCE); \
  1339. } while (0)
  1340. #endif
  1341. #ifdef DOXYGEN
  1342. /**
  1343. * @brief Store a pointer value to be returned by mock_ptr_type() later.
  1344. *
  1345. * @param[in] #function The function which should return the given value.
  1346. *
  1347. * @param[in] value The value to be returned by mock_ptr_type().
  1348. *
  1349. * @code
  1350. * const char * return_pointer(void)
  1351. * {
  1352. * return mock_ptr_type(const char *);
  1353. * }
  1354. *
  1355. * static void test_pointer_return(void **state)
  1356. * {
  1357. * will_return_ptr_type(return_pointer, "hello world", const char *);
  1358. *
  1359. * assert_string_equal(my_func_calling_return_pointer(), "hello world");
  1360. * }
  1361. * @endcode
  1362. *
  1363. * @see mock_ptr_type()
  1364. * @see will_return_ptr_count()
  1365. */
  1366. void will_return_ptr(#function, void *value);
  1367. #else
  1368. #define will_return_ptr(function, value) \
  1369. _will_return(#function, \
  1370. __FILE__, \
  1371. __LINE__, \
  1372. NULL, \
  1373. cast_ptr_to_cmocka_value(value), \
  1374. 1)
  1375. #endif
  1376. #ifdef DOXYGEN
  1377. /**
  1378. * @brief Store a pointer value to be returned by mock_ptr_type_checked() later.
  1379. *
  1380. * This will also check that the type matches and if not will fail(). The type
  1381. * checking only works when used in conjunction with mock_ptr_type_checked().
  1382. * If you use mock_ptr_type() to retrieve the value, no type checking will occur.
  1383. *
  1384. * @param[in] #function The function which should return the given value.
  1385. *
  1386. * @param[in] value The value to be returned by mock_ptr_type_checked().
  1387. *
  1388. * @param[in] #type The type of the pointer.
  1389. * @code
  1390. * const char *return_pointer(void)
  1391. * {
  1392. * return mock_ptr_type_checked(const char *);
  1393. * }
  1394. *
  1395. * static void test_pointer_return(void **state)
  1396. * {
  1397. * will_return_ptr_type(return_pointer, "hello world", const char *);
  1398. *
  1399. * assert_string_equal(my_func_calling_return_pointer(), "hello world");
  1400. * }
  1401. * @endcode
  1402. *
  1403. * @see mock_ptr_type_checked()
  1404. */
  1405. void will_return_ptr_type(#function, void *value, type);
  1406. #else
  1407. #define will_return_ptr_type(function, value, type) \
  1408. _will_return(#function, \
  1409. __FILE__, \
  1410. __LINE__, \
  1411. #type, \
  1412. cast_ptr_to_cmocka_value(value), \
  1413. 1)
  1414. #endif
  1415. #ifdef DOXYGEN
  1416. /**
  1417. * @brief Store a pointer value to be returned by mock_ptr_type() later.
  1418. *
  1419. * @param[in] #function The function which should return the given value.
  1420. *
  1421. * @param[in] value The value to be returned by mock_ptr_type().
  1422. *
  1423. * @param[in] count The parameter indicates the number of times the value should
  1424. * be returned by mock(). If count is set to -1, the value
  1425. * will always be returned but must be returned at least once.
  1426. * If count is set to -2, the value will always be returned
  1427. * by mock(), but is not required to be returned.
  1428. *
  1429. * @see mock_ptr_type()
  1430. */
  1431. void will_return_ptr_count(#function, void *value, int count);
  1432. #else
  1433. #define will_return_ptr_count(function, value, count) \
  1434. _will_return(#function, \
  1435. __FILE__, \
  1436. __LINE__, \
  1437. NULL, \
  1438. cast_ptr_to_cmocka_value(value), \
  1439. count)
  1440. #endif
  1441. #ifdef DOXYGEN
  1442. /**
  1443. * @brief Store a value that will be always returned by mock_ptr_type().
  1444. *
  1445. * @param[in] #function The function which should return the given value.
  1446. *
  1447. * @param[in] #value The value to be returned by mock_ptr_type().
  1448. *
  1449. * This is equivalent to:
  1450. * @code
  1451. * will_return_ptr_count(function, value, -1);
  1452. * @endcode
  1453. *
  1454. * @see will_return_ptr_count()
  1455. * @see mock_ptr_type()
  1456. */
  1457. void will_return_ptr_always(#function, void *value);
  1458. #else
  1459. #define will_return_ptr_always(function, value) \
  1460. will_return_ptr_count(function, (value), WILL_RETURN_ALWAYS)
  1461. #endif
  1462. #ifdef DOXYGEN
  1463. /**
  1464. * @brief Store a value that may be always returned by mock_ptr_type().
  1465. *
  1466. * This stores a value which will always be returned by mock_ptr_type() but is
  1467. * not required to be returned by at least one call to mock_ptr_type().
  1468. * Therefore, in contrast to will_return_ptr_always() which causes a test
  1469. * failure if it is not returned at least once, will_return_ptr_maybe() will
  1470. * never cause a test to fail if its value is not returned.
  1471. *
  1472. * @param[in] #function The function which should return the given value.
  1473. *
  1474. * @param[in] #value The value to be returned by mock_ptr_type().
  1475. *
  1476. * This is equivalent to:
  1477. * @code
  1478. * will_return_ptr_count(function, value, -2);
  1479. * @endcode
  1480. *
  1481. * @see will_return_ptr_count()
  1482. * @see mock_ptr_type()
  1483. */
  1484. void will_return_ptr_maybe(#function, void *value);
  1485. #else
  1486. #define will_return_ptr_maybe(function, value) \
  1487. will_return_ptr_count(function, (value), WILL_RETURN_ONCE)
  1488. #endif
  1489. #ifdef DOXYGEN
  1490. /**
  1491. * @brief Store a named value to be returned by mock_parameter() later.
  1492. *
  1493. * @param[in] #function The function in which the given value should be return.
  1494. *
  1495. * @param[in] #name The name under which the given value should be returned.
  1496. *
  1497. * @param[in] value The value to be returned by mock_parameter().
  1498. *
  1499. * @code
  1500. * void return_integer(int *result)
  1501. * {
  1502. * *result = (int)mock_parameter(result);
  1503. * }
  1504. *
  1505. * static void test_integer_return(void **state)
  1506. * {
  1507. * will_set_parameter(return_integer, result, 42);
  1508. *
  1509. * int retVal = 0;
  1510. * my_function_calling_return_integer(&retVal);
  1511. * assert_int_equal(result, 42);
  1512. * }
  1513. * @endcode
  1514. *
  1515. * @see mock_parameter()
  1516. * @see mock_parameter()
  1517. * @see mock_parameter_int()
  1518. * @see mock_parameter_uint()
  1519. * @see mock_parameter_float()
  1520. * @see mock_parameter_ptr()
  1521. * @see mock_parameter_ptr_type()
  1522. * @see will_set_parameter_int()
  1523. * @see will_set_parameter_uint()
  1524. * @see will_set_parameter_float()
  1525. * @see will_set_parameter_ptr()
  1526. * @see will_set_parameter_ptr_type()
  1527. * @see will_set_parameter_count()
  1528. * @see will_set_parameter_always()
  1529. * @see will_set_parameter_maybe()
  1530. * @see will_set_parameter_ptr_count()
  1531. * @see will_set_parameter_ptr_always()
  1532. * @see will_set_parameter_ptr_maybe()
  1533. */
  1534. void will_set_parameter(#function, #name, uintmax_t value);
  1535. #else
  1536. #define will_set_parameter(function, name, value) \
  1537. _will_set_parameter(cmocka_tostring(function), \
  1538. #name, \
  1539. __FILE__, \
  1540. __LINE__, \
  1541. NULL, \
  1542. cast_int_to_cmocka_value(value), \
  1543. 1)
  1544. #endif
  1545. #ifdef DOXYGEN
  1546. /**
  1547. * @brief Store a named integer value to be returned by mock_parameter() later.
  1548. *
  1549. * And adds some type checking information to be able to check
  1550. * with call to mock_parameter_int().
  1551. *
  1552. * @param[in] #function The function in which the given value should be return.
  1553. *
  1554. * @param[in] #name The name under which the given value should be returned.
  1555. *
  1556. * @param[in] value The value to be returned by mock_parameter().
  1557. *
  1558. * @code
  1559. * void return_int32(int32_t *result)
  1560. * {
  1561. * *result = (int32_t)mock_parameter_int(result);
  1562. * }
  1563. *
  1564. * static void test_integer_return(void **state)
  1565. * {
  1566. * will_set_parameter_int(return_int32, result, -42);
  1567. * int32_t result_param = 0;
  1568. * return_int32(&result_param);
  1569. * assert_int_equal(result_param, -42);
  1570. * }
  1571. * @endcode
  1572. *
  1573. * @see mock_parameter()
  1574. * @see mock_parameter_int()
  1575. * @see will_set_parameter()
  1576. */
  1577. void will_set_parameter_int(#function, #name, intmax_t value);
  1578. #else
  1579. #define will_set_parameter_int(function, name, value) \
  1580. _will_set_parameter(#function, \
  1581. #name, \
  1582. __FILE__, \
  1583. __LINE__, \
  1584. "intmax_t", \
  1585. assign_int_to_cmocka_value(value), \
  1586. 1)
  1587. #endif
  1588. #ifdef DOXYGEN
  1589. /**
  1590. * @brief Store a named unsigned integer value to be returned by
  1591. * mock_parameter() later.
  1592. *
  1593. * And adds some type checking information to be able to check
  1594. * with call to mock_parameter_uint().
  1595. *
  1596. * @param[in] #function The function in which the given value should be
  1597. * return.
  1598. *
  1599. * @param[in] #name The name under which the given value should be returned.
  1600. *
  1601. * @param[in] value The value to be returned by mock_parameter().
  1602. *
  1603. * @code
  1604. * void return_uint32(uint32_t *result)
  1605. * {
  1606. * *result =(uint32_t)mock_parameter_uint(result);
  1607. * }
  1608. *
  1609. * static void test_integer_return(void **state)
  1610. * {
  1611. * will_set_parameter_uint(return_uint32, result, 42);
  1612. * uint32_t result_param = 0;
  1613. * return_uint32(&result_param);
  1614. * assert_uint_equal(result_param, 42);
  1615. * }
  1616. * @endcode
  1617. *
  1618. * @see mock_parameter()
  1619. * @see mock_parameter_uint()
  1620. * @see will_set_parameter()
  1621. */
  1622. void will_set_parameter_uint(#function, #name, uintmax_t value);
  1623. #else
  1624. #define will_set_parameter_uint(function, name, value) \
  1625. _will_set_parameter(#function, \
  1626. #name, \
  1627. __FILE__, \
  1628. __LINE__, \
  1629. "uintmax_t", \
  1630. assign_uint_to_cmocka_value(value), \
  1631. 1)
  1632. #endif
  1633. #ifdef DOXYGEN
  1634. /**
  1635. * @brief Store a named float value to be returned by mock_parameter() later.
  1636. *
  1637. * And adds some type checking information to be able to check
  1638. * with call to mock_parameter_float().
  1639. *
  1640. * @param[in] #function The function in which the given value should be
  1641. * return.
  1642. *
  1643. * @param[in] #name The name under which the given value should be returned.
  1644. *
  1645. * @param[in] value The float value to be returned by mock_parameter().
  1646. *
  1647. * @code
  1648. * void return_float(float *result)
  1649. * {
  1650. * *result = mock_parameter_float(result);
  1651. * }
  1652. *
  1653. * static void test_float_return(void **state)
  1654. * {
  1655. * will_set_parameter_float(return_float, result, 34.7f);
  1656. * float result_param = NAN;
  1657. * return_float(&result_param);
  1658. * assert_float_equal(result_param, 34.7f, 0.01f);
  1659. * }
  1660. * @endcode
  1661. *
  1662. * @see mock_parameter()
  1663. * @see mock_parameter_float()
  1664. * @see will_set_parameter()
  1665. */
  1666. void will_set_parameter_float(#function, #name, float value);
  1667. #else
  1668. #define will_set_parameter_float(function, name, value) \
  1669. _will_set_parameter(#function, \
  1670. #name, \
  1671. __FILE__, \
  1672. __LINE__, \
  1673. "float", \
  1674. assign_float_to_cmocka_value(value), \
  1675. 1)
  1676. #endif
  1677. #ifdef DOXYGEN
  1678. /**
  1679. * @brief Store a named double precision floating point value to be returned
  1680. * by mock_parameter() later.
  1681. *
  1682. * And adds some type checking information to be able to check
  1683. * with call to mock_parameter_double().
  1684. *
  1685. * @param[in] #function The function in which the given value should be
  1686. * return.
  1687. *
  1688. * @param[in] #name The name under which the given value should be returned.
  1689. *
  1690. * @param[in] value The double value to be returned by mock_parameter().
  1691. *
  1692. * @code
  1693. * void return_double(double *result)
  1694. * {
  1695. * *result = mock_parameter_double(result);
  1696. * }
  1697. *
  1698. * static void test_double_return(void **state)
  1699. * {
  1700. * will_set_parameter_double(return_double, result, 34.7);
  1701. * double result_param = NAN;
  1702. * return_double(&result_param);
  1703. * assert_double_equal(result_param, 34.7, 0.0);
  1704. * }
  1705. * @endcode
  1706. *
  1707. * @see mock_parameter()
  1708. * @see mock_parameter_double()
  1709. * @see will_set_parameter()
  1710. */
  1711. void will_set_parameter_double(#function, #name, double value);
  1712. #else
  1713. #define will_set_parameter_double(function, name, value) \
  1714. _will_set_parameter(#function, \
  1715. #name, \
  1716. __FILE__, \
  1717. __LINE__, \
  1718. "double", \
  1719. assign_double_to_cmocka_value(value), \
  1720. 1)
  1721. #endif
  1722. #ifdef DOXYGEN
  1723. /**
  1724. * @brief Store a named integer value to be returned a specified number of times
  1725. * by mock_parameter_int() later.
  1726. *
  1727. * @param[in] #function The function in which the given value should be
  1728. * return.
  1729. *
  1730. * @param[in] #name The name under which the given value should be returned.
  1731. *
  1732. * @param[in] value The value to be returned by mock_parameter_int().
  1733. *
  1734. * @param[in] count The parameter indicates the number of times the value
  1735. * should be returned. If count is set to -1, the value will always be returned
  1736. * but must be returned at least once. If count is set to -2, the value will
  1737. * always be returned, but is not required to be returned.
  1738. *
  1739. * @see mock_parameter_int()
  1740. * @see will_set_parameter_int()
  1741. */
  1742. void will_set_parameter_int_count(#function, #name, intmax_t value, int count);
  1743. #else
  1744. #define will_set_parameter_int_count(function, name, value, count) \
  1745. _will_set_parameter(#function, \
  1746. #name, \
  1747. __FILE__, \
  1748. __LINE__, \
  1749. "intmax_t", \
  1750. assign_int_to_cmocka_value(value), \
  1751. count)
  1752. #endif
  1753. #ifdef DOXYGEN
  1754. /**
  1755. * @brief Store a named unsigned integer value to be returned a specified
  1756. * number of times by mock_parameter_uint() later.
  1757. *
  1758. * @param[in] #function The function in which the given value should be
  1759. * return.
  1760. *
  1761. * @param[in] #name The name under which the given value should be returned.
  1762. *
  1763. * @param[in] value The value to be returned by mock_parameter_uint().
  1764. *
  1765. * @param[in] count The parameter indicates the number of times the value
  1766. * should be returned. If count is set to -1, the value will always be returned
  1767. * but must be returned at least once. If count is set to -2, the value will
  1768. * always be returned, but is not required to be returned.
  1769. *
  1770. * @see mock_parameter_uint()
  1771. * @see will_set_parameter_uint()
  1772. */
  1773. void will_set_parameter_uint_count(#function,
  1774. #name,
  1775. uintmax_t value,
  1776. int count);
  1777. #else
  1778. #define will_set_parameter_uint_count(function, name, value, count) \
  1779. _will_set_parameter(#function, \
  1780. #name, \
  1781. __FILE__, \
  1782. __LINE__, \
  1783. "uintmax_t", \
  1784. assign_uint_to_cmocka_value(value), \
  1785. count)
  1786. #endif
  1787. #ifdef DOXYGEN
  1788. /**
  1789. * @brief Store a named float value to be returned a specified number of times
  1790. * by mock_parameter_float() later.
  1791. *
  1792. * @param[in] #function The function in which the given value should be
  1793. * return.
  1794. *
  1795. * @param[in] #name The name under which the given value should be returned.
  1796. *
  1797. * @param[in] value The value to be returned by mock_parameter_float().
  1798. *
  1799. * @param[in] count The parameter indicates the number of times the value
  1800. * should be returned. If count is set to -1, the value will always be returned
  1801. * but must be returned at least once. If count is set to -2, the value will
  1802. * always be returned, but is not required to be returned.
  1803. *
  1804. * @see mock_parameter_float()
  1805. * @see will_set_parameter_float()
  1806. */
  1807. void will_set_parameter_float_count(#function, #name, float value, int count);
  1808. #else
  1809. #define will_set_parameter_float_count(function, name, value, count) \
  1810. _will_set_parameter(#function, \
  1811. #name, \
  1812. __FILE__, \
  1813. __LINE__, \
  1814. "float", \
  1815. assign_float_to_cmocka_value(value), \
  1816. count)
  1817. #endif
  1818. #ifdef DOXYGEN
  1819. /**
  1820. * @brief Store a named double value to be returned a specified number of times
  1821. * by mock_parameter_double() later.
  1822. *
  1823. * @param[in] #function The function in which the given value should be
  1824. * return.
  1825. *
  1826. * @param[in] #name The name under which the given value should be returned.
  1827. *
  1828. * @param[in] value The value to be returned by mock_parameter_double().
  1829. *
  1830. * @param[in] count The parameter indicates the number of times the value
  1831. * should be returned. If count is set to -1, the value will always be returned
  1832. * but must be returned at least once. If count is set to -2, the value will
  1833. * always be returned, but is not required to be returned.
  1834. *
  1835. * @see mock_parameter_double()
  1836. * @see will_set_parameter_double()
  1837. */
  1838. void will_set_parameter_double_count(#function, #name, double value, int count);
  1839. #else
  1840. #define will_set_parameter_double_count(function, name, value, count) \
  1841. _will_set_parameter(#function, \
  1842. #name, \
  1843. __FILE__, \
  1844. __LINE__, \
  1845. "double", \
  1846. assign_double_to_cmocka_value(value), \
  1847. count)
  1848. #endif
  1849. #ifdef DOXYGEN
  1850. /**
  1851. * @deprecated Use will_set_parameter_int_count() or
  1852. * will_set_parameter_uint_count()
  1853. */
  1854. void will_set_parameter_count(#function, #name, uintmax_t value, int count);
  1855. #else
  1856. #define will_set_parameter_count(function, name, value, count) \
  1857. do { \
  1858. CMOCKA_DEPRECATION_WARNING( \
  1859. "will_set_parameter_count: use will_set_parameter_int_count or " \
  1860. "will_set_parameter_uint_count instead") \
  1861. _will_set_parameter(cmocka_tostring(function), \
  1862. #name, \
  1863. __FILE__, \
  1864. __LINE__, \
  1865. NULL, \
  1866. cast_int_to_cmocka_value(value), \
  1867. count); \
  1868. } while (0)
  1869. #endif
  1870. #ifdef DOXYGEN
  1871. /**
  1872. * @brief Store a named integer value that will always be returned by
  1873. * mock_parameter_int().
  1874. *
  1875. * @param[in] #function The function in which the given value should be
  1876. * return.
  1877. *
  1878. * @param[in] #name The name under which the given value should be returned.
  1879. *
  1880. * @param[in] value The value to be returned by mock_parameter_int().
  1881. *
  1882. * This is equivalent to:
  1883. * @code
  1884. * will_set_parameter_int_count(function, name, value, -1);
  1885. * @endcode
  1886. *
  1887. * @see mock_parameter_int()
  1888. * @see will_set_parameter_int_count()
  1889. */
  1890. void will_set_parameter_int_always(#function, #name, intmax_t value);
  1891. #else
  1892. #define will_set_parameter_int_always(function, name, value) \
  1893. will_set_parameter_int_count(function, name, (value), WILL_RETURN_ALWAYS)
  1894. #endif
  1895. #ifdef DOXYGEN
  1896. /**
  1897. * @brief Store a named unsigned integer value that will always be returned by
  1898. * mock_parameter_uint().
  1899. *
  1900. * @param[in] #function The function in which the given value should be
  1901. * return.
  1902. *
  1903. * @param[in] #name The name under which the given value should be returned.
  1904. *
  1905. * @param[in] value The value to be returned by mock_parameter_uint().
  1906. *
  1907. * This is equivalent to:
  1908. * @code
  1909. * will_set_parameter_uint_count(function, name, value, -1);
  1910. * @endcode
  1911. *
  1912. * @see mock_parameter_uint()
  1913. * @see will_set_parameter_uint_count()
  1914. */
  1915. void will_set_parameter_uint_always(#function, #name, uintmax_t value);
  1916. #else
  1917. #define will_set_parameter_uint_always(function, name, value) \
  1918. will_set_parameter_uint_count(function, name, (value), WILL_RETURN_ALWAYS)
  1919. #endif
  1920. #ifdef DOXYGEN
  1921. /**
  1922. * @brief Store a named float value that will always be returned by
  1923. * mock_parameter_float().
  1924. *
  1925. * @param[in] #function The function in which the given value should be
  1926. * return.
  1927. *
  1928. * @param[in] #name The name under which the given value should be returned.
  1929. *
  1930. * @param[in] value The value to be returned by mock_parameter_float().
  1931. *
  1932. * This is equivalent to:
  1933. * @code
  1934. * will_set_parameter_float_count(function, name, value, -1);
  1935. * @endcode
  1936. *
  1937. * @see mock_parameter_float()
  1938. * @see will_set_parameter_float_count()
  1939. */
  1940. void will_set_parameter_float_always(#function, #name, float value);
  1941. #else
  1942. #define will_set_parameter_float_always(function, name, value) \
  1943. will_set_parameter_float_count(function, name, (value), WILL_RETURN_ALWAYS)
  1944. #endif
  1945. #ifdef DOXYGEN
  1946. /**
  1947. * @brief Store a named double value that will always be returned by
  1948. * mock_parameter_double().
  1949. *
  1950. * @param[in] #function The function in which the given value should be
  1951. * return.
  1952. *
  1953. * @param[in] #name The name under which the given value should be returned.
  1954. *
  1955. * @param[in] value The value to be returned by mock_parameter_double().
  1956. *
  1957. * This is equivalent to:
  1958. * @code
  1959. * will_set_parameter_double_count(function, name, value, -1);
  1960. * @endcode
  1961. *
  1962. * @see mock_parameter_double()
  1963. * @see will_set_parameter_double_count()
  1964. */
  1965. void will_set_parameter_double_always(#function, #name, double value);
  1966. #else
  1967. #define will_set_parameter_double_always(function, name, value) \
  1968. will_set_parameter_double_count(function, name, (value), WILL_RETURN_ALWAYS)
  1969. #endif
  1970. #ifdef DOXYGEN
  1971. /**
  1972. * @deprecated Use will_set_parameter_int_always() or
  1973. * will_set_parameter_uint_always()
  1974. */
  1975. void will_set_parameter_always(#function, #name, uintmax_t value);
  1976. #else
  1977. #define will_set_parameter_always(function, name, value) \
  1978. do { \
  1979. CMOCKA_DEPRECATION_WARNING( \
  1980. "will_set_parameter_always: use will_set_parameter_int_always or " \
  1981. "will_set_parameter_uint_always instead") \
  1982. will_set_parameter_count(function, name, (value), WILL_RETURN_ALWAYS); \
  1983. } while (0)
  1984. #endif
  1985. #ifdef DOXYGEN
  1986. /**
  1987. * @brief Store a named integer value that may always be returned by mock_parameter_int().
  1988. *
  1989. * This stores a value which will always be returned by mock_parameter_int() but is not
  1990. * required to be returned by at least one call to mock_parameter_int().
  1991. *
  1992. * @param[in] #function The function in which the given value should be return.
  1993. *
  1994. * @param[in] #name The name under which the given value should be returned.
  1995. *
  1996. * @param[in] value The value to be returned by mock_parameter_int().
  1997. *
  1998. * This is equivalent to:
  1999. * @code
  2000. * will_set_parameter_int_count(function, name, value, -2);
  2001. * @endcode
  2002. *
  2003. * @see mock_parameter_int()
  2004. * @see will_set_parameter_int_count()
  2005. */
  2006. void will_set_parameter_int_maybe(#function, #name, intmax_t value);
  2007. #else
  2008. #define will_set_parameter_int_maybe(function, name, value) \
  2009. will_set_parameter_int_count(function, name, (value), WILL_RETURN_ONCE)
  2010. #endif
  2011. #ifdef DOXYGEN
  2012. /**
  2013. * @brief Store a named unsigned integer value that may always be returned by mock_parameter_uint().
  2014. *
  2015. * This stores a value which will always be returned by mock_parameter_uint() but is not
  2016. * required to be returned by at least one call to mock_parameter_uint().
  2017. *
  2018. * @param[in] #function The function in which the given value should be return.
  2019. *
  2020. * @param[in] #name The name under which the given value should be returned.
  2021. *
  2022. * @param[in] value The value to be returned by mock_parameter_uint().
  2023. *
  2024. * This is equivalent to:
  2025. * @code
  2026. * will_set_parameter_uint_count(function, name, value, -2);
  2027. * @endcode
  2028. *
  2029. * @see mock_parameter_uint()
  2030. * @see will_set_parameter_uint_count()
  2031. */
  2032. void will_set_parameter_uint_maybe(#function, #name, uintmax_t value);
  2033. #else
  2034. #define will_set_parameter_uint_maybe(function, name, value) \
  2035. will_set_parameter_uint_count(function, name, (value), WILL_RETURN_ONCE)
  2036. #endif
  2037. #ifdef DOXYGEN
  2038. /**
  2039. * @brief Store a named float value that may always be returned by mock_parameter_float().
  2040. *
  2041. * This stores a value which will always be returned by mock_parameter_float() but is not
  2042. * required to be returned by at least one call to mock_parameter_float().
  2043. *
  2044. * @param[in] #function The function in which the given value should be return.
  2045. *
  2046. * @param[in] #name The name under which the given value should be returned.
  2047. *
  2048. * @param[in] value The value to be returned by mock_parameter_float().
  2049. *
  2050. * This is equivalent to:
  2051. * @code
  2052. * will_set_parameter_float_count(function, name, value, -2);
  2053. * @endcode
  2054. *
  2055. * @see mock_parameter_float()
  2056. * @see will_set_parameter_float_count()
  2057. */
  2058. void will_set_parameter_float_maybe(#function, #name, float value);
  2059. #else
  2060. #define will_set_parameter_float_maybe(function, name, value) \
  2061. will_set_parameter_float_count(function, name, (value), WILL_RETURN_ONCE)
  2062. #endif
  2063. #ifdef DOXYGEN
  2064. /**
  2065. * @brief Store a named double value that may always be returned by mock_parameter_double().
  2066. *
  2067. * This stores a value which will always be returned by mock_parameter_double() but is not
  2068. * required to be returned by at least one call to mock_parameter_double().
  2069. *
  2070. * @param[in] #function The function in which the given value should be return.
  2071. *
  2072. * @param[in] #name The name under which the given value should be returned.
  2073. *
  2074. * @param[in] value The value to be returned by mock_parameter_double().
  2075. *
  2076. * This is equivalent to:
  2077. * @code
  2078. * will_set_parameter_double_count(function, name, value, -2);
  2079. * @endcode
  2080. *
  2081. * @see mock_parameter_double()
  2082. * @see will_set_parameter_double_count()
  2083. */
  2084. void will_set_parameter_double_maybe(#function, #name, double value);
  2085. #else
  2086. #define will_set_parameter_double_maybe(function, name, value) \
  2087. will_set_parameter_double_count(function, name, (value), WILL_RETURN_ONCE)
  2088. #endif
  2089. #ifdef DOXYGEN
  2090. /**
  2091. * @deprecated Use will_set_parameter_int_maybe() or
  2092. * will_set_parameter_uint_maybe()
  2093. */
  2094. void will_set_parameter_maybe(#function, #name, uintmax_t value);
  2095. #else
  2096. #define will_set_parameter_maybe(function, name, value) \
  2097. do { \
  2098. CMOCKA_DEPRECATION_WARNING( \
  2099. "will_set_parameter_maybe: use will_set_parameter_int_maybe or " \
  2100. "will_set_parameter_uint_maybe instead") \
  2101. will_set_parameter_count(function, name, (value), WILL_RETURN_ONCE); \
  2102. } while (0)
  2103. #endif
  2104. #ifdef DOXYGEN
  2105. /**
  2106. * @brief Store a named pointer value to be returned by mock_parameter() later.
  2107. *
  2108. * @param[in] #function The function in which the given value should be
  2109. * return.
  2110. *
  2111. * @param[in] #name The name under which the given value should be returned.
  2112. *
  2113. * @param[in] value The value to be returned by mock_parameter().
  2114. *
  2115. * @code
  2116. * void return_pointer(const char **result)
  2117. * {
  2118. * *result = (const char *)mock_parameter_ptr(result);
  2119. * }
  2120. * static void test_pointer_return(void **state)
  2121. * {
  2122. * will_set_parameter_ptr(return_pointer, result, "hello world");
  2123. * const char *returned = NULL;
  2124. * my_func_calling_return_pointer(&returned);
  2125. * assert_string_equal(returned, "hello world");
  2126. * }
  2127. * @endcode
  2128. *
  2129. * @see mock_parameter()
  2130. * @see mock_parameter_ptr()
  2131. * @see will_set_parameter()
  2132. */
  2133. void will_set_parameter_ptr(#function, #name, void *value);
  2134. #else
  2135. #define will_set_parameter_ptr(function, name, value) \
  2136. _will_set_parameter(#function, \
  2137. #name, \
  2138. __FILE__, \
  2139. __LINE__, \
  2140. NULL, \
  2141. cast_ptr_to_cmocka_value(value), \
  2142. 1)
  2143. #endif
  2144. #ifdef DOXYGEN
  2145. /**
  2146. * @brief Store a named pointer value to be returned by mock_parameter() later.
  2147. *
  2148. * This will also check that the type matches and if not will fail().
  2149. *
  2150. * @param[in] #function The function in which the given value should be return.
  2151. *
  2152. * @param[in] #name The name under which the given value should be returned.
  2153. *
  2154. * @param[in] value The value to be returned by mock_parameter().
  2155. *
  2156. * @param[in] type The type of the pointer.
  2157. *
  2158. * @code
  2159. * void return_pointer(const char **result)
  2160. * {
  2161. * *result = mock_parameter_ptr_typed(result, const char*);
  2162. * }
  2163. * static void test_pointer_return(void **state)
  2164. * {
  2165. * will_set_parameter_ptr_type(return_pointer, result, "hello world", const char*);
  2166. * const char *returned = NULL;
  2167. * my_func_calling_return_pointer(&returned);
  2168. * assert_string_equal(returned, "hello world");
  2169. * }
  2170. * @endcode
  2171. *
  2172. * @see mock_parameter()
  2173. * @see mock_parameter_ptr()
  2174. * @see mock_parameter_ptr_type()
  2175. * @see will_set_parameter()
  2176. * @see will_set_parameter_ptr()
  2177. */
  2178. void will_set_parameter_ptr_type(#function, #name, void *value, #type);
  2179. #else
  2180. #define will_set_parameter_ptr_type(function, name, value, type) \
  2181. _will_set_parameter(#function, \
  2182. #name, \
  2183. __FILE__, \
  2184. __LINE__, \
  2185. #type, \
  2186. cast_ptr_to_cmocka_value(value), \
  2187. 1)
  2188. #endif
  2189. #ifdef DOXYGEN
  2190. /**
  2191. * @brief Store a named pointer value to be returned a specified number of times
  2192. * by mock_parameter_ptr() later.
  2193. *
  2194. * @param[in] #function The function in which the given value should be return.
  2195. *
  2196. * @param[in] #name The name under which the given value should be returned.
  2197. *
  2198. * @param[in] value The value to be returned by mock_parameter_ptr().
  2199. *
  2200. * @param[in] count The parameter indicates the number of times the value should
  2201. * be returned by mock_parameter_ptr(). If count is set to -1, the value
  2202. * will always be returned but must be returned at least once.
  2203. * If count is set to -2, the value will always be returned
  2204. * by mock_parameter_ptr(), but is not required to be returned.
  2205. *
  2206. * @code
  2207. * void return_pointer(const char **resultA, const char **resultB)
  2208. * {
  2209. * *resultA = (const char *)mock_parameter_ptr(result);
  2210. * *resultB = (const char *)mock_parameter_ptr(result);
  2211. * }
  2212. * static void test_pointer_return(void **state)
  2213. * {
  2214. * will_set_parameter_ptr_count(return_pointer, result, "hello world", const char*, 2);
  2215. * const char *returnedA = NULL;
  2216. * const char *returnedB = NULL;
  2217. * my_func_calling_return_pointer(&returnedA, &returnedB);
  2218. * assert_string_equal(returnedA, "hello world");
  2219. * assert_string_equal(returnedB, "hello world");
  2220. * }
  2221. * @endcode
  2222. *
  2223. * @see mock_parameter()
  2224. * @see mock_parameter_ptr()
  2225. * @see will_named_return()
  2226. * @see will_named_return_ptr()
  2227. */
  2228. void will_set_parameter_ptr_count(#function, #name, void *value, int count);
  2229. #else
  2230. #define will_set_parameter_ptr_count(function, name, value, count) \
  2231. _will_set_parameter(#function, \
  2232. #name, \
  2233. __FILE__, \
  2234. __LINE__, \
  2235. NULL, \
  2236. cast_ptr_to_cmocka_value(value), \
  2237. count)
  2238. #endif
  2239. #ifdef DOXYGEN
  2240. /**
  2241. * @brief Store a named pointer value that will be always returned by
  2242. * mock_parameter_ptr().
  2243. *
  2244. * This stores a value which will always be returned by mock_parameter_ptr()
  2245. * and is required to be returned by at least one call to mock_parameter_ptr().
  2246. * If it is not returned at least once the test will fail.
  2247. *
  2248. * @param[in] #function The function in which the given value should be
  2249. * return.
  2250. *
  2251. * @param[in] #name The name under which the given value should be returned.
  2252. *
  2253. * @param[in] value The value to be returned by mock_parameter_ptr().
  2254. *
  2255. * This is equivalent to:
  2256. * @code
  2257. * will_set_parameter_ptr_count(function, name, value, -1);
  2258. * @endcode
  2259. *
  2260. * @see mock_parameter()
  2261. * @see mock_parameter_ptr()
  2262. * @see will_set_parameter()
  2263. * @see will_set_parameter_ptr()
  2264. * @see will_set_parameter_ptr_count()
  2265. */
  2266. void will_set_parameter_ptr_always(#function, #name, void *value);
  2267. #else
  2268. #define will_set_parameter_ptr_always(function, name, value) \
  2269. will_set_parameter_ptr_count(function, name, (value), WILL_RETURN_ALWAYS)
  2270. #endif
  2271. #ifdef DOXYGEN
  2272. /**
  2273. * @brief Store a named pointer value that may be always returned by
  2274. * mock_parameter_ptr().
  2275. *
  2276. * This stores a value which will always be returned by mock_parameter_ptr() but
  2277. * is not required to be returned by at least one call to mock_parameter_ptr().
  2278. * Therefore, in contrast to will_set_parameter_ptr_always() which causes a test
  2279. * failure if it is not returned at least once, will_set_parameter_ptr_maybe()
  2280. * will never cause a test to fail if its value is not returned.
  2281. *
  2282. * @param[in] #function The function in which the given value should be
  2283. * return.
  2284. *
  2285. * @param[in] #name The name under which the given value should be returned.
  2286. *
  2287. * @param[in] value The value to be returned by mock_parameter_ptr().
  2288. *
  2289. * This is equivalent to:
  2290. * @code
  2291. * will_set_parameter_ptr_count(function, name, value, -2);
  2292. * @endcode
  2293. *
  2294. * @see mock_parameter()
  2295. * @see mock_parameter_ptr()
  2296. * @see will_set_parameter()
  2297. * @see will_set_parameter_ptr()
  2298. * @see will_set_parameter_ptr_count()
  2299. */
  2300. void will_set_parameter_ptr_maybe(#function, #name, void *value);
  2301. #else
  2302. #define will_set_parameter_ptr_maybe(function, name, value) \
  2303. will_set_parameter_ptr_count(function, name, (value), WILL_RETURN_ONCE)
  2304. #endif
  2305. #ifdef DOXYGEN
  2306. /**
  2307. * @brief Store an integer value to set errno to by mock_errno() later.
  2308. *
  2309. * @param[in] #function The function in which errno
  2310. * should be set to the given value.
  2311. *
  2312. * @param[in] value The value to set errno to by the call to mock_errno().
  2313. *
  2314. * @code
  2315. * void sets_errno(void)
  2316. * {
  2317. * mock_errno();
  2318. * }
  2319. *
  2320. * static void test_sets_errno(void **state)
  2321. * {
  2322. * will_set_errno(sets_errno, -3);
  2323. *
  2324. * assert_int_equal(errno, -3);
  2325. * }
  2326. * @endcode
  2327. *
  2328. * @see mock_errno()
  2329. */
  2330. void will_set_errno(#function, intmax_t value);
  2331. #else
  2332. #define will_set_errno(function, value) \
  2333. _will_set_parameter(#function, \
  2334. "/errno", \
  2335. __FILE__, \
  2336. __LINE__, \
  2337. "errno", \
  2338. assign_int_to_cmocka_value(value), \
  2339. 1)
  2340. #endif
  2341. #ifdef DOXYGEN
  2342. /**
  2343. * @brief Store an integer value to always set errno to by mock_errno().
  2344. *
  2345. *
  2346. *
  2347. * @param[in] #function The function in which errno
  2348. * should be set to the given value.
  2349. *
  2350. * @param[in] value The value to set errno to by the call to mock_errno().
  2351. *
  2352. * @param[in] count The count parameter gives the number of times the value
  2353. * should be validated by check_expected(). If count is set
  2354. * to @ref EXPECT_ALWAYS the value will always be returned,
  2355. * and cmocka expects check_expected() to be issued at least
  2356. * once. If count is set to @ref EXPECT_MAYBE, any number of
  2357. * calls to check_expected() is accepted, including zero.
  2358. *
  2359. * @code
  2360. * void sets_errno(void)
  2361. * {
  2362. * mock_errno();
  2363. * }
  2364. * static void test_sets_errno(void **state)
  2365. * {
  2366. * will_set_errno_count(sets_errno, -3, 2);
  2367. * sets_errno();
  2368. * assert_int_equal(errno, -3);
  2369. * errno = 0;
  2370. * sets_errno();
  2371. * assert_int_equal(errno, -3);
  2372. * }
  2373. * @endcode
  2374. *
  2375. * @see mock_errno()
  2376. * @see will_set_errno()
  2377. * @see will_set_errno_always()
  2378. * @see will_set_errno_maybe()
  2379. */
  2380. void will_set_errno_count(#function, intmax_t value, size_t count);
  2381. #else
  2382. #define will_set_errno_count(function, value, count) \
  2383. _will_set_parameter(#function, \
  2384. "/errno", \
  2385. __FILE__, \
  2386. __LINE__, \
  2387. "errno", \
  2388. assign_int_to_cmocka_value(value), \
  2389. (count))
  2390. #endif
  2391. #ifdef DOXYGEN
  2392. /**
  2393. * @brief Store an integer value to set errno to by mock_errno() later,
  2394. * for a specified number of times.
  2395. *
  2396. * This stores a value which will errno will always be set to by mock_errno()
  2397. * but is required to be set least once by a call to mock_errno().
  2398. *
  2399. * @param[in] #function The function in which errno
  2400. * should be set to the given value.
  2401. *
  2402. * @param[in] value The value to set errno to by the call to mock_errno().
  2403. *
  2404. * This is equivalent to:
  2405. * @code
  2406. * will_set_parameter_count(function, name, value, -1);
  2407. * @endcode
  2408. *
  2409. * @see mock_errno()
  2410. * @see will_set_errno()
  2411. * @see will_set_errno_count()
  2412. * @see will_set_errno_maybe()
  2413. */
  2414. void will_set_errno_always(#function, intmax_t value);
  2415. #else
  2416. #define will_set_errno_always(function, value) \
  2417. will_set_errno_count(function, (value), WILL_RETURN_ALWAYS);
  2418. #endif
  2419. #ifdef DOXYGEN
  2420. /**
  2421. * @brief Store an integer value to set errno to by mock_errno() later,
  2422. * for a specified number of times.
  2423. *
  2424. * This stores a value which will errno will always be set to by mock_errno()
  2425. * and won't fail if mock_errno() is never called.
  2426. *
  2427. * @param[in] #function The function in which errno
  2428. * should be set to the given value.
  2429. *
  2430. * @param[in] value The value to set errno to by the call to mock_errno().
  2431. *
  2432. * This is equivalent to:
  2433. * @code
  2434. * will_set_parameter_count(function, name, value, -2);
  2435. * @endcode
  2436. *
  2437. * @see mock_errno()
  2438. * @see will_set_errno()
  2439. * @see will_set_errno_count()
  2440. * @see will_set_errno_always()
  2441. */
  2442. void will_set_errno_maybe(#function, intmax_t value);
  2443. #else
  2444. #define will_set_errno_maybe(function, value) \
  2445. will_set_errno_count(function, (value), WILL_RETURN_ONCE);
  2446. #endif
  2447. /** @} */ /* cmocka_mock */
  2448. /**
  2449. * @defgroup cmocka_param ✅ Checking Parameters
  2450. * @ingroup cmocka
  2451. * @brief Validate function parameters match expected values.
  2452. *
  2453. * Functionality to store expected values for mock function parameters.
  2454. *
  2455. * In addition to storing the return values of mock functions, cmocka provides
  2456. * functionality to store expected values for mock function parameters using
  2457. * the expect_*() functions provided. A mock function parameter can then be
  2458. * validated using the check_expected_*() macros.
  2459. *
  2460. * Successive calls to expect_*() macros for a parameter queues values to check
  2461. * the specified parameter. check_expected_*() checks a function parameter
  2462. * against the next value queued using expect_*(), if the parameter check fails
  2463. * a test failure is signalled. In addition if check_expected_*() is called and
  2464. * no more parameter values are queued a test failure occurs.
  2465. *
  2466. * The following test stub illustrates how to do this. First is the the function
  2467. * we call in the test driver:
  2468. *
  2469. * @code
  2470. * static void test_driver(void **state)
  2471. * {
  2472. * expect_string(chef_cook, order, "hotdog");
  2473. * }
  2474. * @endcode
  2475. *
  2476. * Now the chef_cook function can check if the parameter we got passed is the
  2477. * parameter which is expected by the test driver. This can be done the
  2478. * following way:
  2479. *
  2480. * @code
  2481. * int chef_cook(const char *order, char **dish_out)
  2482. * {
  2483. * check_expected_ptr(order);
  2484. * }
  2485. * @endcode
  2486. *
  2487. * For a complete example please take a look
  2488. * <a href="https://git.cryptomilk.org/projects/cmocka.git/tree/example/mock">here</a>
  2489. *
  2490. * @{
  2491. */
  2492. #ifdef DOXYGEN
  2493. /**
  2494. * @deprecated Use expect_check_data()
  2495. */
  2496. void expect_check(function,
  2497. parameter,
  2498. CheckParameterValue check_function,
  2499. const void *check_data);
  2500. #else
  2501. #define expect_check(function, parameter, check_function, check_data) \
  2502. do { \
  2503. CMOCKA_DEPRECATION_WARNING( \
  2504. "expect_check: use expect_check_data instead") \
  2505. _expect_check(cmocka_tostring(function), \
  2506. cmocka_tostring(parameter), \
  2507. __FILE__, \
  2508. __LINE__, \
  2509. check_function, \
  2510. cast_to_uintmax_type(check_data), \
  2511. NULL, \
  2512. 1); \
  2513. } while (0)
  2514. #endif
  2515. #ifdef DOXYGEN
  2516. /**
  2517. * @deprecated Use expect_check_data_count()
  2518. */
  2519. void expect_check_count(function,
  2520. parameter,
  2521. CheckParameterValue check_function,
  2522. const void *check_data,
  2523. size_t count);
  2524. #else
  2525. #define expect_check_count( \
  2526. function, parameter, check_function, check_data, count) \
  2527. do { \
  2528. CMOCKA_DEPRECATION_WARNING( \
  2529. "expect_check_count: use expect_check_data_count instead") \
  2530. _expect_check(cmocka_tostring(function), \
  2531. cmocka_tostring(parameter), \
  2532. __FILE__, \
  2533. __LINE__, \
  2534. check_function, \
  2535. cast_to_uintmax_type(check_data), \
  2536. NULL, \
  2537. count); \
  2538. } while (0)
  2539. #endif
  2540. #ifdef DOXYGEN
  2541. /**
  2542. * @brief Add a custom parameter checking function using CMockaValueData (new API).
  2543. *
  2544. * This is the new API that uses CMockaValueData for type-safe parameter checking.
  2545. * It allows checking of integer, float, double, and pointer values.
  2546. *
  2547. * @param[in] #function The function to add a custom parameter checking
  2548. * function for.
  2549. *
  2550. * @param[in] #parameter The parameters passed to the function.
  2551. *
  2552. * @param[in] #check_function The check function to call (CheckParameterValueData).
  2553. *
  2554. * @param[in] check_data The data to pass to the check function (CMockaValueData).
  2555. *
  2556. * ## Checker Function Interface
  2557. *
  2558. * The checker function must have the following signature:
  2559. * @code
  2560. * int checker_function(CMockaValueData value, CMockaValueData check_data);
  2561. * @endcode
  2562. *
  2563. * ### Parameters
  2564. * - **value**: The actual parameter value passed to the mocked function.
  2565. * This is provided via check_expected(), check_expected_int(),
  2566. * check_expected_uint(), check_expected_float(), or check_expected_double()
  2567. * in the mocked function.
  2568. * - **check_data**: The expected data that was passed to expect_check_data().
  2569. * This contains the value you want to compare against.
  2570. *
  2571. * ### Return Value
  2572. * The checker function should return:
  2573. * - **Non-zero** (typically 1 or true) if the check succeeds
  2574. * - **Zero** (0 or false) if the check fails
  2575. *
  2576. * When the checker returns zero, cmocka will fail the test with an appropriate
  2577. * error message.
  2578. *
  2579. * ### Accessing Values in CMockaValueData
  2580. *
  2581. * The CMockaValueData union contains the following fields:
  2582. * - **int_val**: For signed integer types (intmax_t)
  2583. * - **uint_val**: For unsigned integer types (uintmax_t)
  2584. * - **float_val**: For single-precision floating-point types (float)
  2585. * - **real_val**: For double-precision floating-point types (double)
  2586. * - **ptr**: For pointer types (const void *)
  2587. *
  2588. * ## Usage Notes
  2589. *
  2590. * 1. **Calling will_return() in the checker**: You can call will_return() or
  2591. * other cmocka setup functions within your checker function to set up return
  2592. * values dynamically based on the parameter being checked. This is useful
  2593. * when the return value depends on the input parameter.
  2594. *
  2595. * 2. **Checking multiple parameters**: To check all parameters of a function
  2596. * at once, you can pass a pointer to a struct containing all parameter
  2597. * values as the check_data. Your checker function can then validate all
  2598. * fields in a single call. See example below.
  2599. *
  2600. * 3. **Memory allocation for check_data**: If you allocate memory for the
  2601. * check_data parameter (e.g., for a struct), you are responsible for
  2602. * managing its lifetime. The checker function receives the data by value,
  2603. * so if you pass a pointer in check_data.ptr, ensure it remains valid
  2604. * until the checker is called. Note that cmocka does not free this memory
  2605. * automatically.
  2606. *
  2607. * @code
  2608. * // Example: Custom range checker
  2609. * typedef struct {
  2610. * int min;
  2611. * int max;
  2612. * } range_data;
  2613. *
  2614. * int check_in_custom_range(CMockaValueData value, CMockaValueData check_data)
  2615. * {
  2616. * range_data *range = (range_data *)check_data.ptr;
  2617. * int val = value.int_val;
  2618. *
  2619. * // Return 1 (true) if in range, 0 (false) otherwise
  2620. * return (val >= range->min && val <= range->max);
  2621. * }
  2622. *
  2623. * // In your test:
  2624. * void test_custom_check(void **state)
  2625. * {
  2626. * range_data range = {10, 20};
  2627. * expect_check_data(my_function, param,
  2628. * check_in_custom_range,
  2629. * cast_ptr_to_cmocka_value(&range));
  2630. * my_function(15); // This will pass
  2631. * }
  2632. *
  2633. * // The mocked function:
  2634. * void my_function(int param)
  2635. * {
  2636. * check_expected_int(param); // Triggers the checker
  2637. * }
  2638. * @endcode
  2639. *
  2640. * @code
  2641. * // Example: Checker that also sets return values
  2642. * int check_and_setup_return(CMockaValueData value, CMockaValueData check_data)
  2643. * {
  2644. * int expected = check_data.int_val;
  2645. * int actual = value.int_val;
  2646. *
  2647. * if (actual == expected) {
  2648. * // Set up return value dynamically based on the parameter
  2649. * will_return_int(some_other_function, actual * 2);
  2650. * return 1; // Success
  2651. * }
  2652. * return 0; // Failure
  2653. * }
  2654. * @endcode
  2655. *
  2656. * @code
  2657. * // Example: Checking multiple parameters at once
  2658. * typedef struct {
  2659. * int expected_a;
  2660. * int expected_b;
  2661. * const char *expected_str;
  2662. * } multi_param_check;
  2663. *
  2664. * int check_multiple_params(CMockaValueData value, CMockaValueData check_data)
  2665. * {
  2666. * multi_param_check *expected = (multi_param_check *)check_data.ptr;
  2667. * multi_param_check *actual = (multi_param_check *)value.ptr;
  2668. *
  2669. * return (actual->expected_a == expected->expected_a &&
  2670. * actual->expected_b == expected->expected_b &&
  2671. * strcmp(actual->expected_str, expected->expected_str) == 0);
  2672. * }
  2673. *
  2674. * // In your test:
  2675. * void test_multi_param(void **state)
  2676. * {
  2677. * multi_param_check expected = {42, 100, "test"};
  2678. * multi_param_check actual = {42, 100, "test"};
  2679. *
  2680. * expect_check_data(my_function, params,
  2681. * check_multiple_params,
  2682. * cast_ptr_to_cmocka_value(&expected));
  2683. *
  2684. * // In the mocked function, you would pack all params into a struct
  2685. * // and call check_expected_ptr(params)
  2686. * }
  2687. * @endcode
  2688. *
  2689. * @see check_expected_int()
  2690. * @see check_expected_uint()
  2691. * @see check_expected_float()
  2692. * @see check_expected_double()
  2693. * @see check_expected_ptr()
  2694. * @see expect_check_data_count()
  2695. */
  2696. void expect_check_data(function,
  2697. parameter,
  2698. CheckParameterValueData check_function,
  2699. CMockaValueData check_data);
  2700. #else
  2701. #define expect_check_data(function, parameter, check_function, check_data) \
  2702. _expect_check_data(cmocka_tostring(function), \
  2703. cmocka_tostring(parameter), \
  2704. __FILE__, \
  2705. __LINE__, \
  2706. check_function, \
  2707. check_data, \
  2708. NULL, \
  2709. 1)
  2710. #endif
  2711. #ifdef DOXYGEN
  2712. /**
  2713. * @brief Add a custom parameter checking function using CMockaValueData with
  2714. * count (new API).
  2715. *
  2716. * This is the new API that uses CMockaValueData for type-safe parameter
  2717. * checking. This version allows you to specify how many times the check should
  2718. * be performed.
  2719. *
  2720. * @param[in] #function The function to add a custom parameter checking
  2721. * function for.
  2722. *
  2723. * @param[in] #parameter The parameters passed to the function.
  2724. *
  2725. * @param[in] #check_function The check function to call
  2726. * (CheckParameterValueData).
  2727. *
  2728. * @param[in] check_data The data to pass to the check function (CMockaValueData).
  2729. *
  2730. * @param[in] count The number of times this check should be called.
  2731. * - A specific positive number: The check will be performed
  2732. * exactly that many times.
  2733. * - **EXPECT_ALWAYS** (-1): The check will always be
  2734. * performed and must be called at least once. The test
  2735. * will fail if not called.
  2736. * - **EXPECT_MAYBE** (-2): The check will always be
  2737. * performed but is not required to be called. The test
  2738. * will not fail if the checker is never invoked.
  2739. *
  2740. * See expect_check_data() for detailed documentation on the checker function
  2741. * interface, usage notes, and examples.
  2742. *
  2743. * @code
  2744. * // Example: Check a parameter exactly 3 times
  2745. * expect_check_data_count(my_function, param,
  2746. * my_checker,
  2747. * assign_int_to_cmocka_value(42),
  2748. * 3);
  2749. * my_function(42);
  2750. * my_function(42);
  2751. * my_function(42);
  2752. * @endcode
  2753. *
  2754. * @code
  2755. * // Example: Always check (must be called at least once)
  2756. * expect_check_data_count(my_function, param,
  2757. * my_checker,
  2758. * assign_int_to_cmocka_value(42),
  2759. * EXPECT_ALWAYS);
  2760. * my_function(42);
  2761. * my_function(42);
  2762. * // Can call any number of times, but at least once
  2763. * @endcode
  2764. *
  2765. * @code
  2766. * // Example: Optional check (may or may not be called)
  2767. * expect_check_data_count(my_function, param,
  2768. * my_checker,
  2769. * assign_int_to_cmocka_value(42),
  2770. * EXPECT_MAYBE);
  2771. * // my_function may or may not be called - test won't fail either way
  2772. * @endcode
  2773. *
  2774. * @see expect_check_data()
  2775. */
  2776. void expect_check_data_count(function,
  2777. parameter,
  2778. CheckParameterValueData check_function,
  2779. CMockaValueData check_data,
  2780. size_t count);
  2781. #else
  2782. #define expect_check_data_count(function, \
  2783. parameter, \
  2784. check_function, \
  2785. check_data, \
  2786. count) \
  2787. _expect_check_data(cmocka_tostring(function), \
  2788. cmocka_tostring(parameter), \
  2789. __FILE__, \
  2790. __LINE__, \
  2791. check_function, \
  2792. check_data, \
  2793. NULL, \
  2794. count)
  2795. #endif
  2796. #ifdef DOXYGEN
  2797. /**
  2798. * @deprecated Use expect_int_in_set() or expect_uint_in_set()
  2799. */
  2800. void expect_in_set(#function, #parameter, uintmax_t value_array[]);
  2801. #else
  2802. #define expect_in_set(function, parameter, value_array) \
  2803. do { \
  2804. CMOCKA_DEPRECATION_WARNING("expect_in_set: use expect_int_in_set or " \
  2805. "expect_uint_in_set instead") \
  2806. expect_in_set_count(function, parameter, value_array, 1); \
  2807. } while (0)
  2808. #endif
  2809. #ifdef DOXYGEN
  2810. /**
  2811. * @brief Add an event to check if the parameter value is part of the provided
  2812. * integer array.
  2813. *
  2814. * The event is triggered by calling check_expected() in the mocked function.
  2815. *
  2816. * @param[in] #function The function to add the check for.
  2817. *
  2818. * @param[in] #parameter The name of the parameter passed to the function.
  2819. *
  2820. * @param[in] value_array[] The array to check for the value.
  2821. *
  2822. * @see check_expected().
  2823. */
  2824. void expect_in_set(#function, #parameter, intmax_t value_array[]);
  2825. #else
  2826. #define expect_int_in_set(function, parameter, value_array) \
  2827. expect_int_in_set_count(function, parameter, value_array, 1)
  2828. #endif
  2829. #ifdef DOXYGEN
  2830. /**
  2831. * @brief Add an event to check if the parameter value is part of the provided
  2832. * unsigned integer array.
  2833. *
  2834. * The event is triggered by calling check_expected() in the mocked function.
  2835. *
  2836. * @param[in] #function The function to add the check for.
  2837. *
  2838. * @param[in] #parameter The name of the parameter passed to the function.
  2839. *
  2840. * @param[in] value_array[] The array to check for the value.
  2841. *
  2842. * @see check_expected().
  2843. */
  2844. void expect_in_set(#function, #parameter, intmax_t value_array[]);
  2845. #else
  2846. #define expect_uint_in_set(function, parameter, value_array) \
  2847. expect_uint_in_set_count(function, parameter, value_array, 1)
  2848. #endif
  2849. #ifdef DOXYGEN
  2850. /**
  2851. * @deprecated Use expect_int_in_set_count() or expect_uint_in_set_count()
  2852. */
  2853. void expect_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count);
  2854. #else
  2855. #define expect_in_set_count(function, parameter, value_array, count) \
  2856. do { \
  2857. CMOCKA_DEPRECATION_WARNING( \
  2858. "expect_in_set_count: use expect_int_in_set_count or " \
  2859. "expect_uint_in_set_count instead") \
  2860. _expect_uint_in_set(cmocka_tostring(function), \
  2861. cmocka_tostring(parameter), \
  2862. __FILE__, \
  2863. __LINE__, \
  2864. value_array, \
  2865. sizeof(value_array) / sizeof((value_array)[0]), \
  2866. count); \
  2867. } while (0)
  2868. #endif
  2869. #ifdef DOXYGEN
  2870. /**
  2871. * @brief Add an event to check if the parameter value is part of the provided
  2872. * integer array.
  2873. *
  2874. * The event is triggered by calling check_expected() in the mocked function.
  2875. *
  2876. * @param[in] #function The function to add the check for.
  2877. *
  2878. * @param[in] #parameter The name of the parameter passed to the function.
  2879. *
  2880. * @param[in] value_array[] The array to check for the value.
  2881. *
  2882. * @param[in] count The count parameter returns the number of times the value
  2883. * should be returned by check_expected(). If count is set
  2884. * to -1 the value will always be returned.
  2885. *
  2886. * @see check_expected().
  2887. */
  2888. void expect_int_in_set_count(#function, #parameter, intmax_t value_array[], size_t count);
  2889. #else
  2890. #define expect_int_in_set_count(function, parameter, value_array, count) \
  2891. _expect_int_in_set(cmocka_tostring(function), \
  2892. cmocka_tostring(parameter), \
  2893. __FILE__, \
  2894. __LINE__, \
  2895. value_array, \
  2896. sizeof(value_array) / sizeof((value_array)[0]), \
  2897. count)
  2898. #endif
  2899. #ifdef DOXYGEN
  2900. /**
  2901. * @brief Add an event to check if the parameter value is part of the provided
  2902. * unsigned integer array.
  2903. *
  2904. * The event is triggered by calling check_expected() in the mocked function.
  2905. *
  2906. * @param[in] #function The function to add the check for.
  2907. *
  2908. * @param[in] #parameter The name of the parameter passed to the function.
  2909. *
  2910. * @param[in] value_array[] The array to check for the value.
  2911. *
  2912. * @param[in] count The count parameter returns the number of times the value
  2913. * should be returned by check_expected(). If count is set
  2914. * to -1 the value will always be returned.
  2915. *
  2916. * @see check_expected().
  2917. */
  2918. void expect_uint_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count);
  2919. #else
  2920. #define expect_uint_in_set_count(function, parameter, value_array, count) \
  2921. _expect_uint_in_set(cmocka_tostring(function), \
  2922. cmocka_tostring(parameter), \
  2923. __FILE__, \
  2924. __LINE__, \
  2925. value_array, \
  2926. sizeof(value_array) / sizeof((value_array)[0]), \
  2927. count)
  2928. #endif
  2929. #ifdef DOXYGEN
  2930. /**
  2931. * @deprecated Use expect_int_not_in_set() or expect_uint_not_in_set()
  2932. */
  2933. void expect_not_in_set(#function, #parameter, uintmax_t value_array[]);
  2934. #else
  2935. #define expect_not_in_set(function, parameter, value_array) \
  2936. do { \
  2937. CMOCKA_DEPRECATION_WARNING( \
  2938. "expect_not_in_set: use expect_int_not_in_set or " \
  2939. "expect_uint_not_in_set instead") \
  2940. expect_not_in_set_count(function, parameter, value_array, 1); \
  2941. } while (0)
  2942. #endif
  2943. #ifdef DOXYGEN
  2944. /**
  2945. * @deprecated Use expect_int_not_in_set_count() or expect_uint_not_in_set_count()
  2946. */
  2947. void expect_not_in_set_count(#function, #parameter, uintmax_t value_array[], size_t count);
  2948. #else
  2949. #define expect_not_in_set_count(function, parameter, value_array, count) \
  2950. do { \
  2951. CMOCKA_DEPRECATION_WARNING( \
  2952. "expect_not_in_set_count: use expect_int_not_in_set_count or " \
  2953. "expect_uint_not_in_set_count instead") \
  2954. _expect_not_in_set(cmocka_tostring(function), \
  2955. cmocka_tostring(parameter), \
  2956. __FILE__, \
  2957. __LINE__, \
  2958. value_array, \
  2959. sizeof(value_array) / sizeof((value_array)[0]), \
  2960. count); \
  2961. } while (0)
  2962. #endif
  2963. #ifdef DOXYGEN
  2964. /**
  2965. * @brief Add an event to check if the integer parameter value is not part of
  2966. * the provided integer array.
  2967. *
  2968. * The event is triggered by calling check_expected() in the mocked function.
  2969. *
  2970. * @param[in] #function The function to add the check for.
  2971. *
  2972. * @param[in] #parameter The name of the parameter passed to the function.
  2973. *
  2974. * @param[in] value_array[] The array to check for the value.
  2975. *
  2976. * @see check_expected().
  2977. */
  2978. void expect_int_not_in_set(#function, #parameter, intmax_t value_array[]);
  2979. #else
  2980. #define expect_int_not_in_set(function, parameter, value_array) \
  2981. expect_int_not_in_set_count(function, parameter, value_array, 1)
  2982. #endif
  2983. #ifdef DOXYGEN
  2984. /**
  2985. * @brief Add an event to check if the integer parameter value is not part of
  2986. * the provided integer array.
  2987. *
  2988. * The event is triggered by calling check_expected() in the mocked function.
  2989. *
  2990. * @param[in] #function The function to add the check for.
  2991. *
  2992. * @param[in] #parameter The name of the parameter passed to the function.
  2993. *
  2994. * @param[in] value_array[] The array to check for the value.
  2995. *
  2996. * @param[in] count The count parameter returns the number of times the value
  2997. * should be returned by check_expected(). If count is set
  2998. * to -1 the value will always be returned.
  2999. *
  3000. * @see check_expected().
  3001. */
  3002. void expect_int_not_in_set_count(#function,
  3003. #parameter,
  3004. intmax_t value_array[],
  3005. size_t count);
  3006. #else
  3007. #define expect_int_not_in_set_count(function, parameter, value_array, count) \
  3008. _expect_int_not_in_set(cmocka_tostring(function), \
  3009. cmocka_tostring(parameter), \
  3010. __FILE__, \
  3011. __LINE__, \
  3012. value_array, \
  3013. sizeof(value_array) / sizeof((value_array)[0]), \
  3014. count)
  3015. #endif
  3016. #ifdef DOXYGEN
  3017. /**
  3018. * @brief Add an event to check if the unsigned integer parameter value is not
  3019. * part of the provided unsigned integer array.
  3020. *
  3021. * The event is triggered by calling check_expected() in the mocked function.
  3022. *
  3023. * @param[in] #function The function to add the check for.
  3024. *
  3025. * @param[in] #parameter The name of the parameter passed to the function.
  3026. *
  3027. * @param[in] value_array[] The array to check for the value.
  3028. *
  3029. * @see check_expected().
  3030. */
  3031. void expect_uint_not_in_set(#function, #parameter, uintmax_t value_array[]);
  3032. #else
  3033. #define expect_uint_not_in_set(function, parameter, value_array) \
  3034. expect_uint_not_in_set_count(function, parameter, value_array, 1)
  3035. #endif
  3036. #ifdef DOXYGEN
  3037. /**
  3038. * @brief Add an event to check if the unsigned integer parameter value is not
  3039. * part of the provided unsigned integer array.
  3040. *
  3041. * The event is triggered by calling check_expected() in the mocked function.
  3042. *
  3043. * @param[in] #function The function to add the check for.
  3044. *
  3045. * @param[in] #parameter The name of the parameter passed to the function.
  3046. *
  3047. * @param[in] value_array[] The array to check for the value.
  3048. *
  3049. * @param[in] count The count parameter returns the number of times the value
  3050. * should be returned by check_expected(). If count is set
  3051. * to -1 the value will always be returned.
  3052. *
  3053. * @see check_expected().
  3054. */
  3055. void expect_uint_not_in_set_count(#function,
  3056. #parameter,
  3057. uintmax_t value_array[],
  3058. size_t count);
  3059. #else
  3060. #define expect_uint_not_in_set_count(function, parameter, value_array, count) \
  3061. _expect_uint_not_in_set(cmocka_tostring(function), \
  3062. cmocka_tostring(parameter), \
  3063. __FILE__, \
  3064. __LINE__, \
  3065. value_array, \
  3066. sizeof(value_array) / sizeof((value_array)[0]), \
  3067. count)
  3068. #endif
  3069. #ifdef DOXYGEN
  3070. /**
  3071. * @brief Add an event to check if the float parameter value is part of the
  3072. * provided array.
  3073. *
  3074. * The event is triggered by calling check_expected_float() in the mocked function.
  3075. *
  3076. * @param[in] #function The function to add the check for.
  3077. *
  3078. * @param[in] #parameter The name of the parameter passed to the function.
  3079. *
  3080. * @param[in] epsilon The epsilon used as margin for float comparison.
  3081. *
  3082. * @param[in] value_array[] The array to check for the value.
  3083. *
  3084. * @see check_expected_float().
  3085. */
  3086. void expect_float_in_set(#function, #parameter, double value_array[], double epsilon);
  3087. #else
  3088. #define expect_float_in_set(function, parameter, value_array, epsilon) \
  3089. expect_float_in_set_count(function, parameter, value_array, epsilon, 1)
  3090. #endif
  3091. #ifdef DOXYGEN
  3092. /**
  3093. * @brief Add an event to check if the float parameter value is part of the
  3094. * provided integer array.
  3095. *
  3096. * The event is triggered by calling check_expected_float() in the mocked function.
  3097. *
  3098. * @param[in] #function The function to add the check for.
  3099. *
  3100. * @param[in] #parameter The name of the parameter passed to the function.
  3101. *
  3102. * @param[in] value_array[] The array to check for the value.
  3103. *
  3104. * @param[in] epsilon The epsilon used as margin for float comparison.
  3105. *
  3106. * @param[in] count The count parameter returns the number of times the value
  3107. * should be returned by check_expected(). If count is set
  3108. * to -1 the value will always be returned.
  3109. *
  3110. * @see check_expected_float().
  3111. */
  3112. void expect_float_in_set_count(#function, #parameter, double value_array[], double epsilon, size_t count);
  3113. #else
  3114. #define expect_float_in_set_count(function, parameter, value_array, epsilon, count) \
  3115. _expect_float_in_set(cmocka_tostring(function), \
  3116. cmocka_tostring(parameter), \
  3117. __FILE__, \
  3118. __LINE__, \
  3119. value_array, \
  3120. sizeof(value_array) / sizeof((value_array)[0]), \
  3121. epsilon, \
  3122. count)
  3123. #endif
  3124. #ifdef DOXYGEN
  3125. /**
  3126. * @brief Add an event to check if the float parameter value is not part of the
  3127. * provided array.
  3128. *
  3129. * The event is triggered by calling check_expected_float() in the mocked function.
  3130. *
  3131. * @param[in] #function The function to add the check for.
  3132. *
  3133. * @param[in] #parameter The name of the parameter passed to the function.
  3134. *
  3135. * @param[in] epsilon The epsilon used as margin for float comparison.
  3136. *
  3137. * @param[in] value_array[] The array to check for the value.
  3138. *
  3139. * @see check_expected_float().
  3140. */
  3141. void expect_float_not_in_set(#function, #parameter, double value_array[], double epsilon);
  3142. #else
  3143. #define expect_float_not_in_set(function, parameter, value_array, epsilon) \
  3144. expect_float_not_in_set_count(function, parameter, value_array, epsilon, 1)
  3145. #endif
  3146. #ifdef DOXYGEN
  3147. /**
  3148. * @brief Add an event to check if the float parameter value is not part of the
  3149. * provided integer array.
  3150. *
  3151. * The event is triggered by calling check_expected_float() in the mocked function.
  3152. *
  3153. * @param[in] #function The function to add the check for.
  3154. *
  3155. * @param[in] #parameter The name of the parameter passed to the function.
  3156. *
  3157. * @param[in] value_array[] The array to check for the value.
  3158. *
  3159. * @param[in] epsilon The epsilon used as margin for float comparison.
  3160. *
  3161. * @param[in] count The count parameter returns the number of times the value
  3162. * should be returned by check_expected(). If count is set
  3163. * to -1 the value will always be returned.
  3164. *
  3165. * @see check_expected_float().
  3166. */
  3167. void expect_float_not_in_set_count(#function, #parameter, double value_array[], double epsilon, size_t count);
  3168. #else
  3169. #define expect_float_not_in_set_count(function, parameter, value_array, epsilon, count) \
  3170. _expect_float_not_in_set(cmocka_tostring(function), \
  3171. cmocka_tostring(parameter), \
  3172. __FILE__, \
  3173. __LINE__, \
  3174. value_array, \
  3175. sizeof(value_array) / sizeof((value_array)[0]), \
  3176. epsilon, \
  3177. count)
  3178. #endif
  3179. #ifdef DOXYGEN
  3180. /**
  3181. * @deprecated Use expect_int_in_range()
  3182. */
  3183. void expect_in_range(#function, #parameter, uintmax_t minimum, uintmax_t maximum);
  3184. #else
  3185. #define expect_in_range(function, parameter, minimum, maximum) \
  3186. do { \
  3187. CMOCKA_DEPRECATION_WARNING( \
  3188. "expect_in_range: use expect_int_in_range or " \
  3189. "expect_uint_in_range instead") \
  3190. expect_in_range_count(function, parameter, minimum, maximum, 1); \
  3191. } while (0)
  3192. #endif
  3193. #ifdef DOXYGEN
  3194. /**
  3195. * @deprecated Use expect_int_in_range_count()
  3196. */
  3197. void expect_in_range_count(#function, #parameter, uintmax_t minimum, uintmax_t maximum, size_t count);
  3198. #else
  3199. #define expect_in_range_count(function, parameter, minimum, maximum, count) \
  3200. do { \
  3201. CMOCKA_DEPRECATION_WARNING( \
  3202. "expect_in_range_count: use expect_int_in_range_count or " \
  3203. "expect_uint_in_range_count instead") \
  3204. _expect_in_range(cmocka_tostring(function), \
  3205. cmocka_tostring(parameter), \
  3206. __FILE__, \
  3207. __LINE__, \
  3208. minimum, \
  3209. maximum, \
  3210. count); \
  3211. } while (0)
  3212. #endif
  3213. #ifdef DOXYGEN
  3214. /**
  3215. * @brief Add an event to check an integer parameter is inside a numerical
  3216. * range. The check would succeed if minimum <= value <= maximum.
  3217. *
  3218. * The event is triggered by calling check_expected() in the mocked function.
  3219. *
  3220. * @param[in] #function The function to add the check for.
  3221. *
  3222. * @param[in] #parameter The name of the parameter passed to the function.
  3223. *
  3224. * @param[in] minimum The lower boundary of the interval to check against.
  3225. *
  3226. * @param[in] maximum The upper boundary of the interval to check against.
  3227. *
  3228. * @see check_expected().
  3229. */
  3230. void expect_int_in_range(#function,
  3231. #parameter,
  3232. intmax_t minimum,
  3233. intmax_t maximum);
  3234. #else
  3235. #define expect_int_in_range(function, parameter, minimum, maximum) \
  3236. expect_int_in_range_count(function, parameter, minimum, maximum, 1)
  3237. #endif
  3238. #ifdef DOXYGEN
  3239. /**
  3240. * @brief Add an event to repeatedly check an integer parameter is inside a
  3241. * numerical range. The check would succeed if minimum <= value <= maximum.
  3242. *
  3243. * The event is triggered by calling check_expected() in the mocked function.
  3244. *
  3245. * @param[in] #function The function to add the check for.
  3246. *
  3247. * @param[in] #parameter The name of the parameter passed to the function.
  3248. *
  3249. * @param[in] minimum The lower boundary of the interval to check against.
  3250. *
  3251. * @param[in] maximum The upper boundary of the interval to check against.
  3252. *
  3253. * @param[in] count The count parameter returns the number of times the value
  3254. * should be returned by check_expected(). If count is set
  3255. * to -1 the value will always be returned.
  3256. *
  3257. * @see check_expected().
  3258. */
  3259. void expect_int_in_range_count(#function,
  3260. #parameter,
  3261. intmax_t minimum,
  3262. intmax_t maximum,
  3263. size_t count);
  3264. #else
  3265. #define expect_int_in_range_count( \
  3266. function, parameter, minimum, maximum, count) \
  3267. _expect_int_in_range(cmocka_tostring(function), \
  3268. cmocka_tostring(parameter), \
  3269. __FILE__, \
  3270. __LINE__, \
  3271. minimum, \
  3272. maximum, \
  3273. count)
  3274. #endif
  3275. #ifdef DOXYGEN
  3276. /**
  3277. * @brief Add an event to check an unsigned integer parameter is inside a
  3278. * numerical range. The check would succeed if minimum <= value <= maximum.
  3279. *
  3280. * The event is triggered by calling check_expected() in the mocked function.
  3281. *
  3282. * @param[in] #function The function to add the check for.
  3283. *
  3284. * @param[in] #parameter The name of the parameter passed to the function.
  3285. *
  3286. * @param[in] minimum The lower boundary of the interval to check against.
  3287. *
  3288. * @param[in] maximum The upper boundary of the interval to check against.
  3289. *
  3290. * @see check_expected().
  3291. */
  3292. void expect_uint_in_range(#function,
  3293. #parameter,
  3294. uintmax_t minimum,
  3295. uintmax_t maximum);
  3296. #else
  3297. #define expect_uint_in_range(function, parameter, minimum, maximum) \
  3298. expect_uint_in_range_count(function, parameter, minimum, maximum, 1)
  3299. #endif
  3300. #ifdef DOXYGEN
  3301. /**
  3302. * @brief Add an event to repeatedly check an unsigned integer parameter is
  3303. * inside a numerical range. The check would succeed if minimum <= value <=
  3304. * maximum.
  3305. *
  3306. * The event is triggered by calling check_expected() in the mocked function.
  3307. *
  3308. * @param[in] #function The function to add the check for.
  3309. *
  3310. * @param[in] #parameter The name of the parameter passed to the function.
  3311. *
  3312. * @param[in] minimum The lower boundary of the interval to check against.
  3313. *
  3314. * @param[in] maximum The upper boundary of the interval to check against.
  3315. *
  3316. * @param[in] count The count parameter returns the number of times the value
  3317. * should be returned by check_expected(). If count is set
  3318. * to -1 the value will always be returned.
  3319. *
  3320. * @see check_expected().
  3321. */
  3322. void expect_uint_in_range_count(#function,
  3323. #parameter,
  3324. uintmax_t minimum,
  3325. uintmax_t maximum,
  3326. size_t count);
  3327. #else
  3328. #define expect_uint_in_range_count( \
  3329. function, parameter, minimum, maximum, count) \
  3330. _expect_uint_in_range(cmocka_tostring(function), \
  3331. cmocka_tostring(parameter), \
  3332. __FILE__, \
  3333. __LINE__, \
  3334. minimum, \
  3335. maximum, \
  3336. count)
  3337. #endif
  3338. #ifdef DOXYGEN
  3339. /**
  3340. * @brief Add an event to check a parameter is outside a numerical range.
  3341. * The check would succeed if minimum > value > maximum.
  3342. *
  3343. * The event is triggered by calling check_expected() in the mocked function.
  3344. *
  3345. * @param[in] #function The function to add the check for.
  3346. *
  3347. * @param[in] #parameter The name of the parameter passed to the function.
  3348. *
  3349. * @param[in] minimum The lower boundary of the interval to check against.
  3350. *
  3351. * @param[in] maximum The upper boundary of the interval to check against.
  3352. *
  3353. * @see check_expected().
  3354. */
  3355. void expect_not_in_range(#function, #parameter, uintmax_t minimum, uintmax_t maximum);
  3356. #else
  3357. #define expect_not_in_range(function, parameter, minimum, maximum) \
  3358. expect_not_in_range_count(function, parameter, minimum, maximum, 1)
  3359. #endif
  3360. #ifdef DOXYGEN
  3361. /**
  3362. * @brief Add an event to repeatedly check a parameter is outside a
  3363. * numerical range. The check would succeed if minimum > value > maximum.
  3364. *
  3365. * The event is triggered by calling check_expected() in the mocked function.
  3366. *
  3367. * @param[in] #function The function to add the check for.
  3368. *
  3369. * @param[in] #parameter The name of the parameter passed to the function.
  3370. *
  3371. * @param[in] minimum The lower boundary of the interval to check against.
  3372. *
  3373. * @param[in] maximum The upper boundary of the interval to check against.
  3374. *
  3375. * @param[in] count The count parameter returns the number of times the value
  3376. * should be returned by check_expected(). If count is set
  3377. * to -1 the value will always be returned.
  3378. *
  3379. * @see check_expected().
  3380. */
  3381. void expect_not_in_range_count(#function, #parameter, uintmax_t minimum, uintmax_t maximum, size_t count);
  3382. #else
  3383. #define expect_not_in_range_count(function, parameter, minimum, maximum, \
  3384. count) \
  3385. _expect_not_in_range(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
  3386. minimum, maximum, count)
  3387. #endif
  3388. #ifdef DOXYGEN
  3389. /**
  3390. * @brief Add an event to check an integer parameter is outside a numerical
  3391. * range. The check would succeed if minimum > value > maximum.
  3392. *
  3393. * The event is triggered by calling check_expected() in the mocked function.
  3394. *
  3395. * @param[in] #function The function to add the check for.
  3396. *
  3397. * @param[in] #parameter The name of the parameter passed to the function.
  3398. *
  3399. * @param[in] minimum The lower boundary of the interval to check against.
  3400. *
  3401. * @param[in] maximum The upper boundary of the interval to check against.
  3402. *
  3403. * @see check_expected().
  3404. */
  3405. void expect_int_not_in_range(#function,
  3406. #parameter,
  3407. intmax_t minimum,
  3408. intmax_t maximum);
  3409. #else
  3410. #define expect_int_not_in_range(function, parameter, minimum, maximum) \
  3411. expect_int_not_in_range_count(function, parameter, minimum, maximum, 1)
  3412. #endif
  3413. #ifdef DOXYGEN
  3414. /**
  3415. * @brief Add an event to repeatedly check an integer parameter is outside a
  3416. * numerical range. The check would succeed if minimum > value > maximum.
  3417. *
  3418. * The event is triggered by calling check_expected() in the mocked function.
  3419. *
  3420. * @param[in] #function The function to add the check for.
  3421. *
  3422. * @param[in] #parameter The name of the parameter passed to the function.
  3423. *
  3424. * @param[in] minimum The lower boundary of the interval to check against.
  3425. *
  3426. * @param[in] maximum The upper boundary of the interval to check against.
  3427. *
  3428. * @param[in] count The count parameter returns the number of times the value
  3429. * should be returned by check_expected(). If count is set
  3430. * to -1 the value will always be returned.
  3431. *
  3432. * @see check_expected().
  3433. */
  3434. void expect_int_not_in_range_count(#function,
  3435. #parameter,
  3436. intmax_t minimum,
  3437. intmax_t maximum,
  3438. size_t count);
  3439. #else
  3440. #define expect_int_not_in_range_count( \
  3441. function, parameter, minimum, maximum, count) \
  3442. _expect_int_not_in_range(cmocka_tostring(function), \
  3443. cmocka_tostring(parameter), \
  3444. __FILE__, \
  3445. __LINE__, \
  3446. minimum, \
  3447. maximum, \
  3448. count)
  3449. #endif
  3450. #ifdef DOXYGEN
  3451. /**
  3452. * @brief Add an event to check an unsigned integer parameter is outside a
  3453. * numerical range. The check would succeed if minimum > value > maximum.
  3454. *
  3455. * The event is triggered by calling check_expected() in the mocked function.
  3456. *
  3457. * @param[in] #function The function to add the check for.
  3458. *
  3459. * @param[in] #parameter The name of the parameter passed to the function.
  3460. *
  3461. * @param[in] minimum The lower boundary of the interval to check against.
  3462. *
  3463. * @param[in] maximum The upper boundary of the interval to check against.
  3464. *
  3465. * @see check_expected().
  3466. */
  3467. void expect_uint_not_in_range(#function,
  3468. #parameter,
  3469. uintmax_t minimum,
  3470. uintmax_t maximum);
  3471. #else
  3472. #define expect_uint_not_in_range(function, parameter, minimum, maximum) \
  3473. expect_uint_not_in_range_count(function, parameter, minimum, maximum, 1)
  3474. #endif
  3475. #ifdef DOXYGEN
  3476. /**
  3477. * @brief Add an event to repeatedly check an unsigned integer parameter is
  3478. * outside a numerical range. The check would succeed if minimum > value >
  3479. * maximum.
  3480. *
  3481. * The event is triggered by calling check_expected() in the mocked function.
  3482. *
  3483. * @param[in] #function The function to add the check for.
  3484. *
  3485. * @param[in] #parameter The name of the parameter passed to the function.
  3486. *
  3487. * @param[in] minimum The lower boundary of the interval to check against.
  3488. *
  3489. * @param[in] maximum The upper boundary of the interval to check against.
  3490. *
  3491. * @param[in] count The count parameter returns the number of times the value
  3492. * should be returned by check_expected(). If count is set
  3493. * to -1 the value will always be returned.
  3494. *
  3495. * @see check_expected().
  3496. */
  3497. void expect_uint_not_in_range_count(#function,
  3498. #parameter,
  3499. uintmax_t minimum,
  3500. uintmax_t maximum,
  3501. size_t count);
  3502. #else
  3503. #define expect_uint_not_in_range_count( \
  3504. function, parameter, minimum, maximum, count) \
  3505. _expect_uint_not_in_range(cmocka_tostring(function), \
  3506. cmocka_tostring(parameter), \
  3507. __FILE__, \
  3508. __LINE__, \
  3509. minimum, \
  3510. maximum, \
  3511. count)
  3512. #endif
  3513. #ifdef DOXYGEN
  3514. /**
  3515. * @brief Add an event to check a parameter is inside a numerical range.
  3516. * The check would succeed if minimum <= value <= maximum.
  3517. *
  3518. * The event is triggered by calling check_expected_float() in the mocked function.
  3519. *
  3520. * @param[in] #function The function to add the check for.
  3521. *
  3522. * @param[in] #parameter The name of the parameter passed to the function.
  3523. *
  3524. * @param[in] minimum The lower boundary of the interval to check against.
  3525. *
  3526. * @param[in] maximum The upper boundary of the interval to check against.
  3527. *
  3528. * @param[in] epsilon The epsilon used as margin for float comparison.
  3529. *
  3530. * @see check_expected_float().
  3531. */
  3532. void expect_float_in_range(#function, #parameter, double minimum, double maximum, double epsilon);
  3533. #else
  3534. #define expect_float_in_range(function, parameter, minimum, maximum, epsilon) \
  3535. expect_float_in_range_count(function, parameter, minimum, maximum, epsilon, 1)
  3536. #endif
  3537. #ifdef DOXYGEN
  3538. /**
  3539. * @brief Add an event to repeatedly check a parameter is inside a
  3540. * numerical range. The check would succeed if minimum <= value <= maximum.
  3541. *
  3542. * The event is triggered by calling check_expected_float() in the mocked function.
  3543. *
  3544. * @param[in] #function The function to add the check for.
  3545. *
  3546. * @param[in] #parameter The name of the parameter passed to the function.
  3547. *
  3548. * @param[in] minimum The lower boundary of the interval to check against.
  3549. *
  3550. * @param[in] maximum The upper boundary of the interval to check against.
  3551. *
  3552. * @param[in] epsilon The epsilon used as margin for float comparison.
  3553. *
  3554. * @param[in] count The count parameter returns the number of times the value
  3555. * should be returned by check_expected(). If count is set
  3556. * to -1 the value will always be returned.
  3557. *
  3558. * @see check_expected_float()
  3559. */
  3560. void expect_float_in_range_count(#function, #parameter, double minimum, double maximum, double epsilon, size_t count);
  3561. #else
  3562. #define expect_float_in_range_count(function, parameter, minimum, maximum, epsilon, count) \
  3563. _expect_float_in_range(cmocka_tostring(function), \
  3564. cmocka_tostring(parameter), \
  3565. __FILE__, \
  3566. __LINE__, \
  3567. cast_to_double_type(minimum), \
  3568. cast_to_double_type(maximum), \
  3569. cast_to_double_type(epsilon), \
  3570. count)
  3571. #endif
  3572. #ifdef DOXYGEN
  3573. /**
  3574. * @brief Add an event to check a parameter is outside a numerical range.
  3575. * The check would succeed if minimum > value > maximum.
  3576. *
  3577. * The event is triggered by calling check_expected() in the mocked function.
  3578. *
  3579. * @param[in] #function The function to add the check for.
  3580. *
  3581. * @param[in] #parameter The name of the parameter passed to the function.
  3582. *
  3583. * @param[in] minimum The lower boundary of the interval to check against.
  3584. *
  3585. * @param[in] maximum The upper boundary of the interval to check against.
  3586. *
  3587. * @param[in] epsilon The epsilon used as margin for float comparison.
  3588. *
  3589. * @see check_expected().
  3590. */
  3591. void expect_float_not_in_range(#function, #parameter, double minimum, double maximum, double epsilon);
  3592. #else
  3593. #define expect_float_not_in_range(function, parameter, minimum, maximum, epsilon) \
  3594. expect_float_not_in_range_count(function, parameter, minimum, maximum, epsilon, 1)
  3595. #endif
  3596. #ifdef DOXYGEN
  3597. /**
  3598. * @brief Add an event to repeatedly check a parameter is outside a
  3599. * numerical range. The check would succeed if minimum > value > maximum.
  3600. *
  3601. * The event is triggered by calling check_expected() in the mocked function.
  3602. *
  3603. * @param[in] #function The function to add the check for.
  3604. *
  3605. * @param[in] #parameter The name of the parameter passed to the function.
  3606. *
  3607. * @param[in] minimum The lower boundary of the interval to check against.
  3608. *
  3609. * @param[in] maximum The upper boundary of the interval to check against.
  3610. *
  3611. * @param[in] epsilon The epsilon used as margin for float comparison.
  3612. *
  3613. * @param[in] count The count parameter returns the number of times the value
  3614. * should be returned by check_expected(). If count is set
  3615. * to -1 the value will always be returned.
  3616. *
  3617. * @see check_expected().
  3618. */
  3619. void expect_float_not_in_range_count(#function, #parameter, double minimum, double maximum, double epsilon, size_t count);
  3620. #else
  3621. #define expect_float_not_in_range_count(function, parameter, minimum, maximum, \
  3622. epsilon, count) \
  3623. _expect_float_not_in_range(cmocka_tostring(function), \
  3624. cmocka_tostring(parameter), \
  3625. __FILE__, \
  3626. __LINE__, \
  3627. cast_to_double_type(minimum), \
  3628. cast_to_double_type(maximum), \
  3629. cast_to_double_type(epsilon), \
  3630. count)
  3631. #endif
  3632. #ifdef DOXYGEN
  3633. /**
  3634. * @deprecated Use expect_int_value() or expect_uint_value()
  3635. */
  3636. void expect_value(#function, #parameter, uintmax_t value);
  3637. #else
  3638. #define expect_value(function, parameter, value) \
  3639. do { \
  3640. CMOCKA_DEPRECATION_WARNING("expect_value: use expect_int_value or " \
  3641. "expect_uint_value instead") \
  3642. expect_value_count(function, parameter, value, 1); \
  3643. } while (0)
  3644. #endif
  3645. #ifdef DOXYGEN
  3646. /**
  3647. * @deprecated Use expect_int_value_count() or expect_uint_value_count()
  3648. */
  3649. void expect_value_count(#function, #parameter, uintmax_t value, size_t count);
  3650. #else
  3651. #define expect_value_count(function, parameter, value, count) \
  3652. do { \
  3653. CMOCKA_DEPRECATION_WARNING( \
  3654. "expect_value_count: use expect_int_value_count or " \
  3655. "expect_uint_value_count instead") \
  3656. _expect_value(cmocka_tostring(function), \
  3657. cmocka_tostring(parameter), \
  3658. __FILE__, \
  3659. __LINE__, \
  3660. cast_to_uintmax_type(value), \
  3661. count); \
  3662. } while (0)
  3663. #endif
  3664. #ifdef DOXYGEN
  3665. /**
  3666. * @brief Add an event to check if an integer parameter is the given value.
  3667. *
  3668. * The event is triggered by calling check_expected() in the mocked function.
  3669. *
  3670. * @param[in] #function The function to add the check for.
  3671. *
  3672. * @param[in] #parameter The name of the parameter passed to the function.
  3673. *
  3674. * @param[in] value The value to check.
  3675. *
  3676. * @see check_expected().
  3677. */
  3678. void expect_int_value(#function, #parameter, intmax_t value);
  3679. #else
  3680. #define expect_int_value(function, parameter, value) \
  3681. expect_int_value_count(function, parameter, value, 1)
  3682. #endif
  3683. #ifdef DOXYGEN
  3684. /**
  3685. * @brief Add an event to repeatedly check if an integer parameter is the
  3686. * given value.
  3687. *
  3688. * The event is triggered by calling check_expected() in the mocked function.
  3689. *
  3690. * @param[in] #function The function to add the check for.
  3691. *
  3692. * @param[in] #parameter The name of the parameter passed to the function.
  3693. *
  3694. * @param[in] value The value to check.
  3695. *
  3696. * @param[in] count The count parameter returns the number of times the value
  3697. * should be returned by check_expected(). If count is set
  3698. * to -1 the value will always be returned.
  3699. *
  3700. * @see check_expected().
  3701. */
  3702. void expect_int_value_count(#function,
  3703. #parameter,
  3704. intmax_t value,
  3705. size_t count);
  3706. #else
  3707. #define expect_int_value_count(function, parameter, value, count) \
  3708. _expect_int_value(cmocka_tostring(function), \
  3709. cmocka_tostring(parameter), \
  3710. __FILE__, \
  3711. __LINE__, \
  3712. value, \
  3713. count)
  3714. #endif
  3715. #ifdef DOXYGEN
  3716. /**
  3717. * @brief Add an event to check if an unsigned integer parameter is the given
  3718. * value.
  3719. *
  3720. * The event is triggered by calling check_expected() in the mocked function.
  3721. *
  3722. * @param[in] #function The function to add the check for.
  3723. *
  3724. * @param[in] #parameter The name of the parameter passed to the function.
  3725. *
  3726. * @param[in] value The value to check.
  3727. *
  3728. * @see check_expected().
  3729. */
  3730. void expect_uint_value(#function, #parameter, uintmax_t value);
  3731. #else
  3732. #define expect_uint_value(function, parameter, value) \
  3733. expect_uint_value_count(function, parameter, value, 1)
  3734. #endif
  3735. #ifdef DOXYGEN
  3736. /**
  3737. * @brief Add an event to repeatedly check if an unsigned integer parameter is
  3738. * the given value.
  3739. *
  3740. * The event is triggered by calling check_expected() in the mocked function.
  3741. *
  3742. * @param[in] #function The function to add the check for.
  3743. *
  3744. * @param[in] #parameter The name of the parameter passed to the function.
  3745. *
  3746. * @param[in] value The value to check.
  3747. *
  3748. * @param[in] count The count parameter returns the number of times the value
  3749. * should be returned by check_expected(). If count is set
  3750. * to -1 the value will always be returned.
  3751. *
  3752. * @see check_expected().
  3753. */
  3754. void expect_uint_value_count(#function,
  3755. #parameter,
  3756. uintmax_t value,
  3757. size_t count);
  3758. #else
  3759. #define expect_uint_value_count(function, parameter, value, count) \
  3760. _expect_uint_value(cmocka_tostring(function), \
  3761. cmocka_tostring(parameter), \
  3762. __FILE__, \
  3763. __LINE__, \
  3764. value, \
  3765. count)
  3766. #endif
  3767. #ifdef DOXYGEN
  3768. /**
  3769. * @brief Add an event to check if a parameter (int) isn't the given value.
  3770. *
  3771. * The event is triggered by calling check_expected() in the mocked function.
  3772. *
  3773. * @param[in] #function The function to add the check for.
  3774. *
  3775. * @param[in] #parameter The name of the parameter passed to the function.
  3776. *
  3777. * @param[in] value The value (intmax_t) to check.
  3778. *
  3779. * @see check_expected().
  3780. */
  3781. void expect_int_not_value(#function, #parameter, intmax_t value);
  3782. #else
  3783. #define expect_int_not_value(function, parameter, value) \
  3784. expect_int_not_value_count(function, parameter, value, 1)
  3785. #endif
  3786. #ifdef DOXYGEN
  3787. /**
  3788. * @brief Add an event to repeatedly check if a parameter (int) isn't the given
  3789. * value.
  3790. *
  3791. * The event is triggered by calling check_expected() in the mocked function.
  3792. *
  3793. * @param[in] #function The function to add the check for.
  3794. *
  3795. * @param[in] #parameter The name of the parameter passed to the function.
  3796. *
  3797. * @param[in] value The value (intmax_t) to check.
  3798. *
  3799. * @param[in] count The count parameter returns the number of times the value
  3800. * should be returned by check_expected(). If count is set
  3801. * to -1 the value will always be returned.
  3802. *
  3803. * @see check_expected().
  3804. */
  3805. void expect_int_not_value_count(#function,
  3806. #parameter,
  3807. intmax_t value,
  3808. size_t count);
  3809. #else
  3810. #define expect_int_not_value_count(function, parameter, value, count) \
  3811. _expect_int_not_value(cmocka_tostring(function), \
  3812. cmocka_tostring(parameter), \
  3813. __FILE__, \
  3814. __LINE__, \
  3815. value, \
  3816. count)
  3817. #endif
  3818. #ifdef DOXYGEN
  3819. /**
  3820. * @brief Add an event to check if a parameter (uint) isn't the given value.
  3821. *
  3822. * The event is triggered by calling check_expected() in the mocked function.
  3823. *
  3824. * @param[in] #function The function to add the check for.
  3825. *
  3826. * @param[in] #parameter The name of the parameter passed to the function.
  3827. *
  3828. * @param[in] value The value (uintmax_t) to check.
  3829. *
  3830. * @see check_expected().
  3831. */
  3832. void expect_uint_not_value(#function, #parameter, uintmax_t value);
  3833. #else
  3834. #define expect_uint_not_value(function, parameter, value) \
  3835. expect_uint_not_value_count(function, parameter, value, 1)
  3836. #endif
  3837. #ifdef DOXYGEN
  3838. /**
  3839. * @brief Add an event to repeatedly check if a parameter (uint) isn't the given
  3840. * value.
  3841. *
  3842. * The event is triggered by calling check_expected() in the mocked function.
  3843. *
  3844. * @param[in] #function The function to add the check for.
  3845. *
  3846. * @param[in] #parameter The name of the parameter passed to the function.
  3847. *
  3848. * @param[in] value The value (uintmax_t) to check.
  3849. *
  3850. * @param[in] count The count parameter returns the number of times the value
  3851. * should be returned by check_expected(). If count is set
  3852. * to -1 the value will always be returned.
  3853. *
  3854. * @see check_expected().
  3855. */
  3856. void expect_uint_not_value_count(#function,
  3857. #parameter,
  3858. uintmax_t value,
  3859. size_t count);
  3860. #else
  3861. #define expect_uint_not_value_count(function, parameter, value, count) \
  3862. _expect_uint_not_value(cmocka_tostring(function), \
  3863. cmocka_tostring(parameter), \
  3864. __FILE__, \
  3865. __LINE__, \
  3866. value, \
  3867. count)
  3868. #endif
  3869. #ifdef DOXYGEN
  3870. /**
  3871. * @deprecated Use expect_int_not_value() or expect_uint_not_value()
  3872. */
  3873. void expect_not_value(#function, #parameter, uintmax_t value);
  3874. #else
  3875. #define expect_not_value(function, parameter, value) \
  3876. do { \
  3877. CMOCKA_DEPRECATION_WARNING( \
  3878. "expect_not_value: use expect_int_not_value or " \
  3879. "expect_uint_not_value instead") \
  3880. expect_not_value_count(function, parameter, value, 1); \
  3881. } while (0)
  3882. #endif
  3883. #ifdef DOXYGEN
  3884. /**
  3885. * @deprecated Use expect_int_not_value_count() or expect_uint_not_value_count()
  3886. */
  3887. void expect_not_value_count(#function, #parameter, uintmax_t value, size_t count);
  3888. #else
  3889. #define expect_not_value_count(function, parameter, value, count) \
  3890. do { \
  3891. CMOCKA_DEPRECATION_WARNING( \
  3892. "expect_not_value_count: use expect_int_not_value_count or " \
  3893. "expect_uint_not_value_count instead") \
  3894. _expect_not_value(cmocka_tostring(function), \
  3895. cmocka_tostring(parameter), \
  3896. __FILE__, \
  3897. __LINE__, \
  3898. cast_to_uintmax_type(value), \
  3899. count); \
  3900. } while (0)
  3901. #endif
  3902. #ifdef DOXYGEN
  3903. /**
  3904. * @brief Add an event to check if a parameter is the given floating point value.
  3905. *
  3906. * The event is triggered by calling check_expected_float() in the mocked function.
  3907. *
  3908. * @param[in] #function The function to add the check for.
  3909. *
  3910. * @param[in] #parameter The name of the parameter passed to the function.
  3911. *
  3912. * @param[in] value The value to check.
  3913. *
  3914. * @param[in] epsilon The epsilon used as margin for float comparison.
  3915. *
  3916. * @see check_expected_float()
  3917. * @see expect_string()
  3918. * @see expect_memory()
  3919. * @see expect_any()
  3920. */
  3921. void expect_float(#function, #parameter, double value, double epsilon);
  3922. #else
  3923. #define expect_float(function, parameter, value, epsilon) \
  3924. expect_float_count(function, parameter, cast_to_double_type(value), \
  3925. cast_to_double_type(epsilon), 1)
  3926. #endif
  3927. #ifdef DOXYGEN
  3928. /**
  3929. * @brief Add an event to repeatedly check if a parameter is the given floating
  3930. * point value.
  3931. *
  3932. * The event is triggered by calling check_expected_float() in the mocked function.
  3933. *
  3934. * @param[in] #function The function to add the check for.
  3935. *
  3936. * @param[in] #parameter The name of the parameter passed to the function.
  3937. *
  3938. * @param[in] value The value to check.
  3939. *
  3940. * @param[in] epsilon The epsilon used as margin for float comparison.
  3941. *
  3942. * @param[in] count The count parameter returns the number of times the value
  3943. * should be returned by check_expected(). If count is set
  3944. * to -1 the value will always be returned.
  3945. *
  3946. * @see check_expected_float().
  3947. * @see expect_not_string()
  3948. * @see expect_not_memory()
  3949. */
  3950. void expect_float_count(#function, #parameter, double value, double epsilon, size_t count);
  3951. #else
  3952. #define expect_float_count(function, parameter, value, epsilon, count) \
  3953. _expect_float(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
  3954. cast_to_double_type(value), cast_to_double_type(epsilon), count)
  3955. #endif
  3956. #ifdef DOXYGEN
  3957. /**
  3958. * @brief Add an event to check if a parameter isn't the given floating point
  3959. * value.
  3960. *
  3961. * The event is triggered by calling check_expected_float() in the mocked function.
  3962. *
  3963. * @param[in] #function The function to add the check for.
  3964. *
  3965. * @param[in] #parameter The name of the parameter passed to the function.
  3966. *
  3967. * @param[in] value The value to check.
  3968. *
  3969. * @param[in] epsilon The epsilon used as margin for float comparison.
  3970. *
  3971. * @see check_expected_float()
  3972. * @see expect_string()
  3973. * @see expect_memory()
  3974. * @see expect_any()
  3975. */
  3976. void expect_not_float(#function, #parameter, double value, double epsilon);
  3977. #else
  3978. #define expect_not_float(function, parameter, value, epsilon) \
  3979. expect_not_float_count(function, \
  3980. parameter, \
  3981. cast_to_float_type(value), \
  3982. cast_to_float_type(epsilon), \
  3983. 1)
  3984. #endif
  3985. #ifdef DOXYGEN
  3986. /**
  3987. * @brief Add an event to repeatedly check if a parameter isn't the floating
  3988. * point value.
  3989. *
  3990. * The event is triggered by calling check_expected_float() in the mocked function.
  3991. *
  3992. * @param[in] #function The function to add the check for.
  3993. *
  3994. * @param[in] #parameter The name of the parameter passed to the function.
  3995. *
  3996. * @param[in] value The value to check.
  3997. *
  3998. * @param[in] epsilon The epsilon used as margin for float comparison.
  3999. *
  4000. * @param[in] count The count parameter returns the number of times the value
  4001. * should be returned by check_expected(). If count is set
  4002. * to -1 the value will always be returned.
  4003. *
  4004. * @see check_expected_float().
  4005. * @see expect_not_string()
  4006. * @see expect_not_memory()
  4007. */
  4008. void expect_not_float_count(#function, #parameter, double value, double epsilon, size_t count);
  4009. #else
  4010. #define expect_not_float_count(function, parameter, value, epsilon, count) \
  4011. _expect_not_float(cmocka_tostring(function), \
  4012. cmocka_tostring(parameter), \
  4013. __FILE__, \
  4014. __LINE__, \
  4015. cast_to_float_type(value), \
  4016. cast_to_float_type(epsilon), \
  4017. count)
  4018. #endif
  4019. #ifdef DOXYGEN
  4020. /**
  4021. * @brief Add an event to check if a parameter is the given double
  4022. * precision floating point value.
  4023. *
  4024. * The event is triggered by calling check_expected_double() in the mocked
  4025. * function.
  4026. *
  4027. * @param[in] #function The function to add the check for.
  4028. *
  4029. * @param[in] #parameter The name of the parameter passed to the function.
  4030. *
  4031. * @param[in] value The value to check.
  4032. *
  4033. * @param[in] epsilon The epsilon used as margin for double comparison.
  4034. *
  4035. * @see check_expected_double()
  4036. */
  4037. void expect_double(#function, #parameter, double value, double epsilon);
  4038. #else
  4039. #define expect_double(function, parameter, value, epsilon) \
  4040. expect_double_count(function, \
  4041. parameter, \
  4042. cast_to_double_type(value), \
  4043. cast_to_double_type(epsilon), \
  4044. 1)
  4045. #endif
  4046. #ifdef DOXYGEN
  4047. /**
  4048. * @brief Add an event to repeatedly check if a parameter is the given double
  4049. * precision floating point value.
  4050. *
  4051. * The event is triggered by calling check_expected_double() in the mocked
  4052. * function.
  4053. *
  4054. * @param[in] #function The function to add the check for.
  4055. *
  4056. * @param[in] #parameter The name of the parameter passed to the function.
  4057. *
  4058. * @param[in] value The value to check.
  4059. *
  4060. * @param[in] epsilon The epsilon used as margin for double comparison.
  4061. *
  4062. * @param[in] count The count parameter returns the number of times the value
  4063. * should be returned by check_expected(). If count is set
  4064. * to -1 the value will always be returned.
  4065. *
  4066. * @see check_expected_double().
  4067. */
  4068. void expect_double_count(#function,
  4069. #parameter,
  4070. double value,
  4071. double epsilon,
  4072. size_t count);
  4073. #else
  4074. #define expect_double_count(function, parameter, value, epsilon, count) \
  4075. _expect_double(cmocka_tostring(function), \
  4076. cmocka_tostring(parameter), \
  4077. __FILE__, \
  4078. __LINE__, \
  4079. cast_to_double_type(value), \
  4080. cast_to_double_type(epsilon), \
  4081. count)
  4082. #endif
  4083. #ifdef DOXYGEN
  4084. /**
  4085. * @brief Add an event to check if a parameter isn't the given double precision
  4086. * floating point value.
  4087. *
  4088. * The event is triggered by calling check_expected_double() in the mocked
  4089. * function.
  4090. *
  4091. * @param[in] #function The function to add the check for.
  4092. *
  4093. * @param[in] #parameter The name of the parameter passed to the function.
  4094. *
  4095. * @param[in] value The value to check.
  4096. *
  4097. * @param[in] epsilon The epsilon used as margin for double comparison.
  4098. *
  4099. * @see check_expected_double()
  4100. */
  4101. void expect_not_double(#function, #parameter, double value, double epsilon);
  4102. #else
  4103. #define expect_not_double(function, parameter, value, epsilon) \
  4104. expect_not_double_count(function, \
  4105. parameter, \
  4106. cast_to_double_type(value), \
  4107. cast_to_double_type(epsilon), \
  4108. 1)
  4109. #endif
  4110. #ifdef DOXYGEN
  4111. /**
  4112. * @brief Add an event to repeatedly check if a parameter isn't the double
  4113. * precision floating point value.
  4114. *
  4115. * The event is triggered by calling check_expected_double() in the mocked
  4116. * function.
  4117. *
  4118. * @param[in] #function The function to add the check for.
  4119. *
  4120. * @param[in] #parameter The name of the parameter passed to the function.
  4121. *
  4122. * @param[in] value The value to check.
  4123. *
  4124. * @param[in] epsilon The epsilon used as margin for double comparison.
  4125. *
  4126. * @param[in] count The count parameter returns the number of times the value
  4127. * should be returned by check_expected(). If count is set
  4128. * to -1 the value will always be returned.
  4129. *
  4130. * @see check_expected_double().
  4131. */
  4132. void expect_not_double_count(#function,
  4133. #parameter,
  4134. double value,
  4135. double epsilon,
  4136. size_t count);
  4137. #else
  4138. #define expect_not_double_count(function, parameter, value, epsilon, count) \
  4139. _expect_not_double(cmocka_tostring(function), \
  4140. cmocka_tostring(parameter), \
  4141. __FILE__, \
  4142. __LINE__, \
  4143. cast_to_double_type(value), \
  4144. cast_to_double_type(epsilon), \
  4145. count)
  4146. #endif
  4147. #ifdef DOXYGEN
  4148. /**
  4149. * @brief Add an event to check if the parameter value is equal to the
  4150. * provided string.
  4151. *
  4152. * The event is triggered by calling check_expected() in the mocked function.
  4153. *
  4154. * @param[in] #function The function to add the check for.
  4155. *
  4156. * @param[in] #parameter The name of the parameter passed to the function.
  4157. *
  4158. * @param[in] string The string value to compare.
  4159. *
  4160. * @see check_expected().
  4161. */
  4162. void expect_string(#function, #parameter, const char *string);
  4163. #else
  4164. #define expect_string(function, parameter, string) \
  4165. expect_string_count(function, parameter, string, 1)
  4166. #endif
  4167. #ifdef DOXYGEN
  4168. /**
  4169. * @brief Add an event to check if the parameter value is equal to the
  4170. * provided string.
  4171. *
  4172. * The event is triggered by calling check_expected() in the mocked function.
  4173. *
  4174. * @param[in] #function The function to add the check for.
  4175. *
  4176. * @param[in] #parameter The name of the parameter passed to the function.
  4177. *
  4178. * @param[in] string The string value to compare.
  4179. *
  4180. * @param[in] count The count parameter returns the number of times the value
  4181. * should be returned by check_expected(). If count is set
  4182. * to -1 the value will always be returned.
  4183. *
  4184. * @see check_expected().
  4185. */
  4186. void expect_string_count(#function, #parameter, const char *string, size_t count);
  4187. #else
  4188. #define expect_string_count(function, parameter, string, count) \
  4189. _expect_string(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
  4190. (const char*)(string), count)
  4191. #endif
  4192. #ifdef DOXYGEN
  4193. /**
  4194. * @brief Add an event to check if the parameter value isn't equal to the
  4195. * provided string.
  4196. *
  4197. * The event is triggered by calling check_expected() in the mocked function.
  4198. *
  4199. * @param[in] #function The function to add the check for.
  4200. *
  4201. * @param[in] #parameter The name of the parameter passed to the function.
  4202. *
  4203. * @param[in] string The string value to compare.
  4204. *
  4205. * @see check_expected().
  4206. */
  4207. void expect_not_string(#function, #parameter, const char *string);
  4208. #else
  4209. #define expect_not_string(function, parameter, string) \
  4210. expect_not_string_count(function, parameter, string, 1)
  4211. #endif
  4212. #ifdef DOXYGEN
  4213. /**
  4214. * @brief Add an event to check if the parameter value isn't equal to the
  4215. * provided string.
  4216. *
  4217. * The event is triggered by calling check_expected() in the mocked function.
  4218. *
  4219. * @param[in] #function The function to add the check for.
  4220. *
  4221. * @param[in] #parameter The name of the parameter passed to the function.
  4222. *
  4223. * @param[in] string The string value to compare.
  4224. *
  4225. * @param[in] count The count parameter returns the number of times the value
  4226. * should be returned by check_expected(). If count is set
  4227. * to -1 the value will always be returned.
  4228. *
  4229. * @see check_expected().
  4230. */
  4231. void expect_not_string_count(#function, #parameter, const char *string, size_t count);
  4232. #else
  4233. #define expect_not_string_count(function, parameter, string, count) \
  4234. _expect_not_string(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
  4235. (const char*)(string), count)
  4236. #endif
  4237. #ifdef DOXYGEN
  4238. /**
  4239. * @brief Add an event to check if the parameter does match an area of memory.
  4240. *
  4241. * The event is triggered by calling check_expected() in the mocked function.
  4242. *
  4243. * @param[in] #function The function to add the check for.
  4244. *
  4245. * @param[in] #parameter The name of the parameter passed to the function.
  4246. *
  4247. * @param[in] memory The memory to compare.
  4248. *
  4249. * @param[in] size The size of the memory to compare.
  4250. *
  4251. * @see check_expected().
  4252. */
  4253. void expect_memory(#function, #parameter, void *memory, size_t size);
  4254. #else
  4255. #define expect_memory(function, parameter, memory, size) \
  4256. expect_memory_count(function, parameter, memory, size, 1)
  4257. #endif
  4258. #ifdef DOXYGEN
  4259. /**
  4260. * @brief Add an event to repeatedly check if the parameter does match an area
  4261. * of memory.
  4262. *
  4263. * The event is triggered by calling check_expected() in the mocked function.
  4264. *
  4265. * @param[in] #function The function to add the check for.
  4266. *
  4267. * @param[in] #parameter The name of the parameter passed to the function.
  4268. *
  4269. * @param[in] memory The memory to compare.
  4270. *
  4271. * @param[in] size The size of the memory to compare.
  4272. *
  4273. * @param[in] count The count parameter returns the number of times the value
  4274. * should be returned by check_expected(). If count is set
  4275. * to -1 the value will always be returned.
  4276. *
  4277. * @see check_expected().
  4278. */
  4279. void expect_memory_count(#function, #parameter, void *memory, size_t size, size_t count);
  4280. #else
  4281. #define expect_memory_count(function, parameter, memory, size, count) \
  4282. _expect_memory(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
  4283. (const void*)(memory), size, count)
  4284. #endif
  4285. #ifdef DOXYGEN
  4286. /**
  4287. * @brief Add an event to check if the parameter doesn't match an area of
  4288. * memory.
  4289. *
  4290. * The event is triggered by calling check_expected() in the mocked function.
  4291. *
  4292. * @param[in] #function The function to add the check for.
  4293. *
  4294. * @param[in] #parameter The name of the parameter passed to the function.
  4295. *
  4296. * @param[in] memory The memory to compare.
  4297. *
  4298. * @param[in] size The size of the memory to compare.
  4299. *
  4300. * @see check_expected().
  4301. */
  4302. void expect_not_memory(#function, #parameter, void *memory, size_t size);
  4303. #else
  4304. #define expect_not_memory(function, parameter, memory, size) \
  4305. expect_not_memory_count(function, parameter, memory, size, 1)
  4306. #endif
  4307. #ifdef DOXYGEN
  4308. /**
  4309. * @brief Add an event to repeatedly check if the parameter doesn't match an
  4310. * area of memory.
  4311. *
  4312. * The event is triggered by calling check_expected() in the mocked function.
  4313. *
  4314. * @param[in] #function The function to add the check for.
  4315. *
  4316. * @param[in] #parameter The name of the parameter passed to the function.
  4317. *
  4318. * @param[in] memory The memory to compare.
  4319. *
  4320. * @param[in] size The size of the memory to compare.
  4321. *
  4322. * @param[in] count The count parameter returns the number of times the value
  4323. * should be returned by check_expected(). If count is set
  4324. * to -1 the value will always be returned.
  4325. *
  4326. * @see check_expected().
  4327. */
  4328. void expect_not_memory_count(#function, #parameter, void *memory, size_t size, size_t count);
  4329. #else
  4330. #define expect_not_memory_count(function, parameter, memory, size, count) \
  4331. _expect_not_memory(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, \
  4332. (const void*)(memory), size, count)
  4333. #endif
  4334. #ifdef DOXYGEN
  4335. /**
  4336. * @brief Add an event to check if a parameter (of any value) has been passed.
  4337. *
  4338. * The event is triggered by calling check_expected() in the mocked function.
  4339. *
  4340. * @param[in] #function The function to add the check for.
  4341. *
  4342. * @param[in] #parameter The name of the parameter passed to the function.
  4343. *
  4344. * @see check_expected().
  4345. */
  4346. void expect_any(#function, #parameter);
  4347. #else
  4348. #define expect_any(function, parameter) \
  4349. expect_any_count(function, parameter, 1)
  4350. #endif
  4351. #ifdef DOXYGEN
  4352. /**
  4353. * @brief Add an event to always check if a parameter (of any value) has been passed.
  4354. *
  4355. * The event is triggered by calling check_expected() in the mocked function.
  4356. *
  4357. * @param[in] #function The function to add the check for.
  4358. *
  4359. * @param[in] #parameter The name of the parameter passed to the function.
  4360. *
  4361. * @see check_expected().
  4362. */
  4363. void expect_any_always(#function, #parameter);
  4364. #else
  4365. #define expect_any_always(function, parameter) \
  4366. expect_any_count(function, parameter, WILL_RETURN_ALWAYS)
  4367. #endif
  4368. #ifdef DOXYGEN
  4369. /**
  4370. * @brief Add an event to repeatedly check if a parameter (of any value) has
  4371. * been passed.
  4372. *
  4373. * The event is triggered by calling check_expected() in the mocked function.
  4374. *
  4375. * @param[in] #function The function to add the check for.
  4376. *
  4377. * @param[in] #parameter The name of the parameter passed to the function.
  4378. *
  4379. * @param[in] count The count parameter returns the number of times the value
  4380. * should be returned by check_expected(). If count is set
  4381. * to -1 the value will always be returned.
  4382. *
  4383. * @see check_expected().
  4384. */
  4385. void expect_any_count(#function, #parameter, size_t count);
  4386. #else
  4387. #define expect_any_count(function, parameter, count) \
  4388. _expect_any(cmocka_tostring(function), cmocka_tostring(parameter), __FILE__, __LINE__, count)
  4389. #endif
  4390. #ifdef DOXYGEN
  4391. /**
  4392. * @deprecated Use check_expected_int(), check_expected_uint(),
  4393. * check_expected_float or check_expetecd_double() instead.
  4394. */
  4395. void check_expected(#parameter);
  4396. #else
  4397. #define check_expected(parameter) \
  4398. do { \
  4399. CMOCKA_DEPRECATION_WARNING( \
  4400. "check_expected: use check_expected_int or " \
  4401. "check_expected_uint instead") \
  4402. _check_expected(__func__, \
  4403. #parameter, \
  4404. __FILE__, \
  4405. __LINE__, \
  4406. cast_int_to_cmocka_value(parameter)); \
  4407. } while (0)
  4408. #endif
  4409. #ifdef DOXYGEN
  4410. /**
  4411. * @brief Check that any parameter value matches the next value in the queue.
  4412. *
  4413. * This generic parameter checker works with any type including structs passed
  4414. * by value. It passes the address of the parameter, making it suitable for
  4415. * struct validation with custom checkers.
  4416. *
  4417. * Use this when:
  4418. * - Checking structs passed by value with expect_check_data()
  4419. * - Generic/template code where the type isn't known
  4420. *
  4421. * For scalar types, prefer the type-specific versions:
  4422. * - check_expected_int() for signed integers
  4423. * - check_expected_uint() for unsigned integers
  4424. * - check_expected_float() for float types
  4425. * - check_expected_double() for double types
  4426. * - check_expected_ptr() for pointers
  4427. *
  4428. * @param[in] #parameter The parameter to check.
  4429. *
  4430. * @see check_expected_int()
  4431. * @see check_expected_uint()
  4432. * @see check_expected_float()
  4433. * @see check_expected_double()
  4434. * @see check_expected_ptr()
  4435. * @see expect_check_data()
  4436. */
  4437. void check_expected_any(#parameter);
  4438. #else
  4439. #define check_expected_any(parameter) \
  4440. _check_expected(__func__, #parameter, __FILE__, __LINE__, \
  4441. cast_ptr_to_cmocka_value(&(parameter)))
  4442. #endif
  4443. #ifdef DOXYGEN
  4444. /**
  4445. * @brief Determine whether a function parameter is correct.
  4446. *
  4447. * This ensures the next value queued by one of the expect_*() macros matches
  4448. * the specified variable.
  4449. *
  4450. * This function needs to be called in the mock object.
  4451. *
  4452. * @param[in] #parameter The pointer to check.
  4453. */
  4454. void check_expected_ptr(#parameter);
  4455. #else
  4456. #define check_expected_ptr(parameter) \
  4457. _check_expected(__func__, #parameter, __FILE__, __LINE__, \
  4458. cast_ptr_to_cmocka_value(parameter))
  4459. #endif
  4460. #ifdef DOXYGEN
  4461. /**
  4462. * @brief Determine whether a function parameter is correct.
  4463. *
  4464. * This ensures the next value queued by one of the expect_int*() macros matches
  4465. * the specified variable.
  4466. *
  4467. * This function needs to be called in the mock object.
  4468. *
  4469. * @param[in] #parameter The parameter to check.
  4470. */
  4471. void check_expected_int(#parameter);
  4472. #else
  4473. #define check_expected_int(parameter) \
  4474. _check_expected(__func__, \
  4475. #parameter, \
  4476. __FILE__, \
  4477. __LINE__, \
  4478. assign_int_to_cmocka_value(parameter))
  4479. #endif
  4480. #ifdef DOXYGEN
  4481. /**
  4482. * @brief Determine whether a function parameter is correct.
  4483. *
  4484. * This ensures the next value queued by one of the expect_uint*() macros
  4485. * matches the specified variable.
  4486. *
  4487. * This function needs to be called in the mock object.
  4488. *
  4489. * @param[in] #parameter The parameter to check.
  4490. */
  4491. void check_expected_uint(#parameter);
  4492. #else
  4493. #define check_expected_uint(parameter) \
  4494. _check_expected(__func__, \
  4495. #parameter, \
  4496. __FILE__, \
  4497. __LINE__, \
  4498. assign_uint_to_cmocka_value(parameter))
  4499. #endif
  4500. #ifdef DOXYGEN
  4501. /**
  4502. * @brief Determine whether a function parameter is correct.
  4503. *
  4504. * This ensures the next value queued by one of the expect*_float() macros matches
  4505. * the specified variable.
  4506. *
  4507. * This function needs to be called in the mock object.
  4508. *
  4509. * @param[in] #parameter The parameter to check.
  4510. *
  4511. * @see expect_float
  4512. * @see expect_not_float
  4513. * @see expect_float_count
  4514. * @see expect_not_float_count
  4515. */
  4516. void check_expected_float(#parameter);
  4517. #else
  4518. #define check_expected_float(parameter) \
  4519. _check_expected(__func__, \
  4520. #parameter, \
  4521. __FILE__, \
  4522. __LINE__, \
  4523. assign_float_to_cmocka_value(parameter))
  4524. #endif
  4525. #ifdef DOXYGEN
  4526. /**
  4527. * @brief Determine whether a function parameter is correct.
  4528. *
  4529. * This ensures the next value queued by one of the expect*_double() macros
  4530. * matches the specified variable.
  4531. *
  4532. * This function needs to be called in the mock object.
  4533. *
  4534. * @param[in] #parameter The parameter to check.
  4535. *
  4536. * @see expect_double
  4537. * @see expect_not_double
  4538. * @see expect_double_count
  4539. * @see expect_not_double_count
  4540. */
  4541. void check_expected_double(#parameter);
  4542. #else
  4543. #define check_expected_double(parameter) \
  4544. _check_expected(__func__, \
  4545. #parameter, \
  4546. __FILE__, \
  4547. __LINE__, \
  4548. assign_double_to_cmocka_value(parameter))
  4549. #endif
  4550. /** @} */ /* cmocka_param */
  4551. /**
  4552. * @defgroup cmocka_asserts 🛡️ Assert Macros
  4553. * @ingroup cmocka
  4554. * @brief Verify conditions and fail tests when assertions don't hold.
  4555. *
  4556. * Assertion macros for validating test conditions.
  4557. *
  4558. * CMocka provides type-specific assertion macros that display detailed
  4559. * information about failures, making debugging easier than the standard C
  4560. * library's assert(3) macro.
  4561. *
  4562. * On an assertion failure a cmocka assert macro will write the failure to
  4563. * the standard error stream and signal a test failure. Due to limitations
  4564. * of the C language the general C standard library assert() and cmocka's
  4565. * assert_true() and assert_false() macros can only display the expression
  4566. * that caused the assert failure. cmocka's type specific assert macros,
  4567. * assert_{type}_equal() and assert_{type}_not_equal(), display the data
  4568. * that caused the assertion failure which increases data visibility aiding
  4569. * debugging of failing test cases.
  4570. *
  4571. * @{
  4572. */
  4573. #ifdef DOXYGEN
  4574. /**
  4575. * @brief Assert that the given expression is true.
  4576. *
  4577. * The function prints an error message to standard error and terminates the
  4578. * test by calling fail() if expression is false (i.e., compares equal to
  4579. * zero).
  4580. *
  4581. * @param[in] expression The expression to evaluate.
  4582. *
  4583. * @see assert_int_equal()
  4584. * @see assert_string_equal()
  4585. */
  4586. void assert_true(scalar expression);
  4587. #else
  4588. #define assert_true(c) _assert_true(cast_to_uintmax_type(c), #c, \
  4589. __FILE__, __LINE__)
  4590. #endif
  4591. #ifdef DOXYGEN
  4592. /**
  4593. * @brief Assert that the given expression is false.
  4594. *
  4595. * The function prints an error message to standard error and terminates the
  4596. * test by calling fail() if expression is true.
  4597. *
  4598. * @param[in] expression The expression to evaluate.
  4599. *
  4600. * @see assert_int_equal()
  4601. * @see assert_string_equal()
  4602. */
  4603. void assert_false(scalar expression);
  4604. #else
  4605. #define assert_false(c) _assert_false(cast_to_uintmax_type(c), #c, \
  4606. __FILE__, __LINE__)
  4607. #endif
  4608. #ifdef DOXYGEN
  4609. /**
  4610. * @brief Assert that the return_code is greater than or equal to 0.
  4611. *
  4612. * The function prints an error message to standard error and terminates the
  4613. * test by calling fail() if the return code is smaller than 0. If the function
  4614. * you check sets an errno if it fails you can pass it to the function and
  4615. * it will be printed as part of the error message.
  4616. *
  4617. * @param[in] rc The return code to evaluate.
  4618. *
  4619. * @param[in] error Pass errno here or 0.
  4620. */
  4621. void assert_return_code(intmax_t rc, int32_t error);
  4622. #else
  4623. #define assert_return_code(rc, error) \
  4624. _assert_return_code((rc), \
  4625. (error), \
  4626. #rc, __FILE__, __LINE__)
  4627. #endif
  4628. #ifdef DOXYGEN
  4629. /**
  4630. * @brief Assert that the given pointer is non-NULL.
  4631. *
  4632. * The function prints an error message to standard error and terminates the
  4633. * test by calling fail() if the pointer is NULL.
  4634. *
  4635. * @param[in] pointer The pointer to evaluate.
  4636. *
  4637. * @see assert_null()
  4638. */
  4639. void assert_non_null(void *pointer);
  4640. #else
  4641. #define assert_non_null(c) assert_ptr_not_equal((c), NULL)
  4642. #endif
  4643. #ifdef DOXYGEN
  4644. /**
  4645. * @brief Assert that the given pointer is non-NULL.
  4646. *
  4647. * The function prints an error message extended by message to standard error
  4648. * and terminates the test by calling fail() if the pointer is NULL.
  4649. *
  4650. * @param[in] pointer The pointer to evaluate.
  4651. *
  4652. * @param[in] message The message to print when the pointer is NULL.
  4653. *
  4654. * @see assert_null_msg()
  4655. */
  4656. void assert_non_null_msg(void *pointer, const char *const message);
  4657. #else
  4658. #define assert_non_null_msg(c, msg) assert_ptr_not_equal_msg((c), NULL, (msg))
  4659. #endif
  4660. #ifdef DOXYGEN
  4661. /**
  4662. * @brief Assert that the given pointer is NULL.
  4663. *
  4664. * The function prints an error message to standard error and terminates the
  4665. * test by calling fail() if the pointer is non-NULL.
  4666. *
  4667. * @param[in] pointer The pointer to evaluate.
  4668. *
  4669. * @see assert_non_null()
  4670. */
  4671. void assert_null(void *pointer);
  4672. #else
  4673. #define assert_null(c) assert_ptr_equal((c), NULL)
  4674. #endif
  4675. #ifdef DOXYGEN
  4676. /**
  4677. * @brief Assert that the given pointer is NULL.
  4678. *
  4679. * The function prints an error message extended by message to standard error
  4680. * and terminates the test by calling fail() if the pointer is non-NULL.
  4681. *
  4682. * @param[in] pointer The pointer to evaluate.
  4683. *
  4684. * @param[in] message The message to print when the pointer is not NULL.
  4685. *
  4686. * @see assert_non_null_msg()
  4687. */
  4688. void assert_null_msg(void *pointer, const char *const message);
  4689. #else
  4690. #define assert_null_msg(c, msg) assert_ptr_equal_msg((c), NULL, (msg))
  4691. #endif
  4692. #ifdef DOXYGEN
  4693. /**
  4694. * @brief Assert that the two given pointers are equal.
  4695. *
  4696. * The function prints an error message and terminates the test by calling
  4697. * fail() if the pointers are not equal.
  4698. *
  4699. * @param[in] a The first pointer to compare.
  4700. *
  4701. * @param[in] b The pointer to compare against the first one.
  4702. */
  4703. void assert_ptr_equal(void *a, void *b);
  4704. #else
  4705. #define assert_ptr_equal(a, b) assert_ptr_equal_msg((a), (b), NULL)
  4706. #endif
  4707. #ifdef DOXYGEN
  4708. /**
  4709. * @brief Assert that the two given pointers are equal.
  4710. *
  4711. * The function prints the failing comparison and the error message given by the user
  4712. * and then terminates the test by calling fail() if the pointers are not equal.
  4713. *
  4714. * @param[in] a The first pointer to compare.
  4715. *
  4716. * @param[in] b The pointer to compare against the first one.
  4717. *
  4718. * @param[in] msg The error message to print when a & b are not equal.
  4719. */
  4720. void assert_ptr_equal_msg(void *a, void *b, const char *const msg);
  4721. #else
  4722. #define assert_ptr_equal_msg(a, b, msg) \
  4723. _assert_ptr_equal_msg(cast_to_void_pointer(a), \
  4724. cast_to_void_pointer(b), \
  4725. __FILE__, __LINE__, (msg))
  4726. #endif
  4727. #ifdef DOXYGEN
  4728. /**
  4729. * @brief Assert that the two given pointers are not equal.
  4730. *
  4731. * The function prints an error message and terminates the test by calling
  4732. * fail() if the pointers are equal.
  4733. *
  4734. * @param[in] a The first pointer to compare.
  4735. *
  4736. * @param[in] b The pointer to compare against the first one.
  4737. */
  4738. void assert_ptr_not_equal(void *a, void *b);
  4739. #else
  4740. #define assert_ptr_not_equal(a, b) \
  4741. assert_ptr_not_equal_msg((a), (b), NULL)
  4742. #endif
  4743. #ifdef DOXYGEN
  4744. /**
  4745. * @brief Assert that the two given pointers are not equal.
  4746. *
  4747. * The function prints the failing comparison and the error message given by the user
  4748. * and then terminates the test by calling fail() if the pointers are equal.
  4749. *
  4750. * @param[in] a The first pointer to compare.
  4751. *
  4752. * @param[in] b The pointer to compare against the first one.
  4753. *
  4754. * @param[in] msg The error message to print when a & b are equal.
  4755. */
  4756. void assert_ptr_not_equal_msg(void *a, void *b, const char *const msg);
  4757. #else /* DOXYGEN */
  4758. #if defined(__has_builtin)
  4759. #if __has_builtin(__builtin_unreachable)
  4760. #define assert_ptr_not_equal_msg(a, b, msg) \
  4761. do { \
  4762. const void *cmocka_p1 = cast_to_void_pointer(a), \
  4763. *cmocka_p2 = cast_to_void_pointer(b); \
  4764. _assert_ptr_not_equal_msg( \
  4765. cmocka_p1, cmocka_p2, __FILE__, __LINE__, (msg)); \
  4766. if (cmocka_p1 == cmocka_p2) { \
  4767. __builtin_unreachable(); \
  4768. } \
  4769. } while (0)
  4770. #else /* __has_builtin(__builtin_unreachable) */
  4771. #define assert_ptr_not_equal_msg(a, b, msg) \
  4772. _assert_ptr_not_equal_msg(cast_to_void_pointer(a), \
  4773. cast_to_void_pointer(b), \
  4774. __FILE__, \
  4775. __LINE__, \
  4776. (msg))
  4777. #endif /* __has_builtin(__builtin_unreachable) */
  4778. #else /* defined(__has_builtin) */
  4779. #define assert_ptr_not_equal_msg(a, b, msg) \
  4780. _assert_ptr_not_equal_msg(cast_to_void_pointer(a), \
  4781. cast_to_void_pointer(b), \
  4782. __FILE__, \
  4783. __LINE__, \
  4784. (msg))
  4785. #endif /* __has_builtin(__builtin_unreachable) */
  4786. #endif /* DOXYGEN */
  4787. #ifdef DOXYGEN
  4788. /**
  4789. * @brief Assert that the two given integers are equal.
  4790. *
  4791. * The function prints an error message to standard error and terminates the
  4792. * test by calling fail() if the integers are not equal.
  4793. *
  4794. * @param[in] a The first integer to compare.
  4795. *
  4796. * @param[in] b The integer to compare against the first one.
  4797. */
  4798. void assert_int_equal(intmax_t a, intmax_t b);
  4799. #else
  4800. #define assert_int_equal(a, b) \
  4801. _assert_int_equal(cast_to_intmax_type(a), \
  4802. cast_to_intmax_type(b), \
  4803. __FILE__, __LINE__)
  4804. #endif
  4805. #ifdef DOXYGEN
  4806. /**
  4807. * @brief Assert that the two given unsigned integers are equal.
  4808. *
  4809. * The function prints an error message to standard error and terminates the
  4810. * test by calling fail() if the integers are not equal.
  4811. *
  4812. * @param[in] a The first unsigned integer to compare.
  4813. *
  4814. * @param[in] b The unsigned integer to compare against the first one.
  4815. */
  4816. void assert_uint_equal(uintmax_t a, uintmax_t b);
  4817. #else
  4818. #define assert_uint_equal(a, b) \
  4819. _assert_uint_equal(cast_to_uintmax_type(a), \
  4820. cast_to_uintmax_type(b), \
  4821. __FILE__, __LINE__)
  4822. #endif
  4823. #ifdef DOXYGEN
  4824. /**
  4825. * @brief Assert that the two given integers are not equal.
  4826. *
  4827. * The function prints an error message to standard error and terminates the
  4828. * test by calling fail() if the integers are equal.
  4829. *
  4830. * @param[in] a The first integer to compare.
  4831. *
  4832. * @param[in] b The integer to compare against the first one.
  4833. *
  4834. * @see assert_int_equal()
  4835. */
  4836. void assert_int_not_equal(intmax_t a, intmax_t b);
  4837. #else
  4838. #define assert_int_not_equal(a, b) \
  4839. _assert_int_not_equal(cast_to_intmax_type(a), \
  4840. cast_to_intmax_type(b), \
  4841. __FILE__, __LINE__)
  4842. #endif
  4843. #ifdef DOXYGEN
  4844. /**
  4845. * @brief Assert that the two given unsigned integers are not equal.
  4846. *
  4847. * The function prints an error message to standard error and terminates the
  4848. * test by calling fail() if the integers are not equal.
  4849. *
  4850. * @param[in] a The first unsigned integer to compare.
  4851. *
  4852. * @param[in] b The unsigned integer to compare against the first one.
  4853. */
  4854. void assert_uint_not_equal(uintmax_t a, uintmax_t b);
  4855. #else
  4856. #define assert_uint_not_equal(a, b) \
  4857. _assert_uint_not_equal(cast_to_uintmax_type(a), \
  4858. cast_to_uintmax_type(b), \
  4859. __FILE__, __LINE__)
  4860. #endif
  4861. #ifdef DOXYGEN
  4862. /**
  4863. * @brief Assert that the two given float are equal given an epsilon.
  4864. *
  4865. * The function prints an error message to standard error and terminates the
  4866. * test by calling fail() if the float are not equal (given an epsilon).
  4867. *
  4868. * @param[in] a The first float to compare.
  4869. *
  4870. * @param[in] b The float to compare against the first one.
  4871. *
  4872. * @param[in] epsilon The epsilon used as margin for float comparison.
  4873. */
  4874. void assert_float_equal(float a, float b, float epsilon);
  4875. #else
  4876. #define assert_float_equal(a, b, epsilon) \
  4877. _assert_float_equal((float)a, \
  4878. (float)b, \
  4879. (float)epsilon, \
  4880. __FILE__, __LINE__)
  4881. #endif
  4882. #ifdef DOXYGEN
  4883. /**
  4884. * @brief Assert that the two given float are not equal given an epsilon.
  4885. *
  4886. * The function prints an error message to standard error and terminates the
  4887. * test by calling fail() if the float are not equal (given an epsilon).
  4888. *
  4889. * @param[in] a The first float to compare.
  4890. *
  4891. * @param[in] b The float to compare against the first one.
  4892. *
  4893. * @param[in] epsilon The epsilon used as margin for float comparison.
  4894. */
  4895. void assert_float_not_equal(float a, float b, float epsilon);
  4896. #else
  4897. #define assert_float_not_equal(a, b, epsilon) \
  4898. _assert_float_not_equal((float)a, \
  4899. (float)b, \
  4900. (float)epsilon, \
  4901. __FILE__, __LINE__)
  4902. #endif
  4903. #ifdef DOXYGEN
  4904. /**
  4905. * @brief Assert that the two given double are equal given an epsilon.
  4906. *
  4907. * The function prints an error message to standard error and terminates the
  4908. * test by calling fail() if the double are not equal (given an epsilon).
  4909. *
  4910. * @param[in] a The first double to compare.
  4911. *
  4912. * @param[in] b The double to compare against the first one.
  4913. *
  4914. * @param[in] epsilon The epsilon used as margin for double comparison.
  4915. */
  4916. void assert_double_equal(double a, double b, double epsilon);
  4917. #else
  4918. #define assert_double_equal(a, b, epsilon) \
  4919. _assert_double_equal((double)a, \
  4920. (double)b, \
  4921. (double)epsilon, \
  4922. __FILE__, __LINE__)
  4923. #endif
  4924. #ifdef DOXYGEN
  4925. /**
  4926. * @brief Assert that the two given double are not equal given an epsilon.
  4927. *
  4928. * The function prints an error message to standard error and terminates the
  4929. * test by calling fail() if the double are not equal (given an epsilon).
  4930. *
  4931. * @param[in] a The first double to compare.
  4932. *
  4933. * @param[in] b The double to compare against the first one.
  4934. *
  4935. * @param[in] epsilon The epsilon used as margin for double comparison.
  4936. */
  4937. void assert_double_not_equal(double a, double b, double epsilon);
  4938. #else
  4939. #define assert_double_not_equal(a, b, epsilon) \
  4940. _assert_double_not_equal((double)a, \
  4941. (double)b, \
  4942. (double)epsilon, \
  4943. __FILE__, __LINE__)
  4944. #endif
  4945. #ifdef DOXYGEN
  4946. /**
  4947. * @brief Assert that the two given strings are equal.
  4948. *
  4949. * The function prints an error message to standard error and terminates the
  4950. * test by calling fail() if the strings are not equal.
  4951. *
  4952. * @param[in] a The string to check.
  4953. *
  4954. * @param[in] b The other string to compare.
  4955. */
  4956. void assert_string_equal(const char *a, const char *b);
  4957. #else
  4958. #define assert_string_equal(a, b) \
  4959. _assert_string_equal((a), (b), __FILE__, __LINE__)
  4960. #endif
  4961. #ifdef DOXYGEN
  4962. /**
  4963. * @brief Assert that the two given strings are not equal.
  4964. *
  4965. * The function prints an error message to standard error and terminates the
  4966. * test by calling fail() if the strings are equal.
  4967. *
  4968. * @param[in] a The string to check.
  4969. *
  4970. * @param[in] b The other string to compare.
  4971. */
  4972. void assert_string_not_equal(const char *a, const char *b);
  4973. #else
  4974. #define assert_string_not_equal(a, b) \
  4975. _assert_string_not_equal((a), (b), __FILE__, __LINE__)
  4976. #endif
  4977. #ifdef DOXYGEN
  4978. /**
  4979. * @brief Assert that the two given areas of memory are equal, otherwise fail.
  4980. *
  4981. * The function prints an error message to standard error and terminates the
  4982. * test by calling fail() if the memory is not equal.
  4983. *
  4984. * @param[in] a The first memory area to compare
  4985. * (interpreted as unsigned char).
  4986. *
  4987. * @param[in] b The second memory area to compare
  4988. * (interpreted as unsigned char).
  4989. *
  4990. * @param[in] size The first n bytes of the memory areas to compare.
  4991. */
  4992. void assert_memory_equal(const void *a, const void *b, size_t size);
  4993. #else
  4994. #define assert_memory_equal(a, b, size) \
  4995. _assert_memory_equal((const void*)(a), (const void*)(b), size, __FILE__, \
  4996. __LINE__)
  4997. #endif
  4998. #ifdef DOXYGEN
  4999. /**
  5000. * @brief Assert that the two given areas of memory are not equal.
  5001. *
  5002. * The function prints an error message to standard error and terminates the
  5003. * test by calling fail() if the memory is equal.
  5004. *
  5005. * @param[in] a The first memory area to compare
  5006. * (interpreted as unsigned char).
  5007. *
  5008. * @param[in] b The second memory area to compare
  5009. * (interpreted as unsigned char).
  5010. *
  5011. * @param[in] size The first n bytes of the memory areas to compare.
  5012. */
  5013. void assert_memory_not_equal(const void *a, const void *b, size_t size);
  5014. #else
  5015. #define assert_memory_not_equal(a, b, size) \
  5016. _assert_memory_not_equal((const void*)(a), (const void*)(b), size, \
  5017. __FILE__, __LINE__)
  5018. #endif
  5019. #ifdef DOXYGEN
  5020. /**
  5021. * @brief Assert that the specified integer value is not smaller than the
  5022. * minimum and and not greater than the maximum.
  5023. *
  5024. * The function prints an error message to standard error and terminates the
  5025. * test by calling fail() if value is not in range.
  5026. *
  5027. * @param[in] value The value to check.
  5028. *
  5029. * @param[in] minimum The minimum value allowed.
  5030. *
  5031. * @param[in] maximum The maximum value allowed.
  5032. */
  5033. void assert_int_in_range(intmax_t value, intmax_t minimum, intmax_t maximum);
  5034. #else
  5035. #define assert_int_in_range(value, minimum, maximum) \
  5036. _assert_int_in_range( \
  5037. cast_to_intmax_type(value), \
  5038. cast_to_intmax_type(minimum), \
  5039. cast_to_intmax_type(maximum), __FILE__, __LINE__)
  5040. #endif
  5041. #ifdef DOXYGEN
  5042. /**
  5043. * @brief Assert that the specified unsigned integer value is not smaller than
  5044. * the minimum and and not greater than the maximum.
  5045. *
  5046. * The function prints an error message to standard error and terminates the
  5047. * test by calling fail() if value is not in range.
  5048. *
  5049. * @param[in] value The value to check.
  5050. *
  5051. * @param[in] minimum The minimum value allowed.
  5052. *
  5053. * @param[in] maximum The maximum value allowed.
  5054. */
  5055. void assert_uint_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum);
  5056. #else
  5057. #define assert_uint_in_range(value, minimum, maximum) \
  5058. _assert_uint_in_range( \
  5059. cast_to_intmax_type(value), \
  5060. cast_to_intmax_type(minimum), \
  5061. cast_to_intmax_type(maximum), __FILE__, __LINE__)
  5062. #endif
  5063. #ifdef DOXYGEN
  5064. /**
  5065. * @brief Assert that the specified value is smaller than the minimum or
  5066. * greater than the maximum.
  5067. *
  5068. * The function prints an error message to standard error and terminates the
  5069. * test by calling fail() if value is in range.
  5070. *
  5071. * The function prints an error message to standard error and terminates the
  5072. * test by calling fail() if value is not in range.
  5073. *
  5074. * @param[in] value The value to check.
  5075. *
  5076. * @param[in] minimum The minimum value allowed.
  5077. *
  5078. * @param[in] maximum The maximum value allowed.
  5079. */
  5080. void assert_int_not_in_range(intmax_t value,
  5081. intmax_t minimum,
  5082. intmax_t maximum);
  5083. #else
  5084. #define assert_int_not_in_range(value, minimum, maximum) \
  5085. _assert_int_not_in_range(cast_to_intmax_type(value), \
  5086. cast_to_intmax_type(minimum), \
  5087. cast_to_intmax_type(maximum), \
  5088. __FILE__, \
  5089. __LINE__)
  5090. #endif
  5091. #ifdef DOXYGEN
  5092. /**
  5093. * @brief Assert that the specified value is smaller than the minimum or
  5094. * greater than the maximum.
  5095. *
  5096. * The function prints an error message to standard error and terminates the
  5097. * test by calling fail() if value is in range.
  5098. *
  5099. * The function prints an error message to standard error and terminates the
  5100. * test by calling fail() if value is not in range.
  5101. *
  5102. * @param[in] value The value to check.
  5103. *
  5104. * @param[in] minimum The minimum value allowed.
  5105. *
  5106. * @param[in] maximum The maximum value allowed.
  5107. */
  5108. void assert_uint_not_in_range(uintmax_t value,
  5109. uintmax_t minimum,
  5110. uintmax_t maximum);
  5111. #else
  5112. #define assert_uint_not_in_range(value, minimum, maximum) \
  5113. _assert_uint_not_in_range(cast_to_uintmax_type(value), \
  5114. cast_to_uintmax_type(minimum), \
  5115. cast_to_uintmax_type(maximum), \
  5116. __FILE__, \
  5117. __LINE__)
  5118. #endif
  5119. #ifdef DOXYGEN
  5120. /**
  5121. * @deprecated Use assert_int_in_range() and assert_uint_in_range()
  5122. */
  5123. void assert_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum);
  5124. #else
  5125. #define assert_in_range(value, minimum, maximum) \
  5126. do { \
  5127. CMOCKA_DEPRECATION_WARNING( \
  5128. "assert_in_range: use assert_int_in_range or " \
  5129. "assert_uint_in_range instead") \
  5130. _assert_uint_in_range(cast_to_uintmax_type(value), \
  5131. cast_to_uintmax_type(minimum), \
  5132. cast_to_uintmax_type(maximum), \
  5133. __FILE__, \
  5134. __LINE__); \
  5135. } while (0)
  5136. #endif
  5137. #ifdef DOXYGEN
  5138. /**
  5139. * @deprecated Use assert_int_not_in_range() or assert_uint_not_in_range()
  5140. */
  5141. void assert_not_in_range(uintmax_t value, uintmax_t minimum, uintmax_t maximum);
  5142. #else
  5143. #define assert_not_in_range(value, minimum, maximum) \
  5144. do { \
  5145. CMOCKA_DEPRECATION_WARNING( \
  5146. "assert_not_in_range: use assert_int_not_in_range or " \
  5147. "assert_uint_not_in_range instead") \
  5148. _assert_uint_not_in_range(cast_to_uintmax_type(value), \
  5149. cast_to_uintmax_type(minimum), \
  5150. cast_to_uintmax_type(maximum), \
  5151. __FILE__, \
  5152. __LINE__); \
  5153. } while (0)
  5154. #endif
  5155. #ifdef DOXYGEN
  5156. /**
  5157. * @brief Assert that the specified float value is smaller than the minimum or
  5158. * greater than the maximum.
  5159. *
  5160. * The function prints an error message to standard error and terminates the
  5161. * test by calling fail() if value is in range.
  5162. *
  5163. * The function prints an error message to standard error and terminates the
  5164. * test by calling fail() if value is not in range.
  5165. *
  5166. * @param[in] value The value to check.
  5167. *
  5168. * @param[in] minimum The minimum value allowed.
  5169. *
  5170. * @param[in] maximum The maximum value allowed.
  5171. *
  5172. * @param[in] epsilon The epsilon used as margin for float comparison.
  5173. */
  5174. void assert_float_not_in_range(double value, double minimum, double maximum, double epsilon);
  5175. #else
  5176. #define assert_float_not_in_range(value, minimum, maximum, epsilon) \
  5177. _assert_float_not_in_range(cast_to_double_type(value), \
  5178. cast_to_double_type(minimum), \
  5179. cast_to_double_type(maximum), \
  5180. cast_to_double_type(epsilon), \
  5181. __FILE__, \
  5182. __LINE__)
  5183. #endif
  5184. #ifdef DOXYGEN
  5185. /**
  5186. * @brief Assert that the specified float value is not smaller than
  5187. * the minimum and and not greater than the maximum.
  5188. *
  5189. * The function prints an error message to standard error and terminates the
  5190. * test by calling fail() if value is not in range.
  5191. *
  5192. * @param[in] value The value to check.
  5193. *
  5194. * @param[in] minimum The minimum value allowed.
  5195. *
  5196. * @param[in] maximum The maximum value allowed.
  5197. *
  5198. * @param[in] epsilon The epsilon used as margin for float comparison.
  5199. */
  5200. void assert_float_in_range(double value, double minimum, double maximum, double epsilon);
  5201. #else
  5202. #define assert_float_in_range(value, minimum, maximum, epsilon) \
  5203. _assert_float_in_range( \
  5204. cast_to_double_type(value), \
  5205. cast_to_double_type(minimum), \
  5206. cast_to_double_type(maximum), \
  5207. cast_to_double_type(epsilon), __FILE__, __LINE__)
  5208. #endif
  5209. #ifdef DOXYGEN
  5210. /**
  5211. * @deprecated Use assert_int_in_set() or assert_uint_in_set()
  5212. */
  5213. void assert_in_set(uintmax_t value, uintmax_t values[], size_t count);
  5214. #else
  5215. #define assert_in_set(value, values, number_of_values) \
  5216. do { \
  5217. CMOCKA_DEPRECATION_WARNING("assert_in_set: use assert_int_in_set or " \
  5218. "assert_uint_in_set instead") \
  5219. _assert_uint_in_set( \
  5220. value, values, number_of_values, __FILE__, __LINE__); \
  5221. } while (0)
  5222. #endif
  5223. #ifdef DOXYGEN
  5224. /**
  5225. * @brief Assert that the specified value is not within a set.
  5226. *
  5227. * The function prints an error message to standard error and terminates the
  5228. * test by calling fail() if value is within a set.
  5229. *
  5230. * @param[in] value The value to look up
  5231. *
  5232. * @param[in] values[] The array to check for the value.
  5233. *
  5234. * @param[in] count The size of the values array.
  5235. */
  5236. void assert_not_in_set(uintmax_t value, uintmax_t values[], size_t count);
  5237. #else
  5238. #define assert_not_in_set(value, values, number_of_values) \
  5239. _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__)
  5240. #endif
  5241. #ifdef DOXYGEN
  5242. /**
  5243. * @brief Assert that the specified integer value is within a set.
  5244. *
  5245. * The function prints an error message to standard error and terminates the
  5246. * test by calling fail() if value is not within a set.
  5247. *
  5248. * @param[in] value The value to look up
  5249. *
  5250. * @param[in] values[] The array to check for the value.
  5251. *
  5252. * @param[in] count The size of the values array.
  5253. */
  5254. void assert_int_in_set(intmax_t value, intmax_t values[], size_t count);
  5255. #else
  5256. #define assert_int_in_set(value, values, number_of_values) \
  5257. if (number_of_values > 0) { \
  5258. intmax_t _cmocka_set[number_of_values]; \
  5259. for (size_t _i = 0; _i < number_of_values; _i++) { \
  5260. _cmocka_set[_i] = values[_i]; \
  5261. } \
  5262. _assert_int_in_set(value, _cmocka_set, number_of_values, __FILE__, __LINE__); \
  5263. }
  5264. #endif
  5265. #ifdef DOXYGEN
  5266. /**
  5267. * @brief Assert that the specified value is not within a set.
  5268. *
  5269. * The function prints an error message to standard error and terminates the
  5270. * test by calling fail() if value is within a set.
  5271. *
  5272. * @param[in] value The value to look up
  5273. *
  5274. * @param[in] values[] The array to check for the value.
  5275. *
  5276. * @param[in] count The size of the values array.
  5277. */
  5278. void assert_int_not_in_set(intmax_t value, intmax_t values[], size_t count);
  5279. #else
  5280. #define assert_int_not_in_set(value, values, number_of_values) \
  5281. if (number_of_values > 0) { \
  5282. intmax_t _cmocka_set[number_of_values]; \
  5283. for (size_t _i = 0; _i < number_of_values; _i++) { \
  5284. _cmocka_set[_i] = values[_i]; \
  5285. } \
  5286. _assert_int_not_in_set(value, _cmocka_set, number_of_values, __FILE__, __LINE__); \
  5287. }
  5288. #endif
  5289. #ifdef DOXYGEN
  5290. /**
  5291. * @brief Assert that the specified unsigned integer value is within a set.
  5292. *
  5293. * The function prints an error message to standard error and terminates the
  5294. * test by calling fail() if value is not within a set.
  5295. *
  5296. * @param[in] value The value to look up
  5297. *
  5298. * @param[in] values[] The array to check for the value.
  5299. *
  5300. * @param[in] count The size of the values array.
  5301. */
  5302. void assert_uint_in_set(uintmax_t value, uintmax_t values[], size_t count);
  5303. #else
  5304. #define assert_uint_in_set(value, values, number_of_values) \
  5305. if (number_of_values > 0) { \
  5306. uintmax_t _cmocka_set[number_of_values]; \
  5307. for (size_t _i = 0; _i < number_of_values; _i++) { \
  5308. _cmocka_set[_i] = values[_i]; \
  5309. } \
  5310. _assert_uint_in_set(value, _cmocka_set, number_of_values, __FILE__, __LINE__); \
  5311. }
  5312. #endif
  5313. #ifdef DOXYGEN
  5314. /**
  5315. * @brief Assert that the specified unsigned integer value is not within a set.
  5316. *
  5317. * The function prints an error message to standard error and terminates the
  5318. * test by calling fail() if value is within a set.
  5319. *
  5320. * @param[in] value The value to look up
  5321. *
  5322. * @param[in] values[] The array to check for the value.
  5323. *
  5324. * @param[in] count The size of the values array.
  5325. */
  5326. void assert_uint_not_in_set(uintmax_t value, uintmax_t values[], size_t count);
  5327. #else
  5328. #define assert_uint_not_in_set(value, values, number_of_values) \
  5329. if (number_of_values > 0) { \
  5330. uintmax_t _cmocka_set[number_of_values]; \
  5331. for (size_t _i = 0; _i < number_of_values; _i++) { \
  5332. _cmocka_set[_i] = values[_i]; \
  5333. } \
  5334. _assert_uint_not_in_set(value, _cmocka_set, number_of_values, __FILE__, __LINE__); \
  5335. }
  5336. #endif
  5337. #ifdef DOXYGEN
  5338. /**
  5339. * @brief Assert that the specified float value is within a set.
  5340. *
  5341. * The function prints an error message to standard error and terminates the
  5342. * test by calling fail() if value is not within a set.
  5343. *
  5344. * @param[in] value The value to look up
  5345. *
  5346. * @param[in] values[] The array to check for the value.
  5347. *
  5348. * @param[in] count The size of the values array.
  5349. *
  5350. * @param[in] epsilon The epsilon used as margin for float comparison.
  5351. */
  5352. void assert_float_in_set(double value, double values[], size_t count, double epsilon);
  5353. #else
  5354. #define assert_float_in_set(value, values, number_of_values, epsilon) \
  5355. if (number_of_values > 0) { \
  5356. double _cmocka_set[number_of_values]; \
  5357. for (size_t _i = 0; _i < number_of_values; _i++) { \
  5358. _cmocka_set[_i] = values[_i]; \
  5359. } \
  5360. _assert_float_in_set(value, _cmocka_set, number_of_values, epsilon, __FILE__, __LINE__); \
  5361. }
  5362. #endif
  5363. #ifdef DOXYGEN
  5364. /**
  5365. * @brief Assert that the specified float value is not within a set.
  5366. *
  5367. * The function prints an error message to standard error and terminates the
  5368. * test by calling fail() if value is not within a set.
  5369. *
  5370. * @param[in] value The value to look up
  5371. *
  5372. * @param[in] values[] The array to check for the value.
  5373. *
  5374. * @param[in] count The size of the values array.
  5375. *
  5376. * @param[in] epsilon The epsilon used as margin for float comparison.
  5377. */
  5378. void assert_float_not_in_set(double value, double values[], size_t count, double epsilon);
  5379. #else
  5380. #define assert_float_not_in_set(value, values, number_of_values, epsilon) \
  5381. if (number_of_values > 0) { \
  5382. double _cmocka_set[number_of_values]; \
  5383. for (size_t _i = 0; _i < number_of_values; _i++) { \
  5384. _cmocka_set[_i] = values[_i]; \
  5385. } \
  5386. _assert_float_not_in_set(value, _cmocka_set, number_of_values, epsilon, __FILE__, __LINE__); \
  5387. }
  5388. #endif
  5389. /** @} */ /* cmocka_asserts */
  5390. /**
  5391. * @defgroup cmocka_call_order 🔢 Call Ordering
  5392. * @ingroup cmocka
  5393. * @brief Ensure functions are called in the correct sequence.
  5394. *
  5395. * Verify that functions are called in the expected order.
  5396. *
  5397. * This module provides functionality to ensure functions are called in a
  5398. * specific sequence, independent of mock return values and parameter
  5399. * checking. Both of the aforementioned do not verify the order in which
  5400. * functions are called.
  5401. *
  5402. * <ul>
  5403. * <li><strong>expect_function_call(function)</strong> - The
  5404. * expect_function_call() macro pushes an expectation onto the stack of
  5405. * expected calls.</li>
  5406. *
  5407. * <li><strong>function_called()</strong> - pops a value from the stack of
  5408. * expected calls. function_called() is invoked within the mock object
  5409. * that uses it.
  5410. * </ul>
  5411. *
  5412. * expect_function_call() and function_called() are intended to be used in
  5413. * pairs. Cmocka will fail a test if there are more or less expected calls
  5414. * created (e.g. expect_function_call()) than consumed with function_called().
  5415. * There are provisions such as ignore_function_calls() which allow this
  5416. * restriction to be circumvented in tests where mock calls for the code under
  5417. * test are not the focus of the test. function_called() must be called from
  5418. * the same thread as expect_function_call(), and that thread must have been
  5419. * initialized for use by cmocka (see also the [Threading section of the main
  5420. * documentation page](index.html#main-threads)).
  5421. *
  5422. * The following example illustrates how a unit test instructs cmocka
  5423. * to expect a function_called() from a particular mock,
  5424. * <strong>chef_sing()</strong>:
  5425. *
  5426. * @code
  5427. * void chef_sing(void);
  5428. *
  5429. * void code_under_test()
  5430. * {
  5431. * chef_sing();
  5432. * }
  5433. *
  5434. * void some_test(void **state)
  5435. * {
  5436. * expect_function_call(chef_sing);
  5437. * code_under_test();
  5438. * }
  5439. * @endcode
  5440. *
  5441. * The implementation of the mock then must check whether it was meant to
  5442. * be called by invoking <strong>function_called()</strong>:
  5443. *
  5444. * @code
  5445. * void chef_sing()
  5446. * {
  5447. * function_called();
  5448. * }
  5449. * @endcode
  5450. *
  5451. * @{
  5452. */
  5453. #ifdef DOXYGEN
  5454. /**
  5455. * @brief Check that current mocked function is being called in the expected
  5456. * order
  5457. *
  5458. * @see expect_function_call()
  5459. */
  5460. void function_called(void);
  5461. #else
  5462. #define function_called() _function_called(__func__, __FILE__, __LINE__)
  5463. #endif
  5464. #ifdef DOXYGEN
  5465. /**
  5466. * @brief Store expected call(s) to a mock to be checked by function_called()
  5467. * later.
  5468. *
  5469. * @param[in] #function The function which should should be called
  5470. *
  5471. * @param[in] times number of times this mock must be called
  5472. *
  5473. * @see function_called()
  5474. */
  5475. void expect_function_calls(#function, const int times);
  5476. #else
  5477. #define expect_function_calls(function, times) \
  5478. _expect_function_call(cmocka_tostring(function), __FILE__, __LINE__, times)
  5479. #endif
  5480. #ifdef DOXYGEN
  5481. /**
  5482. * @brief Store expected single call to a mock to be checked by
  5483. * function_called() later.
  5484. *
  5485. * @param[in] #function The function which should should be called
  5486. *
  5487. * @see function_called()
  5488. */
  5489. void expect_function_call(#function);
  5490. #else
  5491. #define expect_function_call(function) \
  5492. _expect_function_call(cmocka_tostring(function), __FILE__, __LINE__, 1)
  5493. #endif
  5494. #ifdef DOXYGEN
  5495. /**
  5496. * @brief Expects function_called() from given mock at least once
  5497. *
  5498. * @param[in] #function The function which should should be called
  5499. *
  5500. * @see function_called()
  5501. */
  5502. void expect_function_call_any(#function);
  5503. #else
  5504. #define expect_function_call_any(function) \
  5505. _expect_function_call(cmocka_tostring(function), __FILE__, __LINE__, -1)
  5506. #endif
  5507. #ifdef DOXYGEN
  5508. /**
  5509. * @brief Ignores function_called() invocations from given mock function.
  5510. *
  5511. * @param[in] #function The function which should should be called
  5512. *
  5513. * @see function_called()
  5514. */
  5515. void ignore_function_calls(#function);
  5516. #else
  5517. #define ignore_function_calls(function) \
  5518. _expect_function_call(cmocka_tostring(function), __FILE__, __LINE__, -2)
  5519. #endif
  5520. /** @} */ /* cmocka_call_order */
  5521. /**
  5522. * @defgroup cmocka_exec ▶️ Running Tests
  5523. * @ingroup cmocka
  5524. * @brief Execute test suites with setup and teardown functions.
  5525. *
  5526. * Test execution framework and test runners.
  5527. *
  5528. * This module provides the infrastructure for defining, organizing, and
  5529. * running tests, including support for setup/teardown functions (fixtures),
  5530. * test grouping, and multiple test runner macros.
  5531. *
  5532. * The following example illustrates how to define and run tests with
  5533. * CMocka.
  5534. *
  5535. * @code
  5536. * void Test0(void **state);
  5537. * void Test1(void **state);
  5538. *
  5539. * int main(void)
  5540. * {
  5541. * const struct CMUnitTest tests[] = {
  5542. * cmocka_unit_test(Test0),
  5543. * cmocka_unit_test(Test1),
  5544. * };
  5545. *
  5546. * return cmocka_run_group_tests(tests, NULL, NULL);
  5547. * }
  5548. * @endcode
  5549. *
  5550. * @{
  5551. */
  5552. #ifdef DOXYGEN
  5553. /**
  5554. * @brief Forces the test to fail immediately and quit.
  5555. */
  5556. void fail(void);
  5557. #else
  5558. #define fail() _fail(__FILE__, __LINE__)
  5559. #endif
  5560. #ifdef DOXYGEN
  5561. /**
  5562. * @brief Forces the test to not be executed, but marked as skipped.
  5563. */
  5564. void skip(void);
  5565. #else
  5566. #define skip() _skip(__FILE__, __LINE__)
  5567. #endif
  5568. #ifdef DOXYGEN
  5569. /**
  5570. * @brief Forces the test to be stopped immediately.
  5571. *
  5572. * Call stop() to stop a running test.
  5573. * The test is considered passed if there are no leftover values, otherwise a test failure
  5574. * is signaled.
  5575. * Calling stop() is especially useful in mocked functions that do not return, e.g reset the CPU.
  5576. */
  5577. void stop(void);
  5578. #else
  5579. #define stop() _stop()
  5580. #endif
  5581. #ifdef DOXYGEN
  5582. /**
  5583. * @brief Forces the test to fail immediately and quit, printing the reason.
  5584. *
  5585. * @code
  5586. * fail_msg("This is some error message for test");
  5587. * @endcode
  5588. *
  5589. * or
  5590. *
  5591. * @code
  5592. * char *error_msg = "This is some error message for test";
  5593. * fail_msg("%s", error_msg);
  5594. * @endcode
  5595. */
  5596. void fail_msg(const char *msg, ...);
  5597. #else
  5598. #define fail_msg(msg, ...) do { \
  5599. cmocka_print_error("ERROR: " msg "\n", ##__VA_ARGS__); \
  5600. fail(); \
  5601. } while (0)
  5602. #endif
  5603. static inline void _unit_test_dummy(void **state) {
  5604. (void)state;
  5605. }
  5606. /** Initializes a UnitTest structure.
  5607. *
  5608. * @deprecated This function was deprecated in favor of cmocka_unit_test
  5609. */
  5610. #define unit_test(f) \
  5611. (CMOCKA_DEPRECATION_WARNING("unit_test: use cmocka_unit_test instead")( \
  5612. UnitTest){#f, f, UNIT_TEST_FUNCTION_TYPE_TEST})
  5613. /** @cond INTERNAL */
  5614. #define _unit_test_setup(test, setup) \
  5615. { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP }
  5616. /** @endcond */
  5617. /** Initializes a UnitTest structure with a setup function.
  5618. *
  5619. * @deprecated This function was deprecated in favor of cmocka_unit_test_setup
  5620. */
  5621. #define unit_test_setup(test, setup) \
  5622. CMOCKA_DEPRECATION_WARNING( \
  5623. "unit_test_setup: use cmocka_unit_test_setup instead") \
  5624. _unit_test_setup(test, setup), unit_test(test), \
  5625. _unit_test_teardown(test, _unit_test_dummy)
  5626. /** @cond INTERNAL */
  5627. #define _unit_test_teardown(test, teardown) \
  5628. { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN }
  5629. /** @endcond */
  5630. /** Initializes a UnitTest structure with a teardown function.
  5631. *
  5632. * @deprecated This function was deprecated in favor of cmocka_unit_test_teardown
  5633. */
  5634. #define unit_test_teardown(test, teardown) \
  5635. CMOCKA_DEPRECATION_WARNING( \
  5636. "unit_test_teardown: use cmocka_unit_test_teardown instead") \
  5637. _unit_test_setup(test, _unit_test_dummy), unit_test(test), \
  5638. _unit_test_teardown(test, teardown)
  5639. /** Initializes a UnitTest structure for a group setup function.
  5640. *
  5641. * @deprecated This function was deprecated in favor of cmocka_run_group_tests
  5642. */
  5643. #define group_test_setup(setup) \
  5644. (CMOCKA_DEPRECATION_WARNING( \
  5645. "group_test_setup: use cmocka_run_group_tests instead")(UnitTest){ \
  5646. "group_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP})
  5647. /** Initializes a UnitTest structure for a group teardown function.
  5648. *
  5649. * @deprecated This function was deprecated in favor of cmocka_run_group_tests
  5650. */
  5651. #define group_test_teardown(teardown) \
  5652. (CMOCKA_DEPRECATION_WARNING( \
  5653. "group_test_teardown: use cmocka_run_group_tests instead")(UnitTest){ \
  5654. "group_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN})
  5655. /**
  5656. * Initialize an array of UnitTest structures with a setup function for a test
  5657. * and a teardown function. Either setup or teardown can be NULL.
  5658. *
  5659. * @deprecated This function was deprecated in favor of
  5660. * cmocka_unit_test_setup_teardown
  5661. */
  5662. #define unit_test_setup_teardown(test, setup, teardown) \
  5663. CMOCKA_DEPRECATION_WARNING("unit_test_setup_teardown: use " \
  5664. "cmocka_unit_test_setup_teardown instead") \
  5665. _unit_test_setup(test, setup), unit_test(test), \
  5666. _unit_test_teardown(test, teardown)
  5667. /** Initializes a CMUnitTest structure. */
  5668. #define cmocka_unit_test(f) { #f, f, NULL, NULL, NULL }
  5669. /** Initializes a CMUnitTest structure with a setup function. */
  5670. #define cmocka_unit_test_setup(f, setup) { #f, f, setup, NULL, NULL }
  5671. /** Initializes a CMUnitTest structure with a teardown function. */
  5672. #define cmocka_unit_test_teardown(f, teardown) { #f, f, NULL, teardown, NULL }
  5673. /**
  5674. * Initialize an array of CMUnitTest structures with a setup function for a test
  5675. * and a teardown function. Either setup or teardown can be NULL.
  5676. */
  5677. #define cmocka_unit_test_setup_teardown(f, setup, teardown) { #f, f, setup, teardown, NULL }
  5678. /**
  5679. * Initialize a CMUnitTest structure with given initial state. It will be passed
  5680. * to test function as an argument later. It can be used when test state does
  5681. * not need special initialization or was initialized already.
  5682. * @note If the group setup function initialized the state already, it won't be
  5683. * overridden by the initial state defined here.
  5684. */
  5685. #define cmocka_unit_test_prestate(f, state) { #f, f, NULL, NULL, state }
  5686. /**
  5687. * Initialize a CMUnitTest structure with given initial state, setup and
  5688. * teardown function. Any of these values can be NULL. Initial state is passed
  5689. * later to setup function, or directly to test if none was given.
  5690. * @note If the group setup function initialized the state already, it won't be
  5691. * overridden by the initial state defined here.
  5692. */
  5693. #define cmocka_unit_test_prestate_setup_teardown(f, setup, teardown, state) { #f, f, setup, teardown, state }
  5694. #ifdef DOXYGEN
  5695. /**
  5696. * @brief Run tests specified by an array of CMUnitTest structures.
  5697. *
  5698. * @param[in] group_tests[] The array of unit tests to execute.
  5699. *
  5700. * @param[in] group_setup The setup function which should be called before
  5701. * all unit tests are executed.
  5702. *
  5703. * @param[in] group_teardown The teardown function to be called after all
  5704. * tests have finished.
  5705. *
  5706. * @return 0 on success, or the number of failed tests.
  5707. *
  5708. * @code
  5709. * static int setup(void **state) {
  5710. * int *answer = malloc(sizeof(int));
  5711. * if (answer == NULL) {
  5712. * return -1;
  5713. * }
  5714. * *answer = 42;
  5715. *
  5716. * *state = answer;
  5717. *
  5718. * return 0;
  5719. * }
  5720. *
  5721. * static int teardown(void **state) {
  5722. * free(*state);
  5723. *
  5724. * return 0;
  5725. * }
  5726. *
  5727. * static void null_test_success(void **state) {
  5728. * (void) state;
  5729. * }
  5730. *
  5731. * static void int_test_success(void **state) {
  5732. * int *answer = *state;
  5733. * assert_int_equal(*answer, 42);
  5734. * }
  5735. *
  5736. * int main(void) {
  5737. * const struct CMUnitTest tests[] = {
  5738. * cmocka_unit_test(null_test_success),
  5739. * cmocka_unit_test_setup_teardown(int_test_success, setup, teardown),
  5740. * };
  5741. *
  5742. * return cmocka_run_group_tests(tests, NULL, NULL);
  5743. * }
  5744. * @endcode
  5745. *
  5746. * @see cmocka_unit_test
  5747. * @see cmocka_unit_test_setup
  5748. * @see cmocka_unit_test_teardown
  5749. * @see cmocka_unit_test_setup_teardown
  5750. */
  5751. int cmocka_run_group_tests(const struct CMUnitTest group_tests[],
  5752. CMFixtureFunction group_setup,
  5753. CMFixtureFunction group_teardown);
  5754. #else
  5755. # define cmocka_run_group_tests(group_tests, group_setup, group_teardown) \
  5756. _cmocka_run_group_tests(#group_tests, group_tests, sizeof(group_tests) / sizeof((group_tests)[0]), group_setup, group_teardown)
  5757. #endif
  5758. #ifdef DOXYGEN
  5759. /**
  5760. * @brief Run tests specified by an array of CMUnitTest structures and specify
  5761. * a name.
  5762. *
  5763. * @param[in] group_name The name of the group test.
  5764. *
  5765. * @param[in] group_tests[] The array of unit tests to execute.
  5766. *
  5767. * @param[in] group_setup The setup function which should be called before
  5768. * all unit tests are executed.
  5769. *
  5770. * @param[in] group_teardown The teardown function to be called after all
  5771. * tests have finished.
  5772. *
  5773. * @return 0 on success, or the number of failed tests.
  5774. *
  5775. * @code
  5776. * static int setup(void **state) {
  5777. * int *answer = malloc(sizeof(int));
  5778. * if (answer == NULL) {
  5779. * return -1;
  5780. * }
  5781. * *answer = 42;
  5782. *
  5783. * *state = answer;
  5784. *
  5785. * return 0;
  5786. * }
  5787. *
  5788. * static int teardown(void **state) {
  5789. * free(*state);
  5790. *
  5791. * return 0;
  5792. * }
  5793. *
  5794. * static void null_test_success(void **state) {
  5795. * (void) state;
  5796. * }
  5797. *
  5798. * static void int_test_success(void **state) {
  5799. * int *answer = *state;
  5800. * assert_int_equal(*answer, 42);
  5801. * }
  5802. *
  5803. * int main(void) {
  5804. * const struct CMUnitTest tests[] = {
  5805. * cmocka_unit_test(null_test_success),
  5806. * cmocka_unit_test_setup_teardown(int_test_success, setup, teardown),
  5807. * };
  5808. *
  5809. * return cmocka_run_group_tests_name("success_test", tests, NULL, NULL);
  5810. * }
  5811. * @endcode
  5812. *
  5813. * @see cmocka_unit_test
  5814. * @see cmocka_unit_test_setup
  5815. * @see cmocka_unit_test_teardown
  5816. * @see cmocka_unit_test_setup_teardown
  5817. */
  5818. int cmocka_run_group_tests_name(const char *group_name,
  5819. const struct CMUnitTest group_tests[],
  5820. CMFixtureFunction group_setup,
  5821. CMFixtureFunction group_teardown);
  5822. #else
  5823. # define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown) \
  5824. _cmocka_run_group_tests(group_name, group_tests, sizeof(group_tests) / sizeof((group_tests)[0]), group_setup, group_teardown)
  5825. #endif
  5826. /** @} */ /* cmocka_exec */
  5827. /**
  5828. * @defgroup cmocka_alloc 🧩 Dynamic Memory Allocation
  5829. * @ingroup cmocka
  5830. * @brief Detect memory leaks, buffer overflows, and allocation errors.
  5831. *
  5832. * @warning This shouldn't be used anymore, better use
  5833. * <a href="https://clang.llvm.org/docs/AddressSanitizer.html">AddressSanitizer</a>.
  5834. *
  5835. * To test for memory leaks, buffer overflows and underflows a module being
  5836. * tested by cmocka should replace calls to malloc(), calloc() and free() to
  5837. * test_malloc(), test_calloc() and test_free() respectively. Each time a block
  5838. * is deallocated using test_free() it is checked for corruption, if a corrupt
  5839. * block is found a test failure is signalled. All blocks allocated using the
  5840. * test_*() allocation functions are tracked by the cmocka library. When a test
  5841. * completes if any allocated blocks (memory leaks) remain they are reported
  5842. * and a test failure is signalled.
  5843. *
  5844. * For simplicity cmocka currently executes all tests in one process. Therefore
  5845. * all test cases in a test application share a single address space which
  5846. * means memory corruption from a single test case could potentially cause the
  5847. * test application to exit prematurely.
  5848. *
  5849. * <b>Automatic Allocation Redirection (Deprecated):</b>
  5850. *
  5851. * When both UNIT_TESTING and ALLOCATION_TESTING are defined, the standard
  5852. * C library allocation functions (malloc, calloc, realloc, free) are
  5853. * automatically redirected to cmocka's test allocators. This enables
  5854. * automatic memory leak detection and helps ensure proper memory management
  5855. * in tested code.
  5856. *
  5857. * @note This feature is deprecated and should not be used in new code.
  5858. * Better use
  5859. * <a href="https://clang.llvm.org/docs/AddressSanitizer.html">AddressSanitizer</a>.
  5860. *
  5861. * To enable allocation testing, define both macros before including cmocka.h:
  5862. *
  5863. * @code
  5864. * #include <stdlib.h>
  5865. *
  5866. * #define UNIT_TESTING 1
  5867. * #define ALLOCATION_TESTING 1
  5868. * #include <cmocka.h>
  5869. *
  5870. * // This code will have malloc/free automatically redirected
  5871. * void* ptr = malloc(100); // Actually calls test_malloc()
  5872. * free(ptr); // Actually calls test_free()
  5873. * @endcode
  5874. *
  5875. * With ALLOCATION_TESTING enabled:
  5876. * - malloc() → test_malloc()
  5877. * - calloc() → test_calloc()
  5878. * - realloc() → test_realloc()
  5879. * - free() → test_free()
  5880. *
  5881. * @warning Mixing regular allocations with test allocations can lead to
  5882. * memory corruption. Ensure consistent usage throughout your
  5883. * test code.
  5884. * @{
  5885. */
  5886. #ifdef DOXYGEN
  5887. /**
  5888. * @brief Test function overriding malloc.
  5889. *
  5890. * @param[in] size The bytes which should be allocated.
  5891. *
  5892. * @return A pointer to the allocated memory or NULL on error.
  5893. *
  5894. * @code
  5895. * #ifdef UNIT_TESTING
  5896. * extern void* _test_malloc(const size_t size, const char* file, const int line);
  5897. *
  5898. * #define malloc(size) _test_malloc(size, __FILE__, __LINE__)
  5899. * #endif
  5900. *
  5901. * void leak_memory() {
  5902. * int * const temporary = (int*)malloc(sizeof(int));
  5903. * *temporary = 0;
  5904. * }
  5905. * @endcode
  5906. *
  5907. * @see malloc(3)
  5908. */
  5909. void *test_malloc(size_t size);
  5910. #else
  5911. #define test_malloc(size) _test_malloc(size, __FILE__, __LINE__)
  5912. #endif
  5913. #ifdef DOXYGEN
  5914. /**
  5915. * @brief Test function overriding calloc.
  5916. *
  5917. * The memory is set to zero.
  5918. *
  5919. * @param[in] nmemb The number of elements for an array to be allocated.
  5920. *
  5921. * @param[in] size The size in bytes of each array element to allocate.
  5922. *
  5923. * @return A pointer to the allocated memory, NULL on error.
  5924. *
  5925. * @see calloc(3)
  5926. */
  5927. void *test_calloc(size_t nmemb, size_t size);
  5928. #else
  5929. #define test_calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
  5930. #endif
  5931. #ifdef DOXYGEN
  5932. /**
  5933. * @brief Test function overriding realloc which detects buffer overruns
  5934. * and memory leaks.
  5935. *
  5936. * @param[in] ptr The memory block which should be changed.
  5937. *
  5938. * @param[in] size The bytes which should be allocated.
  5939. *
  5940. * @return The newly allocated memory block, NULL on error.
  5941. */
  5942. void *test_realloc(void *ptr, size_t size);
  5943. #else
  5944. #define test_realloc(ptr, size) _test_realloc(ptr, size, __FILE__, __LINE__)
  5945. #endif
  5946. #ifdef DOXYGEN
  5947. /**
  5948. * @brief Test function overriding free(3).
  5949. *
  5950. * @param[in] ptr The pointer to the memory space to free.
  5951. *
  5952. * @see free(3).
  5953. */
  5954. void test_free(void *ptr);
  5955. #else
  5956. #define test_free(ptr) _test_free(ptr, __FILE__, __LINE__)
  5957. #endif
  5958. #if defined(UNIT_TESTING) && defined(ALLOCATION_TESTING)
  5959. #define malloc test_malloc
  5960. #define realloc test_realloc
  5961. #define calloc test_calloc
  5962. #define free test_free
  5963. #endif /* UNIT_TESTING && ALLOCATION_TESTING */
  5964. /** @} */ /* cmocka_alloc */
  5965. /**
  5966. * @defgroup cmocka_mock_assert 🎯 Standard Assertions
  5967. * @ingroup cmocka
  5968. * @brief Test code that uses assert(3) from the standard C library.
  5969. *
  5970. * How to handle assert(3) of the standard C library.
  5971. *
  5972. * Runtime assert macros like the standard C library's assert() should be
  5973. * redefined in modules being tested to use cmocka's mock_assert() function.
  5974. * Normally mock_assert() signals a test failure. If a function is called using
  5975. * the expect_assert_failure() macro, any calls to mock_assert() within the
  5976. * function will result in the execution of the test. If no calls to
  5977. * mock_assert() occur during the function called via expect_assert_failure() a
  5978. * test failure is signalled.
  5979. *
  5980. * @{
  5981. */
  5982. /**
  5983. * @brief Function to replace assert(3) in tested code.
  5984. *
  5985. * In conjunction with check_assert() it's possible to determine whether an
  5986. * assert condition has failed without stopping a test.
  5987. *
  5988. * @param[in] result The expression to assert.
  5989. *
  5990. * @param[in] expression The expression as string.
  5991. *
  5992. * @param[in] file The file mock_assert() is called.
  5993. *
  5994. * @param[in] line The line mock_assert() is called.
  5995. *
  5996. * @code
  5997. * #ifdef UNIT_TESTING
  5998. * extern void mock_assert(const int result, const char* const expression,
  5999. * const char * const file, const int line);
  6000. *
  6001. * #undef assert
  6002. * #define assert(expression) \
  6003. * mock_assert((int)(expression), #expression, __FILE__, __LINE__);
  6004. * #endif
  6005. *
  6006. * void increment_value(int * const value) {
  6007. * assert(value);
  6008. * (*value) ++;
  6009. * }
  6010. * @endcode
  6011. *
  6012. * @see assert(3)
  6013. * @see expect_assert_failure
  6014. */
  6015. void mock_assert(const int result, const char* const expression,
  6016. const char * const file, const int line);
  6017. #ifdef DOXYGEN
  6018. /**
  6019. * @brief Ensure that mock_assert() is called.
  6020. *
  6021. * If mock_assert() is called the assert expression string is returned.
  6022. *
  6023. * @param[in] fn_call The function will will call mock_assert().
  6024. *
  6025. * @code
  6026. * #define assert mock_assert
  6027. *
  6028. * void showmessage(const char *message) {
  6029. * assert(message);
  6030. * }
  6031. *
  6032. * int main(int argc, const char* argv[]) {
  6033. * expect_assert_failure(show_message(NULL));
  6034. * printf("succeeded\n");
  6035. * return 0;
  6036. * }
  6037. * @endcode
  6038. *
  6039. */
  6040. void expect_assert_failure(function fn_call);
  6041. #else
  6042. #define expect_assert_failure(function_call) \
  6043. { \
  6044. global_expecting_assert = 1; \
  6045. if (setjmp(global_expect_assert_env) != 0) { \
  6046. print_message("Expected assertion %s occurred\n", \
  6047. global_last_failed_assert); \
  6048. global_expecting_assert = 0; \
  6049. } else { \
  6050. function_call ; \
  6051. global_expecting_assert = 0; \
  6052. print_error("Expected assert in %s\n", #function_call); \
  6053. _fail(__FILE__, __LINE__); \
  6054. } \
  6055. }
  6056. #endif
  6057. /** @} */ /* cmocka_mock_assert */
  6058. /**
  6059. * @ingroup cmocka_util
  6060. *
  6061. * CMocka value data type.
  6062. *
  6063. * Allows storing multiple types of values in CMocka functions without using
  6064. * undefined behavior.
  6065. */
  6066. typedef union {
  6067. /** Holds signed integral types */
  6068. intmax_t int_val;
  6069. /** Holds integral types */
  6070. uintmax_t uint_val;
  6071. /** Holds floating-point type */
  6072. float float_val;
  6073. /** Holds double/real floating-pointing types*/
  6074. double real_val; // TODO: Should we use `long double` instead
  6075. /** Holds pointer data */
  6076. void *ptr;
  6077. /** Holds pointer data (const) */
  6078. const void *const_ptr;
  6079. // The following aren't used by CMocka currently, but are added to avoid
  6080. // breaking ABI compatibility in the future
  6081. /** Holds function pointer data */
  6082. void *(*func)(void);
  6083. } CMockaValueData;
  6084. #ifndef DOXYGEN
  6085. /**
  6086. * @deprecated This type was replaced by uintmax_t for better type clarity.
  6087. * Use uintmax_t directly instead.
  6088. */
  6089. #define LargestIntegralType uintmax_t
  6090. /**
  6091. * @deprecated Use cast_ptr_to_uintmax_type instead
  6092. */
  6093. #if defined(__GNUC__)
  6094. #define cast_ptr_to_largest_integral_type(value) \
  6095. __extension__({ \
  6096. CMOCKA_DEPRECATION_WARNING( \
  6097. "cast_ptr_to_largest_integral_type: " \
  6098. "use cast_ptr_to_uintmax_type instead"); \
  6099. cast_ptr_to_uintmax_type(value); \
  6100. })
  6101. #else
  6102. #define cast_ptr_to_largest_integral_type(value) \
  6103. cast_ptr_to_uintmax_type(value)
  6104. #endif
  6105. #endif
  6106. /**
  6107. * @ingroup cmocka_exec
  6108. *
  6109. * Function prototype for setup, test and teardown functions.
  6110. */
  6111. typedef void (*UnitTestFunction)(void **state);
  6112. /**
  6113. * @ingroup cmocka_param
  6114. *
  6115. * Function that determines whether a function parameter value is correct (old API).
  6116. */
  6117. typedef int (*CheckParameterValue)(const uintmax_t value,
  6118. const uintmax_t check_value_data);
  6119. /**
  6120. * @ingroup cmocka_param
  6121. *
  6122. * Function that determines whether a function parameter value is correct (new API with CMockaValueData).
  6123. */
  6124. typedef int (*CheckParameterValueData)(const CMockaValueData value,
  6125. const CMockaValueData check_value_data);
  6126. /**
  6127. * @ingroup cmocka_param
  6128. *
  6129. * Function that determines whether a function parameter value is correct.
  6130. */
  6131. typedef int (*CheckIntParameterValue)(const intmax_t value,
  6132. const intmax_t check_value_data);
  6133. /**
  6134. * @ingroup cmocka_param
  6135. *
  6136. * Function that determines whether a function parameter value is correct.
  6137. */
  6138. typedef int (*CheckUintParameterValue)(const uintmax_t value,
  6139. const uintmax_t check_value_data);
  6140. /**
  6141. * @ingroup cmocka_exec
  6142. *
  6143. * Type of the unit test function.
  6144. */
  6145. typedef enum UnitTestFunctionType {
  6146. UNIT_TEST_FUNCTION_TYPE_TEST = 0,
  6147. UNIT_TEST_FUNCTION_TYPE_SETUP,
  6148. UNIT_TEST_FUNCTION_TYPE_TEARDOWN,
  6149. UNIT_TEST_FUNCTION_TYPE_GROUP_SETUP,
  6150. UNIT_TEST_FUNCTION_TYPE_GROUP_TEARDOWN,
  6151. } UnitTestFunctionType;
  6152. /**
  6153. * @ingroup cmocka_exec
  6154. *
  6155. * Stores a unit test function with its name and type.
  6156. * NOTE: Every setup function must be paired with a teardown function. It's
  6157. * possible to specify NULL function pointers.
  6158. */
  6159. typedef struct UnitTest {
  6160. const char* name;
  6161. UnitTestFunction function;
  6162. UnitTestFunctionType function_type;
  6163. } UnitTest;
  6164. /**
  6165. * @ingroup cmocka_exec
  6166. */
  6167. typedef struct GroupTest {
  6168. UnitTestFunction setup;
  6169. UnitTestFunction teardown;
  6170. const UnitTest *tests;
  6171. const size_t number_of_tests;
  6172. } GroupTest;
  6173. /**
  6174. * @ingroup cmocka_exec
  6175. *
  6176. * Function prototype for test functions.
  6177. */
  6178. typedef void (*CMUnitTestFunction)(void **state);
  6179. /**
  6180. * @ingroup cmocka_exec
  6181. *
  6182. * Function prototype for setup and teardown functions.
  6183. */
  6184. typedef int (*CMFixtureFunction)(void **state);
  6185. /**
  6186. * @ingroup cmocka_exec
  6187. */
  6188. struct CMUnitTest {
  6189. const char *name;
  6190. CMUnitTestFunction test_func;
  6191. CMFixtureFunction setup_func;
  6192. CMFixtureFunction teardown_func;
  6193. void *initial_state;
  6194. };
  6195. /**
  6196. * @ingroup cmocka_param
  6197. *
  6198. * Location within some source code.
  6199. */
  6200. typedef struct SourceLocation {
  6201. const char* file;
  6202. int line;
  6203. } SourceLocation;
  6204. /**
  6205. * @ingroup cmocka_param
  6206. *
  6207. * Event that's called to check a parameter value (old API).
  6208. */
  6209. typedef struct CheckParameterEvent {
  6210. SourceLocation location;
  6211. const char *parameter_name;
  6212. CheckParameterValue check_value;
  6213. uintmax_t check_value_data;
  6214. } CheckParameterEvent;
  6215. /**
  6216. * @ingroup cmocka_param
  6217. *
  6218. * Event that's called to check a parameter value (new API with CMockaValueData).
  6219. */
  6220. typedef struct CheckParameterEventData {
  6221. SourceLocation location;
  6222. const char *parameter_name;
  6223. CheckParameterValueData check_value;
  6224. CMockaValueData check_value_data;
  6225. } CheckParameterEventData;
  6226. /**
  6227. * @defgroup cmocka_config 🔧 Configuration and Output
  6228. * @ingroup cmocka
  6229. * @brief Control test output formats and execution behavior.
  6230. *
  6231. * Configure test execution behavior and output formatting.
  6232. *
  6233. * This module provides functions to customize CMocka's behavior, including
  6234. * setting custom output callbacks, controlling output format (STANDARD,
  6235. * SUBUNIT, TAP, XML), and filtering which tests to run or skip.
  6236. *
  6237. * @{
  6238. */
  6239. /* Standard output and error print methods. */
  6240. void print_message(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
  6241. void print_error(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
  6242. void vprint_message(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
  6243. void vprint_error(const char* const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1, 0);
  6244. /**
  6245. * Callbacks which can be set via cmocka_set_callbacks().
  6246. *
  6247. * @ingroup cmocka_config
  6248. * @sa cmocka_set_callbacks()
  6249. */
  6250. struct CMCallbacks {
  6251. /** A callback for printing out standard messages.
  6252. * The supplied callback function will be invoked by the standard output
  6253. * print methods. If no callback has been supplied, the default action
  6254. * is to print to `stdout`.
  6255. *
  6256. * The one exception at present is XML output, which is always written directly
  6257. * to a file handle, even if that is set to `stdout`. */
  6258. void (*vprint_message)(const char * const format, va_list args);
  6259. /** A callback for printing out error messages.
  6260. * The supplied callback function will be invoked by the standard output
  6261. * print methods. If no callback has been supplied, the default action
  6262. * is to print to `stdout`.
  6263. *
  6264. * The one exception at present is XML output, which is always written directly
  6265. * to a file handle, even if that is set to `stdout`. */
  6266. void (*vprint_error)(const char * const format, va_list args);
  6267. };
  6268. /**
  6269. * @brief Set callback functions for CMocka.
  6270. *
  6271. * Input is a structure containing function pointers to one or more
  6272. * user-supplied callback functions. A NULL pointer for a particular
  6273. * callback will set that callback to the default implementation.
  6274. *
  6275. * See the CMCallbacks documentation for details of each callback.
  6276. *
  6277. * @param[in] f_callbacks A structure containing the user callbacks to use.
  6278. *
  6279. * @ingroup cmocka_config
  6280. * @sa CMCallbacks
  6281. */
  6282. void cmocka_set_callbacks(const struct CMCallbacks *f_callbacks);
  6283. /**
  6284. * @brief Output format options for test results.
  6285. *
  6286. * These are bitfield flags that can be combined using bitwise OR to enable
  6287. * multiple output formats simultaneously.
  6288. *
  6289. * @ingroup cmocka_config
  6290. */
  6291. enum cm_message_output {
  6292. /** Standard CMocka output format (bit 0) */
  6293. CM_OUTPUT_STANDARD = 0x00000001,
  6294. /** Alias for CM_OUTPUT_STANDARD (for API compatibility) */
  6295. CM_OUTPUT_STDOUT = 0x00000001,
  6296. /** Subunit output format for test result aggregation (bit 1) */
  6297. CM_OUTPUT_SUBUNIT = 0x00000002,
  6298. /** Test Anything Protocol (TAP) output format (bit 2) */
  6299. CM_OUTPUT_TAP = 0x00000004,
  6300. /** JUnit-compatible XML output format (bit 3) */
  6301. CM_OUTPUT_XML = 0x00000008,
  6302. };
  6303. #ifdef DOXYGEN
  6304. /**
  6305. * @deprecated Use cmocka_print_error()
  6306. */
  6307. void cm_print_error(const char* const format, ...);
  6308. #else
  6309. #define cm_print_error(format, ...) \
  6310. do { \
  6311. CMOCKA_DEPRECATION_WARNING( \
  6312. "cm_print_error: use cmocka_print_error instead") \
  6313. cmocka_print_error(format, ##__VA_ARGS__); \
  6314. } while (0)
  6315. #endif
  6316. /**
  6317. * @brief Print error message using the cmocka output format.
  6318. *
  6319. * This prints an error message using the message output defined by the
  6320. * environment variable CMOCKA_MESSAGE_OUTPUT or
  6321. * cmocka_set_message_output().
  6322. *
  6323. * @param format The format string fprintf(3) uses.
  6324. * @param ... The parameters used to fill format.
  6325. *
  6326. * @ingroup cmocka_config
  6327. */
  6328. void cmocka_print_error(const char* const format, ...) CMOCKA_PRINTF_ATTRIBUTE(1, 2);
  6329. /**
  6330. * @brief Function to set the output format for a test.
  6331. *
  6332. * The output format(s) for the test can either be set globally using this
  6333. * function or overwritten with environment variable CMOCKA_MESSAGE_OUTPUT.
  6334. *
  6335. * The environment variable can be set to STANDARD, SUBUNIT, TAP or XML.
  6336. * Multiple outputs separated with comma are permitted.
  6337. * (e.g. export CMOCKA_MESSAGE_OUTPUT=STANDARD,XML)
  6338. *
  6339. * @param[in] output The output format from cm_message_output to use
  6340. * for the test. For multiple outputs OR options
  6341. * together.
  6342. *
  6343. * @ingroup cmocka_config
  6344. */
  6345. void cmocka_set_message_output(uint32_t output);
  6346. /**
  6347. * @brief Set a pattern to only run the test matching the pattern.
  6348. *
  6349. * This allows to filter tests and only run the ones matching the pattern.
  6350. * The pattern can include two wildcards. The first is '*', a wildcard that
  6351. * matches zero or more characters, or '?', a wildcard that matches exactly
  6352. * one character.
  6353. *
  6354. * The same can also be achieved by setting the environment variable
  6355. * CMOCKA_TEST_FILTER, without needing to recompile the application.
  6356. *
  6357. * @param[in] pattern The pattern to match, e.g. "test_wurst*"
  6358. *
  6359. * @ingroup cmocka_config
  6360. */
  6361. void cmocka_set_test_filter(const char *pattern);
  6362. /**
  6363. * @brief Set a pattern to skip tests matching the pattern.
  6364. *
  6365. * This allows to filter tests and skip the ones matching the pattern. The
  6366. * pattern can include two wildcards. The first is '*', a wildcard that
  6367. * matches zero or more characters, or '?', a wildcard that matches exactly
  6368. * one character.
  6369. *
  6370. * The same can also be achieved by setting the environment variable
  6371. * CMOCKA_SKIP_FILTER, without needing to recompile the application.
  6372. *
  6373. * @param[in] pattern The pattern to match, e.g. "test_wurst*"
  6374. *
  6375. * @ingroup cmocka_config
  6376. */
  6377. void cmocka_set_skip_filter(const char *pattern);
  6378. /** @} */ /* cmocka_config */
  6379. /**
  6380. * @cond INTERNAL
  6381. *
  6382. * Internal functions used by CMocka macros.
  6383. *
  6384. * These functions are implementation details and should not be called directly.
  6385. * Users should only use the documented macros that wrap these functions.
  6386. * These are excluded from the documentation to avoid confusion.
  6387. */
  6388. /* Used by expect_assert_failure() and mock_assert(). */
  6389. CMOCKA_DLLEXTERN extern int global_expecting_assert;
  6390. CMOCKA_DLLEXTERN extern jmp_buf global_expect_assert_env;
  6391. CMOCKA_DLLEXTERN extern const char * global_last_failed_assert;
  6392. /* Retrieves a value for the given function, as set by "will_return". */
  6393. CMockaValueData _mock(const char *const function,
  6394. const char *const file,
  6395. const int line,
  6396. const char *name);
  6397. CMockaValueData _mock_parameter(const char *const function,
  6398. const char *name,
  6399. const char *const file,
  6400. const int line,
  6401. const char *type);
  6402. bool _has_mock(const char *const function);
  6403. void _expect_function_call(
  6404. const char * const function_name,
  6405. const char * const file,
  6406. const int line,
  6407. const int count);
  6408. void _function_called(const char * const function, const char* const file,
  6409. const int line);
  6410. /* Old API function using uintmax_t */
  6411. void _expect_check(
  6412. const char* const function, const char* const parameter,
  6413. const char* const file, const int line,
  6414. const CheckParameterValue check_function,
  6415. const uintmax_t check_data, CheckParameterEvent * const event,
  6416. const int count) CMOCKA_DEPRECATED;
  6417. /* New API function using CMockaValueData */
  6418. void _expect_check_data(
  6419. const char* const function, const char* const parameter,
  6420. const char* const file, const int line,
  6421. const CheckParameterValueData check_function,
  6422. const CMockaValueData check_data, CheckParameterEventData * const event,
  6423. const int count);
  6424. void _expect_int_in_set(const char *const function,
  6425. const char *const parameter,
  6426. const char *const file,
  6427. const size_t line,
  6428. const intmax_t values[],
  6429. const size_t number_of_values,
  6430. const size_t count);
  6431. void _expect_uint_in_set(const char *const function,
  6432. const char *const parameter,
  6433. const char *const file,
  6434. const size_t line,
  6435. const uintmax_t values[],
  6436. const size_t number_of_values,
  6437. const size_t count);
  6438. void _expect_float_in_set(const char *const function,
  6439. const char *const parameter,
  6440. const char *const file,
  6441. const size_t line,
  6442. const double values[],
  6443. const size_t number_of_values,
  6444. const double epsilon,
  6445. const size_t count);
  6446. void _expect_not_in_set(
  6447. const char* const function, const char* const parameter,
  6448. const char* const file, const int line, const uintmax_t values[],
  6449. const size_t number_of_values, const int count);
  6450. void _expect_int_not_in_set(const char *const function,
  6451. const char *const parameter,
  6452. const char *const file,
  6453. const size_t line,
  6454. const intmax_t values[],
  6455. const size_t number_of_values,
  6456. const size_t count);
  6457. void _expect_uint_not_in_set(const char *const function,
  6458. const char *const parameter,
  6459. const char *const file,
  6460. const size_t line,
  6461. const uintmax_t values[],
  6462. const size_t number_of_values,
  6463. const size_t count);
  6464. void _expect_float_not_in_set(
  6465. const char* const function, const char* const parameter,
  6466. const char* const file, const size_t line, const double values[],
  6467. const size_t number_of_values, const double epsilon, const size_t count);
  6468. void _expect_in_range(const char *const function,
  6469. const char *const parameter,
  6470. const char *const file,
  6471. const int line,
  6472. const uintmax_t minimum,
  6473. const uintmax_t maximum,
  6474. const int count) CMOCKA_DEPRECATED;
  6475. void _expect_int_in_range(const char *const function,
  6476. const char *const parameter,
  6477. const char *const file,
  6478. const size_t line,
  6479. const intmax_t minimum,
  6480. const intmax_t maximum,
  6481. const size_t count);
  6482. void _expect_uint_in_range(const char *const function,
  6483. const char *const parameter,
  6484. const char *const file,
  6485. const size_t line,
  6486. const uintmax_t minimum,
  6487. const uintmax_t maximum,
  6488. const size_t count);
  6489. void _expect_not_in_range(
  6490. const char* const function, const char* const parameter,
  6491. const char* const file, const int line,
  6492. const uintmax_t minimum,
  6493. const uintmax_t maximum, const int count);
  6494. void _expect_int_not_in_range(const char *const function,
  6495. const char *const parameter,
  6496. const char *const file,
  6497. const size_t line,
  6498. const intmax_t minimum,
  6499. const intmax_t maximum,
  6500. const size_t count);
  6501. void _expect_uint_not_in_range(const char *const function,
  6502. const char *const parameter,
  6503. const char *const file,
  6504. const size_t line,
  6505. const uintmax_t minimum,
  6506. const uintmax_t maximum,
  6507. const size_t count);
  6508. void _expect_float_in_range(
  6509. const char* const function, const char* const parameter,
  6510. const char* const file, const int line,
  6511. const double minimum, const double maximum, const double epsilon,
  6512. const int count);
  6513. void _expect_float_not_in_range(
  6514. const char* const function, const char* const parameter,
  6515. const char* const file, const int line,
  6516. const double minimum, const double maximum, const double epsilon,
  6517. const int count);
  6518. void _expect_value(
  6519. const char* const function, const char* const parameter,
  6520. const char* const file, const int line, const uintmax_t value,
  6521. const int count);
  6522. void _expect_int_value(const char *const function,
  6523. const char *const parameter,
  6524. const char *const file,
  6525. const size_t line,
  6526. const intmax_t value,
  6527. const size_t count);
  6528. void _expect_uint_value(const char *const function,
  6529. const char *const parameter,
  6530. const char *const file,
  6531. const size_t line,
  6532. const uintmax_t value,
  6533. const size_t count);
  6534. void _expect_int_not_value(const char *const function,
  6535. const char *const parameter,
  6536. const char *const file,
  6537. const size_t line,
  6538. const intmax_t value,
  6539. const size_t count);
  6540. void _expect_uint_not_value(const char *const function,
  6541. const char *const parameter,
  6542. const char *const file,
  6543. const size_t line,
  6544. const uintmax_t value,
  6545. const size_t count);
  6546. void _expect_not_value(
  6547. const char* const function, const char* const parameter,
  6548. const char* const file, const int line, const uintmax_t value,
  6549. const int count);
  6550. void _expect_float(
  6551. const char* const function, const char* const parameter,
  6552. const char* const file, const int line, const double value,
  6553. const double epsilon, const int count);
  6554. void _expect_not_float(
  6555. const char* const function, const char* const parameter,
  6556. const char* const file, const int line, const double value,
  6557. const double epsilon, const int count);
  6558. void _expect_double(const char *const function,
  6559. const char *const parameter,
  6560. const char *const file,
  6561. const int line,
  6562. const double value,
  6563. const double epsilon,
  6564. const int count);
  6565. void _expect_not_double(const char *const function,
  6566. const char *const parameter,
  6567. const char *const file,
  6568. const int line,
  6569. const double value,
  6570. const double epsilon,
  6571. const int count);
  6572. void _expect_string(
  6573. const char* const function, const char* const parameter,
  6574. const char* const file, const int line, const char* string,
  6575. const int count);
  6576. void _expect_not_string(
  6577. const char* const function, const char* const parameter,
  6578. const char* const file, const int line, const char* string,
  6579. const int count);
  6580. void _expect_memory(
  6581. const char* const function, const char* const parameter,
  6582. const char* const file, const int line, const void* const memory,
  6583. const size_t size, const int count);
  6584. void _expect_not_memory(
  6585. const char* const function, const char* const parameter,
  6586. const char* const file, const int line, const void* const memory,
  6587. const size_t size, const int count);
  6588. void _expect_any(
  6589. const char* const function, const char* const parameter,
  6590. const char* const file, const int line, const int count);
  6591. void _check_expected(
  6592. const char * const function_name, const char * const parameter_name,
  6593. const char* file, const int line, const CMockaValueData value);
  6594. void _will_return(const char *const function_name,
  6595. const char *const file,
  6596. const int line,
  6597. const char *name,
  6598. const CMockaValueData value,
  6599. const int count);
  6600. void _will_set_parameter(const char *const function_name,
  6601. const char *name,
  6602. const char *const file,
  6603. const int line,
  6604. const char *type,
  6605. const CMockaValueData value,
  6606. const int count);
  6607. void _assert_true(const uintmax_t result,
  6608. const char* const expression,
  6609. const char * const file, const int line);
  6610. void _assert_false(const uintmax_t result,
  6611. const char * const expression,
  6612. const char * const file, const int line);
  6613. void _assert_return_code(const intmax_t result,
  6614. const int32_t error,
  6615. const char * const expression,
  6616. const char * const file,
  6617. const int line);
  6618. void _assert_float_equal(const float a, const float n,
  6619. const float epsilon, const char* const file,
  6620. const int line);
  6621. void _assert_float_not_equal(const float a, const float n,
  6622. const float epsilon, const char* const file,
  6623. const int line);
  6624. void _assert_double_equal(const double a, const double n,
  6625. const double epsilon, const char* const file,
  6626. const int line);
  6627. void _assert_double_not_equal(const double a, const double n,
  6628. const double epsilon, const char* const file,
  6629. const int line);
  6630. void _assert_int_equal(const intmax_t a,
  6631. const intmax_t b,
  6632. const char * const file,
  6633. const int line);
  6634. void _assert_int_not_equal(const intmax_t a,
  6635. const intmax_t b,
  6636. const char * const file,
  6637. const int line);
  6638. void _assert_uint_equal(const uintmax_t a,
  6639. const uintmax_t b,
  6640. const char * const file,
  6641. const int line);
  6642. void _assert_uint_not_equal(const uintmax_t a,
  6643. const uintmax_t b,
  6644. const char * const file,
  6645. const int line);
  6646. CMOCKA_NO_ACCESS_ATTRIBUTE
  6647. void _assert_ptr_equal_msg(const void *a,
  6648. const void *b,
  6649. const char *const file,
  6650. const int line,
  6651. const char *const msg);
  6652. CMOCKA_NO_ACCESS_ATTRIBUTE
  6653. void _assert_ptr_not_equal_msg(const void *a,
  6654. const void *b,
  6655. const char *const file,
  6656. const int line,
  6657. const char *const msg);
  6658. void _assert_string_equal(const char * const a, const char * const b,
  6659. const char * const file, const int line);
  6660. void _assert_string_not_equal(const char * const a, const char * const b,
  6661. const char *file, const int line);
  6662. void _assert_memory_equal(const void * const a, const void * const b,
  6663. const size_t size, const char* const file,
  6664. const int line);
  6665. void _assert_memory_not_equal(const void * const a, const void * const b,
  6666. const size_t size, const char* const file,
  6667. const int line);
  6668. void _assert_int_in_range(const intmax_t value,
  6669. const intmax_t minimum,
  6670. const intmax_t maximum,
  6671. const char* const file,
  6672. const int line);
  6673. void _assert_int_not_in_range(const intmax_t value,
  6674. const intmax_t minimum,
  6675. const intmax_t maximum,
  6676. const char *const file,
  6677. const int line);
  6678. void _assert_uint_in_range(const uintmax_t value,
  6679. const uintmax_t minimum,
  6680. const uintmax_t maximum,
  6681. const char* const file,
  6682. const int line);
  6683. void _assert_uint_not_in_range(const uintmax_t value,
  6684. const uintmax_t minimum,
  6685. const uintmax_t maximum,
  6686. const char* const file,
  6687. const int line);
  6688. void _assert_float_in_range(const double value,
  6689. const double minimum,
  6690. const double maximum,
  6691. const double epsilon,
  6692. const char* const file,
  6693. const int line);
  6694. void _assert_float_not_in_range(const double value,
  6695. const double minimum,
  6696. const double maximum,
  6697. const double epsilon,
  6698. const char* const file,
  6699. const int line);
  6700. void _assert_not_in_set(
  6701. const uintmax_t value, const uintmax_t values[],
  6702. const size_t number_of_values, const char* const file, const int line);
  6703. void _assert_int_in_set(const intmax_t value,
  6704. const intmax_t values[],
  6705. const size_t number_of_values,
  6706. const char *const file,
  6707. const int line);
  6708. void _assert_int_not_in_set(const intmax_t value,
  6709. const intmax_t values[],
  6710. const size_t number_of_values,
  6711. const char *const file,
  6712. const int line);
  6713. void _assert_uint_in_set(const uintmax_t value,
  6714. const uintmax_t values[],
  6715. const size_t number_of_values,
  6716. const char *const file,
  6717. const int line);
  6718. void _assert_uint_not_in_set(const uintmax_t value,
  6719. const uintmax_t values[],
  6720. const size_t number_of_values,
  6721. const char *const file,
  6722. const int line);
  6723. void _assert_float_in_set(const double value,
  6724. const double values[],
  6725. const size_t number_of_values,
  6726. const double epsilon,
  6727. const char *const file,
  6728. const int line);
  6729. void _assert_float_not_in_set(const double value,
  6730. const double values[],
  6731. const size_t number_of_values,
  6732. const double epsilon,
  6733. const char *const file,
  6734. const int line);
  6735. void* _test_malloc(const size_t size, const char* file, const int line);
  6736. void* _test_realloc(void *ptr, const size_t size, const char* file, const int line);
  6737. void* _test_calloc(const size_t number_of_elements, const size_t size,
  6738. const char* file, const int line);
  6739. void _test_free(void* const ptr, const char* file, const int line);
  6740. CMOCKA_NORETURN void _fail(const char * const file, const int line);
  6741. CMOCKA_NORETURN void _skip(const char * const file, const int line);
  6742. CMOCKA_NORETURN void _stop(void);
  6743. /* Test runner */
  6744. int _cmocka_run_group_tests(const char *group_name,
  6745. const struct CMUnitTest * const tests,
  6746. const size_t num_tests,
  6747. CMFixtureFunction group_setup,
  6748. CMFixtureFunction group_teardown);
  6749. /** @endcond */
  6750. #ifdef __cplusplus
  6751. } /* extern "C" */
  6752. #endif
  6753. #endif /* CMOCKA_H_ */