Browse Source

One step closer. Converted first test (not really converted, just shoved into framework)

local_cpptest
Krista Bennett 4 years ago
parent
commit
0523aa3da3
8 changed files with 158 additions and 30 deletions
  1. +17
    -30
      test/DecorateTests.cc
  2. +21
    -0
      test/DecorateTests.h
  3. +3
    -0
      test/EngineTestIndividualSuite.h
  4. +3
    -0
      test/EngineTestSuite.cc
  5. +16
    -0
      test/SuiteMaker.cc
  6. +16
    -0
      test/SuiteMaker.h
  7. +71
    -0
      test/TestDriver.cc
  8. +11
    -0
      test/TestDriver.h

test/decorate_test.cc → test/DecorateTests.cc View File


+ 21
- 0
test/DecorateTests.h View File

@ -0,0 +1,21 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include <stdlib.h>
#include <string.h>
#include "platform.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include "mime.h"
#include "message_api.h"
#include "test_util.h"
using namespace std;
class DecorateTests : public EngineTestSessionSuite {
public:
DecorateTests(string suitename, string test_home_dir);
private:
void check_decorate();
};

+ 3
- 0
test/EngineTestIndividualSuite.h View File

@ -11,5 +11,8 @@ class EngineTestIndividualSuite : public EngineTestSuite {
public:
EngineIndividualTestSuite(string suitename, string test_home_dir);
~EngineIndividualTestSuite();
protected:
virtual void setup();
virtual void tear_down();
};
#endif

+ 3
- 0
test/EngineTestSuite.cc View File

@ -89,3 +89,6 @@ int EngineTestSuite::util_delete_filepath(const char *filepath,
return retval;
}
void EngineTestSuite::setup() {}
void EngineTestSuite::tear_down() {}

+ 16
- 0
test/SuiteMaker.cc View File

@ -0,0 +1,16 @@
#include <cpptest-suite.h>
#include <string>
#include <sys/stat.h>
#include <errno.h>
#include "EngineTestSuite.h"
#include "EngineTestIndividualSuite.h"
#include "EngineTestSessionSuite.h"
// Begin where we should generate stuff
#include "DecorateTests.h"
static EngineTestSuite* build(const char* test_class_name, const char* test_home) {
if (strcmp(test_class_name, "DecorateTests") == 0)
return new DecorateTests(test_class_name, test_home);
return NULL;
}

+ 16
- 0
test/SuiteMaker.h View File

@ -0,0 +1,16 @@
#include <cpptest-suite.h>
#include <string>
#include <sys/stat.h>
#include <errno.h>
#include "EngineTestSuite.h"
#include "EngineTestIndividualSuite.h"
#include "EngineTestSessionSuite.h"
// Begin where we should generate stuff
#include "DecorateTests.h"
class SuiteMaker {
public:
static EngineTestSuite* build(const char* test_class_name,
const char* test_home);
};

+ 71
- 0
test/TestDriver.cc View File

@ -0,0 +1,71 @@
#include <cpptest-suite.h>
#include <string>
#include <sys/stat.h>
#include <errno.h>
#include "EngineTestSuite.h"
#include "EngineTestIndividualSuite.h"
#include "EngineTestSessionSuite.h"
using namespace std;
string common_test_home = "~/pEp_tests";
void usage() {
throw "Bad usage. Fix me, you loser developer.";
}
EngineTestSuite*
int main(int argc, char** argv) {
const int MIN_ARGC = 1;
if (argc < MIN_ARGC)
usage();
int start_index = 1;
if (argc > 1) {
string tmpstr = argv[1];
if (tmpstr.compare(0,10,"--testdir=")) {
try {
tmpstr = tmpstr.substr(10);
}
catch (std::out_of_range o) {
usage();
}
common_test_home = tmpstr;
start_index++;
}
}
struct stat dirchk;
if (stat(common_test_home.c_str(), &dirchk) == 0) {
if (!S_ISDIR(dirchk.st_mode))
throw ("The test directory, " + common_test_home + "exists, but is not a directory.").c_str();
}
else if (common_test_home.compare("~/pEp_tests")) {
int errchk = mkdir(common_test_home);
if (errchk != 0)
throw "Error creating a test directory.";
}
else
throw "Test directory does not exist. Test directories from the command line must be created first. Because we're lazy.";
EngineTestSuite* test_runner = new EngineTestSuite("MainTestDriver", test_home);
for (int i = start_index; i < argc; i++) {
char* curr_arg = argv[i];
EngineTestSuite* test_suite = SuiteMaker.build(argv[i], common_test_home);
if (!test_suite)
throw "Could not create a test suite instance."; // FIXME, better error, cleanup, obviously
test_runner.add(test_suite);
test_suite = NULL;
}
Test::TextOutput output(Test::TextOutput::Terse);
return test_runner.run(output) ? 1 : 0;
}

+ 11
- 0
test/TestDriver.h View File

@ -0,0 +1,11 @@
#include <cpptest-suite.h>
#include <string>
#include <map>
#include "EngineTestSuite.h"
#include "EngineTestIndividualSuite.h"
#include "EngineTestSessionSuite.h"
using namespace std;
typedef map<string, EngineTestSuite> SuiteMap;
typedef set<string> NameSet;

Loading…
Cancel
Save