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

test-date.cc

00001 /*
00002 *  Name:         test-date.cc
00003 *  Author:       Francisco Rodrigo Escobedo Robles
00004 *  Contributor:  Rafael Jesus Alcantara Perez
00005 *  Summary:      Base date class
00006 *  Date:         $Date: 2003/04/14 00:18:36 $
00007 *  Revision:     $Revision: 1.1 $
00008 *
00009 *  Copyright (C) 2000  Francisco Rodrigo Escobedo Robles <frer@dedalo-ing.com>
00010 *  Copyright (C) 2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00011 *
00012 *  This program is free software; you can redistribute it and/or modify
00013 *  it under the terms of the GNU General Public License as published by
00014 *  the Free Software Foundation; either version 2 of the License, or
00015 *  (at your option) any later version.
00016 *
00017 *  This program is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  You should have received a copy of the GNU General Public License
00023 *  along with this program; if not, write to the Free Software
00024 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00025 *  MA 02111-1307, USA.
00026 */
00027 
00028 #include <mpcl/text/gmt_date.hh>
00029 #include <mpcl/text/local_date.hh>
00030 #include <mpcl/test.h>
00031 
00032 
00034 int main (void)
00035 {
00036 
00037   using mpcl::text::IDate;
00038   using mpcl::text::TGmtDate;
00039   using mpcl::text::TLocalDate;
00040   using mpcl::TConstraintException;
00041 
00042   bool         gExceptionTest;
00043   TGmtDate     tEmptyGmtDate  (IDate::eEmpty);
00044   TGmtDate     tGmtDate1999   (1999, 12, 31, 23, 59, 59);
00045   TGmtDate     tGmtDate2000   (2000,  1,  1,  0,  0,  0);
00046   TLocalDate   tLocalDate1999 (1999, 12, 31, 23, 59, 59);
00047   TLocalDate   tLocalDate2000 (2000,  1,  1,  0,  0,  0);
00048 
00049   TEST_INIT ("tests for classes 'TGmtDate' and 'TLocalDate'");
00050 
00051   //
00052   //  Supplied comparators.
00053   //
00054   TEST_NUMBERS (false, ( tGmtDate1999   == tGmtDate2000   ));
00055   TEST_NUMBERS (false, ( tGmtDate1999   >  tGmtDate2000   ));
00056   TEST_NUMBERS (false, ( tGmtDate1999   >= tGmtDate2000   ));
00057   TEST_NUMBERS (false, ( tLocalDate1999 == tLocalDate2000 ));
00058   TEST_NUMBERS (false, ( tLocalDate1999 >  tLocalDate2000 ));
00059   TEST_NUMBERS (false, ( tLocalDate1999 >= tLocalDate2000 ));
00060   TEST_NUMBERS (true,  ( tGmtDate1999   != tGmtDate2000   ));
00061   TEST_NUMBERS (true,  ( tGmtDate1999   <  tGmtDate2000   ));
00062   TEST_NUMBERS (true,  ( tGmtDate1999   <= tGmtDate2000   ));
00063   TEST_NUMBERS (true,  ( tLocalDate1999 != tLocalDate2000 ));
00064   TEST_NUMBERS (true,  ( tLocalDate1999 <  tLocalDate2000 ));
00065   TEST_NUMBERS (true,  ( tLocalDate1999 <= tLocalDate2000 ));
00066 
00067   //
00068   //  Rollover tests.
00069   //
00070   TEST_NUMBERS (true,  ( tGmtDate1999.addSeconds   (1) == tGmtDate2000   ));
00071   TEST_NUMBERS (true,  ( tLocalDate1999.addSeconds (1) == tLocalDate2000 ))
00072   TEST_NUMBERS (false, ( tGmtDate1999                  <  tGmtDate2000   ));
00073   TEST_NUMBERS (false, ( tLocalDate1999                <  tLocalDate2000 ));
00074 
00075   //
00076   //  Interval tests.
00077   //
00078   tGmtDate1999.set (1999, 12, 31, 23, 59, 59);
00079   tGmtDate2000.set (2000,  1,  1,  0,  0,  0);
00080   TEST_NUMBERS (true,  tGmtDate1999.in (tGmtDate1999,          tGmtDate1999));
00081   TEST_NUMBERS (false, tGmtDate1999.in (tGmtDate2000,          tGmtDate2000));
00082   TEST_NUMBERS (false, tGmtDate1999.in (tGmtDate2000,          tGmtDate1999));
00083   TEST_NUMBERS (true,  tGmtDate1999.in (TGmtDate (1970, 1, 1), tGmtDate2000));
00084   TEST_NUMBERS (true,  tGmtDate1999.in (TGmtDate (1970, 1, 1), tGmtDate1999));
00085   TEST_NUMBERS (false, tGmtDate2000.in (tGmtDate1999,          tGmtDate1999));
00086   TEST_NUMBERS (true,  tGmtDate2000.in (tGmtDate2000,          tGmtDate2000));
00087   TEST_NUMBERS (false, tGmtDate2000.in (tGmtDate2000,          tGmtDate1999));
00088   TEST_NUMBERS (true,  tGmtDate2000.in (TGmtDate (1970, 1, 1), tGmtDate2000));
00089   TEST_NUMBERS (false, tGmtDate2000.in (TGmtDate (1970, 1, 1), tGmtDate1999));
00090 
00091   //
00092   //  Tries to manipulate with empty dates.
00093   //
00094   try
00095   {
00096     TEST_NUMBERS (false, tGmtDate2000.in (tEmptyGmtDate, tEmptyGmtDate));
00097     TEST_FAIL;
00098   }
00099   catch (const TConstraintException& rktEXCEPTION)
00100   {
00101     TEST_PASS;
00102   }
00103   
00104   //
00105   //  Tries to manipulate an empty date.
00106   //
00107   try
00108   {
00109     TEST_NUMBERS (false, tEmptyGmtDate.in (tGmtDate1999, tGmtDate2000));
00110     TEST_FAIL;
00111   }
00112   catch (const TConstraintException& rktEXCEPTION)
00113   {
00114     TEST_PASS;
00115   }
00116   
00117   //
00118   //  Tries to manipulate an empty date.
00119   //
00120   try
00121   {
00122     tEmptyGmtDate.addSeconds (1);
00123     TEST_FAIL;
00124   }
00125   catch (const TConstraintException& rktEXCEPTION)
00126   {
00127     TEST_PASS;
00128   }
00129   try
00130   {
00131     //
00132     //  Tries to manipulate an empty date.
00133     //
00134     gExceptionTest = ( tEmptyGmtDate == tGmtDate2000 );
00135     TEST_FAIL;
00136   }
00137   catch (const TConstraintException& rktEXCEPTION)
00138   {
00139     TEST_PASS;
00140   }
00141   try
00142   {
00143     //
00144     //  Tries to manipulate an empty date.
00145     //
00146     gExceptionTest = ( tEmptyGmtDate <  tGmtDate2000 );
00147     TEST_FAIL;
00148   }
00149   catch (const TConstraintException& rktEXCEPTION)
00150   {
00151     TEST_PASS;
00152   }
00153 
00154   TEST_MEMORY_STATUS;
00155   TEST_RETURN_CODE;
00156 
00157 }  // main()

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