Browse Source

Shelving broken things to break other things

local_cpptest
Krista Bennett 4 years ago
parent
commit
3575a9f8d5
6 changed files with 53 additions and 66 deletions
  1. +4
    -0
      .hgignore
  2. +0
    -30
      test/_test_template_cc
  3. +8
    -7
      test/include/EngineTestSuite.h
  4. +8
    -27
      test/src/EngineTestSuite.cc
  5. +31
    -0
      test/src/TestDriver.cc
  6. +2
    -2
      test/src/engine_tests/DecorateTests.cc

+ 4
- 0
.hgignore View File

@ -63,3 +63,7 @@ __pycache__
test/python_tests/test?
test/pEp_test_home
test/TestDriver
test/local
.tags
*/.tags
*/*/.tags

+ 0
- 30
test/_test_template_cc View File

@ -1,30 +0,0 @@
// This file is under GNU General Public License 3.0
// see LICENSE.txt
#include <iostream>
#include <string>
#include <assert.h>
#include "pEpEngine_test.h"
#include "MODULE.h"
using namespace std;
int main() {
cout << "\n*** MODULE_test ***\n\n";
PEP_SESSION session;
cout << "calling init()\n";
PEP_STATUS status1 = init(&session);
ASSERT_STATUS(status1);
assert(session);
cout << "init() completed.\n";
// MODULE test code
cout << "calling release()\n";
release(session);
return 0;
}

+ 8
- 7
test/include/EngineTestSuite.h View File

@ -2,9 +2,8 @@
#define ENGINE_TEST_SUITE_H
#include <cpptest.h>
#include <cpptest-suite.h>
#include <cpptest-textoutput.h>
#include <string>
#include <vector>
#include "pEpEngine.h"
using namespace std;
@ -14,22 +13,24 @@ class EngineTestSuite : public Test::Suite {
EngineTestSuite(string suitename, string test_home_dir);
virtual ~EngineTestSuite();
void add_test_to_suite(void (*test)()); // We do this so we can count
protected:
PEP_SESSION session;
string test_home;
string prev_gpg_home;
string name;
string current_test_name;
unsigned int number_of_tests;
unsigned int on_test_number;
virtual void setup();
virtual void tear_down();
void set_full_env();
void restore_full_env();
void initialise_test_home();
private:
static int util_delete_filepath(const char *filepath,
const struct stat *file_stat,
int ftw_info,
struct FTW * ftw_struct);
};
#endif

+ 8
- 27
test/src/EngineTestSuite.cc View File

@ -15,17 +15,18 @@ EngineTestSuite::EngineTestSuite(string suitename, string test_home_dir) {
char* tmp = getenv("GNUPGHOME");
if (tmp)
prev_gpg_home = getenv("GNUPGHOME");
struct stat buf;
if (stat(test_home.c_str(), &buf) == 0) {
cout << test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
int success = nftw((test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
}
number_of_tests = 0;
on_test_number = 0;
}
EngineTestSuite::~EngineTestSuite() {}
void EngineTestSuite::add_test_to_suite(Test::Suite::Func test) {
TEST_ADD(test);
number_of_tests++;
}
void EngineTestSuite::set_full_env() {
if (test_home.empty())
@ -75,25 +76,5 @@ void EngineTestSuite::restore_full_env() {
throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
}
int EngineTestSuite::util_delete_filepath(const char *filepath,
const struct stat *file_stat,
int ftw_info,
struct FTW * ftw_struct) {
int retval = 0;
switch (ftw_info) {
case FTW_DP:
retval = rmdir(filepath);
break;
case FTW_F:
case FTW_SLN:
retval = unlink(filepath);
break;
default:
retval = -1;
}
return retval;
}
void EngineTestSuite::setup() {}
void EngineTestSuite::tear_down() {}

+ 31
- 0
test/src/TestDriver.cc View File

@ -6,6 +6,9 @@
#include <vector>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <ftw.h>
#include "EngineTestSuite.h"
#include "EngineTestIndividualSuite.h"
#include "EngineTestSessionSuite.h"
@ -19,6 +22,27 @@ void usage() {
throw std::runtime_error("Bad usage. Fix me, you loser developer.");
}
int util_delete_filepath(const char *filepath,
const struct stat *file_stat,
int ftw_info,
struct FTW * ftw_struct) {
int retval = 0;
switch (ftw_info) {
case FTW_DP:
retval = rmdir(filepath);
break;
case FTW_F:
case FTW_SLN:
retval = unlink(filepath);
break;
default:
retval = -1;
}
return retval;
}
int main(int argc, const char** argv) {
const int MIN_ARGC = 1;
if (argc < MIN_ARGC)
@ -28,6 +52,13 @@ int main(int argc, const char** argv) {
if (stat(common_test_home.c_str(), &dirchk) == 0) {
if (!S_ISDIR(dirchk.st_mode))
throw std::runtime_error(("The test directory, " + common_test_home + "exists, but is not a directory.").c_str());
struct stat buf;
if (stat(common_test_home.c_str(), &buf) == 0) {
cout << common_test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
int success = nftw((common_test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
}
}
else {
int errchk = mkdir(common_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);


+ 2
- 2
test/src/engine_tests/DecorateTests.cc View File

@ -22,8 +22,8 @@
using namespace std;
DecorateTests::DecorateTests(string suitename, string test_home_dir) :
EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
TEST_ADD(DecorateTests::check_decorate);
EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
add_test_to_suite(check_decorate);
}
void DecorateTests::check_decorate() {


Loading…
Cancel
Save