Finally have session vs. individual setup/teardown working. Will set up the remaining test shells, and then finis for now. local_cpptest
authorKrista Bennett <krista@pep-project.org>
Mon, 07 May 2018 15:34:55 +0200
branchlocal_cpptest
changeset 2653232367954cc5
parent 2652 43b913f99a27
child 2654 be057a8a002e
Finally have session vs. individual setup/teardown working. Will set up the remaining test shells, and then finis for now.
test/include/AppleMailTests.h
test/include/BloblistTests.h
test/include/CaseAndDotAddressTests.h
test/include/DecorateTests.h
test/include/EngineTestSessionSuite.h
test/include/EngineTestSuite.h
test/include/SequenceTests.h
test/include/TrustManipulationTests.h
test/include/TrustwordsTests.h
test/include/UserIDAliasTests.h
test/src/EngineTestSessionSuite.cc
test/src/EngineTestSuite.cc
test/src/engine_tests/AppleMailTests.cc
test/src/engine_tests/BloblistTests.cc
test/src/engine_tests/CaseAndDotAddressTests.cc
test/src/engine_tests/DecorateTests.cc
test/src/engine_tests/SequenceTests.cc
test/src/engine_tests/StringlistTests.cc
test/src/engine_tests/StringpairListTests.cc
test/src/engine_tests/TrustManipulationTests.cc
test/src/engine_tests/TrustwordsTests.cc
test/src/engine_tests/UserIDAliasTests.cc
     1.1 --- a/test/include/AppleMailTests.h	Fri May 04 16:30:21 2018 +0200
     1.2 +++ b/test/include/AppleMailTests.h	Mon May 07 15:34:55 2018 +0200
     1.3 @@ -4,22 +4,12 @@
     1.4  #ifndef APPLE_MAIL_TESTS_H
     1.5  #define APPLE_MAIL_TESTS_H
     1.6  
     1.7 -#include <stdlib.h>
     1.8  #include <string.h>
     1.9 -#include "platform.h"
    1.10 -#include <iostream>
    1.11 -#include <fstream>
    1.12 -#include <sstream>
    1.13 -#include <cpptest.h>
    1.14 -#include <cpptest-suite.h>
    1.15 -#include <cpptest-textoutput.h>
    1.16 -#include "mime.h"
    1.17 -#include "message_api.h"
    1.18 -#include "test_util.h"
    1.19 +#include "EngineTestSessionSuite.h"
    1.20  
    1.21  using namespace std;
    1.22  
    1.23 -class AppleMailTests : public EngineTestIndividualSuite {
    1.24 +class AppleMailTests : public EngineTestSessionSuite {
    1.25      public:
    1.26          AppleMailTests(string suitename, string test_home_dir);
    1.27      private:
     2.1 --- a/test/include/BloblistTests.h	Fri May 04 16:30:21 2018 +0200
     2.2 +++ b/test/include/BloblistTests.h	Mon May 07 15:34:55 2018 +0200
     2.3 @@ -5,6 +5,7 @@
     2.4  #define BLOBLIST_TESTS_H
     2.5  
     2.6  #include <string>
     2.7 +#include "bloblist.h"
     2.8  #include "EngineTestSuite.h"
     2.9  
    2.10  using namespace std;
     3.1 --- a/test/include/CaseAndDotAddressTests.h	Fri May 04 16:30:21 2018 +0200
     3.2 +++ b/test/include/CaseAndDotAddressTests.h	Mon May 07 15:34:55 2018 +0200
     3.3 @@ -5,11 +5,11 @@
     3.4  #define CASE_AND_DOT_ADDRESS_TESTS_H
     3.5  
     3.6  #include <string>
     3.7 -#include "EngineTestIndividualSuite.h"
     3.8 +#include "EngineTestSessionSuite.h"
     3.9  
    3.10  using namespace std;
    3.11  
    3.12 -class CaseAndDotAddressTests : public EngineTestIndividualSuite {
    3.13 +class CaseAndDotAddressTests : public EngineTestSessionSuite {
    3.14      public:
    3.15          CaseAndDotAddressTests(string suitename, string test_home_dir);
    3.16      private:
     4.1 --- a/test/include/DecorateTests.h	Fri May 04 16:30:21 2018 +0200
     4.2 +++ b/test/include/DecorateTests.h	Mon May 07 15:34:55 2018 +0200
     4.3 @@ -5,11 +5,11 @@
     4.4  #define DECORATE_TESTS_H
     4.5  
     4.6  #include <string>
     4.7 -#include "EngineTestIndividualSuite.h"
     4.8 +#include "EngineTestSessionSuite.h"
     4.9  
    4.10  using namespace std;
    4.11  
    4.12 -class DecorateTests : public EngineTestIndividualSuite {
    4.13 +class DecorateTests : public EngineTestSessionSuite {
    4.14      public:
    4.15          DecorateTests(string suitename, string test_home_dir);
    4.16      private:
     5.1 --- a/test/include/EngineTestSessionSuite.h	Fri May 04 16:30:21 2018 +0200
     5.2 +++ b/test/include/EngineTestSessionSuite.h	Mon May 07 15:34:55 2018 +0200
     5.3 @@ -13,5 +13,8 @@
     5.4      public:
     5.5          EngineTestSessionSuite(string suitename, string test_home_dir);
     5.6          virtual ~EngineTestSessionSuite();
     5.7 +        
     5.8 +        virtual void setup();
     5.9 +        virtual void tear_down();
    5.10  };
    5.11  #endif
     6.1 --- a/test/include/EngineTestSuite.h	Fri May 04 16:30:21 2018 +0200
     6.2 +++ b/test/include/EngineTestSuite.h	Mon May 07 15:34:55 2018 +0200
     6.3 @@ -3,7 +3,7 @@
     6.4  
     6.5  #include <cpptest.h>
     6.6  #include <string>
     6.7 -#include <vector>
     6.8 +#include <map>
     6.9  #include "pEpEngine.h"
    6.10  
    6.11  using namespace std;
    6.12 @@ -13,8 +13,8 @@
    6.13          EngineTestSuite(string suitename, string test_home_dir);
    6.14          virtual ~EngineTestSuite();
    6.15          
    6.16 -        void add_test_to_suite(void (*test)()); // We do this so we can count
    6.17 -                
    6.18 +        void add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()> test_func);
    6.19 +        
    6.20      protected:
    6.21          PEP_SESSION session;
    6.22          string test_home;
    6.23 @@ -22,12 +22,15 @@
    6.24          string name;
    6.25          
    6.26          string current_test_name;
    6.27 +
    6.28 +        std::map<std::string, void (Test::Suite::*)()> test_map;                
    6.29          
    6.30          unsigned int number_of_tests;
    6.31          unsigned int on_test_number;
    6.32          
    6.33          virtual void setup();
    6.34          virtual void tear_down();
    6.35 +        
    6.36          void set_full_env();
    6.37          void restore_full_env();
    6.38          void initialise_test_home();
     7.1 --- a/test/include/SequenceTests.h	Fri May 04 16:30:21 2018 +0200
     7.2 +++ b/test/include/SequenceTests.h	Mon May 07 15:34:55 2018 +0200
     7.3 @@ -5,11 +5,11 @@
     7.4  #define SEQUENCE_TESTS_H
     7.5  
     7.6  #include <string>
     7.7 -#include "EngineTestIndividualSuite.h"
     7.8 +#include "EngineTestSessionSuite.h"
     7.9  
    7.10  using namespace std;
    7.11  
    7.12 -class SequenceTests : public EngineTestIndividualSuite {
    7.13 +class SequenceTests : public EngineTestSessionSuite {
    7.14      public:
    7.15          SequenceTests(string suitename, string test_home_dir);
    7.16      private:
     8.1 --- a/test/include/TrustManipulationTests.h	Fri May 04 16:30:21 2018 +0200
     8.2 +++ b/test/include/TrustManipulationTests.h	Mon May 07 15:34:55 2018 +0200
     8.3 @@ -5,11 +5,11 @@
     8.4  #define TRUST_MANIPULATION_TESTS_H
     8.5  
     8.6  #include <string>
     8.7 -#include "EngineTestIndividualSuite.h"
     8.8 +#include "EngineTestSessionSuite.h"
     8.9  
    8.10  using namespace std;
    8.11  
    8.12 -class TrustManipulationTests : public EngineTestIndividualSuite {
    8.13 +class TrustManipulationTests : public EngineTestSessionSuite {
    8.14      public:
    8.15          TrustManipulationTests(string suitename, string test_home_dir);
    8.16      private:
     9.1 --- a/test/include/TrustwordsTests.h	Fri May 04 16:30:21 2018 +0200
     9.2 +++ b/test/include/TrustwordsTests.h	Mon May 07 15:34:55 2018 +0200
     9.3 @@ -5,11 +5,11 @@
     9.4  #define TRUSTWORDS_TESTS_H
     9.5  
     9.6  #include <string>
     9.7 -#include "EngineTestIndividualSuite.h"
     9.8 +#include "EngineTestSessionSuite.h"
     9.9  
    9.10  using namespace std;
    9.11  
    9.12 -class TrustwordsTests : public EngineTestIndividualSuite {
    9.13 +class TrustwordsTests : public EngineTestSessionSuite {
    9.14      public:
    9.15          TrustwordsTests(string suitename, string test_home_dir);
    9.16      private:
    10.1 --- a/test/include/UserIDAliasTests.h	Fri May 04 16:30:21 2018 +0200
    10.2 +++ b/test/include/UserIDAliasTests.h	Mon May 07 15:34:55 2018 +0200
    10.3 @@ -5,11 +5,11 @@
    10.4  #define USERID_ALIAS_TESTS_H
    10.5  
    10.6  #include <string>
    10.7 -#include "EngineTestIndividualSuite.h"
    10.8 +#include "EngineTestSessionSuite.h"
    10.9  
   10.10  using namespace std;
   10.11  
   10.12 -class UserIDAliasTests : public EngineTestIndividualSuite {
   10.13 +class UserIDAliasTests : public EngineTestSessionSuite {
   10.14      public:
   10.15          UserIDAliasTests(string suitename, string test_home_dir);
   10.16      private:
    11.1 --- a/test/src/EngineTestSessionSuite.cc	Fri May 04 16:30:21 2018 +0200
    11.2 +++ b/test/src/EngineTestSessionSuite.cc	Mon May 07 15:34:55 2018 +0200
    11.3 @@ -12,10 +12,19 @@
    11.4  
    11.5  // Constructor
    11.6  EngineTestSessionSuite::EngineTestSessionSuite(string suitename, string test_home_dir) 
    11.7 -    : EngineTestSuite(suitename, test_home_dir) {
    11.8 -    set_full_env();
    11.9 +    : EngineTestSuite(suitename, test_home_dir) {}
   11.10 +
   11.11 +EngineTestSessionSuite::~EngineTestSessionSuite() {}
   11.12 +
   11.13 +void EngineTestSessionSuite::setup() {
   11.14 +    EngineTestSuite::setup();
   11.15 +    if (on_test_number == 1)
   11.16 +        set_full_env();
   11.17  }
   11.18  
   11.19 -EngineTestSessionSuite::~EngineTestSessionSuite() {
   11.20 -    restore_full_env();
   11.21 +void EngineTestSessionSuite::tear_down() {
   11.22 +    if (on_test_number == number_of_tests)
   11.23 +        restore_full_env();
   11.24 +        
   11.25 +    EngineTestSuite::tear_down();
   11.26  }
    12.1 --- a/test/src/EngineTestSuite.cc	Fri May 04 16:30:21 2018 +0200
    12.2 +++ b/test/src/EngineTestSuite.cc	Mon May 07 15:34:55 2018 +0200
    12.3 @@ -22,8 +22,9 @@
    12.4  
    12.5  EngineTestSuite::~EngineTestSuite() {}
    12.6  
    12.7 -void EngineTestSuite::add_test_to_suite(Test::Suite::Func test) {
    12.8 -    TEST_ADD(test);
    12.9 +void EngineTestSuite::add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()> test_func) {
   12.10 +    test_map.insert(test_func);
   12.11 +    register_test(test_func.second, test_func.first);
   12.12      number_of_tests++;
   12.13  }
   12.14  
   12.15 @@ -76,5 +77,8 @@
   12.16          throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
   12.17  }
   12.18  
   12.19 -void EngineTestSuite::setup() {}
   12.20 +void EngineTestSuite::setup() {
   12.21 +    on_test_number++;
   12.22 +}
   12.23 +
   12.24  void EngineTestSuite::tear_down() {}
    13.1 --- a/test/src/engine_tests/AppleMailTests.cc	Fri May 04 16:30:21 2018 +0200
    13.2 +++ b/test/src/engine_tests/AppleMailTests.cc	Mon May 07 15:34:55 2018 +0200
    13.3 @@ -20,13 +20,13 @@
    13.4  #include "test_util.h" // for slurp()
    13.5  
    13.6  #include "EngineTestSuite.h"
    13.7 -#include "EngineTestIndividualSuite.h"
    13.8 +#include "EngineTestSessionSuite.h"
    13.9  #include "AppleMailTests.h"
   13.10  
   13.11  using namespace std;
   13.12  
   13.13  AppleMailTests::AppleMailTests(string suitename, string test_home_dir) : 
   13.14 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   13.15 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
   13.16      TEST_ADD(AppleMailTests::check_apple_mail);
   13.17  }
   13.18  
    14.1 --- a/test/src/engine_tests/BloblistTests.cc	Fri May 04 16:30:21 2018 +0200
    14.2 +++ b/test/src/engine_tests/BloblistTests.cc	Mon May 07 15:34:55 2018 +0200
    14.3 @@ -11,7 +11,6 @@
    14.4  #include "bloblist.h"
    14.5  
    14.6  #include "EngineTestSuite.h"
    14.7 -#include "EngineTestIndividualSuite.h"
    14.8  #include "BloblistTests.h"
    14.9  
   14.10  using namespace std;
    15.1 --- a/test/src/engine_tests/CaseAndDotAddressTests.cc	Fri May 04 16:30:21 2018 +0200
    15.2 +++ b/test/src/engine_tests/CaseAndDotAddressTests.cc	Mon May 07 15:34:55 2018 +0200
    15.3 @@ -12,13 +12,13 @@
    15.4  #include "test_util.h"
    15.5  
    15.6  #include "EngineTestSuite.h"
    15.7 -#include "EngineTestIndividualSuite.h"
    15.8 +#include "EngineTestSessionSuite.h"
    15.9  #include "CaseAndDotAddressTests.h"
   15.10  
   15.11  using namespace std;
   15.12  
   15.13  CaseAndDotAddressTests::CaseAndDotAddressTests(string suitename, string test_home_dir) : 
   15.14 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   15.15 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
   15.16      TEST_ADD(CaseAndDotAddressTests::check_case_and_dot_address);
   15.17  }
   15.18  
    16.1 --- a/test/src/engine_tests/DecorateTests.cc	Fri May 04 16:30:21 2018 +0200
    16.2 +++ b/test/src/engine_tests/DecorateTests.cc	Mon May 07 15:34:55 2018 +0200
    16.3 @@ -16,14 +16,15 @@
    16.4  #include "test_util.h"
    16.5  
    16.6  #include "EngineTestSuite.h"
    16.7 -#include "EngineTestIndividualSuite.h"
    16.8 +#include "EngineTestSessionSuite.h"
    16.9  #include "DecorateTests.h"
   16.10  
   16.11  using namespace std;
   16.12  
   16.13  DecorateTests::DecorateTests(string suitename, string test_home_dir) : 
   16.14 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {           
   16.15 -    add_test_to_suite(check_decorate);
   16.16 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {               
   16.17 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DecorateTests::check_decorate"), 
   16.18 +                                                                      static_cast<Func>(&DecorateTests::check_decorate)));
   16.19  }
   16.20  
   16.21  void DecorateTests::check_decorate() {
    17.1 --- a/test/src/engine_tests/SequenceTests.cc	Fri May 04 16:30:21 2018 +0200
    17.2 +++ b/test/src/engine_tests/SequenceTests.cc	Mon May 07 15:34:55 2018 +0200
    17.3 @@ -8,13 +8,13 @@
    17.4  #include "pEpEngine.h"
    17.5  
    17.6  #include "EngineTestSuite.h"
    17.7 -#include "EngineTestIndividualSuite.h"
    17.8 +#include "EngineTestSessionSuite.h"
    17.9  #include "SequenceTests.h"
   17.10  
   17.11  using namespace std;
   17.12  
   17.13  SequenceTests::SequenceTests(string suitename, string test_home_dir) : 
   17.14 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   17.15 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
   17.16      TEST_ADD(SequenceTests::check_sequences);
   17.17  }
   17.18  
    18.1 --- a/test/src/engine_tests/StringlistTests.cc	Fri May 04 16:30:21 2018 +0200
    18.2 +++ b/test/src/engine_tests/StringlistTests.cc	Mon May 07 15:34:55 2018 +0200
    18.3 @@ -11,7 +11,6 @@
    18.4  #include "stringlist.h"
    18.5  
    18.6  #include "EngineTestSuite.h"
    18.7 -#include "EngineTestIndividualSuite.h"
    18.8  #include "StringlistTests.h"
    18.9  
   18.10  using namespace std;
    19.1 --- a/test/src/engine_tests/StringpairListTests.cc	Fri May 04 16:30:21 2018 +0200
    19.2 +++ b/test/src/engine_tests/StringpairListTests.cc	Mon May 07 15:34:55 2018 +0200
    19.3 @@ -11,7 +11,6 @@
    19.4  #include "stringpair.h"
    19.5  
    19.6  #include "EngineTestSuite.h"
    19.7 -#include "EngineTestIndividualSuite.h"
    19.8  #include "StringpairListTests.h"
    19.9  
   19.10  using namespace std;
    20.1 --- a/test/src/engine_tests/TrustManipulationTests.cc	Fri May 04 16:30:21 2018 +0200
    20.2 +++ b/test/src/engine_tests/TrustManipulationTests.cc	Mon May 07 15:34:55 2018 +0200
    20.3 @@ -12,13 +12,13 @@
    20.4  #include "test_util.h"
    20.5  
    20.6  #include "EngineTestSuite.h"
    20.7 -#include "EngineTestIndividualSuite.h"
    20.8 +#include "EngineTestSessionSuite.h"
    20.9  #include "TrustManipulationTests.h"
   20.10  
   20.11  using namespace std;
   20.12  
   20.13  TrustManipulationTests::TrustManipulationTests(string suitename, string test_home_dir) : 
   20.14 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   20.15 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
   20.16      TEST_ADD(TrustManipulationTests::check_trust_manipulation);
   20.17  }
   20.18  
    21.1 --- a/test/src/engine_tests/TrustwordsTests.cc	Fri May 04 16:30:21 2018 +0200
    21.2 +++ b/test/src/engine_tests/TrustwordsTests.cc	Mon May 07 15:34:55 2018 +0200
    21.3 @@ -7,13 +7,13 @@
    21.4  #include "message_api.h"
    21.5  
    21.6  #include "EngineTestSuite.h"
    21.7 -#include "EngineTestIndividualSuite.h"
    21.8 +#include "EngineTestSessionSuite.h"
    21.9  #include "TrustwordsTests.h"
   21.10  
   21.11  using namespace std;
   21.12  
   21.13  TrustwordsTests::TrustwordsTests(string suitename, string test_home_dir) : 
   21.14 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   21.15 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
   21.16      TEST_ADD(TrustwordsTests::check_trustwords);
   21.17  }
   21.18  
    22.1 --- a/test/src/engine_tests/UserIDAliasTests.cc	Fri May 04 16:30:21 2018 +0200
    22.2 +++ b/test/src/engine_tests/UserIDAliasTests.cc	Mon May 07 15:34:55 2018 +0200
    22.3 @@ -12,13 +12,13 @@
    22.4  #include "test_util.h"
    22.5  
    22.6  #include "EngineTestSuite.h"
    22.7 -#include "EngineTestIndividualSuite.h"
    22.8 +#include "EngineTestSessionSuite.h"
    22.9  #include "UserIDAliasTests.h"
   22.10  
   22.11  using namespace std;
   22.12  
   22.13  UserIDAliasTests::UserIDAliasTests(string suitename, string test_home_dir) : 
   22.14 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   22.15 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
   22.16      TEST_ADD(UserIDAliasTests::check_userid_aliases);
   22.17  }
   22.18