diff options
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/nidstool.cpp | 124 | ||||
| -rw-r--r-- | src/tests/rh.cpp | 52 |
2 files changed, 176 insertions, 0 deletions
diff --git a/src/tests/nidstool.cpp b/src/tests/nidstool.cpp new file mode 100644 index 0000000..546534e --- /dev/null +++ b/src/tests/nidstool.cpp | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | #include "bu/file.h" | ||
| 2 | #include "bu/nids.h" | ||
| 3 | #include "bu/nidsstream.h" | ||
| 4 | #include "bu/paramproc.h" | ||
| 5 | |||
| 6 | #include <stdlib.h> | ||
| 7 | |||
| 8 | class Param : public Bu::ParamProc | ||
| 9 | { | ||
| 10 | public: | ||
| 11 | Param( int argc, char *argv[] ) | ||
| 12 | { | ||
| 13 | addHelpBanner("nidstool - Do stuff with nids files.\n\n"); | ||
| 14 | addParam("info", 'i', mkproc(Param::procInfo), | ||
| 15 | "Print some info about the file."); | ||
| 16 | addParam("dump", 'd', mkproc(Param::procDump), | ||
| 17 | "Dump a stream to a file"); | ||
| 18 | addParam("help", 'h', mkproc(Bu::ParamProc::help), "This help."); | ||
| 19 | process( argc, argv ); | ||
| 20 | } | ||
| 21 | |||
| 22 | virtual ~Param() | ||
| 23 | { | ||
| 24 | } | ||
| 25 | |||
| 26 | int procInfo( int argc, char *argv[] ) | ||
| 27 | { | ||
| 28 | if( argc < 1 ) | ||
| 29 | { | ||
| 30 | printf("You must provide a file name.\n"); | ||
| 31 | exit( 1 ); | ||
| 32 | } | ||
| 33 | |||
| 34 | Bu::File fIn( argv[0], Bu::File::Read ); | ||
| 35 | Bu::Nids n( fIn ); | ||
| 36 | n.initialize(); | ||
| 37 | |||
| 38 | printf("Block size: %db\n", n.getBlockSize() ); | ||
| 39 | printf("Block count: %d\n", n.getNumBlocks() ); | ||
| 40 | printf("Blocks used: %d (%d%%)\n", n.getNumUsedBlocks(), | ||
| 41 | n.getNumUsedBlocks()*100/n.getNumBlocks() ); | ||
| 42 | printf("Block start: %db\n", n.getBlockStart() ); | ||
| 43 | printf("Block overhead: %db\n", n.getBlockOverhead() ); | ||
| 44 | printf("Block storage: %db (%d%%)\n", | ||
| 45 | n.getBlockSize()-n.getBlockOverhead(), | ||
| 46 | (n.getBlockSize()-n.getBlockOverhead())*100/n.getBlockSize() ); | ||
| 47 | |||
| 48 | if( argc >= 2 ) | ||
| 49 | { | ||
| 50 | typedef struct Block | ||
| 51 | { | ||
| 52 | uint32_t uFirstBlock; | ||
| 53 | uint32_t uNextBlock; | ||
| 54 | uint32_t uPrevBlock; | ||
| 55 | uint32_t uBytesUsed; | ||
| 56 | uint32_t uReserved; | ||
| 57 | } Block; | ||
| 58 | |||
| 59 | uint32_t uStream = strtoul( argv[1], NULL, 0 ); | ||
| 60 | uint32_t uBlock = uStream; | ||
| 61 | |||
| 62 | Block b; | ||
| 63 | |||
| 64 | for(;;) | ||
| 65 | { | ||
| 66 | fIn.setPos( n.getBlockStart()+n.getBlockSize()*uBlock ); | ||
| 67 | fIn.read( &b, sizeof(Block) ); | ||
| 68 | printf("Stream %u: block %u, next %u, prev %u, %ub used.\n", | ||
| 69 | uStream, uBlock, b.uNextBlock, b.uPrevBlock, b.uBytesUsed | ||
| 70 | ); | ||
| 71 | if( b.uNextBlock == 0xFFFFFFFFUL ) | ||
| 72 | break; | ||
| 73 | uBlock = b.uNextBlock; | ||
| 74 | } | ||
| 75 | printf("Stream End.\n"); | ||
| 76 | |||
| 77 | return 2; | ||
| 78 | } | ||
| 79 | |||
| 80 | return 1; | ||
| 81 | } | ||
| 82 | |||
| 83 | int procDump( int argc, char *argv[] ) | ||
| 84 | { | ||
| 85 | if( argc < 3 ) | ||
| 86 | { | ||
| 87 | printf("You must provide a nids file, a stream id, and an output " | ||
| 88 | "file.\n"); | ||
| 89 | exit( 1 ); | ||
| 90 | } | ||
| 91 | |||
| 92 | Bu::File fIn( argv[0], Bu::File::Read ); | ||
| 93 | Bu::Nids n( fIn ); | ||
| 94 | n.initialize(); | ||
| 95 | |||
| 96 | int iStream = strtol( argv[1], NULL, 0 ); | ||
| 97 | Bu::NidsStream sIn = n.openStream( iStream ); | ||
| 98 | |||
| 99 | Bu::File fOut( argv[2], Bu::File::Write|Bu::File::Create ); | ||
| 100 | int iTotal = 0; | ||
| 101 | char buf[100]; | ||
| 102 | for(;;) | ||
| 103 | { | ||
| 104 | int iRead = sIn.read( buf, 100 ); | ||
| 105 | iTotal += fOut.write( buf, iRead ); | ||
| 106 | if( iRead < 100 ) | ||
| 107 | break; | ||
| 108 | } | ||
| 109 | |||
| 110 | printf("Wrote %db from stream %d in %s to %s.\n", | ||
| 111 | iTotal, iStream, argv[0], argv[2] ); | ||
| 112 | return 3; | ||
| 113 | } | ||
| 114 | |||
| 115 | }; | ||
| 116 | |||
| 117 | |||
| 118 | int main( int argc, char *argv[] ) | ||
| 119 | { | ||
| 120 | Param p( argc, argv ); | ||
| 121 | |||
| 122 | return 0; | ||
| 123 | } | ||
| 124 | |||
diff --git a/src/tests/rh.cpp b/src/tests/rh.cpp new file mode 100644 index 0000000..70abcb7 --- /dev/null +++ b/src/tests/rh.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #include "bu/file.h" | ||
| 2 | #include "bu/hash.h" | ||
| 3 | #include "bu/archive.h" | ||
| 4 | #include "bu/fstring.h" | ||
| 5 | #include "bu/nids.h" | ||
| 6 | #include "bu/nidsstream.h" | ||
| 7 | |||
| 8 | int main( int argc, char *argv[] ) | ||
| 9 | { | ||
| 10 | if( argv[1][0] == 'r' ) | ||
| 11 | { | ||
| 12 | typedef Bu::Hash<Bu::FString, int> Hsh; | ||
| 13 | |||
| 14 | Bu::File fIn( argv[2], Bu::File::Read ); | ||
| 15 | Bu::Archive ar( fIn, Bu::Archive::load ); | ||
| 16 | |||
| 17 | Hsh h; | ||
| 18 | ar >> h; | ||
| 19 | |||
| 20 | printf("Read %d.\n", h.getSize() ); | ||
| 21 | for( Hsh::iterator i = h.begin(); i != h.end(); i++ ) | ||
| 22 | { | ||
| 23 | printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); | ||
| 24 | } | ||
| 25 | |||
| 26 | printf("%d vs. %d\n", h.getSize(), h.getKeys().getSize() ); | ||
| 27 | } | ||
| 28 | else if( argv[1][0] == 'n' ) | ||
| 29 | { | ||
| 30 | typedef Bu::Hash<Bu::FString, int> Hsh; | ||
| 31 | |||
| 32 | Bu::File fIn( argv[2], Bu::File::Read ); | ||
| 33 | Bu::Nids n( fIn ); | ||
| 34 | n.initialize(); | ||
| 35 | Bu::NidsStream sIn = n.openStream( 0 ); | ||
| 36 | Bu::Archive ar( sIn, Bu::Archive::load ); | ||
| 37 | |||
| 38 | Hsh h; | ||
| 39 | ar >> h; | ||
| 40 | |||
| 41 | printf("Read %d.\n", h.getSize() ); | ||
| 42 | for( Hsh::iterator i = h.begin(); i != h.end(); i++ ) | ||
| 43 | { | ||
| 44 | printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); | ||
| 45 | } | ||
| 46 | |||
| 47 | printf("%d vs. %d\n", h.getSize(), h.getKeys().getSize() ); | ||
| 48 | } | ||
| 49 | |||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | |||
