Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / utility / tst_streambuf.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 // $XConsortium: tst_streambuf.C /main/4 1996/08/21 15:55:40 drk $
24
25 #include <iostream.h>
26
27 #include "utility/debug.h"
28 #include "utility/c_charbuf.h"
29
30
31 streambuf_test1()
32 {
33    MESSAGE(cerr, "TEST 1");
34    char buf[5];
35    charbuf sb(buf, 5);
36
37    sb.put('a');
38    sb.put('b');
39    sb.put('c');
40
41    MESSAGE(cerr, "examine char a:");
42    debug(cerr, (char)sb.examine());
43
44    MESSAGE(cerr, "get char a:");
45    int c = sb.get();
46    debug(cerr, (char)c);
47
48    sb.put('d');
49    sb.put('e');
50
51    sb.putback(c);
52    MESSAGE(cerr, "putback char a:");
53    debug(cerr, (char)c);
54
55    MESSAGE(cerr, "get char a - e:");
56    debug(cerr, (char)sb.get());
57    debug(cerr, (char)sb.get());
58    debug(cerr, (char)sb.get());
59    debug(cerr, (char)sb.get());
60    debug(cerr, (char)sb.get());
61 }
62
63 streambuf_test2()
64 {
65    MESSAGE(cerr, "TEST 2");
66    char buf[5];
67    charbuf sb(buf, 5);
68
69    sb.put(0);
70    sb.put(1);
71
72    MESSAGE(cerr, "get 0:");
73    debug(cerr, sb.get());
74    MESSAGE(cerr, "get 1:");
75    debug(cerr, sb.get());
76    MESSAGE(cerr, "get -1:");
77    debug(cerr, sb.get());
78
79    sb.putback(2);
80    MESSAGE(cerr, "get 2:");
81    debug(cerr, sb.get());
82 }
83
84 streambuf_test3()
85 {
86    MESSAGE(cerr, "TEST 3");
87    char buf[5];
88    charbuf sb(buf, 5);
89
90    MESSAGE(cerr, "return 0:");
91    debug(cerr, sb.put(0));
92    MESSAGE(cerr, "return 0:");
93    debug(cerr, sb.put(1));
94    MESSAGE(cerr, "return 0:");
95    debug(cerr, sb.put(2));
96    MESSAGE(cerr, "return 0:");
97    debug(cerr, sb.put(3));
98    MESSAGE(cerr, "return 0:");
99    debug(cerr, sb.put(4));
100    MESSAGE(cerr, "return -1:");
101    debug(cerr, sb.put(5));
102    MESSAGE(cerr, "return -1:");
103    debug(cerr, sb.put(6));
104 }
105
106 streambuf_test4()
107 {
108    MESSAGE(cerr, "TEST 4");
109    char buf[5];
110    charbuf sb(buf, 5);
111
112    debug(cerr, sb.putback(0));
113    debug(cerr, sb.putback(1));
114    debug(cerr, sb.putback(2));
115    debug(cerr, sb.putback(3));
116    debug(cerr, sb.putback(4));
117
118    MESSAGE(cerr, "get 4:");
119    debug(cerr, sb.get());
120    MESSAGE(cerr, "get 3:");
121    debug(cerr, sb.get());
122    MESSAGE(cerr, "get 2:");
123    debug(cerr, sb.get());
124    MESSAGE(cerr, "get 1:");
125    debug(cerr, sb.get());
126    MESSAGE(cerr, "get 0:");
127    debug(cerr, sb.get());
128 }
129
130 main()
131 {
132    streambuf_test1();
133    streambuf_test2();
134    streambuf_test3();
135    streambuf_test4();
136 }