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

brokertest.cpp

Go to the documentation of this file.
00001 // *******************************************************************
00002 // brokertest.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 and Broker.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>
00025 #include <string>
00026 #include "Document.h"
00027 #include "Broker.h"
00028 
00029 using namespace std;
00030 using namespace unitpp;
00031 
00032 namespace
00033 {
00034 class BrokerTestSuite : public suite
00035 {
00036     //--------------------------------------------------------------------
00037     //Purpose:           Test the getCounter method.
00038     //Preconditions:    Broker object.
00039     //Postconditions:  Broker counter is checked.
00040     //Arguments:       none.
00041     //Returns:           0.
00042     //Called Funcs:    Broker(), Broker.getCounter(), assert_eq().
00043     //--------------------------------------------------------------------
00044     void testGetCounter()
00045     {
00046         Broker myBroker;
00047         assert_eq("broker counter check", 1, myBroker.getCounter() );
00048     }
00049 
00050     //--------------------------------------------------------------------
00051     //Purpose:           Test the increaseCounter method.
00052     //Preconditions:    Two Broker objects.
00053     //Postconditions:  Broker counter is increased and checked.
00054     //Arguments:       none.
00055     //Returns:           0.
00056     //Called Funcs:    Broker(), Broker.getCounter(), assert_eq().
00057     //--------------------------------------------------------------------
00058     void testIncreaseCounter()
00059     {
00060         Broker myBroker;
00061         assert_eq("initial counter check", 1, myBroker.getCounter() );
00062         Broker anotherBroker;
00063         assert_eq("increase counter check", 2, anotherBroker.getCounter() );
00064     }
00065 
00066     //--------------------------------------------------------------------
00067     //Purpose:           Test decresing of Broker Counter.
00068     //Preconditions:    Two Broker objects.
00069     //Postconditions:  Broker counter is increased, decreased and checked.
00070     //Arguments:       none.
00071     //Returns:           0.
00072     //Called Funcs:    Broker(), ~Broker(), Broker.getCounter(), assert_eq().
00073     //--------------------------------------------------------------------
00074     void testDecreaseCounter()
00075     {
00076         {
00077             Broker myBroker;
00078             Broker anotherBroker;
00079             int mycounter = anotherBroker.getCounter();
00080             assert_eq("pre decrease counter check", 2, mycounter );
00081         }
00082         Broker yetAnotherBroker;
00083         int yetanothercounter = yetAnotherBroker.getCounter();
00084         assert_eq("decreased counter check", 1, yetanothercounter );
00085     }
00086 
00087     //--------------------------------------------------------------------
00088     //Purpose:           Test the getFile method.
00089     //Preconditions:   Broker and Document objects.
00090     //Postconditions: Broker counter is checked.
00091     //Arguments:       none.
00092     //Returns:           0.
00093     //Called Funcs:   Broker(), Document( URI, routine ),
00094     //                      Broker.getFile( file ), assert_eq().
00095     //--------------------------------------------------------------------
00096     void testGetFile()
00097     {
00098         Broker myBroker;
00099         Document myDocument("http://www.google.com/index.html", "html2pdbtxt");
00100         if ( myBroker.getFile(myDocument) )
00101         {
00102             int match;  // to check matching strings.
00103             if ( myDocument.getFileLocation() == "/tmp/index.html" )
00104             {
00105                 match = 0;
00106             }
00107             else
00108             {
00109                 match = 1;
00110             }
00111             assert_eq( "get file check", 0, match );
00112         }
00113     }
00114 
00115     //--------------------------------------------------------------------
00116     //Purpose:           Test the getDocumentUrl method.
00117     //Preconditions:   Document object.
00118     //Postconditions: Document getDocumentUrl method checked.
00119     //Arguments:       none.
00120     //Returns:           0.
00121     //Called Funcs:   Document( URI, routine ), Document.getDocumentUrl(),
00122     //                      assert_eq().
00123     //--------------------------------------------------------------------
00124     void testGetDocumentUrl()
00125     {
00126         Document myDocument("http://infolab.uvt.nl/people/erics/docs/tech_clearinghouse.pdf", "pdf2ps");
00127         string myUrl = myDocument.getDocumentUrl();
00128         int match;  // to check matching strings.
00129         if ( myUrl == "http://infolab.uvt.nl/people/erics/docs/tech_clearinghouse.pdf" )
00130         {
00131             match = 0;
00132         }
00133         else
00134         {
00135             match = 1;
00136         }
00137         assert_eq("get Document url check", 0, match);
00138     }
00139 
00140     //--------------------------------------------------------------------
00141     //Purpose:           Test the getDocumentFile method.
00142     //Preconditions:   Document object.
00143     //Postconditions: Document getDocumentFile method checked.
00144     //Arguments:       none.
00145     //Returns:           0.
00146     //Called Funcs:   Document( URI, routine ), Document.getDocumentFile(),
00147     //                      assert_eq().
00148     //--------------------------------------------------------------------
00149     void testGetDocumentFile()
00150     {
00151         Document myDocument("http://infolab.uvt.nl/people/erics/docs/tech_clearinghouse.pdf", "pdf2ps");
00152         string myFile = myDocument.getDocumentFile();
00153         int match;  // to check matching strings.
00154         if ( myFile == "tech_clearinghouse.pdf" )
00155         {
00156             match = 0;
00157         }
00158         else
00159         {
00160             match = 1;
00161         }
00162         assert_eq("get Document file check", 0, match);
00163     }
00164 
00165     //--------------------------------------------------------------------
00166     //Purpose:           Test the getDocumentConversion method.
00167     //Preconditions:   Document object.
00168     //Postconditions: Document getDocumentConversion method checked.
00169     //Arguments:       none.
00170     //Returns:           0.
00171     //Called Funcs:   Document( URI, routine ),
00172     //                     Document.getDocumentConversion(), assert_eq().
00173     //--------------------------------------------------------------------
00174     void testGetDocumentConversion()
00175     {
00176         Document myDocument("http://infolab.uvt.nl/people/erics/docs/tech_clearinghouse.pdf", "pdf2ps");
00177         string myConversion = myDocument.getDocumentConversion();
00178         int match;  // to check matching strings.
00179         if ( myConversion == "pdf2ps" )
00180         {
00181             match = 0;
00182         }
00183         else
00184         {
00185             match = 1;
00186         }
00187         assert_eq("get Document conversion check", 0, match);
00188     }
00189 
00190     //--------------------------------------------------------------------
00191     //Purpose:           Test the getConversionLocation method.
00192     //Preconditions:   Document object.
00193     //Postconditions: Document getConversionLocation method checked.
00194     //Arguments:       none.
00195     //Returns:           0.
00196     //Called Funcs:   Document( URI, routine ),
00197     //                     Document.setConversionLocation(),
00198     //                     Document.getConversionLocation(), assert_eq().
00199     //--------------------------------------------------------------------
00200     void testGetDocumentConLocation()
00201     {
00202         Document myDocument("http://infolab.uvt.nl/people/erics/docs/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 myDocument("http://infolab.uvt.nl/people/erics/docs/tech_clearinghouse.pdf", "pdf2ps");
00230         myDocument.setFileLocation("/tmp");
00231         string myFileLocation = myDocument.getFileLocation();
00232         int match;  // to check matching strings.
00233         if ( myFileLocation == "/tmp" )
00234         {
00235             match = 0;
00236         }
00237         else
00238         {
00239             match = 1;
00240         }
00241         assert_eq("get Document file location check", 0, match);
00242     }
00243 
00244     //--------------------------------------------------------------------
00245     //Purpose:           Test the convertDocument method.
00246     //Preconditions:   Broker and Document objects.
00247     //Postconditions: Document convertDocument method checked.
00248     //Arguments:       none.
00249     //Returns:           0.
00250     //Called Funcs:   Document( URI, routine ), Broker(),
00251     //                     Broker.convertDocument(), assert_true().
00252     //--------------------------------------------------------------------
00253     void testConvertDocument()
00254     {
00255         Broker myBroker;
00256         Document myDocument("http://infolab.uvt.nl/people/erics/docs/tech_clearinghouse.pdf", "pdf2ps");
00257         if ( myBroker.convertDocument(myDocument) )
00258         {
00259             assert_true( "Conversion results", true );
00260         }
00261         else
00262         {
00263             assert_true( "Conversion results", false );
00264         }
00265     }
00266 
00267 public:
00268     BrokerTestSuite() : suite("BrokerTestSuite")
00269     {
00270         add
00271             ("DocumentGetDocumentConLocation", testcase(this, "testGetDocumentConLocation",
00272                     &BrokerTestSuite::testGetDocumentConLocation));
00273         add
00274             ("BrokerDecreaseCounter", testcase(this, "testDecreaseCounter",
00275                                                &BrokerTestSuite::testDecreaseCounter));
00276         add
00277             ("BrokerIncreaseCounter", testcase(this, "testIncreaseCounter",
00278                                                &BrokerTestSuite::testIncreaseCounter));
00279         add
00280             ("BrokerGetCounter", testcase(this, "testGetCounter",
00281                                           &BrokerTestSuite::testGetCounter));
00282         add
00283             ("BrokerGetFile", testcase(this, "testGetFile",
00284                                        &BrokerTestSuite::testGetFile));
00285         add
00286             ("DocumentGetDocumentUrl", testcase(this, "testGetDocumentUrl",
00287                                                 &BrokerTestSuite::testGetDocumentUrl));
00288         add
00289             ("DocumentGetDocumentFile", testcase(this, "testGetDocumentFile",
00290                                                  &BrokerTestSuite::testGetDocumentFile));
00291         add
00292             ("DocumentGetDocumentConversion", testcase(this, "testGetDocumentConversion",
00293                     &BrokerTestSuite::testGetDocumentConversion));
00294         add
00295             ("DocumentGetDocumentFileLocation", testcase(this, "testGetDocumentFileLocation",
00296                     &BrokerTestSuite::testGetDocumentFileLocation));
00297         add
00298             ("DocumentConvertDocument", testcase(this, "testConvertDocument",
00299                                                  &BrokerTestSuite::testConvertDocument));
00300         suite::main().add("BrokerTestSuite",this);
00301     }
00302 
00303 };
00304 
00305 BrokerTestSuite* theBrokerTest = new BrokerTestSuite();
00306 }
00307 

Generated on Tue Oct 7 15:52:48 2003 for docconversion.kdevelop by doxygen 1.3.3