mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
ArduinoTestSuite updates from Paul Stoffregen
This commit is contained in:
@ -7,7 +7,6 @@
|
||||
//* Oct 16, 2010 <ROA> Test of Arduino Constants
|
||||
//************************************************************************
|
||||
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
|
@ -1 +1,101 @@
|
||||
//************************************************************************
|
||||
//************************************************************************
|
||||
//* 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 <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()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -8,11 +8,7 @@
|
||||
//* Oct 18, 2010 <MLS> Added memory testing
|
||||
//************************************************************************
|
||||
|
||||
#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
|
||||
@ -20,6 +16,12 @@
|
||||
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||
#define kBoard_PinCount 70
|
||||
#define kBoard_AnalogCount 16
|
||||
|
||||
#elif defined(CORE_TEENSY)
|
||||
#define kBoard_PinCount CORE_NUM_TOTAL_PINS
|
||||
#define kBoard_AnalogCount CORE_NUM_ANALOG
|
||||
#define SERIAL_PORT_COUNT 2
|
||||
HardwareSerial Serial1 = HardwareSerial();
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
//* Oct 16, 2010 <ROA> Started on String Test
|
||||
//************************************************************************
|
||||
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
|
@ -7,19 +7,12 @@
|
||||
//* Oct 16, 2010 <ROA> Started on String Test
|
||||
//************************************************************************
|
||||
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
void setup()
|
||||
|
||||
void do_string_operations(int startMemoryUsage)
|
||||
{
|
||||
char testName[64];
|
||||
int startMemoryUsage;
|
||||
/*
|
||||
* Create variable for the tests.
|
||||
*/
|
||||
|
||||
|
||||
String stringOne;
|
||||
int firstClosingBracket;
|
||||
int firstOpeningBracket;
|
||||
@ -31,67 +24,77 @@ void setup()
|
||||
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:
|
||||
int secondLastParagraph;
|
||||
int thirdLastParagraph;
|
||||
|
||||
// 1111111111
|
||||
// 01234567890123456789
|
||||
stringOne = "<HTML><HEAD><BODY>";
|
||||
firstClosingBracket = stringOne.indexOf('>');
|
||||
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
|
||||
ATS_PrintTestStatus("firstClosingBracket", firstClosingBracket == 5);
|
||||
|
||||
// 1111111111
|
||||
// 01234567890123456789
|
||||
stringOne = "<HTML><HEAD><BODY>";
|
||||
secondOpeningBracket = firstClosingBracket + 1;
|
||||
secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket );
|
||||
Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket);
|
||||
ATS_PrintTestStatus("secondClosingBracket", secondClosingBracket == 11);
|
||||
|
||||
// you can also use indexOf() to search for Strings:
|
||||
// 1111111111
|
||||
// 01234567890123456789
|
||||
stringOne = "<HTML><HEAD><BODY>";
|
||||
bodyTag = stringOne.indexOf("<BODY>");
|
||||
Serial.println("The index of the body tag in the string " + stringOne + " is " + bodyTag);
|
||||
ATS_PrintTestStatus("bodyTag", bodyTag == 12);
|
||||
|
||||
// 111111111122222222223333333333
|
||||
// 0123456789012345678901234567890123456789
|
||||
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);
|
||||
secondListItem = stringOne.indexOf("<LI>", firstListItem + 1 );
|
||||
|
||||
ATS_PrintTestStatus("firstListItem", firstListItem == 4);
|
||||
ATS_PrintTestStatus("secondListItem", secondListItem == 12);
|
||||
|
||||
// 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);
|
||||
|
||||
ATS_PrintTestStatus("lastOpeningBracket", lastOpeningBracket == 28);
|
||||
|
||||
lastListItem = stringOne.lastIndexOf("<LI>");
|
||||
Serial.println("The index of the last list item in the string " + stringOne + " is " + lastListItem);
|
||||
|
||||
ATS_PrintTestStatus("lastListItem", lastListItem == 20);
|
||||
|
||||
// lastIndexOf() can also search for a string:
|
||||
// 11111111112222222222333333333344444444445555555555
|
||||
// 012345678901234567890123456789012345678901234567890123456789
|
||||
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);
|
||||
secondLastParagraph = stringOne.lastIndexOf("<p", lastParagraph - 1);
|
||||
thirdLastParagraph = stringOne.lastIndexOf("<p", secondLastParagraph - 1);
|
||||
ATS_PrintTestStatus("lastParagraph", lastParagraph == 45);
|
||||
ATS_PrintTestStatus("secondLastParagraph", secondLastParagraph == 33);
|
||||
ATS_PrintTestStatus("thirdLastParagraph", thirdLastParagraph == 0);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
int startMemoryUsage=0;
|
||||
|
||||
startMemoryUsage = ATS_GetFreeMemory();
|
||||
ATS_begin("Arduino", "String Memory Test");
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Test complete
|
||||
*/
|
||||
|
||||
// Run all the string functions. All string objects used are local variables,
|
||||
// so they go out of scope upon return. Memory used should be fully released.
|
||||
do_string_operations(startMemoryUsage);
|
||||
|
||||
ATS_ReportMemoryUsage(startMemoryUsage);
|
||||
ATS_end();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//************************************************************************
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
//* Oct 16, 2010 <ROA> Started on String Test
|
||||
//************************************************************************
|
||||
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
@ -101,10 +100,14 @@ void setup()
|
||||
// or perhaps you want to ignore case:
|
||||
ATS_PrintTestStatus("11. EqualsIgnoreCase() method equals", stringOne.equalsIgnoreCase(stringTwo));
|
||||
|
||||
#if ARDUINO < 100 || defined(CORE_TEENSY)
|
||||
// David Mellis decided not to keep implicit string to number comparison operators
|
||||
// in Arduino 1.0. Only run this test on older version, or if using Teensy
|
||||
// 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);
|
||||
#endif
|
||||
|
||||
// two numeric strings compared:
|
||||
stringOne = "2";
|
||||
@ -129,18 +132,18 @@ void setup()
|
||||
|
||||
ATS_PrintTestStatus("18. The compareTo() operator also allows you to compare strings", stringOne.compareTo(stringTwo) < 0);
|
||||
|
||||
// These two tests assume the string compare parses numbers
|
||||
// within strings, but it does not actually do any such thing
|
||||
// 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);
|
||||
|
||||
|
||||
//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);
|
||||
//stringOne = "Sensor: ";
|
||||
//stringTwo= "Sensor: ";
|
||||
//stringOne += 50;
|
||||
//stringTwo += 150;
|
||||
//ATS_PrintTestStatus("20. The compareTo() compare strings with appended integers", stringOne.compareTo(stringTwo) < 0);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -1,18 +1,5 @@
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
void Test_Equal(char *testString, char *expected, const String &actual)
|
||||
{
|
||||
char buf[100]; actual.toCharArray(buf, 100);
|
||||
boolean b = (strcmp(buf, expected) == 0);
|
||||
ATS_PrintTestStatus(testString, b);
|
||||
if (!b) {
|
||||
Serial.print("expected '");
|
||||
Serial.print(expected);
|
||||
Serial.print("', actual '");
|
||||
Serial.print(actual);
|
||||
Serial.println("'");
|
||||
}
|
||||
}
|
||||
#include "Test_Equal.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
@ -22,11 +22,7 @@
|
||||
//* Oct 23, 2010 <MLS> Started on ToneTest
|
||||
//************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "HardwareSerial.h"
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
|
||||
#define kBoard_PinCount 20
|
||||
@ -34,10 +30,11 @@
|
||||
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||
#define kBoard_PinCount 70
|
||||
#define kBoard_AnalogCount 16
|
||||
#elif defined(CORE_TEENSY)
|
||||
#define kBoard_PinCount CORE_NUM_TOTAL_PINS
|
||||
#define kBoard_AnalogCount CORE_NUM_ANALOG
|
||||
#endif
|
||||
|
||||
#include <ArduinoTestSuite.h>
|
||||
|
||||
//************************************************************************
|
||||
void TestTonePin(uint8_t toneOutputPinNumber)
|
||||
{
|
||||
@ -63,6 +60,7 @@ long deltaFreq;
|
||||
//* if its ODD
|
||||
helperpin = toneOutputPinNumber - 1;
|
||||
}
|
||||
if (helperpin >= kBoard_PinCount) return;
|
||||
|
||||
//* dont set the mode of the OUTPUT pin, the tone command does that
|
||||
|
||||
@ -143,6 +141,7 @@ long durationTime;
|
||||
//* if its ODD
|
||||
helperpin = toneOutputPinNumber - 1;
|
||||
}
|
||||
if (helperpin >= kBoard_PinCount) return;
|
||||
|
||||
//* dont set the mode of the OUTPUT pin, the tone command does that
|
||||
|
||||
|
Reference in New Issue
Block a user