You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
5.0KB

  1. #include <SPI.h>
  2. #include <SdFat.h>
  3. #include <SdFatTestSuite.h>
  4. //------------------------------------------------------------------------------
  5. void ostreamBool() {
  6. char buf[40];
  7. obufstream ob(buf, sizeof(buf));
  8. bool f = false;
  9. bool t = true;
  10. ob << t << ',' << f << ',' << setw(2) << t << ',' << left << setw(2) << f;
  11. testVerifyStr(buf, "1,0, 1,0 ");
  12. ob.init(buf, sizeof(buf));
  13. ob << boolalpha << t << ',' << f << ',' << setw(5) << t;
  14. ob << ',' << right << setw(6) << f;
  15. testVerifyStr(buf, "true,false,true , false");
  16. }
  17. //------------------------------------------------------------------------------
  18. void ostreamChar() {
  19. char buf[40];
  20. obufstream ob(buf, sizeof(buf));
  21. char c = 'c';
  22. signed char sc = 's';
  23. unsigned char uc = 'u';
  24. ob <<'l' << c << sc << uc;
  25. ob.put('p');
  26. testVerifyStr(buf, "lcsup");
  27. ob.init(buf, sizeof(buf));
  28. ob << 's' << setw(2) << 'r' << 'n' << left << setw(2) << 'l';
  29. ob << 'm' << right << setw(2) << 'e';
  30. testVerifyStr(buf, "s rnl m e");
  31. ob.init(buf, sizeof(buf));
  32. ob << setfill('f') << setw(5) << 'r';
  33. testVerifyStr(buf, "ffffr");
  34. }
  35. //------------------------------------------------------------------------------
  36. void ostreamFloat() {
  37. char buf[50];
  38. obufstream ob(buf, sizeof(buf));
  39. float f = 9.87654;
  40. double d = -123.4567;
  41. ob << f <<',';
  42. ob << internal << setw(10) << d << ',';
  43. ob << setfill('0') << setw(10) << d;
  44. testVerifyStr(buf, "9.88,- 123.46,-000123.46");
  45. ob.init(buf, sizeof(buf));
  46. ob << setw(10) << left << d << ',' << showpos << -d << ',';
  47. ob << setprecision(0) << d;
  48. testVerifyStr(buf, "-123.46000,+123.46,-123");
  49. ob.init(buf, sizeof(buf));
  50. ob << showpoint << d << noshowpoint << ',' << d << ',';
  51. ob << setprecision(4) << f << ',' << setprecision(2) << noshowpos << f;
  52. testVerifyStr(buf, "-123.,-123,+9.8765,9.88");
  53. }
  54. //------------------------------------------------------------------------------
  55. void ostreamNumber() {
  56. char buf[50];
  57. obufstream ob(buf, sizeof(buf));
  58. short s = 1;
  59. short signed ss = 2;
  60. short unsigned su = 3;
  61. int i = 4;
  62. int signed is = 5;
  63. int unsigned iu = 6;
  64. long l = 7;
  65. long signed ls = 8;
  66. long unsigned lu = 9;
  67. ob << s << ss << su << i << is << iu << l <<ls << lu;
  68. s = -1;
  69. ss = -2;
  70. i = -3;
  71. is = -4;
  72. l = -5;
  73. ls = -6;
  74. ob << s << ss << i << is << l <<ls;
  75. testVerifyStr(buf, "123456789-1-2-3-4-5-6");
  76. ob.init(buf, sizeof(buf));
  77. s = ss = 0X8000;
  78. i = is = sizeof(int) == 2 ? 0X8000 : 0X80000000;
  79. l = ls = 0X80000000;
  80. su = iu = lu = 0;
  81. ob << su << iu << lu << s << ss;
  82. testVerifyStr(buf, "000-32768-32768");
  83. ob.init(buf, sizeof(buf));
  84. ob << i << is;
  85. if (sizeof(int) == 2) {
  86. testVerifyStr(buf, "-32768-32768");
  87. } else {
  88. testVerifyStr(buf, "-2147483648-2147483648");
  89. }
  90. ob.init(buf, sizeof(buf));
  91. ob << l << ls;
  92. testVerifyStr(buf, "-2147483648-2147483648");
  93. ob.init(buf, sizeof(buf));
  94. s = ss = i = is = 0X7FFF;
  95. l = ls = 0X7FFFFFFF;
  96. su = iu = 0XFFFF;
  97. lu = 0XFFFFFFFF;
  98. ob << showpos << s << ss << i << is;
  99. testVerifyStr(buf, "+32767+32767+32767+32767");
  100. ob.init(buf, sizeof(buf));
  101. ob << l << ls;
  102. testVerifyStr(buf, "+2147483647+2147483647");
  103. ob.init(buf, sizeof(buf));
  104. ob << su << iu << lu;
  105. testVerifyStr(buf, "+65535+65535+4294967295");
  106. i = 0XABC;
  107. ob.init(buf, sizeof(buf));
  108. ob << noshowpos << hex << i << ',' << dec << i << ',' << oct << i;
  109. testVerifyStr(buf, "abc,2748,5274");
  110. ob.init(buf, sizeof(buf));
  111. ob << showbase << hex << i << ',' << dec << i << ',' << oct << i;
  112. testVerifyStr(buf, "0xabc,2748,05274");
  113. ob.init(buf, sizeof(buf));
  114. ob << showpos << uppercase << hex << i << ',' << dec << i << ',' << oct << i;
  115. testVerifyStr(buf, "0XABC,+2748,05274");
  116. is = -123;
  117. ob.init(buf, sizeof(buf));
  118. ob << internal << setfill('0');
  119. ob << setw(6) << hex << i << ',' << dec << setw(6) << i << ',';
  120. ob << setw(5) << is;
  121. testVerifyStr(buf, "0X0ABC,+02748,-0123");
  122. ob.init(buf, sizeof(buf));
  123. ob << setfill(' ') << left << setw(5) << is << ',' << right << setw(6) << is;
  124. testVerifyStr(buf, "-123 , -123");
  125. }
  126. //------------------------------------------------------------------------------
  127. void ostreamStr() {
  128. char buf[40];
  129. obufstream ob(buf, sizeof(buf));
  130. char c[] = "c";
  131. const char* cc = "CC";
  132. signed char* sc = (signed char*)"sc";
  133. const signed char* csc = (const signed char*)"CSC";
  134. unsigned char *uc = (unsigned char *)"uc";
  135. const unsigned char *cuc = (const unsigned char *)"CUC";
  136. ob << "lit" << c << cc << sc << csc << uc << cuc << F("F");
  137. testVerifyStr(buf, "litcCCscCSCucCUCF");
  138. ob.init(buf, sizeof(buf));
  139. ob << setfill('*') << "s" << setw(8) << "right";
  140. ob << " " << left << setw(6) << "left" << "e";
  141. testVerifyStr(buf, "s***right left**e");
  142. }
  143. //------------------------------------------------------------------------------
  144. void setup() {
  145. testBegin();
  146. ostreamBool();
  147. ostreamChar();
  148. ostreamFloat();
  149. ostreamNumber();
  150. ostreamStr();
  151. testEnd();
  152. }
  153. //------------------------------------------------------------------------------
  154. void loop() {}