aboutsummaryrefslogtreecommitdiff
path: root/src/unit/queuebuf.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/unit/queuebuf.unit
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/unit/queuebuf.unit')
-rw-r--r--src/unit/queuebuf.unit154
1 files changed, 77 insertions, 77 deletions
diff --git a/src/unit/queuebuf.unit b/src/unit/queuebuf.unit
index 553d9fc..bc55a04 100644
--- a/src/unit/queuebuf.unit
+++ b/src/unit/queuebuf.unit
@@ -16,89 +16,89 @@
16 16
17suite QueueBuf 17suite QueueBuf
18{ 18{
19 test testBasic01 19 test testBasic01
20 { 20 {
21 Bu::QueueBuf qb; 21 Bu::QueueBuf qb;
22 unitTest( qb.write("ab", 2 ) == 2 ); 22 unitTest( qb.write("ab", 2 ) == 2 );
23 unitTest( qb.write("cde", 3 ) == 3 ); 23 unitTest( qb.write("cde", 3 ) == 3 );
24 unitTest( qb.write("FG", 2 ) == 2 ); 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::String &fill, unsigned int iSize ) 33 void QBUF_RANDSTR( Bu::String &fill, unsigned int iSize )
34 { 34 {
35 char c; 35 char c;
36 for( unsigned int i=0; i<iSize; ++i ) 36 for( unsigned int i=0; i<iSize; ++i )
37 { 37 {
38 c = RNDCHR; 38 c = RNDCHR;
39 fill.append(&c,1); 39 fill.append(&c,1);
40 } 40 }
41 } 41 }
42 42
43 test testAmounts 43 test testAmounts
44 { 44 {
45 srandom(time(NULL)); 45 srandom(time(NULL));
46 Bu::QueueBuf qb; 46 Bu::QueueBuf qb;
47 Bu::String sTmp; 47 Bu::String sTmp;
48 char buf[4096]; 48 char buf[4096];
49 49
50 for( int i=0; i<200; ++i ) 50 for( int i=0; i<200; ++i )
51 { 51 {
52 unsigned int iAmt = (int)RNDCHR+128; 52 unsigned int iAmt = (int)RNDCHR+128;
53 sTmp.clear(); 53 sTmp.clear();
54 QBUF_RANDSTR( sTmp, iAmt ); 54 QBUF_RANDSTR( sTmp, iAmt );
55 unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == 55 unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) ==
56 (uint32_t)sTmp.getSize() ); 56 (uint32_t)sTmp.getSize() );
57 size_t iRead = qb.read( buf, 4096 ); 57 size_t iRead = qb.read( buf, 4096 );
58 unitTest( iRead == iAmt ); 58 unitTest( iRead == iAmt );
59 } 59 }
60 } 60 }
61 61
62 void QBUF_HEXOUT( const char *s, int iSize ) 62 void QBUF_HEXOUT( const char *s, int iSize )
63 { 63 {
64 for( int i=0; i<iSize; ++i ) 64 for( int i=0; i<iSize; ++i )
65 printf("%02x",(int)(uint8_t)s[i]); 65 printf("%02x",(int)(uint8_t)s[i]);
66 } 66 }
67 67
68 void QBUF_HASH( Bu::String &fill, const char *s, int iSize ) 68 void QBUF_HASH( Bu::String &fill, const char *s, int iSize )
69 { 69 {
70 Bu::Md5 hash; 70 Bu::Md5 hash;
71 hash.reset(); 71 hash.reset();
72 hash.addData( s, iSize ); 72 hash.addData( s, iSize );
73 const Bu::String &sTmp = hash.getResult(); 73 const Bu::String &sTmp = hash.getResult();
74 fill.append( sTmp.getStr(), 16 ); 74 fill.append( sTmp.getStr(), 16 );
75 } 75 }
76 76
77 test testRandomData 77 test testRandomData
78 { 78 {
79 srandom(time(NULL)); 79 srandom(time(NULL));
80 Bu::QueueBuf qb; 80 Bu::QueueBuf qb;
81 Bu::String sTmp; 81 Bu::String sTmp;
82 Bu::String sTmp2; 82 Bu::String sTmp2;
83 char buf[4096]; 83 char buf[4096];
84 84
85 for( int i=0; i<200; ++i ) 85 for( int i=0; i<200; ++i )
86 { 86 {
87 uint32_t iAmt = (uint32_t)RNDCHR+128; 87 uint32_t iAmt = (uint32_t)RNDCHR+128;
88 sTmp.clear(); 88 sTmp.clear();
89 sTmp.append( (const char *)&iAmt, 4 ); 89 sTmp.append( (const char *)&iAmt, 4 );
90 QBUF_RANDSTR( sTmp, iAmt ); 90 QBUF_RANDSTR( sTmp, iAmt );
91 sTmp2.clear(); 91 sTmp2.clear();
92 QBUF_HASH( sTmp2, sTmp.getStr()+4, iAmt ); 92 QBUF_HASH( sTmp2, sTmp.getStr()+4, iAmt );
93 sTmp.append( sTmp2 ); 93 sTmp.append( sTmp2 );
94 unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) == 94 unitTest( qb.write( sTmp.getStr(), sTmp.getSize() ) ==
95 (uint32_t)sTmp.getSize() ); 95 (uint32_t)sTmp.getSize() );
96 size_t iRead = qb.read( buf, 4096 ); 96 size_t iRead = qb.read( buf, 4096 );
97 uint32_t iGotSize = *((uint32_t *)buf); 97 uint32_t iGotSize = *((uint32_t *)buf);
98 unitTest( iRead == iGotSize+4+16 ); 98 unitTest( iRead == iGotSize+4+16 );
99 sTmp2.clear(); 99 sTmp2.clear();
100 QBUF_HASH( sTmp2, buf+4, iGotSize ); 100 QBUF_HASH( sTmp2, buf+4, iGotSize );
101 unitTest( !strncmp(sTmp2.getStr(),buf+4+iGotSize,16) ); 101 unitTest( !strncmp(sTmp2.getStr(),buf+4+iGotSize,16) );
102 } 102 }
103 } 103 }
104} 104}