arduino-0022
This commit is contained in:
parent
4f99742f03
commit
a9ad0e80a0
803 changed files with 69785 additions and 33024 deletions
|
@ -0,0 +1,76 @@
|
|||
//************************************************************************
|
||||
//* Arduino Test of Arduino Constants
|
||||
//* (C) 2010 by Rick Anderson
|
||||
//* Open source as per standard Arduino code
|
||||
//*
|
||||
//************************************************************************
|
||||
//* Oct 16, 2010 <ROA> Test of Arduino Constants
|
||||
//************************************************************************
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
void setup()
|
||||
{
|
||||
int startMemoryUsage;
|
||||
|
||||
//Start memory usage must be site prior to ATS_begin
|
||||
startMemoryUsage = ATS_GetFreeMemory();
|
||||
ATS_begin("Arduino", "Test of Arduino Constants");
|
||||
/*
|
||||
* Test Run Start
|
||||
*/
|
||||
|
||||
|
||||
//test true constant
|
||||
ATS_PrintTestStatus("1. Test of true constant", true == 1);
|
||||
|
||||
//test false consts
|
||||
ATS_PrintTestStatus( "2. Test of false constant", false == 0);
|
||||
|
||||
//Test of HIGH == 1
|
||||
ATS_PrintTestStatus( "3. Test of HIGH == 1", HIGH == 1);
|
||||
|
||||
//Test of LOW == 0
|
||||
ATS_PrintTestStatus( "4. Test of LOW == 0", LOW == 0);
|
||||
|
||||
//Test of INPUT == 1
|
||||
ATS_PrintTestStatus( "5. Test of INPUT == 1", HIGH == 1);
|
||||
|
||||
//Test of OUTPUT == 0
|
||||
ATS_PrintTestStatus( "6. Test of OUTPUT == 0", LOW == 0);
|
||||
|
||||
//test decimal
|
||||
ATS_PrintTestStatus( "7. Test of decimal constant", 101 == ((1 * pow(10,2)) + (0 * pow(10,1)) + 1));
|
||||
|
||||
//test binary
|
||||
ATS_PrintTestStatus( "8. Test of binary constant", B101 == 5);
|
||||
|
||||
//test octal
|
||||
ATS_PrintTestStatus( "9. Test of octal constant", 0101 == 65);
|
||||
|
||||
//test hexadecimal
|
||||
ATS_PrintTestStatus( "7. Test of hexadecimal constant", (0x101 == 257));
|
||||
|
||||
/*
|
||||
* Test Run End
|
||||
*/
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
//************************************************************************
//* Arduino Test Suite
//* ATS_ToneTest
//*
//* Copyright (c) 2010 Mark Sproul All right reserved.
//*
//* This library is free software; you can redistribute it and/or
//* modify it under the terms of the GNU Lesser General Public
//* License as published by the Free Software Foundation; either
//* version 2.1 of the License, or (at your option) any later version.
//*
//* This library is distributed in the hope that it will be useful,
//* but WITHOUT ANY WARRANTY; without even the implied warranty of
//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//* Lesser General Public License for more details.
//*
//* You should have received a copy of the GNU Lesser General Public
//* License along with this library; if not, write to the Free Software
//* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//************************************************************************
//* Aug 31, 2010 <MLS> Started on TestArduino
//* Oct 28, 2010 <MLS> Started on Delay
//************************************************************************
#include "WProgram.h"
#include "HardwareSerial.h"
#include <ArduinoTestSuite.h>
//************************************************************************
void setup()
{
short ii;
short testNum;
int startMemoryUsage;
unsigned long startMillis;
unsigned long endMillis;
unsigned long deltaMillis;
unsigned long errMillis;
boolean passed;
char testNameString[80];
startMemoryUsage = ATS_GetFreeMemory();
ATS_begin("Arduino", "DelayTest");
testNum = 1;
//* we start at 2 because 0/1 are RXD/TXD
for (ii=0; ii<1000; ii+= 15)
{
startMillis = millis();
delay(ii);
endMillis = millis();
deltaMillis = endMillis - startMillis;
if (deltaMillis >= ii)
{
errMillis = deltaMillis - ii;
}
else
{
errMillis = ii - deltaMillis;
}
if (errMillis <= 1)
{
passed = true;
}
else
{
passed = false;
}
sprintf(testNameString, "DelayTest.%02d (delay= %4d actual delay=%ld err=%ld)", testNum, ii, deltaMillis, errMillis);
ATS_PrintTestStatus(testNameString, passed);
testNum++;
}
ATS_ReportMemoryUsage(startMemoryUsage);
ATS_end();
}
//************************************************************************
void loop()
{
}
|
|
@ -0,0 +1,94 @@
|
|||
//************************************************************************
|
||||
//* Arduino Test Suite
|
||||
//* (C) 2010 by Mark Sproul
|
||||
//* Open source as per standard Arduino code
|
||||
//*
|
||||
//************************************************************************
|
||||
//* Aug 31, 2010 <MLS> Started on TestArduino
|
||||
//* Oct 18, 2010 <MLS> Added memory testing
|
||||
//************************************************************************
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include "pins_arduino.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
#include "avr_cpunames.h"
|
||||
|
||||
|
||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
|
||||
#define kBoard_PinCount 20
|
||||
#define kBoard_AnalogCount 6
|
||||
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||
#define kBoard_PinCount 70
|
||||
#define kBoard_AnalogCount 16
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void setup()
|
||||
{
|
||||
short ii;
|
||||
uint8_t timerNumber;
|
||||
int startMemoryUsage;
|
||||
|
||||
startMemoryUsage = ATS_GetFreeMemory();
|
||||
|
||||
ATS_begin("Arduino", "general");
|
||||
|
||||
//* test digital pins
|
||||
//* we start at 2 because 0/1 are RXD/TXD
|
||||
for (ii=2; ii<kBoard_PinCount; ii++)
|
||||
{
|
||||
ATS_Test_DigitalPin(ii);
|
||||
}
|
||||
|
||||
|
||||
//* test PWM pins
|
||||
//* we start at 2 because 0/1 are RXD/TXD
|
||||
for (ii=2; ii<kBoard_PinCount; ii++)
|
||||
{
|
||||
timerNumber = digitalPinToTimer(ii);
|
||||
if (timerNumber != NOT_ON_TIMER)
|
||||
{
|
||||
ATS_Test_PWM_Pin(ii);
|
||||
}
|
||||
}
|
||||
|
||||
for (ii=0; ii<kBoard_AnalogCount; ii++)
|
||||
{
|
||||
ATS_Test_AnalogInput(ii);
|
||||
}
|
||||
|
||||
#if (SERIAL_PORT_COUNT > 1)
|
||||
ATS_TestSerialLoopback(&Serial1, "Serial1");
|
||||
#endif
|
||||
#if (SERIAL_PORT_COUNT > 2)
|
||||
ATS_TestSerialLoopback(&Serial2, "Serial2");
|
||||
#endif
|
||||
#if (SERIAL_PORT_COUNT > 3)
|
||||
ATS_TestSerialLoopback(&Serial3, "Serial3");
|
||||
#endif
|
||||
|
||||
ATS_Test_EEPROM();
|
||||
|
||||
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
// Tests writing to and reading from a file, in particular the
|
||||
// the Stream implementation (e.g. read() and peek()).
|
||||
|
||||
#include <SD.h>
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
int startMemoryUsage = ATS_GetFreeMemory();
|
||||
boolean b;
|
||||
File f;
|
||||
|
||||
ATS_begin("Arduino", "SD Test");
|
||||
|
||||
ATS_PrintTestStatus("SD.begin()", b = SD.begin(4));
|
||||
if (!b) goto done;
|
||||
|
||||
SD.remove("test.txt");
|
||||
|
||||
f = SD.open("test.txt", FILE_WRITE);
|
||||
ATS_PrintTestStatus("SD.open()", f);
|
||||
if (!f) goto done;
|
||||
|
||||
f.print("abc");
|
||||
f.print("de");
|
||||
f.close();
|
||||
|
||||
f = SD.open("test.txt", FILE_WRITE);
|
||||
ATS_PrintTestStatus("SD.open()", f);
|
||||
if (!f) goto done;
|
||||
|
||||
f.print("fgh");
|
||||
f.close();
|
||||
|
||||
f = SD.open("test.txt");
|
||||
ATS_PrintTestStatus("SD.open()", f);
|
||||
if (!f) goto done;
|
||||
|
||||
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.available() != 0);
|
||||
ATS_PrintTestStatus("read()", f.read() == 'e');
|
||||
ATS_PrintTestStatus("available()", f.available() != 0);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'f');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'f');
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'g');
|
||||
ATS_PrintTestStatus("available()", f.available() != 0);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'g');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'g');
|
||||
ATS_PrintTestStatus("available()", f.available() != 0);
|
||||
ATS_PrintTestStatus("available()", f.available() != 0);
|
||||
ATS_PrintTestStatus("available()", f.available() != 0);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'h');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'h');
|
||||
ATS_PrintTestStatus("available()", f.available() == 0);
|
||||
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 = SD.open("test2.txt", FILE_WRITE);
|
||||
ATS_PrintTestStatus("SD.open()", f);
|
||||
if (!f) goto done;
|
||||
|
||||
f.print("ABC");
|
||||
f.close();
|
||||
|
||||
f = SD.open("test.txt");
|
||||
ATS_PrintTestStatus("SD.open()", f);
|
||||
if (!f) goto done;
|
||||
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'a');
|
||||
|
||||
f.close();
|
||||
|
||||
f = SD.open("test2.txt");
|
||||
ATS_PrintTestStatus("SD.open()", f);
|
||||
if (!f) goto done;
|
||||
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'A');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'A');
|
||||
|
||||
f.close();
|
||||
|
||||
done:
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
#include <SD.h>
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
int startMemoryUsage = ATS_GetFreeMemory();
|
||||
boolean b;
|
||||
File f;
|
||||
|
||||
ATS_begin("Arduino", "SD Files Test");
|
||||
|
||||
ATS_PrintTestStatus("SD.begin()", b = SD.begin(4));
|
||||
if (!b) goto done;
|
||||
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.open()", f = SD.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 = SD.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 = SD.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:
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
// Tests writing to and reading from a file, in particular the
|
||||
// the Stream implementation (e.g. read() and peek()).
|
||||
|
||||
#include <SD.h>
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
int startMemoryUsage = ATS_GetFreeMemory();
|
||||
boolean b;
|
||||
File f;
|
||||
|
||||
ATS_begin("Arduino", "SD Test");
|
||||
|
||||
ATS_PrintTestStatus("SD.begin()", b = SD.begin(4));
|
||||
if (!b) goto done;
|
||||
|
||||
SD.remove("test.txt");
|
||||
|
||||
f = SD.open("test.txt", FILE_WRITE);
|
||||
ATS_PrintTestStatus("SD.open()", f);
|
||||
if (!f) goto done;
|
||||
|
||||
ATS_PrintTestStatus("initial position", f.position() == 0);
|
||||
ATS_PrintTestStatus("initial size", f.size() == 0);
|
||||
|
||||
f.print("0123456789");
|
||||
|
||||
ATS_PrintTestStatus("position after writing", f.position() == 10);
|
||||
ATS_PrintTestStatus("size after writing", f.size() == 10);
|
||||
|
||||
f.seek(0);
|
||||
|
||||
ATS_PrintTestStatus("size after seek", f.size() == 10);
|
||||
ATS_PrintTestStatus("position after seek", f.position() == 0);
|
||||
|
||||
f.seek(7);
|
||||
|
||||
ATS_PrintTestStatus("position after seek", f.position() == 7);
|
||||
ATS_PrintTestStatus("reading after seek", f.read() == '7');
|
||||
ATS_PrintTestStatus("position after reading after seeking", f.position() == 8);
|
||||
ATS_PrintTestStatus("reading after reading after seeking", f.read() == '8');
|
||||
|
||||
f.seek(3);
|
||||
|
||||
ATS_PrintTestStatus("position after seeking", f.position() == 3);
|
||||
ATS_PrintTestStatus("peeking after seeking", f.peek() == '3');
|
||||
ATS_PrintTestStatus("position after peeking after seeking", f.position() == 3);
|
||||
ATS_PrintTestStatus("peeking after peeking after seeking", f.peek() == '3');
|
||||
ATS_PrintTestStatus("position after peeking after seeking", f.position() == 3);
|
||||
ATS_PrintTestStatus("peeking after peeking after seeking", f.read() == '3');
|
||||
ATS_PrintTestStatus("position after peeking after seeking", f.position() == 4);
|
||||
|
||||
f.seek(1);
|
||||
|
||||
ATS_PrintTestStatus("position after seeking", f.position() == 1);
|
||||
ATS_PrintTestStatus("peeking after seeking", f.peek() == '1');
|
||||
|
||||
f.seek(4);
|
||||
|
||||
ATS_PrintTestStatus("position after seeking", f.position() == 4);
|
||||
ATS_PrintTestStatus("peeking after seeking", f.peek() == '4');
|
||||
|
||||
f.seek(7);
|
||||
|
||||
ATS_PrintTestStatus("position()", f.position() == 7);
|
||||
ATS_PrintTestStatus("read()", f.read() == '7');
|
||||
|
||||
f.seek(0);
|
||||
f.peek();
|
||||
f.print("AB");
|
||||
|
||||
ATS_PrintTestStatus("position()", f.position() == 2);
|
||||
ATS_PrintTestStatus("size()", f.size() == 10);
|
||||
ATS_PrintTestStatus("read()", f.read() == '2');
|
||||
|
||||
f.seek(0);
|
||||
|
||||
ATS_PrintTestStatus("read()", f.read() == 'A');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'B');
|
||||
ATS_PrintTestStatus("read()", f.read() == '2');
|
||||
|
||||
f.close();
|
||||
|
||||
f = SD.open("test.txt");
|
||||
ATS_PrintTestStatus("SD.open()", f);
|
||||
if (!f) goto done;
|
||||
|
||||
ATS_PrintTestStatus("position()", f.position() == 0);
|
||||
ATS_PrintTestStatus("size()", f.size() == 10);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == 'A');
|
||||
ATS_PrintTestStatus("read()", f.read() == 'A');
|
||||
|
||||
f.seek(4);
|
||||
|
||||
ATS_PrintTestStatus("position()", f.position() == 4);
|
||||
ATS_PrintTestStatus("size()", f.size() == 10);
|
||||
ATS_PrintTestStatus("peek()", f.peek() == '4');
|
||||
ATS_PrintTestStatus("read()", f.read() == '4');
|
||||
|
||||
f.close();
|
||||
|
||||
done:
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
void loop() {}
|
|
@ -0,0 +1,52 @@
|
|||
//************************************************************************
|
||||
//* Arduino Test Example Skeleton
|
||||
//* (C) 2010 by Rick Anderson
|
||||
//* Open source as per standard Arduino code
|
||||
//*
|
||||
//************************************************************************
|
||||
//* Oct 16, 2010 <ROA> Started on String Test
|
||||
//************************************************************************
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
void setup()
|
||||
{
|
||||
int startMemoryUsage;
|
||||
|
||||
//startMemoryUsage must be set directly before ATS_begin
|
||||
startMemoryUsage = ATS_GetFreeMemory();
|
||||
ATS_begin("Arduino", "Skeleton Test");
|
||||
/*
|
||||
* Test Run Start
|
||||
* Test one passes because result is set to true
|
||||
* Test two fails becuase result is set to false
|
||||
* You can test memory for any set of tests by using the ATS_ReportMemoryUsage test
|
||||
* There is also a way to print current memeory for debugging
|
||||
*/
|
||||
ATS_PrintTestStatus("1. Test of true test status", true);
|
||||
|
||||
ATS_PrintTestStatus("2. Test of false test status, this will fail.", false);
|
||||
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
/*
|
||||
* Test Run End
|
||||
*/
|
||||
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
//************************************************************************
|
||||
//* Arduino Test Example Skeleton
|
||||
//* (C) 2010 by Rick Anderson
|
||||
//* Open source as per standard Arduino code
|
||||
//*
|
||||
//************************************************************************
|
||||
//* Oct 16, 2010 <ROA> Started on String Test
|
||||
//************************************************************************
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
void setup()
|
||||
{
|
||||
char testName[64];
|
||||
int startMemoryUsage;
|
||||
/*
|
||||
* Create variable for the tests.
|
||||
*/
|
||||
|
||||
|
||||
String stringOne;
|
||||
int firstClosingBracket;
|
||||
int firstOpeningBracket;
|
||||
int secondOpeningBracket;
|
||||
int secondClosingBracket;
|
||||
int bodyTag;
|
||||
int firstListItem;
|
||||
int secondListItem;
|
||||
int lastOpeningBracket;
|
||||
int lastListItem;
|
||||
int lastParagraph;
|
||||
int secondLastGraf;
|
||||
|
||||
/*;
|
||||
* initiate the test run
|
||||
*/
|
||||
startMemoryUsage = ATS_GetFreeMemory();
|
||||
ATS_begin("Arduino", "String Memory Test");
|
||||
// indexOf() returns the position (i.e. index) of a particular character
|
||||
// in a string. For example, if you were parsing HTML tags, you could use it:
|
||||
stringOne = "<HTML><HEAD><BODY>";
|
||||
firstClosingBracket = stringOne.indexOf('>');
|
||||
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
|
||||
|
||||
stringOne = "<HTML><HEAD><BODY>";
|
||||
secondOpeningBracket = firstClosingBracket + 1;
|
||||
secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket );
|
||||
Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket);
|
||||
|
||||
// you can also use indexOf() to search for Strings:
|
||||
stringOne = "<HTML><HEAD><BODY>";
|
||||
bodyTag = stringOne.indexOf("<BODY>");
|
||||
Serial.println("The index of the body tag in the string " + stringOne + " is " + bodyTag);
|
||||
|
||||
stringOne = "<UL><LI>item<LI>item<LI>item</UL>";
|
||||
firstListItem = stringOne.indexOf("<LI>");
|
||||
secondListItem = stringOne.indexOf("item", firstListItem + 1 );
|
||||
Serial.println("The index of the second list item in the string " + stringOne + " is " + secondClosingBracket);
|
||||
|
||||
// lastIndexOf() gives you the last occurrence of a character or string:
|
||||
lastOpeningBracket = stringOne.lastIndexOf('<');
|
||||
Serial.println("The index of the last < in the string " + stringOne + " is " + lastOpeningBracket);
|
||||
|
||||
lastListItem = stringOne.lastIndexOf("<LI>");
|
||||
Serial.println("The index of the last list item in the string " + stringOne + " is " + lastListItem);
|
||||
|
||||
|
||||
// lastIndexOf() can also search for a string:
|
||||
stringOne = "<p>Lorem ipsum dolor sit amet</p><p>Ipsem</p><p>Quod</p>";
|
||||
lastParagraph = stringOne.lastIndexOf("<p");
|
||||
secondLastGraf = stringOne.lastIndexOf("<p", lastParagraph - 1);
|
||||
Serial.println("The index of the second last paragraph tag " + stringOne + " is " + secondLastGraf);
|
||||
|
||||
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Test complete
|
||||
*/
|
||||
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
//************************************************************************
|
||||
//* Arduino String Test
|
||||
//* (C) 2010 by Rick Anderson
|
||||
//* Open source as per standard Arduino code
|
||||
//*
|
||||
//************************************************************************
|
||||
//* Oct 16, 2010 <ROA> Started on String Test
|
||||
//************************************************************************
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
void setup()
|
||||
{
|
||||
|
||||
int startMemoryUsage;
|
||||
|
||||
ATS_begin("Arduino", "Test of String Library");
|
||||
|
||||
/*
|
||||
* Test Variable Setup
|
||||
* Best practive set all your test variables prior to teseting.
|
||||
* This is required for Memory tests.
|
||||
*/
|
||||
|
||||
String stringOne = String("stringThree = ");
|
||||
String stringTwo = String("this string");
|
||||
String stringThree = String ();
|
||||
char charResult[100];
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Run the tests
|
||||
*/
|
||||
|
||||
// adding a constant integer to a string:
|
||||
stringThree = stringOne + 123;
|
||||
//strcpy(charResult, "\0");
|
||||
stringThree.toCharArray(charResult, sizeof(charResult));
|
||||
|
||||
ATS_PrintTestStatus("1. Adding a constant integer to a string:", strcmp(charResult,"stringThree = 123" ) == 0);
|
||||
|
||||
// adding a constant long interger to a string:
|
||||
stringThree = stringOne + 123456789;
|
||||
stringThree.toCharArray(charResult, sizeof(charResult));
|
||||
|
||||
ATS_PrintTestStatus("2. Adding a constant long interger to a string", strcmp(charResult,"stringThree = 123456789" ) == 0);
|
||||
|
||||
|
||||
// adding a constant character to a string:
|
||||
stringThree = stringOne + 'A';
|
||||
stringThree.toCharArray(charResult, sizeof(charResult));
|
||||
|
||||
ATS_PrintTestStatus("3. Adding a constant character to a string", strcmp(charResult,"stringThree = A" ) == 0);
|
||||
|
||||
|
||||
// adding a constant string to a string:
|
||||
stringThree = stringOne + "abc";
|
||||
stringThree.toCharArray(charResult, sizeof(charResult));
|
||||
|
||||
ATS_PrintTestStatus("4. Adding a constant string variable to a string", strcmp(charResult,"stringThree = abc" ) == 0);
|
||||
|
||||
//"5. Adding a constant long interger to a string"
|
||||
stringThree = stringOne + stringTwo;
|
||||
stringThree.toCharArray(charResult, sizeof(charResult));
|
||||
|
||||
ATS_PrintTestStatus("5. Adding a constant long interger to a string", strcmp(charResult,"stringThree = this string" ) == 0);
|
||||
|
||||
|
||||
/*
|
||||
* setup up String Comparison Operater Tests
|
||||
*/
|
||||
|
||||
stringOne = String("this");
|
||||
stringTwo = String("that");
|
||||
|
||||
// two strings equal:
|
||||
ATS_PrintTestStatus("6. Two strings equal",stringOne == "this");
|
||||
|
||||
// two strings not equal:
|
||||
ATS_PrintTestStatus("7. Two strings not equal",stringOne != stringTwo);
|
||||
|
||||
// two strings not equal (case sensitivity matters):
|
||||
stringOne = "This";
|
||||
stringTwo = "this";
|
||||
ATS_PrintTestStatus("8. Two strings not equal [case sensitivity matters]", stringOne != stringTwo);
|
||||
|
||||
// you can also use equals() to see if two strings are the same:
|
||||
stringOne = "this";
|
||||
stringTwo = "this";
|
||||
ATS_PrintTestStatus("9. Equals() method equals", stringOne.equals(stringTwo));
|
||||
|
||||
|
||||
// you can also use not equals() to see if two strings are not the same:
|
||||
stringOne = String("This");
|
||||
stringTwo = String("this");
|
||||
ATS_PrintTestStatus("10. Not equals() method equals", !stringOne.equals(stringTwo));
|
||||
|
||||
// or perhaps you want to ignore case:
|
||||
ATS_PrintTestStatus("11. EqualsIgnoreCase() method equals", stringOne.equalsIgnoreCase(stringTwo));
|
||||
|
||||
// a numeric string compared to the number it represents:
|
||||
stringOne = "1";
|
||||
int numberOne = 1;
|
||||
ATS_PrintTestStatus("12. A numeric string compared to the number it represents", stringOne == numberOne);
|
||||
|
||||
// two numeric strings compared:
|
||||
stringOne = "2";
|
||||
stringTwo = "1";
|
||||
ATS_PrintTestStatus("13. Two numeric strings compared",stringOne >= stringTwo);
|
||||
|
||||
|
||||
// comparison operators can be used to compare strings for alphabetic sorting too:
|
||||
|
||||
/*
|
||||
stringOne = String("Brown");
|
||||
ATS_PrintTestStatus("14. comparison operator < can be used to compare strings for alphabetic sorting ",stringOne < "Charles");
|
||||
ATS_PrintTestStatus("15. comparison operator > can be used to compare strings for alphabetic sorting ",stringOne > "Adams");
|
||||
ATS_PrintTestStatus("16. comparison operator <= can be used to compare strings for alphabetic sorting ",stringOne <= "Browne");
|
||||
ATS_PrintTestStatus("17. comparison operator >= can be used to compare strings for alphabetic sorting ",stringOne >= "Brow");
|
||||
*/
|
||||
|
||||
|
||||
// the compareTo() operator also allows you to compare strings
|
||||
stringOne = "Cucumber";
|
||||
stringTwo = "Cucuracha";
|
||||
|
||||
ATS_PrintTestStatus("18. The compareTo() operator also allows you to compare strings", stringOne.compareTo(stringTwo) < 0);
|
||||
|
||||
// compareTo() String with numnber > String with number:
|
||||
stringOne = "Sensor: 50";
|
||||
stringTwo= "Sensor: 150";
|
||||
ATS_PrintTestStatus("19. The compareTo() String with integers", stringOne.compareTo(stringTwo) < 0);
|
||||
|
||||
|
||||
// compareTo() String with numnber > String with number append integer, matches example code:
|
||||
stringOne = "Sensor: ";
|
||||
stringTwo= "Sensor: ";
|
||||
stringOne += 50;
|
||||
stringTwo += 150;
|
||||
ATS_PrintTestStatus("20. The compareTo() compare strings with appended integers", stringOne.compareTo(stringTwo) < 0);
|
||||
|
||||
|
||||
/*
|
||||
* setup up String Append Operation Tests
|
||||
*/
|
||||
// Serious awful problem here
|
||||
stringOne = String("Sensor ");
|
||||
stringTwo = String("value");
|
||||
|
||||
stringOne += stringTwo;
|
||||
ATS_PrintTestStatus("21. Adding string to string += ", stringOne.equals("Sensor value"));
|
||||
|
||||
ATS_PrintTestStatus("22. The compareTo() compare strings with appended integers", stringOne.compareTo(stringTwo) < 0);
|
||||
/*
|
||||
* Test complete
|
||||
*/
|
||||
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,250 @@
|
|||
//************************************************************************
|
||||
//* Arduino Test Suite
|
||||
//* ATS_ToneTest
|
||||
//*
|
||||
//* Copyright (c) 2010 Mark Sproul All right reserved.
|
||||
//*
|
||||
//* This library is free software; you can redistribute it and/or
|
||||
//* modify it under the terms of the GNU Lesser General Public
|
||||
//* License as published by the Free Software Foundation; either
|
||||
//* version 2.1 of the License, or (at your option) any later version.
|
||||
//*
|
||||
//* This library is distributed in the hope that it will be useful,
|
||||
//* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
//* Lesser General Public License for more details.
|
||||
//*
|
||||
//* You should have received a copy of the GNU Lesser General Public
|
||||
//* License along with this library; if not, write to the Free Software
|
||||
//* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
//************************************************************************
|
||||
//* Aug 31, 2010 <MLS> Started on TestArduino
|
||||
//* Oct 23, 2010 <MLS> Started on ToneTest
|
||||
//************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "HardwareSerial.h"
|
||||
|
||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
|
||||
#define kBoard_PinCount 20
|
||||
#define kBoard_AnalogCount 6
|
||||
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||
#define kBoard_PinCount 70
|
||||
#define kBoard_AnalogCount 16
|
||||
#endif
|
||||
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
void TestTonePin(uint8_t toneOutputPinNumber)
|
||||
{
|
||||
uint8_t helperpin;
|
||||
unsigned long startMilliSecs;
|
||||
unsigned long highCount, lowCount;
|
||||
int previousState;
|
||||
int currentState;
|
||||
char testNameString[80];
|
||||
long outputFreq;
|
||||
long measuredFreq;
|
||||
boolean passed;
|
||||
long percentError;
|
||||
long deltaFreq;
|
||||
|
||||
if ((toneOutputPinNumber % 2) == 0)
|
||||
{
|
||||
//* if its EVEN, add 1
|
||||
helperpin = toneOutputPinNumber + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//* if its ODD
|
||||
helperpin = toneOutputPinNumber - 1;
|
||||
}
|
||||
|
||||
//* dont set the mode of the OUTPUT pin, the tone command does that
|
||||
|
||||
pinMode(helperpin, INPUT);
|
||||
|
||||
previousState = digitalRead(helperpin);
|
||||
startMilliSecs = millis();
|
||||
highCount = 0;
|
||||
lowCount = 0;
|
||||
measuredFreq = 0;
|
||||
//* we are going to watch for one second
|
||||
outputFreq = random(200, 2000);
|
||||
|
||||
tone(toneOutputPinNumber, outputFreq);
|
||||
while ((millis() - startMilliSecs) < 1000)
|
||||
{
|
||||
currentState = digitalRead(helperpin);
|
||||
if (currentState == HIGH)
|
||||
{
|
||||
highCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
lowCount++;
|
||||
}
|
||||
//* check to see if it changed state
|
||||
if ((currentState == HIGH) && (previousState == LOW))
|
||||
{
|
||||
measuredFreq++;
|
||||
}
|
||||
|
||||
previousState = currentState;
|
||||
}
|
||||
noTone(toneOutputPinNumber);
|
||||
|
||||
deltaFreq = abs(measuredFreq - outputFreq);
|
||||
|
||||
percentError = 100 - abs(((outputFreq - deltaFreq) * 100) / outputFreq);
|
||||
|
||||
sprintf(testNameString, "ToneTest.%02d (out freq= %4ld measured freq= %4ld err= %ld%%)", toneOutputPinNumber, outputFreq, measuredFreq, percentError);
|
||||
if (percentError < 5)
|
||||
{
|
||||
passed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
passed = false;
|
||||
}
|
||||
|
||||
ATS_PrintTestStatus(testNameString, passed);
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
//* this test to make sure the duration option works
|
||||
void TestToneDuration(uint8_t toneOutputPinNumber)
|
||||
{
|
||||
uint8_t helperpin;
|
||||
unsigned long startMilliSecs;
|
||||
unsigned long highCount, lowCount;
|
||||
int previousState;
|
||||
int currentState;
|
||||
char testNameString[80];
|
||||
long outputFreq;
|
||||
long measuredFreq;
|
||||
boolean passed;
|
||||
long percentError;
|
||||
long deltaFreq;
|
||||
long durationTime;
|
||||
|
||||
if ((toneOutputPinNumber % 2) == 0)
|
||||
{
|
||||
//* if its EVEN, add 1
|
||||
helperpin = toneOutputPinNumber + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//* if its ODD
|
||||
helperpin = toneOutputPinNumber - 1;
|
||||
}
|
||||
|
||||
//* dont set the mode of the OUTPUT pin, the tone command does that
|
||||
|
||||
pinMode(helperpin, INPUT);
|
||||
|
||||
previousState = digitalRead(helperpin);
|
||||
startMilliSecs = millis();
|
||||
highCount = 0;
|
||||
lowCount = 0;
|
||||
measuredFreq = 0;
|
||||
durationTime = 0;
|
||||
//* we are going to watch for one second
|
||||
outputFreq = random(500, 2000);
|
||||
|
||||
tone(toneOutputPinNumber, outputFreq, 1000);
|
||||
while ((millis() - startMilliSecs) < 2000)
|
||||
{
|
||||
currentState = digitalRead(helperpin);
|
||||
if (currentState == HIGH)
|
||||
{
|
||||
highCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
lowCount++;
|
||||
}
|
||||
//* count the freq
|
||||
if ((currentState == HIGH) && (previousState == LOW))
|
||||
{
|
||||
measuredFreq++;
|
||||
}
|
||||
|
||||
//* check to see if it changed state
|
||||
if (currentState != previousState)
|
||||
{
|
||||
durationTime = millis() - startMilliSecs;
|
||||
}
|
||||
|
||||
previousState = currentState;
|
||||
}
|
||||
|
||||
deltaFreq = abs(measuredFreq - outputFreq);
|
||||
|
||||
percentError = 100 - abs(((outputFreq - deltaFreq) * 100) / outputFreq);
|
||||
|
||||
sprintf(testNameString, "ToneTesDurationt.%02d (durationTime =%4ld/1000 freq err= %ld%%)", toneOutputPinNumber, durationTime, percentError);
|
||||
if ((durationTime > 990) && (durationTime < 1010) && (percentError < 5))
|
||||
{
|
||||
passed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
passed = false;
|
||||
}
|
||||
noTone(toneOutputPinNumber);
|
||||
|
||||
ATS_PrintTestStatus(testNameString, passed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void setup()
|
||||
{
|
||||
short ii;
|
||||
uint8_t timerNumber;
|
||||
int startMemoryUsage;
|
||||
|
||||
startMemoryUsage = ATS_GetFreeMemory();
|
||||
|
||||
ATS_begin("Arduino", "ToneTest");
|
||||
|
||||
|
||||
//* we start at 2 because 0/1 are RXD/TXD
|
||||
for (ii=2; ii<kBoard_PinCount; ii++)
|
||||
{
|
||||
TestTonePin(ii);
|
||||
}
|
||||
|
||||
|
||||
//* we dont need to test every pin
|
||||
for (ii=2; ii<kBoard_PinCount; ii += 5)
|
||||
{
|
||||
TestToneDuration(ii);
|
||||
}
|
||||
|
||||
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in a new issue