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