Cleanup classes that are moved to ACL
[AXE.git] / demos / acltest.cpp
index 7121166..30b9e73 100644 (file)
@@ -5,7 +5,7 @@
 ***********************
 **      FILE NAME      : acltest.cpp
 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
-**      VERSION NUMBER : $Revision: 1.1 $
+**      VERSION NUMBER : $Revision: 1.6 $
 **
 **  DESCRIPTION      :  Test routine for non-X classes
 **
 ********************************
 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
 **      CREATION DATE   : Feb 06, 1998
-**      LAST UPDATE     : Oct 16, 1999
+**      LAST UPDATE     : Jul 27, 2002
 **************************************************************************/
 
 /*****************************
    $Log: acltest.cpp,v $
-   Revision 1.1  2002-07-25 08:01:18  arjen
+   Revision 1.6  2002-11-04 07:25:00  arjen
+   Use proper namespace for iostream classes
+
+   Revision 1.5  2002/11/03 13:19:33  arjen
+   New functions - String::escape() and String::unescape()
+
+   Revision 1.4  2002/09/26 14:48:46  arjen
+   Use the std: namespace for STL objects
+
+   Revision 1.3  2002/09/02 06:18:12  arjen
+   Fixed some date and time conversion functions
+
+   Revision 1.2  2002/07/27 06:34:06  arjen
+   Removed the obsolete complex number test from acltest.
+   BUG FIX: testaxe crashed when no configuration file is available.
+
+   Revision 1.1  2002/07/25 08:01:18  arjen
    First checkin, AXE release 0.2
 
 *****************************/
 
-static const char *RCSID = "$Id: acltest.cpp,v 1.1 2002-07-25 08:01:18 arjen Exp $";
+static const char *RCSID = "$Id: acltest.cpp,v 1.6 2002-11-04 07:25:00 arjen Exp $";
 
 #include "String.h"
-#include "integer.h" 
-#include "complex/complex.h" 
 #include "date.h"
 
 int main()
@@ -39,139 +53,135 @@ int main()
    String hello = "Hello there";
    String points, pattern;
 
-   cout << hello << ",length= " << ~hello << "\n";
-   cout << "4th character = " << hello[3] << " (Changed to L)\n";
+   std::cout << hello << ",length= " << ~hello << "\n";
+   std::cout << "4th character = " << hello[3] << " (Changed to L)\n";
    hello[3] = 'L';
    
    if ((char *)points)
-      cout  << "Points is not empty\n";
+      std::cout  << "Points is not empty\n";
    if (!points)
-      cout << "Points is empty\n";
+      std::cout << "Points is empty\n";
    points = "123456";
 
    if ((char *)points)
-      cout  << "after assignment: Points is not empty\n";
+      std::cout  << "after assignment: Points is not empty\n";
    if (!points)
-      cout << "after assignment: points is empty\n";
+      std::cout << "after assignment: points is empty\n";
 
    hello += points + String("!??");
-   cout << "Catenated: " << hello << ",length= " << ~hello << "\n";
+   std::cout << "Catenated: " << hello << ",length= " << ~hello << "\n";
 
-   cout << "Substring(10,3) = " << String(hello(10,3)) << "\n";
+   std::cout << "Substring(10,3) = " << String(hello(10,3)) << "\n";
 
    hello(10,3) = points;
-   cout << "hello(10,3)=points ->hello = " << hello << "\n";
-   cout << "Substring(8,9) = " << String(hello(8,9)) << "\n";
+   std::cout << "hello(10,3)=points ->hello = " << hello << "\n";
+   std::cout << "Substring(8,9) = " << String(hello(8,9)) << "\n";
 
-   cout << "Converted to upper case: " << hello.upper() << "\n";
-   cout << "Converted to lower case: " << hello.lower() << "\n";
+   std::cout << "Converted to upper case: " << hello.upper() << "\n";
+   std::cout << "Converted to lower case: " << hello.lower() << "\n";
 
    hello(8,9) = "__";
-   cout << "hello(8,9)=__ ->hello = " << hello << "\n";
+   std::cout << "hello(8,9)=__ ->hello = " << hello << "\n";
    hello(8,7) = "";
-   cout << "Removing with hello(8,7) = \"\": " << hello << "\n";
+   std::cout << "Removing with hello(8,7) = \"\": " << hello << "\n";
    hello(8,0) = "ere ";
-   cout << "Inserting with hello(8,0) = \"ere \": " << hello << "\n";
+   std::cout << "Inserting with hello(8,0) = \"ere \": " << hello << "\n";
    hello(5, ~hello-5) = "";
-   cout << "Truncating with hello(5, ~hello-5) = \"\": " << hello << "\n";
+   std::cout << "Truncating with hello(5, ~hello-5) = \"\": " << hello << "\n";
 
-   cout << "String shifting:\n";
+   std::cout << "String shifting:\n";
    String x("abcdefgh");
    String y;
    y = x << 3;
-   cout << x << " << 3 = " << y << "\n";
+   std::cout << x << " << 3 = " << y << "\n";
    y = x >> 3;
-   cout << x << " >> 3 = " << y << "\n";
-
-   cout << "\nInput a string:\n";
-   cin >> hello;
-   cout << hello << "\n\n";
-   cout << "\nAnd another one:\n";
-   cin >> pattern;
-   cout << pattern << "\n\n";
-   cout << "Second string found at position " << pattern.in(hello);
-   cout << " of first string.\n";
+   std::cout << x << " >> 3 = " << y << "\n";
+
+   std::cout << "\nInput a string:\n";
+   std::cin >> hello;
+   std::cout << hello << "\n\n";
+   std::cout << "\nAnd another one:\n";
+   std::cin >> pattern;
+   std::cout << pattern << "\n\n";
+   std::cout << "Second string found at position " << pattern.in(hello);
+   std::cout << " of first string.\n";
     
-   cout << "Construct a string from an int: ";
+   std::cout << "Construct a string from an int: ";
    String num(3737);
-   cout << num << "\n";
-
-   cout << "***********************\nInteger Test\n*********************\n";
-   integer a(2000000000), b(2048);
-   integer c;
-
-   cout << "a = " << a << ", b = " << b << "\n";
-   cout << "c = " << c << "\n";
-   c = b;
-   cout << "c = b : c = " << c << "\n";
-
-   cout << "***********************\nComplex Number Test\n*********************\n";
-
-#if 0
-   complex z1, z2, z3;
-   z1 = complex(1,0);
-   z2 = complex(0,1);
-   z3 = z1 + z2;
-   cout << z1 << " + " << z2 << " = " << z3 << "\n";
-   z3 = z1 - z2;
-   cout << z1 << " - " << z2 << " = " << z3 << "\n";
-   z3 = z1 * z2;
-   cout << z1 << " * " << z2 << " = " << z3 << "\n";
-   z3 = z1 / z2;
-   cout << z1 << " / " << z2 << " = " << z3 << "\n";
-#endif
-   
-   cout << "***********************\nDate Test\n*********************\n";
+   std::cout << num << "\n";
+
+   std::cout << "***********************\nEscape Test\n*********************\n";
+
+   x = "\a\b\f\n\r\t\v\"'\\\xC0\x02";
+   y = x.escape();
+   std::cout << "Escaped sequence = " << y << "\n";
+   if (y.unescape() == x)
+   {
+      std::cout << "Escape sequence converts back into original string.\n";
+   }
+   else
+   {
+      std::cout << "Escape sequence does NOT convert back into original string.\n";
+      x = y.unescape();
+      std::cout << x.escape() << "\n";
+   }
+
+   std::cout << "***********************\nDate Test\n*********************\n";
+
    date d1, d2(22,7,1964);
    
-   cout << "Default constructor: " << d1 << ", with (d,m,y): " << d2 << "\n";
-   cout << "Enter a date: \n";
+   std::cout << "Default constructor: " << d1 << ", with (d,m,y): " << d2 << "\n";
+   std::cout << "Enter a date: \n";
    
    String datestring;
 
-   cin  >> datestring;
+   std::cin  >> datestring;
    d2 = date(datestring);
 
-   cout << datestring << " parses into (DD-MM-YYYY): " << d2 << "\n";
-   datestring = d2.format();
-   cout << "Formatted date: " << datestring << "\n";
+   std::cout << datestring << " parses into (DD-MM-YYYY): " << d2 << "\n";
+   datestring = d2.format("%F");
+   std::cout << "Formatted date: " << datestring << "\n";
 
    d1 = today();
 
-   cout << "Size of a date is " << sizeof(d1) << "\n";
+   std::cout << "Size of a date is " << sizeof(d1) << "\n";
 
-   cout << "365 days after " << d2 << " is " << d2 + 365 << "\n";
+   std::cout << "365 days after " << d2 << " is " << d2 + 365 << "\n";
    date d3(0,0,0);
    d3 += 365;
-   cout << "365 days was converted to " << d3 << "\n";
-   cout << "Added to the date you entered: " << d2 + d3 << "\n";
+   std::cout << "365 days was converted to " << d3 << "\n";
+   std::cout << "Added to the date you entered: " << d2 + d3 << "\n";
 
-   cout << d2 << " == " << d1 << " is " << (d2 == d1) << "\n";
-   cout << d2 << " != " << d1 << " is " << (d2 != d1) << "\n";
-   cout << d2 << " >= " << d1 << " is " << (d2 >= d1) << "\n";
-   cout << d2 << " <= " << d1 << " is " << (d2 <= d1) << "\n";
-   cout << d2 << " >  " << d1 << " is " << (d2 >  d1) << "\n";
-   cout << d2 << " <  " << d1 << " is " << (d2 <  d1) << "\n";
+   std::cout << d2 << " == " << d1 << " is " << (d2 == d1) << "\n";
+   std::cout << d2 << " != " << d1 << " is " << (d2 != d1) << "\n";
+   std::cout << d2 << " >= " << d1 << " is " << (d2 >= d1) << "\n";
+   std::cout << d2 << " <= " << d1 << " is " << (d2 <= d1) << "\n";
+   std::cout << d2 << " >  " << d1 << " is " << (d2 >  d1) << "\n";
+   std::cout << d2 << " <  " << d1 << " is " << (d2 <  d1) << "\n";
 
-   cout << "difference is " << d2 - d1 << " days.\n\n";
+   std::cout << "difference is " << d2 - d1 << " days.\n\n";
 
-   cout << "***********************\nTime Test\n*********************\n";
+   std::cout << "***********************\nTime Test\n*********************\n";
 
    hour t1, t2;
 
-   cout << "Default constructor: " << t1 << "\n";
+   std::cout << "Default constructor: " << t1 << "\n";
    t1 = hour(10, 50, 30);
-   cout << "With 10,50,30: " << t1 << "\n";
-   cout << "Enter a time: \n";
+   std::cout << "With 10,50,30: " << t1 << "\n";
+   std::cout << "Enter a time: \n";
 
-   cin  >> datestring;
+   std::cin  >> datestring;
    t2 = hour(datestring);
 
-   cout << datestring << " parses into (HH:MM:SS): " << t2 << "\n";
+   std::cout << datestring << " parses into (HH:MM:SS): " << t2 << "\n";
 
-   cout << "t1 + t2 = " << t1 + t2 << "\n";
-   cout << "t1 - t2 = " << t1 - t2 << "\n";
-   cout << "t2 - t1 = " << t2 - t1 << "\n";
+   std::cout << "t1 + t2 = " << t1 + t2 << "\n";
+   std::cout << "t1 - t2 = " << t1 - t2 << "\n";
+   std::cout << "t2 - t1 = " << t2 - t1 << "\n";
+
+   d1 = today();
+   t1 = now();
 
+   std::cout << "\nThe time now is " << d1 << " " << t1 << "\n";
    return 0;
 }