Began work on virtual database filter
[metaproxy-moved-to-github.git] / src / test_filter_virt_db.cpp
1 /* $Id: test_filter_virt_db.cpp,v 1.1 2005-10-24 14:33:30 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "config.hpp"
8 #include <iostream>
9 #include <stdexcept>
10
11 #include "filter_virt_db.hpp"
12
13 #include "router.hpp"
14 #include "session.hpp"
15 #include "package.hpp"
16
17 #define BOOST_AUTO_TEST_MAIN
18 #include <boost/test/auto_unit_test.hpp>
19
20 #include <yaz/zgdu.h>
21 #include <yaz/otherinfo.h>
22 using namespace boost::unit_test;
23
24
25 BOOST_AUTO_TEST_CASE( test_filter_virt_db_1 )
26 {
27     try 
28     {
29         yp2::filter::Virt_db vdb;
30     }
31     catch ( ... ) {
32         BOOST_CHECK (false);
33     }
34 }
35
36 BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 )
37 {
38     try 
39     {
40         yp2::RouterChain router;
41         
42         yp2::filter::Virt_db vdb;
43         
44         router.rule(vdb);
45         
46         // Create package with Z39.50 init request in it
47         yp2::Package pack;
48         
49         ODR odr = odr_createmem(ODR_ENCODE);
50         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
51         
52         BOOST_CHECK(apdu);
53         
54         pack.request() = apdu;
55         odr_destroy(odr);
56         
57         // Put it in router
58         pack.router(router).move(); 
59         
60         // Inspect that we got Z39.50 init Response OK.
61         yazpp_1::GDU *gdu = &pack.response();
62         
63         BOOST_CHECK(!pack.session().is_closed()); 
64         
65         Z_GDU *z_gdu = gdu->get();
66         BOOST_CHECK(z_gdu);
67         if (z_gdu) {
68             BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950);
69             BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
70         }
71     }
72     catch ( ... ) {
73         BOOST_CHECK (false);
74     }
75 }
76
77 /*
78  * Local variables:
79  * c-basic-offset: 4
80  * indent-tabs-mode: nil
81  * c-file-style: "stroustrup"
82  * End:
83  * vim: shiftwidth=4 tabstop=8 expandtab
84  */