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

test-variable_argument_array.cc

00001 /*
00002 *  Name:      test-variable_argument_array.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for Variable argument array
00005 *  Date:      $Date: 2003/04/14 00:18:36 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <iostream>
00027 #include <mpcl/test.h>
00028 #include <mpcl/util/variable_argument_array.hh>
00029 
00030 using mpcl::util::TVariableArgumentArray;
00031 
00032 
00033 class TItem
00034 {
00035 
00036   public:
00037 
00038     int   iValue;
00039     
00040 
00041   public:
00042 
00043     TItem (int iSOURCE_VALUE) :
00044       iValue (iSOURCE_VALUE)  {}
00045 
00046     TItem (void) :
00047       iValue (0) {}
00048 
00049 };  // class TItem
00050 
00051 
00052 static int _TestForInt (int iFIRST_PARAMETER...)
00053 {
00054 
00055   va_list                       tVa_list;
00056   TVariableArgumentArray<int>   tVAA_Int;
00057 
00058   TEST_INIT ("tests for class 'TVariableArgumentArray<int>'");
00059 
00060   va_start (tVa_list, iFIRST_PARAMETER);
00061   tVAA_Int.initialize (tVa_list);
00062   TEST_NUMBERS (iFIRST_PARAMETER, 0);
00063   TEST_NUMBERS (tVAA_Int [0],     1);
00064   TEST_NUMBERS (tVAA_Int [1],     2);
00065   TEST_NUMBERS (tVAA_Int [2],     3);
00066   TEST_NUMBERS (tVAA_Int [3],     4);
00067   TEST_NUMBERS (tVAA_Int [3],     4);
00068   TEST_NUMBERS (tVAA_Int [2],     3);
00069   TEST_NUMBERS (tVAA_Int [1],     2);
00070   TEST_NUMBERS (tVAA_Int [0],     1);
00071   TEST_NUMBERS (tVAA_Int.size(),  4);
00072   
00073   try
00074   {
00075     TEST_NUMBERS (tVAA_Int [4], 1);
00076     TEST_FAIL;
00077   }
00078   catch (...)
00079   {
00080     TEST_PASS;
00081   }  
00082   try
00083   {
00084     TEST_NUMBERS (tVAA_Int [5], 1);
00085     TEST_FAIL;
00086   }
00087   catch (...)
00088   {
00089     TEST_PASS;
00090   }  
00091   
00092   va_end (tVa_list);
00093   
00094   TEST_MEMORY_STATUS;
00095   TEST_RETURN_CODE;
00096 
00097 }  // _TestForInt()
00098 
00099 
00100 static int _TestForString (const char* pkcFIRST_PARAMETER...)
00101 {
00102 
00103   va_list                         tVa_list;
00104   TVariableArgumentArray<char*>   tVAA_PChar;
00105 
00106   TEST_INIT ("tests for class 'TVariableArgumentArray<char*>'");
00107 
00108   va_start (tVa_list, pkcFIRST_PARAMETER);
00109   tVAA_PChar.initialize (tVa_list);
00110   TEST_STRINGS (pkcFIRST_PARAMETER, "0");
00111   TEST_STRINGS (tVAA_PChar [0],     "1");
00112   TEST_STRINGS (tVAA_PChar [1],     "2");
00113   TEST_STRINGS (tVAA_PChar [2],     "3");
00114   TEST_STRINGS (tVAA_PChar [3],     "4");
00115   TEST_STRINGS (tVAA_PChar [3],     "4");
00116   TEST_STRINGS (tVAA_PChar [2],     "3");
00117   TEST_STRINGS (tVAA_PChar [1],     "2");
00118   TEST_STRINGS (tVAA_PChar [0],     "1");
00119   TEST_NUMBERS (tVAA_PChar.size(),  4);
00120   
00121   try
00122   {
00123     TEST_STRINGS (tVAA_PChar [4], "1");
00124     TEST_FAIL;
00125   }
00126   catch (...)
00127   {
00128     TEST_PASS;
00129   }  
00130   try
00131   {
00132     TEST_STRINGS (tVAA_PChar [5], "1");
00133     TEST_FAIL;
00134   }
00135   catch (...)
00136   {
00137     TEST_PASS;
00138   }  
00139   
00140   va_end (tVa_list);
00141   
00142   TEST_MEMORY_STATUS;
00143   TEST_RETURN_CODE;
00144 
00145 }  // _TestForString()
00146 
00147 
00148 static int _TestForItem (TItem* ptFIRST_PARAMETER_ITEM...)
00149 {
00150 
00151   va_list                          tVa_list;
00152   TVariableArgumentArray<TItem*>   tVAA_PTItem;
00153 
00154   TEST_INIT ("tests for class 'TVariableArgumentArray<TIem*>'");
00155 
00156   va_start (tVa_list, ptFIRST_PARAMETER_ITEM);
00157   tVAA_PTItem.initialize (tVa_list);
00158   TEST_NUMBERS (ptFIRST_PARAMETER_ITEM->iValue, 0);
00159   TEST_NUMBERS (tVAA_PTItem [0]->iValue,        1);
00160   TEST_NUMBERS (tVAA_PTItem [1]->iValue,        2);
00161   TEST_NUMBERS (tVAA_PTItem [2]->iValue,        3);
00162   TEST_NUMBERS (tVAA_PTItem [3]->iValue,        4);
00163   TEST_NUMBERS (tVAA_PTItem [3]->iValue,        4);
00164   TEST_NUMBERS (tVAA_PTItem [2]->iValue,        3);
00165   TEST_NUMBERS (tVAA_PTItem [1]->iValue,        2);
00166   TEST_NUMBERS (tVAA_PTItem [0]->iValue,        1);
00167   TEST_NUMBERS (tVAA_PTItem.size(),             4);
00168   
00169   try
00170   {
00171     TEST_NUMBERS (tVAA_PTItem [4]->iValue, 1);
00172     TEST_FAIL;
00173   }
00174   catch (...)
00175   {
00176     TEST_PASS;
00177   }  
00178   try
00179   {
00180     TEST_NUMBERS (tVAA_PTItem [5]->iValue, 1);
00181     TEST_FAIL;
00182   }
00183   catch (...)
00184   {
00185     TEST_PASS;
00186   }  
00187   
00188   va_end (tVa_list);
00189   
00190   TEST_MEMORY_STATUS;
00191   TEST_RETURN_CODE;
00192 
00193 }  // _TestForItem()
00194 
00195 
00196 int main (void)
00197 {
00198 
00199   TEST_INIT ("tests for class 'TVariableArgumentArray'");
00200 
00201   TItem                            tItem0 (0);
00202   TItem                            tItem1 (1);
00203   TItem                            tItem2 (2);
00204   TItem                            tItem3 (3);
00205   TItem                            tItem4 (4);
00206   TVariableArgumentArray<TItem*>   tVAA_PTItem;
00207 
00208   TEST_FUNCTION (_TestForInt    (0, 1, 2, 3, 4, NULL));
00209   TEST_FUNCTION (_TestForString ("0", "1", "2", "3", "4", NULL));
00210   TEST_FUNCTION (_TestForItem   (&tItem0, &tItem1, &tItem2, &tItem3, &tItem4, NULL));
00211 
00212   TEST_MEMORY_STATUS;
00213   TEST_RETURN_CODE;
00214 
00215 }  // main()

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18