]> WPIA git - cassiopeia.git/blob - test/src/bioWrapper.cpp
73d7c3600ebb14d12cf0cf4f10ff4dadcded486f
[cassiopeia.git] / test / src / bioWrapper.cpp
1 #include <iostream>
2
3 #include <boost/test/unit_test.hpp>
4
5 #include "bios.h"
6 #include "opensslBIO.h"
7
8 class OpensslBIO1 : public OpensslBIO {
9 public:
10     int state;
11
12     int write( const char* buf, int num );
13     int read( char* buf, int size );
14     long ctrl( int cmod, long arg1, void* arg2 );
15
16     static const char* getName();
17 };
18
19 int OpensslBIO1::write( const char* buf, int num ) {
20     state = num * 2;
21     ( void ) buf;
22     return 0;
23 }
24 int OpensslBIO1::read( char* buf, int size ) {
25     state = size * 3;
26     ( void ) buf;
27     return 0;
28 }
29 long OpensslBIO1::ctrl( int cmod, long arg1, void* arg2 ) {
30     state = cmod * 7;
31     ( void ) arg1;
32     ( void ) arg2;
33     return 0;
34 }
35 const char* OpensslBIO1::getName() {
36     return "dummyBIO";
37 }
38
39 BOOST_AUTO_TEST_SUITE( TestBioWrapper )
40
41 BOOST_AUTO_TEST_CASE( BasicCalls ) {
42     BIO* n = BIO_new( toBio<OpensslBIO1>() );
43     OpensslBIO* o = new OpensslBIOWrapper( n );
44     OpensslBIO1* data = ( OpensslBIO1* ) n->ptr;
45
46     o->write( "bla", 13 );
47     BOOST_CHECK( data->state == 13 * 2 );
48
49     char buf[17];
50     o->read( buf, 17 );
51     BOOST_CHECK( data->state == 17 * 3 );
52
53     o->ctrl( 19, 0, 0 );
54     BOOST_CHECK( data->state == 19 * 7 );
55
56     delete o;
57 }
58
59 BOOST_AUTO_TEST_SUITE_END()