Files
StreamDevice/streamApp/tests/testStreamBuffer

76 lines
2.0 KiB
Plaintext
Executable File

rm -f test.*
cat > test.cc << EOF
#include <StreamError.h>
#include <StreamBuffer.h>
#include <assert.h>
#include <stdio.h>
int main () {
StreamBuffer haystack = "12345abc123xyz123";
StreamBuffer needle = "1n4m6p7q";
needle.remove(2,4);
assert (needle.startswith("1n7q"));
needle.append("2x3y");
assert (needle.startswith("1n7q2x3y"));
needle.remove(4);
assert (needle.startswith("2x3y"));
needle.remove(1,1);
assert (needle.startswith("23y"));
needle.truncate(-1);
assert (needle.startswith("23"));
assert (haystack.find(needle) == 1);
assert (haystack.find(needle, 2) == 9);
assert (haystack.find(needle, -5) == 15);
assert (haystack.find("23", -5) == 15);
assert (haystack.find((char*)NULL, 10) == 10);
assert (haystack.find(needle, -1) == -1);
assert (haystack.find(needle, 100) == -1);
assert (haystack.find(needle, 0) == 1);
assert (haystack.find(needle, -100) == 1);
haystack.set("12345xy67890xy");
needle.set("xy");
assert (haystack.find(needle) == 5);
needle.set("x");
assert (haystack.find(needle) == 5);
haystack.set("12345\n67890\n");
needle.set("\n");
assert (haystack.find(needle) == 5);
haystack.set("12341234567890\n");
needle.set("2345");
assert (haystack.find(needle) == 5);
needle="7890";
assert (haystack.find(needle) == 10);
needle.append('\0');
assert (haystack.find(needle) == -1);
haystack.clear();
assert (haystack.find(needle) == -1);
haystack.set("deadbeef");
needle.clear();
assert (haystack.find(needle) == 0);
haystack.clear();
assert (haystack.find(needle) == 0);
haystack.reserve(10000);
return 0;
}
EOF
if [ "$1" = "-sls" ]
then
O=../../O.*_$EPICS_HOST_ARCH
else
O=../../src/O.$EPICS_HOST_ARCH
fi
for o in $O
do
g++ -I ../../src $o/StreamBuffer.o $o/StreamError.o test.cc -o test.exe
./test.exe
if [ $? != 0 ]
then
echo -e "\033[31;7mTest failed.\033[0m"
exit 1
fi
done
rm test.*
echo -e "\033[32mTest passed.\033[0m"