added tests

This commit is contained in:
Gerald Schmidt 2018-09-24 20:30:11 +02:00
parent 5d2249ad3d
commit 37a19f1ebb
10 changed files with 11672 additions and 0 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
*.bz2
xmlcopyeditor
xmlcopyeditor.exe
*.o
tests-main

10
tests/Makefile Normal file
View File

@ -0,0 +1,10 @@
build:
g++ -o tests-main \
*.cpp \
../src/replace.cpp \
../src/readfile.cpp
run:
./tests-main
all: build run
clean:
rm *.o tests-main

11605
tests/catch.hpp Normal file

File diff suppressed because it is too large Load Diff

BIN
tests/tests Executable file

Binary file not shown.

2
tests/tests-main.cpp Normal file
View File

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

BIN
tests/tests-main.o Normal file

Binary file not shown.

15
tests/tests-readfile.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "catch.hpp"
#include <string>
#include "../src/readfile.h"
TEST_CASE( "readfile works as specified", "[readfile]" ) {
std::string valid_path = "catch.hpp", invalid_path = "invalid.hpp";
std::string buf;
REQUIRE( ReadFile::run(valid_path, buf) == true );
REQUIRE( buf.at(0) == '/' );
buf.clear();
REQUIRE( ReadFile::run(invalid_path, buf) == false );
REQUIRE( buf.length() == 0 );
}

19
tests/tests-replace.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "catch.hpp"
#include <string>
#include "../src/replace.h"
TEST_CASE( "replace works as specified", "[replace]" ) {
std::string orig = "when shall we three meet again";
std::string find = "THREE";
std::string replace = "four";
// case insensitive
std::string buf = orig;
REQUIRE( Replace::run(buf, find, replace, false) == 1 );
REQUIRE( buf == "when shall we four meet again" );
// case sensitive
buf = orig;
REQUIRE( Replace::run(buf, find, replace, true) == 0 );
REQUIRE( buf == "when shall we three meet again" );
}

19
tests/tests-stringset.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "catch.hpp"
#include <string>
#include <memory>
#include "../src/stringset.h"
TEST_CASE( "stringset works as specified", "[stringset]" ) {
std::string buf = "test";
std::auto_ptr<StringSet<char> > dict ( new StringSet<char>() );
REQUIRE( dict->find(buf) == 0 );
REQUIRE( dict->empty() == true );
REQUIRE( dict->count() == 0 );
dict->insert(buf);
REQUIRE( dict->find(buf) != 0 );
REQUIRE( dict->empty() == false);
REQUIRE( dict->count() == 1);
}

BIN
tests/tests-stringset.o Normal file

Binary file not shown.