tst_streambuf.C 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 libraries 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. #include <iostream>
  25. using namespace std;
  26. #include "utility/debug.h"
  27. #include "utility/c_charbuf.h"
  28. streambuf_test1()
  29. {
  30. MESSAGE(cerr, "TEST 1");
  31. char buf[5];
  32. charbuf sb(buf, 5);
  33. sb.put('a');
  34. sb.put('b');
  35. sb.put('c');
  36. MESSAGE(cerr, "examine char a:");
  37. debug(cerr, (char)sb.examine());
  38. MESSAGE(cerr, "get char a:");
  39. int c = sb.get();
  40. debug(cerr, (char)c);
  41. sb.put('d');
  42. sb.put('e');
  43. sb.putback(c);
  44. MESSAGE(cerr, "putback char a:");
  45. debug(cerr, (char)c);
  46. MESSAGE(cerr, "get char a - e:");
  47. debug(cerr, (char)sb.get());
  48. debug(cerr, (char)sb.get());
  49. debug(cerr, (char)sb.get());
  50. debug(cerr, (char)sb.get());
  51. debug(cerr, (char)sb.get());
  52. }
  53. streambuf_test2()
  54. {
  55. MESSAGE(cerr, "TEST 2");
  56. char buf[5];
  57. charbuf sb(buf, 5);
  58. sb.put(0);
  59. sb.put(1);
  60. MESSAGE(cerr, "get 0:");
  61. debug(cerr, sb.get());
  62. MESSAGE(cerr, "get 1:");
  63. debug(cerr, sb.get());
  64. MESSAGE(cerr, "get -1:");
  65. debug(cerr, sb.get());
  66. sb.putback(2);
  67. MESSAGE(cerr, "get 2:");
  68. debug(cerr, sb.get());
  69. }
  70. streambuf_test3()
  71. {
  72. MESSAGE(cerr, "TEST 3");
  73. char buf[5];
  74. charbuf sb(buf, 5);
  75. MESSAGE(cerr, "return 0:");
  76. debug(cerr, sb.put(0));
  77. MESSAGE(cerr, "return 0:");
  78. debug(cerr, sb.put(1));
  79. MESSAGE(cerr, "return 0:");
  80. debug(cerr, sb.put(2));
  81. MESSAGE(cerr, "return 0:");
  82. debug(cerr, sb.put(3));
  83. MESSAGE(cerr, "return 0:");
  84. debug(cerr, sb.put(4));
  85. MESSAGE(cerr, "return -1:");
  86. debug(cerr, sb.put(5));
  87. MESSAGE(cerr, "return -1:");
  88. debug(cerr, sb.put(6));
  89. }
  90. streambuf_test4()
  91. {
  92. MESSAGE(cerr, "TEST 4");
  93. char buf[5];
  94. charbuf sb(buf, 5);
  95. debug(cerr, sb.putback(0));
  96. debug(cerr, sb.putback(1));
  97. debug(cerr, sb.putback(2));
  98. debug(cerr, sb.putback(3));
  99. debug(cerr, sb.putback(4));
  100. MESSAGE(cerr, "get 4:");
  101. debug(cerr, sb.get());
  102. MESSAGE(cerr, "get 3:");
  103. debug(cerr, sb.get());
  104. MESSAGE(cerr, "get 2:");
  105. debug(cerr, sb.get());
  106. MESSAGE(cerr, "get 1:");
  107. debug(cerr, sb.get());
  108. MESSAGE(cerr, "get 0:");
  109. debug(cerr, sb.get());
  110. }
  111. main()
  112. {
  113. streambuf_test1();
  114. streambuf_test2();
  115. streambuf_test3();
  116. streambuf_test4();
  117. }