Cleanup classes that are moved to ACL
[AXE.git] / demos / acltest.cpp
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 $
9 **
10 **  DESCRIPTION      :  Test routine for non-X classes
11 **
12 **  EXPORTED OBJECTS : 
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
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 **************************************************************************/
22
23 /*****************************
24    $Log: acltest.cpp,v $
25    Revision 1.6  2002-11-04 07:25:00  arjen
26    Use proper namespace for iostream classes
27
28    Revision 1.5  2002/11/03 13:19:33  arjen
29    New functions - String::escape() and String::unescape()
30
31    Revision 1.4  2002/09/26 14:48:46  arjen
32    Use the std: namespace for STL objects
33
34    Revision 1.3  2002/09/02 06:18:12  arjen
35    Fixed some date and time conversion functions
36
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.
40
41    Revision 1.1  2002/07/25 08:01:18  arjen
42    First checkin, AXE release 0.2
43
44 *****************************/
45
46 static const char *RCSID = "$Id: acltest.cpp,v 1.6 2002-11-04 07:25:00 arjen Exp $";
47
48 #include "String.h"
49 #include "date.h"
50
51 int main()
52 {
53    String hello = "Hello there";
54    String points, pattern;
55
56    std::cout << hello << ",length= " << ~hello << "\n";
57    std::cout << "4th character = " << hello[3] << " (Changed to L)\n";
58    hello[3] = 'L';
59    
60    if ((char *)points)
61       std::cout  << "Points is not empty\n";
62    if (!points)
63       std::cout << "Points is empty\n";
64    points = "123456";
65
66    if ((char *)points)
67       std::cout  << "after assignment: Points is not empty\n";
68    if (!points)
69       std::cout << "after assignment: points is empty\n";
70
71    hello += points + String("!??");
72    std::cout << "Catenated: " << hello << ",length= " << ~hello << "\n";
73
74    std::cout << "Substring(10,3) = " << String(hello(10,3)) << "\n";
75
76    hello(10,3) = points;
77    std::cout << "hello(10,3)=points ->hello = " << hello << "\n";
78    std::cout << "Substring(8,9) = " << String(hello(8,9)) << "\n";
79
80    std::cout << "Converted to upper case: " << hello.upper() << "\n";
81    std::cout << "Converted to lower case: " << hello.lower() << "\n";
82
83    hello(8,9) = "__";
84    std::cout << "hello(8,9)=__ ->hello = " << hello << "\n";
85    hello(8,7) = "";
86    std::cout << "Removing with hello(8,7) = \"\": " << hello << "\n";
87    hello(8,0) = "ere ";
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";
91
92    std::cout << "String shifting:\n";
93    String x("abcdefgh");
94    String y;
95    y = x << 3;
96    std::cout << x << " << 3 = " << y << "\n";
97    y = x >> 3;
98    std::cout << x << " >> 3 = " << y << "\n";
99
100    std::cout << "\nInput a string:\n";
101    std::cin >> hello;
102    std::cout << hello << "\n\n";
103    std::cout << "\nAnd another one:\n";
104    std::cin >> pattern;
105    std::cout << pattern << "\n\n";
106    std::cout << "Second string found at position " << pattern.in(hello);
107    std::cout << " of first string.\n";
108     
109    std::cout << "Construct a string from an int: ";
110    String num(3737);
111    std::cout << num << "\n";
112
113    std::cout << "***********************\nEscape Test\n*********************\n";
114
115    x = "\a\b\f\n\r\t\v\"'\\\xC0\x02";
116    y = x.escape();
117    std::cout << "Escaped sequence = " << y << "\n";
118    if (y.unescape() == x)
119    {
120       std::cout << "Escape sequence converts back into original string.\n";
121    }
122    else
123    {
124       std::cout << "Escape sequence does NOT convert back into original string.\n";
125       x = y.unescape();
126       std::cout << x.escape() << "\n";
127    }
128
129    std::cout << "***********************\nDate Test\n*********************\n";
130
131    date d1, d2(22,7,1964);
132    
133    std::cout << "Default constructor: " << d1 << ", with (d,m,y): " << d2 << "\n";
134    std::cout << "Enter a date: \n";
135    
136    String datestring;
137
138    std::cin  >> datestring;
139    d2 = date(datestring);
140
141    std::cout << datestring << " parses into (DD-MM-YYYY): " << d2 << "\n";
142    datestring = d2.format("%F");
143    std::cout << "Formatted date: " << datestring << "\n";
144
145    d1 = today();
146
147    std::cout << "Size of a date is " << sizeof(d1) << "\n";
148
149    std::cout << "365 days after " << d2 << " is " << d2 + 365 << "\n";
150    date d3(0,0,0);
151    d3 += 365;
152    std::cout << "365 days was converted to " << d3 << "\n";
153    std::cout << "Added to the date you entered: " << d2 + d3 << "\n";
154
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";
161
162    std::cout << "difference is " << d2 - d1 << " days.\n\n";
163
164    std::cout << "***********************\nTime Test\n*********************\n";
165
166    hour t1, t2;
167
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";
172
173    std::cin  >> datestring;
174    t2 = hour(datestring);
175
176    std::cout << datestring << " parses into (HH:MM:SS): " << t2 << "\n";
177
178    std::cout << "t1 + t2 = " << t1 + t2 << "\n";
179    std::cout << "t1 - t2 = " << t1 - t2 << "\n";
180    std::cout << "t2 - t1 = " << t2 - t1 << "\n";
181
182    d1 = today();
183    t1 = now();
184
185    std::cout << "\nThe time now is " << d1 << " " << t1 << "\n";
186    return 0;
187 }