Shelving broken things to break other things local_cpptest
authorKrista Bennett <krista@pep-project.org>
Fri, 04 May 2018 16:30:21 +0200
branchlocal_cpptest
changeset 265243b913f99a27
parent 2651 b05ebb3c2a8d
child 2653 232367954cc5
Shelving broken things to break other things
.hgignore
test/_test_template_cc
test/include/EngineTestSuite.h
test/src/EngineTestSuite.cc
test/src/TestDriver.cc
test/src/engine_tests/DecorateTests.cc
     1.1 --- a/.hgignore	Thu May 03 16:53:26 2018 +0200
     1.2 +++ b/.hgignore	Fri May 04 16:30:21 2018 +0200
     1.3 @@ -63,3 +63,7 @@
     1.4  test/python_tests/test?
     1.5  test/pEp_test_home
     1.6  test/TestDriver
     1.7 +test/local
     1.8 +.tags
     1.9 +*/.tags
    1.10 +*/*/.tags
     2.1 --- a/test/_test_template_cc	Thu May 03 16:53:26 2018 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,30 +0,0 @@
     2.4 -// This file is under GNU General Public License 3.0
     2.5 -// see LICENSE.txt
     2.6 -
     2.7 -#include <iostream>
     2.8 -#include <string>
     2.9 -#include <assert.h>
    2.10 -#include "pEpEngine_test.h"
    2.11 -#include "MODULE.h"
    2.12 -
    2.13 -using namespace std;
    2.14 -
    2.15 -int main() {
    2.16 -    cout << "\n*** MODULE_test ***\n\n";
    2.17 -
    2.18 -    PEP_SESSION session;
    2.19 -    
    2.20 -    cout << "calling init()\n";
    2.21 -    PEP_STATUS status1 = init(&session);   
    2.22 -    ASSERT_STATUS(status1);
    2.23 -    assert(session);
    2.24 -    cout << "init() completed.\n";
    2.25 -
    2.26 -    // MODULE test code
    2.27 -
    2.28 -
    2.29 -    cout << "calling release()\n";
    2.30 -    release(session);
    2.31 -    return 0;
    2.32 -}
    2.33 -
     3.1 --- a/test/include/EngineTestSuite.h	Thu May 03 16:53:26 2018 +0200
     3.2 +++ b/test/include/EngineTestSuite.h	Fri May 04 16:30:21 2018 +0200
     3.3 @@ -2,9 +2,8 @@
     3.4  #define ENGINE_TEST_SUITE_H
     3.5  
     3.6  #include <cpptest.h>
     3.7 -#include <cpptest-suite.h>
     3.8 -#include <cpptest-textoutput.h>
     3.9  #include <string>
    3.10 +#include <vector>
    3.11  #include "pEpEngine.h"
    3.12  
    3.13  using namespace std;
    3.14 @@ -14,22 +13,24 @@
    3.15          EngineTestSuite(string suitename, string test_home_dir);
    3.16          virtual ~EngineTestSuite();
    3.17          
    3.18 +        void add_test_to_suite(void (*test)()); // We do this so we can count
    3.19 +                
    3.20      protected:
    3.21          PEP_SESSION session;
    3.22          string test_home;
    3.23          string prev_gpg_home;
    3.24          string name;
    3.25          
    3.26 +        string current_test_name;
    3.27 +        
    3.28 +        unsigned int number_of_tests;
    3.29 +        unsigned int on_test_number;
    3.30 +        
    3.31          virtual void setup();
    3.32          virtual void tear_down();
    3.33          void set_full_env();
    3.34          void restore_full_env();
    3.35          void initialise_test_home();
    3.36          
    3.37 -    private:
    3.38 -        static int util_delete_filepath(const char *filepath, 
    3.39 -                                        const struct stat *file_stat, 
    3.40 -                                        int ftw_info, 
    3.41 -                                        struct FTW * ftw_struct);
    3.42  };
    3.43  #endif
     4.1 --- a/test/src/EngineTestSuite.cc	Thu May 03 16:53:26 2018 +0200
     4.2 +++ b/test/src/EngineTestSuite.cc	Fri May 04 16:30:21 2018 +0200
     4.3 @@ -15,17 +15,18 @@
     4.4      char* tmp = getenv("GNUPGHOME");
     4.5      if (tmp)
     4.6          prev_gpg_home = getenv("GNUPGHOME");
     4.7 -    
     4.8 -    struct stat buf;
     4.9 -    
    4.10 -    if (stat(test_home.c_str(), &buf) == 0) {
    4.11 -        cout << test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
    4.12 -        int success = nftw((test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
    4.13 -    }
    4.14 +        
    4.15 +    number_of_tests = 0;
    4.16 +    on_test_number = 0;
    4.17  }
    4.18  
    4.19  EngineTestSuite::~EngineTestSuite() {}
    4.20  
    4.21 +void EngineTestSuite::add_test_to_suite(Test::Suite::Func test) {
    4.22 +    TEST_ADD(test);
    4.23 +    number_of_tests++;
    4.24 +}
    4.25 +
    4.26  void EngineTestSuite::set_full_env() {
    4.27  
    4.28      if (test_home.empty())
    4.29 @@ -75,25 +76,5 @@
    4.30          throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
    4.31  }
    4.32  
    4.33 -int EngineTestSuite::util_delete_filepath(const char *filepath, 
    4.34 -                                     const struct stat *file_stat, 
    4.35 -                                     int ftw_info, 
    4.36 -                                     struct FTW * ftw_struct) {
    4.37 -    int retval = 0;
    4.38 -    switch (ftw_info) {
    4.39 -        case FTW_DP:
    4.40 -            retval = rmdir(filepath);
    4.41 -            break;
    4.42 -        case FTW_F:
    4.43 -        case FTW_SLN:
    4.44 -            retval = unlink(filepath);
    4.45 -            break;    
    4.46 -        default:
    4.47 -            retval = -1;
    4.48 -    }
    4.49 -    
    4.50 -    return retval;
    4.51 -}
    4.52 -
    4.53  void EngineTestSuite::setup() {}
    4.54  void EngineTestSuite::tear_down() {}
     5.1 --- a/test/src/TestDriver.cc	Thu May 03 16:53:26 2018 +0200
     5.2 +++ b/test/src/TestDriver.cc	Fri May 04 16:30:21 2018 +0200
     5.3 @@ -6,6 +6,9 @@
     5.4  #include <vector>
     5.5  #include <sys/stat.h>
     5.6  #include <errno.h>
     5.7 +#include <stdlib.h>
     5.8 +#include <unistd.h>
     5.9 +#include <ftw.h>
    5.10  #include "EngineTestSuite.h"
    5.11  #include "EngineTestIndividualSuite.h"
    5.12  #include "EngineTestSessionSuite.h"
    5.13 @@ -19,6 +22,27 @@
    5.14      throw std::runtime_error("Bad usage. Fix me, you loser developer.");
    5.15  }
    5.16  
    5.17 +int util_delete_filepath(const char *filepath, 
    5.18 +                         const struct stat *file_stat, 
    5.19 +                         int ftw_info, 
    5.20 +                         struct FTW * ftw_struct) {
    5.21 +    int retval = 0;
    5.22 +    switch (ftw_info) {
    5.23 +        case FTW_DP:
    5.24 +            retval = rmdir(filepath);
    5.25 +            break;
    5.26 +        case FTW_F:
    5.27 +        case FTW_SLN:
    5.28 +            retval = unlink(filepath);
    5.29 +            break;    
    5.30 +        default:
    5.31 +            retval = -1;
    5.32 +    }
    5.33 +    
    5.34 +    return retval;
    5.35 +}
    5.36 +
    5.37 +
    5.38  int main(int argc, const char** argv) {
    5.39      const int MIN_ARGC = 1;
    5.40      if (argc < MIN_ARGC)
    5.41 @@ -28,6 +52,13 @@
    5.42      if (stat(common_test_home.c_str(), &dirchk) == 0) {
    5.43          if (!S_ISDIR(dirchk.st_mode))
    5.44              throw std::runtime_error(("The test directory, " + common_test_home + "exists, but is not a directory.").c_str()); 
    5.45 +                    
    5.46 +        struct stat buf;
    5.47 +
    5.48 +        if (stat(common_test_home.c_str(), &buf) == 0) {
    5.49 +            cout << common_test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
    5.50 +            int success = nftw((common_test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
    5.51 +        }
    5.52      }
    5.53      else {
    5.54          int errchk = mkdir(common_test_home.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
     6.1 --- a/test/src/engine_tests/DecorateTests.cc	Thu May 03 16:53:26 2018 +0200
     6.2 +++ b/test/src/engine_tests/DecorateTests.cc	Fri May 04 16:30:21 2018 +0200
     6.3 @@ -22,8 +22,8 @@
     6.4  using namespace std;
     6.5  
     6.6  DecorateTests::DecorateTests(string suitename, string test_home_dir) : 
     6.7 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
     6.8 -    TEST_ADD(DecorateTests::check_decorate);
     6.9 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {           
    6.10 +    add_test_to_suite(check_decorate);
    6.11  }
    6.12  
    6.13  void DecorateTests::check_decorate() {