123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include "tests/StringBufferTests.h"
- #include "tests/Test.h"
- #include "utils/StringBuffer.h"
- typedef StringBuffer<20> String;
- static void testEquality(Test& test) {
- String s("test");
- test.checkEqual(true, s == "test", "equality with c-string");
- test.checkEqual(true, s == String("test"), "equality with another string");
- test.checkEqual(true, "test" == s, "inverse equality with c-string");
- test.checkEqual(true, String("test") == s, "inverse equality with another string");
- test.checkEqual(true, s == s, "equality with itself");
- }
- static void testInequality(Test& test) {
- String s("test");
- test.checkEqual(false, s != "test", "inequality with c-string");
- test.checkEqual(false, s != String("test"), "inequality with another string");
- test.checkEqual(false, "test" != s, "inverse inequality with c-string");
- test.checkEqual(false, String("test") != s, "inverse inequality with another string");
- test.checkEqual(false, s != s, "inequality with itself");
- }
- static void testStringAppend(Test& test) {
- String s("test");
- s.append("22").append("333").append("4444");
- test.checkEqual(String("test223334444"), s, "multiple appends");
- }
- static void testStringAppendOverflow(Test& test) {
- StringBuffer<5> s("te");
- s.append("2").append("333").append("4444");
- test.checkEqual(StringBuffer<5>("te23"), s, "multiple appends with overflow");
- test.checkEqual(4, s.getLength(), "length after multiple appends with overflow");
- }
- static void testCharacters(Test& test) {
- String s("test");
- test.checkEqual('t', s[0], "character read 1");
- test.checkEqual('e', s[1], "character read 2");
- test.checkEqual('s', s[2], "character read 3");
- test.checkEqual('t', s[3], "character read 4");
- }
- static void testLength(Test& test) {
- String s("test");
- test.checkEqual(4, s.getLength(), "length 1");
- s.append("aaa");
- test.checkEqual(7, s.getLength(), "length 2");
- }
- static void testInt(Test& test) {
- String s("test");
- s.append(524).append(-37);
- test.checkEqual(String("test524-37"), s, "int append");
- }
- static void testOverflowConstructor(Test& test) {
- StringBuffer<5> s("12345678");
- test.checkEqual(StringBuffer<5>("1234"), s, "overflow constructor");
- test.checkEqual(4, s.getLength(), "length after overflow constructor");
- }
- static void testIntOverflow(Test& test) {
- StringBuffer<5> s("te");
- s.append(123456);
- test.checkEqual(StringBuffer<5>("te12"), s, "int append with overflow");
- test.checkEqual(4, s.getLength(), "length after int append with overflow");
- }
- static void testFloat(Test& test) {
- String s("test");
- s.append(5.2378f).append(-500.4321f);
- test.checkEqual(String("test5.24-500.43"), s, "float append");
- }
- static void testBool(Test& test) {
- String s("test");
- s.append(true).append(false).append(true);
- test.checkEqual(String("testtruefalsetrue"), s, "bool append");
- }
- static void testClear(Test& test) {
- String s("test");
- s.append(1234).clear().append("wusi").append("1234");
- test.checkEqual(String("wusi1234"), s, "clear");
- }
- void StringBufferTests::test() {
- Test test("StringBuffer");
- testEquality(test);
- testInequality(test);
- testStringAppend(test);
- testStringAppendOverflow(test);
- testCharacters(test);
- testLength(test);
- testInt(test);
- testOverflowConstructor(test);
- testIntOverflow(test);
- testFloat(test);
- testBool(test);
- testClear(test);
- test.finalize();
- }
|