Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

88 lines
3.2KB

  1. /**
  2. * Copyright (c) 20011-2017 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #include <SdFatTestSuite.h>
  26. static uint16_t failCount;
  27. static uint16_t testCount;
  28. static Print* testOut = &Serial;
  29. //------------------------------------------------------------------------------
  30. static size_t strlenPGM(PGM_P str) {
  31. PGM_P end = str;
  32. while (pgm_read_byte(end++)) {}
  33. return end - str;
  34. }
  35. //------------------------------------------------------------------------------
  36. void testBegin() {
  37. Serial.begin(9600);
  38. while (!Serial) {} // wait for leonardo
  39. testOut = &Serial;
  40. Serial.println(F("Type any character to begin."));
  41. while (Serial.read() <= 0) {}
  42. delay(200); // Catch Due reset problem
  43. testOut->print(F("FreeStack: "));
  44. testOut->println(FreeStack());
  45. testOut->println();
  46. failCount = 0;
  47. testCount = 0;
  48. }
  49. //------------------------------------------------------------------------------
  50. void testEnd() {
  51. testOut->println();
  52. testOut->println(F("Compiled: " __DATE__ " " __TIME__));
  53. testOut->print(F("FreeStack: "));
  54. testOut->println(FreeStack());
  55. testOut->print(F("Test count: "));
  56. testOut->println(testCount);
  57. testOut->print(F("Fail count: "));
  58. testOut->println(failCount);
  59. }
  60. //------------------------------------------------------------------------------
  61. static void testResult(bool b, uint8_t n) {
  62. while (n++ < 60) testOut->write(' ');
  63. if (b) {
  64. testOut->println(F("..ok"));
  65. } else {
  66. testOut->println(F("FAIL"));
  67. failCount++;
  68. }
  69. testCount++;
  70. }
  71. //------------------------------------------------------------------------------
  72. void testVerify_P(char* result, PGM_P expect) {
  73. testOut->write('"');
  74. testOut->print(result);
  75. testOut->print("\",\"");
  76. testOut->print((const __FlashStringHelper*)expect);
  77. testOut->write('"');
  78. uint8_t n = strlen(result) + strlenPGM(expect) + 5;
  79. testResult(!strcmp_P(result, expect), n);
  80. }
  81. //------------------------------------------------------------------------------
  82. void testVerify_P(bool b, PGM_P msg) {
  83. testOut->print((const __FlashStringHelper*)msg);
  84. uint8_t n = strlenPGM(msg);
  85. testResult(b, n);
  86. }