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