Bump year in copyright msg in source
[metaproxy-moved-to-github.git] / src / test_filter_virt_db.cpp
index 56e82ed..dcaa1a5 100644 (file)
@@ -1,14 +1,26 @@
-/* $Id: test_filter_virt_db.cpp,v 1.5 2005-10-26 10:21:03 marc Exp $
-   Copyright (c) 2005, Index Data.
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2009 Index Data
 
-%LICENSE%
- */
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
 
 #include "config.hpp"
 #include <iostream>
 #include <stdexcept>
 
-#include "test_util.hpp"
+#include "util.hpp"
 #include "filter_virt_db.hpp"
 #include "filter_backend_test.hpp"
 #include "filter_log.hpp"
@@ -18,6 +30,7 @@
 #include "package.hpp"
 
 #define BOOST_AUTO_TEST_MAIN
+#define BOOST_TEST_DYN_LINK
 #include <boost/test/auto_unit_test.hpp>
 
 #include <yaz/zgdu.h>
 #include <yaz/otherinfo.h>
 using namespace boost::unit_test;
 
+namespace mp = metaproxy_1;
 
 BOOST_AUTO_TEST_CASE( test_filter_virt_db_1 )
 {
     try 
     {
-        yp2::filter::Virt_db vdb;
+        mp::filter::VirtualDB vdb;
     }
     catch ( ... ) {
         BOOST_CHECK (false);
@@ -41,24 +55,23 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 )
 {
     try 
     {
-        yp2::RouterChain router;
+        mp::RouterChain router;
         
-        yp2::filter::Virt_db vdb;
+        mp::filter::VirtualDB vdb;
         
-        router.rule(vdb);
+        router.append(vdb);
         
         // Create package with Z39.50 init request in it
         // Since there is not vhost given, the virt will make its
         // own init response (regardless of backend)
-        yp2::Package pack;
+        mp::Package pack;
         
-        ODR odr = odr_createmem(ODR_ENCODE);
+        mp::odr odr;
         Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
         
         BOOST_CHECK(apdu);
         
         pack.request() = apdu;
-        odr_destroy(odr);
         
         // Put it in router
         pack.router(router).move(); 
@@ -81,10 +94,10 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_2 )
 }
 
 
-static void init(yp2::Package &pack, yp2::Router &router)
+static void init(mp::Package &pack, mp::Router &router)
 {
     // Create package with Z39.50 init request in it
-    ODR odr = odr_createmem(ODR_ENCODE);
+    mp::odr odr;
     Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest);
     
     BOOST_CHECK(apdu);
@@ -92,7 +105,6 @@ static void init(yp2::Package &pack, yp2::Router &router)
         return;
     
     pack.request() = apdu;
-    odr_destroy(odr);
     
     // Put it in router
     pack.router(router).move(); 
@@ -110,16 +122,16 @@ static void init(yp2::Package &pack, yp2::Router &router)
     BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse);
 }
                  
-static void search(yp2::Package &pack, yp2::Router &router,
+static void search(mp::Package &pack, mp::Router &router,
                    const std::string &query, const char *db,
                    const char *setname)
 {
     // Create package with Z39.50 search request in it
             
-    ODR odr = odr_createmem(ODR_ENCODE);
+    mp::odr odr;
     Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchRequest);
 
-    yp2::util::pqf(odr, apdu, query);
+    mp::util::pqf(odr, apdu, query);
 
     apdu->u.searchRequest->resultSetName = odr_strdup(odr, setname);
     
@@ -134,8 +146,6 @@ static void search(yp2::Package &pack, yp2::Router &router,
     
     pack.request() = apdu;
     
-    odr_destroy(odr);
-    
     Z_GDU *gdu_test = pack.request().get();
     BOOST_CHECK(gdu_test);
     
@@ -155,13 +165,13 @@ static void search(yp2::Package &pack, yp2::Router &router,
     BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_searchResponse);
 }
 
-static void present(yp2::Package &pack, yp2::Router &router,
+static void present(mp::Package &pack, mp::Router &router,
                     int start, int number,
                     const char *setname)
 {
     // Create package with Z39.50 present request in it
             
-    ODR odr = odr_createmem(ODR_ENCODE);
+    mp::odr odr;
     Z_APDU *apdu = zget_APDU(odr, Z_APDU_presentRequest);
     
     apdu->u.presentRequest->resultSetId  = odr_strdup(odr, setname);
@@ -174,8 +184,6 @@ static void present(yp2::Package &pack, yp2::Router &router,
     
     pack.request() = apdu;
     
-    odr_destroy(odr);
-    
     Z_GDU *gdu_test = pack.request().get();
     BOOST_CHECK(gdu_test);
     
@@ -199,43 +207,43 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 )
 {
     try 
     {
-        yp2::RouterChain router;
+        mp::RouterChain router;
 
-        yp2::filter::Log filter_log1("FRONT");
+        mp::filter::Log filter_log1("FRONT");
 #if 0
-        router.rule(filter_log1);
+        router.append(filter_log1);
 #endif
    
-        yp2::filter::Virt_db vdb;        
-        router.rule(vdb);
-        vdb.add_map_db2vhost("Default", "localhost:210");
-        yp2::filter::Log filter_log2("BACK");
+        mp::filter::VirtualDB vdb;        
+        router.append(vdb);
+        vdb.add_map_db2target("Default", "localhost:210", "");
+        mp::filter::Log filter_log2("BACK");
 #if 0
-        router.rule(filter_log2);
+        router.append(filter_log2);
 #endif
-        yp2::filter::Backend_test btest;
-        router.rule(btest);
+        mp::filter::BackendTest btest;
+        router.append(btest);
 
-        yp2::Session session1;
-        yp2::Origin origin1;
+        mp::Session session1;
+        mp::Origin origin1;
         
         {
-            yp2::Package pack(session1, origin1);
+            mp::Package pack(session1, origin1);
             init(pack, router);
         }
         {
             // search for database for which there is no map
-            yp2::Package pack(session1, origin1);
+            mp::Package pack(session1, origin1);
             search(pack, router, "computer", "bad_database", "default");
         }
         {
             // search for database for which there a map
-            yp2::Package pack(session1, origin1);
+            mp::Package pack(session1, origin1);
             search(pack, router, "other", "Default", "default");
         }
         {
             // present from last search
-            yp2::Package pack(session1, origin1);
+            mp::Package pack(session1, origin1);
             present(pack, router, 1, 2, "default");
         }
     }
@@ -248,8 +256,9 @@ BOOST_AUTO_TEST_CASE( test_filter_virt_db_3 )
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+