aboutsummaryrefslogtreecommitdiff
path: root/src/tests/mfstest.cpp
blob: 813ef8e1de1481665ae054edb8f8ec467cb172db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <bu/file.h>
#include <bu/myriadfs.h>
#include <bu/myriadstream.h>
#include <bu/sio.h>

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;
}