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.

SdFatTestSuite.cpp 2.7KB

10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
10 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Arduino SdFat Library
  2. * Copyright (C) 2011 by William Greiman
  3. *
  4. * This file is part of the Arduino SdFat Library
  5. *
  6. * This Library is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This Library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Arduino SdFat Library. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. */
  20. #include <SdFatTestSuite.h>
  21. static uint16_t failCount;
  22. static uint16_t testCount;
  23. static Print* testOut = &Serial;
  24. //------------------------------------------------------------------------------
  25. static size_t strlenPGM(PGM_P str) {
  26. PGM_P end = str;
  27. while (pgm_read_byte(end++)) {}
  28. return end - str;
  29. }
  30. //------------------------------------------------------------------------------
  31. void testBegin() {
  32. Serial.begin(9600);
  33. while (!Serial) {} // wait for leonardo
  34. testOut = &Serial;
  35. Serial.println(F("Type any character to begin."));
  36. while (Serial.read() <= 0) {}
  37. delay(200); // Catch Due reset problem
  38. testOut->print(F("FreeRam: "));
  39. testOut->println(FreeRam());
  40. testOut->println();
  41. failCount = 0;
  42. testCount = 0;
  43. }
  44. //------------------------------------------------------------------------------
  45. void testEnd() {
  46. testOut->println();
  47. testOut->println(F("Compiled: " __DATE__ " " __TIME__));
  48. testOut->print(F("FreeRam: "));
  49. testOut->println(FreeRam());
  50. testOut->print(F("Test count: "));
  51. testOut->println(testCount);
  52. testOut->print(F("Fail count: "));
  53. testOut->println(failCount);
  54. }
  55. //------------------------------------------------------------------------------
  56. static void testResult(bool b, uint8_t n) {
  57. while (n++ < 60) testOut->write(' ');
  58. if (b) {
  59. testOut->println(F("..ok"));
  60. } else {
  61. testOut->println(F("FAIL"));
  62. failCount++;
  63. }
  64. testCount++;
  65. }
  66. //------------------------------------------------------------------------------
  67. void testVerify_P(char* result, PGM_P expect) {
  68. testOut->write('"');
  69. testOut->print(result);
  70. testOut->print("\",\"");
  71. testOut->print((const __FlashStringHelper*)expect);
  72. testOut->write('"');
  73. uint8_t n = strlen(result) + strlenPGM(expect) + 5;
  74. testResult(!strcmp_P(result, expect), n);
  75. }
  76. //------------------------------------------------------------------------------
  77. void testVerify_P(bool b, PGM_P msg) {
  78. testOut->print((const __FlashStringHelper*)msg);
  79. uint8_t n = strlenPGM(msg);
  80. testResult(b, n);
  81. }