Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

docConversionTest.cpp

Go to the documentation of this file.
00001 // *******************************************************************
00002 // docConversionTest.cpp
00003 // *******************************************************************
00004 //
00005 //  DESCRIPTION: This is a unit testing application to test the
00006 //               DocConvert application. It makes use of the C++
00007 //               Unit++ testing framework.
00008 //  NOTE:        This program makes use of the Unit++ testing suite
00009 //               Document.h, Broker.h and Server.h.
00010 //
00011 /***************************************************************************
00012 *   Copyright (C) 2003 by drs. Eric D. Schabell                           *
00013 *   erics@cs.kun.nl                                                       *
00014 *                                                                         *
00015 *   This program is free software; you can redistribute it and/or modify  *
00016 *   it under the terms of the GNU General Public License as published by  *
00017 *   the Free Software Foundation; either version 2 of the License, or     *
00018 *   (at your option) any later version.                                   *
00019 ***************************************************************************/
00020 
00021 //--------------------------------------------------------------------
00022 //#includes
00023 //--------------------------------------------------------------------
00024 #include <unit++.h>     // unit testing with Unit++.
00025 #include <string>       // STL strings.
00026 #include <pqxx/all.h>   // postgresql api.
00027 #include "Document.h"
00028 #include "Broker.h"
00029 #include "Server.h"
00030 
00031 using namespace std;
00032 using namespace unitpp;
00033 
00034 namespace
00035 {
00036 class DocConversionTestSuite : public suite
00037 {
00038     //--------------------------------------------------------------------
00039     //Purpose:           Test the construct of remote Server request.
00040     //Preconditions:    none.
00041     //Postconditions:  server name checked.
00042     //Arguments:       none.
00043     //Returns:           0.
00044     //Called Funcs:    Broker(), Broker.getServerName(), assert_true().
00045     //--------------------------------------------------------------------
00046     void testBrokerRemoteServer()
00047     {
00048         Broker myBroker( "my.conversion.server" );
00049         string myServerName = myBroker.getServerName();
00050         if ( myServerName == "my.conversion.server" )
00051         {
00052             assert_true( "broker remote server check", true );
00053         }
00054         else
00055         {
00056             assert_true( "broker remote server check", false );
00057         }
00058     }
00059 
00060     //--------------------------------------------------------------------
00061     //Purpose:           Test the getCounter method.
00062     //Preconditions:    Broker object.
00063     //Postconditions:  Broker counter is checked.
00064     //Arguments:       none.
00065     //Returns:           0.
00066     //Called Funcs:    Broker(), Broker.getCounter(), assert_eq().
00067     //--------------------------------------------------------------------
00068     void testGetCounter()
00069     {
00070         Broker myBroker;
00071         assert_eq("broker counter check", 1, myBroker.getCounter() );
00072     }
00073 
00074     //--------------------------------------------------------------------
00075     //Purpose:           Test the increaseCounter method.
00076     //Preconditions:    Two Broker objects.
00077     //Postconditions:  Broker counter is increased and checked.
00078     //Arguments:       none.
00079     //Returns:           0.
00080     //Called Funcs:    Broker(), Broker.getCounter(), assert_eq().
00081     //--------------------------------------------------------------------
00082     void testIncreaseCounter()
00083     {
00084         Broker myBroker;
00085         assert_eq("initial counter check", 1, myBroker.getCounter() );
00086         Broker anotherBroker;
00087         assert_eq("increase counter check", 2, anotherBroker.getCounter() );
00088     }
00089 
00090     //--------------------------------------------------------------------
00091     //Purpose:           Test decresing of Broker Counter.
00092     //Preconditions:    Two Broker objects.
00093     //Postconditions:  Broker counter is increased, decreased and checked.
00094     //Arguments:       none.
00095     //Returns:           0.
00096     //Called Funcs:    Broker(), ~Broker(), Broker.getCounter(), assert_eq().
00097     //--------------------------------------------------------------------
00098     void testDecreaseCounter()
00099     {
00100         {
00101             Broker myBroker;
00102             Broker anotherBroker;
00103             int mycounter = anotherBroker.getCounter();
00104             assert_eq("pre decrease counter check", 2, mycounter );
00105         }
00106         Broker yetAnotherBroker;
00107         int yetanothercounter = yetAnotherBroker.getCounter();
00108         assert_eq("decreased counter check", 1, yetanothercounter );
00109     }
00110 
00111     //--------------------------------------------------------------------
00112     //Purpose:           Test the getDocumentUrl method.
00113     //Preconditions:   Document object.
00114     //Postconditions: Document getDocumentUrl method checked.
00115     //Arguments:       none.
00116     //Returns:           0.
00117     //Called Funcs:   Document( URI, routine ), Document.getDocumentUrl(),
00118     //                      assert_eq().
00119     //--------------------------------------------------------------------
00120     void testGetDocumentUrl()
00121     {
00122         Document
00123         myDocument("http://infolab.uvt.nl/people/erics/papers/tech-clearinghouse/tech_clearinghouse.pdf", "pdf2ps");
00124         string myUrl = myDocument.getDocumentUrl();
00125         int match;  // to check matching strings.
00126         if ( myUrl == "http://infolab.uvt.nl/people/erics/papers/tech-clearinghouse/tech_clearinghouse .pdf" )
00127         {
00128             match = 0;
00129         }
00130         else
00131         {
00132             match = 1;
00133         }
00134         assert_eq("get Document url check", 0, match);
00135     }
00136 
00137     //--------------------------------------------------------------------
00138     //Purpose:           Test the getDocumentFile method.
00139     //Preconditions:   Document object.
00140     //Postconditions: Document getDocumentFile method checked.
00141     //Arguments:       none.
00142     //Returns:           0.
00143     //Called Funcs:   Document( URI, routine ), Document.getDocumentFile(),
00144     //                      assert_eq().
00145     //--------------------------------------------------------------------
00146     void testGetDocumentFile()
00147     {
00148         Document
00149         myDocument("http://infolab.uvt.nl/people/erics/papers/tech-clearinghouse/tech_clearinghouse.pdf", "pdf2ps");
00150         string myFile = myDocument.getDocumentFile();
00151         int match;  // to check matching strings.
00152         if ( myFile == "tech_clearinghouse.pdf" )
00153         {
00154             match = 0;
00155         }
00156         else
00157         {
00158             match = 1;
00159         }
00160         assert_eq("get Document file check", 0, match);
00161     }
00162 
00163     //--------------------------------------------------------------------
00164     //Purpose:           Test the getDocumentConversion method.
00165     //Preconditions:   Document object.
00166     //Postconditions: Document getDocumentConversion method checked.
00167     //Arguments:       none.
00168     //Returns:           0.
00169     //Called Funcs:   Document( URI, routine ),
00170     //                     Document.getDocumentConversion(), assert_eq().
00171     //--------------------------------------------------------------------
00172     void testGetDocumentConversion()
00173     {
00174         Document
00175         myDocument("http://infolab.uvt.nl/people/erics/papers/tech-clearinghouse/tech_clearinghouse.pdf", "pdf2ps");
00176         string myConversion = myDocument.getDocumentConversion();
00177         int match;  // to check matching strings.
00178         if ( myConversion == "pdf2ps" )
00179         {
00180             match = 0;
00181         }
00182         else
00183         {
00184             match = 1;
00185         }
00186         assert_eq("get Document conversion check", 0, match);
00187     }
00188 
00189     //--------------------------------------------------------------------
00190     //Purpose:           Test the getConversionLocation method.
00191     //Preconditions:   Document object.
00192     //Postconditions: Document getConversionLocation method checked.
00193     //Arguments:       none.
00194     //Returns:           0.
00195     //Called Funcs:   Document( URI, routine ),
00196     //                     Document.setConversionLocation(),
00197     //                     Document.getConversionLocation(), assert_eq().
00198     //--------------------------------------------------------------------
00199     void testGetDocumentConLocation()
00200     {
00201         Document
00202         myDocument("http://infolab.uvt.nl/people/erics/papers/tech-clearinghouse/tech_clearinghouse.pdf", "pdf2ps");
00203         myDocument.setConversionLocation("http://localhost/conversions");
00204         string loc = myDocument.getConversionLocation();
00205         int match;  // to check matching strings.
00206         if ( loc == "http://localhost/conversions" )
00207         {
00208             match = 0;
00209         }
00210         else
00211         {
00212             match = 1;
00213         }
00214         assert_eq("get Document conversion location check", 0, match);
00215     }
00216 
00217     //--------------------------------------------------------------------
00218     //Purpose:           Test the getFileLocation method.
00219     //Preconditions:   Document object.
00220     //Postconditions: Document getFileLocation method checked.
00221     //Arguments:       none.
00222     //Returns:           0.
00223     //Called Funcs:   Document( URI, routine ),
00224     //                     Document.setFileLocation(),
00225     //                     Document.getFileLocation(), assert_eq().
00226     //--------------------------------------------------------------------
00227     void testGetDocumentFileLocation()
00228     {
00229         Document
00230         myDocument("http://infolab.uvt.nl/people/erics/papers/tech-clearinghouse/tech_clearinghouse.pdf", "pdf2ps");
00231         myDocument.setFileLocation("/tmp");
00232         string myFileLocation = myDocument.getFileLocation();
00233         int match;  // to check matching strings.
00234         if ( myFileLocation == "/tmp" )
00235         {
00236             match = 0;
00237         }
00238         else
00239         {
00240             match = 1;
00241         }
00242         assert_eq("get Document file location check", 0, match);
00243     }
00244 
00245     //--------------------------------------------------------------------
00246     //Purpose:           Test the convertDocument method.
00247     //Preconditions:   Broker and Document objects.
00248     //Postconditions: Document convertDocument method checked.
00249     //Arguments:       none.
00250     //Returns:           0.
00251     //Called Funcs:   Document( URI, routine ), Broker(),
00252     //                     Broker.convertDocument(), assert_true().
00253     //--------------------------------------------------------------------
00254     void testConvertDocument()
00255     {
00256         Broker myBroker;
00257         Document
00258         myDocument("http://infolab.uvt.nl/people/erics/papers/tech-clearinghouse/tech_clearinghouse.pdf", "pdf2ps");
00259         if ( myBroker.convertDocument(myDocument) )
00260         {
00261             assert_true( "Conversion results", true );
00262         }
00263         else
00264         {
00265             assert_true( "Conversion results", false );
00266         }
00267     }
00268 
00269     //--------------------------------------------------------------------
00270     //Purpose:          Test Server requestConversion method.
00271     //Preconditions:    Supply a correctly instantiated Document.
00272     //Postconditions:   Returns true if conversion successful, false
00273     //                  if not.
00274     //Arguments:        none.
00275     //Returns:          0.
00276     //Called Funcs:     Server(), Document(), Server.requestConversion().
00277     //--------------------------------------------------------------------
00278     void testServerRequestConversion()
00279     {
00280         Server myServer;
00281         Document
00282         myDocument("http://infolab.uvt.nl/people/erics/papers/tech-clearinghouse/tech_clearinghouse.pdf", "pdf2ps");
00283         if ( myServer.requestConversion( myDocument ) )
00284         {
00285             assert_true( "server request conversion check", true );
00286         }
00287         else
00288         {
00289             assert_true( "server request conversion check", false );
00290         }
00291     }
00292 
00293     //--------------------------------------------------------------------
00294     //Purpose:          Test Broker/Server listConversionDB  method.
00295     //Preconditions:    Supply Broker.
00296     //Postconditions:   A complete listing of all available converison
00297     //                  routines available in the Clearinghouse DB.
00298     //Arguments:        none.
00299     //Returns:          0.
00300     //Called Funcs:     Broker(), Broker.listConversionDB().
00301     //--------------------------------------------------------------------
00302     void testListConversionDB()
00303     {
00304         Broker myBroker;
00305         Result myDBQuery = myBroker.getConversionListing();
00306         if ( myDBQuery.size() > 0 )
00307         {
00308             assert_true( "list conversions check", true );
00309         }
00310         else
00311         {
00312             assert_true( "list conversions check", false );
00313         }
00314     }
00315 
00316 
00317     //--------------------------------------------------------------------
00318     //Purpose:           Test Broker/Server Representaion type query method.
00319     //Preconditions:    Supply Broker.
00320     //Postconditions:  A listing of all available converison
00321     //                      routines based on given representation type in
00322     //                     the Clearinghouse DB (both from and to).
00323     //Arguments:      none.
00324     //Returns:          0.
00325     //Called Funcs:   Broker(), Broker.getRepresentaionTypeListing( string repType).
00326     //--------------------------------------------------------------------
00327     void
00328     testServerRepresentationTypeQuery()
00329     {
00330         Broker myBroker;
00331         string representationTypeTester = "pdf";
00332 
00333         Result myRepresentationQuery =
00334             myBroker.getRepresentationTypeListing( representationTypeTester );
00335         if ( myRepresentationQuery.size() > 0 )
00336         {
00337             assert_true( "representation types listing", true );
00338         }
00339         else
00340         {
00341             assert_true( "representation types listing", false );
00342         }
00343     }
00344 
00345 
00346     //--------------------------------------------------------------------
00347     //Purpose:           Test Broker/Server feature type query method.
00348     //Preconditions:  Supply Broker.
00349     //Postconditions: A listing of all available converison routines
00350     //                          based on given feature type in the Clearinghouse
00351     //                          DB (both from and to).
00352     //Arguments:       none.
00353     //Returns:            0.
00354     //Called Funcs:   Broker(), Broker.getFeatureTypeListing( string featureType).
00355     //--------------------------------------------------------------------
00356     void
00357     testServerFeatureTypeQuery()
00358     {
00359         Broker myBroker;
00360         string featureTypeTester = "binary";
00361 
00362         Result myFeatureQuery =
00363             myBroker.getFeatureTypeListing( featureTypeTester );
00364         if ( myFeatureQuery.size() > 0 )
00365         {
00366             assert_true( "feature types listing", true );
00367         }
00368         else
00369         {
00370             assert_true( "feature types listing", false );
00371         }
00372     }
00373 
00374 
00375 public:
00376     DocConversionTestSuite() : suite("DocConversionTestSuite")
00377     {
00378         add
00379             ( "BrokerRemoteServer",
00380                     testcase( this, "testBrokerRemoteServer",
00381                               &DocConversionTestSuite::testBrokerRemoteServer )
00382             );
00383         add
00384             ( "BrokerListConversionDB",
00385                     testcase( this, "testListConversionDB",
00386                               &DocConversionTestSuite::testListConversionDB )
00387             );
00388         add
00389             ( "DocumentGetDocumentConLocation",
00390                     testcase( this, "testGetDocumentConLocation",
00391 
00392                               &DocConversionTestSuite::testGetDocumentConLocation )            );
00393         add
00394             ( "BrokerDecreaseCounter",
00395                     testcase( this, "testDecreaseCounter",
00396                               &DocConversionTestSuite::testDecreaseCounter )
00397             );
00398         add
00399             ( "BrokerIncreaseCounter",
00400                     testcase( this, "testIncreaseCounter",
00401                               &DocConversionTestSuite::testIncreaseCounter )
00402             );
00403         add
00404             ( "BrokerGetCounter",
00405                     testcase( this, "testGetCounter",
00406                               &DocConversionTestSuite::testGetCounter )
00407             );
00408         add
00409             ( "DocumentGetDocumentUrl",
00410                     testcase( this, "testGetDocumentUrl",
00411                               &DocConversionTestSuite::testGetDocumentUrl )
00412             );
00413         add
00414             ( "DocumentGetDocumentFile",
00415                     testcase( this, "testGetDocumentFile",
00416                               &DocConversionTestSuite::testGetDocumentFile )
00417             );
00418         add
00419             ( "DocumentGetDocumentConversion",
00420                     testcase( this, "testGetDocumentConversion",
00421                               &DocConversionTestSuite::testGetDocumentConversion
00422                             )            );
00423         add
00424             ( "DocumentGetDocumentFileLocation",
00425                     testcase( this, "testGetDocumentFileLocation",
00426 
00427                               &DocConversionTestSuite::testGetDocumentFileLocation )            );
00428         add
00429             ( "DocumentConvertDocument",
00430                     testcase( this, "testConvertDocument",
00431                               &DocConversionTestSuite::testConvertDocument )
00432             );
00433         add
00434             ( "ServerRequestConversion",
00435                     testcase( this, "testServerRequestConversion",
00436                               &DocConversionTestSuite::testServerRequestConversion )            );
00437         add
00438             ( "ServerRequestRepresentationTypeQuery",
00439                     testcase( this, "testServerRepresentationTypeQuery",
00440                               &DocConversionTestSuite::testServerRepresentationTypeQuery )            );
00441         add
00442             ( "ServerRequestFeatureTypeQuery",
00443                     testcase( this, "testServerFeatureTypeQuery",
00444                               &DocConversionTestSuite::testServerFeatureTypeQuery )            );
00445         suite::main().add("DocConversionTestSuite",this);
00446     }
00447 
00448 };
00449 
00450 DocConversionTestSuite* theDocConversionsTest = new DocConversionTestSuite();
00451 }
00452 

Generated on Thu Dec 4 14:39:17 2003 for docconversion.kdevelop by doxygen 1.3.4