1 /**************************************************************************
2 ** (c) Copyright 1999, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 ** FILE NAME : acltest.cpp
7 ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation
8 ** VERSION NUMBER : $Revision: 1.6 $
10 ** DESCRIPTION : Test routine for non-X classes
15 ***************************************************************************
16 ** ADMINISTRATIVE INFORMATION *
17 ********************************
18 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 ** CREATION DATE : Feb 06, 1998
20 ** LAST UPDATE : Jul 27, 2002
21 **************************************************************************/
23 /*****************************
25 Revision 1.6 2002-11-04 07:25:00 arjen
26 Use proper namespace for iostream classes
28 Revision 1.5 2002/11/03 13:19:33 arjen
29 New functions - String::escape() and String::unescape()
31 Revision 1.4 2002/09/26 14:48:46 arjen
32 Use the std: namespace for STL objects
34 Revision 1.3 2002/09/02 06:18:12 arjen
35 Fixed some date and time conversion functions
37 Revision 1.2 2002/07/27 06:34:06 arjen
38 Removed the obsolete complex number test from acltest.
39 BUG FIX: testaxe crashed when no configuration file is available.
41 Revision 1.1 2002/07/25 08:01:18 arjen
42 First checkin, AXE release 0.2
44 *****************************/
46 static const char *RCSID = "$Id: acltest.cpp,v 1.6 2002-11-04 07:25:00 arjen Exp $";
53 String hello = "Hello there";
54 String points, pattern;
56 std::cout << hello << ",length= " << ~hello << "\n";
57 std::cout << "4th character = " << hello[3] << " (Changed to L)\n";
61 std::cout << "Points is not empty\n";
63 std::cout << "Points is empty\n";
67 std::cout << "after assignment: Points is not empty\n";
69 std::cout << "after assignment: points is empty\n";
71 hello += points + String("!??");
72 std::cout << "Catenated: " << hello << ",length= " << ~hello << "\n";
74 std::cout << "Substring(10,3) = " << String(hello(10,3)) << "\n";
77 std::cout << "hello(10,3)=points ->hello = " << hello << "\n";
78 std::cout << "Substring(8,9) = " << String(hello(8,9)) << "\n";
80 std::cout << "Converted to upper case: " << hello.upper() << "\n";
81 std::cout << "Converted to lower case: " << hello.lower() << "\n";
84 std::cout << "hello(8,9)=__ ->hello = " << hello << "\n";
86 std::cout << "Removing with hello(8,7) = \"\": " << hello << "\n";
88 std::cout << "Inserting with hello(8,0) = \"ere \": " << hello << "\n";
89 hello(5, ~hello-5) = "";
90 std::cout << "Truncating with hello(5, ~hello-5) = \"\": " << hello << "\n";
92 std::cout << "String shifting:\n";
96 std::cout << x << " << 3 = " << y << "\n";
98 std::cout << x << " >> 3 = " << y << "\n";
100 std::cout << "\nInput a string:\n";
102 std::cout << hello << "\n\n";
103 std::cout << "\nAnd another one:\n";
105 std::cout << pattern << "\n\n";
106 std::cout << "Second string found at position " << pattern.in(hello);
107 std::cout << " of first string.\n";
109 std::cout << "Construct a string from an int: ";
111 std::cout << num << "\n";
113 std::cout << "***********************\nEscape Test\n*********************\n";
115 x = "\a\b\f\n\r\t\v\"'\\\xC0\x02";
117 std::cout << "Escaped sequence = " << y << "\n";
118 if (y.unescape() == x)
120 std::cout << "Escape sequence converts back into original string.\n";
124 std::cout << "Escape sequence does NOT convert back into original string.\n";
126 std::cout << x.escape() << "\n";
129 std::cout << "***********************\nDate Test\n*********************\n";
131 date d1, d2(22,7,1964);
133 std::cout << "Default constructor: " << d1 << ", with (d,m,y): " << d2 << "\n";
134 std::cout << "Enter a date: \n";
138 std::cin >> datestring;
139 d2 = date(datestring);
141 std::cout << datestring << " parses into (DD-MM-YYYY): " << d2 << "\n";
142 datestring = d2.format("%F");
143 std::cout << "Formatted date: " << datestring << "\n";
147 std::cout << "Size of a date is " << sizeof(d1) << "\n";
149 std::cout << "365 days after " << d2 << " is " << d2 + 365 << "\n";
152 std::cout << "365 days was converted to " << d3 << "\n";
153 std::cout << "Added to the date you entered: " << d2 + d3 << "\n";
155 std::cout << d2 << " == " << d1 << " is " << (d2 == d1) << "\n";
156 std::cout << d2 << " != " << d1 << " is " << (d2 != d1) << "\n";
157 std::cout << d2 << " >= " << d1 << " is " << (d2 >= d1) << "\n";
158 std::cout << d2 << " <= " << d1 << " is " << (d2 <= d1) << "\n";
159 std::cout << d2 << " > " << d1 << " is " << (d2 > d1) << "\n";
160 std::cout << d2 << " < " << d1 << " is " << (d2 < d1) << "\n";
162 std::cout << "difference is " << d2 - d1 << " days.\n\n";
164 std::cout << "***********************\nTime Test\n*********************\n";
168 std::cout << "Default constructor: " << t1 << "\n";
169 t1 = hour(10, 50, 30);
170 std::cout << "With 10,50,30: " << t1 << "\n";
171 std::cout << "Enter a time: \n";
173 std::cin >> datestring;
174 t2 = hour(datestring);
176 std::cout << datestring << " parses into (HH:MM:SS): " << t2 << "\n";
178 std::cout << "t1 + t2 = " << t1 + t2 << "\n";
179 std::cout << "t1 - t2 = " << t1 - t2 << "\n";
180 std::cout << "t2 - t1 = " << t2 - t1 << "\n";
185 std::cout << "\nThe time now is " << d1 << " " << t1 << "\n";