filesystem.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. -- love.filesystem
  2. --------------------------------------------------------------------------------
  3. --------------------------------------------------------------------------------
  4. ------------------------------------OBJECTS-------------------------------------
  5. --------------------------------------------------------------------------------
  6. --------------------------------------------------------------------------------
  7. -- File (love.filesystem.newFile)
  8. love.test.filesystem.File = function(test)
  9. -- setup a file to play with
  10. local file1 = love.filesystem.openFile('data.txt', 'w')
  11. file1:write('helloworld')
  12. test:assertObject(file1)
  13. file1:close()
  14. -- test read mode
  15. file1:open('r')
  16. test:assertEquals('r', file1:getMode(), 'check read mode')
  17. local contents, size = file1:read()
  18. test:assertEquals('helloworld', contents)
  19. test:assertEquals(10, size, 'check file read')
  20. test:assertEquals(10, file1:getSize())
  21. local ok1, err1 = file1:write('hello')
  22. test:assertNotEquals(nil, err1, 'check cant write in read mode')
  23. local iterator = file1:lines()
  24. test:assertNotEquals(nil, iterator, 'check can read lines')
  25. test:assertEquals('data.txt', file1:getFilename(), 'check filename matches')
  26. file1:close()
  27. -- test write mode
  28. file1:open('w')
  29. test:assertEquals('w', file1:getMode(), 'check write mode')
  30. contents, size = file1:read()
  31. test:assertEquals(nil, contents, 'check cant read file in write mode')
  32. test:assertEquals('string', type(size), 'check err message shown')
  33. local ok2, err2 = file1:write('helloworld')
  34. test:assertTrue(ok2, 'check file write')
  35. test:assertEquals(nil, err2, 'check no err writing')
  36. -- test open/closing
  37. file1:open('r')
  38. test:assertTrue(file1:isOpen(), 'check file is open')
  39. file1:close()
  40. test:assertFalse(file1:isOpen(), 'check file gets closed')
  41. file1:close()
  42. -- test buffering and flushing
  43. file1:open('w')
  44. local ok3, err3 = file1:setBuffer('full', 10000)
  45. test:assertTrue(ok3)
  46. test:assertEquals('full', file1:getBuffer())
  47. file1:write('replacedcontent')
  48. file1:flush()
  49. file1:close()
  50. file1:open('r')
  51. contents, size = file1:read()
  52. test:assertEquals('replacedcontent', contents, 'check buffered content was written')
  53. file1:close()
  54. -- loop through file data with seek/tell until EOF
  55. file1:open('r')
  56. local counter = 0
  57. for i=1,100 do
  58. file1:seek(i)
  59. test:assertEquals(i, file1:tell())
  60. if file1:isEOF() == true then
  61. counter = i
  62. break
  63. end
  64. end
  65. test:assertEquals(counter, 15)
  66. file1:close()
  67. end
  68. -- FileData (love.filesystem.newFileData)
  69. love.test.filesystem.FileData = function(test)
  70. -- create new obj
  71. local fdata = love.filesystem.newFileData('helloworld', 'test.txt')
  72. test:assertObject(fdata)
  73. test:assertEquals('test.txt', fdata:getFilename())
  74. test:assertEquals('txt', fdata:getExtension())
  75. -- check properties match expected
  76. test:assertEquals('helloworld', fdata:getString(), 'check data string')
  77. test:assertEquals(10, fdata:getSize(), 'check data size')
  78. -- check cloning the bytedata
  79. local clonedfdata = fdata:clone()
  80. test:assertObject(clonedfdata)
  81. test:assertEquals('helloworld', clonedfdata:getString(), 'check cloned data')
  82. test:assertEquals(10, clonedfdata:getSize(), 'check cloned size')
  83. end
  84. --------------------------------------------------------------------------------
  85. --------------------------------------------------------------------------------
  86. ------------------------------------METHODS-------------------------------------
  87. --------------------------------------------------------------------------------
  88. --------------------------------------------------------------------------------
  89. -- love.filesystem.append
  90. love.test.filesystem.append = function(test)
  91. -- create a new file to test with
  92. love.filesystem.write('filesystem.append.txt', 'foo')
  93. -- try appending text and check new file contents/size matches
  94. local success, message = love.filesystem.append('filesystem.append.txt', 'bar')
  95. test:assertNotEquals(false, success, 'check success')
  96. test:assertEquals(nil, message, 'check no error msg')
  97. local contents, size = love.filesystem.read('filesystem.append.txt')
  98. test:assertEquals(contents, 'foobar', 'check file contents')
  99. test:assertEquals(size, 6, 'check file size')
  100. -- check appending a specific no. of bytes
  101. love.filesystem.append('filesystem.append.txt', 'foobarfoobarfoo', 6)
  102. contents, size = love.filesystem.read('filesystem.append.txt')
  103. test:assertEquals(contents, 'foobarfoobar', 'check appended contents')
  104. test:assertEquals(size, 12, 'check appended size')
  105. -- cleanup
  106. love.filesystem.remove('filesystem.append.txt')
  107. end
  108. -- love.filesystem.areSymlinksEnabled
  109. -- @NOTE best can do here is just check not nil
  110. love.test.filesystem.areSymlinksEnabled = function(test)
  111. test:assertNotNil(love.filesystem.areSymlinksEnabled())
  112. end
  113. -- love.filesystem.createDirectory
  114. love.test.filesystem.createDirectory = function(test)
  115. -- try creating a dir + subdir and check both exist
  116. local success = love.filesystem.createDirectory('foo/bar')
  117. test:assertNotEquals(false, success, 'check success')
  118. test:assertNotEquals(nil, love.filesystem.getInfo('foo', 'directory'), 'check directory created')
  119. test:assertNotEquals(nil, love.filesystem.getInfo('foo/bar', 'directory'), 'check subdirectory created')
  120. -- cleanup
  121. love.filesystem.remove('foo/bar')
  122. love.filesystem.remove('foo')
  123. end
  124. -- love.filesystem.getAppdataDirectory
  125. -- @NOTE i think this is too platform dependent to be tested nicely
  126. love.test.filesystem.getAppdataDirectory = function(test)
  127. test:assertNotNil(love.filesystem.getAppdataDirectory())
  128. end
  129. -- love.filesystem.getCRequirePath
  130. love.test.filesystem.getCRequirePath = function(test)
  131. -- check default value from documentation
  132. test:assertEquals('??', love.filesystem.getCRequirePath(), 'check default value')
  133. end
  134. -- love.filesystem.getDirectoryItems
  135. love.test.filesystem.getDirectoryItems = function(test)
  136. -- create a dir + subdir with 2 files
  137. love.filesystem.createDirectory('foo/bar')
  138. love.filesystem.write('foo/file1.txt', 'file1')
  139. love.filesystem.write('foo/bar/file2.txt', 'file2')
  140. -- check both the file + subdir exist in the item list
  141. local files = love.filesystem.getDirectoryItems('foo')
  142. local hasfile = false
  143. local hasdir = false
  144. for _,v in ipairs(files) do
  145. local info = love.filesystem.getInfo('foo/'..v)
  146. if v == 'bar' and info.type == 'directory' then hasdir = true end
  147. if v == 'file1.txt' and info.type == 'file' then hasfile = true end
  148. end
  149. test:assertTrue(hasfile, 'check file exists')
  150. test:assertTrue(hasdir, 'check directory exists')
  151. -- cleanup
  152. love.filesystem.remove('foo/file1.txt')
  153. love.filesystem.remove('foo/bar/file2.txt')
  154. love.filesystem.remove('foo/bar')
  155. love.filesystem.remove('foo')
  156. end
  157. -- love.filesystem.getFullCommonPath
  158. love.test.filesystem.getFullCommonPath = function(test)
  159. -- check standard paths
  160. local appsavedir = love.filesystem.getFullCommonPath('appsavedir')
  161. local appdocuments = love.filesystem.getFullCommonPath('appdocuments')
  162. local userhome = love.filesystem.getFullCommonPath('userhome')
  163. local userappdata = love.filesystem.getFullCommonPath('userappdata')
  164. local userdesktop = love.filesystem.getFullCommonPath('userdesktop')
  165. local userdocuments = love.filesystem.getFullCommonPath('userdocuments')
  166. test:assertNotNil(appsavedir)
  167. test:assertNotNil(appdocuments)
  168. test:assertNotNil(userhome)
  169. test:assertNotNil(userappdata)
  170. test:assertNotNil(userdesktop)
  171. test:assertNotNil(userdocuments)
  172. -- check invalid path
  173. local ok = pcall(love.filesystem.getFullCommonPath, 'fakepath')
  174. test:assertFalse(ok, 'check invalid common path')
  175. end
  176. -- love.filesystem.getIdentity
  177. love.test.filesystem.getIdentity = function(test)
  178. -- check setting identity matches
  179. local original = love.filesystem.getIdentity()
  180. love.filesystem.setIdentity('lover')
  181. test:assertEquals('lover', love.filesystem.getIdentity(), 'check identity matches')
  182. -- put back to original value
  183. love.filesystem.setIdentity(original)
  184. end
  185. -- love.filesystem.getRealDirectory
  186. love.test.filesystem.getRealDirectory = function(test)
  187. -- make a test dir + file first
  188. love.filesystem.createDirectory('foo')
  189. love.filesystem.write('foo/test.txt', 'test')
  190. -- check save dir matches the real dir we just wrote to
  191. test:assertEquals(love.filesystem.getSaveDirectory(),
  192. love.filesystem.getRealDirectory('foo/test.txt'), 'check directory matches')
  193. -- cleanup
  194. love.filesystem.remove('foo/test.txt')
  195. love.filesystem.remove('foo')
  196. end
  197. -- love.filesystem.getRequirePath
  198. love.test.filesystem.getRequirePath = function(test)
  199. test:assertEquals('?.lua;?/init.lua',
  200. love.filesystem.getRequirePath(), 'check default value')
  201. end
  202. -- love.filesystem.getSource
  203. -- @NOTE i dont think we can test this cos love calls it first
  204. love.test.filesystem.getSource = function(test)
  205. test:skipTest('used internally')
  206. end
  207. -- love.filesystem.getSourceBaseDirectory
  208. -- @NOTE i think this is too platform dependent to be tested nicely
  209. love.test.filesystem.getSourceBaseDirectory = function(test)
  210. test:assertNotNil(love.filesystem.getSourceBaseDirectory())
  211. end
  212. -- love.filesystem.getUserDirectory
  213. -- @NOTE i think this is too platform dependent to be tested nicely
  214. love.test.filesystem.getUserDirectory = function(test)
  215. test:assertNotNil(love.filesystem.getUserDirectory())
  216. end
  217. -- love.filesystem.getWorkingDirectory
  218. -- @NOTE i think this is too platform dependent to be tested nicely
  219. love.test.filesystem.getWorkingDirectory = function(test)
  220. test:assertNotNil(love.filesystem.getWorkingDirectory())
  221. end
  222. -- love.filesystem.getSaveDirectory
  223. -- @NOTE i think this is too platform dependent to be tested nicely
  224. love.test.filesystem.getSaveDirectory = function(test)
  225. test:assertNotNil(love.filesystem.getSaveDirectory())
  226. end
  227. -- love.filesystem.getInfo
  228. love.test.filesystem.getInfo = function(test)
  229. -- create a dir and subdir with a file
  230. love.filesystem.createDirectory('foo/bar')
  231. love.filesystem.write('foo/bar/file2.txt', 'file2')
  232. -- check getinfo returns the correct values
  233. test:assertEquals(nil, love.filesystem.getInfo('foo/bar/file2.txt', 'directory'), 'check not directory')
  234. test:assertNotEquals(nil, love.filesystem.getInfo('foo/bar/file2.txt'), 'check info not nil')
  235. test:assertEquals(love.filesystem.getInfo('foo/bar/file2.txt').size, 5, 'check info size match')
  236. test:assertFalse(love.filesystem.getInfo('foo/bar/file2.txt').readonly, 'check readonly')
  237. -- @TODO test modified timestamp from info.modtime?
  238. -- cleanup
  239. love.filesystem.remove('foo/bar/file2.txt')
  240. love.filesystem.remove('foo/bar')
  241. love.filesystem.remove('foo')
  242. end
  243. -- love.filesystem.isFused
  244. love.test.filesystem.isFused = function(test)
  245. -- kinda assuming you'd run the testsuite in a non-fused game
  246. test:assertEquals(love.filesystem.isFused(), false, 'check not fused')
  247. end
  248. -- love.filesystem.lines
  249. love.test.filesystem.lines = function(test)
  250. -- check lines returns the 3 lines expected
  251. love.filesystem.write('file.txt', 'line1\nline2\nline3')
  252. local linenum = 1
  253. for line in love.filesystem.lines('file.txt') do
  254. test:assertEquals('line' .. tostring(linenum), line, 'check line matches')
  255. -- also check it removes newlines like the docs says it does
  256. test:assertEquals(nil, string.find(line, '\n'), 'check newline removed')
  257. linenum = linenum + 1
  258. end
  259. -- cleanup
  260. love.filesystem.remove('file.txt')
  261. end
  262. -- love.filesystem.load
  263. love.test.filesystem.load = function(test)
  264. -- setup some fake lua files
  265. love.filesystem.write('test1.lua', 'function test()\nreturn 1\nend\nreturn test()')
  266. love.filesystem.write('test2.lua', 'function test()\nreturn 1')
  267. if test:isAtLeastLuaVersion(5.2) or test:isLuaJITEnabled() then
  268. -- check file that doesn't exist
  269. local chunk1, errormsg1 = love.filesystem.load('faker.lua', 'b')
  270. test:assertEquals(nil, chunk1, 'check file doesnt exist')
  271. -- check valid lua file (text load)
  272. local chunk2, errormsg2 = love.filesystem.load('test1.lua', 't')
  273. test:assertEquals(nil, errormsg2, 'check no error message')
  274. test:assertEquals(1, chunk2(), 'check lua file runs')
  275. else
  276. local _, errormsg3 = love.filesystem.load('test1.lua', 'b')
  277. test:assertNotEquals(nil, errormsg3, 'check for an error message')
  278. local _, errormsg4 = love.filesystem.load('test1.lua', 't')
  279. test:assertNotEquals(nil, errormsg4, 'check for an error message')
  280. end
  281. -- check valid lua file (any load)
  282. local chunk5, errormsg5 = love.filesystem.load('test1.lua', 'bt')
  283. test:assertEquals(nil, errormsg5, 'check no error message')
  284. test:assertEquals(1, chunk5(), 'check lua file runs')
  285. -- check invalid lua file
  286. local ok, chunk, err = pcall(love.filesystem.load, 'test2.lua')
  287. test:assertFalse(ok, 'check invalid lua file')
  288. -- cleanup
  289. love.filesystem.remove('test1.lua')
  290. love.filesystem.remove('test2.lua')
  291. end
  292. -- love.filesystem.mount
  293. love.test.filesystem.mount = function(test)
  294. -- write an example zip to savedir to use
  295. local contents, size = love.filesystem.read('resources/test.zip') -- contains test.txt
  296. love.filesystem.write('test.zip', contents, size)
  297. -- check mounting file and check contents are mounted
  298. local success = love.filesystem.mount('test.zip', 'test')
  299. test:assertTrue(success, 'check success')
  300. test:assertNotEquals(nil, love.filesystem.getInfo('test'), 'check mount not nil')
  301. test:assertEquals('directory', love.filesystem.getInfo('test').type, 'check directory made')
  302. test:assertNotEquals(nil, love.filesystem.getInfo('test/test.txt'), 'check file not nil')
  303. test:assertEquals('file', love.filesystem.getInfo('test/test.txt').type, 'check file type')
  304. -- cleanup
  305. love.filesystem.remove('test/test.txt')
  306. love.filesystem.remove('test')
  307. love.filesystem.remove('test.zip')
  308. end
  309. -- love.filesystem.mountFullPath
  310. love.test.filesystem.mountFullPath = function(test)
  311. -- mount something in the working directory
  312. local mount = love.filesystem.mountFullPath(love.filesystem.getSource() .. '/tests', 'tests', 'read')
  313. test:assertTrue(mount, 'check can mount')
  314. -- check reading file through mounted path label
  315. local contents, _ = love.filesystem.read('tests/audio.lua')
  316. test:assertNotEquals(nil, contents)
  317. local unmount = love.filesystem.unmountFullPath(love.filesystem.getSource() .. '/tests')
  318. test:assertTrue(unmount, 'reset mount')
  319. end
  320. -- love.filesystem.unmountFullPath
  321. love.test.filesystem.unmountFullPath = function(test)
  322. -- try unmounting something we never mounted
  323. local unmount1 = love.filesystem.unmountFullPath(love.filesystem.getSource() .. '/faker')
  324. test:assertFalse(unmount1, 'check not mounted to start with')
  325. -- mount something to unmount after
  326. love.filesystem.mountFullPath(love.filesystem.getSource() .. '/tests', 'tests', 'read')
  327. local unmount2 = love.filesystem.unmountFullPath(love.filesystem.getSource() .. '/tests')
  328. test:assertTrue(unmount2, 'check unmounted')
  329. end
  330. -- love.filesystem.mountCommonPath
  331. love.test.filesystem.mountCommonPath = function(test)
  332. -- check if we can mount all the expected paths
  333. local mount1 = love.filesystem.mountCommonPath('appsavedir', 'appsavedir', 'readwrite')
  334. local mount2 = love.filesystem.mountCommonPath('appdocuments', 'appdocuments', 'readwrite')
  335. local mount3 = love.filesystem.mountCommonPath('userhome', 'userhome', 'readwrite')
  336. local mount4 = love.filesystem.mountCommonPath('userappdata', 'userappdata', 'readwrite')
  337. -- userdesktop isnt valid on linux
  338. if not test:isOS('Linux') then
  339. local mount5 = love.filesystem.mountCommonPath('userdesktop', 'userdesktop', 'readwrite')
  340. test:assertTrue(mount5, 'check mount userdesktop')
  341. end
  342. local mount6 = love.filesystem.mountCommonPath('userdocuments', 'userdocuments', 'readwrite')
  343. local ok = pcall(love.filesystem.mountCommonPath, 'fakepath', 'fake', 'readwrite')
  344. test:assertTrue(mount1, 'check mount appsavedir')
  345. test:assertTrue(mount2, 'check mount appdocuments')
  346. test:assertTrue(mount3, 'check mount userhome')
  347. test:assertTrue(mount4, 'check mount userappdata')
  348. test:assertTrue(mount6, 'check mount userdocuments')
  349. test:assertFalse(ok, 'check mount invalid common path fails')
  350. end
  351. -- love.filesystem.unmountCommonPath
  352. --love.test.filesystem.unmountCommonPath = function(test)
  353. -- -- check unmounting invalid
  354. -- local ok = pcall(love.filesystem.unmountCommonPath, 'fakepath')
  355. -- test:assertFalse(ok, 'check unmount invalid common path')
  356. -- -- check mounting valid paths
  357. -- love.filesystem.mountCommonPath('appsavedir', 'appsavedir', 'read')
  358. -- love.filesystem.mountCommonPath('appdocuments', 'appdocuments', 'read')
  359. -- love.filesystem.mountCommonPath('userhome', 'userhome', 'read')
  360. -- love.filesystem.mountCommonPath('userappdata', 'userappdata', 'read')
  361. -- love.filesystem.mountCommonPath('userdesktop', 'userdesktop', 'read')
  362. -- love.filesystem.mountCommonPath('userdocuments', 'userdocuments', 'read')
  363. -- local unmount1 = love.filesystem.unmountCommonPath('appsavedir')
  364. -- local unmount2 = love.filesystem.unmountCommonPath('appdocuments')
  365. -- local unmount3 = love.filesystem.unmountCommonPath('userhome')
  366. -- local unmount4 = love.filesystem.unmountCommonPath('userappdata')
  367. -- local unmount5 = love.filesystem.unmountCommonPath('userdesktop')
  368. -- local unmount6 = love.filesystem.unmountCommonPath('userdocuments')
  369. -- test:assertTrue(unmount1, 'check unmount appsavedir')
  370. -- test:assertTrue(unmount2, 'check unmount appdocuments')
  371. -- test:assertTrue(unmount3, 'check unmount userhome')
  372. -- test:assertTrue(unmount4, 'check unmount userappdata')
  373. -- test:assertTrue(unmount5, 'check unmount userdesktop')
  374. -- test:assertTrue(unmount6, 'check unmount userdocuments')
  375. -- -- remount or future tests fail
  376. -- love.filesystem.mountCommonPath('appsavedir', 'appsavedir', 'readwrite')
  377. -- love.filesystem.mountCommonPath('appdocuments', 'appdocuments', 'readwrite')
  378. -- love.filesystem.mountCommonPath('userhome', 'userhome', 'readwrite')
  379. -- love.filesystem.mountCommonPath('userappdata', 'userappdata', 'readwrite')
  380. -- love.filesystem.mountCommonPath('userdesktop', 'userdesktop', 'readwrite')
  381. -- love.filesystem.mountCommonPath('userdocuments', 'userdocuments', 'readwrite')
  382. --end
  383. -- love.filesystem.openFile
  384. -- @NOTE this is just basic nil checking, objs have their own test method
  385. love.test.filesystem.openFile = function(test)
  386. test:assertNotNil(love.filesystem.openFile('file2.txt', 'w'))
  387. test:assertNotNil(love.filesystem.openFile('file2.txt', 'r'))
  388. test:assertNotNil(love.filesystem.openFile('file2.txt', 'a'))
  389. test:assertNotNil(love.filesystem.openFile('file2.txt', 'c'))
  390. love.filesystem.remove('file2.txt')
  391. end
  392. -- love.filesystem.newFileData
  393. -- @NOTE this is just basic nil checking, objs have their own test method
  394. love.test.filesystem.newFileData = function(test)
  395. test:assertNotNil(love.filesystem.newFileData('helloworld', 'file1'))
  396. end
  397. -- love.filesystem.read
  398. love.test.filesystem.read = function(test)
  399. -- check reading a full file
  400. local content, size = love.filesystem.read('resources/test.txt')
  401. test:assertNotEquals(nil, content, 'check not nil')
  402. test:assertEquals('helloworld', content, 'check content match')
  403. test:assertEquals(10, size, 'check size match')
  404. -- check reading partial file
  405. content, size = love.filesystem.read('resources/test.txt', 5)
  406. test:assertNotEquals(nil, content, 'check not nil')
  407. test:assertEquals('hello', content, 'check content match')
  408. test:assertEquals(5, size, 'check size match')
  409. end
  410. -- love.filesystem.remove
  411. love.test.filesystem.remove = function(test)
  412. -- create a dir + subdir with a file
  413. love.filesystem.createDirectory('foo/bar')
  414. love.filesystem.write('foo/bar/file2.txt', 'helloworld')
  415. -- check removing files + dirs (should fail to remove dir if file inside)
  416. test:assertFalse(love.filesystem.remove('foo'), 'check fail when file inside')
  417. test:assertFalse(love.filesystem.remove('foo/bar'), 'check fail when file inside')
  418. test:assertTrue(love.filesystem.remove('foo/bar/file2.txt'), 'check file removed')
  419. test:assertTrue(love.filesystem.remove('foo/bar'), 'check subdirectory removed')
  420. test:assertTrue(love.filesystem.remove('foo'), 'check directory removed')
  421. -- cleanup not needed here hopefully...
  422. end
  423. -- love.filesystem.setCRequirePath
  424. love.test.filesystem.setCRequirePath = function(test)
  425. -- check setting path val is returned
  426. love.filesystem.setCRequirePath('/??')
  427. test:assertEquals('/??', love.filesystem.getCRequirePath(), 'check crequirepath value')
  428. love.filesystem.setCRequirePath('??')
  429. end
  430. -- love.filesystem.setIdentity
  431. love.test.filesystem.setIdentity = function(test)
  432. -- check setting identity val is returned
  433. local original = love.filesystem.getIdentity()
  434. love.filesystem.setIdentity('lover')
  435. test:assertEquals('lover', love.filesystem.getIdentity(), 'check indentity value')
  436. -- return value to original
  437. love.filesystem.setIdentity(original)
  438. end
  439. -- love.filesystem.setRequirePath
  440. love.test.filesystem.setRequirePath = function(test)
  441. -- check setting path val is returned
  442. love.filesystem.setRequirePath('?.lua;?/start.lua')
  443. test:assertEquals('?.lua;?/start.lua', love.filesystem.getRequirePath(), 'check require path')
  444. -- reset to default
  445. love.filesystem.setRequirePath('?.lua;?/init.lua')
  446. end
  447. -- love.filesystem.setSource
  448. love.test.filesystem.setSource = function(test)
  449. test:skipTest('used internally')
  450. end
  451. -- love.filesystem.unmount
  452. love.test.filesystem.unmount = function(test)
  453. -- create a zip file mounted to use
  454. local contents, size = love.filesystem.read('resources/test.zip') -- contains test.txt
  455. love.filesystem.write('test.zip', contents, size)
  456. love.filesystem.mount('test.zip', 'test')
  457. -- check mounted, unmount, then check its unmounted
  458. test:assertNotEquals(nil, love.filesystem.getInfo('test/test.txt'), 'check mount exists')
  459. love.filesystem.unmount('test.zip')
  460. test:assertEquals(nil, love.filesystem.getInfo('test/test.txt'), 'check unmounted')
  461. -- cleanup
  462. love.filesystem.remove('test/test.txt')
  463. love.filesystem.remove('test')
  464. love.filesystem.remove('test.zip')
  465. end
  466. -- love.filesystem.write
  467. love.test.filesystem.write = function(test)
  468. -- check writing a bunch of files matches whats read back
  469. love.filesystem.write('test1.txt', 'helloworld')
  470. love.filesystem.write('test2.txt', 'helloworld', 10)
  471. love.filesystem.write('test3.txt', 'helloworld', 5)
  472. test:assertEquals('helloworld', love.filesystem.read('test1.txt'), 'check read file')
  473. test:assertEquals('helloworld', love.filesystem.read('test2.txt'), 'check read all')
  474. test:assertEquals('hello', love.filesystem.read('test3.txt'), 'check read partial')
  475. -- cleanup
  476. love.filesystem.remove('test1.txt')
  477. love.filesystem.remove('test2.txt')
  478. love.filesystem.remove('test3.txt')
  479. end