@@ -25,6 +25,10 @@ Index of this file:
2525#define PL_MATH_INCLUDE_FUNCTIONS
2626#include "pl_math.h"
2727#include "pl_json.h"
28+ #include "pl_string.h"
29+
30+ // stable extensions
31+ #include "pl_platform_ext.h"
2832
2933// unstable extensions
3034#include "pl_collision_ext.h"
@@ -44,6 +48,7 @@ const plDateTimeI* gptDateTime = NULL;
4448const plVfsI * gptVfs = NULL ;
4549const plPakI * gptPak = NULL ;
4650const plCompressI * gptCompress = NULL ;
51+ const plFileI * gptFile = NULL ;
4752
4853#define PL_ALLOC (x ) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
4954#define PL_REALLOC (x , y ) gptMemory->tracked_realloc((x), (y), __FILE__, __LINE__)
@@ -70,6 +75,7 @@ typedef struct _plAppData
7075void collision_only_tests_0 (void * );
7176void datetime_tests_0 (void * );
7277void vfs_tests_0 (void * );
78+ void file_tests_0 (void * );
7379
7480//-----------------------------------------------------------------------------
7581// [SECTION] pl_app_info
@@ -170,6 +176,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
170176 gptVfs = pl_get_api_latest (ptApiRegistry , plVfsI );
171177 gptPak = pl_get_api_latest (ptApiRegistry , plPakI );
172178 gptCompress = pl_get_api_latest (ptApiRegistry , plCompressI );
179+ gptFile = pl_get_api_latest (ptApiRegistry , plFileI );
173180
174181 // this path is taken only during first load, so we
175182 // allocate app memory here
@@ -179,6 +186,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
179186 // mount some directories
180187 gptVfs -> mount_directory ("/testing" , "../out" , PL_VFS_MOUNT_FLAGS_NONE );
181188 gptVfs -> mount_memory ("/ram" , PL_VFS_MOUNT_FLAGS_NONE );
189+ gptVfs -> mount_memory ("/" , PL_VFS_MOUNT_FLAGS_NONE );
182190
183191 plPakFile * ptPak = NULL ;
184192 gptPak -> begin_packing ("../out/testing.pak" , 1 , & ptPak );
@@ -200,6 +208,8 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
200208 gptVfs -> close_file (tHandle );
201209 tHandle = gptVfs -> open_file ("/ram/testing_compressed.json" , PL_VFS_FILE_MODE_WRITE );
202210 szFileSize = gptVfs -> write_file (tHandle , puBuffer , szFileSize );
211+ tHandle = gptVfs -> open_file ("/testing_compressed.json" , PL_VFS_FILE_MODE_WRITE );
212+ szFileSize = gptVfs -> write_file (tHandle , puBuffer , szFileSize );
203213 free (puBuffer );
204214
205215 // create
@@ -220,6 +230,9 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
220230 pl_test_register_test (vfs_tests_0 , ptAppData );
221231 pl_test_run_suite ("pl_vfs_ext.h" );
222232
233+ pl_test_register_test (file_tests_0 , ptAppData );
234+ pl_test_run_suite ("pl_platform_ext.h (plFileI)" );
235+
223236 return ptAppData ;
224237}
225238
@@ -379,16 +392,22 @@ vfs_tests_0(void* pAppData)
379392 gptVfs -> close_file (tHandle );
380393
381394
382- const char * acFiles [3 ] = {
395+ const char * acFiles [] = {
383396 "/ram/testing_compressed.json" ,
384397 "/data/testing_compressed.json" ,
385398 "/data/testing_uncompressed.json" ,
399+ "/testing_compressed.json" ,
386400 };
387401
388- for (uint32_t i = 0 ; i < 3 ; i ++ )
402+ for (uint32_t i = 0 ; i < 4 ; i ++ )
389403 {
390404
391405 size_t szFileSize = gptVfs -> get_file_size_str (acFiles [i ]);
406+ if (szFileSize == 0 )
407+ {
408+ pl_test_expect_true (false, NULL );
409+ continue ;
410+ }
392411 tHandle = gptVfs -> open_file (acFiles [i ], PL_VFS_FILE_MODE_READ );
393412 char * pucBuffer = PL_ALLOC (szFileSize + 1 );
394413 memset (pucBuffer , 0 , szFileSize + 1 );
@@ -492,6 +511,48 @@ vfs_tests_0(void* pAppData)
492511 }
493512}
494513
514+ void
515+ file_tests_0 (void * pAppData )
516+ {
517+
518+ const char * * sbcFiles = NULL ;
519+ pl_sb_push (sbcFiles , "pl_ds.h" );
520+ pl_sb_push (sbcFiles , "pl_json.h" );
521+ pl_sb_push (sbcFiles , "pl_log.h" );
522+ pl_sb_push (sbcFiles , "pl_math.h" );
523+ pl_sb_push (sbcFiles , "pl_memory.h" );
524+ pl_sb_push (sbcFiles , "pl_profile.h" );
525+ pl_sb_push (sbcFiles , "pl_stl.h" );
526+ pl_sb_push (sbcFiles , "pl_string.h" );
527+ pl_sb_push (sbcFiles , "pl_test.h" );
528+
529+ plDirectoryInfo tInfo = {0 };
530+ gptFile -> get_directory_info ("../libs" , & tInfo );
531+
532+ pl_test_expect_uint32_equal (tInfo .uEntryCount , pl_sb_size (sbcFiles ), NULL );
533+
534+ bool bFindMath = false;
535+ uint32_t uMathIndex = 0 ;
536+ for (uint32_t i = 0 ; i < tInfo .uEntryCount ; i ++ )
537+ {
538+
539+ if (pl_str_equal (tInfo .sbtEntries [i ].acName , "pl_math.h" ))
540+ {
541+ bFindMath = true;
542+ uMathIndex = i ;
543+ break ;
544+ }
545+ }
546+ pl_test_expect_true (bFindMath , NULL );
547+ pl_test_expect_true (tInfo .sbtEntries [uMathIndex ].tType == PL_DIRECTORY_ENTRY_TYPE_FILE , NULL );
548+
549+ gptFile -> cleanup_directory_info (& tInfo );
550+ pl_sb_free (sbcFiles );
551+
552+ pl_test_expect_true (gptFile -> directory_exists ("../libs" ), NULL );
553+ pl_test_expect_false (gptFile -> directory_exists ("../libs-offset" ), NULL );
554+ }
555+
495556//-----------------------------------------------------------------------------
496557// [SECTION] unity build
497558//-----------------------------------------------------------------------------
@@ -502,3 +563,6 @@ vfs_tests_0(void* pAppData)
502563
503564#define PL_JSON_IMPLEMENTATION
504565#include "pl_json.h"
566+
567+ #define PL_STRING_IMPLEMENTATION
568+ #include "pl_string.h"
0 commit comments