test_paths.toml 218 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280
  1. # simple path test
  2. [cases.test_paths_simple]
  3. defines.DIR = [false, true]
  4. code = '''
  5. lfs_t lfs;
  6. lfs_format(&lfs, cfg) => 0;
  7. lfs_mount(&lfs, cfg) => 0;
  8. // create paths
  9. lfs_mkdir(&lfs, "coffee") => 0;
  10. if (DIR) {
  11. lfs_mkdir(&lfs, "coffee/drip") => 0;
  12. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  13. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  14. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  15. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  16. lfs_mkdir(&lfs, "coffee/thai") => 0;
  17. } else {
  18. lfs_file_t file;
  19. lfs_file_open(&lfs, &file, "coffee/drip",
  20. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  21. lfs_file_close(&lfs, &file) => 0;
  22. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  23. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  24. lfs_file_close(&lfs, &file) => 0;
  25. lfs_file_open(&lfs, &file, "coffee/turkish",
  26. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  27. lfs_file_close(&lfs, &file) => 0;
  28. lfs_file_open(&lfs, &file, "coffee/tubruk",
  29. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  30. lfs_file_close(&lfs, &file) => 0;
  31. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  32. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  33. lfs_file_close(&lfs, &file) => 0;
  34. lfs_file_open(&lfs, &file, "coffee/thai",
  35. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  36. lfs_file_close(&lfs, &file) => 0;
  37. }
  38. // stat paths
  39. struct lfs_info info;
  40. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  41. assert(strcmp(info.name, "drip") == 0);
  42. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  43. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  44. assert(strcmp(info.name, "coldbrew") == 0);
  45. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  46. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  47. assert(strcmp(info.name, "turkish") == 0);
  48. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  49. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  50. assert(strcmp(info.name, "tubruk") == 0);
  51. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  52. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  53. assert(strcmp(info.name, "vietnamese") == 0);
  54. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  55. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  56. assert(strcmp(info.name, "thai") == 0);
  57. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  58. // file open paths, only works on files!
  59. if (DIR) {
  60. lfs_file_t file;
  61. lfs_file_open(&lfs, &file, "coffee/drip",
  62. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  63. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  64. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  65. lfs_file_open(&lfs, &file, "coffee/turkish",
  66. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  67. lfs_file_open(&lfs, &file, "coffee/tubruk",
  68. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  69. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  70. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  71. lfs_file_open(&lfs, &file, "coffee/thai",
  72. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  73. } else {
  74. lfs_file_t file;
  75. lfs_file_open(&lfs, &file, "coffee/drip",
  76. LFS_O_RDONLY) => 0;
  77. lfs_file_close(&lfs, &file) => 0;
  78. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  79. LFS_O_RDONLY) => 0;
  80. lfs_file_close(&lfs, &file) => 0;
  81. lfs_file_open(&lfs, &file, "coffee/turkish",
  82. LFS_O_RDONLY) => 0;
  83. lfs_file_close(&lfs, &file) => 0;
  84. lfs_file_open(&lfs, &file, "coffee/tubruk",
  85. LFS_O_RDONLY) => 0;
  86. lfs_file_close(&lfs, &file) => 0;
  87. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  88. LFS_O_RDONLY) => 0;
  89. lfs_file_close(&lfs, &file) => 0;
  90. lfs_file_open(&lfs, &file, "coffee/thai",
  91. LFS_O_RDONLY) => 0;
  92. lfs_file_close(&lfs, &file) => 0;
  93. }
  94. // dir open paths, only works on dirs!
  95. if (DIR) {
  96. lfs_dir_t dir;
  97. lfs_dir_open(&lfs, &dir, "coffee/drip") => 0;
  98. lfs_dir_close(&lfs, &dir) => 0;
  99. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => 0;
  100. lfs_dir_close(&lfs, &dir) => 0;
  101. lfs_dir_open(&lfs, &dir, "coffee/turkish") => 0;
  102. lfs_dir_close(&lfs, &dir) => 0;
  103. lfs_dir_open(&lfs, &dir, "coffee/tubruk") => 0;
  104. lfs_dir_close(&lfs, &dir) => 0;
  105. lfs_dir_open(&lfs, &dir, "coffee/vietnamese") => 0;
  106. lfs_dir_close(&lfs, &dir) => 0;
  107. lfs_dir_open(&lfs, &dir, "coffee/thai") => 0;
  108. lfs_dir_close(&lfs, &dir) => 0;
  109. } else {
  110. lfs_dir_t dir;
  111. lfs_dir_open(&lfs, &dir, "coffee/drip") => LFS_ERR_NOTDIR;
  112. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => LFS_ERR_NOTDIR;
  113. lfs_dir_open(&lfs, &dir, "coffee/turkish") => LFS_ERR_NOTDIR;
  114. lfs_dir_open(&lfs, &dir, "coffee/tubruk") => LFS_ERR_NOTDIR;
  115. lfs_dir_open(&lfs, &dir, "coffee/vietnamese") => LFS_ERR_NOTDIR;
  116. lfs_dir_open(&lfs, &dir, "coffee/thai") => LFS_ERR_NOTDIR;
  117. }
  118. // rename paths
  119. lfs_mkdir(&lfs, "espresso") => 0;
  120. lfs_rename(&lfs,
  121. "coffee/drip",
  122. "espresso/espresso") => 0;
  123. lfs_rename(&lfs,
  124. "coffee/coldbrew",
  125. "espresso/americano") => 0;
  126. lfs_rename(&lfs,
  127. "coffee/turkish",
  128. "espresso/macchiato") => 0;
  129. lfs_rename(&lfs,
  130. "coffee/tubruk",
  131. "espresso/latte") => 0;
  132. lfs_rename(&lfs,
  133. "coffee/vietnamese",
  134. "espresso/cappuccino") => 0;
  135. lfs_rename(&lfs,
  136. "coffee/thai",
  137. "espresso/mocha") => 0;
  138. // stat paths
  139. lfs_stat(&lfs, "espresso/espresso", &info) => 0;
  140. assert(strcmp(info.name, "espresso") == 0);
  141. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  142. lfs_stat(&lfs, "espresso/americano", &info) => 0;
  143. assert(strcmp(info.name, "americano") == 0);
  144. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  145. lfs_stat(&lfs, "espresso/macchiato", &info) => 0;
  146. assert(strcmp(info.name, "macchiato") == 0);
  147. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  148. lfs_stat(&lfs, "espresso/latte", &info) => 0;
  149. assert(strcmp(info.name, "latte") == 0);
  150. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  151. lfs_stat(&lfs, "espresso/cappuccino", &info) => 0;
  152. assert(strcmp(info.name, "cappuccino") == 0);
  153. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  154. lfs_stat(&lfs, "espresso/mocha", &info) => 0;
  155. assert(strcmp(info.name, "mocha") == 0);
  156. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  157. lfs_stat(&lfs, "coffee/drip", &info) => LFS_ERR_NOENT;
  158. lfs_stat(&lfs, "coffee/coldbrew", &info) => LFS_ERR_NOENT;
  159. lfs_stat(&lfs, "coffee/turkish", &info) => LFS_ERR_NOENT;
  160. lfs_stat(&lfs, "coffee/tubruk", &info) => LFS_ERR_NOENT;
  161. lfs_stat(&lfs, "coffee/vietnamese", &info) => LFS_ERR_NOENT;
  162. lfs_stat(&lfs, "coffee/thai", &info) => LFS_ERR_NOENT;
  163. // remove paths
  164. lfs_remove(&lfs, "espresso/espresso") => 0;
  165. lfs_remove(&lfs, "espresso/americano") => 0;
  166. lfs_remove(&lfs, "espresso/macchiato") => 0;
  167. lfs_remove(&lfs, "espresso/latte") => 0;
  168. lfs_remove(&lfs, "espresso/cappuccino") => 0;
  169. lfs_remove(&lfs, "espresso/mocha") => 0;
  170. // stat paths
  171. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  172. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  173. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  174. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  175. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  176. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  177. lfs_unmount(&lfs) => 0;
  178. '''
  179. # absolute path test
  180. #
  181. # littlefs does not provide cd, so these are the same as relative paths
  182. [cases.test_paths_absolute]
  183. defines.DIR = [false, true]
  184. code = '''
  185. lfs_t lfs;
  186. lfs_format(&lfs, cfg) => 0;
  187. lfs_mount(&lfs, cfg) => 0;
  188. // create paths
  189. lfs_mkdir(&lfs, "coffee") => 0;
  190. if (DIR) {
  191. lfs_mkdir(&lfs, "/coffee/drip") => 0;
  192. lfs_mkdir(&lfs, "/coffee/coldbrew") => 0;
  193. lfs_mkdir(&lfs, "/coffee/turkish") => 0;
  194. lfs_mkdir(&lfs, "/coffee/tubruk") => 0;
  195. lfs_mkdir(&lfs, "/coffee/vietnamese") => 0;
  196. lfs_mkdir(&lfs, "/coffee/thai") => 0;
  197. } else {
  198. lfs_file_t file;
  199. lfs_file_open(&lfs, &file, "/coffee/drip",
  200. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  201. lfs_file_close(&lfs, &file) => 0;
  202. lfs_file_open(&lfs, &file, "/coffee/coldbrew",
  203. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  204. lfs_file_close(&lfs, &file) => 0;
  205. lfs_file_open(&lfs, &file, "/coffee/turkish",
  206. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  207. lfs_file_close(&lfs, &file) => 0;
  208. lfs_file_open(&lfs, &file, "/coffee/tubruk",
  209. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  210. lfs_file_close(&lfs, &file) => 0;
  211. lfs_file_open(&lfs, &file, "/coffee/vietnamese",
  212. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  213. lfs_file_close(&lfs, &file) => 0;
  214. lfs_file_open(&lfs, &file, "/coffee/thai",
  215. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  216. lfs_file_close(&lfs, &file) => 0;
  217. }
  218. // stat paths
  219. struct lfs_info info;
  220. lfs_stat(&lfs, "/coffee/drip", &info) => 0;
  221. assert(strcmp(info.name, "drip") == 0);
  222. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  223. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  224. assert(strcmp(info.name, "coldbrew") == 0);
  225. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  226. lfs_stat(&lfs, "/coffee/turkish", &info) => 0;
  227. assert(strcmp(info.name, "turkish") == 0);
  228. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  229. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  230. assert(strcmp(info.name, "tubruk") == 0);
  231. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  232. lfs_stat(&lfs, "/coffee/vietnamese", &info) => 0;
  233. assert(strcmp(info.name, "vietnamese") == 0);
  234. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  235. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  236. assert(strcmp(info.name, "thai") == 0);
  237. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  238. // file open paths, only works on files!
  239. if (DIR) {
  240. lfs_file_t file;
  241. lfs_file_open(&lfs, &file, "/coffee/drip",
  242. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  243. lfs_file_open(&lfs, &file, "/coffee/coldbrew",
  244. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  245. lfs_file_open(&lfs, &file, "/coffee/turkish",
  246. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  247. lfs_file_open(&lfs, &file, "/coffee/tubruk",
  248. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  249. lfs_file_open(&lfs, &file, "/coffee/vietnamese",
  250. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  251. lfs_file_open(&lfs, &file, "/coffee/thai",
  252. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  253. } else {
  254. lfs_file_t file;
  255. lfs_file_open(&lfs, &file, "/coffee/drip",
  256. LFS_O_RDONLY) => 0;
  257. lfs_file_close(&lfs, &file) => 0;
  258. lfs_file_open(&lfs, &file, "/coffee/coldbrew",
  259. LFS_O_RDONLY) => 0;
  260. lfs_file_close(&lfs, &file) => 0;
  261. lfs_file_open(&lfs, &file, "/coffee/turkish",
  262. LFS_O_RDONLY) => 0;
  263. lfs_file_close(&lfs, &file) => 0;
  264. lfs_file_open(&lfs, &file, "/coffee/tubruk",
  265. LFS_O_RDONLY) => 0;
  266. lfs_file_close(&lfs, &file) => 0;
  267. lfs_file_open(&lfs, &file, "/coffee/vietnamese",
  268. LFS_O_RDONLY) => 0;
  269. lfs_file_close(&lfs, &file) => 0;
  270. lfs_file_open(&lfs, &file, "/coffee/thai",
  271. LFS_O_RDONLY) => 0;
  272. lfs_file_close(&lfs, &file) => 0;
  273. }
  274. // dir open paths, only works on dirs!
  275. if (DIR) {
  276. lfs_dir_t dir;
  277. lfs_dir_open(&lfs, &dir, "/coffee/drip") => 0;
  278. lfs_dir_close(&lfs, &dir) => 0;
  279. lfs_dir_open(&lfs, &dir, "/coffee/coldbrew") => 0;
  280. lfs_dir_close(&lfs, &dir) => 0;
  281. lfs_dir_open(&lfs, &dir, "/coffee/turkish") => 0;
  282. lfs_dir_close(&lfs, &dir) => 0;
  283. lfs_dir_open(&lfs, &dir, "/coffee/tubruk") => 0;
  284. lfs_dir_close(&lfs, &dir) => 0;
  285. lfs_dir_open(&lfs, &dir, "/coffee/vietnamese") => 0;
  286. lfs_dir_close(&lfs, &dir) => 0;
  287. lfs_dir_open(&lfs, &dir, "/coffee/thai") => 0;
  288. lfs_dir_close(&lfs, &dir) => 0;
  289. } else {
  290. lfs_dir_t dir;
  291. lfs_dir_open(&lfs, &dir, "/coffee/drip") => LFS_ERR_NOTDIR;
  292. lfs_dir_open(&lfs, &dir, "/coffee/coldbrew") => LFS_ERR_NOTDIR;
  293. lfs_dir_open(&lfs, &dir, "/coffee/turkish") => LFS_ERR_NOTDIR;
  294. lfs_dir_open(&lfs, &dir, "/coffee/tubruk") => LFS_ERR_NOTDIR;
  295. lfs_dir_open(&lfs, &dir, "/coffee/vietnamese") => LFS_ERR_NOTDIR;
  296. lfs_dir_open(&lfs, &dir, "/coffee/thai") => LFS_ERR_NOTDIR;
  297. }
  298. // rename paths
  299. lfs_mkdir(&lfs, "espresso") => 0;
  300. lfs_rename(&lfs,
  301. "coffee/drip",
  302. "/espresso/espresso") => 0;
  303. lfs_rename(&lfs,
  304. "coffee/coldbrew",
  305. "/espresso/americano") => 0;
  306. lfs_rename(&lfs,
  307. "/coffee/turkish",
  308. "espresso/macchiato") => 0;
  309. lfs_rename(&lfs,
  310. "/coffee/tubruk",
  311. "espresso/latte") => 0;
  312. lfs_rename(&lfs,
  313. "/coffee/vietnamese",
  314. "/espresso/cappuccino") => 0;
  315. lfs_rename(&lfs,
  316. "/coffee/thai",
  317. "/espresso/mocha") => 0;
  318. // stat paths
  319. lfs_stat(&lfs, "/espresso/espresso", &info) => 0;
  320. assert(strcmp(info.name, "espresso") == 0);
  321. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  322. lfs_stat(&lfs, "espresso/americano", &info) => 0;
  323. assert(strcmp(info.name, "americano") == 0);
  324. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  325. lfs_stat(&lfs, "/espresso/macchiato", &info) => 0;
  326. assert(strcmp(info.name, "macchiato") == 0);
  327. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  328. lfs_stat(&lfs, "espresso/latte", &info) => 0;
  329. assert(strcmp(info.name, "latte") == 0);
  330. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  331. lfs_stat(&lfs, "/espresso/cappuccino", &info) => 0;
  332. assert(strcmp(info.name, "cappuccino") == 0);
  333. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  334. lfs_stat(&lfs, "espresso/mocha", &info) => 0;
  335. assert(strcmp(info.name, "mocha") == 0);
  336. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  337. lfs_stat(&lfs, "/coffee/drip", &info) => LFS_ERR_NOENT;
  338. lfs_stat(&lfs, "/coffee/coldbrew", &info) => LFS_ERR_NOENT;
  339. lfs_stat(&lfs, "/coffee/turkish", &info) => LFS_ERR_NOENT;
  340. lfs_stat(&lfs, "/coffee/tubruk", &info) => LFS_ERR_NOENT;
  341. lfs_stat(&lfs, "/coffee/vietnamese", &info) => LFS_ERR_NOENT;
  342. lfs_stat(&lfs, "/coffee/thai", &info) => LFS_ERR_NOENT;
  343. // remove paths
  344. lfs_remove(&lfs, "/espresso/espresso") => 0;
  345. lfs_remove(&lfs, "/espresso/americano") => 0;
  346. lfs_remove(&lfs, "/espresso/macchiato") => 0;
  347. lfs_remove(&lfs, "/espresso/latte") => 0;
  348. lfs_remove(&lfs, "/espresso/cappuccino") => 0;
  349. lfs_remove(&lfs, "/espresso/mocha") => 0;
  350. // stat paths
  351. lfs_stat(&lfs, "/espresso/espresso", &info) => LFS_ERR_NOENT;
  352. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  353. lfs_stat(&lfs, "/espresso/macchiato", &info) => LFS_ERR_NOENT;
  354. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  355. lfs_stat(&lfs, "/espresso/cappuccino", &info) => LFS_ERR_NOENT;
  356. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  357. lfs_unmount(&lfs) => 0;
  358. '''
  359. # redundant slashes
  360. [cases.test_paths_redundant_slashes]
  361. defines.DIR = [false, true]
  362. code = '''
  363. lfs_t lfs;
  364. lfs_format(&lfs, cfg) => 0;
  365. lfs_mount(&lfs, cfg) => 0;
  366. // create paths
  367. lfs_mkdir(&lfs, "coffee") => 0;
  368. if (DIR) {
  369. lfs_mkdir(&lfs, "/coffee/drip") => 0;
  370. lfs_mkdir(&lfs, "//coffee//coldbrew") => 0;
  371. lfs_mkdir(&lfs, "///coffee///turkish") => 0;
  372. lfs_mkdir(&lfs, "////coffee////tubruk") => 0;
  373. lfs_mkdir(&lfs, "/////coffee/////vietnamese") => 0;
  374. lfs_mkdir(&lfs, "//////coffee//////thai") => 0;
  375. } else {
  376. lfs_file_t file;
  377. lfs_file_open(&lfs, &file, "/coffee/drip",
  378. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  379. lfs_file_close(&lfs, &file) => 0;
  380. lfs_file_open(&lfs, &file, "//coffee//coldbrew",
  381. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  382. lfs_file_close(&lfs, &file) => 0;
  383. lfs_file_open(&lfs, &file, "///coffee///turkish",
  384. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  385. lfs_file_close(&lfs, &file) => 0;
  386. lfs_file_open(&lfs, &file, "////coffee////tubruk",
  387. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  388. lfs_file_close(&lfs, &file) => 0;
  389. lfs_file_open(&lfs, &file, "/////coffee/////vietnamese",
  390. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  391. lfs_file_close(&lfs, &file) => 0;
  392. lfs_file_open(&lfs, &file, "//////coffee//////thai",
  393. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  394. lfs_file_close(&lfs, &file) => 0;
  395. }
  396. // stat paths
  397. struct lfs_info info;
  398. lfs_stat(&lfs, "//////coffee//////drip", &info) => 0;
  399. assert(strcmp(info.name, "drip") == 0);
  400. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  401. lfs_stat(&lfs, "/////coffee/////coldbrew", &info) => 0;
  402. assert(strcmp(info.name, "coldbrew") == 0);
  403. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  404. lfs_stat(&lfs, "////coffee////turkish", &info) => 0;
  405. assert(strcmp(info.name, "turkish") == 0);
  406. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  407. lfs_stat(&lfs, "///coffee///tubruk", &info) => 0;
  408. assert(strcmp(info.name, "tubruk") == 0);
  409. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  410. lfs_stat(&lfs, "//coffee//vietnamese", &info) => 0;
  411. assert(strcmp(info.name, "vietnamese") == 0);
  412. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  413. lfs_stat(&lfs, "/coffee/thai", &info) => 0;
  414. assert(strcmp(info.name, "thai") == 0);
  415. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  416. // file open paths, only works on files!
  417. if (DIR) {
  418. lfs_file_t file;
  419. lfs_file_open(&lfs, &file, "/coffee/drip",
  420. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  421. lfs_file_open(&lfs, &file, "//coffee//coldbrew",
  422. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  423. lfs_file_open(&lfs, &file, "///coffee///turkish",
  424. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  425. lfs_file_open(&lfs, &file, "////coffee////tubruk",
  426. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  427. lfs_file_open(&lfs, &file, "/////coffee/////vietnamese",
  428. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  429. lfs_file_open(&lfs, &file, "//////coffee//////thai",
  430. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  431. } else {
  432. lfs_file_t file;
  433. lfs_file_open(&lfs, &file, "/coffee/drip",
  434. LFS_O_RDONLY) => 0;
  435. lfs_file_close(&lfs, &file) => 0;
  436. lfs_file_open(&lfs, &file, "//coffee//coldbrew",
  437. LFS_O_RDONLY) => 0;
  438. lfs_file_close(&lfs, &file) => 0;
  439. lfs_file_open(&lfs, &file, "///coffee///turkish",
  440. LFS_O_RDONLY) => 0;
  441. lfs_file_close(&lfs, &file) => 0;
  442. lfs_file_open(&lfs, &file, "////coffee////tubruk",
  443. LFS_O_RDONLY) => 0;
  444. lfs_file_close(&lfs, &file) => 0;
  445. lfs_file_open(&lfs, &file, "/////coffee/////vietnamese",
  446. LFS_O_RDONLY) => 0;
  447. lfs_file_close(&lfs, &file) => 0;
  448. lfs_file_open(&lfs, &file, "//////coffee//////thai",
  449. LFS_O_RDONLY) => 0;
  450. lfs_file_close(&lfs, &file) => 0;
  451. }
  452. // dir open paths, only works on dirs!
  453. if (DIR) {
  454. lfs_dir_t dir;
  455. lfs_dir_open(&lfs, &dir, "/coffee/drip") => 0;
  456. lfs_dir_close(&lfs, &dir) => 0;
  457. lfs_dir_open(&lfs, &dir, "//coffee//coldbrew") => 0;
  458. lfs_dir_close(&lfs, &dir) => 0;
  459. lfs_dir_open(&lfs, &dir, "///coffee///turkish") => 0;
  460. lfs_dir_close(&lfs, &dir) => 0;
  461. lfs_dir_open(&lfs, &dir, "////coffee////tubruk") => 0;
  462. lfs_dir_close(&lfs, &dir) => 0;
  463. lfs_dir_open(&lfs, &dir, "/////coffee/////vietnamese") => 0;
  464. lfs_dir_close(&lfs, &dir) => 0;
  465. lfs_dir_open(&lfs, &dir, "//////coffee//////thai") => 0;
  466. lfs_dir_close(&lfs, &dir) => 0;
  467. } else {
  468. lfs_dir_t dir;
  469. lfs_dir_open(&lfs, &dir, "/coffee/drip") => LFS_ERR_NOTDIR;
  470. lfs_dir_open(&lfs, &dir, "//coffee//coldbrew") => LFS_ERR_NOTDIR;
  471. lfs_dir_open(&lfs, &dir, "///coffee///turkish") => LFS_ERR_NOTDIR;
  472. lfs_dir_open(&lfs, &dir, "////coffee////tubruk") => LFS_ERR_NOTDIR;
  473. lfs_dir_open(&lfs, &dir, "/////coffee/////vietnamese") => LFS_ERR_NOTDIR;
  474. lfs_dir_open(&lfs, &dir, "//////coffee//////thai") => LFS_ERR_NOTDIR;
  475. }
  476. // rename paths
  477. lfs_mkdir(&lfs, "espresso") => 0;
  478. lfs_rename(&lfs,
  479. "//////coffee//////drip",
  480. "/espresso/espresso") => 0;
  481. lfs_rename(&lfs,
  482. "/////coffee/////coldbrew",
  483. "//espresso//americano") => 0;
  484. lfs_rename(&lfs,
  485. "////coffee////turkish",
  486. "///espresso///macchiato") => 0;
  487. lfs_rename(&lfs,
  488. "///coffee///tubruk",
  489. "////espresso////latte") => 0;
  490. lfs_rename(&lfs,
  491. "//coffee//vietnamese",
  492. "/////espresso/////cappuccino") => 0;
  493. lfs_rename(&lfs,
  494. "/coffee/thai",
  495. "//////espresso//////mocha") => 0;
  496. // stat paths
  497. lfs_stat(&lfs, "//////espresso//////espresso", &info) => 0;
  498. assert(strcmp(info.name, "espresso") == 0);
  499. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  500. lfs_stat(&lfs, "/////espresso/////americano", &info) => 0;
  501. assert(strcmp(info.name, "americano") == 0);
  502. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  503. lfs_stat(&lfs, "////espresso////macchiato", &info) => 0;
  504. assert(strcmp(info.name, "macchiato") == 0);
  505. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  506. lfs_stat(&lfs, "///espresso///latte", &info) => 0;
  507. assert(strcmp(info.name, "latte") == 0);
  508. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  509. lfs_stat(&lfs, "//espresso//cappuccino", &info) => 0;
  510. assert(strcmp(info.name, "cappuccino") == 0);
  511. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  512. lfs_stat(&lfs, "/espresso/mocha", &info) => 0;
  513. assert(strcmp(info.name, "mocha") == 0);
  514. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  515. lfs_stat(&lfs, "//////coffee//////drip", &info) => LFS_ERR_NOENT;
  516. lfs_stat(&lfs, "/////coffee/////coldbrew", &info) => LFS_ERR_NOENT;
  517. lfs_stat(&lfs, "////coffee////turkish", &info) => LFS_ERR_NOENT;
  518. lfs_stat(&lfs, "///coffee///tubruk", &info) => LFS_ERR_NOENT;
  519. lfs_stat(&lfs, "//coffee//vietnamese", &info) => LFS_ERR_NOENT;
  520. lfs_stat(&lfs, "/coffee/thai", &info) => LFS_ERR_NOENT;
  521. // remove paths
  522. lfs_remove(&lfs, "/espresso/espresso") => 0;
  523. lfs_remove(&lfs, "//espresso//americano") => 0;
  524. lfs_remove(&lfs, "///espresso///macchiato") => 0;
  525. lfs_remove(&lfs, "////espresso////latte") => 0;
  526. lfs_remove(&lfs, "/////espresso/////cappuccino") => 0;
  527. lfs_remove(&lfs, "//////espresso//////mocha") => 0;
  528. // stat paths
  529. lfs_stat(&lfs, "//////espresso//////espresso", &info) => LFS_ERR_NOENT;
  530. lfs_stat(&lfs, "/////espresso/////americano", &info) => LFS_ERR_NOENT;
  531. lfs_stat(&lfs, "////espresso////macchiato", &info) => LFS_ERR_NOENT;
  532. lfs_stat(&lfs, "///espresso///latte", &info) => LFS_ERR_NOENT;
  533. lfs_stat(&lfs, "//espresso//cappuccino", &info) => LFS_ERR_NOENT;
  534. lfs_stat(&lfs, "/espresso/mocha", &info) => LFS_ERR_NOENT;
  535. lfs_unmount(&lfs) => 0;
  536. '''
  537. # test trailing slashes
  538. #
  539. # trailing slashes are only allowed on directories
  540. [cases.test_paths_trailing_slashes]
  541. defines.DIR = [false, true]
  542. code = '''
  543. lfs_t lfs;
  544. lfs_format(&lfs, cfg) => 0;
  545. lfs_mount(&lfs, cfg) => 0;
  546. // create paths
  547. lfs_mkdir(&lfs, "coffee") => 0;
  548. if (DIR) {
  549. lfs_mkdir(&lfs, "coffee/drip/") => 0;
  550. lfs_mkdir(&lfs, "coffee/coldbrew//") => 0;
  551. lfs_mkdir(&lfs, "coffee/turkish///") => 0;
  552. lfs_mkdir(&lfs, "coffee/tubruk////") => 0;
  553. lfs_mkdir(&lfs, "coffee/vietnamese/////") => 0;
  554. lfs_mkdir(&lfs, "coffee/thai//////") => 0;
  555. } else {
  556. lfs_file_t file;
  557. lfs_file_open(&lfs, &file, "coffee/drip/",
  558. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  559. lfs_file_open(&lfs, &file, "coffee/coldbrew//",
  560. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  561. lfs_file_open(&lfs, &file, "coffee/turkish///",
  562. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  563. lfs_file_open(&lfs, &file, "coffee/tubruk////",
  564. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  565. lfs_file_open(&lfs, &file, "coffee/vietnamese/////",
  566. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  567. lfs_file_open(&lfs, &file, "coffee/thai//////",
  568. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_ISDIR;
  569. // still create so we have something to test
  570. lfs_file_open(&lfs, &file, "coffee/drip",
  571. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  572. lfs_file_close(&lfs, &file) => 0;
  573. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  574. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  575. lfs_file_close(&lfs, &file) => 0;
  576. lfs_file_open(&lfs, &file, "coffee/turkish",
  577. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  578. lfs_file_close(&lfs, &file) => 0;
  579. lfs_file_open(&lfs, &file, "coffee/tubruk",
  580. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  581. lfs_file_close(&lfs, &file) => 0;
  582. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  583. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  584. lfs_file_close(&lfs, &file) => 0;
  585. lfs_file_open(&lfs, &file, "coffee/thai",
  586. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  587. lfs_file_close(&lfs, &file) => 0;
  588. }
  589. // stat paths
  590. struct lfs_info info;
  591. if (DIR) {
  592. lfs_stat(&lfs, "coffee/drip//////", &info) => 0;
  593. assert(strcmp(info.name, "drip") == 0);
  594. assert(info.type == LFS_TYPE_DIR);
  595. lfs_stat(&lfs, "coffee/coldbrew/////", &info) => 0;
  596. assert(strcmp(info.name, "coldbrew") == 0);
  597. assert(info.type == LFS_TYPE_DIR);
  598. lfs_stat(&lfs, "coffee/turkish////", &info) => 0;
  599. assert(strcmp(info.name, "turkish") == 0);
  600. assert(info.type == LFS_TYPE_DIR);
  601. lfs_stat(&lfs, "coffee/tubruk///", &info) => 0;
  602. assert(strcmp(info.name, "tubruk") == 0);
  603. assert(info.type == LFS_TYPE_DIR);
  604. lfs_stat(&lfs, "coffee/vietnamese//", &info) => 0;
  605. assert(strcmp(info.name, "vietnamese") == 0);
  606. assert(info.type == LFS_TYPE_DIR);
  607. lfs_stat(&lfs, "coffee/thai/", &info) => 0;
  608. assert(strcmp(info.name, "thai") == 0);
  609. assert(info.type == LFS_TYPE_DIR);
  610. } else {
  611. lfs_stat(&lfs, "coffee/drip//////", &info) => LFS_ERR_NOTDIR;
  612. lfs_stat(&lfs, "coffee/coldbrew/////", &info) => LFS_ERR_NOTDIR;
  613. lfs_stat(&lfs, "coffee/turkish////", &info) => LFS_ERR_NOTDIR;
  614. lfs_stat(&lfs, "coffee/tubruk///", &info) => LFS_ERR_NOTDIR;
  615. lfs_stat(&lfs, "coffee/vietnamese//", &info) => LFS_ERR_NOTDIR;
  616. lfs_stat(&lfs, "coffee/thai/", &info) => LFS_ERR_NOTDIR;
  617. }
  618. // file open paths, only works on files!
  619. if (DIR) {
  620. lfs_file_t file;
  621. lfs_file_open(&lfs, &file, "coffee/drip/",
  622. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  623. lfs_file_open(&lfs, &file, "coffee/coldbrew//",
  624. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  625. lfs_file_open(&lfs, &file, "coffee/turkish///",
  626. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  627. lfs_file_open(&lfs, &file, "coffee/tubruk////",
  628. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  629. lfs_file_open(&lfs, &file, "coffee/vietnamese/////",
  630. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  631. lfs_file_open(&lfs, &file, "coffee/thai//////",
  632. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  633. } else {
  634. lfs_file_t file;
  635. lfs_file_open(&lfs, &file, "coffee/drip/",
  636. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  637. lfs_file_open(&lfs, &file, "coffee/coldbrew//",
  638. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  639. lfs_file_open(&lfs, &file, "coffee/turkish///",
  640. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  641. lfs_file_open(&lfs, &file, "coffee/tubruk////",
  642. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  643. lfs_file_open(&lfs, &file, "coffee/vietnamese/////",
  644. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  645. lfs_file_open(&lfs, &file, "coffee/thai//////",
  646. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  647. }
  648. // dir open paths, only works on dirs!
  649. if (DIR) {
  650. lfs_dir_t dir;
  651. lfs_dir_open(&lfs, &dir, "coffee/drip/") => 0;
  652. lfs_dir_close(&lfs, &dir) => 0;
  653. lfs_dir_open(&lfs, &dir, "coffee/coldbrew//") => 0;
  654. lfs_dir_close(&lfs, &dir) => 0;
  655. lfs_dir_open(&lfs, &dir, "coffee/turkish///") => 0;
  656. lfs_dir_close(&lfs, &dir) => 0;
  657. lfs_dir_open(&lfs, &dir, "coffee/tubruk////") => 0;
  658. lfs_dir_close(&lfs, &dir) => 0;
  659. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/////") => 0;
  660. lfs_dir_close(&lfs, &dir) => 0;
  661. lfs_dir_open(&lfs, &dir, "coffee/thai//////") => 0;
  662. lfs_dir_close(&lfs, &dir) => 0;
  663. } else {
  664. lfs_dir_t dir;
  665. lfs_dir_open(&lfs, &dir, "coffee/drip/") => LFS_ERR_NOTDIR;
  666. lfs_dir_open(&lfs, &dir, "coffee/coldbrew//") => LFS_ERR_NOTDIR;
  667. lfs_dir_open(&lfs, &dir, "coffee/turkish///") => LFS_ERR_NOTDIR;
  668. lfs_dir_open(&lfs, &dir, "coffee/tubruk////") => LFS_ERR_NOTDIR;
  669. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/////") => LFS_ERR_NOTDIR;
  670. lfs_dir_open(&lfs, &dir, "coffee/thai//////") => LFS_ERR_NOTDIR;
  671. }
  672. // rename paths
  673. lfs_mkdir(&lfs, "espresso") => 0;
  674. if (DIR) {
  675. lfs_rename(&lfs,
  676. "coffee/drip//////",
  677. "espresso/espresso/") => 0;
  678. lfs_rename(&lfs,
  679. "coffee/coldbrew/////",
  680. "espresso/americano//") => 0;
  681. lfs_rename(&lfs,
  682. "coffee/turkish////",
  683. "espresso/macchiato///") => 0;
  684. lfs_rename(&lfs,
  685. "coffee/tubruk///",
  686. "espresso/latte////") => 0;
  687. lfs_rename(&lfs,
  688. "coffee/vietnamese//",
  689. "espresso/cappuccino/////") => 0;
  690. lfs_rename(&lfs,
  691. "coffee/thai/",
  692. "espresso/mocha//////") => 0;
  693. // stat paths
  694. lfs_stat(&lfs, "espresso/espresso//////", &info) => 0;
  695. assert(strcmp(info.name, "espresso") == 0);
  696. assert(info.type == LFS_TYPE_DIR);
  697. lfs_stat(&lfs, "espresso/americano/////", &info) => 0;
  698. assert(strcmp(info.name, "americano") == 0);
  699. assert(info.type == LFS_TYPE_DIR);
  700. lfs_stat(&lfs, "espresso/macchiato////", &info) => 0;
  701. assert(strcmp(info.name, "macchiato") == 0);
  702. assert(info.type == LFS_TYPE_DIR);
  703. lfs_stat(&lfs, "espresso/latte///", &info) => 0;
  704. assert(strcmp(info.name, "latte") == 0);
  705. assert(info.type == LFS_TYPE_DIR);
  706. lfs_stat(&lfs, "espresso/cappuccino//", &info) => 0;
  707. assert(strcmp(info.name, "cappuccino") == 0);
  708. assert(info.type == LFS_TYPE_DIR);
  709. lfs_stat(&lfs, "espresso/mocha/", &info) => 0;
  710. assert(strcmp(info.name, "mocha") == 0);
  711. assert(info.type == LFS_TYPE_DIR);
  712. lfs_stat(&lfs, "coffee/drip//////", &info) => LFS_ERR_NOENT;
  713. lfs_stat(&lfs, "coffee/coldbrew/////", &info) => LFS_ERR_NOENT;
  714. lfs_stat(&lfs, "coffee/turkish////", &info) => LFS_ERR_NOENT;
  715. lfs_stat(&lfs, "coffee/tubruk///", &info) => LFS_ERR_NOENT;
  716. lfs_stat(&lfs, "coffee/vietnamese//", &info) => LFS_ERR_NOENT;
  717. lfs_stat(&lfs, "coffee/thai/", &info) => LFS_ERR_NOENT;
  718. // remove paths
  719. lfs_remove(&lfs, "espresso/espresso/") => 0;
  720. lfs_remove(&lfs, "espresso/americano//") => 0;
  721. lfs_remove(&lfs, "espresso/macchiato///") => 0;
  722. lfs_remove(&lfs, "espresso/latte////") => 0;
  723. lfs_remove(&lfs, "espresso/cappuccino/////") => 0;
  724. lfs_remove(&lfs, "espresso/mocha//////") => 0;
  725. // stat paths
  726. lfs_stat(&lfs, "espresso/espresso//////", &info) => LFS_ERR_NOENT;
  727. lfs_stat(&lfs, "espresso/americano/////", &info) => LFS_ERR_NOENT;
  728. lfs_stat(&lfs, "espresso/macchiato////", &info) => LFS_ERR_NOENT;
  729. lfs_stat(&lfs, "espresso/latte///", &info) => LFS_ERR_NOENT;
  730. lfs_stat(&lfs, "espresso/cappuccino//", &info) => LFS_ERR_NOENT;
  731. lfs_stat(&lfs, "espresso/mocha/", &info) => LFS_ERR_NOENT;
  732. } else {
  733. // bad source
  734. lfs_rename(&lfs,
  735. "coffee/drip//////",
  736. "espresso/espresso") => LFS_ERR_NOTDIR;
  737. lfs_rename(&lfs,
  738. "coffee/coldbrew/////",
  739. "espresso/americano") => LFS_ERR_NOTDIR;
  740. lfs_rename(&lfs,
  741. "coffee/turkish////",
  742. "espresso/macchiato") => LFS_ERR_NOTDIR;
  743. lfs_rename(&lfs,
  744. "coffee/tubruk///",
  745. "espresso/latte") => LFS_ERR_NOTDIR;
  746. lfs_rename(&lfs,
  747. "coffee/vietnamese//",
  748. "espresso/cappuccino") => LFS_ERR_NOTDIR;
  749. lfs_rename(&lfs,
  750. "coffee/thai/",
  751. "espresso/mocha") => LFS_ERR_NOTDIR;
  752. // bad destination
  753. lfs_rename(&lfs,
  754. "coffee/drip",
  755. "espresso/espresso/") => LFS_ERR_NOTDIR;
  756. lfs_rename(&lfs,
  757. "coffee/coldbrew",
  758. "espresso/americano//") => LFS_ERR_NOTDIR;
  759. lfs_rename(&lfs,
  760. "coffee/turkish",
  761. "espresso/macchiato///") => LFS_ERR_NOTDIR;
  762. lfs_rename(&lfs,
  763. "coffee/tubruk",
  764. "espresso/latte////") => LFS_ERR_NOTDIR;
  765. lfs_rename(&lfs,
  766. "coffee/vietnamese",
  767. "espresso/cappuccino/////") => LFS_ERR_NOTDIR;
  768. lfs_rename(&lfs,
  769. "coffee/thai",
  770. "espresso/mocha//////") => LFS_ERR_NOTDIR;
  771. // bad source and bad destination
  772. lfs_rename(&lfs,
  773. "coffee/drip//////",
  774. "espresso/espresso/") => LFS_ERR_NOTDIR;
  775. lfs_rename(&lfs,
  776. "coffee/coldbrew/////",
  777. "espresso/americano//") => LFS_ERR_NOTDIR;
  778. lfs_rename(&lfs,
  779. "coffee/turkish////",
  780. "espresso/macchiato///") => LFS_ERR_NOTDIR;
  781. lfs_rename(&lfs,
  782. "coffee/tubruk///",
  783. "espresso/latte////") => LFS_ERR_NOTDIR;
  784. lfs_rename(&lfs,
  785. "coffee/vietnamese//",
  786. "espresso/cappuccino/////") => LFS_ERR_NOTDIR;
  787. lfs_rename(&lfs,
  788. "coffee/thai/",
  789. "espresso/mocha//////") => LFS_ERR_NOTDIR;
  790. // remove paths
  791. lfs_remove(&lfs, "coffee/drip/") => LFS_ERR_NOTDIR;
  792. lfs_remove(&lfs, "coffee/coldbrew//") => LFS_ERR_NOTDIR;
  793. lfs_remove(&lfs, "coffee/turkish///") => LFS_ERR_NOTDIR;
  794. lfs_remove(&lfs, "coffee/tubruk////") => LFS_ERR_NOTDIR;
  795. lfs_remove(&lfs, "coffee/vietnamese/////") => LFS_ERR_NOTDIR;
  796. lfs_remove(&lfs, "coffee/thai//////") => LFS_ERR_NOTDIR;
  797. // stat paths
  798. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  799. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  800. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  801. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  802. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  803. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  804. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  805. assert(strcmp(info.name, "drip") == 0);
  806. assert(info.type == LFS_TYPE_REG);
  807. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  808. assert(strcmp(info.name, "coldbrew") == 0);
  809. assert(info.type == LFS_TYPE_REG);
  810. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  811. assert(strcmp(info.name, "turkish") == 0);
  812. assert(info.type == LFS_TYPE_REG);
  813. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  814. assert(strcmp(info.name, "tubruk") == 0);
  815. assert(info.type == LFS_TYPE_REG);
  816. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  817. assert(strcmp(info.name, "vietnamese") == 0);
  818. assert(info.type == LFS_TYPE_REG);
  819. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  820. assert(strcmp(info.name, "thai") == 0);
  821. assert(info.type == LFS_TYPE_REG);
  822. }
  823. lfs_unmount(&lfs) => 0;
  824. '''
  825. # dot path tests
  826. [cases.test_paths_dots]
  827. defines.DIR = [false, true]
  828. code = '''
  829. lfs_t lfs;
  830. lfs_format(&lfs, cfg) => 0;
  831. lfs_mount(&lfs, cfg) => 0;
  832. // create paths
  833. lfs_mkdir(&lfs, "coffee") => 0;
  834. if (DIR) {
  835. lfs_mkdir(&lfs, "/coffee/drip") => 0;
  836. lfs_mkdir(&lfs, "/./coffee/./coldbrew") => 0;
  837. lfs_mkdir(&lfs, "/././coffee/././turkish") => 0;
  838. lfs_mkdir(&lfs, "/./././coffee/./././tubruk") => 0;
  839. lfs_mkdir(&lfs, "/././././coffee/././././vietnamese") => 0;
  840. lfs_mkdir(&lfs, "/./././././coffee/./././././thai") => 0;
  841. } else {
  842. lfs_file_t file;
  843. lfs_file_open(&lfs, &file, "/coffee/drip",
  844. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  845. lfs_file_close(&lfs, &file) => 0;
  846. lfs_file_open(&lfs, &file, "/./coffee/./coldbrew",
  847. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  848. lfs_file_close(&lfs, &file) => 0;
  849. lfs_file_open(&lfs, &file, "/././coffee/././turkish",
  850. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  851. lfs_file_close(&lfs, &file) => 0;
  852. lfs_file_open(&lfs, &file, "/./././coffee/./././tubruk",
  853. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  854. lfs_file_close(&lfs, &file) => 0;
  855. lfs_file_open(&lfs, &file, "/././././coffee/././././vietnamese",
  856. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  857. lfs_file_close(&lfs, &file) => 0;
  858. lfs_file_open(&lfs, &file, "/./././././coffee/./././././thai",
  859. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  860. lfs_file_close(&lfs, &file) => 0;
  861. }
  862. // stat paths
  863. struct lfs_info info;
  864. lfs_stat(&lfs, "/./././././coffee/./././././drip", &info) => 0;
  865. assert(strcmp(info.name, "drip") == 0);
  866. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  867. lfs_stat(&lfs, "/././././coffee/././././coldbrew", &info) => 0;
  868. assert(strcmp(info.name, "coldbrew") == 0);
  869. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  870. lfs_stat(&lfs, "/./././coffee/./././turkish", &info) => 0;
  871. assert(strcmp(info.name, "turkish") == 0);
  872. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  873. lfs_stat(&lfs, "/././coffee/././tubruk", &info) => 0;
  874. assert(strcmp(info.name, "tubruk") == 0);
  875. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  876. lfs_stat(&lfs, "/./coffee/./vietnamese", &info) => 0;
  877. assert(strcmp(info.name, "vietnamese") == 0);
  878. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  879. lfs_stat(&lfs, "/coffee/thai", &info) => 0;
  880. assert(strcmp(info.name, "thai") == 0);
  881. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  882. // file open paths, only works on files!
  883. if (DIR) {
  884. lfs_file_t file;
  885. lfs_file_open(&lfs, &file, "/coffee/drip",
  886. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  887. lfs_file_open(&lfs, &file, "/./coffee/./coldbrew",
  888. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  889. lfs_file_open(&lfs, &file, "/././coffee/././turkish",
  890. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  891. lfs_file_open(&lfs, &file, "/./././coffee/./././tubruk",
  892. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  893. lfs_file_open(&lfs, &file, "/././././coffee/././././vietnamese",
  894. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  895. lfs_file_open(&lfs, &file, "/./././././coffee/./././././thai",
  896. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  897. } else {
  898. lfs_file_t file;
  899. lfs_file_open(&lfs, &file, "/coffee/drip",
  900. LFS_O_RDONLY) => 0;
  901. lfs_file_close(&lfs, &file) => 0;
  902. lfs_file_open(&lfs, &file, "/./coffee/./coldbrew",
  903. LFS_O_RDONLY) => 0;
  904. lfs_file_close(&lfs, &file) => 0;
  905. lfs_file_open(&lfs, &file, "/././coffee/././turkish",
  906. LFS_O_RDONLY) => 0;
  907. lfs_file_close(&lfs, &file) => 0;
  908. lfs_file_open(&lfs, &file, "/./././coffee/./././tubruk",
  909. LFS_O_RDONLY) => 0;
  910. lfs_file_close(&lfs, &file) => 0;
  911. lfs_file_open(&lfs, &file, "/././././coffee/././././vietnamese",
  912. LFS_O_RDONLY) => 0;
  913. lfs_file_close(&lfs, &file) => 0;
  914. lfs_file_open(&lfs, &file, "/./././././coffee/./././././thai",
  915. LFS_O_RDONLY) => 0;
  916. lfs_file_close(&lfs, &file) => 0;
  917. }
  918. // dir open paths, only works on dirs!
  919. if (DIR) {
  920. lfs_dir_t dir;
  921. lfs_dir_open(&lfs, &dir, "/coffee/drip") => 0;
  922. lfs_dir_close(&lfs, &dir) => 0;
  923. lfs_dir_open(&lfs, &dir, "/./coffee/./coldbrew") => 0;
  924. lfs_dir_close(&lfs, &dir) => 0;
  925. lfs_dir_open(&lfs, &dir, "/././coffee/././turkish") => 0;
  926. lfs_dir_close(&lfs, &dir) => 0;
  927. lfs_dir_open(&lfs, &dir, "/./././coffee/./././tubruk") => 0;
  928. lfs_dir_close(&lfs, &dir) => 0;
  929. lfs_dir_open(&lfs, &dir, "/././././coffee/././././vietnamese") => 0;
  930. lfs_dir_close(&lfs, &dir) => 0;
  931. lfs_dir_open(&lfs, &dir, "/./././././coffee/./././././thai") => 0;
  932. lfs_dir_close(&lfs, &dir) => 0;
  933. } else {
  934. lfs_dir_t dir;
  935. lfs_dir_open(&lfs, &dir, "/coffee/drip") => LFS_ERR_NOTDIR;
  936. lfs_dir_open(&lfs, &dir, "/./coffee/./coldbrew") => LFS_ERR_NOTDIR;
  937. lfs_dir_open(&lfs, &dir, "/././coffee/././turkish") => LFS_ERR_NOTDIR;
  938. lfs_dir_open(&lfs, &dir, "/./././coffee/./././tubruk") => LFS_ERR_NOTDIR;
  939. lfs_dir_open(&lfs, &dir, "/././././coffee/././././vietnamese") => LFS_ERR_NOTDIR;
  940. lfs_dir_open(&lfs, &dir, "/./././././coffee/./././././thai") => LFS_ERR_NOTDIR;
  941. }
  942. // rename paths
  943. lfs_mkdir(&lfs, "espresso") => 0;
  944. lfs_rename(&lfs,
  945. "/./././././coffee/./././././drip",
  946. "/espresso/espresso") => 0;
  947. lfs_rename(&lfs,
  948. "/././././coffee/././././coldbrew",
  949. "/./espresso/./americano") => 0;
  950. lfs_rename(&lfs,
  951. "/./././coffee/./././turkish",
  952. "/././espresso/././macchiato") => 0;
  953. lfs_rename(&lfs,
  954. "/././coffee/././tubruk",
  955. "/./././espresso/./././latte") => 0;
  956. lfs_rename(&lfs,
  957. "/./coffee/./vietnamese",
  958. "/././././espresso/././././cappuccino") => 0;
  959. lfs_rename(&lfs,
  960. "/coffee/thai",
  961. "/./././././espresso/./././././mocha") => 0;
  962. // stat paths
  963. lfs_stat(&lfs, "/./././././espresso/./././././espresso", &info) => 0;
  964. assert(strcmp(info.name, "espresso") == 0);
  965. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  966. lfs_stat(&lfs, "/././././espresso/././././americano", &info) => 0;
  967. assert(strcmp(info.name, "americano") == 0);
  968. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  969. lfs_stat(&lfs, "/./././espresso/./././macchiato", &info) => 0;
  970. assert(strcmp(info.name, "macchiato") == 0);
  971. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  972. lfs_stat(&lfs, "/././espresso/././latte", &info) => 0;
  973. assert(strcmp(info.name, "latte") == 0);
  974. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  975. lfs_stat(&lfs, "/./espresso/./cappuccino", &info) => 0;
  976. assert(strcmp(info.name, "cappuccino") == 0);
  977. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  978. lfs_stat(&lfs, "/espresso/mocha", &info) => 0;
  979. assert(strcmp(info.name, "mocha") == 0);
  980. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  981. lfs_stat(&lfs, "/./././././coffee/./././././drip", &info) => LFS_ERR_NOENT;
  982. lfs_stat(&lfs, "/././././coffee/././././coldbrew", &info) => LFS_ERR_NOENT;
  983. lfs_stat(&lfs, "/./././coffee/./././turkish", &info) => LFS_ERR_NOENT;
  984. lfs_stat(&lfs, "/././coffee/././tubruk", &info) => LFS_ERR_NOENT;
  985. lfs_stat(&lfs, "/./coffee/./vietnamese", &info) => LFS_ERR_NOENT;
  986. lfs_stat(&lfs, "/coffee/thai", &info) => LFS_ERR_NOENT;
  987. // remove paths
  988. lfs_remove(&lfs, "/espresso/espresso") => 0;
  989. lfs_remove(&lfs, "/./espresso/./americano") => 0;
  990. lfs_remove(&lfs, "/././espresso/././macchiato") => 0;
  991. lfs_remove(&lfs, "/./././espresso/./././latte") => 0;
  992. lfs_remove(&lfs, "/././././espresso/././././cappuccino") => 0;
  993. lfs_remove(&lfs, "/./././././espresso/./././././mocha") => 0;
  994. // stat paths
  995. lfs_stat(&lfs, "/./././././espresso/./././././espresso", &info) => LFS_ERR_NOENT;
  996. lfs_stat(&lfs, "/././././espresso/././././americano", &info) => LFS_ERR_NOENT;
  997. lfs_stat(&lfs, "/./././espresso/./././macchiato", &info) => LFS_ERR_NOENT;
  998. lfs_stat(&lfs, "/././espresso/././latte", &info) => LFS_ERR_NOENT;
  999. lfs_stat(&lfs, "/./espresso/./cappuccino", &info) => LFS_ERR_NOENT;
  1000. lfs_stat(&lfs, "/espresso/mocha", &info) => LFS_ERR_NOENT;
  1001. lfs_unmount(&lfs) => 0;
  1002. '''
  1003. # test trailing dots, these get a bit weird
  1004. [cases.test_paths_trailing_dots]
  1005. defines.DIR = [false, true]
  1006. code = '''
  1007. lfs_t lfs;
  1008. lfs_format(&lfs, cfg) => 0;
  1009. lfs_mount(&lfs, cfg) => 0;
  1010. // create paths
  1011. lfs_mkdir(&lfs, "coffee") => 0;
  1012. if (DIR) {
  1013. lfs_mkdir(&lfs, "coffee/drip/.") => LFS_ERR_NOENT;
  1014. lfs_mkdir(&lfs, "coffee/coldbrew/./.") => LFS_ERR_NOENT;
  1015. lfs_mkdir(&lfs, "coffee/turkish/././.") => LFS_ERR_NOENT;
  1016. lfs_mkdir(&lfs, "coffee/tubruk/./././.") => LFS_ERR_NOENT;
  1017. lfs_mkdir(&lfs, "coffee/vietnamese/././././.") => LFS_ERR_NOENT;
  1018. lfs_mkdir(&lfs, "coffee/thai/./././././.") => LFS_ERR_NOENT;
  1019. // still create so we have something to test
  1020. lfs_mkdir(&lfs, "coffee/drip") => 0;
  1021. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  1022. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  1023. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  1024. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  1025. lfs_mkdir(&lfs, "coffee/thai") => 0;
  1026. } else {
  1027. lfs_file_t file;
  1028. lfs_file_open(&lfs, &file, "coffee/drip/.",
  1029. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1030. lfs_file_open(&lfs, &file, "coffee/coldbrew/./.",
  1031. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1032. lfs_file_open(&lfs, &file, "coffee/turkish/././.",
  1033. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1034. lfs_file_open(&lfs, &file, "coffee/tubruk/./././.",
  1035. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1036. lfs_file_open(&lfs, &file, "coffee/vietnamese/././././.",
  1037. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1038. lfs_file_open(&lfs, &file, "coffee/thai/./././././.",
  1039. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1040. // still create so we have something to test
  1041. lfs_file_open(&lfs, &file, "coffee/drip",
  1042. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1043. lfs_file_close(&lfs, &file) => 0;
  1044. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  1045. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1046. lfs_file_close(&lfs, &file) => 0;
  1047. lfs_file_open(&lfs, &file, "coffee/turkish",
  1048. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1049. lfs_file_close(&lfs, &file) => 0;
  1050. lfs_file_open(&lfs, &file, "coffee/tubruk",
  1051. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1052. lfs_file_close(&lfs, &file) => 0;
  1053. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  1054. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1055. lfs_file_close(&lfs, &file) => 0;
  1056. lfs_file_open(&lfs, &file, "coffee/thai",
  1057. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1058. lfs_file_close(&lfs, &file) => 0;
  1059. }
  1060. // stat paths
  1061. struct lfs_info info;
  1062. if (DIR) {
  1063. lfs_stat(&lfs, "coffee/drip/./././././.", &info) => 0;
  1064. assert(strcmp(info.name, "drip") == 0);
  1065. assert(info.type == LFS_TYPE_DIR);
  1066. lfs_stat(&lfs, "coffee/coldbrew/././././.", &info) => 0;
  1067. assert(strcmp(info.name, "coldbrew") == 0);
  1068. assert(info.type == LFS_TYPE_DIR);
  1069. lfs_stat(&lfs, "coffee/turkish/./././.", &info) => 0;
  1070. assert(strcmp(info.name, "turkish") == 0);
  1071. assert(info.type == LFS_TYPE_DIR);
  1072. lfs_stat(&lfs, "coffee/tubruk/././.", &info) => 0;
  1073. assert(strcmp(info.name, "tubruk") == 0);
  1074. assert(info.type == LFS_TYPE_DIR);
  1075. lfs_stat(&lfs, "coffee/vietnamese/./.", &info) => 0;
  1076. assert(strcmp(info.name, "vietnamese") == 0);
  1077. assert(info.type == LFS_TYPE_DIR);
  1078. lfs_stat(&lfs, "coffee/thai/.", &info) => 0;
  1079. assert(strcmp(info.name, "thai") == 0);
  1080. assert(info.type == LFS_TYPE_DIR);
  1081. } else {
  1082. lfs_stat(&lfs, "coffee/drip/./././././.", &info) => LFS_ERR_NOTDIR;
  1083. lfs_stat(&lfs, "coffee/coldbrew/././././.", &info) => LFS_ERR_NOTDIR;
  1084. lfs_stat(&lfs, "coffee/turkish/./././.", &info) => LFS_ERR_NOTDIR;
  1085. lfs_stat(&lfs, "coffee/tubruk/././.", &info) => LFS_ERR_NOTDIR;
  1086. lfs_stat(&lfs, "coffee/vietnamese/./.", &info) => LFS_ERR_NOTDIR;
  1087. lfs_stat(&lfs, "coffee/thai/.", &info) => LFS_ERR_NOTDIR;
  1088. }
  1089. // file open paths, only works on files!
  1090. if (DIR) {
  1091. lfs_file_t file;
  1092. lfs_file_open(&lfs, &file, "coffee/drip/.",
  1093. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1094. lfs_file_open(&lfs, &file, "coffee/coldbrew/./.",
  1095. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1096. lfs_file_open(&lfs, &file, "coffee/turkish/././.",
  1097. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1098. lfs_file_open(&lfs, &file, "coffee/tubruk/./././.",
  1099. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1100. lfs_file_open(&lfs, &file, "coffee/vietnamese/././././.",
  1101. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1102. lfs_file_open(&lfs, &file, "coffee/thai/./././././.",
  1103. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1104. } else {
  1105. lfs_file_t file;
  1106. lfs_file_open(&lfs, &file, "coffee/drip/.",
  1107. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1108. lfs_file_open(&lfs, &file, "coffee/coldbrew/./.",
  1109. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1110. lfs_file_open(&lfs, &file, "coffee/turkish/././.",
  1111. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1112. lfs_file_open(&lfs, &file, "coffee/tubruk/./././.",
  1113. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1114. lfs_file_open(&lfs, &file, "coffee/vietnamese/././././.",
  1115. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1116. lfs_file_open(&lfs, &file, "coffee/thai/./././././.",
  1117. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1118. }
  1119. // dir open paths, only works on dirs!
  1120. if (DIR) {
  1121. lfs_dir_t dir;
  1122. lfs_dir_open(&lfs, &dir, "coffee/drip/.") => 0;
  1123. lfs_dir_close(&lfs, &dir) => 0;
  1124. lfs_dir_open(&lfs, &dir, "coffee/coldbrew/./.") => 0;
  1125. lfs_dir_close(&lfs, &dir) => 0;
  1126. lfs_dir_open(&lfs, &dir, "coffee/turkish/././.") => 0;
  1127. lfs_dir_close(&lfs, &dir) => 0;
  1128. lfs_dir_open(&lfs, &dir, "coffee/tubruk/./././.") => 0;
  1129. lfs_dir_close(&lfs, &dir) => 0;
  1130. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/././././.") => 0;
  1131. lfs_dir_close(&lfs, &dir) => 0;
  1132. lfs_dir_open(&lfs, &dir, "coffee/thai/./././././.") => 0;
  1133. lfs_dir_close(&lfs, &dir) => 0;
  1134. } else {
  1135. lfs_dir_t dir;
  1136. lfs_dir_open(&lfs, &dir, "coffee/drip/.") => LFS_ERR_NOTDIR;
  1137. lfs_dir_open(&lfs, &dir, "coffee/coldbrew/./.") => LFS_ERR_NOTDIR;
  1138. lfs_dir_open(&lfs, &dir, "coffee/turkish/././.") => LFS_ERR_NOTDIR;
  1139. lfs_dir_open(&lfs, &dir, "coffee/tubruk/./././.") => LFS_ERR_NOTDIR;
  1140. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/././././.") => LFS_ERR_NOTDIR;
  1141. lfs_dir_open(&lfs, &dir, "coffee/thai/./././././.") => LFS_ERR_NOTDIR;
  1142. }
  1143. // rename paths
  1144. lfs_mkdir(&lfs, "espresso") => 0;
  1145. if (DIR) {
  1146. // bad source
  1147. lfs_rename(&lfs,
  1148. "coffee/drip/./././././.",
  1149. "espresso/espresso") => LFS_ERR_INVAL;
  1150. lfs_rename(&lfs,
  1151. "coffee/coldbrew/././././.",
  1152. "espresso/americano") => LFS_ERR_INVAL;
  1153. lfs_rename(&lfs,
  1154. "coffee/turkish/./././.",
  1155. "espresso/macchiato") => LFS_ERR_INVAL;
  1156. lfs_rename(&lfs,
  1157. "coffee/tubruk/././.",
  1158. "espresso/latte") => LFS_ERR_INVAL;
  1159. lfs_rename(&lfs,
  1160. "coffee/vietnamese/./.",
  1161. "espresso/cappuccino") => LFS_ERR_INVAL;
  1162. lfs_rename(&lfs,
  1163. "coffee/thai/.",
  1164. "espresso/mocha") => LFS_ERR_INVAL;
  1165. // bad destination
  1166. lfs_rename(&lfs,
  1167. "coffee/drip",
  1168. "espresso/espresso/.") => LFS_ERR_NOENT;
  1169. lfs_rename(&lfs,
  1170. "coffee/coldbrew",
  1171. "espresso/americano/./.") => LFS_ERR_NOENT;
  1172. lfs_rename(&lfs,
  1173. "coffee/turkish",
  1174. "espresso/macchiato/././.") => LFS_ERR_NOENT;
  1175. lfs_rename(&lfs,
  1176. "coffee/tubruk",
  1177. "espresso/latte/./././.") => LFS_ERR_NOENT;
  1178. lfs_rename(&lfs,
  1179. "coffee/vietnamese",
  1180. "espresso/cappuccino/././././.") => LFS_ERR_NOENT;
  1181. lfs_rename(&lfs,
  1182. "coffee/thai",
  1183. "espresso/mocha/./././././.") => LFS_ERR_NOENT;
  1184. // bad source and bad destination
  1185. lfs_rename(&lfs,
  1186. "coffee/drip/./././././.",
  1187. "espresso/espresso/.") => LFS_ERR_NOENT;
  1188. lfs_rename(&lfs,
  1189. "coffee/coldbrew/././././.",
  1190. "espresso/americano/./.") => LFS_ERR_NOENT;
  1191. lfs_rename(&lfs,
  1192. "coffee/turkish/./././.",
  1193. "espresso/macchiato/././.") => LFS_ERR_NOENT;
  1194. lfs_rename(&lfs,
  1195. "coffee/tubruk/././.",
  1196. "espresso/latte/./././.") => LFS_ERR_NOENT;
  1197. lfs_rename(&lfs,
  1198. "coffee/vietnamese/./.",
  1199. "espresso/cappuccino/././././.") => LFS_ERR_NOENT;
  1200. lfs_rename(&lfs,
  1201. "coffee/thai/.",
  1202. "espresso/mocha/./././././.") => LFS_ERR_NOENT;
  1203. } else {
  1204. // bad source
  1205. lfs_rename(&lfs,
  1206. "coffee/drip/./././././.",
  1207. "espresso/espresso") => LFS_ERR_NOTDIR;
  1208. lfs_rename(&lfs,
  1209. "coffee/coldbrew/././././.",
  1210. "espresso/americano") => LFS_ERR_NOTDIR;
  1211. lfs_rename(&lfs,
  1212. "coffee/turkish/./././.",
  1213. "espresso/macchiato") => LFS_ERR_NOTDIR;
  1214. lfs_rename(&lfs,
  1215. "coffee/tubruk/././.",
  1216. "espresso/latte") => LFS_ERR_NOTDIR;
  1217. lfs_rename(&lfs,
  1218. "coffee/vietnamese/./.",
  1219. "espresso/cappuccino") => LFS_ERR_NOTDIR;
  1220. lfs_rename(&lfs,
  1221. "coffee/thai/.",
  1222. "espresso/mocha") => LFS_ERR_NOTDIR;
  1223. // bad destination
  1224. lfs_rename(&lfs,
  1225. "coffee/drip",
  1226. "espresso/espresso/.") => LFS_ERR_NOENT;
  1227. lfs_rename(&lfs,
  1228. "coffee/coldbrew",
  1229. "espresso/americano/./.") => LFS_ERR_NOENT;
  1230. lfs_rename(&lfs,
  1231. "coffee/turkish",
  1232. "espresso/macchiato/././.") => LFS_ERR_NOENT;
  1233. lfs_rename(&lfs,
  1234. "coffee/tubruk",
  1235. "espresso/latte/./././.") => LFS_ERR_NOENT;
  1236. lfs_rename(&lfs,
  1237. "coffee/vietnamese",
  1238. "espresso/cappuccino/././././.") => LFS_ERR_NOENT;
  1239. lfs_rename(&lfs,
  1240. "coffee/thai",
  1241. "espresso/mocha/./././././.") => LFS_ERR_NOENT;
  1242. // bad source and bad destination
  1243. lfs_rename(&lfs,
  1244. "coffee/drip/./././././.",
  1245. "espresso/espresso/.") => LFS_ERR_NOTDIR;
  1246. lfs_rename(&lfs,
  1247. "coffee/coldbrew/././././.",
  1248. "espresso/americano/./.") => LFS_ERR_NOTDIR;
  1249. lfs_rename(&lfs,
  1250. "coffee/turkish/./././.",
  1251. "espresso/macchiato/././.") => LFS_ERR_NOTDIR;
  1252. lfs_rename(&lfs,
  1253. "coffee/tubruk/././.",
  1254. "espresso/latte/./././.") => LFS_ERR_NOTDIR;
  1255. lfs_rename(&lfs,
  1256. "coffee/vietnamese/./.",
  1257. "espresso/cappuccino/././././.") => LFS_ERR_NOTDIR;
  1258. lfs_rename(&lfs,
  1259. "coffee/thai/.",
  1260. "espresso/mocha/./././././.") => LFS_ERR_NOTDIR;
  1261. }
  1262. // remove paths
  1263. if (DIR) {
  1264. lfs_remove(&lfs, "coffee/drip/.") => LFS_ERR_INVAL;
  1265. lfs_remove(&lfs, "coffee/coldbrew/./.") => LFS_ERR_INVAL;
  1266. lfs_remove(&lfs, "coffee/turkish/././.") => LFS_ERR_INVAL;
  1267. lfs_remove(&lfs, "coffee/tubruk/./././.") => LFS_ERR_INVAL;
  1268. lfs_remove(&lfs, "coffee/vietnamese/././././.") => LFS_ERR_INVAL;
  1269. lfs_remove(&lfs, "coffee/thai/./././././.") => LFS_ERR_INVAL;
  1270. } else {
  1271. lfs_remove(&lfs, "coffee/drip/.") => LFS_ERR_NOTDIR;
  1272. lfs_remove(&lfs, "coffee/coldbrew/./.") => LFS_ERR_NOTDIR;
  1273. lfs_remove(&lfs, "coffee/turkish/././.") => LFS_ERR_NOTDIR;
  1274. lfs_remove(&lfs, "coffee/tubruk/./././.") => LFS_ERR_NOTDIR;
  1275. lfs_remove(&lfs, "coffee/vietnamese/././././.") => LFS_ERR_NOTDIR;
  1276. lfs_remove(&lfs, "coffee/thai/./././././.") => LFS_ERR_NOTDIR;
  1277. }
  1278. // stat paths
  1279. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  1280. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  1281. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  1282. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  1283. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  1284. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  1285. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  1286. assert(strcmp(info.name, "drip") == 0);
  1287. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1288. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  1289. assert(strcmp(info.name, "coldbrew") == 0);
  1290. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1291. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  1292. assert(strcmp(info.name, "turkish") == 0);
  1293. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1294. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  1295. assert(strcmp(info.name, "tubruk") == 0);
  1296. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1297. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  1298. assert(strcmp(info.name, "vietnamese") == 0);
  1299. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1300. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  1301. assert(strcmp(info.name, "thai") == 0);
  1302. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1303. lfs_unmount(&lfs) => 0;
  1304. '''
  1305. # dot dot path tests
  1306. [cases.test_paths_dotdots]
  1307. defines.DIR = [false, true]
  1308. code = '''
  1309. lfs_t lfs;
  1310. lfs_format(&lfs, cfg) => 0;
  1311. lfs_mount(&lfs, cfg) => 0;
  1312. // create paths
  1313. lfs_mkdir(&lfs, "no") => 0;
  1314. lfs_mkdir(&lfs, "no/no") => 0;
  1315. lfs_mkdir(&lfs, "coffee") => 0;
  1316. lfs_mkdir(&lfs, "coffee/no") => 0;
  1317. if (DIR) {
  1318. lfs_mkdir(&lfs, "/coffee/drip") => 0;
  1319. lfs_mkdir(&lfs, "/no/../coffee/coldbrew") => 0;
  1320. lfs_mkdir(&lfs, "/coffee/no/../turkish") => 0;
  1321. lfs_mkdir(&lfs, "/no/no/../../coffee/tubruk") => 0;
  1322. lfs_mkdir(&lfs, "/no/no/../../coffee/no/../vietnamese") => 0;
  1323. lfs_mkdir(&lfs, "/no/no/../../no/no/../../coffee/thai") => 0;
  1324. } else {
  1325. lfs_file_t file;
  1326. lfs_file_open(&lfs, &file, "/coffee/drip",
  1327. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1328. lfs_file_close(&lfs, &file) => 0;
  1329. lfs_file_open(&lfs, &file, "/no/../coffee/coldbrew",
  1330. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1331. lfs_file_close(&lfs, &file) => 0;
  1332. lfs_file_open(&lfs, &file, "/coffee/no/../turkish",
  1333. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1334. lfs_file_close(&lfs, &file) => 0;
  1335. lfs_file_open(&lfs, &file, "/no/no/../../coffee/tubruk",
  1336. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1337. lfs_file_close(&lfs, &file) => 0;
  1338. lfs_file_open(&lfs, &file, "/no/no/../../coffee/no/../vietnamese",
  1339. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1340. lfs_file_close(&lfs, &file) => 0;
  1341. lfs_file_open(&lfs, &file, "/no/no/../../no/no/../../coffee/thai",
  1342. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1343. lfs_file_close(&lfs, &file) => 0;
  1344. }
  1345. // stat paths
  1346. struct lfs_info info;
  1347. lfs_stat(&lfs, "/no/no/../../no/no/../../coffee/drip", &info) => 0;
  1348. assert(strcmp(info.name, "drip") == 0);
  1349. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1350. lfs_stat(&lfs, "/no/no/../../coffee/no/../coldbrew", &info) => 0;
  1351. assert(strcmp(info.name, "coldbrew") == 0);
  1352. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1353. lfs_stat(&lfs, "/no/no/../../coffee/turkish", &info) => 0;
  1354. assert(strcmp(info.name, "turkish") == 0);
  1355. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1356. lfs_stat(&lfs, "/coffee/no/../tubruk", &info) => 0;
  1357. assert(strcmp(info.name, "tubruk") == 0);
  1358. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1359. lfs_stat(&lfs, "/no/../coffee/vietnamese", &info) => 0;
  1360. assert(strcmp(info.name, "vietnamese") == 0);
  1361. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1362. lfs_stat(&lfs, "/coffee/thai", &info) => 0;
  1363. assert(strcmp(info.name, "thai") == 0);
  1364. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1365. // file open paths, only works on files!
  1366. if (DIR) {
  1367. lfs_file_t file;
  1368. lfs_file_open(&lfs, &file, "/coffee/drip",
  1369. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1370. lfs_file_open(&lfs, &file, "/no/../coffee/coldbrew",
  1371. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1372. lfs_file_open(&lfs, &file, "/coffee/no/../turkish",
  1373. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1374. lfs_file_open(&lfs, &file, "/no/no/../../coffee/tubruk",
  1375. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1376. lfs_file_open(&lfs, &file, "/no/no/../../coffee/no/../vietnamese",
  1377. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1378. lfs_file_open(&lfs, &file, "/no/no/../../no/no/../../coffee/thai",
  1379. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1380. } else {
  1381. lfs_file_t file;
  1382. lfs_file_open(&lfs, &file, "/coffee/drip",
  1383. LFS_O_RDONLY) => 0;
  1384. lfs_file_close(&lfs, &file) => 0;
  1385. lfs_file_open(&lfs, &file, "/no/../coffee/coldbrew",
  1386. LFS_O_RDONLY) => 0;
  1387. lfs_file_close(&lfs, &file) => 0;
  1388. lfs_file_open(&lfs, &file, "/coffee/no/../turkish",
  1389. LFS_O_RDONLY) => 0;
  1390. lfs_file_close(&lfs, &file) => 0;
  1391. lfs_file_open(&lfs, &file, "/no/no/../../coffee/tubruk",
  1392. LFS_O_RDONLY) => 0;
  1393. lfs_file_close(&lfs, &file) => 0;
  1394. lfs_file_open(&lfs, &file, "/no/no/../../coffee/no/../vietnamese",
  1395. LFS_O_RDONLY) => 0;
  1396. lfs_file_close(&lfs, &file) => 0;
  1397. lfs_file_open(&lfs, &file, "/no/no/../../no/no/../../coffee/thai",
  1398. LFS_O_RDONLY) => 0;
  1399. lfs_file_close(&lfs, &file) => 0;
  1400. }
  1401. // dir open paths, only works on dirs!
  1402. if (DIR) {
  1403. lfs_dir_t dir;
  1404. lfs_dir_open(&lfs, &dir, "/coffee/drip") => 0;
  1405. lfs_dir_close(&lfs, &dir) => 0;
  1406. lfs_dir_open(&lfs, &dir, "/no/../coffee/coldbrew") => 0;
  1407. lfs_dir_close(&lfs, &dir) => 0;
  1408. lfs_dir_open(&lfs, &dir, "/coffee/no/../turkish") => 0;
  1409. lfs_dir_close(&lfs, &dir) => 0;
  1410. lfs_dir_open(&lfs, &dir, "/no/no/../../coffee/tubruk") => 0;
  1411. lfs_dir_close(&lfs, &dir) => 0;
  1412. lfs_dir_open(&lfs, &dir, "/no/no/../../coffee/no/../vietnamese") => 0;
  1413. lfs_dir_close(&lfs, &dir) => 0;
  1414. lfs_dir_open(&lfs, &dir, "/no/no/../../no/no/../../coffee/thai") => 0;
  1415. lfs_dir_close(&lfs, &dir) => 0;
  1416. } else {
  1417. lfs_dir_t dir;
  1418. lfs_dir_open(&lfs, &dir, "/coffee/drip") => LFS_ERR_NOTDIR;
  1419. lfs_dir_open(&lfs, &dir, "/no/../coffee/coldbrew") => LFS_ERR_NOTDIR;
  1420. lfs_dir_open(&lfs, &dir, "/coffee/no/../turkish") => LFS_ERR_NOTDIR;
  1421. lfs_dir_open(&lfs, &dir, "/no/no/../../coffee/tubruk") => LFS_ERR_NOTDIR;
  1422. lfs_dir_open(&lfs, &dir, "/no/no/../../coffee/no/../vietnamese") => LFS_ERR_NOTDIR;
  1423. lfs_dir_open(&lfs, &dir, "/no/no/../../no/no/../../coffee/thai") => LFS_ERR_NOTDIR;
  1424. }
  1425. // rename paths
  1426. lfs_mkdir(&lfs, "espresso") => 0;
  1427. lfs_rename(&lfs,
  1428. "/no/no/../../no/no/../../coffee/drip",
  1429. "/espresso/espresso") => 0;
  1430. lfs_rename(&lfs,
  1431. "/no/no/../../coffee/no/../coldbrew",
  1432. "/no/../espresso/americano") => 0;
  1433. lfs_rename(&lfs,
  1434. "/no/no/../../coffee/turkish",
  1435. "/espresso/no/../macchiato") => 0;
  1436. lfs_rename(&lfs,
  1437. "/coffee/no/../tubruk",
  1438. "/no/no/../../espresso/latte") => 0;
  1439. lfs_rename(&lfs,
  1440. "/no/../coffee/vietnamese",
  1441. "/no/no/../../espresso/no/../cappuccino") => 0;
  1442. lfs_rename(&lfs,
  1443. "/coffee/thai",
  1444. "/no/no/../../no/no/../../espresso/mocha") => 0;
  1445. // stat paths
  1446. lfs_stat(&lfs, "/no/no/../../no/no/../../espresso/espresso", &info) => 0;
  1447. assert(strcmp(info.name, "espresso") == 0);
  1448. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1449. lfs_stat(&lfs, "/no/no/../../espresso/no/../americano", &info) => 0;
  1450. assert(strcmp(info.name, "americano") == 0);
  1451. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1452. lfs_stat(&lfs, "/no/no/../../espresso/macchiato", &info) => 0;
  1453. assert(strcmp(info.name, "macchiato") == 0);
  1454. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1455. lfs_stat(&lfs, "/espresso/no/../latte", &info) => 0;
  1456. assert(strcmp(info.name, "latte") == 0);
  1457. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1458. lfs_stat(&lfs, "/no/../espresso/cappuccino", &info) => 0;
  1459. assert(strcmp(info.name, "cappuccino") == 0);
  1460. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1461. lfs_stat(&lfs, "/espresso/mocha", &info) => 0;
  1462. assert(strcmp(info.name, "mocha") == 0);
  1463. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1464. lfs_stat(&lfs, "/no/no/../../no/no/../../coffee/drip", &info) => LFS_ERR_NOENT;
  1465. lfs_stat(&lfs, "/no/no/../../coffee/no/../coldbrew", &info) => LFS_ERR_NOENT;
  1466. lfs_stat(&lfs, "/no/no/../../coffee/turkish", &info) => LFS_ERR_NOENT;
  1467. lfs_stat(&lfs, "/coffee/no/../tubruk", &info) => LFS_ERR_NOENT;
  1468. lfs_stat(&lfs, "/no/../coffee/vietnamese", &info) => LFS_ERR_NOENT;
  1469. lfs_stat(&lfs, "/coffee/thai", &info) => LFS_ERR_NOENT;
  1470. // remove paths
  1471. lfs_remove(&lfs, "/espresso/espresso") => 0;
  1472. lfs_remove(&lfs, "/no/../espresso/americano") => 0;
  1473. lfs_remove(&lfs, "/espresso/no/../macchiato") => 0;
  1474. lfs_remove(&lfs, "/no/no/../../espresso/latte") => 0;
  1475. lfs_remove(&lfs, "/no/no/../../espresso/no/../cappuccino") => 0;
  1476. lfs_remove(&lfs, "/no/no/../../no/no/../../espresso/mocha") => 0;
  1477. // stat paths
  1478. lfs_stat(&lfs, "/no/no/../../no/no/../../espresso/espresso", &info) => LFS_ERR_NOENT;
  1479. lfs_stat(&lfs, "/no/no/../../espresso/no/../americano", &info) => LFS_ERR_NOENT;
  1480. lfs_stat(&lfs, "/no/no/../../espresso/macchiato", &info) => LFS_ERR_NOENT;
  1481. lfs_stat(&lfs, "/espresso/no/../latte", &info) => LFS_ERR_NOENT;
  1482. lfs_stat(&lfs, "/no/../espresso/cappuccino", &info) => LFS_ERR_NOENT;
  1483. lfs_stat(&lfs, "/espresso/mocha", &info) => LFS_ERR_NOENT;
  1484. lfs_unmount(&lfs) => 0;
  1485. '''
  1486. # test trailing dot dots, these get really weird
  1487. [cases.test_paths_trailing_dotdots]
  1488. defines.DIR = [false, true]
  1489. code = '''
  1490. lfs_t lfs;
  1491. lfs_format(&lfs, cfg) => 0;
  1492. lfs_mount(&lfs, cfg) => 0;
  1493. // create paths
  1494. lfs_mkdir(&lfs, "coffee") => 0;
  1495. if (DIR) {
  1496. lfs_mkdir(&lfs, "coffee/drip/..") => LFS_ERR_NOENT;
  1497. lfs_mkdir(&lfs, "coffee/coldbrew/../..") => LFS_ERR_NOENT;
  1498. lfs_mkdir(&lfs, "coffee/turkish/../../..") => LFS_ERR_NOENT;
  1499. lfs_mkdir(&lfs, "coffee/tubruk/../../../..") => LFS_ERR_NOENT;
  1500. lfs_mkdir(&lfs, "coffee/vietnamese/../../../../..") => LFS_ERR_NOENT;
  1501. lfs_mkdir(&lfs, "coffee/thai/../../../../../..") => LFS_ERR_NOENT;
  1502. // still create so we have something to test
  1503. lfs_mkdir(&lfs, "coffee/drip") => 0;
  1504. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  1505. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  1506. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  1507. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  1508. lfs_mkdir(&lfs, "coffee/thai") => 0;
  1509. } else {
  1510. lfs_file_t file;
  1511. lfs_file_open(&lfs, &file, "coffee/drip/..",
  1512. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1513. lfs_file_open(&lfs, &file, "coffee/coldbrew/../..",
  1514. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1515. lfs_file_open(&lfs, &file, "coffee/turkish/../../..",
  1516. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1517. lfs_file_open(&lfs, &file, "coffee/tubruk/../../../..",
  1518. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1519. lfs_file_open(&lfs, &file, "coffee/vietnamese/../../../../..",
  1520. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1521. lfs_file_open(&lfs, &file, "coffee/thai/../../../../../..",
  1522. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  1523. // still create so we have something to test
  1524. lfs_file_open(&lfs, &file, "coffee/drip",
  1525. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1526. lfs_file_close(&lfs, &file) => 0;
  1527. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  1528. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1529. lfs_file_close(&lfs, &file) => 0;
  1530. lfs_file_open(&lfs, &file, "coffee/turkish",
  1531. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1532. lfs_file_close(&lfs, &file) => 0;
  1533. lfs_file_open(&lfs, &file, "coffee/tubruk",
  1534. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1535. lfs_file_close(&lfs, &file) => 0;
  1536. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  1537. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1538. lfs_file_close(&lfs, &file) => 0;
  1539. lfs_file_open(&lfs, &file, "coffee/thai",
  1540. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1541. lfs_file_close(&lfs, &file) => 0;
  1542. }
  1543. // stat paths
  1544. struct lfs_info info;
  1545. if (DIR) {
  1546. lfs_stat(&lfs, "coffee/drip/../../../../../..", &info) => 0;
  1547. assert(strcmp(info.name, "/") == 0);
  1548. assert(info.type == LFS_TYPE_DIR);
  1549. lfs_stat(&lfs, "coffee/coldbrew/../../../../..", &info) => 0;
  1550. assert(strcmp(info.name, "/") == 0);
  1551. assert(info.type == LFS_TYPE_DIR);
  1552. lfs_stat(&lfs, "coffee/turkish/../../../..", &info) => 0;
  1553. assert(strcmp(info.name, "/") == 0);
  1554. assert(info.type == LFS_TYPE_DIR);
  1555. lfs_stat(&lfs, "coffee/tubruk/../../..", &info) => 0;
  1556. assert(strcmp(info.name, "/") == 0);
  1557. assert(info.type == LFS_TYPE_DIR);
  1558. lfs_stat(&lfs, "coffee/vietnamese/../..", &info) => 0;
  1559. assert(strcmp(info.name, "/") == 0);
  1560. assert(info.type == LFS_TYPE_DIR);
  1561. lfs_stat(&lfs, "coffee/thai/..", &info) => 0;
  1562. assert(strcmp(info.name, "coffee") == 0);
  1563. assert(info.type == LFS_TYPE_DIR);
  1564. } else {
  1565. lfs_stat(&lfs, "coffee/drip/../../../../../..", &info) => LFS_ERR_NOTDIR;
  1566. lfs_stat(&lfs, "coffee/coldbrew/../../../../..", &info) => LFS_ERR_NOTDIR;
  1567. lfs_stat(&lfs, "coffee/turkish/../../../..", &info) => LFS_ERR_NOTDIR;
  1568. lfs_stat(&lfs, "coffee/tubruk/../../..", &info) => LFS_ERR_NOTDIR;
  1569. lfs_stat(&lfs, "coffee/vietnamese/../..", &info) => LFS_ERR_NOTDIR;
  1570. lfs_stat(&lfs, "coffee/thai/..", &info) => LFS_ERR_NOTDIR;
  1571. }
  1572. // file open paths, only works on files!
  1573. if (DIR) {
  1574. lfs_file_t file;
  1575. lfs_file_open(&lfs, &file, "coffee/drip/..",
  1576. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1577. lfs_file_open(&lfs, &file, "coffee/coldbrew/../..",
  1578. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1579. lfs_file_open(&lfs, &file, "coffee/turkish/../../..",
  1580. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1581. lfs_file_open(&lfs, &file, "coffee/tubruk/../../../..",
  1582. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1583. lfs_file_open(&lfs, &file, "coffee/vietnamese/../../../../..",
  1584. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1585. lfs_file_open(&lfs, &file, "coffee/thai/../../../../../..",
  1586. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1587. } else {
  1588. lfs_file_t file;
  1589. lfs_file_open(&lfs, &file, "coffee/drip/..",
  1590. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1591. lfs_file_open(&lfs, &file, "coffee/coldbrew/../..",
  1592. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1593. lfs_file_open(&lfs, &file, "coffee/turkish/../../..",
  1594. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1595. lfs_file_open(&lfs, &file, "coffee/tubruk/../../../..",
  1596. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1597. lfs_file_open(&lfs, &file, "coffee/vietnamese/../../../../..",
  1598. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1599. lfs_file_open(&lfs, &file, "coffee/thai/../../../../../..",
  1600. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  1601. }
  1602. // dir open paths, only works on dirs!
  1603. if (DIR) {
  1604. lfs_dir_t dir;
  1605. lfs_dir_open(&lfs, &dir, "coffee/drip/..") => 0;
  1606. lfs_dir_close(&lfs, &dir) => 0;
  1607. lfs_dir_open(&lfs, &dir, "coffee/coldbrew/../..") => 0;
  1608. lfs_dir_close(&lfs, &dir) => 0;
  1609. lfs_dir_open(&lfs, &dir, "coffee/turkish/../../..") => 0;
  1610. lfs_dir_close(&lfs, &dir) => 0;
  1611. lfs_dir_open(&lfs, &dir, "coffee/tubruk/../../../..") => 0;
  1612. lfs_dir_close(&lfs, &dir) => 0;
  1613. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/../../../../..") => 0;
  1614. lfs_dir_close(&lfs, &dir) => 0;
  1615. lfs_dir_open(&lfs, &dir, "coffee/thai/../../../../../..") => 0;
  1616. lfs_dir_close(&lfs, &dir) => 0;
  1617. } else {
  1618. lfs_dir_t dir;
  1619. lfs_dir_open(&lfs, &dir, "coffee/drip/..") => LFS_ERR_NOTDIR;
  1620. lfs_dir_open(&lfs, &dir, "coffee/coldbrew/../..") => LFS_ERR_NOTDIR;
  1621. lfs_dir_open(&lfs, &dir, "coffee/turkish/../../..") => LFS_ERR_NOTDIR;
  1622. lfs_dir_open(&lfs, &dir, "coffee/tubruk/../../../..") => LFS_ERR_NOTDIR;
  1623. lfs_dir_open(&lfs, &dir, "coffee/vietnamese/../../../../..") => LFS_ERR_NOTDIR;
  1624. lfs_dir_open(&lfs, &dir, "coffee/thai/../../../../../..") => LFS_ERR_NOTDIR;
  1625. }
  1626. // rename paths
  1627. lfs_mkdir(&lfs, "espresso") => 0;
  1628. if (DIR) {
  1629. // bad source
  1630. lfs_rename(&lfs,
  1631. "coffee/drip/../../../../../..",
  1632. "espresso/espresso") => LFS_ERR_INVAL;
  1633. lfs_rename(&lfs,
  1634. "coffee/coldbrew/../../../../..",
  1635. "espresso/americano") => LFS_ERR_INVAL;
  1636. lfs_rename(&lfs,
  1637. "coffee/turkish/../../../..",
  1638. "espresso/macchiato") => LFS_ERR_INVAL;
  1639. lfs_rename(&lfs,
  1640. "coffee/tubruk/../../..",
  1641. "espresso/latte") => LFS_ERR_INVAL;
  1642. lfs_rename(&lfs,
  1643. "coffee/vietnamese/../..",
  1644. "espresso/cappuccino") => LFS_ERR_INVAL;
  1645. lfs_rename(&lfs,
  1646. "coffee/thai/..",
  1647. "espresso/mocha") => LFS_ERR_INVAL;
  1648. // bad destination
  1649. lfs_rename(&lfs,
  1650. "coffee/drip",
  1651. "espresso/espresso/..") => LFS_ERR_NOENT;
  1652. lfs_rename(&lfs,
  1653. "coffee/coldbrew",
  1654. "espresso/americano/../..") => LFS_ERR_NOENT;
  1655. lfs_rename(&lfs,
  1656. "coffee/turkish",
  1657. "espresso/macchiato/../../..") => LFS_ERR_NOENT;
  1658. lfs_rename(&lfs,
  1659. "coffee/tubruk",
  1660. "espresso/latte/../../../..") => LFS_ERR_NOENT;
  1661. lfs_rename(&lfs,
  1662. "coffee/vietnamese",
  1663. "espresso/cappuccino/../../../../..") => LFS_ERR_NOENT;
  1664. lfs_rename(&lfs,
  1665. "coffee/thai",
  1666. "espresso/mocha/../../../../../..") => LFS_ERR_NOENT;
  1667. // bad source and bad destination
  1668. lfs_rename(&lfs,
  1669. "coffee/drip/../../../../../..",
  1670. "espresso/espresso/..") => LFS_ERR_NOENT;
  1671. lfs_rename(&lfs,
  1672. "coffee/coldbrew/../../../../..",
  1673. "espresso/americano/../..") => LFS_ERR_NOENT;
  1674. lfs_rename(&lfs,
  1675. "coffee/turkish/../../../..",
  1676. "espresso/macchiato/../../..") => LFS_ERR_NOENT;
  1677. lfs_rename(&lfs,
  1678. "coffee/tubruk/../../..",
  1679. "espresso/latte/../../../..") => LFS_ERR_NOENT;
  1680. lfs_rename(&lfs,
  1681. "coffee/vietnamese/../..",
  1682. "espresso/cappuccino/../../../../..") => LFS_ERR_NOENT;
  1683. lfs_rename(&lfs,
  1684. "coffee/thai/..",
  1685. "espresso/mocha/../../../../../..") => LFS_ERR_NOENT;
  1686. } else {
  1687. // bad source
  1688. lfs_rename(&lfs,
  1689. "coffee/drip/../../../../../..",
  1690. "espresso/espresso") => LFS_ERR_NOTDIR;
  1691. lfs_rename(&lfs,
  1692. "coffee/coldbrew/../../../../..",
  1693. "espresso/americano") => LFS_ERR_NOTDIR;
  1694. lfs_rename(&lfs,
  1695. "coffee/turkish/../../../..",
  1696. "espresso/macchiato") => LFS_ERR_NOTDIR;
  1697. lfs_rename(&lfs,
  1698. "coffee/tubruk/../../..",
  1699. "espresso/latte") => LFS_ERR_NOTDIR;
  1700. lfs_rename(&lfs,
  1701. "coffee/vietnamese/../..",
  1702. "espresso/cappuccino") => LFS_ERR_NOTDIR;
  1703. lfs_rename(&lfs,
  1704. "coffee/thai/..",
  1705. "espresso/mocha") => LFS_ERR_NOTDIR;
  1706. // bad destination
  1707. lfs_rename(&lfs,
  1708. "coffee/drip",
  1709. "espresso/espresso/..") => LFS_ERR_NOTDIR;
  1710. lfs_rename(&lfs,
  1711. "coffee/coldbrew",
  1712. "espresso/americano/../..") => LFS_ERR_NOTDIR;
  1713. lfs_rename(&lfs,
  1714. "coffee/turkish",
  1715. "espresso/macchiato/../../..") => LFS_ERR_NOTDIR;
  1716. lfs_rename(&lfs,
  1717. "coffee/tubruk",
  1718. "espresso/latte/../../../..") => LFS_ERR_NOTDIR;
  1719. lfs_rename(&lfs,
  1720. "coffee/vietnamese",
  1721. "espresso/cappuccino/../../../../..") => LFS_ERR_NOTDIR;
  1722. lfs_rename(&lfs,
  1723. "coffee/thai",
  1724. "espresso/mocha/../../../../../..") => LFS_ERR_NOTDIR;
  1725. // bad source and bad destination
  1726. lfs_rename(&lfs,
  1727. "coffee/drip/../../../../../..",
  1728. "espresso/espresso/..") => LFS_ERR_NOTDIR;
  1729. lfs_rename(&lfs,
  1730. "coffee/coldbrew/../../../../..",
  1731. "espresso/americano/../..") => LFS_ERR_NOTDIR;
  1732. lfs_rename(&lfs,
  1733. "coffee/turkish/../../../..",
  1734. "espresso/macchiato/../../..") => LFS_ERR_NOTDIR;
  1735. lfs_rename(&lfs,
  1736. "coffee/tubruk/../../..",
  1737. "espresso/latte/../../../..") => LFS_ERR_NOTDIR;
  1738. lfs_rename(&lfs,
  1739. "coffee/vietnamese/../..",
  1740. "espresso/cappuccino/../../../../..") => LFS_ERR_NOTDIR;
  1741. lfs_rename(&lfs,
  1742. "coffee/thai/..",
  1743. "espresso/mocha/../../../../../..") => LFS_ERR_NOTDIR;
  1744. }
  1745. // remove paths
  1746. if (DIR) {
  1747. lfs_remove(&lfs, "coffee/drip/..") => LFS_ERR_INVAL;
  1748. lfs_remove(&lfs, "coffee/coldbrew/../..") => LFS_ERR_INVAL;
  1749. lfs_remove(&lfs, "coffee/turkish/../../..") => LFS_ERR_INVAL;
  1750. lfs_remove(&lfs, "coffee/tubruk/../../../..") => LFS_ERR_INVAL;
  1751. lfs_remove(&lfs, "coffee/vietnamese/../../../../..") => LFS_ERR_INVAL;
  1752. lfs_remove(&lfs, "coffee/thai/../../../../../..") => LFS_ERR_INVAL;
  1753. } else {
  1754. lfs_remove(&lfs, "coffee/drip/..") => LFS_ERR_NOTDIR;
  1755. lfs_remove(&lfs, "coffee/coldbrew/../..") => LFS_ERR_NOTDIR;
  1756. lfs_remove(&lfs, "coffee/turkish/../../..") => LFS_ERR_NOTDIR;
  1757. lfs_remove(&lfs, "coffee/tubruk/../../../..") => LFS_ERR_NOTDIR;
  1758. lfs_remove(&lfs, "coffee/vietnamese/../../../../..") => LFS_ERR_NOTDIR;
  1759. lfs_remove(&lfs, "coffee/thai/../../../../../..") => LFS_ERR_NOTDIR;
  1760. }
  1761. // stat paths
  1762. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  1763. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  1764. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  1765. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  1766. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  1767. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  1768. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  1769. assert(strcmp(info.name, "drip") == 0);
  1770. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1771. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  1772. assert(strcmp(info.name, "coldbrew") == 0);
  1773. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1774. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  1775. assert(strcmp(info.name, "turkish") == 0);
  1776. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1777. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  1778. assert(strcmp(info.name, "tubruk") == 0);
  1779. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1780. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  1781. assert(strcmp(info.name, "vietnamese") == 0);
  1782. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1783. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  1784. assert(strcmp(info.name, "thai") == 0);
  1785. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1786. lfs_unmount(&lfs) => 0;
  1787. '''
  1788. # dot dot dot path tests
  1789. [cases.test_paths_dotdotdots]
  1790. defines.DIR = [false, true]
  1791. code = '''
  1792. lfs_t lfs;
  1793. lfs_format(&lfs, cfg) => 0;
  1794. lfs_mount(&lfs, cfg) => 0;
  1795. // create paths
  1796. lfs_mkdir(&lfs, "coffee") => 0;
  1797. lfs_mkdir(&lfs, "coffee/...") => 0;
  1798. if (DIR) {
  1799. lfs_mkdir(&lfs, "/coffee/.../drip") => 0;
  1800. lfs_mkdir(&lfs, "/coffee/.../coldbrew") => 0;
  1801. lfs_mkdir(&lfs, "/coffee/.../turkish") => 0;
  1802. lfs_mkdir(&lfs, "/coffee/.../tubruk") => 0;
  1803. lfs_mkdir(&lfs, "/coffee/.../vietnamese") => 0;
  1804. lfs_mkdir(&lfs, "/coffee/.../thai") => 0;
  1805. } else {
  1806. lfs_file_t file;
  1807. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1808. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1809. lfs_file_close(&lfs, &file) => 0;
  1810. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1811. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1812. lfs_file_close(&lfs, &file) => 0;
  1813. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1814. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1815. lfs_file_close(&lfs, &file) => 0;
  1816. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1817. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1818. lfs_file_close(&lfs, &file) => 0;
  1819. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  1820. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1821. lfs_file_close(&lfs, &file) => 0;
  1822. lfs_file_open(&lfs, &file, "/coffee/.../thai",
  1823. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1824. lfs_file_close(&lfs, &file) => 0;
  1825. }
  1826. // stat paths
  1827. struct lfs_info info;
  1828. lfs_stat(&lfs, "/coffee/.../drip", &info) => 0;
  1829. assert(strcmp(info.name, "drip") == 0);
  1830. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1831. lfs_stat(&lfs, "/coffee/.../coldbrew", &info) => 0;
  1832. assert(strcmp(info.name, "coldbrew") == 0);
  1833. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1834. lfs_stat(&lfs, "/coffee/.../turkish", &info) => 0;
  1835. assert(strcmp(info.name, "turkish") == 0);
  1836. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1837. lfs_stat(&lfs, "/coffee/.../tubruk", &info) => 0;
  1838. assert(strcmp(info.name, "tubruk") == 0);
  1839. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1840. lfs_stat(&lfs, "/coffee/.../vietnamese", &info) => 0;
  1841. assert(strcmp(info.name, "vietnamese") == 0);
  1842. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1843. lfs_stat(&lfs, "/coffee/.../thai", &info) => 0;
  1844. assert(strcmp(info.name, "thai") == 0);
  1845. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1846. // file open paths, only works on files!
  1847. if (DIR) {
  1848. lfs_file_t file;
  1849. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1850. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1851. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1852. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1853. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1854. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1855. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1856. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1857. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  1858. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1859. lfs_file_open(&lfs, &file, "/coffee/.../thai",
  1860. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  1861. } else {
  1862. lfs_file_t file;
  1863. lfs_file_open(&lfs, &file, "/coffee/.../drip",
  1864. LFS_O_RDONLY) => 0;
  1865. lfs_file_close(&lfs, &file) => 0;
  1866. lfs_file_open(&lfs, &file, "/coffee/.../coldbrew",
  1867. LFS_O_RDONLY) => 0;
  1868. lfs_file_close(&lfs, &file) => 0;
  1869. lfs_file_open(&lfs, &file, "/coffee/.../turkish",
  1870. LFS_O_RDONLY) => 0;
  1871. lfs_file_close(&lfs, &file) => 0;
  1872. lfs_file_open(&lfs, &file, "/coffee/.../tubruk",
  1873. LFS_O_RDONLY) => 0;
  1874. lfs_file_close(&lfs, &file) => 0;
  1875. lfs_file_open(&lfs, &file, "/coffee/.../vietnamese",
  1876. LFS_O_RDONLY) => 0;
  1877. lfs_file_close(&lfs, &file) => 0;
  1878. lfs_file_open(&lfs, &file, "/coffee/.../thai",
  1879. LFS_O_RDONLY) => 0;
  1880. lfs_file_close(&lfs, &file) => 0;
  1881. }
  1882. // dir open paths, only works on dirs!
  1883. if (DIR) {
  1884. lfs_dir_t dir;
  1885. lfs_dir_open(&lfs, &dir, "/coffee/.../drip") => 0;
  1886. lfs_dir_close(&lfs, &dir) => 0;
  1887. lfs_dir_open(&lfs, &dir, "/coffee/.../coldbrew") => 0;
  1888. lfs_dir_close(&lfs, &dir) => 0;
  1889. lfs_dir_open(&lfs, &dir, "/coffee/.../turkish") => 0;
  1890. lfs_dir_close(&lfs, &dir) => 0;
  1891. lfs_dir_open(&lfs, &dir, "/coffee/.../tubruk") => 0;
  1892. lfs_dir_close(&lfs, &dir) => 0;
  1893. lfs_dir_open(&lfs, &dir, "/coffee/.../vietnamese") => 0;
  1894. lfs_dir_close(&lfs, &dir) => 0;
  1895. lfs_dir_open(&lfs, &dir, "/coffee/.../thai") => 0;
  1896. lfs_dir_close(&lfs, &dir) => 0;
  1897. } else {
  1898. lfs_dir_t dir;
  1899. lfs_dir_open(&lfs, &dir, "/coffee/.../drip") => LFS_ERR_NOTDIR;
  1900. lfs_dir_open(&lfs, &dir, "/coffee/.../coldbrew") => LFS_ERR_NOTDIR;
  1901. lfs_dir_open(&lfs, &dir, "/coffee/.../turkish") => LFS_ERR_NOTDIR;
  1902. lfs_dir_open(&lfs, &dir, "/coffee/.../tubruk") => LFS_ERR_NOTDIR;
  1903. lfs_dir_open(&lfs, &dir, "/coffee/.../vietnamese") => LFS_ERR_NOTDIR;
  1904. lfs_dir_open(&lfs, &dir, "/coffee/.../thai") => LFS_ERR_NOTDIR;
  1905. }
  1906. // rename paths
  1907. lfs_mkdir(&lfs, "espresso") => 0;
  1908. lfs_mkdir(&lfs, "espresso/...") => 0;
  1909. lfs_rename(&lfs,
  1910. "/coffee/.../drip",
  1911. "/espresso/.../espresso") => 0;
  1912. lfs_rename(&lfs,
  1913. "/coffee/.../coldbrew",
  1914. "/espresso/.../americano") => 0;
  1915. lfs_rename(&lfs,
  1916. "/coffee/.../turkish",
  1917. "/espresso/.../macchiato") => 0;
  1918. lfs_rename(&lfs,
  1919. "/coffee/.../tubruk",
  1920. "/espresso/.../latte") => 0;
  1921. lfs_rename(&lfs,
  1922. "/coffee/.../vietnamese",
  1923. "/espresso/.../cappuccino") => 0;
  1924. lfs_rename(&lfs,
  1925. "/coffee/.../thai",
  1926. "/espresso/.../mocha") => 0;
  1927. // stat paths
  1928. lfs_stat(&lfs, "/espresso/.../espresso", &info) => 0;
  1929. assert(strcmp(info.name, "espresso") == 0);
  1930. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1931. lfs_stat(&lfs, "/espresso/.../americano", &info) => 0;
  1932. assert(strcmp(info.name, "americano") == 0);
  1933. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1934. lfs_stat(&lfs, "/espresso/.../macchiato", &info) => 0;
  1935. assert(strcmp(info.name, "macchiato") == 0);
  1936. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1937. lfs_stat(&lfs, "/espresso/.../latte", &info) => 0;
  1938. assert(strcmp(info.name, "latte") == 0);
  1939. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1940. lfs_stat(&lfs, "/espresso/.../cappuccino", &info) => 0;
  1941. assert(strcmp(info.name, "cappuccino") == 0);
  1942. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1943. lfs_stat(&lfs, "/espresso/.../mocha", &info) => 0;
  1944. assert(strcmp(info.name, "mocha") == 0);
  1945. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  1946. lfs_stat(&lfs, "coffee/.../drip", &info) => LFS_ERR_NOENT;
  1947. lfs_stat(&lfs, "coffee/.../coldbrew", &info) => LFS_ERR_NOENT;
  1948. lfs_stat(&lfs, "coffee/.../turkish", &info) => LFS_ERR_NOENT;
  1949. lfs_stat(&lfs, "coffee/.../tubruk", &info) => LFS_ERR_NOENT;
  1950. lfs_stat(&lfs, "coffee/.../vietnamese", &info) => LFS_ERR_NOENT;
  1951. lfs_stat(&lfs, "coffee/.../thai", &info) => LFS_ERR_NOENT;
  1952. // remove paths
  1953. lfs_remove(&lfs, "/espresso/.../espresso") => 0;
  1954. lfs_remove(&lfs, "/espresso/.../americano") => 0;
  1955. lfs_remove(&lfs, "/espresso/.../macchiato") => 0;
  1956. lfs_remove(&lfs, "/espresso/.../latte") => 0;
  1957. lfs_remove(&lfs, "/espresso/.../cappuccino") => 0;
  1958. lfs_remove(&lfs, "/espresso/.../mocha") => 0;
  1959. // stat paths
  1960. lfs_stat(&lfs, "/espresso/.../espresso", &info) => LFS_ERR_NOENT;
  1961. lfs_stat(&lfs, "/espresso/.../americano", &info) => LFS_ERR_NOENT;
  1962. lfs_stat(&lfs, "/espresso/.../macchiato", &info) => LFS_ERR_NOENT;
  1963. lfs_stat(&lfs, "/espresso/.../latte", &info) => LFS_ERR_NOENT;
  1964. lfs_stat(&lfs, "/espresso/.../cappuccino", &info) => LFS_ERR_NOENT;
  1965. lfs_stat(&lfs, "/espresso/.../mocha", &info) => LFS_ERR_NOENT;
  1966. lfs_unmount(&lfs) => 0;
  1967. '''
  1968. # leading dot path test
  1969. [cases.test_paths_leading_dots]
  1970. defines.DIR = [false, true]
  1971. code = '''
  1972. lfs_t lfs;
  1973. lfs_format(&lfs, cfg) => 0;
  1974. lfs_mount(&lfs, cfg) => 0;
  1975. // create paths
  1976. lfs_mkdir(&lfs, "coffee") => 0;
  1977. if (DIR) {
  1978. lfs_mkdir(&lfs, "/coffee/.drip") => 0;
  1979. lfs_mkdir(&lfs, "/coffee/..coldbrew") => 0;
  1980. lfs_mkdir(&lfs, "/coffee/...turkish") => 0;
  1981. lfs_mkdir(&lfs, "/coffee/....tubruk") => 0;
  1982. lfs_mkdir(&lfs, "/coffee/.....vietnamese") => 0;
  1983. lfs_mkdir(&lfs, "/coffee/......thai") => 0;
  1984. } else {
  1985. lfs_file_t file;
  1986. lfs_file_open(&lfs, &file, "/coffee/.drip",
  1987. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1988. lfs_file_close(&lfs, &file) => 0;
  1989. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  1990. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1991. lfs_file_close(&lfs, &file) => 0;
  1992. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  1993. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1994. lfs_file_close(&lfs, &file) => 0;
  1995. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  1996. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  1997. lfs_file_close(&lfs, &file) => 0;
  1998. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  1999. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2000. lfs_file_close(&lfs, &file) => 0;
  2001. lfs_file_open(&lfs, &file, "/coffee/......thai",
  2002. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2003. lfs_file_close(&lfs, &file) => 0;
  2004. }
  2005. // stat paths
  2006. struct lfs_info info;
  2007. lfs_stat(&lfs, "/coffee/.drip", &info) => 0;
  2008. assert(strcmp(info.name, ".drip") == 0);
  2009. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2010. lfs_stat(&lfs, "/coffee/..coldbrew", &info) => 0;
  2011. assert(strcmp(info.name, "..coldbrew") == 0);
  2012. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2013. lfs_stat(&lfs, "/coffee/...turkish", &info) => 0;
  2014. assert(strcmp(info.name, "...turkish") == 0);
  2015. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2016. lfs_stat(&lfs, "/coffee/....tubruk", &info) => 0;
  2017. assert(strcmp(info.name, "....tubruk") == 0);
  2018. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2019. lfs_stat(&lfs, "/coffee/.....vietnamese", &info) => 0;
  2020. assert(strcmp(info.name, ".....vietnamese") == 0);
  2021. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2022. lfs_stat(&lfs, "/coffee/......thai", &info) => 0;
  2023. assert(strcmp(info.name, "......thai") == 0);
  2024. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2025. // file open paths, only works on files!
  2026. if (DIR) {
  2027. lfs_file_t file;
  2028. lfs_file_open(&lfs, &file, "/coffee/.drip",
  2029. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2030. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  2031. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2032. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  2033. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2034. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  2035. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2036. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  2037. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2038. lfs_file_open(&lfs, &file, "/coffee/......thai",
  2039. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2040. } else {
  2041. lfs_file_t file;
  2042. lfs_file_open(&lfs, &file, "/coffee/.drip",
  2043. LFS_O_RDONLY) => 0;
  2044. lfs_file_close(&lfs, &file) => 0;
  2045. lfs_file_open(&lfs, &file, "/coffee/..coldbrew",
  2046. LFS_O_RDONLY) => 0;
  2047. lfs_file_close(&lfs, &file) => 0;
  2048. lfs_file_open(&lfs, &file, "/coffee/...turkish",
  2049. LFS_O_RDONLY) => 0;
  2050. lfs_file_close(&lfs, &file) => 0;
  2051. lfs_file_open(&lfs, &file, "/coffee/....tubruk",
  2052. LFS_O_RDONLY) => 0;
  2053. lfs_file_close(&lfs, &file) => 0;
  2054. lfs_file_open(&lfs, &file, "/coffee/.....vietnamese",
  2055. LFS_O_RDONLY) => 0;
  2056. lfs_file_close(&lfs, &file) => 0;
  2057. lfs_file_open(&lfs, &file, "/coffee/......thai",
  2058. LFS_O_RDONLY) => 0;
  2059. lfs_file_close(&lfs, &file) => 0;
  2060. }
  2061. // dir open paths, only works on dirs!
  2062. if (DIR) {
  2063. lfs_dir_t dir;
  2064. lfs_dir_open(&lfs, &dir, "/coffee/.drip") => 0;
  2065. lfs_dir_close(&lfs, &dir) => 0;
  2066. lfs_dir_open(&lfs, &dir, "/coffee/..coldbrew") => 0;
  2067. lfs_dir_close(&lfs, &dir) => 0;
  2068. lfs_dir_open(&lfs, &dir, "/coffee/...turkish") => 0;
  2069. lfs_dir_close(&lfs, &dir) => 0;
  2070. lfs_dir_open(&lfs, &dir, "/coffee/....tubruk") => 0;
  2071. lfs_dir_close(&lfs, &dir) => 0;
  2072. lfs_dir_open(&lfs, &dir, "/coffee/.....vietnamese") => 0;
  2073. lfs_dir_close(&lfs, &dir) => 0;
  2074. lfs_dir_open(&lfs, &dir, "/coffee/......thai") => 0;
  2075. lfs_dir_close(&lfs, &dir) => 0;
  2076. } else {
  2077. lfs_dir_t dir;
  2078. lfs_dir_open(&lfs, &dir, "/coffee/.drip") => LFS_ERR_NOTDIR;
  2079. lfs_dir_open(&lfs, &dir, "/coffee/..coldbrew") => LFS_ERR_NOTDIR;
  2080. lfs_dir_open(&lfs, &dir, "/coffee/...turkish") => LFS_ERR_NOTDIR;
  2081. lfs_dir_open(&lfs, &dir, "/coffee/....tubruk") => LFS_ERR_NOTDIR;
  2082. lfs_dir_open(&lfs, &dir, "/coffee/.....vietnamese") => LFS_ERR_NOTDIR;
  2083. lfs_dir_open(&lfs, &dir, "/coffee/......thai") => LFS_ERR_NOTDIR;
  2084. }
  2085. // rename paths
  2086. lfs_mkdir(&lfs, "espresso") => 0;
  2087. lfs_rename(&lfs,
  2088. "/coffee/.drip",
  2089. "/espresso/.espresso") => 0;
  2090. lfs_rename(&lfs,
  2091. "/coffee/..coldbrew",
  2092. "/espresso/..americano") => 0;
  2093. lfs_rename(&lfs,
  2094. "/coffee/...turkish",
  2095. "/espresso/...macchiato") => 0;
  2096. lfs_rename(&lfs,
  2097. "/coffee/....tubruk",
  2098. "/espresso/....latte") => 0;
  2099. lfs_rename(&lfs,
  2100. "/coffee/.....vietnamese",
  2101. "/espresso/.....cappuccino") => 0;
  2102. lfs_rename(&lfs,
  2103. "/coffee/......thai",
  2104. "/espresso/......mocha") => 0;
  2105. // stat paths
  2106. lfs_stat(&lfs, "/espresso/.espresso", &info) => 0;
  2107. assert(strcmp(info.name, ".espresso") == 0);
  2108. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2109. lfs_stat(&lfs, "/espresso/..americano", &info) => 0;
  2110. assert(strcmp(info.name, "..americano") == 0);
  2111. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2112. lfs_stat(&lfs, "/espresso/...macchiato", &info) => 0;
  2113. assert(strcmp(info.name, "...macchiato") == 0);
  2114. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2115. lfs_stat(&lfs, "/espresso/....latte", &info) => 0;
  2116. assert(strcmp(info.name, "....latte") == 0);
  2117. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2118. lfs_stat(&lfs, "/espresso/.....cappuccino", &info) => 0;
  2119. assert(strcmp(info.name, ".....cappuccino") == 0);
  2120. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2121. lfs_stat(&lfs, "/espresso/......mocha", &info) => 0;
  2122. assert(strcmp(info.name, "......mocha") == 0);
  2123. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2124. lfs_stat(&lfs, "coffee/.drip", &info) => LFS_ERR_NOENT;
  2125. lfs_stat(&lfs, "coffee/..coldbrew", &info) => LFS_ERR_NOENT;
  2126. lfs_stat(&lfs, "coffee/...turkish", &info) => LFS_ERR_NOENT;
  2127. lfs_stat(&lfs, "coffee/....tubruk", &info) => LFS_ERR_NOENT;
  2128. lfs_stat(&lfs, "coffee/.....vietnamese", &info) => LFS_ERR_NOENT;
  2129. lfs_stat(&lfs, "coffee/......thai", &info) => LFS_ERR_NOENT;
  2130. // remove paths
  2131. lfs_remove(&lfs, "/espresso/.espresso") => 0;
  2132. lfs_remove(&lfs, "/espresso/..americano") => 0;
  2133. lfs_remove(&lfs, "/espresso/...macchiato") => 0;
  2134. lfs_remove(&lfs, "/espresso/....latte") => 0;
  2135. lfs_remove(&lfs, "/espresso/.....cappuccino") => 0;
  2136. lfs_remove(&lfs, "/espresso/......mocha") => 0;
  2137. // stat paths
  2138. lfs_stat(&lfs, "/espresso/.espresso", &info) => LFS_ERR_NOENT;
  2139. lfs_stat(&lfs, "/espresso/..americano", &info) => LFS_ERR_NOENT;
  2140. lfs_stat(&lfs, "/espresso/...macchiato", &info) => LFS_ERR_NOENT;
  2141. lfs_stat(&lfs, "/espresso/....latte", &info) => LFS_ERR_NOENT;
  2142. lfs_stat(&lfs, "/espresso/.....cappuccino", &info) => LFS_ERR_NOENT;
  2143. lfs_stat(&lfs, "/espresso/......mocha", &info) => LFS_ERR_NOENT;
  2144. lfs_unmount(&lfs) => 0;
  2145. '''
  2146. # root dot dot path test
  2147. [cases.test_paths_root_dotdots]
  2148. defines.DIR = [false, true]
  2149. code = '''
  2150. lfs_t lfs;
  2151. lfs_format(&lfs, cfg) => 0;
  2152. lfs_mount(&lfs, cfg) => 0;
  2153. // create paths
  2154. lfs_mkdir(&lfs, "no") => 0;
  2155. lfs_mkdir(&lfs, "coffee") => 0;
  2156. if (DIR) {
  2157. lfs_mkdir(&lfs, "/../coffee/drip") => 0;
  2158. lfs_mkdir(&lfs, "/../../coffee/coldbrew") => 0;
  2159. lfs_mkdir(&lfs, "/../../../coffee/turkish") => 0;
  2160. lfs_mkdir(&lfs, "/no/../../coffee/tubruk") => 0;
  2161. lfs_mkdir(&lfs, "/no/../../../coffee/vietnamese") => 0;
  2162. lfs_mkdir(&lfs, "/no/../../../../coffee/thai") => 0;
  2163. } else {
  2164. lfs_file_t file;
  2165. lfs_file_open(&lfs, &file, "/../coffee/drip",
  2166. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2167. lfs_file_close(&lfs, &file) => 0;
  2168. lfs_file_open(&lfs, &file, "/../../coffee/coldbrew",
  2169. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2170. lfs_file_close(&lfs, &file) => 0;
  2171. lfs_file_open(&lfs, &file, "/../../../coffee/turkish",
  2172. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2173. lfs_file_close(&lfs, &file) => 0;
  2174. lfs_file_open(&lfs, &file, "/no/../../coffee/tubruk",
  2175. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2176. lfs_file_close(&lfs, &file) => 0;
  2177. lfs_file_open(&lfs, &file, "/no/../../../coffee/vietnamese",
  2178. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2179. lfs_file_close(&lfs, &file) => 0;
  2180. lfs_file_open(&lfs, &file, "/no/../../../../coffee/thai",
  2181. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2182. lfs_file_close(&lfs, &file) => 0;
  2183. }
  2184. // stat paths
  2185. struct lfs_info info;
  2186. lfs_stat(&lfs, "/no/../../../../coffee/drip", &info) => 0;
  2187. assert(strcmp(info.name, "drip") == 0);
  2188. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2189. lfs_stat(&lfs, "/no/../../../coffee/coldbrew", &info) => 0;
  2190. assert(strcmp(info.name, "coldbrew") == 0);
  2191. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2192. lfs_stat(&lfs, "/no/../../coffee/turkish", &info) => 0;
  2193. assert(strcmp(info.name, "turkish") == 0);
  2194. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2195. lfs_stat(&lfs, "/../../../coffee/tubruk", &info) => 0;
  2196. assert(strcmp(info.name, "tubruk") == 0);
  2197. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2198. lfs_stat(&lfs, "/../../coffee/vietnamese", &info) => 0;
  2199. assert(strcmp(info.name, "vietnamese") == 0);
  2200. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2201. lfs_stat(&lfs, "/../coffee/thai", &info) => 0;
  2202. assert(strcmp(info.name, "thai") == 0);
  2203. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2204. // file open paths, only works on files!
  2205. if (DIR) {
  2206. lfs_file_t file;
  2207. lfs_file_open(&lfs, &file, "/../coffee/drip",
  2208. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2209. lfs_file_open(&lfs, &file, "/../../coffee/coldbrew",
  2210. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2211. lfs_file_open(&lfs, &file, "/../../../coffee/turkish",
  2212. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2213. lfs_file_open(&lfs, &file, "/no/../../coffee/tubruk",
  2214. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2215. lfs_file_open(&lfs, &file, "/no/../../../coffee/vietnamese",
  2216. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2217. lfs_file_open(&lfs, &file, "/no/../../../../coffee/thai",
  2218. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2219. } else {
  2220. lfs_file_t file;
  2221. lfs_file_open(&lfs, &file, "/../coffee/drip",
  2222. LFS_O_RDONLY) => 0;
  2223. lfs_file_close(&lfs, &file) => 0;
  2224. lfs_file_open(&lfs, &file, "/../../coffee/coldbrew",
  2225. LFS_O_RDONLY) => 0;
  2226. lfs_file_close(&lfs, &file) => 0;
  2227. lfs_file_open(&lfs, &file, "/../../../coffee/turkish",
  2228. LFS_O_RDONLY) => 0;
  2229. lfs_file_close(&lfs, &file) => 0;
  2230. lfs_file_open(&lfs, &file, "/no/../../coffee/tubruk",
  2231. LFS_O_RDONLY) => 0;
  2232. lfs_file_close(&lfs, &file) => 0;
  2233. lfs_file_open(&lfs, &file, "/no/../../../coffee/vietnamese",
  2234. LFS_O_RDONLY) => 0;
  2235. lfs_file_close(&lfs, &file) => 0;
  2236. lfs_file_open(&lfs, &file, "/no/../../../../coffee/thai",
  2237. LFS_O_RDONLY) => 0;
  2238. lfs_file_close(&lfs, &file) => 0;
  2239. }
  2240. // dir open paths, only works on dirs!
  2241. if (DIR) {
  2242. lfs_dir_t dir;
  2243. lfs_dir_open(&lfs, &dir, "/../coffee/drip") => 0;
  2244. lfs_dir_close(&lfs, &dir) => 0;
  2245. lfs_dir_open(&lfs, &dir, "/../../coffee/coldbrew") => 0;
  2246. lfs_dir_close(&lfs, &dir) => 0;
  2247. lfs_dir_open(&lfs, &dir, "/../../../coffee/turkish") => 0;
  2248. lfs_dir_close(&lfs, &dir) => 0;
  2249. lfs_dir_open(&lfs, &dir, "/no/../../coffee/tubruk") => 0;
  2250. lfs_dir_close(&lfs, &dir) => 0;
  2251. lfs_dir_open(&lfs, &dir, "/no/../../../coffee/vietnamese") => 0;
  2252. lfs_dir_close(&lfs, &dir) => 0;
  2253. lfs_dir_open(&lfs, &dir, "/no/../../../../coffee/thai") => 0;
  2254. lfs_dir_close(&lfs, &dir) => 0;
  2255. } else {
  2256. lfs_dir_t dir;
  2257. lfs_dir_open(&lfs, &dir, "/../coffee/drip") => LFS_ERR_NOTDIR;
  2258. lfs_dir_open(&lfs, &dir, "/../../coffee/coldbrew") => LFS_ERR_NOTDIR;
  2259. lfs_dir_open(&lfs, &dir, "/../../../coffee/turkish") => LFS_ERR_NOTDIR;
  2260. lfs_dir_open(&lfs, &dir, "/no/../coffee/tubruk") => LFS_ERR_NOTDIR;
  2261. lfs_dir_open(&lfs, &dir, "/no/../../coffee/vietnamese") => LFS_ERR_NOTDIR;
  2262. lfs_dir_open(&lfs, &dir, "/no/../../../coffee/thai") => LFS_ERR_NOTDIR;
  2263. }
  2264. // rename paths
  2265. lfs_mkdir(&lfs, "espresso") => 0;
  2266. lfs_rename(&lfs,
  2267. "/no/../../../../coffee/drip",
  2268. "/../espresso/espresso") => 0;
  2269. lfs_rename(&lfs,
  2270. "/no/../../../coffee/coldbrew",
  2271. "/../../espresso/americano") => 0;
  2272. lfs_rename(&lfs,
  2273. "/no/../../coffee/turkish",
  2274. "/../../../espresso/macchiato") => 0;
  2275. lfs_rename(&lfs,
  2276. "/../../../coffee/tubruk",
  2277. "/no/../../espresso/latte") => 0;
  2278. lfs_rename(&lfs,
  2279. "/../../coffee/vietnamese",
  2280. "/no/../../../espresso/cappuccino") => 0;
  2281. lfs_rename(&lfs,
  2282. "/../coffee/thai",
  2283. "/no/../../../../espresso/mocha") => 0;
  2284. // stat paths
  2285. lfs_stat(&lfs, "/no/../../../../espresso/espresso", &info) => 0;
  2286. assert(strcmp(info.name, "espresso") == 0);
  2287. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2288. lfs_stat(&lfs, "/no/../../../espresso/americano", &info) => 0;
  2289. assert(strcmp(info.name, "americano") == 0);
  2290. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2291. lfs_stat(&lfs, "/no/../../espresso/macchiato", &info) => 0;
  2292. assert(strcmp(info.name, "macchiato") == 0);
  2293. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2294. lfs_stat(&lfs, "/../../../espresso/latte", &info) => 0;
  2295. assert(strcmp(info.name, "latte") == 0);
  2296. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2297. lfs_stat(&lfs, "/../../espresso/cappuccino", &info) => 0;
  2298. assert(strcmp(info.name, "cappuccino") == 0);
  2299. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2300. lfs_stat(&lfs, "/../espresso/mocha", &info) => 0;
  2301. assert(strcmp(info.name, "mocha") == 0);
  2302. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2303. lfs_stat(&lfs, "/no/../../../../coffee/drip", &info) => LFS_ERR_NOENT;
  2304. lfs_stat(&lfs, "/no/../../../coffee/coldbrew", &info) => LFS_ERR_NOENT;
  2305. lfs_stat(&lfs, "/no/../../coffee/turkish", &info) => LFS_ERR_NOENT;
  2306. lfs_stat(&lfs, "/../../../coffee/tubruk", &info) => LFS_ERR_NOENT;
  2307. lfs_stat(&lfs, "/../../coffee/vietnamese", &info) => LFS_ERR_NOENT;
  2308. lfs_stat(&lfs, "/../coffee/thai", &info) => LFS_ERR_NOENT;
  2309. // remove paths
  2310. lfs_remove(&lfs, "/../espresso/espresso") => 0;
  2311. lfs_remove(&lfs, "/../../espresso/americano") => 0;
  2312. lfs_remove(&lfs, "/../../../espresso/macchiato") => 0;
  2313. lfs_remove(&lfs, "/no/../../espresso/latte") => 0;
  2314. lfs_remove(&lfs, "/no/../../../espresso/cappuccino") => 0;
  2315. lfs_remove(&lfs, "/no/../../../../espresso/mocha") => 0;
  2316. // stat paths
  2317. lfs_stat(&lfs, "/no/../../../../espresso/espresso", &info) => LFS_ERR_NOENT;
  2318. lfs_stat(&lfs, "/no/../../../espresso/americano", &info) => LFS_ERR_NOENT;
  2319. lfs_stat(&lfs, "/no/../../espresso/macchiato", &info) => LFS_ERR_NOENT;
  2320. lfs_stat(&lfs, "/../../../espresso/latte", &info) => LFS_ERR_NOENT;
  2321. lfs_stat(&lfs, "/../../espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2322. lfs_stat(&lfs, "/../espresso/mocha", &info) => LFS_ERR_NOENT;
  2323. lfs_unmount(&lfs) => 0;
  2324. '''
  2325. # trailing noent tests
  2326. [cases.test_paths_noent]
  2327. defines.DIR = [false, true]
  2328. code = '''
  2329. lfs_t lfs;
  2330. lfs_format(&lfs, cfg) => 0;
  2331. lfs_mount(&lfs, cfg) => 0;
  2332. // create paths
  2333. lfs_mkdir(&lfs, "coffee") => 0;
  2334. if (DIR) {
  2335. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2336. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2337. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2338. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2339. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2340. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2341. } else {
  2342. lfs_file_t file;
  2343. lfs_file_open(&lfs, &file, "coffee/drip",
  2344. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2345. lfs_file_close(&lfs, &file) => 0;
  2346. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  2347. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2348. lfs_file_close(&lfs, &file) => 0;
  2349. lfs_file_open(&lfs, &file, "coffee/turkish",
  2350. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2351. lfs_file_close(&lfs, &file) => 0;
  2352. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2353. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2354. lfs_file_close(&lfs, &file) => 0;
  2355. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2356. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2357. lfs_file_close(&lfs, &file) => 0;
  2358. lfs_file_open(&lfs, &file, "coffee/thai",
  2359. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2360. lfs_file_close(&lfs, &file) => 0;
  2361. }
  2362. // stat paths
  2363. struct lfs_info info;
  2364. lfs_stat(&lfs, "coffee/_rip", &info) => LFS_ERR_NOENT;
  2365. lfs_stat(&lfs, "coffee/c_ldbrew", &info) => LFS_ERR_NOENT;
  2366. lfs_stat(&lfs, "coffee/tu_kish", &info) => LFS_ERR_NOENT;
  2367. lfs_stat(&lfs, "coffee/tub_uk", &info) => LFS_ERR_NOENT;
  2368. lfs_stat(&lfs, "coffee/_vietnamese", &info) => LFS_ERR_NOENT;
  2369. lfs_stat(&lfs, "coffee/thai_", &info) => LFS_ERR_NOENT;
  2370. // file open paths, only works on files!
  2371. lfs_file_t file;
  2372. lfs_file_open(&lfs, &file, "coffee/_rip",
  2373. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2374. lfs_file_open(&lfs, &file, "coffee/c_ldbrew",
  2375. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2376. lfs_file_open(&lfs, &file, "coffee/tu_kish",
  2377. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2378. lfs_file_open(&lfs, &file, "coffee/tub_uk",
  2379. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2380. lfs_file_open(&lfs, &file, "coffee/_vietnamese",
  2381. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2382. lfs_file_open(&lfs, &file, "coffee/thai_",
  2383. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2384. // dir open paths, only works on dirs!
  2385. lfs_dir_t dir;
  2386. lfs_dir_open(&lfs, &dir, "coffee/_rip") => LFS_ERR_NOENT;
  2387. lfs_dir_open(&lfs, &dir, "coffee/c_ldbrew") => LFS_ERR_NOENT;
  2388. lfs_dir_open(&lfs, &dir, "coffee/tu_kish") => LFS_ERR_NOENT;
  2389. lfs_dir_open(&lfs, &dir, "coffee/tub_uk") => LFS_ERR_NOENT;
  2390. lfs_dir_open(&lfs, &dir, "coffee/_vietnamese") => LFS_ERR_NOENT;
  2391. lfs_dir_open(&lfs, &dir, "coffee/thai_") => LFS_ERR_NOENT;
  2392. // rename paths
  2393. lfs_mkdir(&lfs, "espresso") => 0;
  2394. lfs_rename(&lfs,
  2395. "coffee/_rip",
  2396. "espresso/espresso") => LFS_ERR_NOENT;
  2397. lfs_rename(&lfs,
  2398. "coffee/c_ldbrew",
  2399. "espresso/americano") => LFS_ERR_NOENT;
  2400. lfs_rename(&lfs,
  2401. "coffee/tu_kish",
  2402. "espresso/macchiato") => LFS_ERR_NOENT;
  2403. lfs_rename(&lfs,
  2404. "coffee/tub_uk",
  2405. "espresso/latte") => LFS_ERR_NOENT;
  2406. lfs_rename(&lfs,
  2407. "coffee/_vietnamese",
  2408. "espresso/cappuccino") => LFS_ERR_NOENT;
  2409. lfs_rename(&lfs,
  2410. "coffee/thai_",
  2411. "espresso/mocha") => LFS_ERR_NOENT;
  2412. // remove paths
  2413. lfs_remove(&lfs, "coffee/_rip") => LFS_ERR_NOENT;
  2414. lfs_remove(&lfs, "coffee/c_ldbrew") => LFS_ERR_NOENT;
  2415. lfs_remove(&lfs, "coffee/tu_kish") => LFS_ERR_NOENT;
  2416. lfs_remove(&lfs, "coffee/tub_uk") => LFS_ERR_NOENT;
  2417. lfs_remove(&lfs, "coffee/_vietnamese") => LFS_ERR_NOENT;
  2418. lfs_remove(&lfs, "coffee/thai_") => LFS_ERR_NOENT;
  2419. // stat paths
  2420. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  2421. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  2422. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  2423. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  2424. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2425. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  2426. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2427. assert(strcmp(info.name, "drip") == 0);
  2428. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2429. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2430. assert(strcmp(info.name, "coldbrew") == 0);
  2431. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2432. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2433. assert(strcmp(info.name, "turkish") == 0);
  2434. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2435. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2436. assert(strcmp(info.name, "tubruk") == 0);
  2437. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2438. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2439. assert(strcmp(info.name, "vietnamese") == 0);
  2440. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2441. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2442. assert(strcmp(info.name, "thai") == 0);
  2443. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2444. lfs_unmount(&lfs) => 0;
  2445. '''
  2446. # parent noent tests
  2447. [cases.test_paths_noent_parent]
  2448. defines.DIR = [false, true]
  2449. code = '''
  2450. lfs_t lfs;
  2451. lfs_format(&lfs, cfg) => 0;
  2452. lfs_mount(&lfs, cfg) => 0;
  2453. // create paths
  2454. lfs_mkdir(&lfs, "coffee") => 0;
  2455. if (DIR) {
  2456. lfs_mkdir(&lfs, "_offee/drip") => LFS_ERR_NOENT;
  2457. lfs_mkdir(&lfs, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2458. lfs_mkdir(&lfs, "co_fee/turkish") => LFS_ERR_NOENT;
  2459. lfs_mkdir(&lfs, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2460. lfs_mkdir(&lfs, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2461. lfs_mkdir(&lfs, "coffee_/thai") => LFS_ERR_NOENT;
  2462. } else {
  2463. lfs_file_t file;
  2464. lfs_file_open(&lfs, &file, "_offee/drip",
  2465. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2466. lfs_file_open(&lfs, &file, "c_ffee/coldbrew",
  2467. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2468. lfs_file_open(&lfs, &file, "co_fee/turkish",
  2469. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2470. lfs_file_open(&lfs, &file, "cof_ee/tubruk",
  2471. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2472. lfs_file_open(&lfs, &file, "_coffee/vietnamese",
  2473. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2474. lfs_file_open(&lfs, &file, "coffee_/thai",
  2475. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOENT;
  2476. }
  2477. // ok, actually create paths
  2478. if (DIR) {
  2479. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2480. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2481. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2482. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2483. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2484. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2485. } else {
  2486. lfs_file_t file;
  2487. lfs_file_open(&lfs, &file, "coffee/drip",
  2488. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2489. lfs_file_close(&lfs, &file) => 0;
  2490. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  2491. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2492. lfs_file_close(&lfs, &file) => 0;
  2493. lfs_file_open(&lfs, &file, "coffee/turkish",
  2494. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2495. lfs_file_close(&lfs, &file) => 0;
  2496. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2497. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2498. lfs_file_close(&lfs, &file) => 0;
  2499. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2500. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2501. lfs_file_close(&lfs, &file) => 0;
  2502. lfs_file_open(&lfs, &file, "coffee/thai",
  2503. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2504. lfs_file_close(&lfs, &file) => 0;
  2505. }
  2506. // stat paths
  2507. struct lfs_info info;
  2508. lfs_stat(&lfs, "_offee/drip", &info) => LFS_ERR_NOENT;
  2509. lfs_stat(&lfs, "c_ffee/coldbrew", &info) => LFS_ERR_NOENT;
  2510. lfs_stat(&lfs, "co_fee/turkish", &info) => LFS_ERR_NOENT;
  2511. lfs_stat(&lfs, "cof_ee/tubruk", &info) => LFS_ERR_NOENT;
  2512. lfs_stat(&lfs, "_coffee/vietnamese", &info) => LFS_ERR_NOENT;
  2513. lfs_stat(&lfs, "coffee_/thai", &info) => LFS_ERR_NOENT;
  2514. // file open paths, only works on files!
  2515. lfs_file_t file;
  2516. lfs_file_open(&lfs, &file, "_offee/drip",
  2517. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2518. lfs_file_open(&lfs, &file, "c_ffee/coldbrew",
  2519. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2520. lfs_file_open(&lfs, &file, "co_fee/turkish",
  2521. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2522. lfs_file_open(&lfs, &file, "cof_ee/tubruk",
  2523. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2524. lfs_file_open(&lfs, &file, "_coffee/vietnamese",
  2525. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2526. lfs_file_open(&lfs, &file, "coffee_/thai",
  2527. LFS_O_RDONLY) => LFS_ERR_NOENT;
  2528. // dir open paths, only works on dirs!
  2529. lfs_dir_t dir;
  2530. lfs_dir_open(&lfs, &dir, "_offee/drip") => LFS_ERR_NOENT;
  2531. lfs_dir_open(&lfs, &dir, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2532. lfs_dir_open(&lfs, &dir, "co_fee/turkish") => LFS_ERR_NOENT;
  2533. lfs_dir_open(&lfs, &dir, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2534. lfs_dir_open(&lfs, &dir, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2535. lfs_dir_open(&lfs, &dir, "coffee_/thai") => LFS_ERR_NOENT;
  2536. // rename paths
  2537. lfs_mkdir(&lfs, "espresso") => 0;
  2538. // bad source
  2539. lfs_rename(&lfs,
  2540. "_offee/drip",
  2541. "espresso/espresso") => LFS_ERR_NOENT;
  2542. lfs_rename(&lfs,
  2543. "c_ffee/coldbrew",
  2544. "espresso/americano") => LFS_ERR_NOENT;
  2545. lfs_rename(&lfs,
  2546. "co_fee/turkish",
  2547. "espresso/macchiato") => LFS_ERR_NOENT;
  2548. lfs_rename(&lfs,
  2549. "cof_ee/tubruk",
  2550. "espresso/latte") => LFS_ERR_NOENT;
  2551. lfs_rename(&lfs,
  2552. "_coffee/vietnamese",
  2553. "espresso/cappuccino") => LFS_ERR_NOENT;
  2554. lfs_rename(&lfs,
  2555. "coffee_/thai",
  2556. "espresso/mocha") => LFS_ERR_NOENT;
  2557. // bad destination
  2558. lfs_rename(&lfs,
  2559. "coffee/drip",
  2560. "_spresso/espresso") => LFS_ERR_NOENT;
  2561. lfs_rename(&lfs,
  2562. "coffee/coldbrew",
  2563. "e_presso/americano") => LFS_ERR_NOENT;
  2564. lfs_rename(&lfs,
  2565. "coffee/turkish",
  2566. "es_resso/macchiato") => LFS_ERR_NOENT;
  2567. lfs_rename(&lfs,
  2568. "coffee/tubruk",
  2569. "esp_esso/latte") => LFS_ERR_NOENT;
  2570. lfs_rename(&lfs,
  2571. "coffee/vietnamese",
  2572. "_espresso/cappuccino") => LFS_ERR_NOENT;
  2573. lfs_rename(&lfs,
  2574. "coffee/thai",
  2575. "espresso_/mocha") => LFS_ERR_NOENT;
  2576. // bad source and bad destination
  2577. lfs_rename(&lfs,
  2578. "_offee/drip",
  2579. "_spresso/espresso") => LFS_ERR_NOENT;
  2580. lfs_rename(&lfs,
  2581. "c_ffee/coldbrew",
  2582. "e_presso/americano") => LFS_ERR_NOENT;
  2583. lfs_rename(&lfs,
  2584. "co_fee/turkish",
  2585. "es_resso/macchiato") => LFS_ERR_NOENT;
  2586. lfs_rename(&lfs,
  2587. "cof_ee/tubruk",
  2588. "esp_esso/latte") => LFS_ERR_NOENT;
  2589. lfs_rename(&lfs,
  2590. "_coffee/vietnamese",
  2591. "_espresso/cappuccino") => LFS_ERR_NOENT;
  2592. lfs_rename(&lfs,
  2593. "coffee_/thai",
  2594. "espresso_/mocha") => LFS_ERR_NOENT;
  2595. // here's a weird one, what happens if our rename is also a noop?
  2596. lfs_rename(&lfs,
  2597. "_offee/drip",
  2598. "_offee/drip") => LFS_ERR_NOENT;
  2599. lfs_rename(&lfs,
  2600. "c_ffee/coldbrew",
  2601. "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2602. lfs_rename(&lfs,
  2603. "co_fee/turkish",
  2604. "co_fee/turkish") => LFS_ERR_NOENT;
  2605. lfs_rename(&lfs,
  2606. "cof_ee/tubruk",
  2607. "cof_ee/tubruk") => LFS_ERR_NOENT;
  2608. lfs_rename(&lfs,
  2609. "_coffee/vietnamese",
  2610. "_coffee/vietnamese") => LFS_ERR_NOENT;
  2611. lfs_rename(&lfs,
  2612. "coffee_/thai",
  2613. "coffee_/thai") => LFS_ERR_NOENT;
  2614. // remove paths
  2615. lfs_remove(&lfs, "_offee/drip") => LFS_ERR_NOENT;
  2616. lfs_remove(&lfs, "c_ffee/coldbrew") => LFS_ERR_NOENT;
  2617. lfs_remove(&lfs, "co_fee/turkish") => LFS_ERR_NOENT;
  2618. lfs_remove(&lfs, "cof_ee/tubruk") => LFS_ERR_NOENT;
  2619. lfs_remove(&lfs, "_coffee/vietnamese") => LFS_ERR_NOENT;
  2620. lfs_remove(&lfs, "coffee_/thai") => LFS_ERR_NOENT;
  2621. // stat paths
  2622. lfs_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT;
  2623. lfs_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT;
  2624. lfs_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT;
  2625. lfs_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT;
  2626. lfs_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT;
  2627. lfs_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT;
  2628. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2629. assert(strcmp(info.name, "drip") == 0);
  2630. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2631. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2632. assert(strcmp(info.name, "coldbrew") == 0);
  2633. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2634. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2635. assert(strcmp(info.name, "turkish") == 0);
  2636. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2637. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2638. assert(strcmp(info.name, "tubruk") == 0);
  2639. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2640. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2641. assert(strcmp(info.name, "vietnamese") == 0);
  2642. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2643. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2644. assert(strcmp(info.name, "thai") == 0);
  2645. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2646. lfs_unmount(&lfs) => 0;
  2647. '''
  2648. # parent notdir tests
  2649. [cases.test_paths_notdir_parent]
  2650. defines.DIR = [false, true]
  2651. code = '''
  2652. lfs_t lfs;
  2653. lfs_format(&lfs, cfg) => 0;
  2654. lfs_mount(&lfs, cfg) => 0;
  2655. // create paths
  2656. lfs_file_t file;
  2657. lfs_file_open(&lfs, &file, "drip",
  2658. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2659. lfs_file_close(&lfs, &file) => 0;
  2660. lfs_file_open(&lfs, &file, "coldbrew",
  2661. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2662. lfs_file_close(&lfs, &file) => 0;
  2663. lfs_file_open(&lfs, &file, "turkish",
  2664. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2665. lfs_file_close(&lfs, &file) => 0;
  2666. lfs_file_open(&lfs, &file, "tubruk",
  2667. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2668. lfs_file_close(&lfs, &file) => 0;
  2669. lfs_file_open(&lfs, &file, "vietnamese",
  2670. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2671. lfs_file_close(&lfs, &file) => 0;
  2672. lfs_file_open(&lfs, &file, "thai",
  2673. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2674. lfs_file_close(&lfs, &file) => 0;
  2675. if (DIR) {
  2676. lfs_mkdir(&lfs, "drip/coffee") => LFS_ERR_NOTDIR;
  2677. lfs_mkdir(&lfs, "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2678. lfs_mkdir(&lfs, "turkish/coffee") => LFS_ERR_NOTDIR;
  2679. lfs_mkdir(&lfs, "tubruk/coffee") => LFS_ERR_NOTDIR;
  2680. lfs_mkdir(&lfs, "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2681. lfs_mkdir(&lfs, "thai/coffee") => LFS_ERR_NOTDIR;
  2682. } else {
  2683. lfs_file_t file;
  2684. lfs_file_open(&lfs, &file, "drip/coffee",
  2685. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2686. lfs_file_open(&lfs, &file, "coldbrew/coffee",
  2687. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2688. lfs_file_open(&lfs, &file, "turkish/coffee",
  2689. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2690. lfs_file_open(&lfs, &file, "tubruk/coffee",
  2691. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2692. lfs_file_open(&lfs, &file, "vietnamese/coffee",
  2693. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2694. lfs_file_open(&lfs, &file, "thai/coffee",
  2695. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTDIR;
  2696. }
  2697. // stat paths
  2698. struct lfs_info info;
  2699. lfs_stat(&lfs, "drip/coffee", &info) => LFS_ERR_NOTDIR;
  2700. lfs_stat(&lfs, "coldbrew/coffee", &info) => LFS_ERR_NOTDIR;
  2701. lfs_stat(&lfs, "turkish/coffee", &info) => LFS_ERR_NOTDIR;
  2702. lfs_stat(&lfs, "tubruk/coffee", &info) => LFS_ERR_NOTDIR;
  2703. lfs_stat(&lfs, "vietnamese/coffee", &info) => LFS_ERR_NOTDIR;
  2704. lfs_stat(&lfs, "thai/coffee", &info) => LFS_ERR_NOTDIR;
  2705. // file open paths, only works on files!
  2706. lfs_file_open(&lfs, &file, "drip/coffee",
  2707. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2708. lfs_file_open(&lfs, &file, "coldbrew/coffee",
  2709. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2710. lfs_file_open(&lfs, &file, "turkish/coffee",
  2711. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2712. lfs_file_open(&lfs, &file, "tubruk/coffee",
  2713. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2714. lfs_file_open(&lfs, &file, "vietnamese/coffee",
  2715. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2716. lfs_file_open(&lfs, &file, "thai/coffee",
  2717. LFS_O_RDONLY) => LFS_ERR_NOTDIR;
  2718. // dir open paths, only works on dirs!
  2719. lfs_dir_t dir;
  2720. lfs_dir_open(&lfs, &dir, "drip/coffee") => LFS_ERR_NOTDIR;
  2721. lfs_dir_open(&lfs, &dir, "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2722. lfs_dir_open(&lfs, &dir, "turkish/coffee") => LFS_ERR_NOTDIR;
  2723. lfs_dir_open(&lfs, &dir, "tubruk/coffee") => LFS_ERR_NOTDIR;
  2724. lfs_dir_open(&lfs, &dir, "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2725. lfs_dir_open(&lfs, &dir, "thai/coffee") => LFS_ERR_NOTDIR;
  2726. // make some normal paths so we have something to rename
  2727. lfs_mkdir(&lfs, "coffee") => 0;
  2728. if (DIR) {
  2729. lfs_mkdir(&lfs, "coffee/drip") => 0;
  2730. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  2731. lfs_mkdir(&lfs, "coffee/turkish") => 0;
  2732. lfs_mkdir(&lfs, "coffee/tubruk") => 0;
  2733. lfs_mkdir(&lfs, "coffee/vietnamese") => 0;
  2734. lfs_mkdir(&lfs, "coffee/thai") => 0;
  2735. } else {
  2736. lfs_file_t file;
  2737. lfs_file_open(&lfs, &file, "coffee/drip",
  2738. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2739. lfs_file_close(&lfs, &file) => 0;
  2740. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  2741. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2742. lfs_file_close(&lfs, &file) => 0;
  2743. lfs_file_open(&lfs, &file, "coffee/turkish",
  2744. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2745. lfs_file_close(&lfs, &file) => 0;
  2746. lfs_file_open(&lfs, &file, "coffee/tubruk",
  2747. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2748. lfs_file_close(&lfs, &file) => 0;
  2749. lfs_file_open(&lfs, &file, "coffee/vietnamese",
  2750. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2751. lfs_file_close(&lfs, &file) => 0;
  2752. lfs_file_open(&lfs, &file, "coffee/thai",
  2753. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  2754. lfs_file_close(&lfs, &file) => 0;
  2755. }
  2756. // rename paths
  2757. lfs_mkdir(&lfs, "espresso") => 0;
  2758. // bad source
  2759. lfs_rename(&lfs,
  2760. "drip/coffee",
  2761. "espresso/espresso") => LFS_ERR_NOTDIR;
  2762. lfs_rename(&lfs,
  2763. "coldbrew/coffee",
  2764. "espresso/americano") => LFS_ERR_NOTDIR;
  2765. lfs_rename(&lfs,
  2766. "turkish/coffee",
  2767. "espresso/macchiato") => LFS_ERR_NOTDIR;
  2768. lfs_rename(&lfs,
  2769. "tubruk/coffee",
  2770. "espresso/latte") => LFS_ERR_NOTDIR;
  2771. lfs_rename(&lfs,
  2772. "vietnamese/coffee",
  2773. "espresso/cappuccino") => LFS_ERR_NOTDIR;
  2774. lfs_rename(&lfs,
  2775. "thai/coffee",
  2776. "espresso/mocha") => LFS_ERR_NOTDIR;
  2777. // bad destination
  2778. lfs_rename(&lfs,
  2779. "coffee/drip",
  2780. "drip/espresso") => LFS_ERR_NOTDIR;
  2781. lfs_rename(&lfs,
  2782. "coffee/coldbrew",
  2783. "coldbrew/espresso") => LFS_ERR_NOTDIR;
  2784. lfs_rename(&lfs,
  2785. "coffee/turkish",
  2786. "turkish/espresso") => LFS_ERR_NOTDIR;
  2787. lfs_rename(&lfs,
  2788. "coffee/tubruk",
  2789. "tubruk/espresso") => LFS_ERR_NOTDIR;
  2790. lfs_rename(&lfs,
  2791. "coffee/vietnamese",
  2792. "vietnamese/espresso") => LFS_ERR_NOTDIR;
  2793. lfs_rename(&lfs,
  2794. "coffee/thai",
  2795. "thai/espresso") => LFS_ERR_NOTDIR;
  2796. // bad source and bad destination
  2797. lfs_rename(&lfs,
  2798. "drip/coffee",
  2799. "drip/espresso") => LFS_ERR_NOTDIR;
  2800. lfs_rename(&lfs,
  2801. "coldbrew/coffee",
  2802. "coldbrew/espresso") => LFS_ERR_NOTDIR;
  2803. lfs_rename(&lfs,
  2804. "turkish/coffee",
  2805. "turkish/espresso") => LFS_ERR_NOTDIR;
  2806. lfs_rename(&lfs,
  2807. "tubruk/coffee",
  2808. "tubruk/espresso") => LFS_ERR_NOTDIR;
  2809. lfs_rename(&lfs,
  2810. "vietnamese/coffee",
  2811. "vietnamese/espresso") => LFS_ERR_NOTDIR;
  2812. lfs_rename(&lfs,
  2813. "thai/coffee",
  2814. "thai/espresso") => LFS_ERR_NOTDIR;
  2815. // here's a weird one, what happens if our rename is also a noop?
  2816. lfs_rename(&lfs,
  2817. "drip/coffee",
  2818. "drip/coffee") => LFS_ERR_NOTDIR;
  2819. lfs_rename(&lfs,
  2820. "coldbrew/coffee",
  2821. "coldbrew/coffee") => LFS_ERR_NOTDIR;
  2822. lfs_rename(&lfs,
  2823. "turkish/coffee",
  2824. "turkish/coffee") => LFS_ERR_NOTDIR;
  2825. lfs_rename(&lfs,
  2826. "tubruk/coffee",
  2827. "tubruk/coffee") => LFS_ERR_NOTDIR;
  2828. lfs_rename(&lfs,
  2829. "vietnamese/coffee",
  2830. "vietnamese/coffee") => LFS_ERR_NOTDIR;
  2831. lfs_rename(&lfs,
  2832. "thai/coffee",
  2833. "thai/coffee") => LFS_ERR_NOTDIR;
  2834. // remove paths
  2835. lfs_stat(&lfs, "drip/espresso", &info) => LFS_ERR_NOTDIR;
  2836. lfs_stat(&lfs, "coldbrew/espresso", &info) => LFS_ERR_NOTDIR;
  2837. lfs_stat(&lfs, "turkish/espresso", &info) => LFS_ERR_NOTDIR;
  2838. lfs_stat(&lfs, "tubruk/espresso", &info) => LFS_ERR_NOTDIR;
  2839. lfs_stat(&lfs, "vietnamese/espresso", &info) => LFS_ERR_NOTDIR;
  2840. lfs_stat(&lfs, "thai/espresso", &info) => LFS_ERR_NOTDIR;
  2841. // stat paths
  2842. lfs_stat(&lfs, "drip/espresso", &info) => LFS_ERR_NOTDIR;
  2843. lfs_stat(&lfs, "coldbrew/espresso", &info) => LFS_ERR_NOTDIR;
  2844. lfs_stat(&lfs, "turkish/espresso", &info) => LFS_ERR_NOTDIR;
  2845. lfs_stat(&lfs, "tubruk/espresso", &info) => LFS_ERR_NOTDIR;
  2846. lfs_stat(&lfs, "vietnamese/espresso", &info) => LFS_ERR_NOTDIR;
  2847. lfs_stat(&lfs, "thai/espresso", &info) => LFS_ERR_NOTDIR;
  2848. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  2849. assert(strcmp(info.name, "drip") == 0);
  2850. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2851. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  2852. assert(strcmp(info.name, "coldbrew") == 0);
  2853. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2854. lfs_stat(&lfs, "coffee/turkish", &info) => 0;
  2855. assert(strcmp(info.name, "turkish") == 0);
  2856. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2857. lfs_stat(&lfs, "coffee/tubruk", &info) => 0;
  2858. assert(strcmp(info.name, "tubruk") == 0);
  2859. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2860. lfs_stat(&lfs, "coffee/vietnamese", &info) => 0;
  2861. assert(strcmp(info.name, "vietnamese") == 0);
  2862. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2863. lfs_stat(&lfs, "coffee/thai", &info) => 0;
  2864. assert(strcmp(info.name, "thai") == 0);
  2865. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  2866. lfs_unmount(&lfs) => 0;
  2867. '''
  2868. # root operations
  2869. [cases.test_paths_root]
  2870. defines.DIR = [false, true]
  2871. code = '''
  2872. lfs_t lfs;
  2873. lfs_format(&lfs, cfg) => 0;
  2874. lfs_mount(&lfs, cfg) => 0;
  2875. struct lfs_info info;
  2876. // create root, this should error
  2877. if (DIR) {
  2878. lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
  2879. } else {
  2880. lfs_file_t file;
  2881. lfs_file_open(&lfs, &file, "/",
  2882. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2883. }
  2884. // stat root
  2885. lfs_stat(&lfs, "/", &info) => 0;
  2886. assert(strcmp(info.name, "/") == 0);
  2887. assert(info.type == LFS_TYPE_DIR);
  2888. // file open root, only works on files!
  2889. lfs_file_t file;
  2890. lfs_file_open(&lfs, &file, "/",
  2891. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2892. // dir open root, only works on dirs!
  2893. lfs_dir_t dir;
  2894. lfs_dir_open(&lfs, &dir, "/") => 0;
  2895. lfs_dir_close(&lfs, &dir) => 0;
  2896. // rename root, this should error
  2897. lfs_rename(&lfs, "/", "coffee") => LFS_ERR_INVAL;
  2898. lfs_mkdir(&lfs, "coffee") => 0;
  2899. lfs_rename(&lfs, "coffee", "/") => LFS_ERR_INVAL;
  2900. lfs_remove(&lfs, "coffee") => 0;
  2901. lfs_rename(&lfs, "/", "/") => LFS_ERR_INVAL;
  2902. // stat root
  2903. lfs_stat(&lfs, "/", &info) => 0;
  2904. assert(strcmp(info.name, "/") == 0);
  2905. assert(info.type == LFS_TYPE_DIR);
  2906. // remove root, this should error
  2907. lfs_remove(&lfs, "/") => LFS_ERR_INVAL;
  2908. // stat root
  2909. lfs_stat(&lfs, "/", &info) => 0;
  2910. assert(strcmp(info.name, "/") == 0);
  2911. assert(info.type == LFS_TYPE_DIR);
  2912. lfs_unmount(&lfs) => 0;
  2913. '''
  2914. # other root representations
  2915. [cases.test_paths_root_aliases]
  2916. defines.DIR = [false, true]
  2917. code = '''
  2918. lfs_t lfs;
  2919. lfs_format(&lfs, cfg) => 0;
  2920. lfs_mount(&lfs, cfg) => 0;
  2921. struct lfs_info info;
  2922. // create root, this should error
  2923. if (DIR) {
  2924. lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
  2925. lfs_mkdir(&lfs, "") => LFS_ERR_EXIST;
  2926. lfs_mkdir(&lfs, ".") => LFS_ERR_EXIST;
  2927. lfs_mkdir(&lfs, "..") => LFS_ERR_EXIST;
  2928. lfs_mkdir(&lfs, "./") => LFS_ERR_EXIST;
  2929. lfs_mkdir(&lfs, "/.") => LFS_ERR_EXIST;
  2930. lfs_mkdir(&lfs, "//") => LFS_ERR_EXIST;
  2931. } else {
  2932. lfs_file_t file;
  2933. lfs_file_open(&lfs, &file, "/",
  2934. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2935. lfs_file_open(&lfs, &file, "",
  2936. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2937. lfs_file_open(&lfs, &file, ".",
  2938. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2939. lfs_file_open(&lfs, &file, "..",
  2940. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2941. lfs_file_open(&lfs, &file, "./",
  2942. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2943. lfs_file_open(&lfs, &file, "/.",
  2944. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2945. lfs_file_open(&lfs, &file, "//",
  2946. LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR;
  2947. }
  2948. // stat root
  2949. lfs_stat(&lfs, "/", &info) => 0;
  2950. assert(strcmp(info.name, "/") == 0);
  2951. assert(info.type == LFS_TYPE_DIR);
  2952. lfs_stat(&lfs, "", &info) => 0;
  2953. assert(strcmp(info.name, "/") == 0);
  2954. assert(info.type == LFS_TYPE_DIR);
  2955. lfs_stat(&lfs, ".", &info) => 0;
  2956. assert(strcmp(info.name, "/") == 0);
  2957. assert(info.type == LFS_TYPE_DIR);
  2958. lfs_stat(&lfs, "..", &info) => 0;
  2959. assert(strcmp(info.name, "/") == 0);
  2960. assert(info.type == LFS_TYPE_DIR);
  2961. lfs_stat(&lfs, "./", &info) => 0;
  2962. assert(strcmp(info.name, "/") == 0);
  2963. assert(info.type == LFS_TYPE_DIR);
  2964. lfs_stat(&lfs, "/.", &info) => 0;
  2965. assert(strcmp(info.name, "/") == 0);
  2966. assert(info.type == LFS_TYPE_DIR);
  2967. lfs_stat(&lfs, "//", &info) => 0;
  2968. assert(strcmp(info.name, "/") == 0);
  2969. assert(info.type == LFS_TYPE_DIR);
  2970. // file open root, only works on files!
  2971. lfs_file_t file;
  2972. lfs_file_open(&lfs, &file, "/",
  2973. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2974. lfs_file_open(&lfs, &file, "",
  2975. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2976. lfs_file_open(&lfs, &file, ".",
  2977. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2978. lfs_file_open(&lfs, &file, "..",
  2979. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2980. lfs_file_open(&lfs, &file, "./",
  2981. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2982. lfs_file_open(&lfs, &file, "/.",
  2983. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2984. lfs_file_open(&lfs, &file, "//",
  2985. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  2986. // dir open root, only works on dirs!
  2987. lfs_dir_t dir;
  2988. lfs_dir_open(&lfs, &dir, "/") => 0;
  2989. lfs_dir_close(&lfs, &dir) => 0;
  2990. lfs_dir_open(&lfs, &dir, "") => 0;
  2991. lfs_dir_close(&lfs, &dir) => 0;
  2992. lfs_dir_open(&lfs, &dir, ".") => 0;
  2993. lfs_dir_close(&lfs, &dir) => 0;
  2994. lfs_dir_open(&lfs, &dir, "..") => 0;
  2995. lfs_dir_close(&lfs, &dir) => 0;
  2996. lfs_dir_open(&lfs, &dir, "./") => 0;
  2997. lfs_dir_close(&lfs, &dir) => 0;
  2998. lfs_dir_open(&lfs, &dir, "/.") => 0;
  2999. lfs_dir_close(&lfs, &dir) => 0;
  3000. lfs_dir_open(&lfs, &dir, "//") => 0;
  3001. lfs_dir_close(&lfs, &dir) => 0;
  3002. // rename root, this should error
  3003. lfs_rename(&lfs, "/", "coffee") => LFS_ERR_INVAL;
  3004. lfs_rename(&lfs, "", "coffee") => LFS_ERR_INVAL;
  3005. lfs_rename(&lfs, ".", "coffee") => LFS_ERR_INVAL;
  3006. lfs_rename(&lfs, "..", "coffee") => LFS_ERR_INVAL;
  3007. lfs_rename(&lfs, "./", "coffee") => LFS_ERR_INVAL;
  3008. lfs_rename(&lfs, "/.", "coffee") => LFS_ERR_INVAL;
  3009. lfs_rename(&lfs, "//", "coffee") => LFS_ERR_INVAL;
  3010. lfs_mkdir(&lfs, "coffee") => 0;
  3011. lfs_rename(&lfs, "coffee", "/") => LFS_ERR_INVAL;
  3012. lfs_rename(&lfs, "coffee", "") => LFS_ERR_INVAL;
  3013. lfs_rename(&lfs, "coffee", ".") => LFS_ERR_INVAL;
  3014. lfs_rename(&lfs, "coffee", "..") => LFS_ERR_INVAL;
  3015. lfs_rename(&lfs, "coffee", "./") => LFS_ERR_INVAL;
  3016. lfs_rename(&lfs, "coffee", "/.") => LFS_ERR_INVAL;
  3017. lfs_rename(&lfs, "coffee", "//") => LFS_ERR_INVAL;
  3018. lfs_remove(&lfs, "coffee") => 0;
  3019. lfs_rename(&lfs, "/", "/") => LFS_ERR_INVAL;
  3020. lfs_rename(&lfs, "", "") => LFS_ERR_INVAL;
  3021. lfs_rename(&lfs, ".", ".") => LFS_ERR_INVAL;
  3022. lfs_rename(&lfs, "..", "..") => LFS_ERR_INVAL;
  3023. lfs_rename(&lfs, "./", "./") => LFS_ERR_INVAL;
  3024. lfs_rename(&lfs, "/.", "/.") => LFS_ERR_INVAL;
  3025. lfs_rename(&lfs, "//", "//") => LFS_ERR_INVAL;
  3026. // stat root
  3027. lfs_stat(&lfs, "/", &info) => 0;
  3028. assert(strcmp(info.name, "/") == 0);
  3029. assert(info.type == LFS_TYPE_DIR);
  3030. lfs_stat(&lfs, "", &info) => 0;
  3031. assert(strcmp(info.name, "/") == 0);
  3032. assert(info.type == LFS_TYPE_DIR);
  3033. lfs_stat(&lfs, ".", &info) => 0;
  3034. assert(strcmp(info.name, "/") == 0);
  3035. assert(info.type == LFS_TYPE_DIR);
  3036. lfs_stat(&lfs, "..", &info) => 0;
  3037. assert(strcmp(info.name, "/") == 0);
  3038. assert(info.type == LFS_TYPE_DIR);
  3039. lfs_stat(&lfs, "./", &info) => 0;
  3040. assert(strcmp(info.name, "/") == 0);
  3041. assert(info.type == LFS_TYPE_DIR);
  3042. lfs_stat(&lfs, "/.", &info) => 0;
  3043. assert(strcmp(info.name, "/") == 0);
  3044. assert(info.type == LFS_TYPE_DIR);
  3045. lfs_stat(&lfs, "//", &info) => 0;
  3046. assert(strcmp(info.name, "/") == 0);
  3047. assert(info.type == LFS_TYPE_DIR);
  3048. // remove root, this should error
  3049. lfs_remove(&lfs, "/") => LFS_ERR_INVAL;
  3050. lfs_remove(&lfs, "") => LFS_ERR_INVAL;
  3051. lfs_remove(&lfs, ".") => LFS_ERR_INVAL;
  3052. lfs_remove(&lfs, "..") => LFS_ERR_INVAL;
  3053. lfs_remove(&lfs, "./") => LFS_ERR_INVAL;
  3054. lfs_remove(&lfs, "/.") => LFS_ERR_INVAL;
  3055. lfs_remove(&lfs, "//") => LFS_ERR_INVAL;
  3056. // stat root
  3057. lfs_stat(&lfs, "/", &info) => 0;
  3058. assert(strcmp(info.name, "/") == 0);
  3059. assert(info.type == LFS_TYPE_DIR);
  3060. lfs_stat(&lfs, "", &info) => 0;
  3061. assert(strcmp(info.name, "/") == 0);
  3062. assert(info.type == LFS_TYPE_DIR);
  3063. lfs_stat(&lfs, ".", &info) => 0;
  3064. assert(strcmp(info.name, "/") == 0);
  3065. assert(info.type == LFS_TYPE_DIR);
  3066. lfs_stat(&lfs, "..", &info) => 0;
  3067. assert(strcmp(info.name, "/") == 0);
  3068. assert(info.type == LFS_TYPE_DIR);
  3069. lfs_stat(&lfs, "./", &info) => 0;
  3070. assert(strcmp(info.name, "/") == 0);
  3071. assert(info.type == LFS_TYPE_DIR);
  3072. lfs_stat(&lfs, "/.", &info) => 0;
  3073. assert(strcmp(info.name, "/") == 0);
  3074. assert(info.type == LFS_TYPE_DIR);
  3075. lfs_stat(&lfs, "//", &info) => 0;
  3076. assert(strcmp(info.name, "/") == 0);
  3077. assert(info.type == LFS_TYPE_DIR);
  3078. lfs_unmount(&lfs) => 0;
  3079. '''
  3080. # superblock magic shouldn't appear as a file
  3081. [cases.test_paths_magic_noent]
  3082. code = '''
  3083. lfs_t lfs;
  3084. lfs_format(&lfs, cfg) => 0;
  3085. lfs_mount(&lfs, cfg) => 0;
  3086. // stat littlefs, which shouldn't exist
  3087. struct lfs_info info;
  3088. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3089. // dir open littlefs, which shouldn't exist
  3090. lfs_dir_t dir;
  3091. lfs_dir_open(&lfs, &dir, "littlefs") => LFS_ERR_NOENT;
  3092. // rename littlefs, which shouldn't exist
  3093. lfs_rename(&lfs, "littlefs", "coffee") => LFS_ERR_NOENT;
  3094. // remove littlefs, which shouldn't exist
  3095. lfs_remove(&lfs, "littlefs") => LFS_ERR_NOENT;
  3096. // stat littlefs, which shouldn't exist
  3097. lfs_stat(&lfs, "coffee", &info) => LFS_ERR_NOENT;
  3098. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3099. lfs_unmount(&lfs) => 0;
  3100. '''
  3101. # superblock magic shouldn't conflict with files, that would be silly
  3102. [cases.test_paths_magic_conflict]
  3103. defines.DIR = [false, true]
  3104. code = '''
  3105. lfs_t lfs;
  3106. lfs_format(&lfs, cfg) => 0;
  3107. lfs_mount(&lfs, cfg) => 0;
  3108. // create littlefs
  3109. if (DIR) {
  3110. lfs_mkdir(&lfs, "littlefs") => 0;
  3111. } else {
  3112. lfs_file_t file;
  3113. lfs_file_open(&lfs, &file, "littlefs",
  3114. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3115. lfs_file_close(&lfs, &file) => 0;
  3116. }
  3117. // stat littlefs
  3118. struct lfs_info info;
  3119. lfs_stat(&lfs, "littlefs", &info) => 0;
  3120. assert(strcmp(info.name, "littlefs") == 0);
  3121. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3122. // file open littlefs, only works on files!
  3123. if (DIR) {
  3124. lfs_file_t file;
  3125. lfs_file_open(&lfs, &file, "littlefs",
  3126. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3127. } else {
  3128. lfs_file_t file;
  3129. lfs_file_open(&lfs, &file, "littlefs",
  3130. LFS_O_RDONLY) => 0;
  3131. lfs_file_close(&lfs, &file) => 0;
  3132. }
  3133. // dir open littlefs, only works on dirs!
  3134. if (DIR) {
  3135. lfs_dir_t dir;
  3136. lfs_dir_open(&lfs, &dir, "littlefs") => 0;
  3137. lfs_dir_close(&lfs, &dir) => 0;
  3138. } else {
  3139. lfs_dir_t dir;
  3140. lfs_dir_open(&lfs, &dir, "littlefs") => LFS_ERR_NOTDIR;
  3141. }
  3142. // rename littlefs
  3143. lfs_rename(&lfs, "littlefs", "coffee") => 0;
  3144. lfs_rename(&lfs, "coffee", "littlefs") => 0;
  3145. // stat littlefs
  3146. lfs_stat(&lfs, "littlefs", &info) => 0;
  3147. assert(strcmp(info.name, "littlefs") == 0);
  3148. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3149. lfs_stat(&lfs, "coffee", &info) => LFS_ERR_NOENT;
  3150. // remove littlefs
  3151. lfs_remove(&lfs, "littlefs") => 0;
  3152. // stat littlefs
  3153. lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT;
  3154. lfs_unmount(&lfs) => 0;
  3155. '''
  3156. # test name too long
  3157. [cases.test_paths_nametoolong]
  3158. defines.DIR = [false, true]
  3159. code = '''
  3160. lfs_t lfs;
  3161. lfs_format(&lfs, cfg) => 0;
  3162. lfs_mount(&lfs, cfg) => 0;
  3163. char a_name[512];
  3164. memset(a_name, 'a', LFS_NAME_MAX+1);
  3165. a_name[LFS_NAME_MAX+1] = '\0';
  3166. // create names that are too long, should error
  3167. char path[1024];
  3168. lfs_mkdir(&lfs, "coffee") => 0;
  3169. if (DIR) {
  3170. sprintf(path, "coffee/%s", a_name);
  3171. lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG;
  3172. } else {
  3173. lfs_file_t file;
  3174. sprintf(path, "coffee/%s", a_name);
  3175. lfs_file_open(&lfs, &file, path,
  3176. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NAMETOOLONG;
  3177. }
  3178. // stat paths
  3179. struct lfs_info info;
  3180. sprintf(path, "coffee/%s", a_name);
  3181. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3182. // file open paths, only works on files!
  3183. lfs_file_t file;
  3184. sprintf(path, "coffee/%s", a_name);
  3185. lfs_file_open(&lfs, &file, path,
  3186. LFS_O_RDONLY) => LFS_ERR_NOENT;
  3187. // dir open paths, only works on dirs!
  3188. lfs_dir_t dir;
  3189. sprintf(path, "coffee/%s", a_name);
  3190. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOENT;
  3191. // rename paths
  3192. lfs_mkdir(&lfs, "espresso") => 0;
  3193. sprintf(path, "coffee/%s", a_name);
  3194. lfs_rename(&lfs, path, "espresso/espresso") => LFS_ERR_NOENT;
  3195. // renaming with too long a destination is tricky!
  3196. if (DIR) {
  3197. lfs_mkdir(&lfs, "coffee/drip") => 0;
  3198. } else {
  3199. lfs_file_t file;
  3200. lfs_file_open(&lfs, &file, "coffee/drip",
  3201. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3202. lfs_file_close(&lfs, &file) => 0;
  3203. }
  3204. sprintf(path, "espresso/%s", a_name);
  3205. lfs_rename(&lfs, "coffee/drip", path) => LFS_ERR_NAMETOOLONG;
  3206. // stat paths
  3207. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  3208. assert(strcmp(info.name, "drip") == 0);
  3209. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3210. sprintf(path, "espresso/%s", a_name);
  3211. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3212. // remove paths
  3213. sprintf(path, "espresso/%s", a_name);
  3214. lfs_remove(&lfs, path) => LFS_ERR_NOENT;
  3215. // stat paths
  3216. lfs_stat(&lfs, "coffee/drip", &info) => 0;
  3217. assert(strcmp(info.name, "drip") == 0);
  3218. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3219. sprintf(path, "espresso/%s", a_name);
  3220. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3221. lfs_unmount(&lfs) => 0;
  3222. '''
  3223. # test name really long but not too long
  3224. [cases.test_paths_namejustlongenough]
  3225. defines.DIR = [false, true]
  3226. code = '''
  3227. lfs_t lfs;
  3228. lfs_format(&lfs, cfg) => 0;
  3229. lfs_mount(&lfs, cfg) => 0;
  3230. char a_name[512];
  3231. memset(a_name, 'a', LFS_NAME_MAX);
  3232. a_name[LFS_NAME_MAX] = '\0';
  3233. char b_name[512];
  3234. memset(b_name, 'b', LFS_NAME_MAX);
  3235. b_name[LFS_NAME_MAX] = '\0';
  3236. char c_name[512];
  3237. memset(c_name, 'c', LFS_NAME_MAX);
  3238. c_name[LFS_NAME_MAX] = '\0';
  3239. char d_name[512];
  3240. memset(d_name, 'd', LFS_NAME_MAX);
  3241. d_name[LFS_NAME_MAX] = '\0';
  3242. char e_name[512];
  3243. memset(e_name, 'e', LFS_NAME_MAX);
  3244. e_name[LFS_NAME_MAX] = '\0';
  3245. char f_name[512];
  3246. memset(f_name, 'f', LFS_NAME_MAX);
  3247. f_name[LFS_NAME_MAX] = '\0';
  3248. char g_name[512];
  3249. memset(g_name, 'g', LFS_NAME_MAX);
  3250. g_name[LFS_NAME_MAX] = '\0';
  3251. char h_name[512];
  3252. memset(h_name, 'h', LFS_NAME_MAX);
  3253. h_name[LFS_NAME_MAX] = '\0';
  3254. char i_name[512];
  3255. memset(i_name, 'i', LFS_NAME_MAX);
  3256. i_name[LFS_NAME_MAX] = '\0';
  3257. char j_name[512];
  3258. memset(j_name, 'j', LFS_NAME_MAX);
  3259. j_name[LFS_NAME_MAX] = '\0';
  3260. char k_name[512];
  3261. memset(k_name, 'k', LFS_NAME_MAX);
  3262. k_name[LFS_NAME_MAX] = '\0';
  3263. char l_name[512];
  3264. memset(l_name, 'l', LFS_NAME_MAX);
  3265. l_name[LFS_NAME_MAX] = '\0';
  3266. // create names that aren't too long
  3267. lfs_mkdir(&lfs, c_name) => 0;
  3268. char path[1024];
  3269. if (DIR) {
  3270. sprintf(path, "%s/%s", c_name, a_name);
  3271. lfs_mkdir(&lfs, path) => 0;
  3272. sprintf(path, "%s/%s", c_name, b_name);
  3273. lfs_mkdir(&lfs, path) => 0;
  3274. sprintf(path, "%s/%s", c_name, c_name);
  3275. lfs_mkdir(&lfs, path) => 0;
  3276. sprintf(path, "%s/%s", c_name, d_name);
  3277. lfs_mkdir(&lfs, path) => 0;
  3278. sprintf(path, "%s/%s", c_name, e_name);
  3279. lfs_mkdir(&lfs, path) => 0;
  3280. sprintf(path, "%s/%s", c_name, f_name);
  3281. lfs_mkdir(&lfs, path) => 0;
  3282. } else {
  3283. lfs_file_t file;
  3284. sprintf(path, "%s/%s", c_name, a_name);
  3285. lfs_file_open(&lfs, &file, path,
  3286. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3287. lfs_file_close(&lfs, &file) => 0;
  3288. sprintf(path, "%s/%s", c_name, b_name);
  3289. lfs_file_open(&lfs, &file, path,
  3290. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3291. lfs_file_close(&lfs, &file) => 0;
  3292. sprintf(path, "%s/%s", c_name, c_name);
  3293. lfs_file_open(&lfs, &file, path,
  3294. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3295. lfs_file_close(&lfs, &file) => 0;
  3296. sprintf(path, "%s/%s", c_name, d_name);
  3297. lfs_file_open(&lfs, &file, path,
  3298. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3299. lfs_file_close(&lfs, &file) => 0;
  3300. sprintf(path, "%s/%s", c_name, e_name);
  3301. lfs_file_open(&lfs, &file, path,
  3302. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3303. lfs_file_close(&lfs, &file) => 0;
  3304. sprintf(path, "%s/%s", c_name, f_name);
  3305. lfs_file_open(&lfs, &file, path,
  3306. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3307. lfs_file_close(&lfs, &file) => 0;
  3308. }
  3309. // stat paths
  3310. struct lfs_info info;
  3311. sprintf(path, "%s/%s", c_name, a_name);
  3312. lfs_stat(&lfs, path, &info) => 0;
  3313. assert(strcmp(info.name, a_name) == 0);
  3314. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3315. sprintf(path, "%s/%s", c_name, b_name);
  3316. lfs_stat(&lfs, path, &info) => 0;
  3317. assert(strcmp(info.name, b_name) == 0);
  3318. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3319. sprintf(path, "%s/%s", c_name, c_name);
  3320. lfs_stat(&lfs, path, &info) => 0;
  3321. assert(strcmp(info.name, c_name) == 0);
  3322. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3323. sprintf(path, "%s/%s", c_name, d_name);
  3324. lfs_stat(&lfs, path, &info) => 0;
  3325. assert(strcmp(info.name, d_name) == 0);
  3326. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3327. sprintf(path, "%s/%s", c_name, e_name);
  3328. lfs_stat(&lfs, path, &info) => 0;
  3329. assert(strcmp(info.name, e_name) == 0);
  3330. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3331. sprintf(path, "%s/%s", c_name, f_name);
  3332. lfs_stat(&lfs, path, &info) => 0;
  3333. assert(strcmp(info.name, f_name) == 0);
  3334. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3335. // file open paths, only works on files!
  3336. if (DIR) {
  3337. lfs_file_t file;
  3338. sprintf(path, "%s/%s", c_name, a_name);
  3339. lfs_file_open(&lfs, &file, path,
  3340. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3341. sprintf(path, "%s/%s", c_name, b_name);
  3342. lfs_file_open(&lfs, &file, path,
  3343. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3344. sprintf(path, "%s/%s", c_name, c_name);
  3345. lfs_file_open(&lfs, &file, path,
  3346. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3347. sprintf(path, "%s/%s", c_name, d_name);
  3348. lfs_file_open(&lfs, &file, path,
  3349. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3350. sprintf(path, "%s/%s", c_name, e_name);
  3351. lfs_file_open(&lfs, &file, path,
  3352. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3353. sprintf(path, "%s/%s", c_name, f_name);
  3354. lfs_file_open(&lfs, &file, path,
  3355. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3356. } else {
  3357. lfs_file_t file;
  3358. sprintf(path, "%s/%s", c_name, a_name);
  3359. lfs_file_open(&lfs, &file, path,
  3360. LFS_O_RDONLY) => 0;
  3361. lfs_file_close(&lfs, &file) => 0;
  3362. sprintf(path, "%s/%s", c_name, b_name);
  3363. lfs_file_open(&lfs, &file, path,
  3364. LFS_O_RDONLY) => 0;
  3365. lfs_file_close(&lfs, &file) => 0;
  3366. sprintf(path, "%s/%s", c_name, c_name);
  3367. lfs_file_open(&lfs, &file, path,
  3368. LFS_O_RDONLY) => 0;
  3369. lfs_file_close(&lfs, &file) => 0;
  3370. sprintf(path, "%s/%s", c_name, d_name);
  3371. lfs_file_open(&lfs, &file, path,
  3372. LFS_O_RDONLY) => 0;
  3373. lfs_file_close(&lfs, &file) => 0;
  3374. sprintf(path, "%s/%s", c_name, e_name);
  3375. lfs_file_open(&lfs, &file, path,
  3376. LFS_O_RDONLY) => 0;
  3377. lfs_file_close(&lfs, &file) => 0;
  3378. sprintf(path, "%s/%s", c_name, f_name);
  3379. lfs_file_open(&lfs, &file, path,
  3380. LFS_O_RDONLY) => 0;
  3381. lfs_file_close(&lfs, &file) => 0;
  3382. }
  3383. // dir open paths, only works on dirs!
  3384. if (DIR) {
  3385. lfs_dir_t dir;
  3386. sprintf(path, "%s/%s", c_name, a_name);
  3387. lfs_dir_open(&lfs, &dir, path) => 0;
  3388. lfs_dir_close(&lfs, &dir) => 0;
  3389. sprintf(path, "%s/%s", c_name, b_name);
  3390. lfs_dir_open(&lfs, &dir, path) => 0;
  3391. lfs_dir_close(&lfs, &dir) => 0;
  3392. sprintf(path, "%s/%s", c_name, c_name);
  3393. lfs_dir_open(&lfs, &dir, path) => 0;
  3394. lfs_dir_close(&lfs, &dir) => 0;
  3395. sprintf(path, "%s/%s", c_name, d_name);
  3396. lfs_dir_open(&lfs, &dir, path) => 0;
  3397. lfs_dir_close(&lfs, &dir) => 0;
  3398. sprintf(path, "%s/%s", c_name, e_name);
  3399. lfs_dir_open(&lfs, &dir, path) => 0;
  3400. lfs_dir_close(&lfs, &dir) => 0;
  3401. sprintf(path, "%s/%s", c_name, f_name);
  3402. lfs_dir_open(&lfs, &dir, path) => 0;
  3403. lfs_dir_close(&lfs, &dir) => 0;
  3404. } else {
  3405. lfs_dir_t dir;
  3406. sprintf(path, "%s/%s", c_name, a_name);
  3407. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3408. sprintf(path, "%s/%s", c_name, b_name);
  3409. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3410. sprintf(path, "%s/%s", c_name, c_name);
  3411. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3412. sprintf(path, "%s/%s", c_name, d_name);
  3413. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3414. sprintf(path, "%s/%s", c_name, e_name);
  3415. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3416. sprintf(path, "%s/%s", c_name, f_name);
  3417. lfs_dir_open(&lfs, &dir, path) => LFS_ERR_NOTDIR;
  3418. }
  3419. // rename paths
  3420. lfs_mkdir(&lfs, e_name) => 0;
  3421. char path_[1024];
  3422. sprintf(path, "%s/%s", c_name, a_name);
  3423. sprintf(path_, "%s/%s", e_name, g_name);
  3424. lfs_rename(&lfs, path, path_) => 0;
  3425. sprintf(path, "%s/%s", c_name, b_name);
  3426. sprintf(path_, "%s/%s", e_name, h_name);
  3427. lfs_rename(&lfs, path, path_) => 0;
  3428. sprintf(path, "%s/%s", c_name, c_name);
  3429. sprintf(path_, "%s/%s", e_name, i_name);
  3430. lfs_rename(&lfs, path, path_) => 0;
  3431. sprintf(path, "%s/%s", c_name, d_name);
  3432. sprintf(path_, "%s/%s", e_name, j_name);
  3433. lfs_rename(&lfs, path, path_) => 0;
  3434. sprintf(path, "%s/%s", c_name, e_name);
  3435. sprintf(path_, "%s/%s", e_name, k_name);
  3436. lfs_rename(&lfs, path, path_) => 0;
  3437. sprintf(path, "%s/%s", c_name, f_name);
  3438. sprintf(path_, "%s/%s", e_name, l_name);
  3439. lfs_rename(&lfs, path, path_) => 0;
  3440. // stat paths
  3441. sprintf(path, "%s/%s", e_name, g_name);
  3442. lfs_stat(&lfs, path, &info) => 0;
  3443. assert(strcmp(info.name, g_name) == 0);
  3444. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3445. sprintf(path, "%s/%s", e_name, h_name);
  3446. lfs_stat(&lfs, path, &info) => 0;
  3447. assert(strcmp(info.name, h_name) == 0);
  3448. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3449. sprintf(path, "%s/%s", e_name, i_name);
  3450. lfs_stat(&lfs, path, &info) => 0;
  3451. assert(strcmp(info.name, i_name) == 0);
  3452. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3453. sprintf(path, "%s/%s", e_name, j_name);
  3454. lfs_stat(&lfs, path, &info) => 0;
  3455. assert(strcmp(info.name, j_name) == 0);
  3456. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3457. sprintf(path, "%s/%s", e_name, k_name);
  3458. lfs_stat(&lfs, path, &info) => 0;
  3459. assert(strcmp(info.name, k_name) == 0);
  3460. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3461. sprintf(path, "%s/%s", e_name, l_name);
  3462. lfs_stat(&lfs, path, &info) => 0;
  3463. assert(strcmp(info.name, l_name) == 0);
  3464. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3465. sprintf(path, "%s/%s", c_name, a_name);
  3466. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3467. sprintf(path, "%s/%s", c_name, b_name);
  3468. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3469. sprintf(path, "%s/%s", c_name, c_name);
  3470. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3471. sprintf(path, "%s/%s", c_name, d_name);
  3472. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3473. sprintf(path, "%s/%s", c_name, e_name);
  3474. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3475. sprintf(path, "%s/%s", c_name, f_name);
  3476. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3477. // remove paths
  3478. sprintf(path, "%s/%s", e_name, g_name);
  3479. lfs_remove(&lfs, path) => 0;
  3480. sprintf(path, "%s/%s", e_name, h_name);
  3481. lfs_remove(&lfs, path) => 0;
  3482. sprintf(path, "%s/%s", e_name, i_name);
  3483. lfs_remove(&lfs, path) => 0;
  3484. sprintf(path, "%s/%s", e_name, j_name);
  3485. lfs_remove(&lfs, path) => 0;
  3486. sprintf(path, "%s/%s", e_name, k_name);
  3487. lfs_remove(&lfs, path) => 0;
  3488. sprintf(path, "%s/%s", e_name, l_name);
  3489. lfs_remove(&lfs, path) => 0;
  3490. // stat paths
  3491. sprintf(path, "%s/%s", e_name, g_name);
  3492. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3493. sprintf(path, "%s/%s", e_name, h_name);
  3494. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3495. sprintf(path, "%s/%s", e_name, i_name);
  3496. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3497. sprintf(path, "%s/%s", e_name, j_name);
  3498. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3499. sprintf(path, "%s/%s", e_name, k_name);
  3500. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3501. sprintf(path, "%s/%s", e_name, l_name);
  3502. lfs_stat(&lfs, path, &info) => LFS_ERR_NOENT;
  3503. lfs_unmount(&lfs) => 0;
  3504. '''
  3505. # a quick utf8 test, though utf8 is easy to support
  3506. [cases.test_paths_utf8]
  3507. defines.DIR = [false, true]
  3508. code = '''
  3509. lfs_t lfs;
  3510. lfs_format(&lfs, cfg) => 0;
  3511. lfs_mount(&lfs, cfg) => 0;
  3512. // create paths
  3513. lfs_mkdir(&lfs, "coffee") => 0;
  3514. if (DIR) {
  3515. lfs_mkdir(&lfs, "coffee/dripcoffee") => 0;
  3516. lfs_mkdir(&lfs, "coffee/coldbrew") => 0;
  3517. lfs_mkdir(&lfs, "coffee/türkkahvesi") => 0;
  3518. lfs_mkdir(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => 0;
  3519. lfs_mkdir(&lfs, "coffee/càphêđá") => 0;
  3520. lfs_mkdir(&lfs, "coffee/โอเลี้ยง") => 0;
  3521. } else {
  3522. lfs_file_t file;
  3523. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3524. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3525. lfs_file_close(&lfs, &file) => 0;
  3526. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3527. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3528. lfs_file_close(&lfs, &file) => 0;
  3529. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3530. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3531. lfs_file_close(&lfs, &file) => 0;
  3532. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3533. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3534. lfs_file_close(&lfs, &file) => 0;
  3535. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3536. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3537. lfs_file_close(&lfs, &file) => 0;
  3538. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3539. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3540. lfs_file_close(&lfs, &file) => 0;
  3541. }
  3542. // stat paths
  3543. struct lfs_info info;
  3544. lfs_stat(&lfs, "coffee/dripcoffee", &info) => 0;
  3545. assert(strcmp(info.name, "dripcoffee") == 0);
  3546. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3547. lfs_stat(&lfs, "coffee/coldbrew", &info) => 0;
  3548. assert(strcmp(info.name, "coldbrew") == 0);
  3549. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3550. lfs_stat(&lfs, "coffee/türkkahvesi", &info) => 0;
  3551. assert(strcmp(info.name, "türkkahvesi") == 0);
  3552. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3553. lfs_stat(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀", &info) => 0;
  3554. assert(strcmp(info.name, "ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") == 0);
  3555. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3556. lfs_stat(&lfs, "coffee/càphêđá", &info) => 0;
  3557. assert(strcmp(info.name, "càphêđá") == 0);
  3558. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3559. lfs_stat(&lfs, "coffee/โอเลี้ยง", &info) => 0;
  3560. assert(strcmp(info.name, "โอเลี้ยง") == 0);
  3561. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3562. // file open paths, only works on files!
  3563. if (DIR) {
  3564. lfs_file_t file;
  3565. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3566. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3567. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3568. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3569. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3570. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3571. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3572. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3573. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3574. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3575. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3576. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3577. } else {
  3578. lfs_file_t file;
  3579. lfs_file_open(&lfs, &file, "coffee/dripcoffee",
  3580. LFS_O_RDONLY) => 0;
  3581. lfs_file_close(&lfs, &file) => 0;
  3582. lfs_file_open(&lfs, &file, "coffee/coldbrew",
  3583. LFS_O_RDONLY) => 0;
  3584. lfs_file_close(&lfs, &file) => 0;
  3585. lfs_file_open(&lfs, &file, "coffee/türkkahvesi",
  3586. LFS_O_RDONLY) => 0;
  3587. lfs_file_close(&lfs, &file) => 0;
  3588. lfs_file_open(&lfs, &file, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3589. LFS_O_RDONLY) => 0;
  3590. lfs_file_close(&lfs, &file) => 0;
  3591. lfs_file_open(&lfs, &file, "coffee/càphêđá",
  3592. LFS_O_RDONLY) => 0;
  3593. lfs_file_close(&lfs, &file) => 0;
  3594. lfs_file_open(&lfs, &file, "coffee/โอเลี้ยง",
  3595. LFS_O_RDONLY) => 0;
  3596. lfs_file_close(&lfs, &file) => 0;
  3597. }
  3598. // dir open paths, only works on dirs!
  3599. if (DIR) {
  3600. lfs_dir_t dir;
  3601. lfs_dir_open(&lfs, &dir, "coffee/dripcoffee") => 0;
  3602. lfs_dir_close(&lfs, &dir) => 0;
  3603. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => 0;
  3604. lfs_dir_close(&lfs, &dir) => 0;
  3605. lfs_dir_open(&lfs, &dir, "coffee/türkkahvesi") => 0;
  3606. lfs_dir_close(&lfs, &dir) => 0;
  3607. lfs_dir_open(&lfs, &dir, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => 0;
  3608. lfs_dir_close(&lfs, &dir) => 0;
  3609. lfs_dir_open(&lfs, &dir, "coffee/càphêđá") => 0;
  3610. lfs_dir_close(&lfs, &dir) => 0;
  3611. lfs_dir_open(&lfs, &dir, "coffee/โอเลี้ยง") => 0;
  3612. lfs_dir_close(&lfs, &dir) => 0;
  3613. } else {
  3614. lfs_dir_t dir;
  3615. lfs_dir_open(&lfs, &dir, "coffee/dripcoffee") => LFS_ERR_NOTDIR;
  3616. lfs_dir_open(&lfs, &dir, "coffee/coldbrew") => LFS_ERR_NOTDIR;
  3617. lfs_dir_open(&lfs, &dir, "coffee/türkkahvesi") => LFS_ERR_NOTDIR;
  3618. lfs_dir_open(&lfs, &dir, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀") => LFS_ERR_NOTDIR;
  3619. lfs_dir_open(&lfs, &dir, "coffee/càphêđá") => LFS_ERR_NOTDIR;
  3620. lfs_dir_open(&lfs, &dir, "coffee/โอเลี้ยง") => LFS_ERR_NOTDIR;
  3621. }
  3622. // rename paths
  3623. lfs_mkdir(&lfs, "caffè") => 0;
  3624. lfs_rename(&lfs,
  3625. "coffee/dripcoffee",
  3626. "caffè/espresso") => 0;
  3627. lfs_rename(&lfs,
  3628. "coffee/coldbrew",
  3629. "caffè/americano") => 0;
  3630. lfs_rename(&lfs,
  3631. "coffee/türkkahvesi",
  3632. "caffè/macchiato") => 0;
  3633. lfs_rename(&lfs,
  3634. "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀",
  3635. "caffè/latte") => 0;
  3636. lfs_rename(&lfs,
  3637. "coffee/càphêđá",
  3638. "caffè/cappuccino") => 0;
  3639. lfs_rename(&lfs,
  3640. "coffee/โอเลี้ยง",
  3641. "caffè/mocha") => 0;
  3642. // stat paths
  3643. lfs_stat(&lfs, "caffè/espresso", &info) => 0;
  3644. assert(strcmp(info.name, "espresso") == 0);
  3645. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3646. lfs_stat(&lfs, "caffè/americano", &info) => 0;
  3647. assert(strcmp(info.name, "americano") == 0);
  3648. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3649. lfs_stat(&lfs, "caffè/macchiato", &info) => 0;
  3650. assert(strcmp(info.name, "macchiato") == 0);
  3651. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3652. lfs_stat(&lfs, "caffè/latte", &info) => 0;
  3653. assert(strcmp(info.name, "latte") == 0);
  3654. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3655. lfs_stat(&lfs, "caffè/cappuccino", &info) => 0;
  3656. assert(strcmp(info.name, "cappuccino") == 0);
  3657. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3658. lfs_stat(&lfs, "caffè/mocha", &info) => 0;
  3659. assert(strcmp(info.name, "mocha") == 0);
  3660. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3661. lfs_stat(&lfs, "coffee/dripcoffee", &info) => LFS_ERR_NOENT;
  3662. lfs_stat(&lfs, "coffee/coldbrew", &info) => LFS_ERR_NOENT;
  3663. lfs_stat(&lfs, "coffee/türkkahvesi", &info) => LFS_ERR_NOENT;
  3664. lfs_stat(&lfs, "coffee/ꦏꦺꦴꦥꦶꦠꦸꦧꦿꦸꦏ꧀", &info) => LFS_ERR_NOENT;
  3665. lfs_stat(&lfs, "coffee/càphêđá", &info) => LFS_ERR_NOENT;
  3666. lfs_stat(&lfs, "coffee/โอเลี้ยง", &info) => LFS_ERR_NOENT;
  3667. // remove paths
  3668. lfs_remove(&lfs, "caffè/espresso") => 0;
  3669. lfs_remove(&lfs, "caffè/americano") => 0;
  3670. lfs_remove(&lfs, "caffè/macchiato") => 0;
  3671. lfs_remove(&lfs, "caffè/latte") => 0;
  3672. lfs_remove(&lfs, "caffè/cappuccino") => 0;
  3673. lfs_remove(&lfs, "caffè/mocha") => 0;
  3674. // stat paths
  3675. lfs_stat(&lfs, "caffè/espresso", &info) => LFS_ERR_NOENT;
  3676. lfs_stat(&lfs, "caffè/americano", &info) => LFS_ERR_NOENT;
  3677. lfs_stat(&lfs, "caffè/macchiato", &info) => LFS_ERR_NOENT;
  3678. lfs_stat(&lfs, "caffè/latte", &info) => LFS_ERR_NOENT;
  3679. lfs_stat(&lfs, "caffè/cappuccino", &info) => LFS_ERR_NOENT;
  3680. lfs_stat(&lfs, "caffè/mocha", &info) => LFS_ERR_NOENT;
  3681. lfs_unmount(&lfs) => 0;
  3682. '''
  3683. # more utf8 tests
  3684. [cases.test_paths_utf8_ipa]
  3685. defines.DIR = [false, true]
  3686. code = '''
  3687. lfs_t lfs;
  3688. lfs_format(&lfs, cfg) => 0;
  3689. lfs_mount(&lfs, cfg) => 0;
  3690. // create paths
  3691. lfs_mkdir(&lfs, "ˈkɔ.fi") => 0;
  3692. if (DIR) {
  3693. lfs_mkdir(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => 0;
  3694. lfs_mkdir(&lfs, "ˈkɔ.fi/koʊldbɹuː") => 0;
  3695. lfs_mkdir(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => 0;
  3696. lfs_mkdir(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => 0;
  3697. lfs_mkdir(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => 0;
  3698. lfs_mkdir(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => 0;
  3699. } else {
  3700. lfs_file_t file;
  3701. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3702. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3703. lfs_file_close(&lfs, &file) => 0;
  3704. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3705. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3706. lfs_file_close(&lfs, &file) => 0;
  3707. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3708. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3709. lfs_file_close(&lfs, &file) => 0;
  3710. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3711. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3712. lfs_file_close(&lfs, &file) => 0;
  3713. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3714. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3715. lfs_file_close(&lfs, &file) => 0;
  3716. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3717. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3718. lfs_file_close(&lfs, &file) => 0;
  3719. }
  3720. // stat paths
  3721. struct lfs_info info;
  3722. lfs_stat(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi", &info) => 0;
  3723. assert(strcmp(info.name, "dɹɪpˈkɔ.fi") == 0);
  3724. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3725. lfs_stat(&lfs, "ˈkɔ.fi/koʊldbɹuː", &info) => 0;
  3726. assert(strcmp(info.name, "koʊldbɹuː") == 0);
  3727. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3728. lfs_stat(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi", &info) => 0;
  3729. assert(strcmp(info.name, "tyɾckɑhvɛˈsi") == 0);
  3730. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3731. lfs_stat(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚", &info) => 0;
  3732. assert(strcmp(info.name, "ˈko.piˈt̪up̚.rʊk̚") == 0);
  3733. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3734. lfs_stat(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥", &info) => 0;
  3735. assert(strcmp(info.name, "kaː˨˩fe˧˧ɗaː˧˥") == 0);
  3736. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3737. lfs_stat(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥", &info) => 0;
  3738. assert(strcmp(info.name, "ʔoː˧.lia̯ŋ˦˥") == 0);
  3739. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3740. // file open paths, only works on files!
  3741. if (DIR) {
  3742. lfs_file_t file;
  3743. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3744. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3745. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3746. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3747. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3748. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3749. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3750. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3751. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3752. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3753. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3754. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3755. } else {
  3756. lfs_file_t file;
  3757. lfs_file_open(&lfs, &file, "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3758. LFS_O_RDONLY) => 0;
  3759. lfs_file_close(&lfs, &file) => 0;
  3760. lfs_file_open(&lfs, &file, "ˈkɔ.fi/koʊldbɹuː",
  3761. LFS_O_RDONLY) => 0;
  3762. lfs_file_close(&lfs, &file) => 0;
  3763. lfs_file_open(&lfs, &file, "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3764. LFS_O_RDONLY) => 0;
  3765. lfs_file_close(&lfs, &file) => 0;
  3766. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3767. LFS_O_RDONLY) => 0;
  3768. lfs_file_close(&lfs, &file) => 0;
  3769. lfs_file_open(&lfs, &file, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3770. LFS_O_RDONLY) => 0;
  3771. lfs_file_close(&lfs, &file) => 0;
  3772. lfs_file_open(&lfs, &file, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3773. LFS_O_RDONLY) => 0;
  3774. lfs_file_close(&lfs, &file) => 0;
  3775. }
  3776. // dir open paths, only works on dirs!
  3777. if (DIR) {
  3778. lfs_dir_t dir;
  3779. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => 0;
  3780. lfs_dir_close(&lfs, &dir) => 0;
  3781. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/koʊldbɹuː") => 0;
  3782. lfs_dir_close(&lfs, &dir) => 0;
  3783. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => 0;
  3784. lfs_dir_close(&lfs, &dir) => 0;
  3785. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => 0;
  3786. lfs_dir_close(&lfs, &dir) => 0;
  3787. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => 0;
  3788. lfs_dir_close(&lfs, &dir) => 0;
  3789. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => 0;
  3790. lfs_dir_close(&lfs, &dir) => 0;
  3791. } else {
  3792. lfs_dir_t dir;
  3793. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/dɹɪpˈkɔ.fi") => LFS_ERR_NOTDIR;
  3794. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/koʊldbɹuː") => LFS_ERR_NOTDIR;
  3795. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/tyɾckɑhvɛˈsi") => LFS_ERR_NOTDIR;
  3796. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚") => LFS_ERR_NOTDIR;
  3797. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥") => LFS_ERR_NOTDIR;
  3798. lfs_dir_open(&lfs, &dir, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥") => LFS_ERR_NOTDIR;
  3799. }
  3800. // rename paths
  3801. lfs_mkdir(&lfs, "kafˈfɛ") => 0;
  3802. lfs_rename(&lfs,
  3803. "ˈkɔ.fi/dɹɪpˈkɔ.fi",
  3804. "kafˈfɛ/eˈsprɛsso") => 0;
  3805. lfs_rename(&lfs,
  3806. "ˈkɔ.fi/koʊldbɹuː",
  3807. "kafˈfɛ/ameriˈkano") => 0;
  3808. lfs_rename(&lfs,
  3809. "ˈkɔ.fi/tyɾckɑhvɛˈsi",
  3810. "kafˈfɛ/makˈkjato") => 0;
  3811. lfs_rename(&lfs,
  3812. "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚",
  3813. "kafˈfɛ/ˈlat.te") => 0;
  3814. lfs_rename(&lfs,
  3815. "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥",
  3816. "kafˈfɛ/kapputˈt͡ʃino") => 0;
  3817. lfs_rename(&lfs,
  3818. "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥",
  3819. "kafˈfɛ/ˈmoʊkə") => 0;
  3820. // stat paths
  3821. lfs_stat(&lfs, "kafˈfɛ/eˈsprɛsso", &info) => 0;
  3822. assert(strcmp(info.name, "eˈsprɛsso") == 0);
  3823. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3824. lfs_stat(&lfs, "kafˈfɛ/ameriˈkano", &info) => 0;
  3825. assert(strcmp(info.name, "ameriˈkano") == 0);
  3826. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3827. lfs_stat(&lfs, "kafˈfɛ/makˈkjato", &info) => 0;
  3828. assert(strcmp(info.name, "makˈkjato") == 0);
  3829. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3830. lfs_stat(&lfs, "kafˈfɛ/ˈlat.te", &info) => 0;
  3831. assert(strcmp(info.name, "ˈlat.te") == 0);
  3832. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3833. lfs_stat(&lfs, "kafˈfɛ/kapputˈt͡ʃino", &info) => 0;
  3834. assert(strcmp(info.name, "kapputˈt͡ʃino") == 0);
  3835. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3836. lfs_stat(&lfs, "kafˈfɛ/ˈmoʊkə", &info) => 0;
  3837. assert(strcmp(info.name, "ˈmoʊkə") == 0);
  3838. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3839. lfs_stat(&lfs, "ˈkɔ.fi/dɹɪpˈkɔ.fi", &info) => LFS_ERR_NOENT;
  3840. lfs_stat(&lfs, "ˈkɔ.fi/koʊldbɹuː", &info) => LFS_ERR_NOENT;
  3841. lfs_stat(&lfs, "ˈkɔ.fi/tyɾckɑhvɛˈsi", &info) => LFS_ERR_NOENT;
  3842. lfs_stat(&lfs, "ˈkɔ.fi/ˈko.piˈt̪up̚.rʊk̚", &info) => LFS_ERR_NOENT;
  3843. lfs_stat(&lfs, "ˈkɔ.fi/kaː˨˩fe˧˧ɗaː˧˥", &info) => LFS_ERR_NOENT;
  3844. lfs_stat(&lfs, "ˈkɔ.fi/ʔoː˧.lia̯ŋ˦˥", &info) => LFS_ERR_NOENT;
  3845. // remove paths
  3846. lfs_remove(&lfs, "kafˈfɛ/eˈsprɛsso") => 0;
  3847. lfs_remove(&lfs, "kafˈfɛ/ameriˈkano") => 0;
  3848. lfs_remove(&lfs, "kafˈfɛ/makˈkjato") => 0;
  3849. lfs_remove(&lfs, "kafˈfɛ/ˈlat.te") => 0;
  3850. lfs_remove(&lfs, "kafˈfɛ/kapputˈt͡ʃino") => 0;
  3851. lfs_remove(&lfs, "kafˈfɛ/ˈmoʊkə") => 0;
  3852. // stat paths
  3853. lfs_stat(&lfs, "kafˈfɛ/eˈsprɛsso", &info) => LFS_ERR_NOENT;
  3854. lfs_stat(&lfs, "kafˈfɛ/ameriˈkano", &info) => LFS_ERR_NOENT;
  3855. lfs_stat(&lfs, "kafˈfɛ/makˈkjato", &info) => LFS_ERR_NOENT;
  3856. lfs_stat(&lfs, "kafˈfɛ/ˈlat.te", &info) => LFS_ERR_NOENT;
  3857. lfs_stat(&lfs, "kafˈfɛ/kapputˈt͡ʃino", &info) => LFS_ERR_NOENT;
  3858. lfs_stat(&lfs, "kafˈfɛ/ˈmoʊkə", &info) => LFS_ERR_NOENT;
  3859. lfs_unmount(&lfs) => 0;
  3860. '''
  3861. # test spaces have no problems
  3862. [cases.test_paths_spaces]
  3863. defines.DIR = [false, true]
  3864. code = '''
  3865. lfs_t lfs;
  3866. lfs_format(&lfs, cfg) => 0;
  3867. lfs_mount(&lfs, cfg) => 0;
  3868. // create paths
  3869. lfs_mkdir(&lfs, "c o f f e e") => 0;
  3870. if (DIR) {
  3871. lfs_mkdir(&lfs, "c o f f e e/d r i p") => 0;
  3872. lfs_mkdir(&lfs, "c o f f e e/c o l d b r e w") => 0;
  3873. lfs_mkdir(&lfs, "c o f f e e/t u r k i s h") => 0;
  3874. lfs_mkdir(&lfs, "c o f f e e/t u b r u k") => 0;
  3875. lfs_mkdir(&lfs, "c o f f e e/v i e t n a m e s e") => 0;
  3876. lfs_mkdir(&lfs, "c o f f e e/t h a i") => 0;
  3877. } else {
  3878. lfs_file_t file;
  3879. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3880. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3881. lfs_file_close(&lfs, &file) => 0;
  3882. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3883. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3884. lfs_file_close(&lfs, &file) => 0;
  3885. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3886. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3887. lfs_file_close(&lfs, &file) => 0;
  3888. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3889. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3890. lfs_file_close(&lfs, &file) => 0;
  3891. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3892. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3893. lfs_file_close(&lfs, &file) => 0;
  3894. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3895. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  3896. lfs_file_close(&lfs, &file) => 0;
  3897. }
  3898. // stat paths
  3899. struct lfs_info info;
  3900. lfs_stat(&lfs, "c o f f e e/d r i p", &info) => 0;
  3901. assert(strcmp(info.name, "d r i p") == 0);
  3902. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3903. lfs_stat(&lfs, "c o f f e e/c o l d b r e w", &info) => 0;
  3904. assert(strcmp(info.name, "c o l d b r e w") == 0);
  3905. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3906. lfs_stat(&lfs, "c o f f e e/t u r k i s h", &info) => 0;
  3907. assert(strcmp(info.name, "t u r k i s h") == 0);
  3908. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3909. lfs_stat(&lfs, "c o f f e e/t u b r u k", &info) => 0;
  3910. assert(strcmp(info.name, "t u b r u k") == 0);
  3911. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3912. lfs_stat(&lfs, "c o f f e e/v i e t n a m e s e", &info) => 0;
  3913. assert(strcmp(info.name, "v i e t n a m e s e") == 0);
  3914. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3915. lfs_stat(&lfs, "c o f f e e/t h a i", &info) => 0;
  3916. assert(strcmp(info.name, "t h a i") == 0);
  3917. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  3918. // file open paths, only works on files!
  3919. if (DIR) {
  3920. lfs_file_t file;
  3921. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3922. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3923. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3924. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3925. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3926. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3927. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3928. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3929. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3930. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3931. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3932. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  3933. } else {
  3934. lfs_file_t file;
  3935. lfs_file_open(&lfs, &file, "c o f f e e/d r i p",
  3936. LFS_O_RDONLY) => 0;
  3937. lfs_file_close(&lfs, &file) => 0;
  3938. lfs_file_open(&lfs, &file, "c o f f e e/c o l d b r e w",
  3939. LFS_O_RDONLY) => 0;
  3940. lfs_file_close(&lfs, &file) => 0;
  3941. lfs_file_open(&lfs, &file, "c o f f e e/t u r k i s h",
  3942. LFS_O_RDONLY) => 0;
  3943. lfs_file_close(&lfs, &file) => 0;
  3944. lfs_file_open(&lfs, &file, "c o f f e e/t u b r u k",
  3945. LFS_O_RDONLY) => 0;
  3946. lfs_file_close(&lfs, &file) => 0;
  3947. lfs_file_open(&lfs, &file, "c o f f e e/v i e t n a m e s e",
  3948. LFS_O_RDONLY) => 0;
  3949. lfs_file_close(&lfs, &file) => 0;
  3950. lfs_file_open(&lfs, &file, "c o f f e e/t h a i",
  3951. LFS_O_RDONLY) => 0;
  3952. lfs_file_close(&lfs, &file) => 0;
  3953. }
  3954. // dir open paths, only works on dirs!
  3955. if (DIR) {
  3956. lfs_dir_t dir;
  3957. lfs_dir_open(&lfs, &dir, "c o f f e e/d r i p") => 0;
  3958. lfs_dir_close(&lfs, &dir) => 0;
  3959. lfs_dir_open(&lfs, &dir, "c o f f e e/c o l d b r e w") => 0;
  3960. lfs_dir_close(&lfs, &dir) => 0;
  3961. lfs_dir_open(&lfs, &dir, "c o f f e e/t u r k i s h") => 0;
  3962. lfs_dir_close(&lfs, &dir) => 0;
  3963. lfs_dir_open(&lfs, &dir, "c o f f e e/t u b r u k") => 0;
  3964. lfs_dir_close(&lfs, &dir) => 0;
  3965. lfs_dir_open(&lfs, &dir, "c o f f e e/v i e t n a m e s e") => 0;
  3966. lfs_dir_close(&lfs, &dir) => 0;
  3967. lfs_dir_open(&lfs, &dir, "c o f f e e/t h a i") => 0;
  3968. lfs_dir_close(&lfs, &dir) => 0;
  3969. } else {
  3970. lfs_dir_t dir;
  3971. lfs_dir_open(&lfs, &dir, "c o f f e e/d r i p") => LFS_ERR_NOTDIR;
  3972. lfs_dir_open(&lfs, &dir, "c o f f e e/c o l d b r e w") => LFS_ERR_NOTDIR;
  3973. lfs_dir_open(&lfs, &dir, "c o f f e e/t u r k i s h") => LFS_ERR_NOTDIR;
  3974. lfs_dir_open(&lfs, &dir, "c o f f e e/t u b r u k") => LFS_ERR_NOTDIR;
  3975. lfs_dir_open(&lfs, &dir, "c o f f e e/v i e t n a m e s e") => LFS_ERR_NOTDIR;
  3976. lfs_dir_open(&lfs, &dir, "c o f f e e/t h a i") => LFS_ERR_NOTDIR;
  3977. }
  3978. // rename paths
  3979. lfs_mkdir(&lfs, "e s p r e s s o") => 0;
  3980. lfs_rename(&lfs,
  3981. "c o f f e e/d r i p",
  3982. "e s p r e s s o/e s p r e s s o") => 0;
  3983. lfs_rename(&lfs,
  3984. "c o f f e e/c o l d b r e w",
  3985. "e s p r e s s o/a m e r i c a n o") => 0;
  3986. lfs_rename(&lfs,
  3987. "c o f f e e/t u r k i s h",
  3988. "e s p r e s s o/m a c c h i a t o") => 0;
  3989. lfs_rename(&lfs,
  3990. "c o f f e e/t u b r u k",
  3991. "e s p r e s s o/l a t t e") => 0;
  3992. lfs_rename(&lfs,
  3993. "c o f f e e/v i e t n a m e s e",
  3994. "e s p r e s s o/c a p p u c c i n o") => 0;
  3995. lfs_rename(&lfs,
  3996. "c o f f e e/t h a i",
  3997. "e s p r e s s o/m o c h a") => 0;
  3998. // stat paths
  3999. lfs_stat(&lfs, "e s p r e s s o/e s p r e s s o", &info) => 0;
  4000. assert(strcmp(info.name, "e s p r e s s o") == 0);
  4001. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4002. lfs_stat(&lfs, "e s p r e s s o/a m e r i c a n o", &info) => 0;
  4003. assert(strcmp(info.name, "a m e r i c a n o") == 0);
  4004. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4005. lfs_stat(&lfs, "e s p r e s s o/m a c c h i a t o", &info) => 0;
  4006. assert(strcmp(info.name, "m a c c h i a t o") == 0);
  4007. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4008. lfs_stat(&lfs, "e s p r e s s o/l a t t e", &info) => 0;
  4009. assert(strcmp(info.name, "l a t t e") == 0);
  4010. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4011. lfs_stat(&lfs, "e s p r e s s o/c a p p u c c i n o", &info) => 0;
  4012. assert(strcmp(info.name, "c a p p u c c i n o") == 0);
  4013. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4014. lfs_stat(&lfs, "e s p r e s s o/m o c h a", &info) => 0;
  4015. assert(strcmp(info.name, "m o c h a") == 0);
  4016. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4017. lfs_stat(&lfs, "c o f f e e/d r i p", &info) => LFS_ERR_NOENT;
  4018. lfs_stat(&lfs, "c o f f e e/c o l d b r e w", &info) => LFS_ERR_NOENT;
  4019. lfs_stat(&lfs, "c o f f e e/t u r k i s h", &info) => LFS_ERR_NOENT;
  4020. lfs_stat(&lfs, "c o f f e e/t u b r u k", &info) => LFS_ERR_NOENT;
  4021. lfs_stat(&lfs, "c o f f e e/v i e t n a m e s e", &info) => LFS_ERR_NOENT;
  4022. lfs_stat(&lfs, "c o f f e e/t h a i", &info) => LFS_ERR_NOENT;
  4023. // remove paths
  4024. lfs_remove(&lfs, "e s p r e s s o/e s p r e s s o") => 0;
  4025. lfs_remove(&lfs, "e s p r e s s o/a m e r i c a n o") => 0;
  4026. lfs_remove(&lfs, "e s p r e s s o/m a c c h i a t o") => 0;
  4027. lfs_remove(&lfs, "e s p r e s s o/l a t t e") => 0;
  4028. lfs_remove(&lfs, "e s p r e s s o/c a p p u c c i n o") => 0;
  4029. lfs_remove(&lfs, "e s p r e s s o/m o c h a") => 0;
  4030. // stat paths
  4031. lfs_stat(&lfs, "e s p r e s s o/e s p r e s s o", &info) => LFS_ERR_NOENT;
  4032. lfs_stat(&lfs, "e s p r e s s o/a m e r i c a n o", &info) => LFS_ERR_NOENT;
  4033. lfs_stat(&lfs, "e s p r e s s o/m a c c h i a t o", &info) => LFS_ERR_NOENT;
  4034. lfs_stat(&lfs, "e s p r e s s o/l a t t e", &info) => LFS_ERR_NOENT;
  4035. lfs_stat(&lfs, "e s p r e s s o/c a p p u c c i n o", &info) => LFS_ERR_NOENT;
  4036. lfs_stat(&lfs, "e s p r e s s o/m o c h a", &info) => LFS_ERR_NOENT;
  4037. lfs_unmount(&lfs) => 0;
  4038. '''
  4039. # test with only spaces
  4040. #
  4041. # please don't do this
  4042. [cases.test_paths_oopsallspaces]
  4043. defines.DIR = [false, true]
  4044. code = '''
  4045. lfs_t lfs;
  4046. lfs_format(&lfs, cfg) => 0;
  4047. lfs_mount(&lfs, cfg) => 0;
  4048. // create paths
  4049. lfs_mkdir(&lfs, " ") => 0;
  4050. if (DIR) {
  4051. lfs_mkdir(&lfs, " / ") => 0;
  4052. lfs_mkdir(&lfs, " / ") => 0;
  4053. lfs_mkdir(&lfs, " / ") => 0;
  4054. lfs_mkdir(&lfs, " / ") => 0;
  4055. lfs_mkdir(&lfs, " / ") => 0;
  4056. lfs_mkdir(&lfs, " / ") => 0;
  4057. } else {
  4058. lfs_file_t file;
  4059. lfs_file_open(&lfs, &file, " / ",
  4060. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4061. lfs_file_close(&lfs, &file) => 0;
  4062. lfs_file_open(&lfs, &file, " / ",
  4063. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4064. lfs_file_close(&lfs, &file) => 0;
  4065. lfs_file_open(&lfs, &file, " / ",
  4066. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4067. lfs_file_close(&lfs, &file) => 0;
  4068. lfs_file_open(&lfs, &file, " / ",
  4069. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4070. lfs_file_close(&lfs, &file) => 0;
  4071. lfs_file_open(&lfs, &file, " / ",
  4072. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4073. lfs_file_close(&lfs, &file) => 0;
  4074. lfs_file_open(&lfs, &file, " / ",
  4075. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4076. lfs_file_close(&lfs, &file) => 0;
  4077. }
  4078. // stat paths
  4079. struct lfs_info info;
  4080. lfs_stat(&lfs, " / ", &info) => 0;
  4081. assert(strcmp(info.name, " ") == 0);
  4082. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4083. lfs_stat(&lfs, " / ", &info) => 0;
  4084. assert(strcmp(info.name, " ") == 0);
  4085. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4086. lfs_stat(&lfs, " / ", &info) => 0;
  4087. assert(strcmp(info.name, " ") == 0);
  4088. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4089. lfs_stat(&lfs, " / ", &info) => 0;
  4090. assert(strcmp(info.name, " ") == 0);
  4091. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4092. lfs_stat(&lfs, " / ", &info) => 0;
  4093. assert(strcmp(info.name, " ") == 0);
  4094. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4095. lfs_stat(&lfs, " / ", &info) => 0;
  4096. assert(strcmp(info.name, " ") == 0);
  4097. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4098. // file open paths, only works on files!
  4099. if (DIR) {
  4100. lfs_file_t file;
  4101. lfs_file_open(&lfs, &file, " / ",
  4102. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4103. lfs_file_open(&lfs, &file, " / ",
  4104. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4105. lfs_file_open(&lfs, &file, " / ",
  4106. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4107. lfs_file_open(&lfs, &file, " / ",
  4108. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4109. lfs_file_open(&lfs, &file, " / ",
  4110. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4111. lfs_file_open(&lfs, &file, " / ",
  4112. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4113. } else {
  4114. lfs_file_t file;
  4115. lfs_file_open(&lfs, &file, " / ",
  4116. LFS_O_RDONLY) => 0;
  4117. lfs_file_close(&lfs, &file) => 0;
  4118. lfs_file_open(&lfs, &file, " / ",
  4119. LFS_O_RDONLY) => 0;
  4120. lfs_file_close(&lfs, &file) => 0;
  4121. lfs_file_open(&lfs, &file, " / ",
  4122. LFS_O_RDONLY) => 0;
  4123. lfs_file_close(&lfs, &file) => 0;
  4124. lfs_file_open(&lfs, &file, " / ",
  4125. LFS_O_RDONLY) => 0;
  4126. lfs_file_close(&lfs, &file) => 0;
  4127. lfs_file_open(&lfs, &file, " / ",
  4128. LFS_O_RDONLY) => 0;
  4129. lfs_file_close(&lfs, &file) => 0;
  4130. lfs_file_open(&lfs, &file, " / ",
  4131. LFS_O_RDONLY) => 0;
  4132. lfs_file_close(&lfs, &file) => 0;
  4133. }
  4134. // dir open paths, only works on dirs!
  4135. if (DIR) {
  4136. lfs_dir_t dir;
  4137. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4138. lfs_dir_close(&lfs, &dir) => 0;
  4139. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4140. lfs_dir_close(&lfs, &dir) => 0;
  4141. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4142. lfs_dir_close(&lfs, &dir) => 0;
  4143. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4144. lfs_dir_close(&lfs, &dir) => 0;
  4145. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4146. lfs_dir_close(&lfs, &dir) => 0;
  4147. lfs_dir_open(&lfs, &dir, " / ") => 0;
  4148. lfs_dir_close(&lfs, &dir) => 0;
  4149. } else {
  4150. lfs_dir_t dir;
  4151. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4152. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4153. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4154. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4155. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4156. lfs_dir_open(&lfs, &dir, " / ") => LFS_ERR_NOTDIR;
  4157. }
  4158. // rename paths
  4159. lfs_mkdir(&lfs, " ") => 0;
  4160. lfs_rename(&lfs,
  4161. " / ",
  4162. " / ") => 0;
  4163. lfs_rename(&lfs,
  4164. " / ",
  4165. " / ") => 0;
  4166. lfs_rename(&lfs,
  4167. " / ",
  4168. " / ") => 0;
  4169. lfs_rename(&lfs,
  4170. " / ",
  4171. " / ") => 0;
  4172. lfs_rename(&lfs,
  4173. " / ",
  4174. " / ") => 0;
  4175. lfs_rename(&lfs,
  4176. " / ",
  4177. " / ") => 0;
  4178. // stat paths
  4179. lfs_stat(&lfs, " / ", &info) => 0;
  4180. assert(strcmp(info.name, " ") == 0);
  4181. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4182. lfs_stat(&lfs, " / ", &info) => 0;
  4183. assert(strcmp(info.name, " ") == 0);
  4184. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4185. lfs_stat(&lfs, " / ", &info) => 0;
  4186. assert(strcmp(info.name, " ") == 0);
  4187. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4188. lfs_stat(&lfs, " / ", &info) => 0;
  4189. assert(strcmp(info.name, " ") == 0);
  4190. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4191. lfs_stat(&lfs, " / ", &info) => 0;
  4192. assert(strcmp(info.name, " ") == 0);
  4193. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4194. lfs_stat(&lfs, " / ", &info) => 0;
  4195. assert(strcmp(info.name, " ") == 0);
  4196. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4197. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4198. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4199. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4200. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4201. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4202. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4203. // remove paths
  4204. lfs_remove(&lfs, " / ") => 0;
  4205. lfs_remove(&lfs, " / ") => 0;
  4206. lfs_remove(&lfs, " / ") => 0;
  4207. lfs_remove(&lfs, " / ") => 0;
  4208. lfs_remove(&lfs, " / ") => 0;
  4209. lfs_remove(&lfs, " / ") => 0;
  4210. // stat paths
  4211. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4212. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4213. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4214. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4215. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4216. lfs_stat(&lfs, " / ", &info) => LFS_ERR_NOENT;
  4217. lfs_unmount(&lfs) => 0;
  4218. '''
  4219. # test with only ascii control characters
  4220. #
  4221. # littlefs only cares about "./" and NULL
  4222. [cases.test_paths_nonprintable]
  4223. defines.DIR = [false, true]
  4224. code = '''
  4225. lfs_t lfs;
  4226. lfs_format(&lfs, cfg) => 0;
  4227. lfs_mount(&lfs, cfg) => 0;
  4228. // create paths
  4229. lfs_mkdir(&lfs, "\x0c") => 0;
  4230. if (DIR) {
  4231. lfs_mkdir(&lfs, "\x0c/\x01") => 0;
  4232. lfs_mkdir(&lfs, "\x0c/\x02") => 0;
  4233. lfs_mkdir(&lfs, "\x0c/\x03") => 0;
  4234. lfs_mkdir(&lfs, "\x0c/\x04") => 0;
  4235. lfs_mkdir(&lfs, "\x0c/\x05") => 0;
  4236. lfs_mkdir(&lfs, "\x0c/\x06") => 0;
  4237. } else {
  4238. lfs_file_t file;
  4239. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4240. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4241. lfs_file_close(&lfs, &file) => 0;
  4242. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4243. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4244. lfs_file_close(&lfs, &file) => 0;
  4245. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4246. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4247. lfs_file_close(&lfs, &file) => 0;
  4248. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4249. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4250. lfs_file_close(&lfs, &file) => 0;
  4251. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4252. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4253. lfs_file_close(&lfs, &file) => 0;
  4254. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4255. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4256. lfs_file_close(&lfs, &file) => 0;
  4257. }
  4258. // stat paths
  4259. struct lfs_info info;
  4260. lfs_stat(&lfs, "\x0c/\x01", &info) => 0;
  4261. assert(strcmp(info.name, "\x01") == 0);
  4262. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4263. lfs_stat(&lfs, "\x0c/\x02", &info) => 0;
  4264. assert(strcmp(info.name, "\x02") == 0);
  4265. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4266. lfs_stat(&lfs, "\x0c/\x03", &info) => 0;
  4267. assert(strcmp(info.name, "\x03") == 0);
  4268. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4269. lfs_stat(&lfs, "\x0c/\x04", &info) => 0;
  4270. assert(strcmp(info.name, "\x04") == 0);
  4271. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4272. lfs_stat(&lfs, "\x0c/\x05", &info) => 0;
  4273. assert(strcmp(info.name, "\x05") == 0);
  4274. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4275. lfs_stat(&lfs, "\x0c/\x06", &info) => 0;
  4276. assert(strcmp(info.name, "\x06") == 0);
  4277. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4278. // file open paths, only works on files!
  4279. if (DIR) {
  4280. lfs_file_t file;
  4281. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4282. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4283. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4284. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4285. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4286. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4287. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4288. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4289. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4290. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4291. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4292. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4293. } else {
  4294. lfs_file_t file;
  4295. lfs_file_open(&lfs, &file, "\x0c/\x01",
  4296. LFS_O_RDONLY) => 0;
  4297. lfs_file_close(&lfs, &file) => 0;
  4298. lfs_file_open(&lfs, &file, "\x0c/\x02",
  4299. LFS_O_RDONLY) => 0;
  4300. lfs_file_close(&lfs, &file) => 0;
  4301. lfs_file_open(&lfs, &file, "\x0c/\x03",
  4302. LFS_O_RDONLY) => 0;
  4303. lfs_file_close(&lfs, &file) => 0;
  4304. lfs_file_open(&lfs, &file, "\x0c/\x04",
  4305. LFS_O_RDONLY) => 0;
  4306. lfs_file_close(&lfs, &file) => 0;
  4307. lfs_file_open(&lfs, &file, "\x0c/\x05",
  4308. LFS_O_RDONLY) => 0;
  4309. lfs_file_close(&lfs, &file) => 0;
  4310. lfs_file_open(&lfs, &file, "\x0c/\x06",
  4311. LFS_O_RDONLY) => 0;
  4312. lfs_file_close(&lfs, &file) => 0;
  4313. }
  4314. // dir open paths, only works on dirs!
  4315. if (DIR) {
  4316. lfs_dir_t dir;
  4317. lfs_dir_open(&lfs, &dir, "\x0c/\x01") => 0;
  4318. lfs_dir_close(&lfs, &dir) => 0;
  4319. lfs_dir_open(&lfs, &dir, "\x0c/\x02") => 0;
  4320. lfs_dir_close(&lfs, &dir) => 0;
  4321. lfs_dir_open(&lfs, &dir, "\x0c/\x03") => 0;
  4322. lfs_dir_close(&lfs, &dir) => 0;
  4323. lfs_dir_open(&lfs, &dir, "\x0c/\x04") => 0;
  4324. lfs_dir_close(&lfs, &dir) => 0;
  4325. lfs_dir_open(&lfs, &dir, "\x0c/\x05") => 0;
  4326. lfs_dir_close(&lfs, &dir) => 0;
  4327. lfs_dir_open(&lfs, &dir, "\x0c/\x06") => 0;
  4328. lfs_dir_close(&lfs, &dir) => 0;
  4329. } else {
  4330. lfs_dir_t dir;
  4331. lfs_dir_open(&lfs, &dir, "\x0c/\x01") => LFS_ERR_NOTDIR;
  4332. lfs_dir_open(&lfs, &dir, "\x0c/\x02") => LFS_ERR_NOTDIR;
  4333. lfs_dir_open(&lfs, &dir, "\x0c/\x03") => LFS_ERR_NOTDIR;
  4334. lfs_dir_open(&lfs, &dir, "\x0c/\x04") => LFS_ERR_NOTDIR;
  4335. lfs_dir_open(&lfs, &dir, "\x0c/\x05") => LFS_ERR_NOTDIR;
  4336. lfs_dir_open(&lfs, &dir, "\x0c/\x06") => LFS_ERR_NOTDIR;
  4337. }
  4338. // rename paths
  4339. lfs_mkdir(&lfs, "\x0e") => 0;
  4340. lfs_rename(&lfs,
  4341. "\x0c/\x01",
  4342. "\x0e/\x1a") => 0;
  4343. lfs_rename(&lfs,
  4344. "\x0c/\x02",
  4345. "\x0e/\x1b") => 0;
  4346. lfs_rename(&lfs,
  4347. "\x0c/\x03",
  4348. "\x0e/\x1c") => 0;
  4349. lfs_rename(&lfs,
  4350. "\x0c/\x04",
  4351. "\x0e/\x1d") => 0;
  4352. lfs_rename(&lfs,
  4353. "\x0c/\x05",
  4354. "\x0e/\x1e") => 0;
  4355. lfs_rename(&lfs,
  4356. "\x0c/\x06",
  4357. "\x0e/\x1f") => 0;
  4358. // stat paths
  4359. lfs_stat(&lfs, "\x0e/\x1a", &info) => 0;
  4360. assert(strcmp(info.name, "\x1a") == 0);
  4361. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4362. lfs_stat(&lfs, "\x0e/\x1b", &info) => 0;
  4363. assert(strcmp(info.name, "\x1b") == 0);
  4364. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4365. lfs_stat(&lfs, "\x0e/\x1c", &info) => 0;
  4366. assert(strcmp(info.name, "\x1c") == 0);
  4367. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4368. lfs_stat(&lfs, "\x0e/\x1d", &info) => 0;
  4369. assert(strcmp(info.name, "\x1d") == 0);
  4370. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4371. lfs_stat(&lfs, "\x0e/\x1e", &info) => 0;
  4372. assert(strcmp(info.name, "\x1e") == 0);
  4373. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4374. lfs_stat(&lfs, "\x0e/\x1f", &info) => 0;
  4375. assert(strcmp(info.name, "\x1f") == 0);
  4376. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4377. lfs_stat(&lfs, "\x0c/\x01", &info) => LFS_ERR_NOENT;
  4378. lfs_stat(&lfs, "\x0c/\x02", &info) => LFS_ERR_NOENT;
  4379. lfs_stat(&lfs, "\x0c/\x03", &info) => LFS_ERR_NOENT;
  4380. lfs_stat(&lfs, "\x0c/\x04", &info) => LFS_ERR_NOENT;
  4381. lfs_stat(&lfs, "\x0c/\x05", &info) => LFS_ERR_NOENT;
  4382. lfs_stat(&lfs, "\x0c/\x06", &info) => LFS_ERR_NOENT;
  4383. // remove paths
  4384. lfs_remove(&lfs, "\x0e/\x1a") => 0;
  4385. lfs_remove(&lfs, "\x0e/\x1b") => 0;
  4386. lfs_remove(&lfs, "\x0e/\x1c") => 0;
  4387. lfs_remove(&lfs, "\x0e/\x1d") => 0;
  4388. lfs_remove(&lfs, "\x0e/\x1e") => 0;
  4389. lfs_remove(&lfs, "\x0e/\x1f") => 0;
  4390. // stat paths
  4391. lfs_stat(&lfs, "\x0e/\x1a", &info) => LFS_ERR_NOENT;
  4392. lfs_stat(&lfs, "\x0e/\x1b", &info) => LFS_ERR_NOENT;
  4393. lfs_stat(&lfs, "\x0e/\x1c", &info) => LFS_ERR_NOENT;
  4394. lfs_stat(&lfs, "\x0e/\x1d", &info) => LFS_ERR_NOENT;
  4395. lfs_stat(&lfs, "\x0e/\x1e", &info) => LFS_ERR_NOENT;
  4396. lfs_stat(&lfs, "\x0e/\x1f", &info) => LFS_ERR_NOENT;
  4397. lfs_unmount(&lfs) => 0;
  4398. '''
  4399. # test with only ascii DELs
  4400. #
  4401. # I don't know why you'd do this
  4402. [cases.test_paths_oopsalldels]
  4403. defines.DIR = [false, true]
  4404. code = '''
  4405. lfs_t lfs;
  4406. lfs_format(&lfs, cfg) => 0;
  4407. lfs_mount(&lfs, cfg) => 0;
  4408. // create paths
  4409. lfs_mkdir(&lfs, "\x7f") => 0;
  4410. if (DIR) {
  4411. lfs_mkdir(&lfs, "\x7f/\x7f") => 0;
  4412. lfs_mkdir(&lfs, "\x7f/\x7f\x7f") => 0;
  4413. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f") => 0;
  4414. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f") => 0;
  4415. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f") => 0;
  4416. lfs_mkdir(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4417. } else {
  4418. lfs_file_t file;
  4419. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4420. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4421. lfs_file_close(&lfs, &file) => 0;
  4422. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4423. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4424. lfs_file_close(&lfs, &file) => 0;
  4425. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4426. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4427. lfs_file_close(&lfs, &file) => 0;
  4428. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4429. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4430. lfs_file_close(&lfs, &file) => 0;
  4431. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4432. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4433. lfs_file_close(&lfs, &file) => 0;
  4434. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4435. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4436. lfs_file_close(&lfs, &file) => 0;
  4437. }
  4438. // stat paths
  4439. struct lfs_info info;
  4440. lfs_stat(&lfs, "\x7f/\x7f", &info) => 0;
  4441. assert(strcmp(info.name, "\x7f") == 0);
  4442. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4443. lfs_stat(&lfs, "\x7f/\x7f\x7f", &info) => 0;
  4444. assert(strcmp(info.name, "\x7f\x7f") == 0);
  4445. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4446. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f", &info) => 0;
  4447. assert(strcmp(info.name, "\x7f\x7f\x7f") == 0);
  4448. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4449. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f", &info) => 0;
  4450. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f") == 0);
  4451. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4452. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4453. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f") == 0);
  4454. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4455. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4456. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4457. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4458. // file open paths, only works on files!
  4459. if (DIR) {
  4460. lfs_file_t file;
  4461. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4462. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4463. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4464. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4465. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4466. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4467. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4468. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4469. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4470. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4471. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4472. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4473. } else {
  4474. lfs_file_t file;
  4475. lfs_file_open(&lfs, &file, "\x7f/\x7f",
  4476. LFS_O_RDONLY) => 0;
  4477. lfs_file_close(&lfs, &file) => 0;
  4478. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f",
  4479. LFS_O_RDONLY) => 0;
  4480. lfs_file_close(&lfs, &file) => 0;
  4481. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f",
  4482. LFS_O_RDONLY) => 0;
  4483. lfs_file_close(&lfs, &file) => 0;
  4484. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f",
  4485. LFS_O_RDONLY) => 0;
  4486. lfs_file_close(&lfs, &file) => 0;
  4487. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4488. LFS_O_RDONLY) => 0;
  4489. lfs_file_close(&lfs, &file) => 0;
  4490. lfs_file_open(&lfs, &file, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4491. LFS_O_RDONLY) => 0;
  4492. lfs_file_close(&lfs, &file) => 0;
  4493. }
  4494. // dir open paths, only works on dirs!
  4495. if (DIR) {
  4496. lfs_dir_t dir;
  4497. lfs_dir_open(&lfs, &dir, "\x7f/\x7f") => 0;
  4498. lfs_dir_close(&lfs, &dir) => 0;
  4499. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f") => 0;
  4500. lfs_dir_close(&lfs, &dir) => 0;
  4501. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f") => 0;
  4502. lfs_dir_close(&lfs, &dir) => 0;
  4503. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f") => 0;
  4504. lfs_dir_close(&lfs, &dir) => 0;
  4505. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f") => 0;
  4506. lfs_dir_close(&lfs, &dir) => 0;
  4507. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4508. lfs_dir_close(&lfs, &dir) => 0;
  4509. } else {
  4510. lfs_dir_t dir;
  4511. lfs_dir_open(&lfs, &dir, "\x7f/\x7f") => LFS_ERR_NOTDIR;
  4512. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f") => LFS_ERR_NOTDIR;
  4513. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4514. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4515. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4516. lfs_dir_open(&lfs, &dir, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => LFS_ERR_NOTDIR;
  4517. }
  4518. // rename paths
  4519. lfs_mkdir(&lfs, "\x7f\x7f") => 0;
  4520. lfs_rename(&lfs,
  4521. "\x7f/\x7f",
  4522. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4523. lfs_rename(&lfs,
  4524. "\x7f/\x7f\x7f",
  4525. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4526. lfs_rename(&lfs,
  4527. "\x7f/\x7f\x7f\x7f",
  4528. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4529. lfs_rename(&lfs,
  4530. "\x7f/\x7f\x7f\x7f\x7f",
  4531. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4532. lfs_rename(&lfs,
  4533. "\x7f/\x7f\x7f\x7f\x7f\x7f",
  4534. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4535. lfs_rename(&lfs,
  4536. "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f",
  4537. "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4538. // stat paths
  4539. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4540. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4541. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4542. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4543. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4544. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4545. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4546. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4547. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4548. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4549. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4550. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4551. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4552. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4553. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4554. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => 0;
  4555. assert(strcmp(info.name, "\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") == 0);
  4556. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4557. lfs_stat(&lfs, "\x7f/\x7f", &info) => LFS_ERR_NOENT;
  4558. lfs_stat(&lfs, "\x7f/\x7f\x7f", &info) => LFS_ERR_NOENT;
  4559. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4560. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4561. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4562. lfs_stat(&lfs, "\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4563. // remove paths
  4564. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4565. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4566. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4567. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4568. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4569. lfs_remove(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f") => 0;
  4570. // stat paths
  4571. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4572. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4573. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4574. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4575. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4576. lfs_stat(&lfs, "\x7f\x7f/\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f", &info) => LFS_ERR_NOENT;
  4577. lfs_unmount(&lfs) => 0;
  4578. '''
  4579. # test with invalid utf8 sequences
  4580. #
  4581. # Don't do this! These filenames are not utf8 and will probably break
  4582. # external tools.
  4583. #
  4584. [cases.test_paths_nonutf8]
  4585. defines.DIR = [false, true]
  4586. code = '''
  4587. lfs_t lfs;
  4588. lfs_format(&lfs, cfg) => 0;
  4589. lfs_mount(&lfs, cfg) => 0;
  4590. // create paths
  4591. lfs_mkdir(&lfs, "\xc0") => 0;
  4592. if (DIR) {
  4593. lfs_mkdir(&lfs, "\xc0/\xa0") => 0;
  4594. lfs_mkdir(&lfs, "\xc0/\xb0") => 0;
  4595. lfs_mkdir(&lfs, "\xc0/\xc0") => 0;
  4596. lfs_mkdir(&lfs, "\xc0/\xd0") => 0;
  4597. lfs_mkdir(&lfs, "\xc0/\xe0") => 0;
  4598. lfs_mkdir(&lfs, "\xc0/\xf0") => 0;
  4599. } else {
  4600. lfs_file_t file;
  4601. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4602. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4603. lfs_file_close(&lfs, &file) => 0;
  4604. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4605. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4606. lfs_file_close(&lfs, &file) => 0;
  4607. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4608. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4609. lfs_file_close(&lfs, &file) => 0;
  4610. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4611. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4612. lfs_file_close(&lfs, &file) => 0;
  4613. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4614. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4615. lfs_file_close(&lfs, &file) => 0;
  4616. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4617. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4618. lfs_file_close(&lfs, &file) => 0;
  4619. }
  4620. // stat paths
  4621. struct lfs_info info;
  4622. lfs_stat(&lfs, "\xc0/\xa0", &info) => 0;
  4623. assert(strcmp(info.name, "\xa0") == 0);
  4624. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4625. lfs_stat(&lfs, "\xc0/\xb0", &info) => 0;
  4626. assert(strcmp(info.name, "\xb0") == 0);
  4627. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4628. lfs_stat(&lfs, "\xc0/\xc0", &info) => 0;
  4629. assert(strcmp(info.name, "\xc0") == 0);
  4630. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4631. lfs_stat(&lfs, "\xc0/\xd0", &info) => 0;
  4632. assert(strcmp(info.name, "\xd0") == 0);
  4633. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4634. lfs_stat(&lfs, "\xc0/\xe0", &info) => 0;
  4635. assert(strcmp(info.name, "\xe0") == 0);
  4636. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4637. lfs_stat(&lfs, "\xc0/\xf0", &info) => 0;
  4638. assert(strcmp(info.name, "\xf0") == 0);
  4639. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4640. // file open paths, only works on files!
  4641. if (DIR) {
  4642. lfs_file_t file;
  4643. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4644. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4645. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4646. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4647. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4648. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4649. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4650. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4651. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4652. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4653. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4654. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4655. } else {
  4656. lfs_file_t file;
  4657. lfs_file_open(&lfs, &file, "\xc0/\xa0",
  4658. LFS_O_RDONLY) => 0;
  4659. lfs_file_close(&lfs, &file) => 0;
  4660. lfs_file_open(&lfs, &file, "\xc0/\xb0",
  4661. LFS_O_RDONLY) => 0;
  4662. lfs_file_close(&lfs, &file) => 0;
  4663. lfs_file_open(&lfs, &file, "\xc0/\xc0",
  4664. LFS_O_RDONLY) => 0;
  4665. lfs_file_close(&lfs, &file) => 0;
  4666. lfs_file_open(&lfs, &file, "\xc0/\xd0",
  4667. LFS_O_RDONLY) => 0;
  4668. lfs_file_close(&lfs, &file) => 0;
  4669. lfs_file_open(&lfs, &file, "\xc0/\xe0",
  4670. LFS_O_RDONLY) => 0;
  4671. lfs_file_close(&lfs, &file) => 0;
  4672. lfs_file_open(&lfs, &file, "\xc0/\xf0",
  4673. LFS_O_RDONLY) => 0;
  4674. lfs_file_close(&lfs, &file) => 0;
  4675. }
  4676. // dir open paths, only works on dirs!
  4677. if (DIR) {
  4678. lfs_dir_t dir;
  4679. lfs_dir_open(&lfs, &dir, "\xc0/\xa0") => 0;
  4680. lfs_dir_close(&lfs, &dir) => 0;
  4681. lfs_dir_open(&lfs, &dir, "\xc0/\xb0") => 0;
  4682. lfs_dir_close(&lfs, &dir) => 0;
  4683. lfs_dir_open(&lfs, &dir, "\xc0/\xc0") => 0;
  4684. lfs_dir_close(&lfs, &dir) => 0;
  4685. lfs_dir_open(&lfs, &dir, "\xc0/\xd0") => 0;
  4686. lfs_dir_close(&lfs, &dir) => 0;
  4687. lfs_dir_open(&lfs, &dir, "\xc0/\xe0") => 0;
  4688. lfs_dir_close(&lfs, &dir) => 0;
  4689. lfs_dir_open(&lfs, &dir, "\xc0/\xf0") => 0;
  4690. lfs_dir_close(&lfs, &dir) => 0;
  4691. } else {
  4692. lfs_dir_t dir;
  4693. lfs_dir_open(&lfs, &dir, "\xc0/\xa0") => LFS_ERR_NOTDIR;
  4694. lfs_dir_open(&lfs, &dir, "\xc0/\xb0") => LFS_ERR_NOTDIR;
  4695. lfs_dir_open(&lfs, &dir, "\xc0/\xc0") => LFS_ERR_NOTDIR;
  4696. lfs_dir_open(&lfs, &dir, "\xc0/\xd0") => LFS_ERR_NOTDIR;
  4697. lfs_dir_open(&lfs, &dir, "\xc0/\xe0") => LFS_ERR_NOTDIR;
  4698. lfs_dir_open(&lfs, &dir, "\xc0/\xf0") => LFS_ERR_NOTDIR;
  4699. }
  4700. // rename paths
  4701. lfs_mkdir(&lfs, "\xe0") => 0;
  4702. lfs_rename(&lfs,
  4703. "\xc0/\xa0",
  4704. "\xe0/\xaf") => 0;
  4705. lfs_rename(&lfs,
  4706. "\xc0/\xb0",
  4707. "\xe0/\xbf") => 0;
  4708. lfs_rename(&lfs,
  4709. "\xc0/\xc0",
  4710. "\xe0/\xcf") => 0;
  4711. lfs_rename(&lfs,
  4712. "\xc0/\xd0",
  4713. "\xe0/\xdf") => 0;
  4714. lfs_rename(&lfs,
  4715. "\xc0/\xe0",
  4716. "\xe0/\xef") => 0;
  4717. lfs_rename(&lfs,
  4718. "\xc0/\xf0",
  4719. "\xe0/\xff") => 0;
  4720. // stat paths
  4721. lfs_stat(&lfs, "\xe0/\xaf", &info) => 0;
  4722. assert(strcmp(info.name, "\xaf") == 0);
  4723. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4724. lfs_stat(&lfs, "\xe0/\xbf", &info) => 0;
  4725. assert(strcmp(info.name, "\xbf") == 0);
  4726. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4727. lfs_stat(&lfs, "\xe0/\xcf", &info) => 0;
  4728. assert(strcmp(info.name, "\xcf") == 0);
  4729. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4730. lfs_stat(&lfs, "\xe0/\xdf", &info) => 0;
  4731. assert(strcmp(info.name, "\xdf") == 0);
  4732. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4733. lfs_stat(&lfs, "\xe0/\xef", &info) => 0;
  4734. assert(strcmp(info.name, "\xef") == 0);
  4735. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4736. lfs_stat(&lfs, "\xe0/\xff", &info) => 0;
  4737. assert(strcmp(info.name, "\xff") == 0);
  4738. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4739. lfs_stat(&lfs, "\xc0/\xa0", &info) => LFS_ERR_NOENT;
  4740. lfs_stat(&lfs, "\xc0/\xb0", &info) => LFS_ERR_NOENT;
  4741. lfs_stat(&lfs, "\xc0/\xc0", &info) => LFS_ERR_NOENT;
  4742. lfs_stat(&lfs, "\xc0/\xd0", &info) => LFS_ERR_NOENT;
  4743. lfs_stat(&lfs, "\xc0/\xe0", &info) => LFS_ERR_NOENT;
  4744. lfs_stat(&lfs, "\xc0/\xf0", &info) => LFS_ERR_NOENT;
  4745. // remove paths
  4746. lfs_remove(&lfs, "\xe0/\xaf") => 0;
  4747. lfs_remove(&lfs, "\xe0/\xbf") => 0;
  4748. lfs_remove(&lfs, "\xe0/\xcf") => 0;
  4749. lfs_remove(&lfs, "\xe0/\xdf") => 0;
  4750. lfs_remove(&lfs, "\xe0/\xef") => 0;
  4751. lfs_remove(&lfs, "\xe0/\xff") => 0;
  4752. // stat paths
  4753. lfs_stat(&lfs, "\xe0/\xaf", &info) => LFS_ERR_NOENT;
  4754. lfs_stat(&lfs, "\xe0/\xbf", &info) => LFS_ERR_NOENT;
  4755. lfs_stat(&lfs, "\xe0/\xcf", &info) => LFS_ERR_NOENT;
  4756. lfs_stat(&lfs, "\xe0/\xdf", &info) => LFS_ERR_NOENT;
  4757. lfs_stat(&lfs, "\xe0/\xef", &info) => LFS_ERR_NOENT;
  4758. lfs_stat(&lfs, "\xe0/\xff", &info) => LFS_ERR_NOENT;
  4759. lfs_unmount(&lfs) => 0;
  4760. '''
  4761. # test with only "\xff" characters
  4762. #
  4763. # Don't do this! These filenames are not utf8 and will probably break
  4764. # external tools.
  4765. #
  4766. [cases.test_paths_oopsallffs]
  4767. defines.DIR = [false, true]
  4768. code = '''
  4769. lfs_t lfs;
  4770. lfs_format(&lfs, cfg) => 0;
  4771. lfs_mount(&lfs, cfg) => 0;
  4772. // create paths
  4773. lfs_mkdir(&lfs, "\xff") => 0;
  4774. if (DIR) {
  4775. lfs_mkdir(&lfs, "\xff/\xff") => 0;
  4776. lfs_mkdir(&lfs, "\xff/\xff\xff") => 0;
  4777. lfs_mkdir(&lfs, "\xff/\xff\xff\xff") => 0;
  4778. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff") => 0;
  4779. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff\xff") => 0;
  4780. lfs_mkdir(&lfs, "\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4781. } else {
  4782. lfs_file_t file;
  4783. lfs_file_open(&lfs, &file, "\xff/\xff",
  4784. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4785. lfs_file_close(&lfs, &file) => 0;
  4786. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4787. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4788. lfs_file_close(&lfs, &file) => 0;
  4789. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4790. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4791. lfs_file_close(&lfs, &file) => 0;
  4792. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4793. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4794. lfs_file_close(&lfs, &file) => 0;
  4795. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4796. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4797. lfs_file_close(&lfs, &file) => 0;
  4798. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4799. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
  4800. lfs_file_close(&lfs, &file) => 0;
  4801. }
  4802. // stat paths
  4803. struct lfs_info info;
  4804. lfs_stat(&lfs, "\xff/\xff", &info) => 0;
  4805. assert(strcmp(info.name, "\xff") == 0);
  4806. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4807. lfs_stat(&lfs, "\xff/\xff\xff", &info) => 0;
  4808. assert(strcmp(info.name, "\xff\xff") == 0);
  4809. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4810. lfs_stat(&lfs, "\xff/\xff\xff\xff", &info) => 0;
  4811. assert(strcmp(info.name, "\xff\xff\xff") == 0);
  4812. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4813. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff", &info) => 0;
  4814. assert(strcmp(info.name, "\xff\xff\xff\xff") == 0);
  4815. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4816. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff", &info) => 0;
  4817. assert(strcmp(info.name, "\xff\xff\xff\xff\xff") == 0);
  4818. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4819. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff\xff", &info) => 0;
  4820. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff") == 0);
  4821. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4822. // file open paths, only works on files!
  4823. if (DIR) {
  4824. lfs_file_t file;
  4825. lfs_file_open(&lfs, &file, "\xff/\xff",
  4826. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4827. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4828. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4829. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4830. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4831. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4832. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4833. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4834. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4835. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4836. LFS_O_RDONLY) => LFS_ERR_ISDIR;
  4837. } else {
  4838. lfs_file_t file;
  4839. lfs_file_open(&lfs, &file, "\xff/\xff",
  4840. LFS_O_RDONLY) => 0;
  4841. lfs_file_close(&lfs, &file) => 0;
  4842. lfs_file_open(&lfs, &file, "\xff/\xff\xff",
  4843. LFS_O_RDONLY) => 0;
  4844. lfs_file_close(&lfs, &file) => 0;
  4845. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff",
  4846. LFS_O_RDONLY) => 0;
  4847. lfs_file_close(&lfs, &file) => 0;
  4848. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff",
  4849. LFS_O_RDONLY) => 0;
  4850. lfs_file_close(&lfs, &file) => 0;
  4851. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff",
  4852. LFS_O_RDONLY) => 0;
  4853. lfs_file_close(&lfs, &file) => 0;
  4854. lfs_file_open(&lfs, &file, "\xff/\xff\xff\xff\xff\xff\xff",
  4855. LFS_O_RDONLY) => 0;
  4856. lfs_file_close(&lfs, &file) => 0;
  4857. }
  4858. // dir open paths, only works on dirs!
  4859. if (DIR) {
  4860. lfs_dir_t dir;
  4861. lfs_dir_open(&lfs, &dir, "\xff/\xff") => 0;
  4862. lfs_dir_close(&lfs, &dir) => 0;
  4863. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff") => 0;
  4864. lfs_dir_close(&lfs, &dir) => 0;
  4865. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff") => 0;
  4866. lfs_dir_close(&lfs, &dir) => 0;
  4867. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff") => 0;
  4868. lfs_dir_close(&lfs, &dir) => 0;
  4869. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff") => 0;
  4870. lfs_dir_close(&lfs, &dir) => 0;
  4871. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4872. lfs_dir_close(&lfs, &dir) => 0;
  4873. } else {
  4874. lfs_dir_t dir;
  4875. lfs_dir_open(&lfs, &dir, "\xff/\xff") => LFS_ERR_NOTDIR;
  4876. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff") => LFS_ERR_NOTDIR;
  4877. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff") => LFS_ERR_NOTDIR;
  4878. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4879. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4880. lfs_dir_open(&lfs, &dir, "\xff/\xff\xff\xff\xff\xff\xff") => LFS_ERR_NOTDIR;
  4881. }
  4882. // rename paths
  4883. lfs_mkdir(&lfs, "\xff\xff") => 0;
  4884. lfs_rename(&lfs,
  4885. "\xff/\xff",
  4886. "\xff\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4887. lfs_rename(&lfs,
  4888. "\xff/\xff\xff",
  4889. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff") => 0;
  4890. lfs_rename(&lfs,
  4891. "\xff/\xff\xff\xff",
  4892. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4893. lfs_rename(&lfs,
  4894. "\xff/\xff\xff\xff\xff",
  4895. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4896. lfs_rename(&lfs,
  4897. "\xff/\xff\xff\xff\xff\xff",
  4898. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4899. lfs_rename(&lfs,
  4900. "\xff/\xff\xff\xff\xff\xff\xff",
  4901. "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4902. // stat paths
  4903. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff", &info) => 0;
  4904. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff") == 0);
  4905. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4906. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4907. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff") == 0);
  4908. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4909. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4910. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4911. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4912. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4913. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4914. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4915. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4916. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4917. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4918. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => 0;
  4919. assert(strcmp(info.name, "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") == 0);
  4920. assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG));
  4921. lfs_stat(&lfs, "\xff/\xff", &info) => LFS_ERR_NOENT;
  4922. lfs_stat(&lfs, "\xff/\xff\xff", &info) => LFS_ERR_NOENT;
  4923. lfs_stat(&lfs, "\xff/\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4924. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4925. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4926. lfs_stat(&lfs, "\xff/\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4927. // remove paths
  4928. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff") => 0;
  4929. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff") => 0;
  4930. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4931. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4932. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4933. lfs_remove(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff") => 0;
  4934. // stat paths
  4935. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4936. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4937. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4938. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4939. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4940. lfs_stat(&lfs, "\xff\xff/\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", &info) => LFS_ERR_NOENT;
  4941. lfs_unmount(&lfs) => 0;
  4942. '''