From f1e3f25d9b7a12cdedb99e4cb0bfa66157a1a972 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 27 Aug 2024 13:37:36 -0700 Subject: Making progress. --- src/tests/bigmyriad.cpp | 8 +- src/tests/cache.cpp | 289 ------------------------------------------------ src/tests/cachedel.cpp | 288 ----------------------------------------------- src/tests/mfstest.cpp | 88 --------------- src/tests/myriadfs.cpp | 62 ----------- 5 files changed, 4 insertions(+), 731 deletions(-) delete mode 100644 src/tests/cache.cpp delete mode 100644 src/tests/cachedel.cpp delete mode 100644 src/tests/mfstest.cpp delete mode 100644 src/tests/myriadfs.cpp (limited to 'src/tests') diff --git a/src/tests/bigmyriad.cpp b/src/tests/bigmyriad.cpp index 9af301c..21c5ff2 100644 --- a/src/tests/bigmyriad.cpp +++ b/src/tests/bigmyriad.cpp @@ -5,17 +5,17 @@ int main() { Bu::File f("big.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create ); - Bu::Myriad m( f, 2048 ); + Bu::Myriad m( f, 8, 12 ); char *buf = new char[1024*1024*10]; memset( buf, 0, 1024*1024*10 ); for( int j = 0; j < 250; j++ ) { - m.openStream( m.createStream() ).write( buf, 1024*1024*10 ); +// m.openStream( m.createStream() ).write( buf, 1024*1024*10 ); // m.sync(); - printf("\r%03d%%", (j+1)*100/250 ); - fflush( stdout ); +// printf("\r%03d%%", (j+1)*100/250 ); +// fflush( stdout ); } printf("\n\n"); diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp deleted file mode 100644 index 4751559..0000000 --- a/src/tests/cache.cpp +++ /dev/null @@ -1,289 +0,0 @@ -#include "bu/myriadcache.h" -#include "bu/uuid.h" -#include "bu/string.h" -#include "bu/sio.h" - -class Something : public Bu::CacheObject -{ -friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Something &s ); -friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Something &s ); -public: - Something() - { - } - - Something( const Bu::String &sName ) : - uId( Bu::Uuid::generate() ), - sName( sName ) - { - } - - virtual ~Something() - { - } - - virtual Bu::Uuid getKey() const - { - return uId; - } - - Bu::String getName() const - { - return sName; - } - - void setName( const Bu::String &sNewName ) - { - sName = sNewName; - changed(); - } - - virtual Bu::String toString() const=0; - -private: - Bu::Uuid uId; - Bu::String sName; -}; - -class SubSomethingA : public Something -{ -friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, SubSomethingA &s ); -friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const SubSomethingA &s ); -public: - SubSomethingA() - { - } - - SubSomethingA( const Bu::String &sName, int iNumber ) : - Something( sName ), - iNumber( iNumber ) - { - } - - virtual Bu::String toString() const - { - return Bu::String("[typeA] %1 (%2)").arg( getName() ).arg( iNumber ); - } - -private: - int iNumber; -}; - -class SubSomethingB : public Something -{ -friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, SubSomethingB &s ); -friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const SubSomethingB &s ); -public: - SubSomethingB() - { - } - - SubSomethingB( const Bu::String &sName, const Bu::String &sString ) : - Something( sName ), - sString( sString ) - { - } - - virtual Bu::String toString() const - { - return Bu::String("[typeB] %1 (%2)").arg( getName() ).arg( sString ); - } - -private: - Bu::String sString; -}; - -Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Something &s ) -{ - return ar >> s.uId >> s.sName; -} - -Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Something &s ) -{ - return ar << s.uId << s.sName; -} - -Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, SubSomethingA &s ) -{ - return ar >> (Something &)s >> s.iNumber; -} - -Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const SubSomethingA &s ) -{ - return ar << (Something &)s << s.iNumber; -} - -Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, SubSomethingB &s ) -{ - return ar >> (Something &)s >> s.sString; -} - -Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const SubSomethingB &s ) -{ - return ar << (Something &)s << s.sString; -} - -namespace Bu -{ - template<> - void _cacheObjectSave( Bu::Stream &s, const Something *pObject ) - { - Bu::Archive ar( s, Bu::Archive::save ); - if( typeid(*pObject) == typeid(SubSomethingA) ) - { - ar << (uint8_t)1 << (SubSomethingA &)*pObject; - } - else if( typeid(*pObject) == typeid(SubSomethingB) ) - { - ar << (uint8_t)2 << (SubSomethingB &)*pObject; - } - else - { - Bu::println("Not a recognized type!"); - throw Bu::ExceptionBase("Not recognized type!"); - } - } - - template<> - Something *_cacheObjectLoad( Bu::CacheObject::Initializer &initObj, const Bu::Uuid &rKey, Bu::Stream &s ) - { - Bu::Archive ar( s, Bu::Archive::load ); - uint8_t uType; - ar >> uType; - switch( uType ) - { - case 1: - { - SubSomethingA *ret = initObj(new SubSomethingA()); - ar >> *ret; - return ret; - } - break; - - case 2: - { - SubSomethingB *ret = initObj(new SubSomethingB()); - ar >> *ret; - return ret; - } - break; - - default: - throw Bu::ExceptionBase("Flagrant error! Invalid type!"); - } - - return NULL; - } -} - -typedef Bu::CachePtr SomethingPtr; -typedef Bu::CachePtr SomethingAPtr; -typedef Bu::CachePtr SomethingBPtr; -typedef Bu::MyriadCache SomethingCache; - -int main( int, char *[] ) -{ - Bu::File fStore("test.myr", Bu::File::Create|Bu::File::ReadWrite); - SomethingCache c( fStore ); - - SomethingPtr ptr; - if( time(NULL)%2 ) - ptr = c.insert( new SubSomethingA("Hello", 55) ).cast(); - else - ptr = c.insert( new SubSomethingB("Goodbye", "Things") ).cast(); - - Bu::println("Something[%1]: %2"). - arg( ptr.getKey() ). - arg( ptr->getName() ); - - SomethingCache::KeyList lKeys = c.getKeys(); - Bu::println("Count: %1").arg( lKeys.getSize() ); - for( SomethingCache::KeyList::iterator i = lKeys.begin(); i; i++ ) - { - Bu::println(" - %1: '%2'").arg( *i ).arg( c.get( *i )->toString() ); - } - Bu::println("Count: %1").arg( c.getSize() ); - - SomethingPtr p2 = c.get( ptr.getKey() ); - Bu::println("%1 == %2").arg( p2->getName() ).arg( ptr->getName() ); - SomethingPtr p3 = ptr.cast(); - Bu::println("%1: %2").arg( p3.getKey() ).arg( p3->getName() ); - - return 0; -} - -/* -int main( int argc, char *argv[] ) -{ - Bu::File fStore("test.myr", Bu::File::Create|Bu::File::ReadWrite); - SomethingCache c( fStore ); - - for( int j = 1; j < argc; j++ ) - { - SomethingPtr ptr = c.insert( new Something(argv[j]) ); - - Bu::println("Something[%1]: %2"). - arg( ptr.getKey() ). - arg( ptr->getName() ); - } - - SomethingCache::KeyList lKeys = c.getKeys(); - Bu::println("Count: %1").arg( lKeys.getSize() ); - int j = 0; - for( SomethingCache::KeyList::iterator i = lKeys.begin(); i; i++ ) - { - Bu::println(" - %1: '%2'").arg( *i ).arg( c.get( *i )->getName() ); - if( ((j++)%2) ) - c.erase( *i ); - } - Bu::println("Count: %1").arg( c.getSize() ); - - c._debug(); - - SomethingPtr p2; - SomethingPtr p1( c.get( lKeys.first() ) ); - - c._debug(); - - { - SomethingPtr p2( p1 ); - c._debug(); - } - - c._debug(); - - p2 = p1; - - c._debug(); - - p1.unbind(); - - c._debug(); - - Bu::println("Name: %1").arg( p1->getName() ); - - p1.unbind(); - p1.lock(); - p1.unlock(); - - c._debug(); - - SomethingPtr p3 = c.getLazy( lKeys.first() ); - - c._debug(); - - { - SomethingPtr::Locker l( p3 ); - - Bu::println("Name again: %1").arg( p3->getName() ); - - p3->setName( p3->getName() + " - again" ); - } - - c.sync(); - - c._debug(); - - return 0; -} -*/ diff --git a/src/tests/cachedel.cpp b/src/tests/cachedel.cpp deleted file mode 100644 index 817757c..0000000 --- a/src/tests/cachedel.cpp +++ /dev/null @@ -1,288 +0,0 @@ -#include "bu/myriadcache.h" -#include "bu/uuid.h" -#include "bu/string.h" -#include "bu/sio.h" -#include "bu/membuf.h" - -class Something : public Bu::CacheObject -{ -friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Something &s ); -friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Something &s ); -public: - Something() - { - } - - Something( const Bu::String &sName ) : - uId( Bu::Uuid::generate() ), - sName( sName ) - { - } - - virtual ~Something() - { - } - - virtual Bu::Uuid getKey() const - { - return uId; - } - - Bu::String getName() const - { - return sName; - } - - void setName( const Bu::String &sNewName ) - { - sName = sNewName; - changed(); - } - - virtual Bu::String toString() const=0; - -private: - Bu::Uuid uId; - Bu::String sName; -}; - -class SubSomethingA : public Something -{ -friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, SubSomethingA &s ); -friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const SubSomethingA &s ); -public: - SubSomethingA() - { - } - - SubSomethingA( const Bu::String &sName, int iNumber ) : - Something( sName ), - iNumber( iNumber ) - { - } - - virtual Bu::String toString() const - { - return Bu::String("[typeA] %1 (%2)").arg( getName() ).arg( iNumber ); - } - -private: - int iNumber; -}; - -class SubSomethingB : public Something -{ -friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, SubSomethingB &s ); -friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const SubSomethingB &s ); -public: - SubSomethingB() - { - } - - SubSomethingB( const Bu::String &sName, const Bu::String &sString ) : - Something( sName ), - sString( sString ) - { - } - - virtual Bu::String toString() const - { - return Bu::String("[typeB] %1 (%2)").arg( getName() ).arg( sString ); - } - -private: - Bu::String sString; -}; - -Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Something &s ) -{ - return ar >> s.uId >> s.sName; -} - -Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Something &s ) -{ - return ar << s.uId << s.sName; -} - -Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, SubSomethingA &s ) -{ - return ar >> (Something &)s >> s.iNumber; -} - -Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const SubSomethingA &s ) -{ - return ar << (Something &)s << s.iNumber; -} - -Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, SubSomethingB &s ) -{ - return ar >> (Something &)s >> s.sString; -} - -Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const SubSomethingB &s ) -{ - return ar << (Something &)s << s.sString; -} - -namespace Bu -{ - template<> - void _cacheObjectSave( Bu::Stream &s, const Something *pObject ) - { - Bu::Archive ar( s, Bu::Archive::save ); - if( typeid(*pObject) == typeid(SubSomethingA) ) - { - ar << (uint8_t)1 << (SubSomethingA &)*pObject; - } - else if( typeid(*pObject) == typeid(SubSomethingB) ) - { - ar << (uint8_t)2 << (SubSomethingB &)*pObject; - } - else - { - Bu::println("Not a recognized type!"); - throw Bu::ExceptionBase("Not recognized type!"); - } - } - - template<> - Something *_cacheObjectLoad( Bu::CacheObject::Initializer &initObj, const Bu::Uuid &rKey, Bu::Stream &s ) - { - Bu::Archive ar( s, Bu::Archive::load ); - uint8_t uType; - ar >> uType; - switch( uType ) - { - case 1: - { - SubSomethingA *ret = initObj(new SubSomethingA()); - ar >> *ret; - return ret; - } - break; - - case 2: - { - SubSomethingB *ret = initObj(new SubSomethingB()); - ar >> *ret; - return ret; - } - break; - - default: - throw Bu::ExceptionBase("Flagrant error! Invalid type!"); - } - - return NULL; - } -} - -typedef Bu::CachePtr SomethingPtr; -typedef Bu::CachePtr SomethingAPtr; -typedef Bu::CachePtr SomethingBPtr; -typedef Bu::MyriadCache SomethingCache; - -int main( int, char *[] ) -{ - Bu::MemBuf mbStore; - SomethingCache c( mbStore ); - - SomethingPtr ptr; - if( time(NULL)%2 ) - ptr = c.insert( new SubSomethingA("Hello", 55) ).cast(); - else - ptr = c.insert( new SubSomethingB("Goodbye", "Things") ).cast(); - - Bu::Uuid id = ptr.getKey(); - Bu::println("Something[%1]: %2"). - arg( ptr.getKey() ). - arg( ptr->getName() ); - - Bu::println("has %1: %2").arg( id ).arg( c.has( id ) ); - c.erase( ptr.getKey() ); - Bu::println("has %1: %2").arg( id ).arg( c.has( id ) ); - SomethingPtr b = ptr; - - SomethingPtr p2 = c.insert( new SubSomethingA("new test", 123) ).cast(); - id = p2.getKey(); - p2.unbind(); - c.erase( id ); - - return 0; -} - -/* -int main( int argc, char *argv[] ) -{ - Bu::File fStore("test.myr", Bu::File::Create|Bu::File::ReadWrite); - SomethingCache c( fStore ); - - for( int j = 1; j < argc; j++ ) - { - SomethingPtr ptr = c.insert( new Something(argv[j]) ); - - Bu::println("Something[%1]: %2"). - arg( ptr.getKey() ). - arg( ptr->getName() ); - } - - SomethingCache::KeyList lKeys = c.getKeys(); - Bu::println("Count: %1").arg( lKeys.getSize() ); - int j = 0; - for( SomethingCache::KeyList::iterator i = lKeys.begin(); i; i++ ) - { - Bu::println(" - %1: '%2'").arg( *i ).arg( c.get( *i )->getName() ); - if( ((j++)%2) ) - c.erase( *i ); - } - Bu::println("Count: %1").arg( c.getSize() ); - - c._debug(); - - SomethingPtr p2; - SomethingPtr p1( c.get( lKeys.first() ) ); - - c._debug(); - - { - SomethingPtr p2( p1 ); - c._debug(); - } - - c._debug(); - - p2 = p1; - - c._debug(); - - p1.unbind(); - - c._debug(); - - Bu::println("Name: %1").arg( p1->getName() ); - - p1.unbind(); - p1.lock(); - p1.unlock(); - - c._debug(); - - SomethingPtr p3 = c.getLazy( lKeys.first() ); - - c._debug(); - - { - SomethingPtr::Locker l( p3 ); - - Bu::println("Name again: %1").arg( p3->getName() ); - - p3->setName( p3->getName() + " - again" ); - } - - c.sync(); - - c._debug(); - - return 0; -} -*/ diff --git a/src/tests/mfstest.cpp b/src/tests/mfstest.cpp deleted file mode 100644 index 813ef8e..0000000 --- a/src/tests/mfstest.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#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; -} - diff --git a/src/tests/myriadfs.cpp b/src/tests/myriadfs.cpp deleted file mode 100644 index 1266e4b..0000000 --- a/src/tests/myriadfs.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "bu/file.h" -#include "bu/membuf.h" -#include "bu/myriadfs.h" -#include "bu/myriadstream.h" -#include "bu/sio.h" - -using namespace Bu; - -int main() -{ -// Bu::MemBuf mb; - Bu::File mb("store.myr", File::Read|File::Write|File::Create ); - Bu::MyriadFs mfs( mb, 512 ); - - sio << "Creating dirs..." << sio.nl; - mfs.create("/etc", Bu::MyriadFs::typeDir|0755 ); - mfs.create("/dev", Bu::MyriadFs::typeDir|0755 ); - mfs.create("/usr", Bu::MyriadFs::typeDir|0755 ); - - mfs.create("/dev/null", Bu::MyriadFs::typeChrDev|0666, 1, 3 ); - mfs.create("/dev/zero", Bu::MyriadFs::typeChrDev|0666, 1, 5 ); - mfs.create("/dev/sda", Bu::MyriadFs::typeBlkDev|0660, 8, 0 ); - - sio << "Creating files..." << sio.nl; - { - Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); - ms.write("world!"); - } - { - Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); - ms.write("world, again!"); - } - { - Bu::MyriadStream ms = mfs.open("/etc/trunc", Bu::MyriadFs::Write ); - ms.write("[longer text shouldn't be seen]"); - } - { - Bu::MyriadStream ms = mfs.open("/etc/trunc", Bu::MyriadFs::Write|Bu::MyriadFs::Create|Bu::MyriadFs::Truncate ); - ms.write("[short text]"); - } - - sio << "Reading files..." << sio.nl; - { - Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read ); - char buf[512]; - buf[ms.read( buf, 512 )] = '\0'; - sio << "read: '" << buf << "'" << sio.nl; - } - { - Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read ); - char buf[512]; - buf[ms.read( buf, 512 )] = '\0'; - sio << "read: '" << buf << "'" << sio.nl; - } - { - Bu::MyriadStream ms = mfs.open("/etc/trunc", Bu::MyriadFs::Read ); - char buf[512]; - buf[ms.read( buf, 512 )] = '\0'; - sio << "read: '" << buf << "'" << sio.nl; - } -} - -- cgit v1.2.3