First checkin, AXE release 0.2
[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.1 $
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     : Oct 16, 1999
21 **************************************************************************/
22
23 /*****************************
24    $Log: acltest.cpp,v $
25    Revision 1.1  2002-07-25 08:01:18  arjen
26    First checkin, AXE release 0.2
27
28 *****************************/
29
30 static const char *RCSID = "$Id: acltest.cpp,v 1.1 2002-07-25 08:01:18 arjen Exp $";
31
32 #include "String.h"
33 #include "integer.h" 
34 #include "complex/complex.h" 
35 #include "date.h"
36
37 int main()
38 {
39    String hello = "Hello there";
40    String points, pattern;
41
42    cout << hello << ",length= " << ~hello << "\n";
43    cout << "4th character = " << hello[3] << " (Changed to L)\n";
44    hello[3] = 'L';
45    
46    if ((char *)points)
47       cout  << "Points is not empty\n";
48    if (!points)
49       cout << "Points is empty\n";
50    points = "123456";
51
52    if ((char *)points)
53       cout  << "after assignment: Points is not empty\n";
54    if (!points)
55       cout << "after assignment: points is empty\n";
56
57    hello += points + String("!??");
58    cout << "Catenated: " << hello << ",length= " << ~hello << "\n";
59
60    cout << "Substring(10,3) = " << String(hello(10,3)) << "\n";
61
62    hello(10,3) = points;
63    cout << "hello(10,3)=points ->hello = " << hello << "\n";
64    cout << "Substring(8,9) = " << String(hello(8,9)) << "\n";
65
66    cout << "Converted to upper case: " << hello.upper() << "\n";
67    cout << "Converted to lower case: " << hello.lower() << "\n";
68
69    hello(8,9) = "__";
70    cout << "hello(8,9)=__ ->hello = " << hello << "\n";
71    hello(8,7) = "";
72    cout << "Removing with hello(8,7) = \"\": " << hello << "\n";
73    hello(8,0) = "ere ";
74    cout << "Inserting with hello(8,0) = \"ere \": " << hello << "\n";
75    hello(5, ~hello-5) = "";
76    cout << "Truncating with hello(5, ~hello-5) = \"\": " << hello << "\n";
77
78    cout << "String shifting:\n";
79    String x("abcdefgh");
80    String y;
81    y = x << 3;
82    cout << x << " << 3 = " << y << "\n";
83    y = x >> 3;
84    cout << x << " >> 3 = " << y << "\n";
85
86    cout << "\nInput a string:\n";
87    cin >> hello;
88    cout << hello << "\n\n";
89    cout << "\nAnd another one:\n";
90    cin >> pattern;
91    cout << pattern << "\n\n";
92    cout << "Second string found at position " << pattern.in(hello);
93    cout << " of first string.\n";
94     
95    cout << "Construct a string from an int: ";
96    String num(3737);
97    cout << num << "\n";
98
99    cout << "***********************\nInteger Test\n*********************\n";
100    integer a(2000000000), b(2048);
101    integer c;
102
103    cout << "a = " << a << ", b = " << b << "\n";
104    cout << "c = " << c << "\n";
105    c = b;
106    cout << "c = b : c = " << c << "\n";
107
108    cout << "***********************\nComplex Number Test\n*********************\n";
109
110 #if 0
111    complex z1, z2, z3;
112    z1 = complex(1,0);
113    z2 = complex(0,1);
114    z3 = z1 + z2;
115    cout << z1 << " + " << z2 << " = " << z3 << "\n";
116    z3 = z1 - z2;
117    cout << z1 << " - " << z2 << " = " << z3 << "\n";
118    z3 = z1 * z2;
119    cout << z1 << " * " << z2 << " = " << z3 << "\n";
120    z3 = z1 / z2;
121    cout << z1 << " / " << z2 << " = " << z3 << "\n";
122 #endif
123    
124    cout << "***********************\nDate Test\n*********************\n";
125    date d1, d2(22,7,1964);
126    
127    cout << "Default constructor: " << d1 << ", with (d,m,y): " << d2 << "\n";
128    cout << "Enter a date: \n";
129    
130    String datestring;
131
132    cin  >> datestring;
133    d2 = date(datestring);
134
135    cout << datestring << " parses into (DD-MM-YYYY): " << d2 << "\n";
136    datestring = d2.format();
137    cout << "Formatted date: " << datestring << "\n";
138
139    d1 = today();
140
141    cout << "Size of a date is " << sizeof(d1) << "\n";
142
143    cout << "365 days after " << d2 << " is " << d2 + 365 << "\n";
144    date d3(0,0,0);
145    d3 += 365;
146    cout << "365 days was converted to " << d3 << "\n";
147    cout << "Added to the date you entered: " << d2 + d3 << "\n";
148
149    cout << d2 << " == " << d1 << " is " << (d2 == d1) << "\n";
150    cout << d2 << " != " << d1 << " is " << (d2 != d1) << "\n";
151    cout << d2 << " >= " << d1 << " is " << (d2 >= d1) << "\n";
152    cout << d2 << " <= " << d1 << " is " << (d2 <= d1) << "\n";
153    cout << d2 << " >  " << d1 << " is " << (d2 >  d1) << "\n";
154    cout << d2 << " <  " << d1 << " is " << (d2 <  d1) << "\n";
155
156    cout << "difference is " << d2 - d1 << " days.\n\n";
157
158    cout << "***********************\nTime Test\n*********************\n";
159
160    hour t1, t2;
161
162    cout << "Default constructor: " << t1 << "\n";
163    t1 = hour(10, 50, 30);
164    cout << "With 10,50,30: " << t1 << "\n";
165    cout << "Enter a time: \n";
166
167    cin  >> datestring;
168    t2 = hour(datestring);
169
170    cout << datestring << " parses into (HH:MM:SS): " << t2 << "\n";
171
172    cout << "t1 + t2 = " << t1 + t2 << "\n";
173    cout << "t1 - t2 = " << t1 - t2 << "\n";
174    cout << "t2 - t1 = " << t2 - t1 << "\n";
175
176    return 0;
177 }