From bab5a53403fc4d89b0c61ccd6ce901c17fd379da Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 5 Aug 2024 10:37:38 -0700 Subject: Created test for creating/changing myriadfs file. We have a bug in the live version with a stream being truncated when wer'e not expecting it. Not sure why yet. --- src/tests/mfstest.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/tests/mfstest.cpp (limited to 'src') diff --git a/src/tests/mfstest.cpp b/src/tests/mfstest.cpp new file mode 100644 index 0000000..813ef8e --- /dev/null +++ b/src/tests/mfstest.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include + +class Obstore +{ +public: + Obstore() : + fStore("test.mfs", Bu::File::WriteNew|Bu::File::Read ), + fsOb( fStore, 1024 ) + { + } + + virtual ~Obstore() + { + } + + Bu::String getObject( const Bu::String &sPath ) + { + try + { + Bu::MyriadStream s = fsOb.open( + sPath, + Bu::MyriadFs::Read + ); + return s.readAll(); + } + catch( Bu::ExceptionBase &e ) + { + Bu::println("Exception opening file: %1").arg( e.what() ); + return Bu::String(); + } + } + + void storeObject( const Bu::String &sPath, const Bu::String &sData ) + { + for( Bu::String::const_iterator i = sPath.begin()+1; i; i++ ) + { + if( *i == '/' ) + { + Bu::String sChunk( sPath.begin(), i ); + fsOb.mkDir( sChunk, 0664 ); + } + } + try + { + Bu::MyriadStream s = fsOb.open( + sPath, + Bu::MyriadFs::Write|Bu::MyriadFs::Create|Bu::MyriadFs::Truncate + ); + s.write( sData ); + } + catch(Bu::ExceptionBase &e ) + { + Bu::println("Exception opening file: %1").arg( e.what() ); + } + } + + Bu::File fStore; + Bu::MyriadFs fsOb; +}; + +int main( int, char *[] ) +{ + Obstore os; + + os.storeObject("/killTeamState.json", "This is a json file."); + os.storeObject("/appCredentials/local", "App credentials"); + os.storeObject("/appCredentials/inckybot", "App credentials"); + os.storeObject("/appCredentials/playwith", "App credentials"); + os.storeObject("/restreamIo/users", "User data"); + os.storeObject("/youTube/users", "User data"); + os.storeObject("/topTippers.json", "{\"people\": [\"sam\", \"joe\", \"bob\"]}"); + os.storeObject("/wh40kDecks.json", ""); + + Bu::MyriadStream s = os.fsOb.open( + "/appCredentials/inckybot", + Bu::MyriadFs::Write|Bu::MyriadFs::Create|Bu::MyriadFs::Truncate + ); + s.write("Some new credentials, this is a bigger bit of data."); + + os.storeObject("/wh40kDecks.json", "{ \"op\": \"replaceDecks\", \"decks\": { \"lev\": { \"name\": \"Leviathan\", \"primary\": { \"pt\": {\"name\": \"Priority Targets\"}, \"vg\": {\"name\": \"Vital Ground\"}, \"se\": {\"name\": \"Scorched Earth\"}, \"pf\": {\"name\": \"Purge the Foe\"}, \"th\": {\"name\": \"Take and Hold\"}, \"sd\": {\"name\": \"Supply Drop\"}, \"tr\": {\"name\": \"The Ritual\"}, \"ds\": {\"name\": \"Deploy Servo-Skulls\"}, \"sp\": {\"name\": \"Sites of Power\"}, }, \"secondary\": { \"tt\": {\"name\": \"A Tempting Target\"}, \"ad\": {\"name\": \"Area Denial\"}, \"as\": {\"name\": \"Assassination\"}, \"be\": {\"name\": \"Behind Enemy Lines\"}, \"bd\": {\"name\": \"Bring It Down\"}, \"ce\": {\"name\": \"Capture Enemy Outpost\"}, \"cl\": {\"name\": \"Cleanse\"}, \"ds\": {\"name\": \"Defend Stronghold\"}, \"dt\": {\"name\": \"Deploy Teleport Homer\"}, \"ef\": {\"name\": \"Engage On All Fronts\"}, \"eb\": {\"name\": \"Extend Battle Lines\"}, \"is\": {\"name\": \"Investigate Signals\"}, \"np\": {\"name\": \"No Prisoners\"}, \"of\": {\"name\": \"Overwhelming Force\"}, \"sl\": {\"name\": \"Secure No Man’s Land\"}, \"sh\": {\"name\": \"Storm Hostile Objective\"}, }, \"gambit\": { \"dt\": {\"name\": \"Delaying Tactics\"}, \"ee\": {\"name\": \"Emergency Evacuation\"}, \"oc\": {\"name\": \"Orbital Strike Coordinates\"}, \"pp\": {\"name\": \"Proceed As Planned\"}, }, \"missionRule\": { \"cr\": {\"name\": \"Chilling Rain\"}, \"sc\": {\"name\": \"Sweep and Clear\"}, \"hs\": {\"name\": \"Hidden Supplies\"}, \"mi\": {\"name\": \"Minefields\"}, \"to\": {\"name\": \"Targets of Opportunity\"}, \"sf\": {\"name\": \"Scrambler Fields\"}, \"dr\": {\"name\": \"Delayed Reserves\"}, \"cb\": {\"name\": \"Chosen Battlefield\"}, \"mb\": {\"name\": \"Maelstrom of Battle\"}, \"sl\": {\"name\": \"Supply Lines\"}, \"si\": {\"name\": \"Secret Intel\"}, \"vs\": {\"name\": \"Vox Static\"}, }, }, } }"); + os.storeObject("/wh40kState.json", "{\"cards\": \"hello\"}"); + + return 0; +} + -- cgit v1.2.3