daily_automated
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Copyright (c) 20011-2017 Bill Greiman
|
||||
* This file is part of the SdFat library for SD memory cards.
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include <SdFatTestSuite.h>
|
||||
static uint16_t failCount;
|
||||
static uint16_t testCount;
|
||||
static Print* testOut = &Serial;
|
||||
//------------------------------------------------------------------------------
|
||||
static size_t strlenPGM(PGM_P str) {
|
||||
PGM_P end = str;
|
||||
while (pgm_read_byte(end++)) {}
|
||||
return end - str;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void testBegin() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {} // wait for leonardo
|
||||
testOut = &Serial;
|
||||
Serial.println(F("Type any character to begin."));
|
||||
while (Serial.read() <= 0) {}
|
||||
delay(200); // Catch Due reset problem
|
||||
|
||||
testOut->print(F("FreeStack: "));
|
||||
testOut->println(FreeStack());
|
||||
testOut->println();
|
||||
failCount = 0;
|
||||
testCount = 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void testEnd() {
|
||||
testOut->println();
|
||||
testOut->println(F("Compiled: " __DATE__ " " __TIME__));
|
||||
testOut->print(F("FreeStack: "));
|
||||
testOut->println(FreeStack());
|
||||
testOut->print(F("Test count: "));
|
||||
testOut->println(testCount);
|
||||
testOut->print(F("Fail count: "));
|
||||
testOut->println(failCount);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
static void testResult(bool b, uint8_t n) {
|
||||
while (n++ < 60) testOut->write(' ');
|
||||
if (b) {
|
||||
testOut->println(F("..ok"));
|
||||
} else {
|
||||
testOut->println(F("FAIL"));
|
||||
failCount++;
|
||||
}
|
||||
testCount++;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void testVerify_P(char* result, PGM_P expect) {
|
||||
testOut->write('"');
|
||||
testOut->print(result);
|
||||
testOut->print("\",\"");
|
||||
testOut->print((const __FlashStringHelper*)expect);
|
||||
testOut->write('"');
|
||||
uint8_t n = strlen(result) + strlenPGM(expect) + 5;
|
||||
testResult(!strcmp_P(result, expect), n);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void testVerify_P(bool b, PGM_P msg) {
|
||||
testOut->print((const __FlashStringHelper*)msg);
|
||||
uint8_t n = strlenPGM(msg);
|
||||
testResult(b, n);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 20011-2017 Bill Greiman
|
||||
* This file is part of the SdFat library for SD memory cards.
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef SdFatTestSuite_h
|
||||
#define SdFatTestSuite_h
|
||||
#include "SdFat.h"
|
||||
#include "FreeStack.h"
|
||||
|
||||
#if defined(__arm__) && !defined(strcmp_P)
|
||||
#define strcmp_P(a, b) strcmp((a), (b))
|
||||
#endif // strcmp_P
|
||||
|
||||
#if defined(__arm__) && !defined(strncpy_P)
|
||||
#define strncpy_P(s, t, n) strncpy(s, t, n)
|
||||
#endif // strncpy_P
|
||||
|
||||
#if defined(__arm__) && !defined(strlen_P)
|
||||
#define strlen_P(str) strlen(str)
|
||||
#endif // strlen_P
|
||||
|
||||
#define testVerifyBool(result) testVerify_P(result, PSTR(#result))
|
||||
#define testVerifyMsg(result, msg) testVerify_P(result, PSTR(msg))
|
||||
#define testVerifyStr(result, expect) testVerify_P(result, PSTR(expect))
|
||||
|
||||
void testBegin();
|
||||
void testEnd();
|
||||
void testVerify_P(bool b, PGM_P msg);
|
||||
void testVerify_P(char* result, PGM_P expect);
|
||||
#endif // SdFatTestSuite_h
|
||||
@@ -0,0 +1,105 @@
|
||||
// modified from ArduinoTestSuite 0022 by William Greiman
|
||||
// Tests writing to and reading from a file, in particular the
|
||||
// the Stream implementation (e.g. read() and peek()).
|
||||
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatTestSuite.h>
|
||||
SdFat SD;
|
||||
#define ATS_PrintTestStatus(msg, b) testVerify_P(b, PSTR(msg))
|
||||
void setup() {
|
||||
boolean b;
|
||||
SdFile f;
|
||||
uint32_t fs;
|
||||
|
||||
testBegin();
|
||||
|
||||
ATS_PrintTestStatus("SD.begin()", b = SD.begin());
|
||||
if (!b) goto done;
|
||||
|
||||
SD.remove("test.txt");
|
||||
|
||||
f.open("test.txt", FILE_WRITE);
|
||||
ATS_PrintTestStatus("SD.open()", f.isOpen());
|
||||
if (!f.isOpen()) goto done;
|
||||
|
||||
f.print("abc");
|
||||
f.print("de");
|
||||
f.close();
|
||||
|
||||
f.open("test.txt", FILE_WRITE);
|
||||
ATS_PrintTestStatus("SD.open()", f.isOpen());
|
||||
if (!f.isOpen()) goto done;
|
||||
|
||||
f.print("fgh");
|
||||
f.close();
|
||||
|
||||
f.open("test.txt", O_READ);
|
||||
ATS_PrintTestStatus("SD.open()", f.isOpen());
|
||||
if (!f.isOpen()) goto done;
|
||||
fs =f.fileSize();
|
||||
ATS_PrintTestStatus("read()", f.read() == 'a');
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'b');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'b');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'c');
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'd');
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'd');
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'd');
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'd');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'd');
|
||||
ATS_PrintTestStatus("available()", f.curPosition() != fs);
|
||||
ATS_PrintTestStatus("read()", f.read() == 'e');
|
||||
ATS_PrintTestStatus("available()", f.curPosition() != fs);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'f');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'f');
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'g');
|
||||
ATS_PrintTestStatus("available()", f.curPosition() != fs);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'g');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'g');
|
||||
ATS_PrintTestStatus("available()", f.curPosition() != fs);
|
||||
ATS_PrintTestStatus("available()", f.curPosition() != fs);
|
||||
ATS_PrintTestStatus("available()", f.curPosition() != fs);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'h');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'h');
|
||||
ATS_PrintTestStatus("available()", f.curPosition() == fs);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == -1);
|
||||
ATS_PrintTestStatus("read()", f.read() == -1);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == -1);
|
||||
ATS_PrintTestStatus("read()", f.read() == -1);
|
||||
|
||||
f.close();
|
||||
|
||||
SD.remove("test2.txt");
|
||||
|
||||
f.open("test2.txt", FILE_WRITE);
|
||||
ATS_PrintTestStatus("SD.open()", f.isOpen());
|
||||
if (!f.isOpen()) goto done;
|
||||
|
||||
f.print("ABC");
|
||||
f.close();
|
||||
|
||||
f.open("test.txt", O_READ);
|
||||
ATS_PrintTestStatus("SD.open()", f.isOpen());
|
||||
if (!f.isOpen()) goto done;
|
||||
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'a');
|
||||
|
||||
f.close();
|
||||
|
||||
f.open("test2.txt", O_READ);
|
||||
ATS_PrintTestStatus("SD.open()", f.isOpen());
|
||||
if (!f.isOpen()) goto done;
|
||||
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'A');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'A');
|
||||
|
||||
f.close();
|
||||
|
||||
done:
|
||||
testEnd();
|
||||
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// modified from ArduinoTestSuite 0022 by William Greiman
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatTestSuite.h>
|
||||
SdFat SD;
|
||||
#define ATS_PrintTestStatus(msg, b) testVerify_P(b, PSTR(msg))
|
||||
|
||||
void setup() {
|
||||
boolean b;
|
||||
SdFile f;
|
||||
|
||||
testBegin();
|
||||
|
||||
ATS_PrintTestStatus("SD.begin()", b = SD.begin());
|
||||
if (!b) goto done;
|
||||
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.open()", f.open("asdf.txt", FILE_WRITE)); f.close();
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("/asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.remove()", SD.remove("asdf.txt"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
||||
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf"));
|
||||
ATS_PrintTestStatus("SD.mkdir()", SD.mkdir("asdf"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("/asdf"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf/"));
|
||||
ATS_PrintTestStatus("SD.rmdir()", SD.rmdir("asdf"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf"));
|
||||
|
||||
ATS_PrintTestStatus("SD.mkdir()", SD.mkdir("x/y/z"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x/"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x/y"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x/y/"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x/y/z"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x/y/z/"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("/x/y/z/"));
|
||||
ATS_PrintTestStatus("SD.rmdir()", SD.rmdir("x/y/z"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x/y"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y/z"));
|
||||
ATS_PrintTestStatus("SD.rmdir()", SD.rmdir("x/y/"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("x"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y/z"));
|
||||
ATS_PrintTestStatus("SD.rmdir()", SD.rmdir("/x"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y/z"));
|
||||
|
||||
ATS_PrintTestStatus("!SD.open()", !(f.open("asdf/asdf.txt", FILE_WRITE))); f.close();
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf/asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.mkdir()", SD.mkdir("asdf"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
||||
ATS_PrintTestStatus("SD.open()", f.open("asdf/asdf.txt", FILE_WRITE)); f.close();
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf/asdf.txt"));
|
||||
ATS_PrintTestStatus("!SD.rmdir()", !SD.rmdir("asdf"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf/asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.remove()", SD.remove("asdf/asdf.txt"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf/asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
||||
ATS_PrintTestStatus("SD.rmdir()", SD.rmdir("asdf"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf"));
|
||||
|
||||
done:
|
||||
|
||||
testEnd();
|
||||
|
||||
}
|
||||
void loop() {}
|
||||
@@ -0,0 +1,108 @@
|
||||
// modified from ArduinoTestSuite 0022 by William Greiman
|
||||
// Tests writing to and reading from a file, in particular the
|
||||
// the Stream implementation (e.g. read() and peek()).
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatTestSuite.h>
|
||||
SdFat SD;
|
||||
#define ATS_PrintTestStatus(msg, b) testVerify_P(b, PSTR(msg))
|
||||
|
||||
void setup() {
|
||||
boolean b;
|
||||
SdFile f;
|
||||
|
||||
testBegin();
|
||||
|
||||
ATS_PrintTestStatus("SD.begin()", b = SD.begin());
|
||||
if (!b) goto done;
|
||||
|
||||
SD.remove("test.txt");
|
||||
|
||||
f.open("test.txt", FILE_WRITE);
|
||||
ATS_PrintTestStatus("SD.open()", f.isOpen());
|
||||
if (!f.isOpen()) goto done;
|
||||
|
||||
ATS_PrintTestStatus("initial position", f.curPosition() == 0);
|
||||
ATS_PrintTestStatus("initial size", f.fileSize() == 0);
|
||||
|
||||
f.print("0123456789");
|
||||
|
||||
ATS_PrintTestStatus("position after writing", f.curPosition() == 10);
|
||||
ATS_PrintTestStatus("size after writing", f.fileSize() == 10);
|
||||
|
||||
f.seekSet(0);
|
||||
|
||||
ATS_PrintTestStatus("size after seek", f.fileSize() == 10);
|
||||
ATS_PrintTestStatus("position after seek", f.curPosition() == 0);
|
||||
|
||||
f.seekSet(7);
|
||||
|
||||
ATS_PrintTestStatus("position after seek", f.curPosition() == 7);
|
||||
ATS_PrintTestStatus("reading after seek", f.read() == '7');
|
||||
ATS_PrintTestStatus("position after reading after seeking", f.curPosition() == 8);
|
||||
ATS_PrintTestStatus("reading after reading after seeking", f.read() == '8');
|
||||
|
||||
f.seekSet(3);
|
||||
|
||||
ATS_PrintTestStatus("position after seeking", f.curPosition() == 3);
|
||||
ATS_PrintTestStatus("peeking after seeking", f.peek() == '3');
|
||||
ATS_PrintTestStatus("position after peeking after seeking", f.curPosition() == 3);
|
||||
ATS_PrintTestStatus("peeking after peeking after seeking", f.peek() == '3');
|
||||
ATS_PrintTestStatus("position after peeking after seeking", f.curPosition() == 3);
|
||||
ATS_PrintTestStatus("peeking after peeking after seeking", f.read() == '3');
|
||||
ATS_PrintTestStatus("position after peeking after seeking", f.curPosition() == 4);
|
||||
|
||||
f.seekSet(1);
|
||||
|
||||
ATS_PrintTestStatus("position after seeking", f.curPosition() == 1);
|
||||
ATS_PrintTestStatus("peeking after seeking", f.peek() == '1');
|
||||
|
||||
f.seekSet(4);
|
||||
|
||||
ATS_PrintTestStatus("position after seeking", f.curPosition() == 4);
|
||||
ATS_PrintTestStatus("peeking after seeking", f.peek() == '4');
|
||||
|
||||
f.seekSet(7);
|
||||
|
||||
ATS_PrintTestStatus("position()", f.curPosition() == 7);
|
||||
ATS_PrintTestStatus("read()", f.read() == '7');
|
||||
|
||||
f.seekSet(0);
|
||||
f.peek();
|
||||
f.print("AB");
|
||||
|
||||
ATS_PrintTestStatus("position()", f.curPosition() == 2);
|
||||
ATS_PrintTestStatus("size()", f.fileSize() == 10);
|
||||
ATS_PrintTestStatus("read()", f.read() == '2');
|
||||
|
||||
f.seekSet(0);
|
||||
|
||||
ATS_PrintTestStatus("read()", f.read() == 'A');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'B');
|
||||
ATS_PrintTestStatus("read()", f.read() == '2');
|
||||
|
||||
f.close();
|
||||
|
||||
f.open("test.txt", O_READ);
|
||||
ATS_PrintTestStatus("SD.open()", f.isOpen());
|
||||
if (!f.isOpen()) goto done;
|
||||
|
||||
ATS_PrintTestStatus("position()", f.curPosition() == 0);
|
||||
ATS_PrintTestStatus("size()", f.fileSize() == 10);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'A');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'A');
|
||||
|
||||
f.seekSet(4);
|
||||
|
||||
ATS_PrintTestStatus("position()", f.curPosition() == 4);
|
||||
ATS_PrintTestStatus("size()", f.fileSize() == 10);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == '4');
|
||||
ATS_PrintTestStatus("read()", f.read() == '4');
|
||||
|
||||
f.close();
|
||||
|
||||
done:
|
||||
testEnd();
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
@@ -0,0 +1,76 @@
|
||||
// This stress test will create and write files until the SD is full.
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
|
||||
// SD chip select pin.
|
||||
const uint8_t SD_CS_PIN = SS;
|
||||
|
||||
// Set write buffer size.
|
||||
#ifdef __arm__
|
||||
#ifndef CORE_TEENSY
|
||||
// Due
|
||||
const size_t BUF_SIZE = 32768;
|
||||
#else // CORE_TEENSY
|
||||
// Teensy 3.0
|
||||
const size_t BUF_SIZE = 8192;
|
||||
#endif // CORE_TEENSY
|
||||
#elif defined(RAMEND) && RAMEND > 5000
|
||||
// AVR with more than 4 KB RAM
|
||||
const size_t BUF_SIZE = 4096;
|
||||
#else // __arm__
|
||||
// other
|
||||
const size_t BUF_SIZE = 512;
|
||||
#endif // __arm__
|
||||
|
||||
const size_t FILE_SIZE_KB = 10240;
|
||||
const uint16_t BUFS_PER_FILE = (1024L*FILE_SIZE_KB/BUF_SIZE);
|
||||
|
||||
SdFat sd;
|
||||
|
||||
SdFile file;
|
||||
|
||||
uint8_t buf[BUF_SIZE];
|
||||
char name[13];
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.print("BUF_SIZE ");
|
||||
Serial.println(BUF_SIZE);
|
||||
Serial.println("Type any character to start");
|
||||
while (Serial.read() < 0) {}
|
||||
|
||||
if (!sd.begin(SD_CS_PIN))sd.errorHalt("sd.begin");
|
||||
|
||||
// Fill buf with known value.
|
||||
for (size_t i = 0; i < BUF_SIZE; i++) buf[i] = i;
|
||||
|
||||
// Wait to begin.
|
||||
do {delay(10);} while (Serial.read() >= 0);
|
||||
Serial.println("Type any character to stop after next file");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {
|
||||
// Free KB on SD.
|
||||
uint32_t freeKB = sd.vol()->freeClusterCount()*sd.vol()->blocksPerCluster()/2;
|
||||
|
||||
Serial.print("Free KB: ");
|
||||
Serial.println(freeKB);
|
||||
if (freeKB < 2*FILE_SIZE_KB) {
|
||||
Serial.println(" Done!");
|
||||
while(1);
|
||||
}
|
||||
sprintf(name, "%lu.DAT", freeKB);
|
||||
if (!file.open(name, O_WRITE | O_CREAT | O_TRUNC)) {
|
||||
sd.errorHalt("Open error!");
|
||||
}
|
||||
for (uint16_t i = 0; i < BUFS_PER_FILE; i++) {
|
||||
if (file.write(buf, BUF_SIZE) != BUF_SIZE) {
|
||||
sd.errorHalt("Write error!");
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
if (Serial.available()) {
|
||||
Serial.println("Stopped!");
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* This sketch is a test of subdirectory and file creation.
|
||||
* It also tests allocation of clusters to directories.
|
||||
*
|
||||
* It will create two subdirectories and create enough files
|
||||
* to force the allocation of a cluster to each directory.
|
||||
*
|
||||
* More than 3000 files may be created on a FAT32 volume.
|
||||
*
|
||||
* Note: Some cards may 'stutter' others just get slow due
|
||||
* to the number of flash erases this program causes.
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatUtil.h>
|
||||
|
||||
const uint8_t SD_CHIP_SELECT = SS;
|
||||
|
||||
SdFat sd;
|
||||
|
||||
// store error strings in flash to save RAM
|
||||
#define error(s) sd.errorHalt(F(s))
|
||||
|
||||
/*
|
||||
* create enough files to force a cluster to be allocated to dir.
|
||||
*/
|
||||
void dirAllocTest(FatFile* dir) {
|
||||
char buf[32], name[32];
|
||||
SdFile file;
|
||||
uint16_t n;
|
||||
uint32_t size = dir->dirSize();
|
||||
|
||||
// create files and write name to file
|
||||
for (n = 0; ; n++){
|
||||
// make file name
|
||||
sprintf(name, "%u.TXT", n);
|
||||
|
||||
// open start time
|
||||
uint32_t t0 = millis();
|
||||
if (!file.open(dir, name, O_WRITE | O_CREAT | O_EXCL)) {
|
||||
error("open for write failed");
|
||||
}
|
||||
|
||||
// open end time and write start time
|
||||
uint32_t t1 = millis();
|
||||
// write file name to file
|
||||
file.print(name);
|
||||
if (!file.close()) error("close write");
|
||||
|
||||
// write end time
|
||||
uint32_t t2 = millis();
|
||||
Serial.print(F("WR "));
|
||||
Serial.print(n);
|
||||
Serial.write(' ');
|
||||
|
||||
// print time to create file
|
||||
Serial.print(t1 - t0);
|
||||
Serial.write(' ');
|
||||
|
||||
// print time to write file
|
||||
Serial.println(t2 - t1);
|
||||
|
||||
// directory size will change when a cluster is added
|
||||
if (dir->curPosition() > size) break;
|
||||
}
|
||||
|
||||
// read files and check content
|
||||
for (uint16_t i = 0; i <= n; i++) {
|
||||
sprintf(name, "%u.TXT", i);
|
||||
|
||||
// open start time
|
||||
uint32_t t0 = millis();
|
||||
if (!file.open(dir, name, O_READ)) {
|
||||
error("open for read failed");
|
||||
}
|
||||
|
||||
// open end time and read start time
|
||||
uint32_t t1 = millis();
|
||||
int16_t nr = file.read(buf, sizeof(buf));
|
||||
if (nr < 5) error("file.read failed");
|
||||
|
||||
// read end time
|
||||
uint32_t t2 = millis();
|
||||
|
||||
// check file content
|
||||
if (strlen(name) != (size_t)nr || strncmp(name, buf, nr)) {
|
||||
error("content compare failed");
|
||||
}
|
||||
if (!file.close()) error("close read failed");
|
||||
|
||||
Serial.print(F("RD "));
|
||||
Serial.print(i);
|
||||
Serial.write(' ');
|
||||
|
||||
// print open time
|
||||
Serial.print(t1 - t0);
|
||||
Serial.write(' ');
|
||||
|
||||
// print read time
|
||||
Serial.println(t2 - t1);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {} // wait for Leonardo
|
||||
Serial.println(F("Type any character to start"));
|
||||
while (Serial.read() <= 0) {}
|
||||
delay(200); // Catch Due reset problem
|
||||
|
||||
// initialize the SD card at SPI_FULL_SPEED for best performance.
|
||||
// try SPI_HALF_SPEED if bus errors occur.
|
||||
if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) sd.initErrorHalt();
|
||||
|
||||
uint32_t m = millis();
|
||||
// write files to root if FAT32
|
||||
if (sd.vol()->fatType() == 32) {
|
||||
Serial.println(F("Writing files to root"));
|
||||
dirAllocTest(sd.vwd());
|
||||
}
|
||||
|
||||
// create sub1 and write files
|
||||
SdFile sub1;
|
||||
if (!sub1.mkdir(sd.vwd(), "SUB1")) error("makdeDir SUB1 failed");
|
||||
Serial.println(F("Writing files to SUB1"));
|
||||
dirAllocTest(&sub1);
|
||||
|
||||
// create sub2 and write files
|
||||
SdFile sub2;
|
||||
if (!sub2.mkdir(&sub1, "SUB2")) error("mkdir SUB2 failed");
|
||||
Serial.println(F("Writing files to SUB2"));
|
||||
dirAllocTest(&sub2);
|
||||
m = millis() - m;
|
||||
Serial.print(F("Done millis: "));
|
||||
Serial.println(m);
|
||||
}
|
||||
|
||||
void loop() { }
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This sketch will remove the files and directories
|
||||
* created by the SdFatMakeDir.pde sketch.
|
||||
*
|
||||
* Performance is erratic due to the large number
|
||||
* of flash erase operations caused by many random
|
||||
* writes to file structures.
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatUtil.h>
|
||||
|
||||
const uint8_t SD_CHIP_SELECT = SS;
|
||||
|
||||
SdFat sd;
|
||||
|
||||
// store error strings in flash to save RAM
|
||||
#define error(s) sd.errorHalt(F(s))
|
||||
|
||||
/*
|
||||
* remove all files in dir.
|
||||
*/
|
||||
void deleteFiles(FatFile* dir) {
|
||||
char name[32];
|
||||
SdFile file;
|
||||
|
||||
// open and delete files
|
||||
for (uint16_t n = 0; ; n++){
|
||||
sprintf(name, "%u.TXT", n);
|
||||
|
||||
// open start time
|
||||
uint32_t t0 = millis();
|
||||
|
||||
// assume done if open fails
|
||||
if (!file.open(dir, name, O_WRITE)) return;
|
||||
|
||||
// open end time and remove start time
|
||||
uint32_t t1 = millis();
|
||||
if (!file.remove()) error("file.remove failed");
|
||||
|
||||
// remove end time
|
||||
uint32_t t2 = millis();
|
||||
|
||||
Serial.print(F("RM "));
|
||||
Serial.print(n);
|
||||
Serial.write(' ');
|
||||
|
||||
// open time
|
||||
Serial.print(t1 - t0);
|
||||
Serial.write(' ');
|
||||
|
||||
// remove time
|
||||
Serial.println(t2 - t1);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {} // wait for Leonardo
|
||||
Serial.println(F("Type any character to start"));
|
||||
while (Serial.read() <= 0) {}
|
||||
delay(200); // Catch Due reset problem
|
||||
|
||||
// initialize the SD card at SPI_FULL_SPEED for best performance.
|
||||
// try SPI_HALF_SPEED if bus errors occur.
|
||||
if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) sd.initErrorHalt();
|
||||
|
||||
|
||||
// delete files in root if FAT32
|
||||
if (sd.vol()->fatType() == 32) {
|
||||
Serial.println(F("Remove files in root"));
|
||||
deleteFiles(sd.vwd());
|
||||
}
|
||||
|
||||
// open SUB1 and delete files
|
||||
SdFile sub1;
|
||||
if (!sub1.open("SUB1", O_READ)) error("open SUB1 failed");
|
||||
Serial.println(F("Remove files in SUB1"));
|
||||
deleteFiles(&sub1);
|
||||
|
||||
// open SUB2 and delete files
|
||||
SdFile sub2;
|
||||
if (!sub2.open(&sub1, "SUB2", O_READ)) error("open SUB2 failed");
|
||||
Serial.println(F("Remove files in SUB2"));
|
||||
deleteFiles(&sub2);
|
||||
|
||||
// remove SUB2
|
||||
if (!sub2.rmdir()) error("sub2.rmdir failed");
|
||||
Serial.println(F("SUB2 removed"));
|
||||
|
||||
// remove SUB1
|
||||
if (!sub1.rmdir()) error("sub1.rmdir failed");
|
||||
Serial.println(F("SUB1 removed"));
|
||||
|
||||
Serial.println(F("Done"));
|
||||
}
|
||||
|
||||
void loop() { }
|
||||
@@ -0,0 +1,94 @@
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatTestSuite.h>
|
||||
SdFat sd;
|
||||
const char *testName = "SDFAT.TST";
|
||||
//------------------------------------------------------------------------------
|
||||
void fstreamOpen() {
|
||||
ios::openmode nocreate[] = {ios::in, ios::in | ios::out};
|
||||
ios::openmode create[] =
|
||||
{ios::out, ios::out | ios::app, ios::app, ios::out | ios::trunc,
|
||||
ios::in | ios::out | ios::trunc, ios::in | ios::out | ios::app,
|
||||
ios::in | ios::app};
|
||||
ios::openmode illegal[] =
|
||||
{0, ios::trunc, ios::app | ios::trunc, ios::in | ios::app | ios::trunc,
|
||||
ios::in | ios::trunc, ios::out | ios::app | ios::trunc,
|
||||
ios::in | ios::out | ios::app | ios::trunc};
|
||||
|
||||
sd.remove(testName);
|
||||
fstream file(testName);
|
||||
testVerifyMsg(!file.is_open()&& !sd.exists(testName), "fstream constructor");
|
||||
|
||||
for (uint8_t i = 0 ; i < sizeof(nocreate)/sizeof(nocreate[1]); i++) {
|
||||
file.close();
|
||||
sd.remove(testName);
|
||||
file.open(testName, nocreate[i]);
|
||||
testVerifyMsg(!sd.exists(testName) && !file.is_open(), "fstream nocreate !exists");
|
||||
}
|
||||
for (uint8_t i = 0 ; i < sizeof(create)/sizeof(create[1]); i++) {
|
||||
file.close();
|
||||
sd.remove(testName);
|
||||
file.open(testName, create[i]);
|
||||
testVerifyMsg(sd.exists(testName) && file.is_open(), "fstream create openmode");
|
||||
}
|
||||
for (uint8_t i = 0 ; i < sizeof(illegal)/sizeof(illegal[1]); i++) {
|
||||
file.close();
|
||||
file.open(testName, illegal[i]);
|
||||
testVerifyMsg(sd.exists(testName) && !file.is_open(), "fstream illegal openmode");
|
||||
}
|
||||
for (uint8_t i = 0 ; i < sizeof(nocreate)/sizeof(nocreate[1]); i++) {
|
||||
file.close();
|
||||
file.open(testName, nocreate[i]);
|
||||
testVerifyMsg(sd.exists(testName) && file.is_open(), "fstream nocreate exists");
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void testPosition() {
|
||||
sd.remove(testName);
|
||||
ofstream ofs(testName);
|
||||
testVerifyBool(ofs.good() && ofs.tellp() == 0);
|
||||
ofs.seekp(0, ios::end);
|
||||
testVerifyBool(ofs.good() && ofs.tellp() == 0);
|
||||
ofs << "abcde";
|
||||
testVerifyBool(ofs.good() && ofs.tellp() == 5);
|
||||
ofs.seekp(4);
|
||||
testVerifyBool(ofs.good() && ofs.tellp() == 4);
|
||||
ofs.seekp(-1, ios::cur);
|
||||
testVerifyBool(ofs.good() && ofs.tellp() == 3);
|
||||
ofs.close();
|
||||
ifstream ifs(testName, ios::ate);
|
||||
testVerifyBool(ifs.good() && ifs.tellg() == 5);
|
||||
ifs.seekg(0);
|
||||
testVerifyBool(ifs.get() == 'a' && ifs.get() == 'b');
|
||||
testVerifyBool(ifs.tellg() == 2 && ifs.good());
|
||||
ifs.seekg(3, ios::cur);
|
||||
testVerifyBool(ifs.tellg() == 5 && ifs.good());
|
||||
ifs.seekg(4, ios::beg);
|
||||
testVerifyBool(ifs.good() && ifs.tellg() == 4);
|
||||
ifs.close();
|
||||
ofs.open(testName, ios::app);
|
||||
testVerifyBool(ofs.good() && ofs.tellp() == 0);
|
||||
ofs << 'f';
|
||||
testVerifyBool(ofs.good() && ofs.tellp() == 6);
|
||||
ofs.close();
|
||||
ofs.open(testName, ios::trunc);
|
||||
ofs.seekp(0, ios::end);
|
||||
testVerifyBool(ofs.good() && ofs.tellp() == 0);
|
||||
ofs << "ABCDEF";
|
||||
ofs.close();
|
||||
fstream fs(testName);
|
||||
testVerifyBool(fs.good() && fs.tellp() == 0 && fs.tellg() == 0);
|
||||
fs.seekg(2);
|
||||
testVerifyBool(fs.good() && fs.get() == 'C');
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
|
||||
testBegin();
|
||||
if (!sd.begin()) sd.initErrorHalt();
|
||||
fstreamOpen();
|
||||
testPosition();
|
||||
testEnd();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {}
|
||||
@@ -0,0 +1,261 @@
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatTestSuite.h>
|
||||
|
||||
char buf[100];
|
||||
ibufstream ib;
|
||||
#define ibInit(s) ibInit_P(PSTR(s))
|
||||
|
||||
//----------------------------------------------------------
|
||||
void ibInit_P(PGM_P p) {
|
||||
if (strlen_P(p) >= sizeof(buf)) {
|
||||
ib.init("");
|
||||
ib.setstate(ios::badbit);
|
||||
} else {
|
||||
ib.clear();
|
||||
strncpy_P(buf, p, sizeof(buf));
|
||||
ib.init(buf);
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void istreamBool() {
|
||||
bool b;
|
||||
ibInit(" 0 1 2");
|
||||
testVerifyBool((ib >> b) && !b);
|
||||
testVerifyBool((ib >> b) && b);
|
||||
testVerifyBool(!(ib >> b) && !ib.good());
|
||||
|
||||
ibInit(" true false err");
|
||||
testVerifyBool((ib >> boolalpha >> b) && b && ib.good());
|
||||
testVerifyBool((ib >> b) && !b && ib.good());
|
||||
testVerifyBool(!(ib >> b) && ib.fail());
|
||||
|
||||
ibInit("1");
|
||||
testVerifyBool((ib >> noboolalpha >> b) && b && ib.eof());
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void istreamChar() {
|
||||
char c;
|
||||
signed char sc;
|
||||
unsigned char uc;
|
||||
|
||||
ibInit("c s u g");
|
||||
testVerifyBool((ib >> c) && ib.good() && c == 'c');
|
||||
testVerifyBool((ib >> sc) && ib.good() && sc == 's');
|
||||
testVerifyBool((ib >> uc) && ib.good() && uc == 'u');
|
||||
testVerifyBool(ib.get() == ' ');
|
||||
testVerifyBool(ib.peek() == 'g' && ib.good());
|
||||
testVerifyBool(ib.get() == 'g' && ib.good());
|
||||
testVerifyBool(ib.get() == -1 && ib.eof());
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void istreamDouble() {
|
||||
double f;
|
||||
ibInit("0 .1 1. 2 3.4 .1e5 1e5 -1E6 +2.3e-3 -123.4567");
|
||||
testVerifyBool((ib >> f) && f == 0 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 0.1 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 1.0 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 2.0 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 3.4 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 10000.0 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 1e5 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == -1E6 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 2.3e-3 && ib.good());
|
||||
testVerifyBool((ib >> f) && fabs(f + 123.4567) < 1e-5 && ib.eof());
|
||||
if (fabs(f + 123.4567) >= 1e-5) Serial.println(f, 8);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void istreamFloat() {
|
||||
float f;
|
||||
ibInit("0 .1 1. 2 3.4 .1e5 1e5 -1E6 +2.3e-3 -123.4567");
|
||||
testVerifyBool((ib >> f) && f == 0 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 0.1f && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 1.0 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 2.0 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 3.4f && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 10000.0 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 1e5 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == -1E6 && ib.good());
|
||||
testVerifyBool((ib >> f) && f == 2.3e-3f && ib.good());
|
||||
testVerifyBool((ib >> f) && fabs(f + 123.4567f) < 1e-5 && ib.eof());
|
||||
if (fabs(f + 123.4567) >= 1e-5) Serial.println(f, 8);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void istreamGet() {
|
||||
char s[4];
|
||||
ibInit("ab c");
|
||||
testVerifyBool(ib.get() == 'a' && ib.good() && ib.gcount() == 1);
|
||||
testVerifyBool(ib.get() == 'b' && ib.good() && ib.gcount() == 1);
|
||||
testVerifyBool(ib.get() == ' ' && ib.good() && ib.gcount() == 1);
|
||||
testVerifyBool(ib.get() == 'c' && ib.good() && ib.gcount() == 1);
|
||||
testVerifyBool(ib.get() == -1 && ib.eof() && ib.gcount() == 0);
|
||||
|
||||
ibInit("ab\ncdef");
|
||||
ib.get(s, sizeof(s));
|
||||
testVerifyBool(ib.good() && ib.gcount() == 2);
|
||||
testVerifyStr(s, "ab");
|
||||
testVerifyBool(ib.get() == '\n' && ib.good() && ib.gcount() == 1);
|
||||
ib.get(s, sizeof(s));
|
||||
testVerifyBool(ib.good() && ib.gcount() == 3);
|
||||
testVerifyStr(s, "cde");
|
||||
ib.get(s, sizeof(s));
|
||||
testVerifyBool(ib.eof() && ib.gcount() == 1);
|
||||
testVerifyStr(s, "f");
|
||||
|
||||
ibInit(
|
||||
"short line\n"
|
||||
"\n"
|
||||
"17 character line\n"
|
||||
"too long for buffer\n"
|
||||
"line with no nl"
|
||||
);
|
||||
char buf[18];
|
||||
ib.getline(buf, sizeof(buf));
|
||||
testVerifyBool(ib.good() && ib.gcount() == 11);
|
||||
testVerifyStr(buf, "short line");
|
||||
ib.getline(buf, sizeof(buf));
|
||||
testVerifyBool(ib.good() && ib.gcount() == 1 && buf[0] == '\0');
|
||||
ib.getline(buf, sizeof(buf));
|
||||
testVerifyBool(ib.good() && ib.gcount() == 18);
|
||||
testVerifyStr(buf, "17 character line");
|
||||
ib.getline(buf, sizeof(buf));
|
||||
testVerifyBool(ib.fail() && !ib.eof() && ib.gcount() == 17);
|
||||
testVerifyStr(buf, "too long for buff");
|
||||
ib.clear();
|
||||
ib.getline(buf, sizeof(buf));
|
||||
testVerifyBool(ib.good() && !ib.eof() && ib.gcount() == 3);
|
||||
testVerifyStr(buf, "er");
|
||||
ib.getline(buf, sizeof(buf));
|
||||
testVerifyBool(!ib.fail() && ib.eof() && ib.gcount() == 15);
|
||||
testVerifyStr(buf, "line with no nl");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void istreamNumber() {
|
||||
short s;
|
||||
signed short ss;
|
||||
unsigned short us;
|
||||
int i;
|
||||
signed int si;
|
||||
unsigned int ui;
|
||||
long l;
|
||||
signed long sl;
|
||||
unsigned long ul;
|
||||
|
||||
ibInit("-32769");
|
||||
testVerifyBool(!(ib >> s) && ib.fail());
|
||||
ibInit("-32768 0 32767 32768");
|
||||
testVerifyBool((ib >> s) && s == -32768 && ib.good());
|
||||
testVerifyBool((ib >> s) && s == 0 && ib.good());
|
||||
testVerifyBool((ib >> s) && s == 32767 && ib.good());
|
||||
testVerifyBool(!(ib >> s) && ib.fail());
|
||||
|
||||
ibInit("-32769");
|
||||
testVerifyBool(!(ib >> ss) && ib.fail());
|
||||
ibInit("-32768 0 32767 32768");
|
||||
testVerifyBool((ib >> ss) && ss == -32768 && ib.good());
|
||||
testVerifyBool((ib >> ss) && ss == 0 && ib.good());
|
||||
testVerifyBool((ib >> ss) && ss == 32767 && ib.good());
|
||||
testVerifyBool(!(ib >> ss) && ib.fail());
|
||||
|
||||
ibInit("0 65535 65536");
|
||||
testVerifyBool((ib >> us) && us == 0 && ib.good());
|
||||
testVerifyBool((ib >> us) && us == 65535 && ib.good());
|
||||
testVerifyBool(!(ib >> us) && ib.fail());
|
||||
|
||||
if (sizeof(int) == 2) {
|
||||
ibInit("-32769");
|
||||
testVerifyBool(!(ib >> i) && ib.fail());
|
||||
ibInit("-32768 0 32767 32768");
|
||||
testVerifyBool((ib >> i) && i == -32768 && ib.good());
|
||||
testVerifyBool((ib >> i) && i == 0 && ib.good());
|
||||
testVerifyBool((ib >> i) && i == 32767 && ib.good());
|
||||
testVerifyBool(!(ib >> i) && ib.fail());
|
||||
|
||||
ibInit("-32769");
|
||||
testVerifyBool(!(ib >> si) && ib.fail());
|
||||
ibInit("-32768 0 32767 32768");
|
||||
testVerifyBool((ib >> si) && si == -32768 && ib.good());
|
||||
testVerifyBool((ib >> si) && si == 0 && ib.good());
|
||||
testVerifyBool((ib >> si) && si == 32767 && ib.good());
|
||||
testVerifyBool(!(ib >> si) && ib.fail());
|
||||
|
||||
ibInit("0 65535 65536");
|
||||
testVerifyBool((ib >> ui) && ui == 0 && ib.good());
|
||||
testVerifyBool((ib >> ui) && ui == 65535 && ib.good());
|
||||
testVerifyBool(!(ib >> ui) && ib.fail());
|
||||
} else {
|
||||
ibInit("-2147483649");
|
||||
testVerifyBool(!(ib >> i) && ib.fail());
|
||||
ibInit("-2147483648 0 2147483647 2147483648");
|
||||
testVerifyBool((ib >> i) && i == -2147483648 && ib.good());
|
||||
testVerifyBool((ib >> i) && i == 0 && ib.good());
|
||||
testVerifyBool((ib >> i) && i == 2147483647 && ib.good());
|
||||
testVerifyBool(!(ib >> i) && ib.fail());
|
||||
|
||||
ibInit("-2147483649");
|
||||
testVerifyBool(!(ib >> si) && ib.fail());
|
||||
ibInit("-2147483648 0 2147483647 2147483648");
|
||||
testVerifyBool((ib >> si) && si == -2147483648 && ib.good());
|
||||
testVerifyBool((ib >> si) && si == 0 && ib.good());
|
||||
testVerifyBool((ib >> si) && si == 2147483647 && ib.good());
|
||||
testVerifyBool(!(ib >> si) && ib.fail());
|
||||
|
||||
ibInit("0 4294967295 4294967296");
|
||||
testVerifyBool((ib >> ui) && ui == 0 && ib.good());
|
||||
testVerifyBool((ib >> ui) && ui == 4294967295 && ib.good());
|
||||
testVerifyBool(!(ib >> ui) && ib.fail());
|
||||
}
|
||||
ibInit("-2147483649");
|
||||
testVerifyBool(!(ib >> l) && ib.fail());
|
||||
ibInit("-2147483648 0 2147483647 2147483648");
|
||||
testVerifyBool((ib >> l) && l == -2147483648 && ib.good());
|
||||
testVerifyBool((ib >> l) && l == 0 && ib.good());
|
||||
testVerifyBool((ib >> l) && l == 2147483647 && ib.good());
|
||||
testVerifyBool(!(ib >> l) && ib.fail());
|
||||
|
||||
ibInit("-2147483649");
|
||||
testVerifyBool(!(ib >> sl) && ib.fail());
|
||||
ibInit("-2147483648 0 2147483647 2147483648");
|
||||
testVerifyBool((ib >> sl) && sl == -2147483648 && ib.good());
|
||||
testVerifyBool((ib >> sl) && sl == 0 && ib.good());
|
||||
testVerifyBool((ib >> sl) && sl == 2147483647 && ib.good());
|
||||
testVerifyBool(!(ib >> sl) && ib.fail());
|
||||
|
||||
ibInit("0 4294967295 4294967296");
|
||||
testVerifyBool((ib >> ul) && ul == 0 && ib.good());
|
||||
testVerifyBool((ib >> ul) && ul == 4294967295 && ib.good());
|
||||
testVerifyBool(!(ib >> ul) && ib.fail());
|
||||
|
||||
// octal hex
|
||||
ibInit("123 abc 0xdef 0XABC 567");
|
||||
testVerifyBool((ib >> oct >> i) && i == 83);
|
||||
testVerifyBool((ib >> hex >> i) && i == 0xabc);
|
||||
testVerifyBool((ib >> i) && i == 0xdef);
|
||||
testVerifyBool((ib >> i) && i == 0xabc);
|
||||
testVerifyBool((ib >> dec >> i) && i ==567);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void istreamStr() {
|
||||
char str[20];
|
||||
ibInit("abc def\r\n hij");
|
||||
testVerifyBool((ib >> str) && ib.good());
|
||||
testVerifyStr(str, "abc");
|
||||
testVerifyBool((ib >> str) && ib.good());
|
||||
testVerifyStr(str, "def");
|
||||
testVerifyBool((ib >> str) && ib.eof());
|
||||
testVerifyStr(str, "hij");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
testBegin();
|
||||
istreamBool();
|
||||
istreamChar();
|
||||
istreamDouble();
|
||||
istreamFloat();
|
||||
istreamGet();
|
||||
istreamNumber();
|
||||
istreamStr();
|
||||
testEnd();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Program to compare size of SdFat with the SD.h library.
|
||||
#include <SPI.h>
|
||||
// Select the test library by commenting out one of the following two lines.
|
||||
// #include <SD.h>
|
||||
#include <SdFat.h>
|
||||
|
||||
// SD chip select pin.
|
||||
const uint8_t SD_CS_PIN = SS;
|
||||
|
||||
#ifdef __SD_H__
|
||||
File file;
|
||||
#else // __SD_H__
|
||||
SdFat SD;
|
||||
SdFile file;
|
||||
#endif // __SD_H__
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {} // wait for Leonardo
|
||||
|
||||
if (!SD.begin(SD_CS_PIN)) {
|
||||
Serial.println("begin failed");
|
||||
return;
|
||||
}
|
||||
#ifdef __SD_H__
|
||||
file = SD.open("SFN_file.txt", FILE_WRITE);
|
||||
#else // __SD_H__
|
||||
file.open("LFN_file.txt", O_RDWR | O_CREAT);
|
||||
#endif // __SD_H__
|
||||
|
||||
file.println("Hello");
|
||||
file.close();
|
||||
Serial.println("Done");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {}
|
||||
@@ -0,0 +1,234 @@
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatUtil.h>
|
||||
const uint8_t SD_CS_PIN = SS;
|
||||
SdFat sd;
|
||||
SdFile file;
|
||||
char name[260];
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const char* testName[] = {
|
||||
"low.low",
|
||||
"low.Mix",
|
||||
"low.UP",
|
||||
"Mix.low",
|
||||
"Mix.Mix",
|
||||
"Mix.UP",
|
||||
"UP.low",
|
||||
"UP.Mix",
|
||||
"UP.UP",
|
||||
".dot",
|
||||
".dot.dot",
|
||||
"A b c . txt",
|
||||
" Leading space and no extension",
|
||||
"Trailing dots and space . . .",
|
||||
"Long extension.extension",
|
||||
"Space after dot. txt",
|
||||
"Dot.dot.test.txt",
|
||||
"Dot.dot.test.seq.txt",
|
||||
"LOW.LOW",
|
||||
"MIX.MIX",
|
||||
"Invalid character *.test"
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
bool checkName(char first, size_t len) {
|
||||
size_t i;
|
||||
if (len < 5 || len > sizeof(name)) {
|
||||
return false;
|
||||
}
|
||||
if ( name[0] != first) {
|
||||
return false;
|
||||
}
|
||||
for (i = 1; i < (len - 4); i++) {
|
||||
if (name[i] != (char)('0' + (i + 1) %10)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const char* p = ".txt";
|
||||
while (*p) {
|
||||
if (name[i++] != *p++) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return name[i] == 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void makeName(char first, size_t len) {
|
||||
size_t i;
|
||||
if (len > sizeof(name)) {
|
||||
len = 255;
|
||||
}
|
||||
if (len < 5) {
|
||||
len = 5;
|
||||
}
|
||||
name[0] = first;
|
||||
for (i = 1; i < (len - 4); i++) {
|
||||
name[i] = '0' + (i + 1) %10;
|
||||
}
|
||||
const char* p = ".txt";
|
||||
while (*p) name[i++] = *p++;
|
||||
name[i] = 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// test open, remove, getName, and ls.
|
||||
void basicTest() {
|
||||
size_t i;
|
||||
size_t n = sd.vol()->fatType() == 32 ? 255 : 99;
|
||||
uint16_t maxIndex = 0;
|
||||
|
||||
makeName('Z', 256);
|
||||
if (!file.open(name, O_RDWR | O_CREAT)) {
|
||||
Serial.println(F("255 limit OK"));
|
||||
} else {
|
||||
sd.errorHalt(F("255 limit"));
|
||||
}
|
||||
for (i = 5; i <= n; i++) {
|
||||
makeName('A', i);
|
||||
|
||||
if (!file.open(name, O_RDWR | O_CREAT)) {
|
||||
sd.errorHalt(F("open A"));
|
||||
}
|
||||
file.println(name);
|
||||
Serial.print(i);
|
||||
Serial.write(' ');
|
||||
Serial.print(file.dirIndex());
|
||||
Serial.write(' ');
|
||||
Serial.print(file.fileSize());
|
||||
Serial.println(F(" open A"));
|
||||
if (file.fileSize() != (i + 2)) {
|
||||
sd.errorHalt(F("file size A"));
|
||||
}
|
||||
if (file.dirIndex() >= maxIndex) {
|
||||
maxIndex = file.dirIndex();
|
||||
} else {
|
||||
Serial.print(maxIndex); Serial.print(',');Serial.println(file.dirIndex());
|
||||
sd.errorHalt(F("dirIndex"));
|
||||
}
|
||||
file.close();
|
||||
if (!file.open(sd.vwd(), maxIndex, O_READ)) {
|
||||
sd.errorHalt(F("open by index"));
|
||||
}
|
||||
memset(name, 0, sizeof(name));
|
||||
if (!file.getName(name, sizeof(name))) {
|
||||
sd.errorHalt(F("getName"));
|
||||
}
|
||||
if (!checkName('A', i)) {
|
||||
Serial.println(name);
|
||||
sd.errorHalt(F("checkName"));
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
for (i = n; i >= 5; i -= 2) {
|
||||
makeName('A', i);
|
||||
Serial.print(i);
|
||||
Serial.println(F( " rm A"));
|
||||
if (!sd.remove(name)) {
|
||||
sd.errorHalt(F("remove A"));
|
||||
}
|
||||
}
|
||||
for (i = n; i >= 5; i -= 2) {
|
||||
makeName('B', i);
|
||||
if (!file.open(name, O_RDWR | O_CREAT)) {
|
||||
sd.errorHalt(F("open B"));
|
||||
}
|
||||
file.println(name);
|
||||
Serial.print(i);
|
||||
Serial.write(' ');
|
||||
Serial.print(file.dirIndex());
|
||||
Serial.write(' ');
|
||||
Serial.print(file.fileSize());
|
||||
Serial.println(F(" open B"));
|
||||
if (file.fileSize() != (i + 2)) {
|
||||
sd.errorHalt(F("file size B"));
|
||||
}
|
||||
if (file.dirIndex() > maxIndex) {
|
||||
sd.errorHalt(F("maxIndex"));
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
Serial.println(F("----- ls ------"));
|
||||
sd.ls();
|
||||
for (i = 5; i <= n; i++) {
|
||||
char fc = i & 1 ? 'B' : 'A';
|
||||
makeName(fc, i);
|
||||
Serial.print(i);
|
||||
Serial.print(F(" rm "));
|
||||
Serial.println(fc);
|
||||
if (!sd.remove(name)) {
|
||||
sd.errorHalt(F("remove A/B"));
|
||||
}
|
||||
}
|
||||
if (file.openNext(sd.vwd())) {
|
||||
sd.errorHalt(F("remove all"));
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println(F("basicTest done"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void nameTest() {
|
||||
Serial.println();
|
||||
uint8_t n = sizeof(testName)/sizeof(char*);
|
||||
for (uint8_t i = 0; i < n; i++) {
|
||||
Serial.print(F("Name: "));
|
||||
Serial.write('"');
|
||||
Serial.print(testName[i]);
|
||||
Serial.println('"');
|
||||
if(!file.open(testName[i], O_CREAT | O_RDWR)) {
|
||||
Serial.println(F("Open failed"));
|
||||
} else {
|
||||
file.println(testName[i]);
|
||||
if (!file.getName(name, sizeof(name))) {
|
||||
sd.errorHalt(F("getFilemame"));
|
||||
}
|
||||
file.println(name);
|
||||
Serial.print(F("LFN: "));
|
||||
Serial.write('"');
|
||||
Serial.print(name);
|
||||
Serial.println('"');
|
||||
Serial.print(F("SFN: "));
|
||||
Serial.write('"');
|
||||
file.printSFN(&Serial);
|
||||
Serial.println('"');
|
||||
Serial.print(F("Index: "));
|
||||
if (file.dirIndex() < 10) {
|
||||
Serial.write(' ');
|
||||
}
|
||||
Serial.println(file.dirIndex());
|
||||
file.close();
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
Serial.println(F("----- ls ------"));
|
||||
sd.ls();
|
||||
Serial.println();
|
||||
Serial.println(F("nameTest done"));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while(!Serial);
|
||||
Serial.print(F("\r\nFreeRam: "));
|
||||
Serial.println(FreeRam());
|
||||
Serial.println(F("Type any character to start."));
|
||||
while (Serial.read() < 0) {}
|
||||
if (!sd.begin(SD_CS_PIN)) sd.initErrorHalt();
|
||||
if (file.openNext(sd.vwd())) {
|
||||
file.close();
|
||||
delay(100);
|
||||
while (Serial.read() >= 0) {}
|
||||
Serial.print(F("Type 'W' to wipe the card: "));
|
||||
int c;
|
||||
while ((c = Serial.read()) < 0) {}
|
||||
if (c != 'W') {
|
||||
sd.errorHalt(F("Invalid"));
|
||||
}
|
||||
Serial.println((char)c);
|
||||
if (!sd.wipe(&Serial) || !sd.begin(SD_CS_PIN)) {
|
||||
sd.errorHalt(F("wipe failed"));
|
||||
}
|
||||
}
|
||||
basicTest();
|
||||
nameTest();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {}
|
||||
@@ -0,0 +1,218 @@
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatUtil.h>
|
||||
const uint8_t SD_CS_PIN = SS;
|
||||
SdFat sd;
|
||||
SdFile file;
|
||||
char name[260];
|
||||
|
||||
// Serial output stream
|
||||
ArduinoOutStream cout(Serial);
|
||||
|
||||
// Serial in buffer.
|
||||
char cinBuf[10];
|
||||
|
||||
// Serial input stream
|
||||
ArduinoInStream cin(Serial, cinBuf, sizeof(cinBuf));
|
||||
//------------------------------------------------------------------------------
|
||||
const char* testName[] = {
|
||||
"low.low",
|
||||
"low.Mix",
|
||||
"low.UP",
|
||||
"Mix.low",
|
||||
"Mix.Mix",
|
||||
"Mix.UP",
|
||||
"UP.low",
|
||||
"UP.Mix",
|
||||
"UP.UP",
|
||||
".dot",
|
||||
".dot.dot",
|
||||
"A b c . txt",
|
||||
" Leading space and no extension",
|
||||
"Trailing dots and space . . .",
|
||||
"Long extension.extension",
|
||||
"Space after dot. txt",
|
||||
"Dot.dot.test.txt",
|
||||
"Dot.dot.test.seq.txt",
|
||||
"LOW.LOW",
|
||||
"MIX.MIX",
|
||||
"Invalid character *.test"
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
bool checkName(char first, size_t len) {
|
||||
size_t i;
|
||||
if (len < 5 || len > sizeof(name)) {
|
||||
return false;
|
||||
}
|
||||
if ( name[0] != first) {
|
||||
return false;
|
||||
}
|
||||
for (i = 1; i < (len - 4); i++) {
|
||||
if (name[i] != (char)('0' + (i + 1) %10)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const char* p = ".txt";
|
||||
while (*p) {
|
||||
if (name[i++] != *p++) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return name[i] == 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void makeName(char first, size_t len) {
|
||||
size_t i;
|
||||
if (len > sizeof(name)) {
|
||||
len = 255;
|
||||
}
|
||||
if (len < 5) {
|
||||
len = 5;
|
||||
}
|
||||
name[0] = first;
|
||||
for (i = 1; i < (len - 4); i++) {
|
||||
name[i] = '0' + (i + 1) %10;
|
||||
}
|
||||
const char* p = ".txt";
|
||||
while (*p) name[i++] = *p++;
|
||||
name[i] = 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// test open, remove, getName, and ls.
|
||||
void basicTest() {
|
||||
size_t i;
|
||||
size_t n = sd.vol()->fatType() == 32 ? 255 : 99;
|
||||
uint16_t maxIndex = 0;
|
||||
|
||||
makeName('Z', 256);
|
||||
if (!file.open(name, O_RDWR | O_CREAT)) {
|
||||
cout << F("255 limit OK") << endl;
|
||||
} else {
|
||||
sd.errorHalt(F("255 limit"));
|
||||
}
|
||||
for (i = 5; i <= n; i++) {
|
||||
makeName('A', i);
|
||||
|
||||
if (!file.open(name, O_RDWR | O_CREAT)) {
|
||||
sd.errorHalt(F("open A"));
|
||||
}
|
||||
file.println(name);
|
||||
cout << setw(3) << i << setw(5) << file.dirIndex() << F(" open A") << endl;
|
||||
|
||||
if (file.fileSize() != (i + 2)) {
|
||||
sd.errorHalt(F("file size A"));
|
||||
}
|
||||
if (file.dirIndex() >= maxIndex) {
|
||||
maxIndex = file.dirIndex();
|
||||
} else {
|
||||
sd.errorHalt(F("dirIndex"));
|
||||
}
|
||||
file.close();
|
||||
if (!file.open(sd.vwd(), maxIndex, O_READ)) {
|
||||
sd.errorHalt(F("open by index"));
|
||||
}
|
||||
memset(name, 0, sizeof(name));
|
||||
if (!file.getName(name, sizeof(name))) {
|
||||
sd.errorHalt(F("getName"));
|
||||
}
|
||||
if (!checkName('A', i)) {
|
||||
cout << name << endl;
|
||||
sd.errorHalt(F("checkName"));
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
for (i = n; i >= 5; i -= 2) {
|
||||
makeName('A', i);
|
||||
cout << setw(3) << i << F( " rm A") << endl;
|
||||
if (!sd.remove(name)) {
|
||||
sd.errorHalt(F("remove A"));
|
||||
}
|
||||
}
|
||||
for (i = n; i >= 5; i -= 2) {
|
||||
makeName('B', i);
|
||||
if (!file.open(name, O_RDWR | O_CREAT)) {
|
||||
sd.errorHalt(F("open B"));
|
||||
}
|
||||
file.println(name);
|
||||
|
||||
cout << setw(3) << i << setw(5) << file.dirIndex() << F(" open B") << endl;
|
||||
|
||||
if (file.fileSize() != (i + 2)) {
|
||||
sd.errorHalt(F("file size B"));
|
||||
}
|
||||
if (file.dirIndex() > maxIndex) {
|
||||
sd.errorHalt(F("maxIndex"));
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
cout << endl << F("----- ls ------") << endl;
|
||||
sd.ls();
|
||||
for (i = 5; i <= n; i++) {
|
||||
char fc = i & 1 ? 'B' : 'A';
|
||||
makeName(fc, i);
|
||||
cout << setw(3) << i << F(" rm ") << fc << endl;
|
||||
if (!sd.remove(name)) {
|
||||
sd.errorHalt(F("remove A/B"));
|
||||
}
|
||||
}
|
||||
if (file.openNext(sd.vwd())) {
|
||||
sd.errorHalt(F("remove all"));
|
||||
}
|
||||
cout << endl << F("basicTest done") << endl;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void nameTest() {
|
||||
cout << endl;
|
||||
uint8_t n = sizeof(testName)/sizeof(char*);
|
||||
for (uint8_t i = 0; i < n; i++) {
|
||||
cout << F("Name: \"") << testName[i] << '"' << endl;
|
||||
if(!file.open(testName[i], O_CREAT | O_RDWR)) {
|
||||
cout <<F("Open failed") << endl;
|
||||
} else {
|
||||
file.println(testName[i]);
|
||||
if (!file.getName(name, sizeof(name))) {
|
||||
sd.errorHalt(F("getFilemame"));
|
||||
}
|
||||
cout << F("LFN: \"") << name << '"' << endl;
|
||||
cout << F("SFN: \"");
|
||||
file.printSFN(&Serial);
|
||||
cout << '"' << endl;
|
||||
cout <<F("Index: ") << setw(2) << file.dirIndex() << endl;
|
||||
file.close();
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
cout << F("----- ls ------") << endl;
|
||||
sd.ls();
|
||||
cout << endl << F("nameTest done") << endl;
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while(!Serial); // Wait for USB Serial.
|
||||
|
||||
cout << endl << F("FreeRam: ") << FreeRam() << endl;
|
||||
cout << F("Type any character to start.") << endl;
|
||||
cin.readline();
|
||||
if (!sd.begin(SD_CS_PIN)) {
|
||||
sd.initErrorHalt();
|
||||
}
|
||||
if (file.openNext(sd.vwd())) {
|
||||
file.close();
|
||||
cout << F("Type 'W' to wipe the card: ");
|
||||
cin.readline();
|
||||
char c = cin.get();
|
||||
cout << c << endl;
|
||||
if (c != 'W') {
|
||||
sd.errorHalt(F("Invalid"));
|
||||
}
|
||||
if (!sd.wipe(&Serial) || !sd.begin(SD_CS_PIN)) {
|
||||
sd.errorHalt(F("wipe failed"));
|
||||
}
|
||||
}
|
||||
basicTest();
|
||||
nameTest();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {}
|
||||
@@ -0,0 +1,172 @@
|
||||
#include <SPI.h>
|
||||
#include <SdFat.h>
|
||||
#include <SdFatTestSuite.h>
|
||||
//------------------------------------------------------------------------------
|
||||
void ostreamBool() {
|
||||
char buf[40];
|
||||
obufstream ob(buf, sizeof(buf));
|
||||
bool f = false;
|
||||
bool t = true;
|
||||
ob << t << ',' << f << ',' << setw(2) << t << ',' << left << setw(2) << f;
|
||||
testVerifyStr(buf, "1,0, 1,0 ");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << boolalpha << t << ',' << f << ',' << setw(5) << t;
|
||||
ob << ',' << right << setw(6) << f;
|
||||
testVerifyStr(buf, "true,false,true , false");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void ostreamChar() {
|
||||
char buf[40];
|
||||
obufstream ob(buf, sizeof(buf));
|
||||
char c = 'c';
|
||||
signed char sc = 's';
|
||||
unsigned char uc = 'u';
|
||||
ob <<'l' << c << sc << uc;
|
||||
ob.put('p');
|
||||
testVerifyStr(buf, "lcsup");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << 's' << setw(2) << 'r' << 'n' << left << setw(2) << 'l';
|
||||
ob << 'm' << right << setw(2) << 'e';
|
||||
testVerifyStr(buf, "s rnl m e");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << setfill('f') << setw(5) << 'r';
|
||||
testVerifyStr(buf, "ffffr");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void ostreamFloat() {
|
||||
char buf[50];
|
||||
obufstream ob(buf, sizeof(buf));
|
||||
float f = 9.87654;
|
||||
double d = -123.4567;
|
||||
ob << f <<',';
|
||||
ob << internal << setw(10) << d << ',';
|
||||
ob << setfill('0') << setw(10) << d;
|
||||
testVerifyStr(buf, "9.88,- 123.46,-000123.46");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << setw(10) << left << d << ',' << showpos << -d << ',';
|
||||
ob << setprecision(0) << d;
|
||||
testVerifyStr(buf, "-123.46000,+123.46,-123");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << showpoint << d << noshowpoint << ',' << d << ',';
|
||||
ob << setprecision(4) << f << ',' << setprecision(2) << noshowpos << f;
|
||||
testVerifyStr(buf, "-123.,-123,+9.8765,9.88");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void ostreamNumber() {
|
||||
char buf[50];
|
||||
obufstream ob(buf, sizeof(buf));
|
||||
|
||||
short s = 1;
|
||||
short signed ss = 2;
|
||||
short unsigned su = 3;
|
||||
int i = 4;
|
||||
int signed is = 5;
|
||||
int unsigned iu = 6;
|
||||
long l = 7;
|
||||
long signed ls = 8;
|
||||
long unsigned lu = 9;
|
||||
|
||||
|
||||
ob << s << ss << su << i << is << iu << l <<ls << lu;
|
||||
s = -1;
|
||||
ss = -2;
|
||||
i = -3;
|
||||
is = -4;
|
||||
l = -5;
|
||||
ls = -6;
|
||||
ob << s << ss << i << is << l <<ls;
|
||||
testVerifyStr(buf, "123456789-1-2-3-4-5-6");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
s = ss = 0X8000;
|
||||
i = is = sizeof(int) == 2 ? 0X8000 : 0X80000000;
|
||||
l = ls = 0X80000000;
|
||||
su = iu = lu = 0;
|
||||
ob << su << iu << lu << s << ss;
|
||||
testVerifyStr(buf, "000-32768-32768");
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << i << is;
|
||||
if (sizeof(int) == 2) {
|
||||
testVerifyStr(buf, "-32768-32768");
|
||||
} else {
|
||||
testVerifyStr(buf, "-2147483648-2147483648");
|
||||
}
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << l << ls;
|
||||
testVerifyStr(buf, "-2147483648-2147483648");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
s = ss = i = is = 0X7FFF;
|
||||
l = ls = 0X7FFFFFFF;
|
||||
su = iu = 0XFFFF;
|
||||
lu = 0XFFFFFFFF;
|
||||
ob << showpos << s << ss << i << is;
|
||||
testVerifyStr(buf, "+32767+32767+32767+32767");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << l << ls;
|
||||
testVerifyStr(buf, "+2147483647+2147483647");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << su << iu << lu;
|
||||
testVerifyStr(buf, "+65535+65535+4294967295");
|
||||
|
||||
i = 0XABC;
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << noshowpos << hex << i << ',' << dec << i << ',' << oct << i;
|
||||
testVerifyStr(buf, "abc,2748,5274");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << showbase << hex << i << ',' << dec << i << ',' << oct << i;
|
||||
testVerifyStr(buf, "0xabc,2748,05274");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << showpos << uppercase << hex << i << ',' << dec << i << ',' << oct << i;
|
||||
testVerifyStr(buf, "0XABC,+2748,05274");
|
||||
|
||||
is = -123;
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << internal << setfill('0');
|
||||
ob << setw(6) << hex << i << ',' << dec << setw(6) << i << ',';
|
||||
ob << setw(5) << is;
|
||||
testVerifyStr(buf, "0X0ABC,+02748,-0123");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << setfill(' ') << left << setw(5) << is << ',' << right << setw(6) << is;
|
||||
testVerifyStr(buf, "-123 , -123");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void ostreamStr() {
|
||||
char buf[40];
|
||||
obufstream ob(buf, sizeof(buf));
|
||||
char c[] = "c";
|
||||
const char* cc = "CC";
|
||||
signed char* sc = (signed char*)"sc";
|
||||
const signed char* csc = (const signed char*)"CSC";
|
||||
unsigned char *uc = (unsigned char *)"uc";
|
||||
const unsigned char *cuc = (const unsigned char *)"CUC";
|
||||
ob << "lit" << c << cc << sc << csc << uc << cuc << F("F");
|
||||
testVerifyStr(buf, "litcCCscCSCucCUCF");
|
||||
|
||||
ob.init(buf, sizeof(buf));
|
||||
ob << setfill('*') << "s" << setw(8) << "right";
|
||||
ob << " " << left << setw(6) << "left" << "e";
|
||||
testVerifyStr(buf, "s***right left**e");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
testBegin();
|
||||
ostreamBool();
|
||||
ostreamChar();
|
||||
ostreamFloat();
|
||||
ostreamNumber();
|
||||
ostreamStr();
|
||||
testEnd();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {}
|
||||
Reference in New Issue
Block a user