aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2024-08-05 10:37:38 -0700
committerMike Buland <mike@xagasoft.com>2024-08-05 10:37:38 -0700
commitbab5a53403fc4d89b0c61ccd6ce901c17fd379da (patch)
tree1e54dc8b6cce3c812b8f41c19b471d870db353f1 /src
parent55d1370f2464a817d7e51cedc26cd7ea6ac78814 (diff)
downloadlibbu++-bab5a53403fc4d89b0c61ccd6ce901c17fd379da.tar.gz
libbu++-bab5a53403fc4d89b0c61ccd6ce901c17fd379da.tar.bz2
libbu++-bab5a53403fc4d89b0c61ccd6ce901c17fd379da.tar.xz
libbu++-bab5a53403fc4d89b0c61ccd6ce901c17fd379da.zip
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.
Diffstat (limited to '')
-rw-r--r--src/tests/mfstest.cpp88
1 files changed, 88 insertions, 0 deletions
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 @@
1#include <bu/file.h>
2#include <bu/myriadfs.h>
3#include <bu/myriadstream.h>
4#include <bu/sio.h>
5
6class Obstore
7{
8public:
9 Obstore() :
10 fStore("test.mfs", Bu::File::WriteNew|Bu::File::Read ),
11 fsOb( fStore, 1024 )
12 {
13 }
14
15 virtual ~Obstore()
16 {
17 }
18
19 Bu::String getObject( const Bu::String &sPath )
20 {
21 try
22 {
23 Bu::MyriadStream s = fsOb.open(
24 sPath,
25 Bu::MyriadFs::Read
26 );
27 return s.readAll();
28 }
29 catch( Bu::ExceptionBase &e )
30 {
31 Bu::println("Exception opening file: %1").arg( e.what() );
32 return Bu::String();
33 }
34 }
35
36 void storeObject( const Bu::String &sPath, const Bu::String &sData )
37 {
38 for( Bu::String::const_iterator i = sPath.begin()+1; i; i++ )
39 {
40 if( *i == '/' )
41 {
42 Bu::String sChunk( sPath.begin(), i );
43 fsOb.mkDir( sChunk, 0664 );
44 }
45 }
46 try
47 {
48 Bu::MyriadStream s = fsOb.open(
49 sPath,
50 Bu::MyriadFs::Write|Bu::MyriadFs::Create|Bu::MyriadFs::Truncate
51 );
52 s.write( sData );
53 }
54 catch(Bu::ExceptionBase &e )
55 {
56 Bu::println("Exception opening file: %1").arg( e.what() );
57 }
58 }
59
60 Bu::File fStore;
61 Bu::MyriadFs fsOb;
62};
63
64int main( int, char *[] )
65{
66 Obstore os;
67
68 os.storeObject("/killTeamState.json", "This is a json file.");
69 os.storeObject("/appCredentials/local", "App credentials");
70 os.storeObject("/appCredentials/inckybot", "App credentials");
71 os.storeObject("/appCredentials/playwith", "App credentials");
72 os.storeObject("/restreamIo/users", "User data");
73 os.storeObject("/youTube/users", "User data");
74 os.storeObject("/topTippers.json", "{\"people\": [\"sam\", \"joe\", \"bob\"]}");
75 os.storeObject("/wh40kDecks.json", "");
76
77 Bu::MyriadStream s = os.fsOb.open(
78 "/appCredentials/inckybot",
79 Bu::MyriadFs::Write|Bu::MyriadFs::Create|Bu::MyriadFs::Truncate
80 );
81 s.write("Some new credentials, this is a bigger bit of data.");
82
83 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\"}, }, }, } }");
84 os.storeObject("/wh40kState.json", "{\"cards\": \"hello\"}");
85
86 return 0;
87}
88