1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 06:15:32 +00:00

Added tools/tests/

This commit is contained in:
Nicolay Korslund 2010-01-04 19:16:40 +01:00
parent f526cc640b
commit abde68fed6
8 changed files with 97 additions and 2 deletions

View file

@ -33,9 +33,20 @@ struct SliceArray
const T* ptr;
size_t length;
/// Initialize to zero length
SliceArray() : ptr(0), length(0) {}
/// Initialize from pointer + length
SliceArray(const T* _ptr, size_t _length)
: ptr(_ptr), length(_length) {}
/// Initialize from null-terminated string
SliceArray(const char* str)
{
ptr = str;
length = strlen(str);
}
bool operator==(SliceArray &t)
{
return
@ -52,8 +63,7 @@ struct SliceArray
}
/** This allocates a copy of the data. Only use this for debugging
and error messages.
*/
and error messages. */
std::string toString()
{ return std::string(ptr,length); }
};

1
tools/tests/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*_test

12
tools/tests/Makefile Normal file
View file

@ -0,0 +1,12 @@
GCC=g++
all: strops_test slice_test
slice_test: slice_test.cpp ../slice_array.h
$(GCC) $< -o $@
strops_test: strops_test.cpp ../stringops.h ../stringops.cpp
$(GCC) $< -o $@ ../stringops.cpp
clean:
rm *_test

View file

@ -0,0 +1,6 @@
hello, len=5
001
hell, len=4
010
01
4 3

View file

View file

@ -0,0 +1,30 @@
#include <iostream>
using namespace std;
#include <assert.h>
#include "../slice_array.h"
int main()
{
SString s, t;
s = SString("hello");
cout << s.toString() << ", len=" << s.length << endl;
cout << (s=="hel") << (s=="hell") << (s=="hello") << endl;
t = s;
s = SString("othello"+2, 4);
cout << s.toString() << ", len=" << s.length << endl;
cout << (s=="hel") << (s=="hell") << (s=="hello") << endl;
cout << (s==t) << (SString("hello")==t) << endl;
const int arr[4] = {1,2,3,4};
IntArray ia(arr,4);
cout << ia.length << " " << ia.ptr[2] << endl;
return 0;
}

View file

@ -0,0 +1,18 @@
#include <assert.h>
#include "../stringops.h"
int main()
{
assert(begins("abc", "a"));
assert(begins("abc", "ab"));
assert(begins("abc", "abc"));
assert(begins("abcd", "abc"));
assert(!begins("abc", "b"));
assert(!begins("abc", "bc"));
assert(!begins("abc", "bcd"));
assert(!begins("abc", "abcd"));
return 0;
}

18
tools/tests/test.sh Executable file
View file

@ -0,0 +1,18 @@
#!/bin/bash
make || exit
mkdir -p output
PROGS=*_test
for a in $PROGS; do
if [ -f "output/$a.out" ]; then
echo "Running $a:"
$a | diff output/$a.out -
else
echo "Creating $a.out"
$a > "output/$a.out"
git add "output/$a.out"
fi
done