diff options
Diffstat (limited to '')
-rw-r--r-- | src/unit/queuebuf.unit | 148 |
1 files changed, 74 insertions, 74 deletions
diff --git a/src/unit/queuebuf.unit b/src/unit/queuebuf.unit index 9ae7d36..29ba858 100644 --- a/src/unit/queuebuf.unit +++ b/src/unit/queuebuf.unit | |||
@@ -14,91 +14,91 @@ | |||
14 | 14 | ||
15 | #define RNDCHR ((char)(((double)random()/(double)RAND_MAX)*256.0)) | 15 | #define RNDCHR ((char)(((double)random()/(double)RAND_MAX)*256.0)) |
16 | 16 | ||
17 | {=Init} | 17 | suite QueueBuf |
18 | |||
19 | {%testBasic01} | ||
20 | { | 18 | { |
21 | Bu::QueueBuf qb; | 19 | test testBasic01 |
22 | unitTest( qb.write("ab", 2 ) == 2 ); | 20 | { |
23 | unitTest( qb.write("cde", 3 ) == 3 ); | 21 | Bu::QueueBuf qb; |
24 | unitTest( qb.write("FG", 2 ) == 2 ); | 22 | unitTest( qb.write("ab", 2 ) == 2 ); |
23 | unitTest( qb.write("cde", 3 ) == 3 ); | ||
24 | unitTest( qb.write("FG", 2 ) == 2 ); | ||
25 | 25 | ||
26 | char buf[8]; | 26 | char buf[8]; |
27 | buf[7] = '\0'; | 27 | buf[7] = '\0'; |
28 | unitTest( qb.read( buf, 7 ) == 7 ); | 28 | unitTest( qb.read( buf, 7 ) == 7 ); |
29 | unitTest( !strncmp( buf, "abcdeFG", 7 ) ); | 29 | unitTest( !strncmp( buf, "abcdeFG", 7 ) ); |
30 | unitTest( qb.read( buf, 7 ) == 0 ); | 30 | unitTest( qb.read( buf, 7 ) == 0 ); |
31 | } | 31 | } |
32 | 32 | ||
33 | void QBUF_RANDSTR( Bu::FString &fill, unsigned int iSize ) | 33 | void QBUF_RANDSTR( Bu::FString &fill, unsigned int iSize ) |
34 | { | ||
35 | char c; | ||
36 | for( unsigned int i=0; i<iSize; ++i ) | ||
37 | { | 34 | { |
38 | c = RNDCHR; | 35 | char c; |
39 | fill.append(&c,1); | 36 | for( unsigned int i=0; i<iSize; ++i ) |
37 | { | ||
38 | c = RNDCHR; | ||
39 | fill.append(&c,1); | ||
40 | } | ||
40 | } | 41 | } |
41 | } | ||
42 | 42 | ||
43 | {%testAmounts} | 43 | test testAmounts |
44 | { | ||
45 | srandom(time(NULL)); | ||
46 | Bu::QueueBuf qb; | ||
47 | Bu::FString sTmp; | ||
48 | char buf[4096]; | ||
49 | |||
50 | for( int i=0; i<200; ++i ) | ||
51 | { | 44 | { |
52 | unsigned int iAmt = (int)RNDCHR+128; | 45 | srandom(time(NULL)); |
53 | sTmp.clear(); | 46 | Bu::QueueBuf qb; |
54 | QBUF_RANDSTR( sTmp, iAmt ); | 47 | Bu::FString sTmp; |
55 | unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == | 48 | char buf[4096]; |
56 | (uint32_t)sTmp.getSize() ); | ||
57 | size_t iRead = qb.read( buf, 4096 ); | ||
58 | unitTest( iRead == iAmt ); | ||
59 | } | ||
60 | } | ||
61 | 49 | ||
62 | void QBUF_HEXOUT( const char *s, int iSize ) | 50 | for( int i=0; i<200; ++i ) |
63 | { | 51 | { |
64 | for( int i=0; i<iSize; ++i ) | 52 | unsigned int iAmt = (int)RNDCHR+128; |
65 | printf("%02x",(int)(uint8_t)s[i]); | 53 | sTmp.clear(); |
66 | } | 54 | QBUF_RANDSTR( sTmp, iAmt ); |
55 | unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == | ||
56 | (uint32_t)sTmp.getSize() ); | ||
57 | size_t iRead = qb.read( buf, 4096 ); | ||
58 | unitTest( iRead == iAmt ); | ||
59 | } | ||
60 | } | ||
67 | 61 | ||
68 | void QBUF_HASH( Bu::FString &fill, const char *s, int iSize ) | 62 | void QBUF_HEXOUT( const char *s, int iSize ) |
69 | { | 63 | { |
70 | Bu::Md5 hash; | 64 | for( int i=0; i<iSize; ++i ) |
71 | hash.reset(); | 65 | printf("%02x",(int)(uint8_t)s[i]); |
72 | hash.addData( s, iSize ); | 66 | } |
73 | const Bu::FString &sTmp = hash.getResult(); | ||
74 | fill.append( sTmp.getStr(), 16 ); | ||
75 | } | ||
76 | 67 | ||
77 | {%testRandomData} | 68 | void QBUF_HASH( Bu::FString &fill, const char *s, int iSize ) |
78 | { | 69 | { |
79 | srandom(time(NULL)); | 70 | Bu::Md5 hash; |
80 | Bu::QueueBuf qb; | 71 | hash.reset(); |
81 | Bu::FString sTmp; | 72 | hash.addData( s, iSize ); |
82 | Bu::FString sTmp2; | 73 | const Bu::FString &sTmp = hash.getResult(); |
83 | char buf[4096]; | 74 | fill.append( sTmp.getStr(), 16 ); |
75 | } | ||
84 | 76 | ||
85 | for( int i=0; i<200; ++i ) | 77 | test testRandomData |
86 | { | 78 | { |
87 | uint32_t iAmt = (uint32_t)RNDCHR+128; | 79 | srandom(time(NULL)); |
88 | sTmp.clear(); | 80 | Bu::QueueBuf qb; |
89 | sTmp.append( (const char *)&iAmt, 4 ); | 81 | Bu::FString sTmp; |
90 | QBUF_RANDSTR( sTmp, iAmt ); | 82 | Bu::FString sTmp2; |
91 | sTmp2.clear(); | 83 | char buf[4096]; |
92 | QBUF_HASH( sTmp2, sTmp.getStr()+4, iAmt ); | 84 | |
93 | sTmp.append( sTmp2 ); | 85 | for( int i=0; i<200; ++i ) |
94 | unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == | 86 | { |
95 | (uint32_t)sTmp.getSize() ); | 87 | uint32_t iAmt = (uint32_t)RNDCHR+128; |
96 | size_t iRead = qb.read( buf, 4096 ); | 88 | sTmp.clear(); |
97 | uint32_t iGotSize = *((uint32_t *)buf); | 89 | sTmp.append( (const char *)&iAmt, 4 ); |
98 | unitTest( iRead == iGotSize+4+16 ); | 90 | QBUF_RANDSTR( sTmp, iAmt ); |
99 | sTmp2.clear(); | 91 | sTmp2.clear(); |
100 | QBUF_HASH( sTmp2, buf+4, iGotSize ); | 92 | QBUF_HASH( sTmp2, sTmp.getStr()+4, iAmt ); |
101 | unitTest( !strncmp(sTmp2.getStr(),buf+4+iGotSize,16) ); | 93 | sTmp.append( sTmp2 ); |
94 | unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == | ||
95 | (uint32_t)sTmp.getSize() ); | ||
96 | size_t iRead = qb.read( buf, 4096 ); | ||
97 | uint32_t iGotSize = *((uint32_t *)buf); | ||
98 | unitTest( iRead == iGotSize+4+16 ); | ||
99 | sTmp2.clear(); | ||
100 | QBUF_HASH( sTmp2, buf+4, iGotSize ); | ||
101 | unitTest( !strncmp(sTmp2.getStr(),buf+4+iGotSize,16) ); | ||
102 | } | ||
102 | } | 103 | } |
103 | } | 104 | } |
104 | |||