diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4bd1060 --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +# +# Some common rules +# +.* +*.o +*.a +*.s +*.ko +*.so +*.so.dbg +*.i +*.lst +*.symtypes +*.gz +*.bz2 +*.lzma +*.xz +*.lz4 +*.lzo +*.patch + +core +core.* + +# +# Backup files +# +*.orig +*~ +\#*# + +# +# python +# +*.pyc + +# +# git files that we don't want to ignore even it they are dot-files +# +!.gitignore + +# Some IDE, I don't know which +/.settings +/.cproject +/.project + diff --git a/examples/ATS_ClientTest/ATS_ClientTest.ino b/examples/ATS_ClientTest/ATS_ClientTest.ino index a2c22aa..9df70c3 100644 --- a/examples/ATS_ClientTest/ATS_ClientTest.ino +++ b/examples/ATS_ClientTest/ATS_ClientTest.ino @@ -15,44 +15,34 @@ EthernetClient client; void setup() { - int startMemoryUsage; - Ethernet.begin(mac); - startMemoryUsage = ATS_GetFreeMemory(); - ATS_begin("Arduino 1.0", "ATS_httpClient Tests"); - - ATS_PrintTestStatus("1. DCHCP Address obtained", testDHCP()); - - ATS_ReportMemoryUsage(startMemoryUsage); - ATS_end(); - + Ethernet.begin(mac); + int startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino 1.0", "ATS_httpClient Tests"); + ATS_PrintTestStatus("1. DCHCP Address obtained", testDHCP()); + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } //Test if IP DHCP address receieved boolean testDHCP() { - Serial.println("testDHCP"); - - int temp = 0; - IPAddress ip = Ethernet.localIP(); - int length = Serial.println(ip); - Serial.println(length); - - for (int nn = 0; nn < 4; nn++) - { - temp = temp + ip[nn]; - } - if (temp == 0) - { - return false; - } - return true; + Serial.println("testDHCP"); + + int temp = 0; + IPAddress ip = Ethernet.localIP(); + int length = Serial.println(ip); + Serial.println(length); + + for (int nn = 0; nn < 4; nn++) { + temp = temp + ip[nn]; + } + if (temp == 0) { + return false; + } + return true; } - void loop() { - - } - diff --git a/examples/ATS_Constants/ATS_Constants.ino b/examples/ATS_Constants/ATS_Constants.ino index fc3aab7..61fae53 100644 --- a/examples/ATS_Constants/ATS_Constants.ino +++ b/examples/ATS_Constants/ATS_Constants.ino @@ -7,68 +7,46 @@ //* Oct 16, 2010 Test of Arduino Constants //************************************************************************ -#include +#include //************************************************************************ 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(); - + //Start memory usage must be site prior to ATS_begin + int 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() { - - } - - - - diff --git a/examples/ATS_Delay/ATS_Delay.ino b/examples/ATS_Delay/ATS_Delay.ino index 111302e..47b5ce0 100644 --- a/examples/ATS_Delay/ATS_Delay.ino +++ b/examples/ATS_Delay/ATS_Delay.ino @@ -22,80 +22,51 @@ //* Oct 28, 2010 Started on Delay //************************************************************************ -#include +#include //************************************************************************ 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(); - + short ii; + short testNum; + unsigned long startMillis; + unsigned long endMillis; + unsigned long deltaMillis; + unsigned long errMillis; + boolean passed; + char testNameString[80]; + + int 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(); - + 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; + endMillis = millis(); + deltaMillis = endMillis - startMillis; + if (deltaMillis >= ii) { + errMillis = deltaMillis - ii; + } else { + errMillis = ii - deltaMillis; } - else - { - passed = false; + if (errMillis <= 1) { + passed = true; + } else { + passed = false; } - sprintf(testNameString, "DelayTest.%02d (delay= %4d actual delay=%ld err=%ld)", testNum, ii, deltaMillis, errMillis); - + 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() { - - } - - - diff --git a/examples/ATS_General/ATS_General.ino b/examples/ATS_General/ATS_General.ino index 588342d..16e1580 100644 --- a/examples/ATS_General/ATS_General.ino +++ b/examples/ATS_General/ATS_General.ino @@ -8,88 +8,60 @@ //* Oct 18, 2010 Added memory testing //************************************************************************ -#include +#include -#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) -#define kBoard_PinCount 20 -#define kBoard_AnalogCount 6 +#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) + #define kBoard_PinCount 20 + #define kBoard_AnalogCount 6 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) -#define kBoard_PinCount 70 -#define kBoard_AnalogCount 16 - + #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(); + #define kBoard_PinCount CORE_NUM_TOTAL_PINS + #define kBoard_AnalogCount CORE_NUM_ANALOG + #define SERIAL_PORT_COUNT 2 + HardwareSerial Serial1 = HardwareSerial(); #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 1) - ATS_TestSerialLoopback(&Serial1, "Serial1"); + ATS_TestSerialLoopback(&Serial1, "Serial1"); #endif #if (SERIAL_PORT_COUNT > 2) - ATS_TestSerialLoopback(&Serial2, "Serial2"); + ATS_TestSerialLoopback(&Serial2, "Serial2"); #endif #if (SERIAL_PORT_COUNT > 3) - ATS_TestSerialLoopback(&Serial3, "Serial3"); + ATS_TestSerialLoopback(&Serial3, "Serial3"); #endif - - ATS_Test_EEPROM(); - - - ATS_ReportMemoryUsage(startMemoryUsage); - - ATS_end(); - + ATS_Test_EEPROM(); + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - - } - - - - diff --git a/examples/ATS_GetFreeMemory/ATS_GetFreeMemory.ino b/examples/ATS_GetFreeMemory/ATS_GetFreeMemory.ino index fd5fd23..4a9dd7b 100644 --- a/examples/ATS_GetFreeMemory/ATS_GetFreeMemory.ino +++ b/examples/ATS_GetFreeMemory/ATS_GetFreeMemory.ino @@ -8,106 +8,106 @@ //************************************************************************ #include -void setup() { - ATS_begin("Arduino", "ATS_GetFreeMemory() Tests"); - - testAllocatingThenDeallocatingPreservesFreeMemory(); - testAllocatingAndDeallocatingInterleavedPreservesFreeMemory(); - testRepeatedlyAllocatingAndDeallocatingMemoryPreservesFreeMemory(); - testReallocatingSmallerPreservesFreeMemory(); - testReallocatingLargerPreservesFreeMemory(); - testAllocatingAndDeallocatingSmallerPreservesFreeMemory(); - testReallocatingRepeatedlyLargerPreservesFreeMemory(); - - ATS_end(); +void setup() +{ + ATS_begin("Arduino", "ATS_GetFreeMemory() Tests"); + testAllocatingThenDeallocatingPreservesFreeMemory(); + testAllocatingAndDeallocatingInterleavedPreservesFreeMemory(); + testRepeatedlyAllocatingAndDeallocatingMemoryPreservesFreeMemory(); + testReallocatingSmallerPreservesFreeMemory(); + testReallocatingLargerPreservesFreeMemory(); + testAllocatingAndDeallocatingSmallerPreservesFreeMemory(); + testReallocatingRepeatedlyLargerPreservesFreeMemory(); + ATS_end(); } // This test checks that the free list is taken into account when free memory is calculated // when using versions of free() which *don't* reset __brkval (such as in avr-libc 1.6.4) -void testAllocatingThenDeallocatingPreservesFreeMemory() { - int startMemory = ATS_GetFreeMemory(); - - void* buffer = malloc(10); - free(buffer); - - ATS_PrintTestStatus("Allocating then deallocating preserves free memory", startMemory == ATS_GetFreeMemory()); +void testAllocatingThenDeallocatingPreservesFreeMemory() +{ + int startMemory = ATS_GetFreeMemory(); + void* buffer = malloc(10); + free(buffer); + ATS_PrintTestStatus("Allocating then deallocating preserves free memory", + startMemory == ATS_GetFreeMemory()); } // This test checks that the free list is taken into account when free memory is calculated // even when using versions of free() which *do* reset __brkval (such as in avr-libc 1.7.1) -void testAllocatingAndDeallocatingInterleavedPreservesFreeMemory() { - void* buffer1 = malloc(10); - int startMemory = ATS_GetFreeMemory(); - - void* buffer2 = malloc(10); - free(buffer1); - - ATS_PrintTestStatus("Interleaved allocation and deallocation preserves free memory", startMemory == ATS_GetFreeMemory()); - - free(buffer2); +void testAllocatingAndDeallocatingInterleavedPreservesFreeMemory() +{ + void* buffer1 = malloc(10); + int startMemory = ATS_GetFreeMemory(); + void* buffer2 = malloc(10); + free(buffer1); + ATS_PrintTestStatus("Interleaved allocation and deallocation preserves free memory", + startMemory == ATS_GetFreeMemory()); + free(buffer2); } -void testRepeatedlyAllocatingAndDeallocatingMemoryPreservesFreeMemory() { - int startMemory = ATS_GetFreeMemory(); - - for (int i = 0; i < 10; i++) { - void* buffer1 = malloc(10); - void* buffer2 = malloc(10); - void* buffer3 = malloc(10); - free(buffer3); - free(buffer2); - free(buffer1); - } - - ATS_PrintTestStatus("Repeated allocation and deallocation preserves free memory", startMemory == ATS_GetFreeMemory()); +void testRepeatedlyAllocatingAndDeallocatingMemoryPreservesFreeMemory() +{ + int startMemory = ATS_GetFreeMemory(); + for (int i = 0; i < 10; i++) { + void* buffer1 = malloc(10); + void* buffer2 = malloc(10); + void* buffer3 = malloc(10); + free(buffer3); + free(buffer2); + free(buffer1); + } + ATS_PrintTestStatus("Repeated allocation and deallocation preserves free memory", + startMemory == ATS_GetFreeMemory()); } // TODO MM Currently fails as __brkval is not increased, but the size of the free list is... // Therefore looks as if the total amount of free memory increases (i.e. negative memory leak)! -void testReallocatingSmallerPreservesFreeMemory() { - int startMemory = ATS_GetFreeMemory(); - - // Allocate one byte more than the space taken up by a free list node - void* buffer = malloc(5); - buffer = realloc(buffer, 1); - free(buffer); - - ATS_PrintTestStatus("Reallocating smaller preserves free memory", startMemory == ATS_GetFreeMemory()); +void testReallocatingSmallerPreservesFreeMemory() +{ + int startMemory = ATS_GetFreeMemory(); + // Allocate one byte more than the space taken up by a free list node + void* buffer = malloc(5); + buffer = realloc(buffer, 1); + free(buffer); + ATS_PrintTestStatus("Reallocating smaller preserves free memory", + startMemory == ATS_GetFreeMemory()); } -void testReallocatingLargerPreservesFreeMemory() { - int startMemory = ATS_GetFreeMemory(); - - void* buffer = malloc(1); - buffer = realloc(buffer, 5); - free(buffer); - - ATS_PrintTestStatus("Reallocating larger preserves free memory", startMemory == ATS_GetFreeMemory()); +void testReallocatingLargerPreservesFreeMemory() +{ + int startMemory = ATS_GetFreeMemory(); + void* buffer = malloc(1); + buffer = realloc(buffer, 5); + free(buffer); + ATS_PrintTestStatus("Reallocating larger preserves free memory", + startMemory == ATS_GetFreeMemory()); } -void testAllocatingAndDeallocatingSmallerPreservesFreeMemory() { - int startMemory = ATS_GetFreeMemory(); - - // Allocate one byte more than the space taken up by a free list node - void* buffer = malloc(5); - free(buffer); - buffer = malloc(1); - free(buffer); - - ATS_PrintTestStatus("Allocating and deallocating smaller preserves free memory", startMemory == ATS_GetFreeMemory()); +void testAllocatingAndDeallocatingSmallerPreservesFreeMemory() +{ + int startMemory = ATS_GetFreeMemory(); + // Allocate one byte more than the space taken up by a free list node + void* buffer = malloc(5); + free(buffer); + buffer = malloc(1); + free(buffer); + ATS_PrintTestStatus("Allocating and deallocating smaller preserves free memory", + startMemory == ATS_GetFreeMemory()); } -void testReallocatingRepeatedlyLargerPreservesFreeMemory() { - int startMemory = ATS_GetFreeMemory(); - - void* buffer = malloc(2); - for (int i = 4; i <= 8; i+=2) { - buffer = realloc(buffer, i); - } - free(buffer); - - ATS_PrintTestStatus("Reallocating repeatedly larger preserves free memory", startMemory == ATS_GetFreeMemory()); +void testReallocatingRepeatedlyLargerPreservesFreeMemory() +{ + int startMemory = ATS_GetFreeMemory(); + void* buffer = malloc(2); + for (int i = 4; i <= 8; i+=2) { + buffer = realloc(buffer, i); + } + free(buffer); + ATS_PrintTestStatus("Reallocating repeatedly larger preserves free memory", + startMemory == ATS_GetFreeMemory()); } -void loop() { +void loop() +{ } + diff --git a/examples/ATS_SD_File/ATS_SD_File.ino b/examples/ATS_SD_File/ATS_SD_File.ino index ee09c15..1b6d3bd 100644 --- a/examples/ATS_SD_File/ATS_SD_File.ino +++ b/examples/ATS_SD_File/ATS_SD_File.ino @@ -6,103 +6,108 @@ void setup() { - int startMemoryUsage = ATS_GetFreeMemory(); - boolean b; - File f; - byte buf[] = { 'f', 'g', 'h' }; - - 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.write("abc"); - f.print("de"); - f.close(); - - f = SD.open("test.txt", FILE_WRITE); - ATS_PrintTestStatus("SD.open()", f); - if (!f) goto done; - - f.write(buf, 3); - 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.write('A'); - f.print("BC"); - 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(); + int startMemoryUsage = ATS_GetFreeMemory(); + boolean b; + File f; + byte buf[] = { 'f', 'g', 'h' }; -done: - ATS_ReportMemoryUsage(startMemoryUsage); - ATS_end(); + 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.write("abc"); + f.print("de"); + f.close(); + + f = SD.open("test.txt", FILE_WRITE); + ATS_PrintTestStatus("SD.open()", f); + if (!f) + goto done; + + f.write(buf, 3); + 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"); -void loop() {} + f = SD.open("test2.txt", FILE_WRITE); + ATS_PrintTestStatus("SD.open()", f); + if (!f) + goto done; + f.write('A'); + f.print("BC"); + 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() +{ +} diff --git a/examples/ATS_SD_Files/ATS_SD_Files.ino b/examples/ATS_SD_Files/ATS_SD_Files.ino index c3804f4..6742637 100644 --- a/examples/ATS_SD_Files/ATS_SD_Files.ino +++ b/examples/ATS_SD_Files/ATS_SD_Files.ino @@ -3,76 +3,80 @@ 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")); + int startMemoryUsage = ATS_GetFreeMemory(); + boolean b; + File f; - 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(); + 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")); -void loop() {} + 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() +{ +} diff --git a/examples/ATS_SD_Seek/ATS_SD_Seek.ino b/examples/ATS_SD_Seek/ATS_SD_Seek.ino index 5b0916c..5768774 100644 --- a/examples/ATS_SD_Seek/ATS_SD_Seek.ino +++ b/examples/ATS_SD_Seek/ATS_SD_Seek.ino @@ -6,104 +6,116 @@ 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(); + 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(); + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); +} +void loop() +{ } -void loop() {} diff --git a/examples/ATS_Skeleton/ATS_Skeleton.ino b/examples/ATS_Skeleton/ATS_Skeleton.ino index 58ecaff..33109cd 100644 --- a/examples/ATS_Skeleton/ATS_Skeleton.ino +++ b/examples/ATS_Skeleton/ATS_Skeleton.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino Test Example Skeleton -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino Test Example Skeleton +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -12,39 +12,29 @@ //************************************************************************ 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(); - + //startMemoryUsage must be set directly before ATS_begin + int 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() { - - } - - - diff --git a/examples/ATS_StringAssignmentTest/ATS_StringAssignmentTest.ino b/examples/ATS_StringAssignmentTest/ATS_StringAssignmentTest.ino index bcec262..e9bd0ef 100644 --- a/examples/ATS_StringAssignmentTest/ATS_StringAssignmentTest.ino +++ b/examples/ATS_StringAssignmentTest/ATS_StringAssignmentTest.ino @@ -1,53 +1,47 @@ //************************************************************************ -//* Arduino String Memory test +//* Arduino String Memory test //* Created, 3 strings, check memory status. //* -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ -#include +#include //************************************************************************ void setup() { - int startMemoryUsage; - /* - * Create variable for the tests. - */ - - String stringOne; - - //Assign stringOne to be equal to the longest string - stringOne = "

Lorem ipsum dolor sit amet

Ipsem

Quod

"; - - /*; - * initiate the test run - */ - startMemoryUsage = ATS_GetFreeMemory(); - ATS_begin("Arduino", "ATS_StringAssignmentTest"); - - stringOne = ""; - stringOne = "
  • item
  • item
  • item
"; - stringOne = "

Lorem ipsum dolor sit amet

Ipsem

Quod

"; - - ATS_ReportMemoryUsage(startMemoryUsage); - - /* - * Test complete - */ - - ATS_end(); - + /* + * Create variable for the tests. + */ + String stringOne; + + //Assign stringOne to be equal to the longest string + stringOne = "

Lorem ipsum dolor sit amet

Ipsem

Quod

"; + + /*; + * initiate the test run + */ + int startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino", "ATS_StringAssignmentTest"); + + stringOne = ""; + stringOne = "
  • item
  • item
  • item
"; + stringOne = "

Lorem ipsum dolor sit amet

Ipsem

Quod

"; + + ATS_ReportMemoryUsage(startMemoryUsage); + + /* + * Test complete + */ + ATS_end(); } - //************************************************************************ void loop() { - - } + diff --git a/examples/ATS_StringHtmlReplace/ATS_StringHtmlReplace.ino b/examples/ATS_StringHtmlReplace/ATS_StringHtmlReplace.ino index e2feeba..30ef2ad 100644 --- a/examples/ATS_StringHtmlReplace/ATS_StringHtmlReplace.ino +++ b/examples/ATS_StringHtmlReplace/ATS_StringHtmlReplace.ino @@ -1,106 +1,98 @@ -#include - +#include const char html_data[] PROGMEM = { "\r\n" - "test\r\n" - "\r\n" - "

Title

\r\n" - "This isn't a very interesting page, is it?\r\n" - "\r\n" + "test\r\n" + "\r\n" + "

Title

\r\n" + "This isn't a very interesting page, is it?\r\n" + "\r\n" }; - -unsigned int crcFile(void) { - unsigned int crc=0; - String result = ""; - //result.reserve(100); // better coding practice... - myFile_open("index.htm"); - while (myFile_available()) { - byte thisChar = (char) myFile_read(); - if (result.endsWith("")) { - //Serial.println("replacing"); - String bodyTag = "= 100 - result.replace("")) { + //Serial.println("replacing"); + String bodyTag = "= 100 + result.replace(">= 1; - crc ^= 0xA001; - } else { - crc >>= 1; - } - } - return crc; +unsigned int crc16(unsigned int crc, byte b) +{ + crc ^= b; + for (byte i = 0; i < 8; i++) { + if (crc & 1) { + crc >>= 1; + crc ^= 0xA001; + } else { + crc >>= 1; + } + } + return crc; } - - - - - - - diff --git a/examples/ATS_StringIndexOfMemory/ATS_StringIndexOfMemory.ino b/examples/ATS_StringIndexOfMemory/ATS_StringIndexOfMemory.ino index 2de273e..bd78ad8 100644 --- a/examples/ATS_StringIndexOfMemory/ATS_StringIndexOfMemory.ino +++ b/examples/ATS_StringIndexOfMemory/ATS_StringIndexOfMemory.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino Test Example Skeleton -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino Test Example Skeleton +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -13,92 +13,85 @@ void do_string_operations(int startMemoryUsage) { - String stringOne; - int firstClosingBracket; - int firstOpeningBracket; - int secondOpeningBracket; - int secondClosingBracket; - int bodyTag; - int firstListItem; - int secondListItem; - int lastOpeningBracket; - int lastListItem; - int lastParagraph; - int secondLastParagraph; - int thirdLastParagraph; - - // 1111111111 - // 01234567890123456789 - stringOne = ""; - firstClosingBracket = stringOne.indexOf('>'); - ATS_PrintTestStatus("firstClosingBracket", firstClosingBracket == 5); - - // 1111111111 - // 01234567890123456789 - stringOne = ""; - secondOpeningBracket = firstClosingBracket + 1; - secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket ); - ATS_PrintTestStatus("secondClosingBracket", secondClosingBracket == 11); - - // you can also use indexOf() to search for Strings: - // 1111111111 - // 01234567890123456789 - stringOne = ""; - bodyTag = stringOne.indexOf(""); - ATS_PrintTestStatus("bodyTag", bodyTag == 12); - - // 111111111122222222223333333333 - // 0123456789012345678901234567890123456789 - stringOne = "
  • item
  • item
  • item
"; - firstListItem = stringOne.indexOf("
  • "); - secondListItem = stringOne.indexOf("
  • ", 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('<'); - ATS_PrintTestStatus("lastOpeningBracket", lastOpeningBracket == 28); - - lastListItem = stringOne.lastIndexOf("
  • "); - ATS_PrintTestStatus("lastListItem", lastListItem == 20); - - // lastIndexOf() can also search for a string: - // 11111111112222222222333333333344444444445555555555 - // 012345678901234567890123456789012345678901234567890123456789 - stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; - lastParagraph = stringOne.lastIndexOf("'); + ATS_PrintTestStatus("firstClosingBracket", firstClosingBracket == 5); + + // 1111111111 + // 01234567890123456789 + stringOne = ""; + secondOpeningBracket = firstClosingBracket + 1; + secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket); + ATS_PrintTestStatus("secondClosingBracket", secondClosingBracket == 11); + + // you can also use indexOf() to search for Strings: + // 1111111111 + // 01234567890123456789 + stringOne = ""; + bodyTag = stringOne.indexOf(""); + ATS_PrintTestStatus("bodyTag", bodyTag == 12); + + // 111111111122222222223333333333 + // 0123456789012345678901234567890123456789 + stringOne = "
    • item
    • item
    • item
    "; + firstListItem = stringOne.indexOf("
  • "); + secondListItem = stringOne.indexOf("
  • ", 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('<'); + ATS_PrintTestStatus("lastOpeningBracket", lastOpeningBracket == 28); + + lastListItem = stringOne.lastIndexOf("
  • "); + ATS_PrintTestStatus("lastListItem", lastListItem == 20); + + // lastIndexOf() can also search for a string: + // 11111111112222222222333333333344444444445555555555 + // 012345678901234567890123456789012345678901234567890123456789 + stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; + lastParagraph = stringOne.lastIndexOf(" Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -12,85 +12,71 @@ //************************************************************************ 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; - - //Assign String one longest string. - stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; - - /*; - * 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 = ""; - firstClosingBracket = stringOne.indexOf('>'); - - stringOne = ""; - secondOpeningBracket = firstClosingBracket + 1; - secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket ); - - // you can also use indexOf() to search for Strings: - stringOne = ""; - bodyTag = stringOne.indexOf(""); - - stringOne = "
    • item
    • item
    • item
    "; - firstListItem = stringOne.indexOf("
  • "); - secondListItem = stringOne.indexOf("item", firstListItem + 1 ); - - // lastIndexOf() gives you the last occurrence of a character or string: - lastOpeningBracket = stringOne.lastIndexOf('<'); - - lastListItem = stringOne.lastIndexOf("
  • "); - - - // lastIndexOf() can also search for a string: - stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; - lastParagraph = stringOne.lastIndexOf("'); + + stringOne = ""; + secondOpeningBracket = firstClosingBracket + 1; + secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket); + + // you can also use indexOf() to search for Strings: + stringOne = ""; + bodyTag = stringOne.indexOf(""); + + stringOne = "
    • item
    • item
    • item
    "; + firstListItem = stringOne.indexOf("
  • "); + secondListItem = stringOne.indexOf("item", firstListItem + 1); + + // lastIndexOf() gives you the last occurrence of a character or string: + lastOpeningBracket = stringOne.lastIndexOf('<'); + + lastListItem = stringOne.lastIndexOf("
  • "); + + // lastIndexOf() can also search for a string: + stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; + lastParagraph = stringOne.lastIndexOf(" -void setup() { +void setup() +{ } -void run() { - String webColor = "#"; - int red = 0xff; - webColor += String(red, HEX); - int green = 0x24; - webColor += String(green, HEX); - int blue = 0xc9; - webColor += String(blue, HEX); - char buf[16]; - webColor.toCharArray(buf, sizeof(buf)); - ATS_PrintTestStatus("webColor result", strcmp(buf, "#ff24c9") == 0); +void run() +{ + String webColor = "#"; + int red = 0xff; + webColor += String(red, HEX); + int green = 0x24; + webColor += String(green, HEX); + int blue = 0xc9; + webColor += String(blue, HEX); + char buf[16]; + webColor.toCharArray(buf, sizeof(buf)); + ATS_PrintTestStatus("webColor result", strcmp(buf, "#ff24c9") == 0); } -void loop() { - int startMemoryUsage = ATS_GetFreeMemory(); - ATS_begin("Arduino", "Tom's webColor, infinite repeat"); - run(); - ATS_ReportMemoryUsage(startMemoryUsage); - ATS_end(); +void loop() +{ + int startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino", "Tom's webColor, infinite repeat"); + run(); + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } + diff --git a/examples/ATS_StringMemoryTestPassByReference/ATS_StringMemoryTestPassByReference.ino b/examples/ATS_StringMemoryTestPassByReference/ATS_StringMemoryTestPassByReference.ino index 60a042f..ffa348c 100644 --- a/examples/ATS_StringMemoryTestPassByReference/ATS_StringMemoryTestPassByReference.ino +++ b/examples/ATS_StringMemoryTestPassByReference/ATS_StringMemoryTestPassByReference.ino @@ -1,12 +1,12 @@ //************************************************************************ -//* Arduino String Memory test +//* Arduino String Memory test //* Created, 3 strings, check memory status. //* -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -14,49 +14,34 @@ //************************************************************************ void setup() { - int startMemoryUsage; - /* - * Create variable for the tests. - */ - String stringOne; - - //Assign stringOne to be equal to the longest string - stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; - - /* - * initiate the test run - */ - - - startMemoryUsage = ATS_GetFreeMemory(); - ATS_begin("Arduino", "ATS_StringMemoryTestPassByReference"); - - assignStringValues(&stringOne); - - ATS_ReportMemoryUsage(startMemoryUsage); - - /* - * Test complete - */ - - ATS_end(); + /* + * Create variable for the tests. + */ + String stringOne; + //Assign stringOne to be equal to the longest string + stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; + /* + * initiate the test run + */ + int startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino", "ATS_StringMemoryTestPassByReference"); + assignStringValues(&stringOne); + ATS_ReportMemoryUsage(startMemoryUsage); + /* + * Test complete + */ + ATS_end(); } -void assignStringValues(String *argString ) { - *argString = ""; - *argString = "
    • item
    • item
    • item
    "; - *argString = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; +void assignStringValues(String * argString) +{ + *argString = ""; + *argString = "
    • item
    • item
    • item
    "; + *argString = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; } //************************************************************************ void loop() { - - } - - - - - diff --git a/examples/ATS_StringTest/ATS_StringTest.ino b/examples/ATS_StringTest/ATS_StringTest.ino index 632bced..600b9ff 100644 --- a/examples/ATS_StringTest/ATS_StringTest.ino +++ b/examples/ATS_StringTest/ATS_StringTest.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino String Test -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino String Test +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -12,110 +12,110 @@ //************************************************************************ 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)); + int startMemoryUsage = ATS_GetFreeMemory(); + 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)); #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); + // 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"; - stringTwo = "1"; - ATS_PrintTestStatus("13. Two numeric strings compared",stringOne >= stringTwo); + // 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: + // comparison operators can be used to compare strings for alphabetic sorting too: /* stringOne = String("Brown"); @@ -123,64 +123,52 @@ void setup() 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); - - // 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); + */ + + // 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); + + // 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); // 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(); - + //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_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - - } - - - - - - - - - - - diff --git a/examples/ATS_StringTest_1/ATS_StringTest_1.ino b/examples/ATS_StringTest_1/ATS_StringTest_1.ino index 6628414..8375d10 100644 --- a/examples/ATS_StringTest_1/ATS_StringTest_1.ino +++ b/examples/ATS_StringTest_1/ATS_StringTest_1.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino String Test -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino String Test +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -12,122 +12,127 @@ //************************************************************************ 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[60]; + int startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino", "Test of String Library"); - /* - * Run the tests - */ + /* + * Test Variable Setup + * Best practive set all your test variables prior to teseting. + * This is required for Memory tests. + */ - // adding a constant integer to a string: - stringThree = stringOne + 123; - //strcpy(charResult, "\0"); - stringThree.toCharArray(charResult, sizeof(charResult)); + String stringOne = String("stringThree = "); + String stringTwo = String("this string"); + String stringThree = String(); + char charResult[60]; - ATS_PrintTestStatus("1. Add integer to string:", strcmp(charResult,"stringThree = 123" ) == 0); + /* + * Run the tests + */ - // adding a constant long interger to a string: - stringThree = stringOne + 123456789; - stringThree.toCharArray(charResult, sizeof(charResult)); + // adding a constant integer to a string: + stringThree = stringOne + 123; + //strcpy(charResult, "\0"); + stringThree.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("2. Add long to string", strcmp(charResult,"stringThree = 123456789" ) == 0); + ATS_PrintTestStatus("1. Add integer to string:", + strcmp(charResult, "stringThree = 123") == 0); + // adding a constant long interger to a string: + stringThree = stringOne + 123456789; + stringThree.toCharArray(charResult, sizeof(charResult)); - // adding a constant character to a string: - stringThree = stringOne + 'A'; - stringThree.toCharArray(charResult, sizeof(charResult)); + ATS_PrintTestStatus("2. Add long to string", + strcmp(charResult, "stringThree = 123456789") == 0); - ATS_PrintTestStatus("3. Add char", strcmp(charResult,"stringThree = A" ) == 0); + // adding a constant character to a string: + stringThree = stringOne + 'A'; + stringThree.toCharArray(charResult, sizeof(charResult)); + ATS_PrintTestStatus("3. Add char", + strcmp(charResult, "stringThree = A") == 0); - // adding a constant string to a string: - stringThree = stringOne + "abc"; - stringThree.toCharArray(charResult, sizeof(charResult)); + // adding a constant string to a string: + stringThree = stringOne + "abc"; + stringThree.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("4. Add string to string", strcmp(charResult,"stringThree = abc" ) == 0); + ATS_PrintTestStatus("4. Add string to string", + strcmp(charResult, "stringThree = abc") == 0); - //"5. Adding a constant long interger to a string" - stringThree = stringOne + stringTwo; - stringThree.toCharArray(charResult, sizeof(charResult)); + //"5. Adding a constant long interger to a string" + stringThree = stringOne + stringTwo; + stringThree.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("5. Add long", strcmp(charResult,"stringThree = this string" ) == 0); + ATS_PrintTestStatus("5. Add long", + strcmp(charResult, + "stringThree = this string") == 0); + /* + * setup up String Comparison Operater Tests + */ - /* - * setup up String Comparison Operater Tests - */ + stringOne = String("this"); + stringTwo = String("that"); - stringOne = String("this"); - stringTwo = String("that"); + // two strings equal: + ATS_PrintTestStatus("6. equal", stringOne == "this"); - // two strings equal: - ATS_PrintTestStatus("6. equal",stringOne == "this"); + // two strings not equal: + ATS_PrintTestStatus("7. not equal", stringOne != stringTwo); - // two strings not equal: - ATS_PrintTestStatus("7. not equal",stringOne != stringTwo); + // two strings not equal (case sensitivity matters): + stringOne = "This"; + stringTwo = "this"; + ATS_PrintTestStatus("8. not equal (case matters)", + stringOne != stringTwo); - // two strings not equal (case sensitivity matters): - stringOne = "This"; - stringTwo = "this"; - ATS_PrintTestStatus("8. not equal (case matters)", stringOne != stringTwo); + // you can also use equals() to see if two strings are the same: + stringOne = "this"; + stringTwo = "this"; + ATS_PrintTestStatus("9. Equals()", stringOne.equals(stringTwo)); - // you can also use equals() to see if two strings are the same: - stringOne = "this"; - stringTwo = "this"; - ATS_PrintTestStatus("9. 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)); - - // 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()", stringOne.equalsIgnoreCase(stringTwo)); + // or perhaps you want to ignore case: + ATS_PrintTestStatus("11. EqualsIgnoreCase()", + 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 number", stringOne == numberOne); + // a numeric string compared to the number it represents: + stringOne = "1"; + int numberOne = 1; + ATS_PrintTestStatus("12. A numeric string compared to number", + stringOne == numberOne); #endif - // two numeric strings compared: - stringOne = "2"; - stringTwo = "1"; - ATS_PrintTestStatus("13. Two numeric strings compared",stringOne >= stringTwo); - + // 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: + // comparison operators can be used to compare strings for alphabetic sorting too: - stringOne = String("Brown"); - ATS_PrintTestStatus("14. comparison <",stringOne < "Charles"); - ATS_PrintTestStatus("15. comparison >",stringOne > "Adams"); - ATS_PrintTestStatus("16. comparison <=",stringOne <= "Browne"); - ATS_PrintTestStatus("17. comparison >= ",stringOne >= "Brow"); + stringOne = String("Brown"); + ATS_PrintTestStatus("14. comparison <", stringOne < "Charles"); + ATS_PrintTestStatus("15. comparison >", stringOne > "Adams"); + ATS_PrintTestStatus("16. comparison <=", stringOne <= "Browne"); + ATS_PrintTestStatus("17. comparison >= ", stringOne >= "Brow"); + // the compareTo() operator also allows you to compare strings + stringOne = "Cucumber"; + stringTwo = "Cucuracha"; - // the compareTo() operator also allows you to compare strings - stringOne = "Cucumber"; - stringTwo = "Cucuracha"; - - ATS_PrintTestStatus("18. compareTo()", stringOne.compareTo(stringTwo) < 0); + ATS_PrintTestStatus("18. compareTo()", + stringOne.compareTo(stringTwo) < 0); /* // These two tests are based on a misunderstanding of compareTo() @@ -146,36 +151,24 @@ void setup() ATS_PrintTestStatus("20. The compareTo() compare strings with appended integers", stringOne.compareTo(stringTwo) < 0); */ - stringOne = String("Sensor "); - stringTwo = String("value"); + stringOne = String("Sensor "); + stringTwo = String("value"); - stringOne += stringTwo; - ATS_PrintTestStatus("21. Adding string to string += ", stringOne.equals("Sensor value")); - ATS_PrintTestStatus("22. The compareTo() appended int", stringOne.compareTo(stringTwo) < 0); - - /* - * Test complete - */ + stringOne += stringTwo; + ATS_PrintTestStatus("21. Adding string to string += ", + stringOne.equals("Sensor value")); + ATS_PrintTestStatus("22. The compareTo() appended int", + stringOne.compareTo(stringTwo) < 0); - ATS_end(); + /* + * Test complete + */ + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - - } - - - - - - - - - - - diff --git a/examples/ATS_StringTest_2/ATS_StringTest_2.ino b/examples/ATS_StringTest_2/ATS_StringTest_2.ino index 57f1db2..285042a 100644 --- a/examples/ATS_StringTest_2/ATS_StringTest_2.ino +++ b/examples/ATS_StringTest_2/ATS_StringTest_2.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino String Test -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino String Test +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -12,97 +12,89 @@ //************************************************************************ void setup() { - - int startMemoryUsage; - ATS_begin("Arduino", "Test of String Library"); + int startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino", "Test of String Library"); + + String stringOne; + String stringTwo; + + stringOne = "The quick brown fox"; + ATS_PrintTestStatus("23. Substring ", stringOne.substring(0, 1) == "T"); + ATS_PrintTestStatus("24. Substring ", + stringOne.substring(0, 3) == "The"); + ATS_PrintTestStatus("25. Substring ", + stringOne.substring(4, 9) == "quick"); + ATS_PrintTestStatus("26. Substring ", + stringOne.substring(10, 15) == "brown"); + ATS_PrintTestStatus("27. Substring ", + stringOne.substring(16, 19) == "fox"); + ATS_PrintTestStatus("28. Substring ", + stringOne.substring(18, 19) == "x"); + ATS_PrintTestStatus("29. Substring ", + stringOne.substring(0, 19) == stringOne); + + stringOne = + "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; + int i; + i = stringOne.lastIndexOf("

    "); + ATS_PrintTestStatus("30. lastIndexOf ", i == 56); + i = stringOne.lastIndexOf("

    ", i); + ATS_PrintTestStatus("31. lastIndexOf ", i == 56); + i = stringOne.lastIndexOf("

    ", i - 1); + ATS_PrintTestStatus("32. lastIndexOf ", i == 45); + i = stringOne.lastIndexOf("

    ", i - 1); + ATS_PrintTestStatus("33. lastIndexOf ", i == 33); + i = stringOne.lastIndexOf("

    ", i - 1); + ATS_PrintTestStatus("34. lastIndexOf ", i == 0); + i = stringOne.lastIndexOf("ipsum", 8); + ATS_PrintTestStatus("35. lastIndexOf ", i == -1); + i = stringOne.lastIndexOf(stringOne); + ATS_PrintTestStatus("36. lastIndexOf ", i == 0); - String stringOne; - String stringTwo; - - stringOne = "The quick brown fox"; - ATS_PrintTestStatus("23. Substring ", stringOne.substring(0, 1) == "T"); - ATS_PrintTestStatus("24. Substring ", stringOne.substring(0, 3) == "The"); - ATS_PrintTestStatus("25. Substring ", stringOne.substring(4, 9) == "quick"); - ATS_PrintTestStatus("26. Substring ", stringOne.substring(10, 15) == "brown"); - ATS_PrintTestStatus("27. Substring ", stringOne.substring(16, 19) == "fox"); - ATS_PrintTestStatus("28. Substring ", stringOne.substring(18, 19) == "x"); - ATS_PrintTestStatus("29. Substring ", stringOne.substring(0, 19) == stringOne); - - stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; - int i; - i = stringOne.lastIndexOf("

    "); - ATS_PrintTestStatus("30. lastIndexOf ", i == 56); - i = stringOne.lastIndexOf("

    ", i); - ATS_PrintTestStatus("31. lastIndexOf ", i == 56); - i = stringOne.lastIndexOf("

    ", i - 1); - ATS_PrintTestStatus("32. lastIndexOf ", i == 45); - i = stringOne.lastIndexOf("

    ", i - 1); - ATS_PrintTestStatus("33. lastIndexOf ", i == 33); - i = stringOne.lastIndexOf("

    ", i - 1); - ATS_PrintTestStatus("34. lastIndexOf ", i == 0); - i = stringOne.lastIndexOf("ipsum", 8); - ATS_PrintTestStatus("35. lastIndexOf ", i == -1); - i = stringOne.lastIndexOf(stringOne); - ATS_PrintTestStatus("36. lastIndexOf ", i == 0); - #if ARDUINO >= 100 - stringOne = " test 123 \t "; - stringOne.trim(); - ATS_PrintTestStatus("37. trim ", stringOne == "test 123"); - stringOne = "test 123"; - stringOne.trim(); - ATS_PrintTestStatus("38. trim ", stringOne == "test 123"); - stringOne = "test 123 \t "; - stringOne.trim(); - ATS_PrintTestStatus("39. trim ", stringOne == "test 123"); - stringOne = " test 123"; - stringOne.trim(); - ATS_PrintTestStatus("40. trim ", stringOne == "test 123"); - stringOne = (char *)NULL; - stringOne.trim(); - ATS_PrintTestStatus("41. empty ", stringOne == ""); - stringOne = ""; - stringOne.trim(); - ATS_PrintTestStatus("42. empty ", stringOne == ""); + stringOne = " test 123 \t "; + stringOne.trim(); + ATS_PrintTestStatus("37. trim ", stringOne == "test 123"); + stringOne = "test 123"; + stringOne.trim(); + ATS_PrintTestStatus("38. trim ", stringOne == "test 123"); + stringOne = "test 123 \t "; + stringOne.trim(); + ATS_PrintTestStatus("39. trim ", stringOne == "test 123"); + stringOne = " test 123"; + stringOne.trim(); + ATS_PrintTestStatus("40. trim ", stringOne == "test 123"); + stringOne = (char *)NULL; + stringOne.trim(); + ATS_PrintTestStatus("41. empty ", stringOne == ""); + stringOne = ""; + stringOne.trim(); + ATS_PrintTestStatus("42. empty ", stringOne == ""); #else - stringOne = " test 123 \t "; - ATS_PrintTestStatus("37. trim ", stringOne.trim() == "test 123"); - stringOne = "test 123"; - ATS_PrintTestStatus("38. trim ", stringOne.trim() == "test 123"); - stringOne = "test 123 \t "; - ATS_PrintTestStatus("39. trim ", stringOne.trim() == "test 123"); - stringOne = " test 123"; - ATS_PrintTestStatus("40. trim ", stringOne.trim() == "test 123"); - stringOne = (char *)NULL; - ATS_PrintTestStatus("41. empty ", stringOne.trim() == ""); - stringOne = ""; - ATS_PrintTestStatus("42. empty ", stringOne.trim() == ""); + stringOne = " test 123 \t "; + ATS_PrintTestStatus("37. trim ", stringOne.trim() == "test 123"); + stringOne = "test 123"; + ATS_PrintTestStatus("38. trim ", stringOne.trim() == "test 123"); + stringOne = "test 123 \t "; + ATS_PrintTestStatus("39. trim ", stringOne.trim() == "test 123"); + stringOne = " test 123"; + ATS_PrintTestStatus("40. trim ", stringOne.trim() == "test 123"); + stringOne = (char *)NULL; + ATS_PrintTestStatus("41. empty ", stringOne.trim() == ""); + stringOne = ""; + ATS_PrintTestStatus("42. empty ", stringOne.trim() == ""); #endif - /* - * Test complete - */ - - ATS_end(); + /* + * Test complete + */ + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - - } - - - - - - - - - - - diff --git a/examples/ATS_StringTest_3/ATS_StringTest_3.ino b/examples/ATS_StringTest_3/ATS_StringTest_3.ino index f0db160..3f35c03 100644 --- a/examples/ATS_StringTest_3/ATS_StringTest_3.ino +++ b/examples/ATS_StringTest_3/ATS_StringTest_3.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino String Test -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino String Test +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -16,123 +16,146 @@ //************************************************************************ void setup() { - int startMemoryUsage; + int startMemoryUsage = ATS_GetFreeMemory(); - ATS_begin("Arduino", "Test of String Library"); + ATS_begin("Arduino", "Test of String Library"); - String stringOne = String("stringThree = "); - String stringTwo = String("this string"); - int i=0; + String stringOne = String("stringThree = "); + String stringTwo = String("this string"); + int i = 0; #if ARDUINO >= 100 - stringOne = "test one test"; - stringOne.replace("test", "1234"); - ATS_PrintTestStatus("43. replace", stringOne == "1234 one 1234"); - stringOne = "test one test two"; - stringOne.replace("test", "1234"); - ATS_PrintTestStatus("44. replace", stringOne == "1234 one 1234 two"); - stringOne = "zero test one test two"; - stringOne.replace("test", "12345"); - ATS_PrintTestStatus("45. replace", stringOne == "zero 12345 one 12345 two"); - stringOne = "zero test one test"; - stringOne.replace("test", "1234"); - ATS_PrintTestStatus("46. replace", stringOne == "zero 1234 one 1234"); - stringOne = "test one test"; - stringOne.replace("test", "123"); - ATS_PrintTestStatus("47. replace", stringOne == "123 one 123"); - stringOne = "test one test two"; - stringOne.replace("test", "123"); - ATS_PrintTestStatus("48. replace", stringOne == "123 one 123 two"); - stringOne = "zero test one test two"; - stringOne.replace("test", "12"); - ATS_PrintTestStatus("49. replace", stringOne == "zero 12 one 12 two"); - stringOne = "zero test one test"; - stringOne.replace("test", "1"); - ATS_PrintTestStatus("50. replace", stringOne == "zero 1 one 1"); - stringOne = "test one test"; - stringOne.replace("test", "12345"); - ATS_PrintTestStatus("51. replace", stringOne == "12345 one 12345"); - stringOne = "test one test two"; - stringOne.replace("test", "123456"); - ATS_PrintTestStatus("52. replace", stringOne == "123456 one 123456 two"); - stringOne = "zero test one test two"; - stringOne.replace("test", "1234567"); - ATS_PrintTestStatus("53. replace", stringOne == "zero 1234567 one 1234567 two"); - stringOne = "zero test one test"; - stringOne.replace("test", "12345678"); - ATS_PrintTestStatus("54. replace", stringOne == "zero 12345678 one 12345678"); - stringOne = "zero test one test"; - stringOne.replace('e', 'X'); - ATS_PrintTestStatus("55. replace char", stringOne == "zXro tXst onX tXst"); + stringOne = "test one test"; + stringOne.replace("test", "1234"); + ATS_PrintTestStatus("43. replace", stringOne == "1234 one 1234"); + stringOne = "test one test two"; + stringOne.replace("test", "1234"); + ATS_PrintTestStatus("44. replace", stringOne == "1234 one 1234 two"); + stringOne = "zero test one test two"; + stringOne.replace("test", "12345"); + ATS_PrintTestStatus("45. replace", + stringOne == "zero 12345 one 12345 two"); + stringOne = "zero test one test"; + stringOne.replace("test", "1234"); + ATS_PrintTestStatus("46. replace", stringOne == "zero 1234 one 1234"); + stringOne = "test one test"; + stringOne.replace("test", "123"); + ATS_PrintTestStatus("47. replace", stringOne == "123 one 123"); + stringOne = "test one test two"; + stringOne.replace("test", "123"); + ATS_PrintTestStatus("48. replace", stringOne == "123 one 123 two"); + stringOne = "zero test one test two"; + stringOne.replace("test", "12"); + ATS_PrintTestStatus("49. replace", stringOne == "zero 12 one 12 two"); + stringOne = "zero test one test"; + stringOne.replace("test", "1"); + ATS_PrintTestStatus("50. replace", stringOne == "zero 1 one 1"); + stringOne = "test one test"; + stringOne.replace("test", "12345"); + ATS_PrintTestStatus("51. replace", stringOne == "12345 one 12345"); + stringOne = "test one test two"; + stringOne.replace("test", "123456"); + ATS_PrintTestStatus("52. replace", + stringOne == "123456 one 123456 two"); + stringOne = "zero test one test two"; + stringOne.replace("test", "1234567"); + ATS_PrintTestStatus("53. replace", + stringOne == "zero 1234567 one 1234567 two"); + stringOne = "zero test one test"; + stringOne.replace("test", "12345678"); + ATS_PrintTestStatus("54. replace", + stringOne == "zero 12345678 one 12345678"); + stringOne = "zero test one test"; + stringOne.replace('e', 'X'); + ATS_PrintTestStatus("55. replace char", + stringOne == "zXro tXst onX tXst"); #else - stringOne = "test one test"; - ATS_PrintTestStatus("43. replace", stringOne.replace("test", "1234") == "1234 one 1234"); - stringOne = "test one test two"; - ATS_PrintTestStatus("44. replace", stringOne.replace("test", "1234") == "1234 one 1234 two"); - stringOne = "zero test one test two"; - ATS_PrintTestStatus("45. replace", stringOne.replace("test", "12345") == F("zero 12345 one 12345 two")); - stringOne = "zero test one test"; - ATS_PrintTestStatus("46. replace", stringOne.replace("test", "1234") == "zero 1234 one 1234"); - stringOne = "test one test"; - ATS_PrintTestStatus("47. replace", stringOne.replace("test", "123") == "123 one 123"); - stringOne = "test one test two"; - ATS_PrintTestStatus("48. replace", stringOne.replace("test", "123") == "123 one 123 two"); - stringOne = F("zero test one test two"); - ATS_PrintTestStatus("49. replace", stringOne.replace("test", "12") == "zero 12 one 12 two"); - stringOne = "zero test one test"; - ATS_PrintTestStatus("50. replace", stringOne.replace("test", "1") == "zero 1 one 1"); - stringOne = "test one test"; - ATS_PrintTestStatus("51. replace", stringOne.replace("test", "12345") == "12345 one 12345"); - stringOne = "test one test two"; - ATS_PrintTestStatus("52. replace", stringOne.replace("test", "123456") == "123456 one 123456 two"); - stringOne = F("zero test one test two"); - ATS_PrintTestStatus("53. replace", stringOne.replace("test", "1234567") == F("zero 1234567 one 1234567 two")); - stringOne = "zero test one test"; - ATS_PrintTestStatus("54. replace", stringOne.replace("test", "12345678") == F("zero 12345678 one 12345678")); - stringOne = F("zero test one test"); - ATS_PrintTestStatus("55. replace char", stringOne.replace('e', 'X') == "zXro tXst onX tXst"); + stringOne = "test one test"; + ATS_PrintTestStatus("43. replace", + stringOne.replace("test", + "1234") == "1234 one 1234"); + stringOne = "test one test two"; + ATS_PrintTestStatus("44. replace", + stringOne.replace("test", + "1234") == "1234 one 1234 two"); + stringOne = "zero test one test two"; + ATS_PrintTestStatus("45. replace", + stringOne.replace("test", + "12345") == + F("zero 12345 one 12345 two")); + stringOne = "zero test one test"; + ATS_PrintTestStatus("46. replace", + stringOne.replace("test", + "1234") == "zero 1234 one 1234"); + stringOne = "test one test"; + ATS_PrintTestStatus("47. replace", + stringOne.replace("test", "123") == "123 one 123"); + stringOne = "test one test two"; + ATS_PrintTestStatus("48. replace", + stringOne.replace("test", + "123") == "123 one 123 two"); + stringOne = F("zero test one test two"); + ATS_PrintTestStatus("49. replace", + stringOne.replace("test", + "12") == "zero 12 one 12 two"); + stringOne = "zero test one test"; + ATS_PrintTestStatus("50. replace", + stringOne.replace("test", "1") == "zero 1 one 1"); + stringOne = "test one test"; + ATS_PrintTestStatus("51. replace", + stringOne.replace("test", + "12345") == "12345 one 12345"); + stringOne = "test one test two"; + ATS_PrintTestStatus("52. replace", + stringOne.replace("test", + "123456") == + "123456 one 123456 two"); + stringOne = F("zero test one test two"); + ATS_PrintTestStatus("53. replace", + stringOne.replace("test", + "1234567") == + F("zero 1234567 one 1234567 two")); + stringOne = "zero test one test"; + ATS_PrintTestStatus("54. replace", + stringOne.replace("test", + "12345678") == + F("zero 12345678 one 12345678")); + stringOne = F("zero test one test"); + ATS_PrintTestStatus("55. replace char", + stringOne.replace('e', + 'X') == "zXro tXst onX tXst"); #endif - stringOne = "Zero"; - stringTwo = "oNe"; - ATS_PrintTestStatus("56. add", stringOne + "124" + stringTwo + 5678 == "Zero124oNe5678"); + stringOne = "Zero"; + stringTwo = "oNe"; + ATS_PrintTestStatus("56. add", + stringOne + "124" + stringTwo + 5678 == + "Zero124oNe5678"); #if ARDUINO >= 100 - stringOne.toUpperCase(); - ATS_PrintTestStatus("57. toUpperCase", stringOne == "ZERO"); - stringTwo.toLowerCase(); - ATS_PrintTestStatus("58. toLowerCase", stringTwo == "one"); + stringOne.toUpperCase(); + ATS_PrintTestStatus("57. toUpperCase", stringOne == "ZERO"); + stringTwo.toLowerCase(); + ATS_PrintTestStatus("58. toLowerCase", stringTwo == "one"); #else - ATS_PrintTestStatus("57. toUpperCase", stringOne.toUpperCase() == "ZERO"); - ATS_PrintTestStatus("58. toLowerCase", stringTwo.toLowerCase() == "one"); + ATS_PrintTestStatus("57. toUpperCase", + stringOne.toUpperCase() == "ZERO"); + ATS_PrintTestStatus("58. toLowerCase", + stringTwo.toLowerCase() == "one"); #endif - stringOne = "-1234567"; - ATS_PrintTestStatus("59. toInt", stringOne.toInt() == -1234567L); - stringOne = "12345"; - ATS_PrintTestStatus("60. toInt", stringOne.toInt() == 12345); - - /* - * Test complete - */ - - ATS_end(); + stringOne = "-1234567"; + ATS_PrintTestStatus("59. toInt", stringOne.toInt() == -1234567L); + stringOne = "12345"; + ATS_PrintTestStatus("60. toInt", stringOne.toInt() == 12345); + + /* + * Test complete + */ + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - - } - - - - - - - - - - - diff --git a/examples/ATS_StringTest_4/ATS_StringTest_4.ino b/examples/ATS_StringTest_4/ATS_StringTest_4.ino index f0f3021..9f11771 100644 --- a/examples/ATS_StringTest_4/ATS_StringTest_4.ino +++ b/examples/ATS_StringTest_4/ATS_StringTest_4.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino String Test -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino String Test +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -18,13 +18,12 @@ //************************************************************************ void setup() { - int startMemoryUsage; + int startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino", "Test of String Library"); - ATS_begin("Arduino", "Test of String Library"); - - String stringOne; - String stringTwo; - int i=0; + String stringOne; + String stringTwo; + int i = 0; #if !defined(F) || (ARDUINO >= 100 && !defined(CORE_TEENSY)) // Arduino 1.0, does not support for using F("cstring") with @@ -39,50 +38,52 @@ void setup() #define F(s) (s) #endif - stringOne = F("flash string"); - ATS_PrintTestStatus("61. assign flash string", stringOne == "flash string"); - stringOne += F(" test"); - ATS_PrintTestStatus("62. append flash string", stringOne == "flash string test"); - ATS_PrintTestStatus("63. append flash string", stringOne == F("flash string test")); - ATS_PrintTestStatus("64. add flash string", F("1234 ") + stringOne == "1234 flash string test"); - - stringOne = F("tst"); - char *ptr = NULL; - stringOne.concat(ptr); - ATS_PrintTestStatus("65. append", stringOne == "tst"); - ATS_PrintTestStatus("66. concat", stringOne + "123" + ptr + "hi" == "tst123hi"); - ATS_PrintTestStatus("67. append", stringOne == "tst"); - - stringOne = F("TST"); - stringOne.concat(""); - ATS_PrintTestStatus("68. append", stringOne == "TST"); - ATS_PrintTestStatus("69. concat", stringOne + "" == "TST"); - ATS_PrintTestStatus("70. append", stringOne == "TST"); - - stringOne = F("ZXDY"); - stringOne.concat("123"); - ATS_PrintTestStatus("71. append", stringOne == "ZXDY123"); - ATS_PrintTestStatus("72. concat", stringOne + "567" == "ZXDY123567"); - ATS_PrintTestStatus("73. append", stringOne == "ZXDY123"); - - stringOne = F("ra"); - stringOne.concat(F("573")); - ATS_PrintTestStatus("74. append", stringOne == "ra573"); - ATS_PrintTestStatus("75. concat", stringOne + F("4543") == "ra5734543"); - ATS_PrintTestStatus("76. append", stringOne == "ra573"); - - /* - * Test complete - */ - - ATS_end(); + stringOne = F("flash string"); + ATS_PrintTestStatus("61. assign flash string", + stringOne == "flash string"); + stringOne += F(" test"); + ATS_PrintTestStatus("62. append flash string", + stringOne == "flash string test"); + ATS_PrintTestStatus("63. append flash string", + stringOne == F("flash string test")); + ATS_PrintTestStatus("64. add flash string", + F("1234 ") + stringOne == "1234 flash string test"); + + stringOne = F("tst"); + char *ptr = NULL; + stringOne.concat(ptr); + ATS_PrintTestStatus("65. append", stringOne == "tst"); + ATS_PrintTestStatus("66. concat", + stringOne + "123" + ptr + "hi" == "tst123hi"); + ATS_PrintTestStatus("67. append", stringOne == "tst"); + + stringOne = F("TST"); + stringOne.concat(""); + ATS_PrintTestStatus("68. append", stringOne == "TST"); + ATS_PrintTestStatus("69. concat", stringOne + "" == "TST"); + ATS_PrintTestStatus("70. append", stringOne == "TST"); + + stringOne = F("ZXDY"); + stringOne.concat("123"); + ATS_PrintTestStatus("71. append", stringOne == "ZXDY123"); + ATS_PrintTestStatus("72. concat", stringOne + "567" == "ZXDY123567"); + ATS_PrintTestStatus("73. append", stringOne == "ZXDY123"); + + stringOne = F("ra"); + stringOne.concat(F("573")); + ATS_PrintTestStatus("74. append", stringOne == "ra573"); + ATS_PrintTestStatus("75. concat", stringOne + F("4543") == "ra5734543"); + ATS_PrintTestStatus("76. append", stringOne == "ra573"); + + /* + * Test complete + */ + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - } - diff --git a/examples/ATS_StringTest_4b/ATS_StringTest_4b.ino b/examples/ATS_StringTest_4b/ATS_StringTest_4b.ino index f2bf822..8f54cd8 100644 --- a/examples/ATS_StringTest_4b/ATS_StringTest_4b.ino +++ b/examples/ATS_StringTest_4b/ATS_StringTest_4b.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino String Test -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino String Test +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -18,13 +18,12 @@ //************************************************************************ void setup() { - int startMemoryUsage; + int startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino", "Test of String Library"); - ATS_begin("Arduino", "Test of String Library"); - - String stringOne; - String stringTwo; - int i=0; + String stringOne; + String stringTwo; + int i = 0; #if !defined(F) || (ARDUINO >= 100 && !defined(CORE_TEENSY)) // Arduino 1.0, does not support for using F("cstring") with @@ -39,80 +38,88 @@ void setup() #define F(s) (s) #endif - char c = '7'; - unsigned char uc = '9'; - stringOne = F("tywe"); - stringOne.concat(c); - stringOne.concat(uc); - ATS_PrintTestStatus("77. append", stringOne == F("tywe79")); - stringOne += uc; - stringOne += c; - ATS_PrintTestStatus("78. append", stringOne == F("tywe7997")); - c = '.'; - ATS_PrintTestStatus("79. concat", stringOne + c == F("tywe7997.")); - uc = 'R'; - ATS_PrintTestStatus("80. concat", stringOne + uc == F("tywe7997R")); - ATS_PrintTestStatus("81. append", stringOne == F("tywe7997")); - - i = -32768; - stringOne = F("u572h"); - stringOne.concat(i); - ATS_PrintTestStatus("82. append", stringOne == F("u572h-32768")); - stringOne += i; - ATS_PrintTestStatus("83. append", stringOne == F("u572h-32768-32768")); - i = -25000; - ATS_PrintTestStatus("84. concat", stringOne + i == F("u572h-32768-32768-25000")); - ATS_PrintTestStatus("85. append", stringOne == F("u572h-32768-32768")); - - i = 24173; - stringOne = F("5u1klj"); - stringOne.concat(i); - ATS_PrintTestStatus("86. append", stringOne == F("5u1klj24173")); - stringOne += i; - ATS_PrintTestStatus("87. append", stringOne == F("5u1klj2417324173")); - ATS_PrintTestStatus("88. concat", stringOne + i == F("5u1klj241732417324173")); - ATS_PrintTestStatus("89. append", stringOne == F("5u1klj2417324173")); - - unsigned int u = 65190; - stringOne = F("i8skjm"); - stringOne.concat(u); - ATS_PrintTestStatus("90. append", stringOne == F("i8skjm65190")); - stringOne += u; - ATS_PrintTestStatus("91. append", stringOne == F("i8skjm6519065190")); - ATS_PrintTestStatus("92. concat", stringOne + u == F("i8skjm651906519065190")); - ATS_PrintTestStatus("93. append", stringOne == F("i8skjm6519065190")); - - long n = -91093847; - stringOne = F("ywh"); - stringOne.concat(n); - ATS_PrintTestStatus("94. append", stringOne == F("ywh-91093847")); - stringOne += n; - ATS_PrintTestStatus("95. append", stringOne == F("ywh-91093847-91093847")); - ATS_PrintTestStatus("96. concat", stringOne + n == F("ywh-91093847-91093847-91093847")); - ATS_PrintTestStatus("97. append", stringOne == F("ywh-91093847-91093847")); - - unsigned long un = 4294961479; - stringOne = F("iu"); - stringOne.concat(un); - ATS_PrintTestStatus("98. append", stringOne == F("iu4294961479")); - un -= 4; - stringOne += un; - ATS_PrintTestStatus("99. append", stringOne == F("iu42949614794294961475")); - ATS_PrintTestStatus("100. concat", stringOne + un == F("iu429496147942949614754294961475")); - ATS_PrintTestStatus("101. append", stringOne == F("iu42949614794294961475")); - - /* - * Test complete - */ - - ATS_end(); + char c = '7'; + unsigned char uc = '9'; + stringOne = F("tywe"); + stringOne.concat(c); + stringOne.concat(uc); + ATS_PrintTestStatus("77. append", stringOne == F("tywe79")); + stringOne += uc; + stringOne += c; + ATS_PrintTestStatus("78. append", stringOne == F("tywe7997")); + c = '.'; + ATS_PrintTestStatus("79. concat", stringOne + c == F("tywe7997.")); + uc = 'R'; + ATS_PrintTestStatus("80. concat", stringOne + uc == F("tywe7997R")); + ATS_PrintTestStatus("81. append", stringOne == F("tywe7997")); + + i = -32768; + stringOne = F("u572h"); + stringOne.concat(i); + ATS_PrintTestStatus("82. append", stringOne == F("u572h-32768")); + stringOne += i; + ATS_PrintTestStatus("83. append", stringOne == F("u572h-32768-32768")); + i = -25000; + ATS_PrintTestStatus("84. concat", + stringOne + i == F("u572h-32768-32768-25000")); + ATS_PrintTestStatus("85. append", stringOne == F("u572h-32768-32768")); + + i = 24173; + stringOne = F("5u1klj"); + stringOne.concat(i); + ATS_PrintTestStatus("86. append", stringOne == F("5u1klj24173")); + stringOne += i; + ATS_PrintTestStatus("87. append", stringOne == F("5u1klj2417324173")); + ATS_PrintTestStatus("88. concat", + stringOne + i == F("5u1klj241732417324173")); + ATS_PrintTestStatus("89. append", stringOne == F("5u1klj2417324173")); + + unsigned int u = 65190; + stringOne = F("i8skjm"); + stringOne.concat(u); + ATS_PrintTestStatus("90. append", stringOne == F("i8skjm65190")); + stringOne += u; + ATS_PrintTestStatus("91. append", stringOne == F("i8skjm6519065190")); + ATS_PrintTestStatus("92. concat", + stringOne + u == F("i8skjm651906519065190")); + ATS_PrintTestStatus("93. append", stringOne == F("i8skjm6519065190")); + + long n = -91093847; + stringOne = F("ywh"); + stringOne.concat(n); + ATS_PrintTestStatus("94. append", stringOne == F("ywh-91093847")); + stringOne += n; + ATS_PrintTestStatus("95. append", + stringOne == F("ywh-91093847-91093847")); + ATS_PrintTestStatus("96. concat", + stringOne + n == + F("ywh-91093847-91093847-91093847")); + ATS_PrintTestStatus("97. append", + stringOne == F("ywh-91093847-91093847")); + + unsigned long un = 4294961479; + stringOne = F("iu"); + stringOne.concat(un); + ATS_PrintTestStatus("98. append", stringOne == F("iu4294961479")); + un -= 4; + stringOne += un; + ATS_PrintTestStatus("99. append", + stringOne == F("iu42949614794294961475")); + ATS_PrintTestStatus("100. concat", + stringOne + un == + F("iu429496147942949614754294961475")); + ATS_PrintTestStatus("101. append", + stringOne == F("iu42949614794294961475")); + + /* + * Test complete + */ + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - } - diff --git a/examples/ATS_StringTest_5/ATS_StringTest_5.ino b/examples/ATS_StringTest_5/ATS_StringTest_5.ino index cc4ddd4..46f3396 100644 --- a/examples/ATS_StringTest_5/ATS_StringTest_5.ino +++ b/examples/ATS_StringTest_5/ATS_StringTest_5.ino @@ -6,20 +6,19 @@ 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 stringTwo; - String stringThree; - char charResult[100]; - int i; + int startMemoryUsage = ATS_GetFreeMemory(); + 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 stringTwo; + String stringThree; + char charResult[100]; + int i; #if !defined(F) || (ARDUINO >= 100 && !defined(CORE_TEENSY)) // Arduino 1.0, does not support for using F("cstring") with @@ -34,102 +33,107 @@ void setup() #define F(s) (s) #endif - stringOne = "123"; - stringTwo = "456"; // TODO: repeat this test for all overload permutations - stringThree = "789"; - stringOne = (stringTwo += stringThree); - ATS_PrintTestStatus("102. append result", stringOne == F("456789")); - ATS_PrintTestStatus("103. append", stringTwo == F("456789")); - ATS_PrintTestStatus("104. append const in", stringThree == F("789")); - - stringOne = "abc"; - stringTwo = "def"; - stringThree = "ghi"; - stringOne = stringTwo = stringThree; - ATS_PrintTestStatus("105. assign", stringOne == F("ghi")); - ATS_PrintTestStatus("106. assign", stringTwo == F("ghi")); - - // 111111111122222222223333333333 - // 0123456789012345678901234567890123456789 - stringOne = F("Now is the time for all good men"); - stringOne.toCharArray(charResult, 6); - ATS_PrintTestStatus("107. toCharArray", strcmp_P(charResult, PSTR("Now i")) == 0); + stringOne = "123"; + stringTwo = "456"; // TODO: repeat this test for all overload permutations + stringThree = "789"; + stringOne = (stringTwo += stringThree); + ATS_PrintTestStatus("102. append result", stringOne == F("456789")); + ATS_PrintTestStatus("103. append", stringTwo == F("456789")); + ATS_PrintTestStatus("104. append const in", stringThree == F("789")); + + stringOne = "abc"; + stringTwo = "def"; + stringThree = "ghi"; + stringOne = stringTwo = stringThree; + ATS_PrintTestStatus("105. assign", stringOne == F("ghi")); + ATS_PrintTestStatus("106. assign", stringTwo == F("ghi")); + + // 111111111122222222223333333333 + // 0123456789012345678901234567890123456789 + stringOne = F("Now is the time for all good men"); + stringOne.toCharArray(charResult, 6); + ATS_PrintTestStatus("107. toCharArray", + strcmp_P(charResult, PSTR("Now i")) == 0); #if ARDUINO >= 100 || defined(CORE_TEENSY) // these tests check toCharArray's handling of offsets, which was added // in Teensyduino and contributed to Arduino 1.0. Arduino 0022 does // not have this feature, so do not run these tests on older Arduino // unless using Teensy. - stringOne.toCharArray(charResult, 10, 8); - ATS_PrintTestStatus("108. toCharArray", strcmp_P(charResult, PSTR("he time f")) == 0); + stringOne.toCharArray(charResult, 10, 8); + ATS_PrintTestStatus("108. toCharArray", + strcmp_P(charResult, PSTR("he time f")) == 0); - stringOne.toCharArray(charResult, sizeof(charResult), 25); - ATS_PrintTestStatus("109. toCharArray", strcmp_P(charResult, PSTR("ood men")) == 0); + stringOne.toCharArray(charResult, sizeof(charResult), 25); + ATS_PrintTestStatus("109. toCharArray", + strcmp_P(charResult, PSTR("ood men")) == 0); - stringOne.getBytes((unsigned char *)charResult, 6); - ATS_PrintTestStatus("110. getBytes", strcmp_P(charResult, PSTR("Now i")) == 0); + stringOne.getBytes((unsigned char *)charResult, 6); + ATS_PrintTestStatus("110. getBytes", + strcmp_P(charResult, PSTR("Now i")) == 0); - stringOne.getBytes((unsigned char *)charResult, 10, 8); - ATS_PrintTestStatus("111. getBytes", strcmp_P(charResult, PSTR("he time f")) == 0); + stringOne.getBytes((unsigned char *)charResult, 10, 8); + ATS_PrintTestStatus("111. getBytes", + strcmp_P(charResult, PSTR("he time f")) == 0); - stringOne.getBytes((unsigned char *)charResult, sizeof(charResult), 25); - ATS_PrintTestStatus("112. getBytes", strcmp_P(charResult, PSTR("ood men")) == 0); + stringOne.getBytes((unsigned char *)charResult, sizeof(charResult), 25); + ATS_PrintTestStatus("112. getBytes", + strcmp_P(charResult, PSTR("ood men")) == 0); - stringOne.toCharArray(charResult, sizeof(charResult), 100); - ATS_PrintTestStatus("113. toCharArray", strcmp_P(charResult, PSTR("")) == 0); + stringOne.toCharArray(charResult, sizeof(charResult), 100); + ATS_PrintTestStatus("113. toCharArray", + strcmp_P(charResult, PSTR("")) == 0); #endif - ATS_PrintTestStatus("114. operator [] read", stringOne[0] == 'N'); - ATS_PrintTestStatus("115. operator [] read", stringOne[20] == 'a'); - ATS_PrintTestStatus("116. operator [] read", stringOne[30] == 'e'); - ATS_PrintTestStatus("117. operator [] read", stringOne[32] == 0); - ATS_PrintTestStatus("118. operator [] read", stringOne[40] == 0); - - stringOne[0] = 'n'; // should write to the string - stringOne[11] = 'S'; - stringOne[28] = '_'; - - ATS_PrintTestStatus("119. operator [] write", stringOne == F("now is the Sime for all good_men")); - stringOne.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("120. operator [] write", strcmp_P(charResult, PSTR("now is the Sime for all good_men")) == 0); - - stringOne[32] = '.'; // should not write over null term - - ATS_PrintTestStatus("121. operator [] write", stringOne == F("now is the Sime for all good_men")); - stringOne.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("122. operator [] write", strcmp_P(charResult, PSTR("now is the Sime for all good_men")) == 0); - - for (i=33; i<10000; i++) { - stringOne[i] = '.'; // should not buffer overflow (test will crash if it does) - } - - ATS_PrintTestStatus("123. operator [] write", stringOne == F("now is the Sime for all good_men")); - stringOne.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("124. operator [] write", strcmp_P(charResult, PSTR("now is the Sime for all good_men")) == 0); - - /* - * Test complete - */ - - ATS_end(); + ATS_PrintTestStatus("114. operator [] read", stringOne[0] == 'N'); + ATS_PrintTestStatus("115. operator [] read", stringOne[20] == 'a'); + ATS_PrintTestStatus("116. operator [] read", stringOne[30] == 'e'); + ATS_PrintTestStatus("117. operator [] read", stringOne[32] == 0); + ATS_PrintTestStatus("118. operator [] read", stringOne[40] == 0); + + stringOne[0] = 'n'; // should write to the string + stringOne[11] = 'S'; + stringOne[28] = '_'; + + ATS_PrintTestStatus("119. operator [] write", + stringOne == F("now is the Sime for all good_men")); + stringOne.toCharArray(charResult, sizeof(charResult)); + ATS_PrintTestStatus("120. operator [] write", + strcmp_P(charResult, + PSTR("now is the Sime for all good_men")) + == 0); + + stringOne[32] = '.'; // should not write over null term + + ATS_PrintTestStatus("121. operator [] write", + stringOne == F("now is the Sime for all good_men")); + stringOne.toCharArray(charResult, sizeof(charResult)); + ATS_PrintTestStatus("122. operator [] write", + strcmp_P(charResult, + PSTR("now is the Sime for all good_men")) + == 0); + + for (i = 33; i < 10000; i++) { + stringOne[i] = '.'; // should not buffer overflow (test will crash if it does) + } + + ATS_PrintTestStatus("123. operator [] write", + stringOne == F("now is the Sime for all good_men")); + stringOne.toCharArray(charResult, sizeof(charResult)); + ATS_PrintTestStatus("124. operator [] write", + strcmp_P(charResult, + PSTR("now is the Sime for all good_men")) + == 0); + + /* + * Test complete + */ + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - - } - - - - - - - - - - - diff --git a/examples/ATS_StringTest_all_Mega/ATS_StringTest_all_Mega.ino b/examples/ATS_StringTest_all_Mega/ATS_StringTest_all_Mega.ino index c062d05..21cc82f 100644 --- a/examples/ATS_StringTest_all_Mega/ATS_StringTest_all_Mega.ino +++ b/examples/ATS_StringTest_all_Mega/ATS_StringTest_all_Mega.ino @@ -11,14 +11,13 @@ // test suite consume over 4K of RAM, so this all-in-one // test can only run on boards with 8k or more RAM. - //************************************************************************ -//* Arduino String Test -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino String Test +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Oct 16, 2010 Started on String Test +//* Oct 16, 2010 Started on String Test //************************************************************************ #include @@ -26,123 +25,129 @@ //************************************************************************ 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)); + int startMemoryUsage = ATS_GetFreeMemory(); + 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)); #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); + // 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"; - stringTwo = "1"; - ATS_PrintTestStatus("13. Two numeric strings compared",stringOne >= stringTwo); - - - // comparison operators can be used to compare strings for alphabetic sorting too: + // two numeric strings compared: + stringOne = "2"; + stringTwo = "1"; + ATS_PrintTestStatus("13. Two numeric strings compared", + stringOne >= stringTwo); - stringOne = String("Brown"); - ATS_PrintTestStatus("14. operator <",stringOne < "Charles"); - ATS_PrintTestStatus("15. operator >",stringOne > "Adams"); - ATS_PrintTestStatus("16. operator <=",stringOne <= "Browne"); - ATS_PrintTestStatus("17. operator >=",stringOne >= "Brow"); + // comparison operators can be used to compare strings for alphabetic sorting too: + stringOne = String("Brown"); + ATS_PrintTestStatus("14. operator <", stringOne < "Charles"); + ATS_PrintTestStatus("15. operator >", stringOne > "Adams"); + ATS_PrintTestStatus("16. operator <=", stringOne <= "Browne"); + ATS_PrintTestStatus("17. operator >=", stringOne >= "Brow"); - // the compareTo() operator also allows you to compare strings - stringOne = "Cucumber"; - stringTwo = "Cucuracha"; + // the compareTo() operator also allows you to compare strings + stringOne = "Cucumber"; + stringTwo = "Cucuracha"; - ATS_PrintTestStatus("18. compareTo() compare strings", stringOne.compareTo(stringTwo) < 0); + ATS_PrintTestStatus("18. compareTo() compare strings", + stringOne.compareTo(stringTwo) < 0); /* // compareTo() String with numnber > String with number: @@ -159,164 +164,209 @@ void setup() 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); - - - stringOne = "The quick brown fox"; - ATS_PrintTestStatus("23. Substring ", stringOne.substring(0, 1) == "T"); - ATS_PrintTestStatus("24. Substring ", stringOne.substring(0, 3) == "The"); - ATS_PrintTestStatus("25. Substring ", stringOne.substring(4, 9) == "quick"); - ATS_PrintTestStatus("26. Substring ", stringOne.substring(10, 15) == "brown"); - ATS_PrintTestStatus("27. Substring ", stringOne.substring(16, 19) == "fox"); - ATS_PrintTestStatus("28. Substring ", stringOne.substring(18, 19) == "x"); - ATS_PrintTestStatus("29. Substring ", stringOne.substring(0, 19) == stringOne); - - stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; - int i; - i = stringOne.lastIndexOf("

    "); - ATS_PrintTestStatus("30. lastIndexOf ", i == 56); - i = stringOne.lastIndexOf("

    ", i); - ATS_PrintTestStatus("31. lastIndexOf ", i == 56); - i = stringOne.lastIndexOf("

    ", i - 1); - ATS_PrintTestStatus("32. lastIndexOf ", i == 45); - i = stringOne.lastIndexOf("

    ", i - 1); - ATS_PrintTestStatus("33. lastIndexOf ", i == 33); - i = stringOne.lastIndexOf("

    ", i - 1); - ATS_PrintTestStatus("34. lastIndexOf ", i == 0); - i = stringOne.lastIndexOf("ipsum", 8); - ATS_PrintTestStatus("35. lastIndexOf ", i == -1); - i = stringOne.lastIndexOf(stringOne); - ATS_PrintTestStatus("36. lastIndexOf ", i == 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); + + stringOne = "The quick brown fox"; + ATS_PrintTestStatus("23. Substring ", stringOne.substring(0, 1) == "T"); + ATS_PrintTestStatus("24. Substring ", + stringOne.substring(0, 3) == "The"); + ATS_PrintTestStatus("25. Substring ", + stringOne.substring(4, 9) == "quick"); + ATS_PrintTestStatus("26. Substring ", + stringOne.substring(10, 15) == "brown"); + ATS_PrintTestStatus("27. Substring ", + stringOne.substring(16, 19) == "fox"); + ATS_PrintTestStatus("28. Substring ", + stringOne.substring(18, 19) == "x"); + ATS_PrintTestStatus("29. Substring ", + stringOne.substring(0, 19) == stringOne); + + stringOne = + "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; + int i; + i = stringOne.lastIndexOf("

    "); + ATS_PrintTestStatus("30. lastIndexOf ", i == 56); + i = stringOne.lastIndexOf("

    ", i); + ATS_PrintTestStatus("31. lastIndexOf ", i == 56); + i = stringOne.lastIndexOf("

    ", i - 1); + ATS_PrintTestStatus("32. lastIndexOf ", i == 45); + i = stringOne.lastIndexOf("

    ", i - 1); + ATS_PrintTestStatus("33. lastIndexOf ", i == 33); + i = stringOne.lastIndexOf("

    ", i - 1); + ATS_PrintTestStatus("34. lastIndexOf ", i == 0); + i = stringOne.lastIndexOf("ipsum", 8); + ATS_PrintTestStatus("35. lastIndexOf ", i == -1); + i = stringOne.lastIndexOf(stringOne); + ATS_PrintTestStatus("36. lastIndexOf ", i == 0); #if ARDUINO >= 100 - stringOne = " test 123 \t "; - stringOne.trim(); - ATS_PrintTestStatus("37. trim ", stringOne == "test 123"); - stringOne = "test 123"; - stringOne.trim(); - ATS_PrintTestStatus("38. trim ", stringOne == "test 123"); - stringOne = "test 123 \t "; - stringOne.trim(); - ATS_PrintTestStatus("39. trim ", stringOne == "test 123"); - stringOne = " test 123"; - stringOne.trim(); - ATS_PrintTestStatus("40. trim ", stringOne == "test 123"); - stringOne = (char *)NULL; - stringOne.trim(); - ATS_PrintTestStatus("41. empty ", stringOne == ""); - stringOne = ""; - stringOne.trim(); - ATS_PrintTestStatus("42. empty ", stringOne == ""); + stringOne = " test 123 \t "; + stringOne.trim(); + ATS_PrintTestStatus("37. trim ", stringOne == "test 123"); + stringOne = "test 123"; + stringOne.trim(); + ATS_PrintTestStatus("38. trim ", stringOne == "test 123"); + stringOne = "test 123 \t "; + stringOne.trim(); + ATS_PrintTestStatus("39. trim ", stringOne == "test 123"); + stringOne = " test 123"; + stringOne.trim(); + ATS_PrintTestStatus("40. trim ", stringOne == "test 123"); + stringOne = (char *)NULL; + stringOne.trim(); + ATS_PrintTestStatus("41. empty ", stringOne == ""); + stringOne = ""; + stringOne.trim(); + ATS_PrintTestStatus("42. empty ", stringOne == ""); #else - stringOne = " test 123 \t "; - ATS_PrintTestStatus("37. trim ", stringOne.trim() == "test 123"); - stringOne = "test 123"; - ATS_PrintTestStatus("38. trim ", stringOne.trim() == "test 123"); - stringOne = "test 123 \t "; - ATS_PrintTestStatus("39. trim ", stringOne.trim() == "test 123"); - stringOne = " test 123"; - ATS_PrintTestStatus("40. trim ", stringOne.trim() == "test 123"); - stringOne = (char *)NULL; - ATS_PrintTestStatus("41. empty ", stringOne.trim() == ""); - stringOne = ""; - ATS_PrintTestStatus("42. empty ", stringOne.trim() == ""); + stringOne = " test 123 \t "; + ATS_PrintTestStatus("37. trim ", stringOne.trim() == "test 123"); + stringOne = "test 123"; + ATS_PrintTestStatus("38. trim ", stringOne.trim() == "test 123"); + stringOne = "test 123 \t "; + ATS_PrintTestStatus("39. trim ", stringOne.trim() == "test 123"); + stringOne = " test 123"; + ATS_PrintTestStatus("40. trim ", stringOne.trim() == "test 123"); + stringOne = (char *)NULL; + ATS_PrintTestStatus("41. empty ", stringOne.trim() == ""); + stringOne = ""; + ATS_PrintTestStatus("42. empty ", stringOne.trim() == ""); #endif - + #if ARDUINO >= 100 - stringOne = "test one test"; - stringOne.replace("test", "1234"); - ATS_PrintTestStatus("43. replace", stringOne == "1234 one 1234"); - stringOne = "test one test two"; - stringOne.replace("test", "1234"); - ATS_PrintTestStatus("44. replace", stringOne == "1234 one 1234 two"); - stringOne = "zero test one test two"; - stringOne.replace("test", "12345"); - ATS_PrintTestStatus("45. replace", stringOne == "zero 12345 one 12345 two"); - stringOne = "zero test one test"; - stringOne.replace("test", "1234"); - ATS_PrintTestStatus("46. replace", stringOne == "zero 1234 one 1234"); - stringOne = "test one test"; - stringOne.replace("test", "123"); - ATS_PrintTestStatus("47. replace", stringOne == "123 one 123"); - stringOne = "test one test two"; - stringOne.replace("test", "123"); - ATS_PrintTestStatus("48. replace", stringOne == "123 one 123 two"); - stringOne = "zero test one test two"; - stringOne.replace("test", "12"); - ATS_PrintTestStatus("49. replace", stringOne == "zero 12 one 12 two"); - stringOne = "zero test one test"; - stringOne.replace("test", "1"); - ATS_PrintTestStatus("50. replace", stringOne == "zero 1 one 1"); - stringOne = "test one test"; - stringOne.replace("test", "12345"); - ATS_PrintTestStatus("51. replace", stringOne == "12345 one 12345"); - stringOne = "test one test two"; - stringOne.replace("test", "123456"); - ATS_PrintTestStatus("52. replace", stringOne == "123456 one 123456 two"); - stringOne = "zero test one test two"; - stringOne.replace("test", "1234567"); - ATS_PrintTestStatus("53. replace", stringOne == "zero 1234567 one 1234567 two"); - stringOne = "zero test one test"; - stringOne.replace("test", "12345678"); - ATS_PrintTestStatus("54. replace", stringOne == "zero 12345678 one 12345678"); - stringOne = "zero test one test"; - stringOne.replace('e', 'X'); - ATS_PrintTestStatus("55. replace char", stringOne == "zXro tXst onX tXst"); -#else - stringOne = "test one test"; - ATS_PrintTestStatus("43. replace", stringOne.replace("test", "1234") == "1234 one 1234"); - stringOne = "test one test two"; - ATS_PrintTestStatus("44. replace", stringOne.replace("test", "1234") == "1234 one 1234 two"); - stringOne = "zero test one test two"; - ATS_PrintTestStatus("45. replace", stringOne.replace("test", "12345") == "zero 12345 one 12345 two"); - stringOne = "zero test one test"; - ATS_PrintTestStatus("46. replace", stringOne.replace("test", "1234") == "zero 1234 one 1234"); - stringOne = "test one test"; - ATS_PrintTestStatus("47. replace", stringOne.replace("test", "123") == "123 one 123"); - stringOne = "test one test two"; - ATS_PrintTestStatus("48. replace", stringOne.replace("test", "123") == "123 one 123 two"); - stringOne = "zero test one test two"; - ATS_PrintTestStatus("49. replace", stringOne.replace("test", "12") == "zero 12 one 12 two"); - stringOne = "zero test one test"; - ATS_PrintTestStatus("50. replace", stringOne.replace("test", "1") == "zero 1 one 1"); - stringOne = "test one test"; - ATS_PrintTestStatus("51. replace", stringOne.replace("test", "12345") == "12345 one 12345"); - stringOne = "test one test two"; - ATS_PrintTestStatus("52. replace", stringOne.replace("test", "123456") == "123456 one 123456 two"); - stringOne = "zero test one test two"; - ATS_PrintTestStatus("53. replace", stringOne.replace("test", "1234567") == "zero 1234567 one 1234567 two"); - stringOne = "zero test one test"; - ATS_PrintTestStatus("54. replace", stringOne.replace("test", "12345678") == "zero 12345678 one 12345678"); - stringOne = "zero test one test"; - ATS_PrintTestStatus("55. replace char", stringOne.replace('e', 'X') == "zXro tXst onX tXst"); + stringOne = "test one test"; + stringOne.replace("test", "1234"); + ATS_PrintTestStatus("43. replace", stringOne == "1234 one 1234"); + stringOne = "test one test two"; + stringOne.replace("test", "1234"); + ATS_PrintTestStatus("44. replace", stringOne == "1234 one 1234 two"); + stringOne = "zero test one test two"; + stringOne.replace("test", "12345"); + ATS_PrintTestStatus("45. replace", + stringOne == "zero 12345 one 12345 two"); + stringOne = "zero test one test"; + stringOne.replace("test", "1234"); + ATS_PrintTestStatus("46. replace", stringOne == "zero 1234 one 1234"); + stringOne = "test one test"; + stringOne.replace("test", "123"); + ATS_PrintTestStatus("47. replace", stringOne == "123 one 123"); + stringOne = "test one test two"; + stringOne.replace("test", "123"); + ATS_PrintTestStatus("48. replace", stringOne == "123 one 123 two"); + stringOne = "zero test one test two"; + stringOne.replace("test", "12"); + ATS_PrintTestStatus("49. replace", stringOne == "zero 12 one 12 two"); + stringOne = "zero test one test"; + stringOne.replace("test", "1"); + ATS_PrintTestStatus("50. replace", stringOne == "zero 1 one 1"); + stringOne = "test one test"; + stringOne.replace("test", "12345"); + ATS_PrintTestStatus("51. replace", stringOne == "12345 one 12345"); + stringOne = "test one test two"; + stringOne.replace("test", "123456"); + ATS_PrintTestStatus("52. replace", + stringOne == "123456 one 123456 two"); + stringOne = "zero test one test two"; + stringOne.replace("test", "1234567"); + ATS_PrintTestStatus("53. replace", + stringOne == "zero 1234567 one 1234567 two"); + stringOne = "zero test one test"; + stringOne.replace("test", "12345678"); + ATS_PrintTestStatus("54. replace", + stringOne == "zero 12345678 one 12345678"); + stringOne = "zero test one test"; + stringOne.replace('e', 'X'); + ATS_PrintTestStatus("55. replace char", + stringOne == "zXro tXst onX tXst"); +#else + stringOne = "test one test"; + ATS_PrintTestStatus("43. replace", + stringOne.replace("test", + "1234") == "1234 one 1234"); + stringOne = "test one test two"; + ATS_PrintTestStatus("44. replace", + stringOne.replace("test", + "1234") == "1234 one 1234 two"); + stringOne = "zero test one test two"; + ATS_PrintTestStatus("45. replace", + stringOne.replace("test", + "12345") == + "zero 12345 one 12345 two"); + stringOne = "zero test one test"; + ATS_PrintTestStatus("46. replace", + stringOne.replace("test", + "1234") == "zero 1234 one 1234"); + stringOne = "test one test"; + ATS_PrintTestStatus("47. replace", + stringOne.replace("test", "123") == "123 one 123"); + stringOne = "test one test two"; + ATS_PrintTestStatus("48. replace", + stringOne.replace("test", + "123") == "123 one 123 two"); + stringOne = "zero test one test two"; + ATS_PrintTestStatus("49. replace", + stringOne.replace("test", + "12") == "zero 12 one 12 two"); + stringOne = "zero test one test"; + ATS_PrintTestStatus("50. replace", + stringOne.replace("test", "1") == "zero 1 one 1"); + stringOne = "test one test"; + ATS_PrintTestStatus("51. replace", + stringOne.replace("test", + "12345") == "12345 one 12345"); + stringOne = "test one test two"; + ATS_PrintTestStatus("52. replace", + stringOne.replace("test", + "123456") == + "123456 one 123456 two"); + stringOne = "zero test one test two"; + ATS_PrintTestStatus("53. replace", + stringOne.replace("test", + "1234567") == + "zero 1234567 one 1234567 two"); + stringOne = "zero test one test"; + ATS_PrintTestStatus("54. replace", + stringOne.replace("test", + "12345678") == + "zero 12345678 one 12345678"); + stringOne = "zero test one test"; + ATS_PrintTestStatus("55. replace char", + stringOne.replace('e', + 'X') == "zXro tXst onX tXst"); #endif - - stringOne = "Zero"; - stringTwo = "oNe"; - ATS_PrintTestStatus("56. add", stringOne + "124" + stringTwo + 5678 == "Zero124oNe5678"); + + stringOne = "Zero"; + stringTwo = "oNe"; + ATS_PrintTestStatus("56. add", + stringOne + "124" + stringTwo + 5678 == + "Zero124oNe5678"); #if ARDUINO >= 100 - stringOne.toUpperCase(); - ATS_PrintTestStatus("57. toUpperCase", stringOne == "ZERO"); - stringTwo.toLowerCase(); - ATS_PrintTestStatus("58. toLowerCase", stringTwo == "one"); + stringOne.toUpperCase(); + ATS_PrintTestStatus("57. toUpperCase", stringOne == "ZERO"); + stringTwo.toLowerCase(); + ATS_PrintTestStatus("58. toLowerCase", stringTwo == "one"); #else - ATS_PrintTestStatus("57. toUpperCase", stringOne.toUpperCase() == "ZERO"); - ATS_PrintTestStatus("58. toLowerCase", stringTwo.toLowerCase() == "one"); + ATS_PrintTestStatus("57. toUpperCase", + stringOne.toUpperCase() == "ZERO"); + ATS_PrintTestStatus("58. toLowerCase", + stringTwo.toLowerCase() == "one"); #endif - stringOne = "-1234567"; - ATS_PrintTestStatus("59. toInt", stringOne.toInt() == -1234567L); - stringOne = "12345"; - ATS_PrintTestStatus("60. toInt", stringOne.toInt() == 12345); - + stringOne = "-1234567"; + ATS_PrintTestStatus("59. toInt", stringOne.toInt() == -1234567L); + stringOne = "12345"; + ATS_PrintTestStatus("60. toInt", stringOne.toInt() == 12345); #if !defined(F) || (ARDUINO >= 100 && !defined(CORE_TEENSY)) // Arduino 1.0, does not support for using F("cstring") with @@ -331,196 +381,217 @@ void setup() #define F(s) (s) #endif - stringOne = F("flash string"); - ATS_PrintTestStatus("61. assign flash string", stringOne == "flash string"); - stringOne += F(" test"); - ATS_PrintTestStatus("62. append flash string", stringOne == "flash string test"); - ATS_PrintTestStatus("63. append flash string", stringOne == F("flash string test")); - ATS_PrintTestStatus("64. add flash string", F("1234 ") + stringOne == "1234 flash string test"); - - stringOne = F("tst"); - char *ptr = NULL; - stringOne.concat(ptr); - ATS_PrintTestStatus("65. append", stringOne == "tst"); - ATS_PrintTestStatus("66. concat", stringOne + "123" + ptr + "hi" == "tst123hi"); - ATS_PrintTestStatus("67. append", stringOne == "tst"); - - stringOne = F("TST"); - stringOne.concat(""); - ATS_PrintTestStatus("68. append", stringOne == "TST"); - ATS_PrintTestStatus("69. concat", stringOne + "" == "TST"); - ATS_PrintTestStatus("70. append", stringOne == "TST"); - - stringOne = F("ZXDY"); - stringOne.concat("123"); - ATS_PrintTestStatus("71. append", stringOne == "ZXDY123"); - ATS_PrintTestStatus("72. concat", stringOne + "567" == "ZXDY123567"); - ATS_PrintTestStatus("73. append", stringOne == "ZXDY123"); - - stringOne = F("ra"); - stringOne.concat(F("573")); - ATS_PrintTestStatus("74. append", stringOne == "ra573"); - ATS_PrintTestStatus("75. concat", stringOne + F("4543") == "ra5734543"); - ATS_PrintTestStatus("76. append", stringOne == "ra573"); - - char c = '7'; - unsigned char uc = '9'; - stringOne = F("tywe"); - stringOne.concat(c); - stringOne.concat(uc); - ATS_PrintTestStatus("77. append", stringOne == F("tywe79")); - stringOne += uc; - stringOne += c; - ATS_PrintTestStatus("78. append", stringOne == F("tywe7997")); - c = '.'; - ATS_PrintTestStatus("79. concat", stringOne + c == F("tywe7997.")); - uc = 'R'; - ATS_PrintTestStatus("80. concat", stringOne + uc == F("tywe7997R")); - ATS_PrintTestStatus("81. append", stringOne == F("tywe7997")); - - i = -32768; - stringOne = F("u572h"); - stringOne.concat(i); - ATS_PrintTestStatus("82. append", stringOne == F("u572h-32768")); - stringOne += i; - ATS_PrintTestStatus("83. append", stringOne == F("u572h-32768-32768")); - i = -25000; - ATS_PrintTestStatus("84. concat", stringOne + i == F("u572h-32768-32768-25000")); - ATS_PrintTestStatus("85. append", stringOne == F("u572h-32768-32768")); - - i = 24173; - stringOne = F("5u1klj"); - stringOne.concat(i); - ATS_PrintTestStatus("86. append", stringOne == F("5u1klj24173")); - stringOne += i; - ATS_PrintTestStatus("87. append", stringOne == F("5u1klj2417324173")); - ATS_PrintTestStatus("88. concat", stringOne + i == F("5u1klj241732417324173")); - ATS_PrintTestStatus("89. append", stringOne == F("5u1klj2417324173")); - - unsigned int u = 65190; - stringOne = F("i8skjm"); - stringOne.concat(u); - ATS_PrintTestStatus("90. append", stringOne == F("i8skjm65190")); - stringOne += u; - ATS_PrintTestStatus("91. append", stringOne == F("i8skjm6519065190")); - ATS_PrintTestStatus("92. concat", stringOne + u == F("i8skjm651906519065190")); - ATS_PrintTestStatus("93. append", stringOne == F("i8skjm6519065190")); - - long n = -91093847; - stringOne = F("ywh"); - stringOne.concat(n); - ATS_PrintTestStatus("94. append", stringOne == F("ywh-91093847")); - stringOne += n; - ATS_PrintTestStatus("95. append", stringOne == F("ywh-91093847-91093847")); - ATS_PrintTestStatus("96. concat", stringOne + n == F("ywh-91093847-91093847-91093847")); - ATS_PrintTestStatus("97. append", stringOne == F("ywh-91093847-91093847")); - - unsigned long un = 4294961479; - stringOne = F("iu"); - stringOne.concat(un); - ATS_PrintTestStatus("98. append", stringOne == F("iu4294961479")); - un -= 4; - stringOne += un; - ATS_PrintTestStatus("99. append", stringOne == F("iu42949614794294961475")); - ATS_PrintTestStatus("100. concat", stringOne + un == F("iu429496147942949614754294961475")); - ATS_PrintTestStatus("101. append", stringOne == F("iu42949614794294961475")); - - stringOne = "123"; - stringTwo = "456"; // TODO: repeat this test for all overload permutations - stringThree = "789"; - stringOne = (stringTwo += stringThree); - ATS_PrintTestStatus("102. append result", stringOne == F("456789")); - ATS_PrintTestStatus("103. append", stringTwo == F("456789")); - ATS_PrintTestStatus("104. append const in", stringThree == F("789")); - - stringOne = "abc"; - stringTwo = "def"; - stringThree = "ghi"; - stringOne = stringTwo = stringThree; - ATS_PrintTestStatus("105. assign", stringOne == F("ghi")); - ATS_PrintTestStatus("106. assign", stringTwo == F("ghi")); - - // 111111111122222222223333333333 - // 0123456789012345678901234567890123456789 - stringOne = F("Now is the time for all good men"); - stringOne.toCharArray(charResult, 6); - ATS_PrintTestStatus("107. toCharArray", strcmp_P(charResult, PSTR("Now i")) == 0); + stringOne = F("flash string"); + ATS_PrintTestStatus("61. assign flash string", + stringOne == "flash string"); + stringOne += F(" test"); + ATS_PrintTestStatus("62. append flash string", + stringOne == "flash string test"); + ATS_PrintTestStatus("63. append flash string", + stringOne == F("flash string test")); + ATS_PrintTestStatus("64. add flash string", + F("1234 ") + stringOne == "1234 flash string test"); + + stringOne = F("tst"); + char *ptr = NULL; + stringOne.concat(ptr); + ATS_PrintTestStatus("65. append", stringOne == "tst"); + ATS_PrintTestStatus("66. concat", + stringOne + "123" + ptr + "hi" == "tst123hi"); + ATS_PrintTestStatus("67. append", stringOne == "tst"); + + stringOne = F("TST"); + stringOne.concat(""); + ATS_PrintTestStatus("68. append", stringOne == "TST"); + ATS_PrintTestStatus("69. concat", stringOne + "" == "TST"); + ATS_PrintTestStatus("70. append", stringOne == "TST"); + + stringOne = F("ZXDY"); + stringOne.concat("123"); + ATS_PrintTestStatus("71. append", stringOne == "ZXDY123"); + ATS_PrintTestStatus("72. concat", stringOne + "567" == "ZXDY123567"); + ATS_PrintTestStatus("73. append", stringOne == "ZXDY123"); + + stringOne = F("ra"); + stringOne.concat(F("573")); + ATS_PrintTestStatus("74. append", stringOne == "ra573"); + ATS_PrintTestStatus("75. concat", stringOne + F("4543") == "ra5734543"); + ATS_PrintTestStatus("76. append", stringOne == "ra573"); + + char c = '7'; + unsigned char uc = '9'; + stringOne = F("tywe"); + stringOne.concat(c); + stringOne.concat(uc); + ATS_PrintTestStatus("77. append", stringOne == F("tywe79")); + stringOne += uc; + stringOne += c; + ATS_PrintTestStatus("78. append", stringOne == F("tywe7997")); + c = '.'; + ATS_PrintTestStatus("79. concat", stringOne + c == F("tywe7997.")); + uc = 'R'; + ATS_PrintTestStatus("80. concat", stringOne + uc == F("tywe7997R")); + ATS_PrintTestStatus("81. append", stringOne == F("tywe7997")); + + i = -32768; + stringOne = F("u572h"); + stringOne.concat(i); + ATS_PrintTestStatus("82. append", stringOne == F("u572h-32768")); + stringOne += i; + ATS_PrintTestStatus("83. append", stringOne == F("u572h-32768-32768")); + i = -25000; + ATS_PrintTestStatus("84. concat", + stringOne + i == F("u572h-32768-32768-25000")); + ATS_PrintTestStatus("85. append", stringOne == F("u572h-32768-32768")); + + i = 24173; + stringOne = F("5u1klj"); + stringOne.concat(i); + ATS_PrintTestStatus("86. append", stringOne == F("5u1klj24173")); + stringOne += i; + ATS_PrintTestStatus("87. append", stringOne == F("5u1klj2417324173")); + ATS_PrintTestStatus("88. concat", + stringOne + i == F("5u1klj241732417324173")); + ATS_PrintTestStatus("89. append", stringOne == F("5u1klj2417324173")); + + unsigned int u = 65190; + stringOne = F("i8skjm"); + stringOne.concat(u); + ATS_PrintTestStatus("90. append", stringOne == F("i8skjm65190")); + stringOne += u; + ATS_PrintTestStatus("91. append", stringOne == F("i8skjm6519065190")); + ATS_PrintTestStatus("92. concat", + stringOne + u == F("i8skjm651906519065190")); + ATS_PrintTestStatus("93. append", stringOne == F("i8skjm6519065190")); + + long n = -91093847; + stringOne = F("ywh"); + stringOne.concat(n); + ATS_PrintTestStatus("94. append", stringOne == F("ywh-91093847")); + stringOne += n; + ATS_PrintTestStatus("95. append", + stringOne == F("ywh-91093847-91093847")); + ATS_PrintTestStatus("96. concat", + stringOne + n == + F("ywh-91093847-91093847-91093847")); + ATS_PrintTestStatus("97. append", + stringOne == F("ywh-91093847-91093847")); + + unsigned long un = 4294961479; + stringOne = F("iu"); + stringOne.concat(un); + ATS_PrintTestStatus("98. append", stringOne == F("iu4294961479")); + un -= 4; + stringOne += un; + ATS_PrintTestStatus("99. append", + stringOne == F("iu42949614794294961475")); + ATS_PrintTestStatus("100. concat", + stringOne + un == + F("iu429496147942949614754294961475")); + ATS_PrintTestStatus("101. append", + stringOne == F("iu42949614794294961475")); + + stringOne = "123"; + stringTwo = "456"; // TODO: repeat this test for all overload permutations + stringThree = "789"; + stringOne = (stringTwo += stringThree); + ATS_PrintTestStatus("102. append result", stringOne == F("456789")); + ATS_PrintTestStatus("103. append", stringTwo == F("456789")); + ATS_PrintTestStatus("104. append const in", stringThree == F("789")); + + stringOne = "abc"; + stringTwo = "def"; + stringThree = "ghi"; + stringOne = stringTwo = stringThree; + ATS_PrintTestStatus("105. assign", stringOne == F("ghi")); + ATS_PrintTestStatus("106. assign", stringTwo == F("ghi")); + + // 111111111122222222223333333333 + // 0123456789012345678901234567890123456789 + stringOne = F("Now is the time for all good men"); + stringOne.toCharArray(charResult, 6); + ATS_PrintTestStatus("107. toCharArray", + strcmp_P(charResult, PSTR("Now i")) == 0); #if ARDUINO >= 100 || defined(CORE_TEENSY) // these tests check toCharArray's handling of offsets, which was added // in Teensyduino and contributed to Arduino 1.0. Arduino 0022 does // not have this feature, so do not run these tests on older Arduino // unless using Teensy. - stringOne.toCharArray(charResult, 10, 8); - ATS_PrintTestStatus("108. toCharArray", strcmp_P(charResult, PSTR("he time f")) == 0); + stringOne.toCharArray(charResult, 10, 8); + ATS_PrintTestStatus("108. toCharArray", + strcmp_P(charResult, PSTR("he time f")) == 0); - stringOne.toCharArray(charResult, sizeof(charResult), 25); - ATS_PrintTestStatus("109. toCharArray", strcmp_P(charResult, PSTR("ood men")) == 0); + stringOne.toCharArray(charResult, sizeof(charResult), 25); + ATS_PrintTestStatus("109. toCharArray", + strcmp_P(charResult, PSTR("ood men")) == 0); - stringOne.getBytes((unsigned char *)charResult, 6); - ATS_PrintTestStatus("110. getBytes", strcmp_P(charResult, PSTR("Now i")) == 0); + stringOne.getBytes((unsigned char *)charResult, 6); + ATS_PrintTestStatus("110. getBytes", + strcmp_P(charResult, PSTR("Now i")) == 0); - stringOne.getBytes((unsigned char *)charResult, 10, 8); - ATS_PrintTestStatus("111. getBytes", strcmp_P(charResult, PSTR("he time f")) == 0); + stringOne.getBytes((unsigned char *)charResult, 10, 8); + ATS_PrintTestStatus("111. getBytes", + strcmp_P(charResult, PSTR("he time f")) == 0); - stringOne.getBytes((unsigned char *)charResult, sizeof(charResult), 25); - ATS_PrintTestStatus("112. getBytes", strcmp_P(charResult, PSTR("ood men")) == 0); + stringOne.getBytes((unsigned char *)charResult, sizeof(charResult), 25); + ATS_PrintTestStatus("112. getBytes", + strcmp_P(charResult, PSTR("ood men")) == 0); - stringOne.toCharArray(charResult, sizeof(charResult), 100); - ATS_PrintTestStatus("113. toCharArray", strcmp_P(charResult, PSTR("")) == 0); + stringOne.toCharArray(charResult, sizeof(charResult), 100); + ATS_PrintTestStatus("113. toCharArray", + strcmp_P(charResult, PSTR("")) == 0); #endif - ATS_PrintTestStatus("114. operator [] read", stringOne[0] == 'N'); - ATS_PrintTestStatus("115. operator [] read", stringOne[20] == 'a'); - ATS_PrintTestStatus("116. operator [] read", stringOne[30] == 'e'); - ATS_PrintTestStatus("117. operator [] read", stringOne[32] == 0); - ATS_PrintTestStatus("118. operator [] read", stringOne[40] == 0); - - stringOne[0] = 'n'; // should write to the string - stringOne[11] = 'S'; - stringOne[28] = '_'; - - ATS_PrintTestStatus("119. operator [] write", stringOne == F("now is the Sime for all good_men")); - stringOne.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("120. operator [] write", strcmp_P(charResult, PSTR("now is the Sime for all good_men")) == 0); - - stringOne[32] = '.'; // should not write over null term - - ATS_PrintTestStatus("121. operator [] write", stringOne == F("now is the Sime for all good_men")); - stringOne.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("122. operator [] write", strcmp_P(charResult, PSTR("now is the Sime for all good_men")) == 0); - - for (i=33; i<10000; i++) { - stringOne[i] = '.'; // should not buffer overflow (test will crash if it does) - } - - ATS_PrintTestStatus("123. operator [] write", stringOne == F("now is the Sime for all good_men")); - stringOne.toCharArray(charResult, sizeof(charResult)); - ATS_PrintTestStatus("124. operator [] write", strcmp_P(charResult, PSTR("now is the Sime for all good_men")) == 0); - - /* - * Test complete - */ - - ATS_end(); + ATS_PrintTestStatus("114. operator [] read", stringOne[0] == 'N'); + ATS_PrintTestStatus("115. operator [] read", stringOne[20] == 'a'); + ATS_PrintTestStatus("116. operator [] read", stringOne[30] == 'e'); + ATS_PrintTestStatus("117. operator [] read", stringOne[32] == 0); + ATS_PrintTestStatus("118. operator [] read", stringOne[40] == 0); + + stringOne[0] = 'n'; // should write to the string + stringOne[11] = 'S'; + stringOne[28] = '_'; + + ATS_PrintTestStatus("119. operator [] write", + stringOne == F("now is the Sime for all good_men")); + stringOne.toCharArray(charResult, sizeof(charResult)); + ATS_PrintTestStatus("120. operator [] write", + strcmp_P(charResult, + PSTR("now is the Sime for all good_men")) + == 0); + + stringOne[32] = '.'; // should not write over null term + + ATS_PrintTestStatus("121. operator [] write", + stringOne == F("now is the Sime for all good_men")); + stringOne.toCharArray(charResult, sizeof(charResult)); + ATS_PrintTestStatus("122. operator [] write", + strcmp_P(charResult, + PSTR("now is the Sime for all good_men")) + == 0); + + for (i = 33; i < 10000; i++) { + stringOne[i] = '.'; // should not buffer overflow (test will crash if it does) + } + + ATS_PrintTestStatus("123. operator [] write", + stringOne == F("now is the Sime for all good_men")); + stringOne.toCharArray(charResult, sizeof(charResult)); + ATS_PrintTestStatus("124. operator [] write", + strcmp_P(charResult, + PSTR("now is the Sime for all good_men")) + == 0); + + /* + * Test complete + */ + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - - } - - - - - - - - - - - diff --git a/examples/ATS_String_Addition/ATS_String_Addition.ino b/examples/ATS_String_Addition/ATS_String_Addition.ino index fc611bb..9c39cb4 100644 --- a/examples/ATS_String_Addition/ATS_String_Addition.ino +++ b/examples/ATS_String_Addition/ATS_String_Addition.ino @@ -3,46 +3,47 @@ void setup() { - ATS_begin("Arduino", "String Addition Test"); - - String stringOne = String("string"); - String stringTwo = String("other"); - String stringThree = stringOne + stringTwo; - - Test_Equal("Add strings", "stringother", stringThree); - Test_Equal("Adding strings doesn't change them", "string", stringOne); - Test_Equal("Adding strings doesn't change them", "other", stringTwo); - Test_Equal("Add strings", "stringotherstringstringstringother", stringOne + stringTwo + stringOne + stringOne + stringOne + stringTwo); - Test_Equal("Add string to integer", "string12345", stringOne + 12345); - Test_Equal("Add string to negative integer", "string-12345", stringOne + -12345); - Test_Equal("Add integer to string", "123string", 123 + stringOne); - Test_Equal("Add string to integers", "string123456789", stringOne + 123 + 456 + 789); - Test_Equal("Add integer to string", "123string456789", 123 + stringOne + 456 + 789); - Test_Equal("Add string to long", "string123456789", stringOne + 123456789L); - Test_Equal("Add string to negative long", "string-123456789", stringOne + -123456789L); - Test_Equal("Add string to unsigned long", "string123456789", stringOne + 123456789UL); - Test_Equal("Add string to byte", "string123", stringOne + byte(123)); - Test_Equal("Add char", "stringA", stringOne + 'A'); - Test_Equal("Add char", "Astring", 'A' + stringOne); - Test_Equal("Add \"string\"", "stringabc", stringOne + "abc"); - Test_Equal("Add \"string\"", "abcstring", "abc" + stringOne); - Test_Equal("Add multiple \"string\"", "stringabcdef", stringOne + "abc" + "def"); - Test_Equal("Add multiple \"string\"", "abcstringdef", "abc" + stringOne + "def"); - Test_Equal("Add \"string\" and int", "bc", "abc" + 1); - - ATS_end(); + ATS_begin("Arduino", "String Addition Test"); + + String stringOne = String("string"); + String stringTwo = String("other"); + String stringThree = stringOne + stringTwo; + + Test_Equal("Add strings", "stringother", stringThree); + Test_Equal("Adding strings doesn't change them", "string", stringOne); + Test_Equal("Adding strings doesn't change them", "other", stringTwo); + Test_Equal("Add strings", "stringotherstringstringstringother", + stringOne + stringTwo + stringOne + stringOne + stringOne + + stringTwo); + Test_Equal("Add string to integer", "string12345", stringOne + 12345); + Test_Equal("Add string to negative integer", "string-12345", + stringOne + -12345); + Test_Equal("Add integer to string", "123string", 123 + stringOne); + Test_Equal("Add string to integers", "string123456789", + stringOne + 123 + 456 + 789); + Test_Equal("Add integer to string", "123string456789", + 123 + stringOne + 456 + 789); + Test_Equal("Add string to long", "string123456789", + stringOne + 123456789L); + Test_Equal("Add string to negative long", "string-123456789", + stringOne + -123456789L); + Test_Equal("Add string to unsigned long", "string123456789", + stringOne + 123456789UL); + Test_Equal("Add string to byte", "string123", stringOne + byte(123)); + Test_Equal("Add char", "stringA", stringOne + 'A'); + Test_Equal("Add char", "Astring", 'A' + stringOne); + Test_Equal("Add \"string\"", "stringabc", stringOne + "abc"); + Test_Equal("Add \"string\"", "abcstring", "abc" + stringOne); + Test_Equal("Add multiple \"string\"", "stringabcdef", + stringOne + "abc" + "def"); + Test_Equal("Add multiple \"string\"", "abcstringdef", + "abc" + stringOne + "def"); + Test_Equal("Add \"string\" and int", "bc", "abc" + 1); + + ATS_end(); } -void loop() {} - - - - - - - - - - - +void loop() +{ +} diff --git a/examples/ATS_String_Addition/Test_Equal.cpp b/examples/ATS_String_Addition/Test_Equal.cpp index abad86e..3602448 100644 --- a/examples/ATS_String_Addition/Test_Equal.cpp +++ b/examples/ATS_String_Addition/Test_Equal.cpp @@ -6,7 +6,7 @@ // ambigious overload error. #if ARDUINO >= 100 || defined(CORE_TEENSY) -void Test_Equal(char *testString, char *expected, const String &actual) +void Test_Equal(char *testString, char *expected, const String & actual) #else // the old string code does not define toCharArray() as const // this simple but ugly workaround is for Arduino 0022 and @@ -15,15 +15,15 @@ void Test_Equal(char *testString, char *expected, const String &actual) void Test_Equal(char *testString, char *expected, String actual) #endif { - 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("'"); - } + 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("'"); + } } - diff --git a/examples/ATS_String_Addition/Test_Equal.h b/examples/ATS_String_Addition/Test_Equal.h index c36f249..b1c75d2 100644 --- a/examples/ATS_String_Addition/Test_Equal.h +++ b/examples/ATS_String_Addition/Test_Equal.h @@ -1,16 +1,16 @@ #if ARDUINO >= 100 -#include + #include #else -#include + #include #endif #if ARDUINO >= 100 || defined(CORE_TEENSY) -void Test_Equal(char *testString, char *expected, const String &actual); + void Test_Equal(char *testString, char *expected, const String &actual); #else -// the old string code does not define toCharArray() as const -// this simple but ugly workaround is for Arduino 0022 and -// should someday be removed. For more info, see -// http://code.google.com/p/arduino/issues/detail?id=552 -void Test_Equal(char *testString, char *expected, String actual); + // the old string code does not define toCharArray() as const + // this simple but ugly workaround is for Arduino 0022 and + // should someday be removed. For more info, see + // http://code.google.com/p/arduino/issues/detail?id=552 + void Test_Equal(char *testString, char *expected, String actual); #endif diff --git a/examples/ATS_TomIgoeStringMemoryTest/ATS_TomIgoeStringMemoryTest.ino b/examples/ATS_TomIgoeStringMemoryTest/ATS_TomIgoeStringMemoryTest.ino index 3832c64..53eb465 100644 --- a/examples/ATS_TomIgoeStringMemoryTest/ATS_TomIgoeStringMemoryTest.ino +++ b/examples/ATS_TomIgoeStringMemoryTest/ATS_TomIgoeStringMemoryTest.ino @@ -1,10 +1,10 @@ //************************************************************************ -//* Arduino Tom Igoe Memory Test -//* (C) 2010 by Rick Anderson -//* Open source as per standard Arduino code +//* Arduino Tom Igoe Memory Test +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code //* //************************************************************************ -//* Jan 4, 2011 Started on Tom Igoe Memory Test +//* Jan 4, 2011 Started on Tom Igoe Memory Test //************************************************************************ #include @@ -12,45 +12,37 @@ //************************************************************************ void setup() { - int startMemoryUsage; - /* - * Create variable for the tests. - */ - - String webColor = "#000000"; - - int red = 1023/4; - int blue = 512/4; - int green = 128/4; - - /* - * initiate the test run - */ - //Record starting memory amount - startMemoryUsage = ATS_GetFreeMemory(); - //Begin test run - ATS_begin("Arduino", "Tom Igoe Memory Test"); - - webColor = "#"; - webColor += String(red, HEX); - webColor += String(green, HEX); - webColor += String(blue, HEX); - - ATS_ReportMemoryUsage(startMemoryUsage); - - /* - * Test complete - */ - - ATS_end(); + /* + * Create variable for the tests. + */ + String webColor = "#000000"; + + int red = 1023 / 4; + int blue = 512 / 4; + int green = 128 / 4; + + /* + * initiate the test run + */ + //Record starting memory amount + int startMemoryUsage = ATS_GetFreeMemory(); + //Begin test run + ATS_begin("Arduino", "Tom Igoe Memory Test"); + + webColor = "#"; + webColor += String(red, HEX); + webColor += String(green, HEX); + webColor += String(blue, HEX); + + /* + * Test complete + */ + ATS_ReportMemoryUsage(startMemoryUsage); + ATS_end(); } - //************************************************************************ void loop() { - - } - diff --git a/examples/ATS_ToneTest/ATS_ToneTest.ino b/examples/ATS_ToneTest/ATS_ToneTest.ino index 195a3ca..31d87d9 100644 --- a/examples/ATS_ToneTest/ATS_ToneTest.ino +++ b/examples/ATS_ToneTest/ATS_ToneTest.ino @@ -1,248 +1,208 @@ //************************************************************************ -//* 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 +//* 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 Started on TestArduino -//* Oct 23, 2010 Started on ToneTest +//* Aug 31, 2010 Started on TestArduino +//* Oct 23, 2010 Started on ToneTest //************************************************************************ #include #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) - #define kBoard_PinCount 20 - #define kBoard_AnalogCount 6 +#define kBoard_PinCount 20 +#define kBoard_AnalogCount 6 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - #define kBoard_PinCount 70 - #define kBoard_AnalogCount 16 +#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 kBoard_PinCount CORE_NUM_TOTAL_PINS +#define kBoard_AnalogCount CORE_NUM_ANALOG #endif //************************************************************************ -void TestTonePin(uint8_t toneOutputPinNumber) +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; + 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; } - else - { - //* if its ODD - helperpin = toneOutputPinNumber - 1; - } - if (helperpin >= kBoard_PinCount) return; + if (helperpin >= kBoard_PinCount) + return; + + //* dont set the mode of the OUTPUT pin, the tone command does that - //* 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); - + + 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) - { + while ((millis() - startMilliSecs) < 1000) { + currentState = digitalRead(helperpin); + if (currentState == HIGH) { highCount++; - } - else - { + } else { lowCount++; } - //* check to see if it changed state - if ((currentState == HIGH) && (previousState == LOW)) - { + //* check to see if it changed state + if ((currentState == HIGH) && (previousState == LOW)) { measuredFreq++; } - - previousState = currentState; + + 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; + + 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) +//* 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; + 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; } - if (helperpin >= kBoard_PinCount) return; + if (helperpin >= kBoard_PinCount) + return; + + //* dont set the mode of the OUTPUT pin, the tone command does that - //* 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); - + + 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) - { + while ((millis() - startMilliSecs) < 2000) { + currentState = digitalRead(helperpin); + if (currentState == HIGH) { highCount++; - } - else - { + } else { lowCount++; } - //* count the freq - if ((currentState == HIGH) && (previousState == LOW)) - { + //* count the freq + if ((currentState == HIGH) && (previousState == LOW)) { measuredFreq++; } - - //* check to see if it changed state - if (currentState != previousState) - { - durationTime = millis() - startMilliSecs; + //* 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; + + previousState = currentState; } - else - { - passed = false; + + 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(); - + short ii; + uint8_t timerNumber; + int startMemoryUsage = ATS_GetFreeMemory(); ATS_begin("Arduino", "ToneTest"); - - - //* we start at 2 because 0/1 are RXD/TXD - for (ii=2; ii= 0) - { - Serial.print("Got status code: "); - Serial.println(err); - - // Usually you'd check that the response code is 200 or a - // similar "success" code (200-299) before carrying on, - // but we'll print out whatever response we get - - err = http.skipResponseHeaders(); - if (err >= 0) - { - int bodyLen = http.contentLength(); - Serial.print("Content length is: "); - Serial.println(bodyLen); - Serial.println(); - Serial.println("Body returned follows:"); - - // Now we've got to the body, so we can print it out - unsigned long timeoutStart = millis(); - char c; - // Whilst we haven't timed out & haven't reached the end of the body - while ( (http.connected() || http.available()) && - ((millis() - timeoutStart) < kNetworkTimeout) ) - { - if (http.available()) - { - c = http.read(); - // Print out this character - Serial.print(c); - - bodyLen--; - // We read something, reset the timeout counter - timeoutStart = millis(); - } - else - { - // We haven't got any data, so let's pause to allow some to - // arrive - delay(kNetworkDelay); - } - } - } - else - { - Serial.print("Failed to skip response headers: "); - Serial.println(err); - } - } - else - { - Serial.print("Getting response failed: "); - Serial.println(err); - } - } - else - { - Serial.print("Connect failed: "); - Serial.println(err); - } - http.stop(); - - return false; + int err = 0; + HttpClient http(cc); + + err = http.get(kHostname, kPort, kPath); + if (err == 0) { + Serial.println("startedRequest ok"); + err = http.responseStatusCode(); + if (err >= 0) { + Serial.print("Got status code: "); + Serial.println(err); + // Usually you'd check that the response code is 200 or a + // similar "success" code (200-299) before carrying on, + // but we'll print out whatever response we get + err = http.skipResponseHeaders(); + if (err >= 0) { + int bodyLen = http.contentLength(); + Serial.print("Content length is: "); + Serial.println(bodyLen); + Serial.println(); + Serial.println("Body returned follows:"); + // Now we've got to the body, so we can print it out + unsigned long timeoutStart = millis(); + char c; + // Whilst we haven't timed out & haven't reached the end of the body + while ((http.connected() || http.available()) && + ((millis() - timeoutStart) < kNetworkTimeout)) { + if (http.available()) { + c = http.read(); + // Print out this character + Serial.print(c); + bodyLen--; + // We read something, reset the timeout counter + timeoutStart = millis(); + } else { + // We haven't got any data, so let's pause to allow some to + // arrive + delay(kNetworkDelay); + } + } + } else { + Serial.print("Failed to skip response headers: "); + Serial.println(err); + } + } else { + Serial.print("Getting response failed: "); + Serial.println(err); + } + } else { + Serial.print("Connect failed: "); + Serial.println(err); + } + + http.stop(); + + return false; } - void loop() { - - } - - diff --git a/examples/pulseInTest/pulseInTest.ino b/examples/pulseInTest/pulseInTest.ino index 127983d..84cd0d2 100644 --- a/examples/pulseInTest/pulseInTest.ino +++ b/examples/pulseInTest/pulseInTest.ino @@ -10,74 +10,75 @@ #include #include "pulse_hardware.h" -void setup() { - pinMode(pulseout_pin, OUTPUT); - pinMode(pulsein_pin, INPUT); - int mem = ATS_GetFreeMemory(); - ATS_begin("Arduino", "PulseInTest"); - run(HIGH); - run(LOW); - ATS_ReportMemoryUsage(mem); - Serial.print("info.diagnostic = Frequency on pin "); - Serial.print((int)pulseout_pin); - Serial.print(" should be "); - Serial.print(freq); - Serial.println(" Hz"); - ATS_end(); +void setup() +{ + pinMode(pulseout_pin, OUTPUT); + pinMode(pulsein_pin, INPUT); + int mem = ATS_GetFreeMemory(); + ATS_begin("Arduino", "PulseInTest"); + run(HIGH); + run(LOW); + ATS_ReportMemoryUsage(mem); + Serial.print("info.diagnostic = Frequency on pin "); + Serial.print((int)pulseout_pin); + Serial.print(" should be "); + Serial.print(freq); + Serial.println(" Hz"); + ATS_end(); } - // run the pulseIn test on a variety of PWM signals. // -void run(byte polarity) { - static int count = 1; - unsigned int errint; - float measure, ideal, error; - long measure_l, ideal_l; - char buf[120]; +void run(byte polarity) +{ + static int count = 1; + unsigned int errint; + float measure, ideal, error; + long measure_l, ideal_l; + char buf[120]; - for (int n=20; n < 235; n += 10) { - analogWrite(pulseout_pin, n); - delay(5); - measure = pulse_test(polarity); - if (polarity == HIGH) { - ideal = period * ((float)n / 255.0); - } else { - ideal = period * (1.0 - (float)n / 255.0); - } - error = (ideal - measure) / ideal; - if (error < 0.0) error *= -1.0; - errint = (unsigned int)(error * 1000.0 + 0.5); - measure_l = (long)(measure * 10.0 + 0.5); - ideal_l = (long)(ideal * 10.0 + 0.5); - sprintf(buf, "PulseInTest.%02d (measure=%ld.%ld, ideal=%ld.%ld, err=%u.%u%%", - count++, measure_l / 10, measure_l % 10, - ideal_l / 10, ideal_l % 10, - errint / 10, errint % 10); - ATS_PrintTestStatus(buf, (error < 0.03)); - } - analogWrite(pulseout_pin, 128); + for (int n = 20; n < 235; n += 10) { + analogWrite(pulseout_pin, n); + delay(5); + measure = pulse_test(polarity); + if (polarity == HIGH) { + ideal = period * ((float)n / 255.0); + } else { + ideal = period * (1.0 - (float)n / 255.0); + } + error = (ideal - measure) / ideal; + if (error < 0.0) + error *= -1.0; + errint = (unsigned int)(error * 1000.0 + 0.5); + measure_l = (long)(measure * 10.0 + 0.5); + ideal_l = (long)(ideal * 10.0 + 0.5); + sprintf(buf, + "PulseInTest.%02d (measure=%ld.%ld, ideal=%ld.%ld, err=%u.%u%%", + count++, measure_l / 10, measure_l % 10, ideal_l / 10, + ideal_l % 10, errint / 10, errint % 10); + ATS_PrintTestStatus(buf, (error < 0.03)); + } + analogWrite(pulseout_pin, 128); } - // do pulseIn 500 times and return the average // but if pulseIn ever returns 0, abort and return 0 // float pulse_test(uint8_t polarity) { - unsigned long n, sum = 0; - for (int i=0; i < 500; i++) { - noInterrupts(); - n = pulseIn(pulsein_pin, polarity, 100000); - interrupts(); - if (n == 0) return 0; - sum = sum + n; - } - return (float)sum * 0.002; + unsigned long n, sum = 0; + for (int i = 0; i < 500; i++) { + noInterrupts(); + n = pulseIn(pulsein_pin, polarity, 100000); + interrupts(); + if (n == 0) + return 0; + sum = sum + n; + } + return (float)sum *0.002; } - -void loop() { +void loop() +{ } - diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..de63713 --- /dev/null +++ b/keywords.txt @@ -0,0 +1,32 @@ +######################################## +# Syntax Coloring Map +######################################## + +######################################## +# Datatypes (KEYWORD1) +######################################## + + + +######################################## +# Methods and Functions (KEYWORD2) +######################################## + +ATS_begin KEYWORD2 +ATS_end KEYWORD2 +ATS_PrintTestStatus KEYWORD2 +ATS_Test_DigitalPin KEYWORD2 +ATS_Test_PWM_Pin KEYWORD2 +ATS_Test_AnalogInput KEYWORD2 +ATS_Test_EEPROM KEYWORD2 +ATS_TestSerialLoopback KEYWORD2 +ATS_GetFreeMemory KEYWORD2 +ATS_GetMaximumMemoryAllocated KEYWORD2 + +######################################## +# Constants (LITERAL1) +######################################## + +PASSED LITERAL1 +FAILED LITERAL1 + diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..ffea5e9 --- /dev/null +++ b/library.properties @@ -0,0 +1,10 @@ +name=Tests +version=1.1.0 +author=Mark Sproul, Rick Anderson +maintainer=David A. Mellis +sentence=Arduino Test Suit Library +paragraph=This library allows you to create standard test suite for the Arduino software. +category=Other +url=https://github.com/arduino/Tests +architectures=avr + diff --git a/ArduinoTestSuite.cpp b/src/ArduinoTestSuite.cpp similarity index 81% rename from ArduinoTestSuite.cpp rename to src/ArduinoTestSuite.cpp index 44e75da..fd8bcb5 100644 --- a/ArduinoTestSuite.cpp +++ b/src/ArduinoTestSuite.cpp @@ -23,11 +23,8 @@ #include #include - - #include "ArduinoTestSuite.h" - #include "avr_cpunames.h" #if defined(USART3_RX_vect) @@ -38,13 +35,10 @@ #define SERIAL_PORT_COUNT 1 #endif - - - //************************************************************************ enum { - ATS_Manufacturer = 1, + ATS_Manufacturer = 1, ATS_CPU, ATS_GCC_version, ATS_LIBC_version, @@ -56,40 +50,38 @@ enum }; unsigned long gTestStartTime; unsigned long gTestTotalElapsedTime; -short gTagIndent; -int gYotalErrors; -int gTestCount; - - - -prog_char gTextMsg_Manufacturer[] PROGMEM = "MANUFACTURER"; -prog_char gTextMsg_CPUname[] PROGMEM = "CPU-NAME"; -prog_char gTextMsg_GCC_VERSION[] PROGMEM = "GCC-Version"; -prog_char gTextMsg_AVR_LIBC[] PROGMEM = "AVR-LibC-Ver"; -prog_char gTextMsg_COMPILED_DATE[] PROGMEM = "Compiled-date"; -prog_char gTextMsg_TEST_SUITE_NAME[] PROGMEM = "Test-Suite-Name"; -prog_char gTextMsg_memoryUsage[] PROGMEM = "Free-memory"; -prog_char gTextMsg_dotdotdot[] PROGMEM = "... "; -prog_char gTextMsg_ok[] PROGMEM = "ok"; -prog_char gTextMsg_FAIL[] PROGMEM = "FAIL"; -prog_char gTextMsg_spaceEqual[] PROGMEM = " = "; -prog_char gTextMsg_info[] PROGMEM = "info."; -prog_char gTextMsg_dashLine[] PROGMEM = "--------------------------"; -prog_char gTextMsg_DigitalRW[] PROGMEM = "DigitalReadWrite_"; -prog_char gTextMsg_PWMoutput[] PROGMEM = "PWMoutput_"; -prog_char gTextMsg_AnalogInput[] PROGMEM = "AnalogInput_"; +short gTagIndent; +int gTotalErrors; +int gTestCount; + +const char gTextMsg_Manufacturer[] PROGMEM = "MANUFACTURER"; +const char gTextMsg_CPUname[] PROGMEM = "CPU-NAME"; +const char gTextMsg_GCC_VERSION[] PROGMEM = "GCC-Version"; +const char gTextMsg_AVR_LIBC[] PROGMEM = "AVR-LibC-Ver"; +const char gTextMsg_COMPILED_DATE[] PROGMEM = "Compiled-date"; +const char gTextMsg_TEST_SUITE_NAME[] PROGMEM = "Test-Suite-Name"; +const char gTextMsg_memoryUsage[] PROGMEM = "Free-memory"; +const char gTextMsg_dotdotdot[] PROGMEM = "... "; +const char gTextMsg_ok[] PROGMEM = "ok"; +const char gTextMsg_FAIL[] PROGMEM = "FAIL"; +const char gTextMsg_spaceEqual[] PROGMEM = " = "; +const char gTextMsg_info[] PROGMEM = "info."; +const char gTextMsg_dashLine[] PROGMEM = "--------------------------"; +const char gTextMsg_DigitalRW[] PROGMEM = "DigitalReadWrite_"; +const char gTextMsg_PWMoutput[] PROGMEM = "PWMoutput_"; +const char gTextMsg_AnalogInput[] PROGMEM = "AnalogInput_"; //************************************************************************ -void Serial_print_P(prog_char *flashMemStr) +void Serial_print_P(const char *flashMemStr) { -char theChar; -int ii; + char theChar; + int ii; - ii = 0; + ii = 0; #if (FLASHEND > 0x10000) - while (theChar = pgm_read_byte_far(flashMemStr + ii++)) + while (theChar = pgm_read_byte_far(flashMemStr + ii++)) #else - while (theChar = pgm_read_byte_near(flashMemStr + ii++)) + while (theChar = pgm_read_byte_near(flashMemStr + ii++)) #endif { Serial.print(theChar); @@ -97,7 +89,7 @@ int ii; } //************************************************************************ -void Serial_println_P(prog_char *flashMemStr) +void Serial_println_P(const char *flashMemStr) { Serial_print_P(flashMemStr); Serial.println(); @@ -105,93 +97,93 @@ void Serial_println_P(prog_char *flashMemStr) //************************************************************************ //* this is for internal use only, not made pubic to the API -static void ATS_PrintProperty( int propertyTagNum, - char *propertyName, - char *propertyValue) +static void ATS_PrintProperty(int propertyTagNum, const char *propertyName, const char *propertyValue) { -char lineBuffer[64]; + char lineBuffer[64]; strcpy_P(lineBuffer, gTextMsg_info); - switch(propertyTagNum) - { - case 0: - strcat(lineBuffer, propertyName); - break; - - case ATS_Manufacturer: - strcat_P(lineBuffer, gTextMsg_Manufacturer); - break; + switch(propertyTagNum) { + case 0: + strcat(lineBuffer, propertyName); + break; + + case ATS_Manufacturer: + strcat_P(lineBuffer, gTextMsg_Manufacturer); + break; - case ATS_CPU: - strcat_P(lineBuffer, gTextMsg_CPUname); - break; + case ATS_CPU: + strcat_P(lineBuffer, gTextMsg_CPUname); + break; - case ATS_GCC_version: - strcat_P(lineBuffer, gTextMsg_GCC_VERSION); - break; + case ATS_GCC_version: + strcat_P(lineBuffer, gTextMsg_GCC_VERSION); + break; - case ATS_LIBC_version: - strcat_P(lineBuffer, gTextMsg_AVR_LIBC); - break; + case ATS_LIBC_version: + strcat_P(lineBuffer, gTextMsg_AVR_LIBC); + break; - case ATS_CompiledDate: - strcat_P(lineBuffer, gTextMsg_COMPILED_DATE); - break; + case ATS_CompiledDate: + strcat_P(lineBuffer, gTextMsg_COMPILED_DATE); + break; - case ATS_TestSuiteName: - strcat_P(lineBuffer, gTextMsg_TEST_SUITE_NAME); - break; + case ATS_TestSuiteName: + strcat_P(lineBuffer, gTextMsg_TEST_SUITE_NAME); + break; - case ATS_FreeMemory: - strcat_P(lineBuffer, gTextMsg_memoryUsage); - break; + case ATS_FreeMemory: + strcat_P(lineBuffer, gTextMsg_memoryUsage); + break; } - while (strlen(lineBuffer) < 20) - { + while (strlen(lineBuffer) < 20) { strcat(lineBuffer, " "); } strcat_P(lineBuffer, gTextMsg_spaceEqual); - if (propertyValue != 0) - { + if (propertyValue != 0) { strcat(lineBuffer, propertyValue); } Serial.println(lineBuffer); - } - - - //************************************************************************ -void ATS_begin(char *manufName, char *testSuiteName) +void ATS_begin(const char *manufName, const char *testSuiteName, int baudRate) { -int freeMemory; -char memoryMsg[48]; + static bool serialInitialized = false; - gYotalErrors = 0; - gTestCount = 0; + int freeMemory; + char memoryMsg[48]; - Serial.begin(9600); - delay(100); - + if (!serialInitialized ){ + Serial.begin(baudRate); + while (!Serial) { + ; + // wait for serial port to connect. + // Needed for Leonardo only + } + delay(100); + serialInitialized = true; + } + + gTotalErrors = 0; + gTestCount = 0; gTestTotalElapsedTime = 0; Serial.println(); Serial.println(); Serial.println(); - ATS_PrintProperty(ATS_Manufacturer, 0, manufName); - ATS_PrintProperty(ATS_CPU, 0, _AVR_CPU_NAME_); - ATS_PrintProperty(ATS_GCC_version, 0, __VERSION__); - ATS_PrintProperty(ATS_LIBC_version, 0, __AVR_LIBC_VERSION_STRING__); - ATS_PrintProperty(ATS_CompiledDate, 0, __DATE__); - ATS_PrintProperty(ATS_TestSuiteName, 0, testSuiteName); + ATS_PrintProperty(ATS_Manufacturer, 0, manufName); + ATS_PrintProperty(ATS_CPU, 0, _AVR_CPU_NAME_); + ATS_PrintProperty(ATS_GCC_version, 0, __VERSION__); + ATS_PrintProperty(ATS_LIBC_version, 0, __AVR_LIBC_VERSION_STRING__); + ATS_PrintProperty(ATS_CompiledDate, 0, __DATE__); + ATS_PrintProperty(ATS_TestSuiteName, 0, testSuiteName); - freeMemory = ATS_GetFreeMemory(); + freeMemory = ATS_GetFreeMemory(); sprintf(memoryMsg, "%d bytes", freeMemory); - ATS_PrintProperty(ATS_FreeMemory, 0, memoryMsg); + ATS_PrintProperty(ATS_FreeMemory, 0, memoryMsg); randomSeed(analogRead(0)); @@ -201,9 +193,9 @@ char memoryMsg[48]; //************************************************************************ void ATS_end() { -unsigned long seconds; -unsigned long microSecs; -char buf[8]; + unsigned long seconds; + unsigned long microSecs; + char buf[8]; gTestTotalElapsedTime += (micros() - gTestStartTime); @@ -231,14 +223,14 @@ char buf[8]; } Serial.println(); - if (gYotalErrors == 0) + if (gTotalErrors == 0) { Serial.print("OK"); } else { Serial.print("FAILED (failures="); - Serial.print(gYotalErrors); + Serial.print(gTotalErrors); Serial.print(")"); } Serial.println(); @@ -250,7 +242,7 @@ char buf[8]; //************************************************************************ -void ATS_PrintTestStatus(char *testString, boolean passed) +void ATS_PrintTestStatus(const char *testString, boolean passed) { int sLen; @@ -272,7 +264,7 @@ int sLen; else { Serial_print_P(gTextMsg_FAIL); - gYotalErrors++; + gTotalErrors++; } Serial.println(); @@ -376,7 +368,6 @@ int ATS_TestTimer( uint8_t timerPinNumber, char *errorString) { boolean passedOK; -unsigned long loopCounter; unsigned long lowCount; unsigned long highCount; unsigned long startTime; @@ -387,7 +378,6 @@ char numString[48]; int pwmValue; pwmValue = 128; - loopCounter = 0; lowCount = 0; highCount = 0; passedOK = true; @@ -576,7 +566,7 @@ uint8_t helperpin; #if (SERIAL_PORT_COUNT > 1) //************************************************************************ //* retunrs 0 if no errors, 1 if an error occured -short ATS_TestSerialLoopback(HardwareSerial *theSerialPort, char *serialPortName) +short ATS_TestSerialLoopback(HardwareSerial *theSerialPort, const char *serialPortName) { char xmitChar; char rcvChar; diff --git a/ArduinoTestSuite.h b/src/ArduinoTestSuite.h similarity index 51% rename from ArduinoTestSuite.h rename to src/ArduinoTestSuite.h index f2f00ca..8b04f34 100644 --- a/ArduinoTestSuite.h +++ b/src/ArduinoTestSuite.h @@ -2,6 +2,9 @@ //************************************************************************ //* Aug 31, 2010 Started on TestArduino //************************************************************************ +#ifndef ARDUINO_TEST_SUITE_H_INCLUDED +#define ARDUINO_TEST_SUITE_H_INCLUDED + #if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" @@ -11,7 +14,6 @@ #include "pins_arduino.h" #endif - #if defined(USART3_RX_vect) #define SERIAL_PORT_COUNT 4 #elif defined(USART1_RX_vect) @@ -20,21 +22,27 @@ #define SERIAL_PORT_COUNT 1 #endif +void ATS_begin(const char *manufName, const char *testSuiteName, int baudRate=9600); +void ATS_end(); -void ATS_begin(char *manufName, char *testSuiteName); -void ATS_end(); - -void ATS_PrintTestStatus(char *testString, boolean passed); +void ATS_PrintTestStatus(const char *testString, boolean passed); boolean ATS_Test_DigitalPin(uint8_t digitalPinToTest); boolean ATS_Test_PWM_Pin(uint8_t digitalPinToTest); boolean ATS_Test_AnalogInput(uint8_t analogPintoTest); boolean ATS_Test_EEPROM(void); -short ATS_TestSerialLoopback(HardwareSerial *theSerialPort, char *serialPortName); +#define ATS_Assert(c) { \ + /* maybe use much memory... */ \ + String name = String(__FILE__) + "(" + String(__LINE__) + ")"; \ + byte str[name.length() + 1]; \ + name.getBytes(str, name.length() + 1); \ + ATS_PrintTestStatus( (char *)str, c ); \ + } +short ATS_TestSerialLoopback(HardwareSerial *theSerialPort, const char *serialPortName); -int ATS_GetFreeMemory(); -int ATS_GetMaximumMemoryAllocated(); +int ATS_GetFreeMemory(); +int ATS_GetMaximumMemoryAllocated(); //************************************************************************ @@ -42,33 +50,27 @@ int ATS_GetMaximumMemoryAllocated(); inline void ATS_ReportMemoryUsage(int _memoryUsageAtStart) __attribute__((always_inline, unused)); inline void ATS_ReportMemoryUsage(int _memoryUsageAtStart) { -int freeMemoryAtEnd; -int lostMemory; -boolean memoryOK; -char memoryUsage[48]; - - freeMemoryAtEnd = ATS_GetFreeMemory(); - lostMemory = _memoryUsageAtStart - freeMemoryAtEnd; - if (lostMemory == 0) - { + int freeMemoryAtEnd; + int lostMemory; + boolean memoryOK; + char memoryUsage[48]; + + freeMemoryAtEnd = ATS_GetFreeMemory(); + lostMemory = _memoryUsageAtStart - freeMemoryAtEnd; + memoryOK = lostMemory == 0; + if (memoryOK) { strcpy(memoryUsage, "Memory Usage"); - memoryOK = true; - } - else - { + } else { sprintf(memoryUsage, "Memory Usage (lost %d bytes)", lostMemory); - memoryOK = false; } ATS_PrintTestStatus(memoryUsage, memoryOK); } +extern unsigned long gTestStartTime; +extern int gTotalErrors; +extern int gTestCount; +#define PASSED true +#define FAILED false -extern unsigned long gTestStartTime; -extern int gYotalErrors; -extern int gTestCount; - - -#define PASSED true -#define FAILED false - +#endif diff --git a/avr_cpunames.h b/src/avr_cpunames.h similarity index 100% rename from avr_cpunames.h rename to src/avr_cpunames.h