Reverted out device model sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Fri, 15 Mar 2019 12:43:56 +0100
branchsync
changeset 333509af2cf0ac74
parent 3331 d11bc639db5c
child 3336 bea05d3b250e
Reverted out device model
test/convenience_scripts/compile_it.sh
test/convenience_scripts/mime_decrypt.cc
test/convenience_scripts/mime_encrypt.cc
test/convenience_scripts/mime_encrypt_decrypt.cc
test/gentestshell.py
test/include/DeviceModelTests.h
test/include/EngineTestIndividualSuite.h
test/include/EngineTestSuite.h
test/include/KeyResetMessageTests.h
test/include/SyncDeviceTests.h
test/include/TestUtils.h
test/include/locked_queue.hh
test/include/pEpTestDevice.h
test/include/test_util.h
test/src/EngineTestIndividualSuite.cc
test/src/EngineTestSuite.cc
test/src/SuiteMaker.cc
test/src/TestUtils.cc
test/src/engine_tests/AppleMailTests.cc
test/src/engine_tests/BCCTests.cc
test/src/engine_tests/BlacklistAcceptNewKeyTests.cc
test/src/engine_tests/BlacklistTests.cc
test/src/engine_tests/CaseAndDotAddressTests.cc
test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc
test/src/engine_tests/DecorateTests.cc
test/src/engine_tests/DecryptAttachPrivateKeyTrustedTests.cc
test/src/engine_tests/DecryptAttachPrivateKeyUntrustedTests.cc
test/src/engine_tests/DeviceModelTests.cc
test/src/engine_tests/EncryptAttachPrivateKeyTests.cc
test/src/engine_tests/EncryptForIdentityTests.cc
test/src/engine_tests/EncryptMissingPrivateKeyTests.cc
test/src/engine_tests/Engine358Tests.cc
test/src/engine_tests/Engine463Tests.cc
test/src/engine_tests/ExpiredSubkeyTests.cc
test/src/engine_tests/ExternalRevokeTests.cc
test/src/engine_tests/HeaderKeyImportTests.cc
test/src/engine_tests/IntegrityTests.do.not.run.before.ENGINE-434
test/src/engine_tests/KeyAttachmentTests.cc
test/src/engine_tests/KeyResetMessageTests.cc
test/src/engine_tests/LeastColorGroupTests.cc
test/src/engine_tests/LeastCommonDenomColorTests.cc
test/src/engine_tests/MessageApiTests.cc
test/src/engine_tests/MessageNullFromTests.cc
test/src/engine_tests/MessageTwoPointOhTests.cc
test/src/engine_tests/NewUpdateIdAndMyselfTests.cc
test/src/engine_tests/PepSubjectReceivedTests.cc
test/src/engine_tests/ReencryptPlusExtraKeysTests.cc
test/src/engine_tests/RevokeRegenAttachTests.cc
test/src/engine_tests/SignOnlyTests.cc
test/src/engine_tests/SimpleBodyNotAltTests.cc
test/src/engine_tests/SubkeyRatingEvalTests.cc
test/src/engine_tests/SyncDeviceTests.cc
test/src/engine_tests/TrustManipulationTests.cc
test/src/engine_tests/UserIDAliasTests.cc
test/src/engine_tests/UserIdCollisionTests.cc
test/src/pEpTestDevice.cc
test/src/util/test_util.cc
     1.1 --- a/test/convenience_scripts/compile_it.sh	Sat Mar 09 11:50:11 2019 +0100
     1.2 +++ b/test/convenience_scripts/compile_it.sh	Fri Mar 15 12:43:56 2019 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4  #!/bin/bash
     1.5  g++ -std=gnu++11 -pthread -fdiagnostics-color=always -I../src -I../asn.1 -I/home/krista/include -I./include -g -ggdb   -c -o $1.o $1.cc
     1.6 -#g++ -std=gnu++11 -pthread -fdiagnostics-color=always -I../src -I../asn.1 -I/home/krista/include -I./include -g -ggdb   -c -o TestUtils.o src/util/TestUtils.cc
     1.7 -g++ -std=gnu++11 -pthread -fdiagnostics-color=always -I../src -I../asn.1 -I/home/krista/include -I./include -g -ggdb   -c -o TestUtils.o TestUtils.cc
     1.8 -g++ -std=gnu++11 -pthread $1.o TestUtils.o  -L/home/krista/lib -L../asn.1 -L../src  -letpan -lpEpEngine -lstdc++ -lasn1 -luuid -lsqlite3 -o $1
     1.9 +#g++ -std=gnu++11 -pthread -fdiagnostics-color=always -I../src -I../asn.1 -I/home/krista/include -I./include -g -ggdb   -c -o test_util.o src/util/test_util.cc
    1.10 +g++ -std=gnu++11 -pthread -fdiagnostics-color=always -I../src -I../asn.1 -I/home/krista/include -I./include -g -ggdb   -c -o test_util.o test_util.cc
    1.11 +g++ -std=gnu++11 -pthread $1.o test_util.o  -L/home/krista/lib -L../asn.1 -L../src  -letpan -lpEpEngine -lstdc++ -lasn1 -luuid -lsqlite3 -o $1
    1.12  
     2.1 --- a/test/convenience_scripts/mime_decrypt.cc	Sat Mar 09 11:50:11 2019 +0100
     2.2 +++ b/test/convenience_scripts/mime_decrypt.cc	Fri Mar 15 12:43:56 2019 +0100
     2.3 @@ -10,7 +10,7 @@
     2.4  #include "mime.h"
     2.5  #include "message_api.h"
     2.6  #include "keymanagement.h"
     2.7 -#include "TestUtils.h"
     2.8 +#include "test_util.h"
     2.9  
    2.10  using namespace std;
    2.11  
     3.1 --- a/test/convenience_scripts/mime_encrypt.cc	Sat Mar 09 11:50:11 2019 +0100
     3.2 +++ b/test/convenience_scripts/mime_encrypt.cc	Fri Mar 15 12:43:56 2019 +0100
     3.3 @@ -10,7 +10,7 @@
     3.4  #include "mime.h"
     3.5  #include "message_api.h"
     3.6  #include "keymanagement.h"
     3.7 -#include "TestUtils.h"
     3.8 +#include "test_util.h"
     3.9  
    3.10  using namespace std;
    3.11  
     4.1 --- a/test/convenience_scripts/mime_encrypt_decrypt.cc	Sat Mar 09 11:50:11 2019 +0100
     4.2 +++ b/test/convenience_scripts/mime_encrypt_decrypt.cc	Fri Mar 15 12:43:56 2019 +0100
     4.3 @@ -10,7 +10,7 @@
     4.4  #include "mime.h"
     4.5  #include "message_api.h"
     4.6  #include "keymanagement.h"
     4.7 -#include "TestUtils.h"
     4.8 +#include "test_util.h"
     4.9  
    4.10  using namespace std;
    4.11  
     5.1 --- a/test/gentestshell.py	Sat Mar 09 11:50:11 2019 +0100
     5.2 +++ b/test/gentestshell.py	Fri Mar 15 12:43:56 2019 +0100
     5.3 @@ -87,11 +87,7 @@
     5.4  if not args.no_src:
     5.5      src_inc = ('#include <stdlib.h>\n'
     5.6                 '#include <string>\n\n'
     5.7 -               '#include <cpptest.h>\n\n'
     5.8 -               '#include <cstring>\n\n'                              
     5.9                 '#include "pEpEngine.h"\n\n'
    5.10 -               '#include "TestUtils.h"\n\n'
    5.11 -               '#include "pEpTestDevice.h"\n\n'
    5.12                 '#include "' + superclass +'.h"\n'
    5.13                 '#include "' + test_suite + '.h"\n\n')
    5.14  
     6.1 --- a/test/include/DeviceModelTests.h	Sat Mar 09 11:50:11 2019 +0100
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,34 +0,0 @@
     6.4 -// This file is under GNU General Public License 3.0
     6.5 -// see LICENSE.txt
     6.6 -
     6.7 -#ifndef DEVICE_MODEL_H
     6.8 -#define DEVICE_MODEL_H
     6.9 -
    6.10 -#include <string>
    6.11 -#include <vector>
    6.12 -#include "EngineTestIndividualSuite.h"
    6.13 -
    6.14 -using namespace std;
    6.15 -
    6.16 -class DeviceModelTests : public EngineTestIndividualSuite {
    6.17 -    public:
    6.18 -        DeviceModelTests(string test_suite, string test_home_dir);
    6.19 -
    6.20 -    protected:
    6.21 -        void setup();
    6.22 -        void tear_down();
    6.23 -        
    6.24 -    private:
    6.25 -        void check_device_model();
    6.26 -        void check_two_device_model();
    6.27 -        void check_two_device_functionality();
    6.28 -        void check_mbox();
    6.29 -        void check_three_device_mbox_with_send();
    6.30 -        void check_switch_context();
    6.31 -        
    6.32 -        void clear_and_delete_devices();
    6.33 -        
    6.34 -        vector<pEpTestDevice*> devices;
    6.35 -};
    6.36 -
    6.37 -#endif
     7.1 --- a/test/include/EngineTestIndividualSuite.h	Sat Mar 09 11:50:11 2019 +0100
     7.2 +++ b/test/include/EngineTestIndividualSuite.h	Fri Mar 15 12:43:56 2019 +0100
     7.3 @@ -12,8 +12,7 @@
     7.4  
     7.5  class EngineTestIndividualSuite : public EngineTestSuite {
     7.6      public:
     7.7 -        EngineTestIndividualSuite(string suitename, string test_home_dir,
     7.8 -                                  bool make_default_device = true);
     7.9 +        EngineTestIndividualSuite(string suitename, string test_home_dir);
    7.10          virtual ~EngineTestIndividualSuite();
    7.11      protected:
    7.12          virtual void setup();
     8.1 --- a/test/include/EngineTestSuite.h	Sat Mar 09 11:50:11 2019 +0100
     8.2 +++ b/test/include/EngineTestSuite.h	Fri Mar 15 12:43:56 2019 +0100
     8.3 @@ -7,16 +7,12 @@
     8.4  #include <vector>
     8.5  #include <utility>
     8.6  #include "pEpEngine.h"
     8.7 -#include "pEpTestDevice.h"
     8.8  
     8.9  using namespace std;
    8.10  
    8.11  class EngineTestSuite : public Test::Suite {
    8.12      public:
    8.13 -        EngineTestSuite(string suitename, 
    8.14 -                        string test_home_dir, 
    8.15 -                        bool make_default_device = true);   
    8.16 -                             
    8.17 +        EngineTestSuite(string suitename, string test_home_dir);
    8.18          virtual ~EngineTestSuite();
    8.19          
    8.20          void add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()> test_func);
    8.21 @@ -25,9 +21,6 @@
    8.22  
    8.23      protected:
    8.24          PEP_SESSION session;
    8.25 -        bool make_device;
    8.26 -        pEpTestDevice* device;
    8.27 -        
    8.28          string test_home;
    8.29          string real_home;
    8.30          string prev_pgp_home;
    8.31 @@ -35,6 +28,9 @@
    8.32          
    8.33          string current_test_name;
    8.34  
    8.35 +        messageToSend_t cached_messageToSend;
    8.36 +        inject_sync_event_t cached_inject_sync_event;
    8.37 +
    8.38  #define TEST_FAILED_MESSAGE_BUFSIZE 1000        
    8.39          char failed_msg_buf[TEST_FAILED_MESSAGE_BUFSIZE];
    8.40          
     9.1 --- a/test/include/KeyResetMessageTests.h	Sat Mar 09 11:50:11 2019 +0100
     9.2 +++ b/test/include/KeyResetMessageTests.h	Fri Mar 15 12:43:56 2019 +0100
     9.3 @@ -35,7 +35,6 @@
     9.4  
     9.5      protected:
     9.6          void setup();
     9.7 -        void tear_down();
     9.8                  
     9.9      private:
    9.10          void check_key_reset_message();        
    10.1 --- a/test/include/SyncDeviceTests.h	Sat Mar 09 11:50:11 2019 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,20 +0,0 @@
    10.4 -// This file is under GNU General Public License 3.0
    10.5 -// see LICENSE.txt
    10.6 -
    10.7 -#ifndef SYNC_DEVICE_H
    10.8 -#define SYNC_DEVICE_H
    10.9 -
   10.10 -#include <string>
   10.11 -#include "EngineTestIndividualSuite.h"
   10.12 -
   10.13 -using namespace std;
   10.14 -
   10.15 -class SyncDeviceTests : public EngineTestIndividualSuite {
   10.16 -    public:
   10.17 -        SyncDeviceTests(string test_suite, string test_home_dir);
   10.18 -                
   10.19 -    private:
   10.20 -        void check_sync_device();
   10.21 -};
   10.22 -
   10.23 -#endif
    11.1 --- a/test/include/TestUtils.h	Sat Mar 09 11:50:11 2019 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,60 +0,0 @@
    11.4 -#ifndef PEP_TEST_UTILS_H
    11.5 -#define PEP_TEST_UTILS_H
    11.6 -
    11.7 -#include <string>
    11.8 -#include <stdlib.h>
    11.9 -#include <sys/stat.h>
   11.10 -#include <ftw.h>
   11.11 -
   11.12 -#include "pEpEngine.h"
   11.13 -#include "message_api.h"
   11.14 -
   11.15 -void test_init();
   11.16 -
   11.17 -bool file_exists(std::string filename);
   11.18 -
   11.19 -PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname);
   11.20 -PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session, 
   11.21 -                                     const char* key_fname,
   11.22 -                                     const char* address,
   11.23 -                                     const char* fpr,
   11.24 -                                     const char* user_id,
   11.25 -                                     const char* username,
   11.26 -                                     pEp_identity** ret_ident,
   11.27 -                                     bool is_priv);
   11.28 -
   11.29 -// string equality (case and non-case sensitive)
   11.30 -bool _streq(const char* str1, const char* str2);
   11.31 -bool _strceq(const char* str1, const char* str2);
   11.32 -
   11.33 -// reads a whole file and returns it as std::string
   11.34 -// throws std::runtime_error() if the file cannot be read. Empty file is not an error.
   11.35 -std::string slurp(const std::string& filename);
   11.36 -
   11.37 -// dumps char* to file
   11.38 -// throws std::runtime_error() if the file cannot be opened.
   11.39 -void dump_out(const char* filename, const char* outdata);
   11.40 -
   11.41 -// Returns the string value of the input rating enum value. 
   11.42 -const char* tl_rating_string(PEP_rating rating);
   11.43 -
   11.44 -// Returns the string value of the input comm_type enum value. 
   11.45 -const char* tl_ct_string(PEP_comm_type ct);
   11.46 -
   11.47 -// Returns the string value of the input status enum value. 
   11.48 -const char* tl_status_string(PEP_STATUS status);
   11.49 -
   11.50 -// Grabs a new uuid for your randomish string needs.
   11.51 -char* get_new_uuid();
   11.52 -
   11.53 -bool slurp_and_import_key(PEP_SESSION session, const char* key_filename);
   11.54 -
   11.55 -bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename);
   11.56 -
   11.57 -int util_delete_filepath(const char *filepath, 
   11.58 -                         const struct stat *file_stat, 
   11.59 -                         int ftw_info, 
   11.60 -                         struct FTW * ftw_struct);
   11.61 -                         
   11.62 -        
   11.63 -#endif
    12.1 --- a/test/include/locked_queue.hh	Sat Mar 09 11:50:11 2019 +0100
    12.2 +++ b/test/include/locked_queue.hh	Fri Mar 15 12:43:56 2019 +0100
    12.3 @@ -58,4 +58,4 @@
    12.4              return _q.empty();
    12.5          }
    12.6      };
    12.7 -}
    12.8 +};
    13.1 --- a/test/include/pEpTestDevice.h	Sat Mar 09 11:50:11 2019 +0100
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,104 +0,0 @@
    13.4 -#ifndef PEP_TEST_DEVICE_H
    13.5 -#define PEP_TEST_DEVICE_H
    13.6 -
    13.7 -#include <cpptest.h>
    13.8 -#include <string>
    13.9 -#include <map>
   13.10 -#include <vector>
   13.11 -#include <utility>
   13.12 -#include "pEpEngine.h"
   13.13 -#include "message.h"
   13.14 -#include "sync_api.h"
   13.15 -#include "locked_queue.hh"
   13.16 -#include "Sync_event.h"
   13.17 -
   13.18 -using namespace std;
   13.19 -
   13.20 -class pEpTestDevice {
   13.21 -    public:
   13.22 -        pEpTestDevice(string test_dir, string my_name);        
   13.23 -                      
   13.24 -        virtual ~pEpTestDevice();
   13.25 -        
   13.26 -        static pEpTestDevice* active;
   13.27 -        static void switch_context(pEpTestDevice* switch_to);
   13.28 -
   13.29 -        // Write mail string to a timestamp-named file in the listed mailbox,
   13.30 -        // and return the name of the file.
   13.31 -        static string save_mail_to_mailbox(string mailbox_path, string mail);
   13.32 -
   13.33 -        void set_mailbox_dir(string mbox_dirname);
   13.34 -        
   13.35 -        // set my variables as the environment vars (HOME, GNUPGHOME, etc)
   13.36 -        void set_device_environment();
   13.37 -        
   13.38 -        // clean up crypto agents and 
   13.39 -        void unset_device_environment();
   13.40 -        
   13.41 -        // Make all of this device's environment information the current
   13.42 -        // environment, and restart session for this device with this,
   13.43 -        // releasing the victim's device and session (and processing their 
   13.44 -        // send queue before doing this)
   13.45 -        void grab_context(pEpTestDevice* victim);
   13.46 -
   13.47 -        // take string and save to own mailbox as timestamped mail file and 
   13.48 -        // return filename 
   13.49 -        string receive_mail(string mail); 
   13.50 -        
   13.51 -        // Get the filenames of all unread mails
   13.52 -        void check_mail(vector<string> &unread);
   13.53 -        
   13.54 -        // Read all mails (by filename) into a vector of strings
   13.55 -        void read_mail(vector<string>mails, vector<message*> &to_read);
   13.56 -        
   13.57 -        // write everything into the correct mail by mailbox.
   13.58 -        // PRESUMES address_to_mbox_map HAS AN ENTRY FOR EVERY ADDRESS IN 
   13.59 -        // THE RECIP LIST
   13.60 -        PEP_STATUS process_send_queue();
   13.61 -        
   13.62 -        // write individual message struct to the correct mailbox
   13.63 -        PEP_STATUS send_mail(message* mail);
   13.64 -
   13.65 -        void add_message_to_send_queue(message* msg);
   13.66 -        
   13.67 -        string device_name;
   13.68 -        PEP_SESSION session;
   13.69 -        string device_dir;        
   13.70 -        string root_test_dir;
   13.71 -        string mbox_dir;
   13.72 -        utility::locked_queue<Sync_event_t*> q;
   13.73 -
   13.74 -        static Sync_event_t* retrieve_next_sync_event(void *management, unsigned int threshold);
   13.75 -        static PEP_STATUS notify_handshake(pEp_identity *me,
   13.76 -                                    pEp_identity *partner,
   13.77 -                                    sync_handshake_signal signal);
   13.78 -        
   13.79 -        static int inject_sync_event(SYNC_EVENT ev, void *management);
   13.80 -//        Sync_event_t *retrieve_next_sync_event(void *management, unsigned threshold);
   13.81 -        static PEP_STATUS message_to_send(struct _message *msg);
   13.82 -
   13.83 -
   13.84 -//        messageToSend_t device_messageToSend;
   13.85 -//        inject_sync_event_t device_inject_sync_event;
   13.86 -        map<string,string> address_to_mbox_map; // maybe string, vector<string>?
   13.87 -        vector<message*> send_queue;
   13.88 -        
   13.89 -    protected:        
   13.90 -        string mbox_last_read;
   13.91 -        vector<string> mail_to_read;
   13.92 -        
   13.93 -//        string current_test_name;
   13.94 -        
   13.95 -//        void set_full_env();
   13.96 -//        void set_full_env(const char* gpg_conf_copy_path, const char* gpg_agent_conf_file_copy_path, const char* db_conf_file_copy_path);
   13.97 -//        void restore_full_env();
   13.98 -//        void initialise_test_home();
   13.99 -	
  13.100 -        // std::vector<std::pair<std::string, std::string>> gpgdir_fileadd_queue;
  13.101 -        // std::vector<std::pair<std::string, std::string>> homedir_fileadd_queue;
  13.102 -        // void add_file_to_gpg_dir_queue(std::string copy_from, std::string dst_fname);    
  13.103 -        // void add_file_to_home_dir_queue(std::string copy_from, std::string dst_fname);
  13.104 -        // void process_file_queue(std::string dirname, std::vector<std::pair<std::string, std::string>> file_queue);
  13.105 -};
  13.106 -    
  13.107 -#endif
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/include/test_util.h	Fri Mar 15 12:43:56 2019 +0100
    14.3 @@ -0,0 +1,60 @@
    14.4 +#ifndef PEP_TEST_UTILS_H
    14.5 +#define PEP_TEST_UTILS_H
    14.6 +
    14.7 +#include <string>
    14.8 +#include <stdlib.h>
    14.9 +#include <sys/stat.h>
   14.10 +#include <ftw.h>
   14.11 +
   14.12 +#include "pEpEngine.h"
   14.13 +#include "message_api.h"
   14.14 +
   14.15 +void test_init();
   14.16 +
   14.17 +bool file_exists(std::string filename);
   14.18 +
   14.19 +PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname);
   14.20 +PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session, 
   14.21 +                                     const char* key_fname,
   14.22 +                                     const char* address,
   14.23 +                                     const char* fpr,
   14.24 +                                     const char* user_id,
   14.25 +                                     const char* username,
   14.26 +                                     pEp_identity** ret_ident,
   14.27 +                                     bool is_priv);
   14.28 +
   14.29 +// string equality (case and non-case sensitive)
   14.30 +bool _streq(const char* str1, const char* str2);
   14.31 +bool _strceq(const char* str1, const char* str2);
   14.32 +
   14.33 +// reads a whole file and returns it as std::string
   14.34 +// throws std::runtime_error() if the file cannot be read. Empty file is not an error.
   14.35 +std::string slurp(const std::string& filename);
   14.36 +
   14.37 +// dumps char* to file
   14.38 +// throws std::runtime_error() if the file cannot be opened.
   14.39 +void dump_out(const char* filename, const char* outdata);
   14.40 +
   14.41 +// Returns the string value of the input rating enum value. 
   14.42 +const char* tl_rating_string(PEP_rating rating);
   14.43 +
   14.44 +// Returns the string value of the input comm_type enum value. 
   14.45 +const char* tl_ct_string(PEP_comm_type ct);
   14.46 +
   14.47 +// Returns the string value of the input status enum value. 
   14.48 +const char* tl_status_string(PEP_STATUS status);
   14.49 +
   14.50 +// Grabs a new uuid for your randomish string needs.
   14.51 +char* get_new_uuid();
   14.52 +
   14.53 +bool slurp_and_import_key(PEP_SESSION session, const char* key_filename);
   14.54 +
   14.55 +bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename);
   14.56 +
   14.57 +int util_delete_filepath(const char *filepath, 
   14.58 +                         const struct stat *file_stat, 
   14.59 +                         int ftw_info, 
   14.60 +                         struct FTW * ftw_struct);
   14.61 +                         
   14.62 +        
   14.63 +#endif
    15.1 --- a/test/src/EngineTestIndividualSuite.cc	Sat Mar 09 11:50:11 2019 +0100
    15.2 +++ b/test/src/EngineTestIndividualSuite.cc	Fri Mar 15 12:43:56 2019 +0100
    15.3 @@ -12,10 +12,8 @@
    15.4  using namespace std;
    15.5  
    15.6  // Constructor
    15.7 -EngineTestIndividualSuite::EngineTestIndividualSuite(string suitename, 
    15.8 -                                                     string test_home_dir,
    15.9 -                                                     bool make_default_device) 
   15.10 -    : EngineTestSuite(suitename, test_home_dir, make_default_device) { 
   15.11 +EngineTestIndividualSuite::EngineTestIndividualSuite(string suitename, string test_home_dir) 
   15.12 +    : EngineTestSuite(suitename, test_home_dir) { 
   15.13  }
   15.14  
   15.15  EngineTestIndividualSuite::~EngineTestIndividualSuite() {
    16.1 --- a/test/src/EngineTestSuite.cc	Sat Mar 09 11:50:11 2019 +0100
    16.2 +++ b/test/src/EngineTestSuite.cc	Fri Mar 15 12:43:56 2019 +0100
    16.3 @@ -13,11 +13,10 @@
    16.4  #include <string>
    16.5  #include <vector>
    16.6  #include <utility>
    16.7 -#include <cpptest.h>
    16.8  
    16.9  #include "platform_unix.h"
   16.10  
   16.11 -#include "TestUtils.h"
   16.12 +#include "test_util.h"
   16.13  #include "EngineTestSuite.h"
   16.14  #include "pEpTestStatic.h"
   16.15  #include <algorithm>
   16.16 @@ -26,18 +25,15 @@
   16.17  using namespace std;
   16.18  
   16.19  // Constructor
   16.20 -EngineTestSuite::EngineTestSuite(string suitename, 
   16.21 -                                 string test_home_dir,
   16.22 -                                 bool make_default_device) {
   16.23 +EngineTestSuite::EngineTestSuite(string suitename, string test_home_dir) {
   16.24      // FIXME: deal with base
   16.25      test_home = test_home_dir;
   16.26              
   16.27      number_of_tests = 0;
   16.28      on_test_number = 0;
   16.29      real_home = getenv("HOME");
   16.30 -    session = NULL;
   16.31 -    device = NULL;
   16.32 -    make_device = make_default_device;
   16.33 +    cached_messageToSend = NULL;
   16.34 +    cached_inject_sync_event = NULL;
   16.35  }
   16.36  
   16.37  EngineTestSuite::~EngineTestSuite() {}
   16.38 @@ -105,12 +101,12 @@
   16.39      
   16.40      set_my_name();
   16.41  
   16.42 -// // FIXME
   16.43 -// #ifndef USE_NETPGP
   16.44 -//     success = system("gpgconf --kill all");
   16.45 -//     if (success != 0)
   16.46 -//         throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
   16.47 -// #endif
   16.48 +// FIXME
   16.49 +#ifndef USE_NETPGP
   16.50 +    success = system("gpgconf --kill all");
   16.51 +    if (success != 0)
   16.52 +        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
   16.53 +#endif
   16.54  
   16.55      if (stat(test_home.c_str(), &dirchk) == 0) {
   16.56          if (!S_ISDIR(dirchk.st_mode))
   16.57 @@ -170,92 +166,84 @@
   16.58      
   16.59      assert(temp_test_home.compare(home) != 0);
   16.60      assert(temp_test_home.compare(home + "/") != 0);
   16.61 -    // assert(temp_test_home.compare(home + "/.gnupg") != 0); // This is an EXCLUSION test, so we leave this.
   16.62 -    // assert(temp_test_home.compare(home + ".gnupg") != 0);
   16.63 -    // assert(temp_test_home.compare(home + "/gnupg") != 0);
   16.64 -    // assert(temp_test_home.compare(home + "gnupg") != 0);
   16.65 -    // assert(temp_test_home.compare(prev_pgp_home) != 0);
   16.66 -    // assert(temp_test_home.compare(prev_pgp_home + "/gnupg") != 0);
   16.67 -    // assert(temp_test_home.compare(prev_pgp_home + "gnupg") != 0);
   16.68 -    // assert(temp_test_home.compare(prev_pgp_home + "/.gnupg") != 0);
   16.69 -    // assert(temp_test_home.compare(prev_pgp_home + ".gnupg") != 0);
   16.70 +    assert(temp_test_home.compare(home + "/.gnupg") != 0); // This is an EXCLUSION test, so we leave this.
   16.71 +    assert(temp_test_home.compare(home + ".gnupg") != 0);
   16.72 +    assert(temp_test_home.compare(home + "/gnupg") != 0);
   16.73 +    assert(temp_test_home.compare(home + "gnupg") != 0);
   16.74 +    assert(temp_test_home.compare(prev_pgp_home) != 0);
   16.75 +    assert(temp_test_home.compare(prev_pgp_home + "/gnupg") != 0);
   16.76 +    assert(temp_test_home.compare(prev_pgp_home + "gnupg") != 0);
   16.77 +    assert(temp_test_home.compare(prev_pgp_home + "/.gnupg") != 0);
   16.78 +    assert(temp_test_home.compare(prev_pgp_home + ".gnupg") != 0);
   16.79  
   16.80      if (temp_test_home.compare(home) == 0 || temp_test_home.compare(home + "/") == 0 ||
   16.81          temp_test_home.compare(home + "/gnupg") == 0 || temp_test_home.compare(home + "gnupg") == 0 ||
   16.82 -        temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0)
   16.83 -        // temp_test_home.compare(prev_pgp_home) == 0 || temp_test_home.compare(prev_pgp_home + "/gnupg") == 0 ||
   16.84 -        // temp_test_home.compare(prev_pgp_home + "gnupg") == 0 || temp_test_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
   16.85 -        // temp_test_home.compare(prev_pgp_home + ".gnupg") == 0)
   16.86 +        temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0 ||
   16.87 +        temp_test_home.compare(prev_pgp_home) == 0 || temp_test_home.compare(prev_pgp_home + "/gnupg") == 0 ||
   16.88 +        temp_test_home.compare(prev_pgp_home + "gnupg") == 0 || temp_test_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
   16.89 +        temp_test_home.compare(prev_pgp_home + ".gnupg") == 0)
   16.90          throw std::runtime_error("SETUP: new pgp homedir threatens to mess up user pgp homedir (and delete all their keys). NO DICE.");
   16.91      
   16.92  //    cout << "Ok - checked if new test home will be safe. We'll try and make the directory, deleting it if it has already exists." << endl;
   16.93      cout << "Test home directory is " << temp_test_home << endl;
   16.94      
   16.95      struct stat buf;
   16.96 -    // 
   16.97 -    // success = setenv("GNUPGHOME", (temp_test_home + "/gnupg").c_str(), 1);
   16.98 -    // if (success != 0)
   16.99 -    //     throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
  16.100 -    // 
  16.101 -    // cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
  16.102 +    
  16.103 +    success = setenv("GNUPGHOME", (temp_test_home + "/gnupg").c_str(), 1);
  16.104 +    if (success != 0)
  16.105 +        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
  16.106 +
  16.107 +    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
  16.108      
  16.109      success = setenv("HOME", temp_test_home.c_str(), 1);
  16.110      if (success != 0)
  16.111          throw std::runtime_error("SETUP: Cannot set test_home for init.");
  16.112  
  16.113 -    // string tmp_gpg_dir = temp_test_home + "/.gnupg";
  16.114 +    string tmp_gpg_dir = temp_test_home + "/.gnupg";
  16.115  
  16.116 -    // process_file_queue(tmp_gpg_dir, gpgdir_fileadd_queue);
  16.117 -    // process_file_queue(temp_test_home, homedir_fileadd_queue);
  16.118 +    process_file_queue(tmp_gpg_dir, gpgdir_fileadd_queue);
  16.119 +    process_file_queue(temp_test_home, homedir_fileadd_queue);
  16.120  
  16.121 -    // if (gpg_conf_copy_path)
  16.122 -    //     copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_conf_copy_path, "gpg.conf");
  16.123 -    // if (gpg_agent_conf_file_copy_path)        
  16.124 -    //     copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_agent_conf_file_copy_path, "gpg-agent.conf");
  16.125 -    // if (db_conf_file_copy_path)
  16.126 -    //     copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
  16.127 +    if (gpg_conf_copy_path)
  16.128 +        copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_conf_copy_path, "gpg.conf");
  16.129 +    if (gpg_agent_conf_file_copy_path)        
  16.130 +        copy_conf_file_to_test_dir((temp_test_home + "/gnupg").c_str(), gpg_agent_conf_file_copy_path, "gpg-agent.conf");
  16.131 +    if (db_conf_file_copy_path)
  16.132 +        copy_conf_file_to_test_dir(temp_test_home.c_str(), db_conf_file_copy_path, ".pEp_management.db");
  16.133          
  16.134 -    // unix_local_db(true);
  16.135 -    // gpg_conf(true);
  16.136 -    // gpg_agent_conf(true);
  16.137 +    unix_local_db(true);
  16.138 +    gpg_conf(true);
  16.139 +    gpg_agent_conf(true);
  16.140      
  16.141  //    cout << "calling init()\n";
  16.142 -//     PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
  16.143 -// #ifndef USE_NETPGP            
  16.144 -//     success = system("gpgconf --create-socketdir");
  16.145 -//     if (success != 0)
  16.146 -//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
  16.147 -//     system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
  16.148 -// #endif
  16.149 +    PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event);
  16.150 +#ifndef USE_NETPGP            
  16.151 +    success = system("gpgconf --create-socketdir");
  16.152 +    if (success != 0)
  16.153 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
  16.154 +    system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
  16.155 +#endif
  16.156  
  16.157 -//    assert(status == PEP_STATUS_OK);
  16.158 -//    assert(session);
  16.159 +    assert(status == PEP_STATUS_OK);
  16.160 +    assert(session);
  16.161  //    cout << "init() completed.\n";
  16.162 -    if (make_device) {
  16.163 -        device = new pEpTestDevice(temp_test_home, "DefaultDevice");
  16.164 -        session = device->session;
  16.165 -    }
  16.166 +
  16.167  }
  16.168  
  16.169  void EngineTestSuite::restore_full_env() {
  16.170 -//    release(session);
  16.171 -//    session = NULL;
  16.172 -    if (make_device) {
  16.173 -        delete(device);
  16.174 -        device = NULL;
  16.175 -        session = NULL;
  16.176 -    }
  16.177 +    release(session);
  16.178 +    session = NULL;
  16.179          
  16.180      int success = 0;    
  16.181  
  16.182 -// #ifndef USE_NETPGP        
  16.183 -//     success = system("gpgconf --kill all");
  16.184 -//     if (success != 0)
  16.185 -//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
  16.186 -//     success = system("gpgconf --remove-socketdir");            
  16.187 -//     if (success != 0)
  16.188 -//         throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
  16.189 -// #endif
  16.190 +#ifndef USE_NETPGP        
  16.191 +    success = system("gpgconf --kill all");
  16.192 +    if (success != 0)
  16.193 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
  16.194 +    success = system("gpgconf --remove-socketdir");            
  16.195 +    if (success != 0)
  16.196 +        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
  16.197 +#endif
  16.198  
  16.199      success = setenv("GNUPGHOME", prev_pgp_home.c_str(), 1);
  16.200      if (success != 0)
  16.201 @@ -268,9 +256,9 @@
  16.202          throw std::runtime_error("RESTORE: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");
  16.203      // else
  16.204      //     cout << "RESTORE: HOME is now " << getenv("HOME") << endl;
  16.205 -    // unix_local_db(true);
  16.206 -    // gpg_conf(true);
  16.207 -    // gpg_agent_conf(true);
  16.208 +    unix_local_db(true);
  16.209 +    gpg_conf(true);
  16.210 +    gpg_agent_conf(true);
  16.211  
  16.212  }
  16.213  
    17.1 --- a/test/src/SuiteMaker.cc	Sat Mar 09 11:50:11 2019 +0100
    17.2 +++ b/test/src/SuiteMaker.cc	Fri Mar 15 12:43:56 2019 +0100
    17.3 @@ -18,7 +18,6 @@
    17.4  #include "Engine463Tests.h"
    17.5  #include "BloblistTests.h"
    17.6  #include "NewUpdateIdAndMyselfTests.h"
    17.7 -#include "SyncDeviceTests.h"
    17.8  #include "I18nTests.h"
    17.9  #include "IdentityListTests.h"
   17.10  #include "PgpBinaryTests.h"
   17.11 @@ -36,6 +35,7 @@
   17.12  #include "Engine358Tests.h"
   17.13  #include "BlacklistAcceptNewKeyTests.h"
   17.14  #include "DecryptAttachPrivateKeyUntrustedTests.h"
   17.15 +#include "ReturnMistrustFprTests.h"
   17.16  #include "BlacklistTests.h"
   17.17  #include "RevokeRegenAttachTests.h"
   17.18  #include "PepSubjectReceivedTests.h"
   17.19 @@ -49,7 +49,6 @@
   17.20  #include "CheckRenewedExpiredKeyTrustStatusTests.h"
   17.21  #include "TrustwordsTests.h"
   17.22  #include "SimpleBodyNotAltTests.h"
   17.23 -#include "DeviceModelTests.h"
   17.24  #include "ReencryptPlusExtraKeysTests.h"
   17.25  #include "MapAsn1Tests.h"
   17.26  #include "DecorateTests.h"
   17.27 @@ -71,7 +70,6 @@
   17.28      "Engine463Tests",
   17.29      "BloblistTests",
   17.30      "NewUpdateIdAndMyselfTests",
   17.31 -    "SyncDeviceTests",
   17.32      "I18nTests",
   17.33      "IdentityListTests",
   17.34      "PgpBinaryTests",
   17.35 @@ -89,6 +87,7 @@
   17.36      "Engine358Tests",
   17.37      "BlacklistAcceptNewKeyTests",
   17.38      "DecryptAttachPrivateKeyUntrustedTests",
   17.39 +    "ReturnMistrustFprTests",
   17.40      "BlacklistTests",
   17.41      "RevokeRegenAttachTests",
   17.42      "PepSubjectReceivedTests",
   17.43 @@ -102,7 +101,6 @@
   17.44      "CheckRenewedExpiredKeyTrustStatusTests",
   17.45      "TrustwordsTests",
   17.46      "SimpleBodyNotAltTests",
   17.47 -    "DeviceModelTests",
   17.48      "ReencryptPlusExtraKeysTests",
   17.49      "MapAsn1Tests",
   17.50      "DecorateTests",
   17.51 @@ -118,7 +116,7 @@
   17.52  };
   17.53  
   17.54  // This file is generated, so magic constants are ok.
   17.55 -int SuiteMaker::num_suites = 50;
   17.56 +int SuiteMaker::num_suites = 49;
   17.57  
   17.58  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
   17.59      if (strcmp(test_class_name, "MimeTests") == 0)
   17.60 @@ -133,8 +131,6 @@
   17.61          *test_suite = new BloblistTests(test_class_name, test_home);
   17.62      else if (strcmp(test_class_name, "NewUpdateIdAndMyselfTests") == 0)
   17.63          *test_suite = new NewUpdateIdAndMyselfTests(test_class_name, test_home);
   17.64 -    else if (strcmp(test_class_name, "SyncDeviceTests") == 0)
   17.65 -        *test_suite = new SyncDeviceTests(test_class_name, test_home);
   17.66      else if (strcmp(test_class_name, "I18nTests") == 0)
   17.67          *test_suite = new I18nTests(test_class_name, test_home);
   17.68      else if (strcmp(test_class_name, "IdentityListTests") == 0)
   17.69 @@ -169,6 +165,8 @@
   17.70          *test_suite = new BlacklistAcceptNewKeyTests(test_class_name, test_home);
   17.71      else if (strcmp(test_class_name, "DecryptAttachPrivateKeyUntrustedTests") == 0)
   17.72          *test_suite = new DecryptAttachPrivateKeyUntrustedTests(test_class_name, test_home);
   17.73 +    else if (strcmp(test_class_name, "ReturnMistrustFprTests") == 0)
   17.74 +        *test_suite = new ReturnMistrustFprTests(test_class_name, test_home);
   17.75      else if (strcmp(test_class_name, "BlacklistTests") == 0)
   17.76          *test_suite = new BlacklistTests(test_class_name, test_home);
   17.77      else if (strcmp(test_class_name, "RevokeRegenAttachTests") == 0)
   17.78 @@ -195,8 +193,6 @@
   17.79          *test_suite = new TrustwordsTests(test_class_name, test_home);
   17.80      else if (strcmp(test_class_name, "SimpleBodyNotAltTests") == 0)
   17.81          *test_suite = new SimpleBodyNotAltTests(test_class_name, test_home);
   17.82 -    else if (strcmp(test_class_name, "DeviceModelTests") == 0)
   17.83 -        *test_suite = new DeviceModelTests(test_class_name, test_home);
   17.84      else if (strcmp(test_class_name, "ReencryptPlusExtraKeysTests") == 0)
   17.85          *test_suite = new ReencryptPlusExtraKeysTests(test_class_name, test_home);
   17.86      else if (strcmp(test_class_name, "MapAsn1Tests") == 0)
    18.1 --- a/test/src/TestUtils.cc	Sat Mar 09 11:50:11 2019 +0100
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,456 +0,0 @@
    18.4 -#include "pEpEngine_test.h"
    18.5 -#include "pEpEngine.h"
    18.6 -#include "pEp_internal.h"
    18.7 -#include "message_api.h"
    18.8 -#include "TestUtils.h"
    18.9 -#include "TestConstants.h"
   18.10 -
   18.11 -#include <fstream>
   18.12 -#include <sstream>
   18.13 -#include <stdexcept>
   18.14 -#include <stdlib.h>
   18.15 -#include <sys/stat.h>
   18.16 -#include <errno.h>
   18.17 -#include <stdlib.h>
   18.18 -#include <unistd.h>
   18.19 -#include <ftw.h>
   18.20 -
   18.21 -PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname) {
   18.22 -    const std::string key = slurp(fname);
   18.23 -    PEP_STATUS status = (key.empty() ? PEP_KEY_NOT_FOUND : PEP_STATUS_OK);
   18.24 -    if (status == PEP_STATUS_OK)
   18.25 -        status = import_key(session, key.c_str(), key.size(), NULL);
   18.26 -    return status;    
   18.27 -}
   18.28 -
   18.29 -PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session,
   18.30 -                                     const char* key_fname,
   18.31 -                                     const char* address,
   18.32 -                                     const char* fpr,
   18.33 -                                     const char* user_id,
   18.34 -                                     const char* username,
   18.35 -                                     pEp_identity** ret_ident,
   18.36 -                                     bool is_priv) {
   18.37 -    PEP_STATUS status = read_file_and_import_key(session,key_fname);
   18.38 -    if (status != PEP_KEY_IMPORTED)
   18.39 -        return status;
   18.40 -    else
   18.41 -        status = PEP_STATUS_OK;
   18.42 -    
   18.43 -    pEp_identity* ident = new_identity(address, fpr, user_id, username);
   18.44 -    if (is_priv && fpr) {
   18.45 -        status = set_own_key(session, ident, fpr);
   18.46 -        if (status == PEP_STATUS_OK)
   18.47 -            status = myself(session, ident);
   18.48 -    }
   18.49 -    else    
   18.50 -        status = update_identity(session, ident);
   18.51 -
   18.52 -    if (status != PEP_STATUS_OK)
   18.53 -        goto pep_free;
   18.54 -        
   18.55 -    if (!ident || !ident->fpr) {
   18.56 -        status = PEP_CANNOT_FIND_IDENTITY;
   18.57 -        goto pep_free;
   18.58 -    }
   18.59 -    
   18.60 -    if (ret_ident)
   18.61 -        *ret_ident = ident;
   18.62 -        
   18.63 -pep_free:
   18.64 -    if (!ret_ident)
   18.65 -        free_identity(ident);
   18.66 -    return status;    
   18.67 -}
   18.68 -
   18.69 -
   18.70 -bool file_exists(std::string filename) {
   18.71 -    struct stat buffer;
   18.72 -    return (stat(filename.c_str(), &buffer) == 0);
   18.73 -}
   18.74 -
   18.75 -char* str_to_lower(const char* str) {
   18.76 -    if (!str)
   18.77 -        return NULL;
   18.78 -    int str_len = strlen(str);
   18.79 -    if (str_len == 0)
   18.80 -        return strdup("");
   18.81 -    int i;
   18.82 -    
   18.83 -    char* retval = (char*) calloc(1, str_len + 1);
   18.84 -    for (i = 0; i < str_len; i++) {
   18.85 -        retval[i] = tolower(str[i]);
   18.86 -    }    
   18.87 -    return retval;
   18.88 -}
   18.89 -
   18.90 -// Because annoyed
   18.91 -bool _streq(const char* str1, const char* str2) {
   18.92 -    if (!str1) {
   18.93 -        if (str2)
   18.94 -            return false;
   18.95 -        return true;
   18.96 -    }
   18.97 -    if (!str2)
   18.98 -        return false;
   18.99 -        
  18.100 -    return (strcmp(str1, str2) == 0);
  18.101 -}
  18.102 -
  18.103 -bool _strceq(const char* str1, const char* str2) {
  18.104 -    char* str1_dup = str_to_lower(str1);
  18.105 -    char* str2_dup = str_to_lower(str2);
  18.106 -
  18.107 -    bool retval = _streq(str_to_lower(str1_dup), str_to_lower(str2_dup));
  18.108 -    free(str1_dup);
  18.109 -    free(str2_dup);
  18.110 -    return retval;
  18.111 -}
  18.112 -
  18.113 -void test_init() {
  18.114 -    unlink ("../test_home/.pEp_management.db");
  18.115 -    unlink ("../test_home/.pEp_management.db-shm");
  18.116 -    unlink ("../test_home/.pEp_management.db-wal");
  18.117 -}
  18.118 -
  18.119 -std::string slurp(const std::string& filename)
  18.120 -{
  18.121 -	std::ifstream input(filename.c_str());
  18.122 -	if(!input)
  18.123 -	{
  18.124 -		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
  18.125 -	}
  18.126 -	
  18.127 -	std::stringstream sstr;
  18.128 -	sstr << input.rdbuf();
  18.129 -	return sstr.str();
  18.130 -}
  18.131 -
  18.132 -void dump_out(const char* filename, const char* outdata)
  18.133 -{
  18.134 -	std::ofstream outfile(filename);
  18.135 -	if(!outfile)
  18.136 -	{
  18.137 -		throw std::runtime_error("Cannot open output file!");
  18.138 -	}
  18.139 -	
  18.140 -	outfile << outdata;
  18.141 -    outfile.close();
  18.142 -}
  18.143 -
  18.144 -char* get_new_uuid() {
  18.145 -    char* new_uuid = (char*)calloc(37, 1);
  18.146 -    pEpUUID uuid;
  18.147 -    uuid_generate_random(uuid);
  18.148 -    uuid_unparse_upper(uuid, new_uuid);
  18.149 -    return new_uuid;
  18.150 -}
  18.151 -
  18.152 -const char* tl_status_string(PEP_STATUS status) {
  18.153 -    switch (status) {
  18.154 -        case PEP_STATUS_OK:
  18.155 -            return "PEP_STATUS_OK";
  18.156 -        case PEP_INIT_CANNOT_LOAD_GPGME:
  18.157 -            return "PEP_INIT_CANNOT_LOAD_GPGME";
  18.158 -        case PEP_INIT_GPGME_INIT_FAILED:
  18.159 -            return "PEP_INIT_GPGME_INIT_FAILED";
  18.160 -        case PEP_INIT_NO_GPG_HOME:
  18.161 -            return "PEP_INIT_NO_GPG_HOME";
  18.162 -        case PEP_INIT_NETPGP_INIT_FAILED:
  18.163 -            return "PEP_INIT_NETPGP_INIT_FAILED";
  18.164 -        case PEP_INIT_CANNOT_DETERMINE_GPG_VERSION:
  18.165 -            return "PEP_INIT_CANNOT_DETERMINE_GPG_VERSION";
  18.166 -        case PEP_INIT_UNSUPPORTED_GPG_VERSION:
  18.167 -            return "PEP_INIT_UNSUPPORTED_GPG_VERSION";
  18.168 -        case PEP_INIT_CANNOT_CONFIG_GPG_AGENT:
  18.169 -            return "PEP_INIT_CANNOT_CONFIG_GPG_AGENT";
  18.170 -        case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
  18.171 -            return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
  18.172 -        case PEP_INIT_CANNOT_OPEN_DB:
  18.173 -            return "PEP_INIT_CANNOT_OPEN_DB";
  18.174 -        case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
  18.175 -            return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
  18.176 -        case PEP_UNKNOWN_DB_ERROR:
  18.177 -            return "PEP_UNKNOWN_DB_ERROR";
  18.178 -        case PEP_KEY_NOT_FOUND:
  18.179 -            return "PEP_KEY_NOT_FOUND";
  18.180 -        case PEP_KEY_HAS_AMBIG_NAME:
  18.181 -            return "PEP_KEY_HAS_AMBIG_NAME";
  18.182 -        case PEP_GET_KEY_FAILED:
  18.183 -            return "PEP_GET_KEY_FAILED";
  18.184 -        case PEP_CANNOT_EXPORT_KEY:
  18.185 -            return "PEP_CANNOT_EXPORT_KEY";
  18.186 -        case PEP_CANNOT_EDIT_KEY:
  18.187 -            return "PEP_CANNOT_EDIT_KEY";
  18.188 -        case PEP_KEY_UNSUITABLE:
  18.189 -            return "PEP_KEY_UNSUITABLE";
  18.190 -        case PEP_MALFORMED_KEY_RESET_MSG:
  18.191 -            return "PEP_MALFORMED_KEY_RESET_MSG";
  18.192 -        case PEP_KEY_NOT_RESET:
  18.193 -            return "PEP_KEY_NOT_RESET";
  18.194 -        case PEP_KEY_IMPORTED:
  18.195 -            return "PEP_KEY_IMPORTED";
  18.196 -        case PEP_NO_KEY_IMPORTED:
  18.197 -            return "PEP_NO_KEY_IMPORTED";
  18.198 -        case PEP_KEY_IMPORT_STATUS_UNKNOWN:
  18.199 -            return "PEP_KEY_IMPORT_STATUS_UNKNOWN";
  18.200 -        case PEP_CANNOT_FIND_IDENTITY:
  18.201 -            return "PEP_CANNOT_FIND_IDENTITY";
  18.202 -        case PEP_CANNOT_SET_PERSON:
  18.203 -            return "PEP_CANNOT_SET_PERSON";
  18.204 -        case PEP_CANNOT_SET_PGP_KEYPAIR:
  18.205 -            return "PEP_CANNOT_SET_PGP_KEYPAIR";
  18.206 -        case PEP_CANNOT_SET_IDENTITY:
  18.207 -            return "PEP_CANNOT_SET_IDENTITY";
  18.208 -        case PEP_CANNOT_SET_TRUST:
  18.209 -            return "PEP_CANNOT_SET_TRUST";
  18.210 -        case PEP_CANNOT_FIND_PERSON:
  18.211 -            return "PEP_CANNOT_FIND_PERSON";
  18.212 -        case PEP_CANNOT_FIND_ALIAS:
  18.213 -            return "PEP_CANNOT_FIND_ALIAS";        
  18.214 -        case PEP_KEY_BLACKLISTED:
  18.215 -            return "PEP_KEY_BLACKLISTED";
  18.216 -        case PEP_UNENCRYPTED:
  18.217 -            return "PEP_UNENCRYPTED";
  18.218 -        case PEP_VERIFIED:
  18.219 -            return "PEP_VERIFIED";
  18.220 -        case PEP_DECRYPTED:
  18.221 -            return "PEP_DECRYPTED";
  18.222 -        case PEP_DECRYPTED_AND_VERIFIED:
  18.223 -            return "PEP_DECRYPTED_AND_VERIFIED";
  18.224 -        case PEP_DECRYPT_WRONG_FORMAT:
  18.225 -            return "PEP_DECRYPT_WRONG_FORMAT";
  18.226 -        case PEP_DECRYPT_NO_KEY:
  18.227 -            return "PEP_DECRYPT_NO_KEY";
  18.228 -        case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
  18.229 -            return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
  18.230 -//        case PEP_DECRYPTED_BUT_UNSIGNED:
  18.231 -//            return "PEP_DECRYPTED_BUT_UNSIGNED";
  18.232 -//        case PEP_DECRYPT_MODIFICATION_DETECTED:
  18.233 -//            return "PEP_DECRYPT_MODIFICATION_DETECTED";
  18.234 -//        case PEP_DECRYPT_NO_KEY_FOR_SIGNER:
  18.235 -//            return "PEP_DECRYPT_NO_KEY_FOR_SIGNER";
  18.236 -        case PEP_VERIFY_NO_KEY:
  18.237 -            return "PEP_VERIFY_NO_KEY";
  18.238 -        case PEP_VERIFIED_AND_TRUSTED:
  18.239 -            return "PEP_VERIFIED_AND_TRUSTED";
  18.240 -        case PEP_CANNOT_REENCRYPT:
  18.241 -            return "PEP_CANNOT_REENCRYPT";    
  18.242 -        case PEP_CANNOT_DECRYPT_UNKNOWN:
  18.243 -            return "PEP_CANNOT_DECRYPT_UNKNOWN";
  18.244 -        case PEP_TRUSTWORD_NOT_FOUND:
  18.245 -            return "PEP_TRUSTWORD_NOT_FOUND";
  18.246 -        case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
  18.247 -            return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
  18.248 -        case PEP_TRUSTWORDS_DUPLICATE_FPR:
  18.249 -            return "PEP_TRUSTWORDS_DUPLICATE_FPR";    
  18.250 -        case PEP_CANNOT_CREATE_KEY:
  18.251 -            return "PEP_CANNOT_CREATE_KEY";
  18.252 -        case PEP_CANNOT_SEND_KEY:
  18.253 -            return "PEP_CANNOT_SEND_KEY";
  18.254 -        case PEP_PHRASE_NOT_FOUND:
  18.255 -            return "PEP_PHRASE_NOT_FOUND";
  18.256 -        case PEP_SEND_FUNCTION_NOT_REGISTERED:
  18.257 -            return "PEP_SEND_FUNCTION_NOT_REGISTERED";
  18.258 -        case PEP_CONTRAINTS_VIOLATED:
  18.259 -            return "PEP_CONTRAINTS_VIOLATED";
  18.260 -        case PEP_CANNOT_ENCODE:
  18.261 -            return "PEP_CANNOT_ENCODE";
  18.262 -        case PEP_SYNC_NO_NOTIFY_CALLBACK:
  18.263 -            return "PEP_SYNC_NO_NOTIFY_CALLBACK";
  18.264 -        case PEP_SYNC_ILLEGAL_MESSAGE:
  18.265 -            return "PEP_SYNC_ILLEGAL_MESSAGE";
  18.266 -        case PEP_SYNC_NO_INJECT_CALLBACK:
  18.267 -            return "PEP_SYNC_NO_INJECT_CALLBACK";
  18.268 -        case PEP_SYNC_NO_CHANNEL:
  18.269 -            return "PEP_SYNC_NO_CHANNEL";
  18.270 -        case PEP_SYNC_CANNOT_ENCRYPT:
  18.271 -            return "PEP_SYNC_CANNOT_ENCRYPT";
  18.272 -        case PEP_SYNC_NO_MESSAGE_SEND_CALLBACK:
  18.273 -            return "PEP_SYNC_NO_MESSAGE_SEND_CALLBACK";            
  18.274 -        case PEP_CANNOT_INCREASE_SEQUENCE:
  18.275 -            return "PEP_CANNOT_INCREASE_SEQUENCE";
  18.276 -        case PEP_STATEMACHINE_ERROR:
  18.277 -            return "PEP_STATEMACHINE_ERROR";
  18.278 -        case PEP_NO_TRUST:
  18.279 -            return "PEP_NO_TRUST";
  18.280 -        case PEP_STATEMACHINE_INVALID_STATE:
  18.281 -            return "PEP_STATEMACHINE_INVALID_STATE";
  18.282 -        case PEP_STATEMACHINE_INVALID_EVENT:
  18.283 -            return "PEP_STATEMACHINE_INVALID_EVENT";
  18.284 -        case PEP_STATEMACHINE_INVALID_CONDITION:
  18.285 -            return "PEP_STATEMACHINE_INVALID_CONDITION";
  18.286 -        case PEP_STATEMACHINE_INVALID_ACTION:
  18.287 -            return "PEP_STATEMACHINE_INVALID_ACTION";
  18.288 -        case PEP_STATEMACHINE_INHIBITED_EVENT:
  18.289 -            return "PEP_STATEMACHINE_INHIBITED_EVENT";
  18.290 -        case PEP_STATEMACHINE_CANNOT_SEND:
  18.291 -            return "PEP_STATEMACHINE_CANNOT_SEND";    
  18.292 -        case PEP_COMMIT_FAILED:
  18.293 -            return "PEP_COMMIT_FAILED";
  18.294 -        case PEP_MESSAGE_CONSUME:
  18.295 -            return "PEP_MESSAGE_CONSUME";
  18.296 -        case PEP_MESSAGE_IGNORE:
  18.297 -            return "PEP_MESSAGE_IGNORE";
  18.298 -        case PEP_RECORD_NOT_FOUND:
  18.299 -            return "PEP_RECORD_NOT_FOUND";
  18.300 -        case PEP_CANNOT_CREATE_TEMP_FILE:
  18.301 -            return "PEP_CANNOT_CREATE_TEMP_FILE";
  18.302 -        case PEP_ILLEGAL_VALUE:
  18.303 -            return "PEP_ILLEGAL_VALUE";
  18.304 -        case PEP_BUFFER_TOO_SMALL:
  18.305 -            return "PEP_BUFFER_TOO_SMALL";
  18.306 -        case PEP_OUT_OF_MEMORY:
  18.307 -            return "PEP_OUT_OF_MEMORY";
  18.308 -        case PEP_UNKNOWN_ERROR:
  18.309 -            return "PEP_UNKNOWN_ERROR";
  18.310 -        case PEP_VERSION_MISMATCH:
  18.311 -            return "PEP_VERSION_MISMATCH";
  18.312 -        default:
  18.313 -            return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
  18.314 -    }
  18.315 -}
  18.316 -const char* tl_rating_string(PEP_rating rating) {
  18.317 -    switch (rating) {
  18.318 -        case PEP_rating_undefined:
  18.319 -            return "PEP_rating_undefined";
  18.320 -        case PEP_rating_cannot_decrypt:
  18.321 -            return "PEP_rating_cannot_decrypt";
  18.322 -        case PEP_rating_have_no_key:
  18.323 -            return "PEP_rating_have_no_key";
  18.324 -        case PEP_rating_unencrypted:
  18.325 -            return "PEP_rating_unencrypted";
  18.326 -        case PEP_rating_unencrypted_for_some:
  18.327 -            return "PEP_rating_unencrypted_for_some";
  18.328 -        case PEP_rating_unreliable:
  18.329 -            return "PEP_rating_unreliable";
  18.330 -        case PEP_rating_reliable:
  18.331 -            return "PEP_rating_reliable";
  18.332 -        case PEP_rating_trusted:
  18.333 -            return "PEP_rating_trusted";
  18.334 -        case PEP_rating_trusted_and_anonymized:
  18.335 -            return "PEP_rating_trusted_and_anonymized";
  18.336 -        case PEP_rating_fully_anonymous:
  18.337 -            return "PEP_rating_fully_anonymous";
  18.338 -        case PEP_rating_mistrust:
  18.339 -            return "PEP_rating_mistrust";
  18.340 -        case PEP_rating_b0rken:
  18.341 -            return "PEP_rating_b0rken";
  18.342 -        case PEP_rating_under_attack:
  18.343 -            return "PEP_rating_under_attack";
  18.344 -        default:
  18.345 -            return "PEP_rating_OMGWTFBBQ - in other words, INVALID RATING VALUE!!!\n\nSomething bad is going on here, or a new rating value has been added to the enum and not the test function.";
  18.346 -    }
  18.347 -}
  18.348 -
  18.349 -const char* tl_ct_string(PEP_comm_type ct) {
  18.350 -    switch (ct) {
  18.351 -        case PEP_ct_unknown:
  18.352 -            return "PEP_ct_unknown";
  18.353 -        case PEP_ct_no_encryption:
  18.354 -            return "PEP_ct_no_encryption";
  18.355 -        case PEP_ct_no_encrypted_channel:
  18.356 -            return "PEP_ct_no_encrypted_channel";
  18.357 -        case PEP_ct_key_not_found:
  18.358 -            return "PEP_ct_key_not_found";
  18.359 -        case PEP_ct_key_expired:
  18.360 -            return "PEP_ct_key_expired";
  18.361 -        case PEP_ct_key_revoked:
  18.362 -            return "PEP_ct_key_revoked";
  18.363 -        case PEP_ct_key_b0rken:
  18.364 -            return "PEP_ct_key_b0rken";
  18.365 -        case PEP_ct_my_key_not_included:
  18.366 -            return "PEP_ct_my_key_not_included";
  18.367 -        case PEP_ct_security_by_obscurity:
  18.368 -            return "PEP_ct_security_by_obscurity";
  18.369 -        case PEP_ct_b0rken_crypto:
  18.370 -            return "PEP_ct_b0rken_crypto";
  18.371 -        case PEP_ct_key_too_short:
  18.372 -            return "PEP_ct_key_too_short";
  18.373 -        case PEP_ct_compromised:
  18.374 -            return "PEP_ct_compromised";
  18.375 -        case PEP_ct_mistrusted:
  18.376 -            return "PEP_ct_mistrusted";
  18.377 -        case PEP_ct_unconfirmed_encryption:
  18.378 -            return "PEP_ct_unconfirmed_encryption";
  18.379 -        case PEP_ct_OpenPGP_weak_unconfirmed:
  18.380 -            return "PEP_ct_OpenPGP_weak_unconfirmed";
  18.381 -        case PEP_ct_to_be_checked:
  18.382 -            return "PEP_ct_to_be_checked";
  18.383 -        case PEP_ct_SMIME_unconfirmed:
  18.384 -            return "PEP_ct_SMIME_unconfirmed";
  18.385 -        case PEP_ct_CMS_unconfirmed:
  18.386 -            return "PEP_ct_CMS_unconfirmed";
  18.387 -        case PEP_ct_strong_but_unconfirmed:
  18.388 -            return "PEP_ct_strong_but_unconfirmed";
  18.389 -        case PEP_ct_OpenPGP_unconfirmed:
  18.390 -            return "PEP_ct_OpenPGP_unconfirmed";
  18.391 -        case PEP_ct_OTR_unconfirmed:
  18.392 -            return "PEP_ct_OTR_unconfirmed";
  18.393 -        case PEP_ct_unconfirmed_enc_anon:
  18.394 -            return "PEP_ct_unconfirmed_enc_anon";
  18.395 -        case PEP_ct_pEp_unconfirmed:
  18.396 -            return "PEP_ct_pEp_unconfirmed";
  18.397 -        case PEP_ct_confirmed:
  18.398 -            return "PEP_ct_pEp_confirmed";
  18.399 -        case PEP_ct_confirmed_encryption:
  18.400 -            return "PEP_ct_confirmed_encryption";
  18.401 -        case PEP_ct_OpenPGP_weak:
  18.402 -            return "PEP_ct_OpenPGP_weak";
  18.403 -        case PEP_ct_to_be_checked_confirmed:
  18.404 -            return "PEP_ct_to_be_checked_confirmed";
  18.405 -        case PEP_ct_SMIME:
  18.406 -            return "PEP_ct_SMIME";
  18.407 -        case PEP_ct_CMS:
  18.408 -            return "PEP_ct_CMS";
  18.409 -        case PEP_ct_strong_encryption:
  18.410 -            return "PEP_ct_strong_encryption";
  18.411 -        case PEP_ct_OpenPGP:
  18.412 -            return "PEP_ct_OpenPGP";
  18.413 -        case PEP_ct_OTR:
  18.414 -            return "PEP_ct_OTR";
  18.415 -        case PEP_ct_confirmed_enc_anon:
  18.416 -            return "PEP_ct_confirmed_enc_anon";
  18.417 -        case PEP_ct_pEp:
  18.418 -            return "PEP_ct_pEp";
  18.419 -        default:
  18.420 -            return "PEP_ct_OMGWTFBBQ\n\nIn other words, comm type is invalid. Either something's corrupt or a new ct value has been added to the enum but not to the test function.";
  18.421 -    }
  18.422 -}
  18.423 -
  18.424 -bool slurp_and_import_key(PEP_SESSION session, const char* key_filename) {
  18.425 -    std::string keyfile = slurp(key_filename);
  18.426 -    if (import_key(session, keyfile.c_str(), keyfile.size(), NULL) != PEP_TEST_KEY_IMPORT_SUCCESS)
  18.427 -        return false;
  18.428 -    return true;
  18.429 -}
  18.430 -
  18.431 -bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename) {
  18.432 -    bool ok = true;
  18.433 -    message = slurp(message_fname);
  18.434 -    if (key_filename)
  18.435 -        ok = slurp_and_import_key(session, key_filename);
  18.436 -    return ok;
  18.437 -}
  18.438 -
  18.439 -
  18.440 -
  18.441 -int util_delete_filepath(const char *filepath, 
  18.442 -                         const struct stat *file_stat, 
  18.443 -                         int ftw_info, 
  18.444 -                         struct FTW * ftw_struct) {
  18.445 -    int retval = 0;
  18.446 -    switch (ftw_info) {
  18.447 -        case FTW_DP:
  18.448 -            retval = rmdir(filepath);
  18.449 -            break;
  18.450 -        case FTW_F:
  18.451 -        case FTW_SLN:
  18.452 -            retval = unlink(filepath);
  18.453 -            break;    
  18.454 -        default:
  18.455 -            retval = -1;
  18.456 -    }
  18.457 -    
  18.458 -    return retval;
  18.459 -}
    19.1 --- a/test/src/engine_tests/AppleMailTests.cc	Sat Mar 09 11:50:11 2019 +0100
    19.2 +++ b/test/src/engine_tests/AppleMailTests.cc	Fri Mar 15 12:43:56 2019 +0100
    19.3 @@ -17,7 +17,7 @@
    19.4  #include "keymanagement.h"
    19.5  #include "message_api.h"
    19.6  #include "mime.h"
    19.7 -#include "TestUtils.h" // for slurp()
    19.8 +#include "test_util.h" // for slurp()
    19.9  #include "TestConstants.h"
   19.10  
   19.11  #include "EngineTestSuite.h"
    20.1 --- a/test/src/engine_tests/BCCTests.cc	Sat Mar 09 11:50:11 2019 +0100
    20.2 +++ b/test/src/engine_tests/BCCTests.cc	Fri Mar 15 12:43:56 2019 +0100
    20.3 @@ -11,7 +11,7 @@
    20.4  #include "TestConstants.h"
    20.5  
    20.6  #include <cpptest.h>
    20.7 -#include "TestUtils.h"
    20.8 +#include "test_util.h"
    20.9  #include "EngineTestIndividualSuite.h"
   20.10  #include "BCCTests.h"
   20.11  
    21.1 --- a/test/src/engine_tests/BlacklistAcceptNewKeyTests.cc	Sat Mar 09 11:50:11 2019 +0100
    21.2 +++ b/test/src/engine_tests/BlacklistAcceptNewKeyTests.cc	Fri Mar 15 12:43:56 2019 +0100
    21.3 @@ -6,7 +6,7 @@
    21.4  #include <cstring> // for strcmp()
    21.5  #include <cpptest.h>
    21.6  
    21.7 -#include "TestUtils.h"
    21.8 +#include "test_util.h"
    21.9  #include "TestConstants.h"
   21.10  
   21.11  #include "pEpEngine.h"
    22.1 --- a/test/src/engine_tests/BlacklistTests.cc	Sat Mar 09 11:50:11 2019 +0100
    22.2 +++ b/test/src/engine_tests/BlacklistTests.cc	Fri Mar 15 12:43:56 2019 +0100
    22.3 @@ -9,7 +9,7 @@
    22.4  // #include <TEST_ASSERT.h>
    22.5  // #include "blacklist.h"
    22.6  // #include "keymanagement.h"
    22.7 -// #include "TestUtils.h"
    22.8 +// #include "test_util.h"
    22.9  // 
   22.10  // // This file is under GNU General Public License 3.0
   22.11  // // see LICENSE.txt
   22.12 @@ -26,7 +26,7 @@
   22.13  
   22.14  #include "blacklist.h"
   22.15  #include "keymanagement.h"
   22.16 -#include "TestUtils.h"
   22.17 +#include "test_util.h"
   22.18  #include "TestConstants.h"
   22.19  
   22.20  #include "EngineTestSessionSuite.h"
    23.1 --- a/test/src/engine_tests/CaseAndDotAddressTests.cc	Sat Mar 09 11:50:11 2019 +0100
    23.2 +++ b/test/src/engine_tests/CaseAndDotAddressTests.cc	Fri Mar 15 12:43:56 2019 +0100
    23.3 @@ -9,7 +9,7 @@
    23.4  #include <fstream>
    23.5  #include "mime.h"
    23.6  #include "message_api.h"
    23.7 -#include "TestUtils.h"
    23.8 +#include "test_util.h"
    23.9  #include "TestConstants.h"
   23.10  
   23.11  #include "EngineTestSuite.h"
    24.1 --- a/test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc	Sat Mar 09 11:50:11 2019 +0100
    24.2 +++ b/test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc	Fri Mar 15 12:43:56 2019 +0100
    24.3 @@ -9,7 +9,7 @@
    24.4  #include "pEpEngine.h"
    24.5  
    24.6  #include <cpptest.h>
    24.7 -#include "TestUtils.h"
    24.8 +#include "test_util.h"
    24.9  #include "EngineTestIndividualSuite.h"
   24.10  #include "CheckRenewedExpiredKeyTrustStatusTests.h"
   24.11  
    25.1 --- a/test/src/engine_tests/DecorateTests.cc	Sat Mar 09 11:50:11 2019 +0100
    25.2 +++ b/test/src/engine_tests/DecorateTests.cc	Fri Mar 15 12:43:56 2019 +0100
    25.3 @@ -14,7 +14,7 @@
    25.4  #include <sstream>
    25.5  #include "mime.h"
    25.6  #include "message_api.h"
    25.7 -#include "TestUtils.h"
    25.8 +#include "test_util.h"
    25.9  
   25.10  #include "EngineTestSuite.h"
   25.11  #include "EngineTestSessionSuite.h"
    26.1 --- a/test/src/engine_tests/DecryptAttachPrivateKeyTrustedTests.cc	Sat Mar 09 11:50:11 2019 +0100
    26.2 +++ b/test/src/engine_tests/DecryptAttachPrivateKeyTrustedTests.cc	Fri Mar 15 12:43:56 2019 +0100
    26.3 @@ -13,7 +13,7 @@
    26.4  #include "mime.h"
    26.5  #include "message_api.h"
    26.6  #include "keymanagement.h"
    26.7 -#include "TestUtils.h"
    26.8 +#include "test_util.h"
    26.9  
   26.10  #include "EngineTestSessionSuite.h"
   26.11  #include "DecryptAttachPrivateKeyTrustedTests.h"
    27.1 --- a/test/src/engine_tests/DecryptAttachPrivateKeyUntrustedTests.cc	Sat Mar 09 11:50:11 2019 +0100
    27.2 +++ b/test/src/engine_tests/DecryptAttachPrivateKeyUntrustedTests.cc	Fri Mar 15 12:43:56 2019 +0100
    27.3 @@ -10,7 +10,7 @@
    27.4  #include "mime.h"
    27.5  #include "message_api.h"
    27.6  #include "keymanagement.h"
    27.7 -#include "TestUtils.h"
    27.8 +#include "test_util.h"
    27.9  
   27.10  #include "pEpEngine.h"
   27.11  
    28.1 --- a/test/src/engine_tests/DeviceModelTests.cc	Sat Mar 09 11:50:11 2019 +0100
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,683 +0,0 @@
    28.4 -// This file is under GNU General Public License 3.0
    28.5 -// see LICENSE.txt
    28.6 -
    28.7 -#include <stdlib.h>
    28.8 -#include <string>
    28.9 -#include <sys/stat.h>
   28.10 -#include <errno.h>
   28.11 -#include <unistd.h>
   28.12 -#include <assert.h>
   28.13 -#include <fstream>
   28.14 -#include <iostream>
   28.15 -#include <sys/types.h>
   28.16 -
   28.17 -#include "pEpEngine.h"
   28.18 -#include "mime.h"
   28.19 -
   28.20 -#include "TestUtils.h"
   28.21 -#include "EngineTestIndividualSuite.h"
   28.22 -#include "DeviceModelTests.h"
   28.23 -#include <cpptest.h>
   28.24 -#include <cstring>
   28.25 -
   28.26 -using namespace std;
   28.27 -
   28.28 -static void remove_sync_mails(vector<message*> &mails) {
   28.29 -    for (vector<message*>::iterator it = mails.begin(); it != mails.end(); ) {
   28.30 -        stringpair_list_t* opt_fields = (*it)->opt_fields;
   28.31 -        bool erased = false;
   28.32 -        while (opt_fields && opt_fields->value && opt_fields->value->key && opt_fields->value->value) {
   28.33 -            if (strcmp(opt_fields->value->key, "pEp-auto-consume") == 0 &&
   28.34 -                strcmp(opt_fields->value->value, "yes") == 0) {
   28.35 -                it = mails.erase(it);
   28.36 -                erased = true;
   28.37 -            }
   28.38 -            opt_fields = opt_fields->next;
   28.39 -        }
   28.40 -        if (!erased)
   28.41 -            it++;
   28.42 -    }
   28.43 -}
   28.44 -
   28.45 -DeviceModelTests::DeviceModelTests(string suitename, string test_home_dir) :
   28.46 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir, false) {
   28.47 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeviceModelTests::check_device_model"),
   28.48 -                                                                      static_cast<Func>(&DeviceModelTests::check_device_model)));
   28.49 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeviceModelTests::check_two_device_model"),
   28.50 -                                                                      static_cast<Func>(&DeviceModelTests::check_two_device_model)));
   28.51 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeviceModelTests::check_two_device_functionality"),
   28.52 -                                                                      static_cast<Func>(&DeviceModelTests::check_two_device_functionality)));
   28.53 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeviceModelTests::check_mbox"),
   28.54 -                                                                      static_cast<Func>(&DeviceModelTests::check_mbox)));
   28.55 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeviceModelTests::check_three_device_mbox_with_send"),
   28.56 -                                                                      static_cast<Func>(&DeviceModelTests::check_three_device_mbox_with_send)));
   28.57 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeviceModelTests::check_switch_context"),
   28.58 -                                                                      static_cast<Func>(&DeviceModelTests::check_switch_context)));
   28.59 -}
   28.60 -
   28.61 -void DeviceModelTests::setup() {
   28.62 -    EngineTestIndividualSuite::setup();
   28.63 -    pEpTestDevice::active = NULL;
   28.64 -}
   28.65 -
   28.66 -void DeviceModelTests::tear_down() {
   28.67 -    for (vector<pEpTestDevice*>::iterator it = devices.begin();
   28.68 -                                         it != devices.end(); it++)
   28.69 -        delete(*it);                                         
   28.70 -    devices.clear();
   28.71 -    EngineTestIndividualSuite::tear_down();
   28.72 -}
   28.73 -
   28.74 -void DeviceModelTests::check_device_model() {
   28.75 -    pEpTestDevice* single = new pEpTestDevice(temp_test_home, "SingleDevice");
   28.76 -    TEST_ASSERT_MSG(device == NULL, "EngineTestSuite created device when it should not have.");
   28.77 -    TEST_ASSERT_MSG(session == NULL, "EngineTestSuite has a default session - not cool.");    
   28.78 -    TEST_ASSERT_MSG(single->session, "Device has no session.");
   28.79 -
   28.80 -    single->set_mailbox_dir(single->device_dir + "/mbox");
   28.81 -    const string mbox_dir = single->mbox_dir;
   28.82 -    struct stat dirchk;
   28.83 -    TEST_ASSERT_MSG(stat(mbox_dir.c_str(), &dirchk) == 0,
   28.84 -                    "Device mbox dir not created.");
   28.85 -    TEST_ASSERT_MSG(S_ISDIR(dirchk.st_mode), "Device mbox dir exists, but isn't a directory.");                
   28.86 -
   28.87 -    const string device_dir = string(single->device_dir);
   28.88 -    delete(single);
   28.89 -    TEST_ASSERT_MSG(stat(device_dir.c_str(), &dirchk) != 0,
   28.90 -                         "Device dir not removed.");
   28.91 -}
   28.92 -
   28.93 -void DeviceModelTests::check_two_device_model() {
   28.94 -    pEpTestDevice* first_device = new pEpTestDevice(temp_test_home, "First");
   28.95 -    devices.push_back(first_device);
   28.96 -    first_device->set_mailbox_dir(first_device->device_dir + "/mbox");
   28.97 -    string homedir = getenv("HOME");
   28.98 -    TEST_ASSERT_MSG(strcmp(homedir.c_str(), first_device->device_dir.c_str()) == 0, "First device didn't set $HOME correctly.");
   28.99 -    string gpgdir = getenv("GNUPGHOME");
  28.100 -    TEST_ASSERT_MSG(strcmp(gpgdir.c_str(), (first_device->device_dir + "/gnupg").c_str()) == 0, "First device didn't set $GNUPGHOME correctly.");    
  28.101 -
  28.102 -    pEpTestDevice* second_device = new pEpTestDevice(temp_test_home, "Second");
  28.103 -    devices.push_back(second_device);
  28.104 -    homedir = getenv("HOME");
  28.105 -    TEST_ASSERT_MSG(strcmp(homedir.c_str(), second_device->device_dir.c_str()) == 0, "Second device didn't set $HOME correctly");
  28.106 -    gpgdir = getenv("GNUPGHOME");
  28.107 -    TEST_ASSERT_MSG(strcmp(gpgdir.c_str(), (second_device->device_dir + "/gnupg").c_str()) == 0, "Second device didn't set $GNUPGHOME correctly.");    
  28.108 -    second_device->set_mailbox_dir(first_device->device_dir + "/mbox");
  28.109 -    first_device->grab_context(second_device);
  28.110 -    homedir = getenv("HOME");
  28.111 -    TEST_ASSERT_MSG(strcmp(homedir.c_str(), first_device->device_dir.c_str()) == 0, "First device failed to grab context.");
  28.112 -    gpgdir = getenv("GNUPGHOME");
  28.113 -    TEST_ASSERT_MSG(strcmp(gpgdir.c_str(), (first_device->device_dir + "/gnupg").c_str()) == 0, "First device context switch didn't set $GNUPGHOME correctly.");    
  28.114 -    second_device->grab_context(first_device);
  28.115 -    homedir = getenv("HOME");
  28.116 -    TEST_ASSERT_MSG(strcmp(homedir.c_str(), second_device->device_dir.c_str()) == 0, "Second device failed to grab context.");
  28.117 -    gpgdir = getenv("GNUPGHOME");
  28.118 -    TEST_ASSERT_MSG(strcmp(gpgdir.c_str(), (second_device->device_dir + "/gnupg").c_str()) == 0, "Second device context switch didn't set $GNUPGHOME correctly.");        
  28.119 -}
  28.120 -
  28.121 -void DeviceModelTests::check_two_device_functionality() {
  28.122 -    // Set up devices and shared mailbox
  28.123 -    pEpTestDevice* first_device = new pEpTestDevice(temp_test_home, "First");
  28.124 -    devices.push_back(first_device);    
  28.125 -    first_device->set_mailbox_dir(first_device->device_dir + "/mbox");
  28.126 -    
  28.127 -    pEpTestDevice* second_device = new pEpTestDevice(temp_test_home, "Second");
  28.128 -    devices.push_back(second_device);    
  28.129 -    second_device->set_mailbox_dir(first_device->device_dir + "/mbox");
  28.130 -
  28.131 -    first_device->grab_context(second_device);
  28.132 -    TEST_ASSERT_MSG(first_device->mbox_dir.compare(second_device->mbox_dir) == 0,
  28.133 -                    "Shared mailbox is not really shared");
  28.134 -
  28.135 -    string alice_email = "pep.test.alice@pep-project.org";
  28.136 -    string alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
  28.137 -    
  28.138 -    // First device is Alice's established one with the current key
  28.139 -    TEST_ASSERT_MSG(slurp_and_import_key(first_device->session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"),
  28.140 -                    "Alice's pubkey not imported for first device.");
  28.141 -    TEST_ASSERT_MSG(slurp_and_import_key(first_device->session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc"),
  28.142 -                    "Alice's privkey not imported for first device.");
  28.143 -
  28.144 -    pEp_identity* alice_dev_1_ident = new_identity(alice_email.c_str(), alice_fpr.c_str(), "ALICE", "Alice From Mel's Diner");
  28.145 -    
  28.146 -    PEP_STATUS status = set_own_key(first_device->session, alice_dev_1_ident, alice_fpr.c_str());    
  28.147 -    TEST_ASSERT_MSG(status == PEP_STATUS_OK, 
  28.148 -        (string("Unable to set own key on first device. status is ") + tl_status_string(status)).c_str());
  28.149 -
  28.150 -    free(alice_dev_1_ident->fpr);
  28.151 -    alice_dev_1_ident->fpr = NULL;
  28.152 -    status = myself(first_device->session, alice_dev_1_ident);
  28.153 -    TEST_ASSERT(alice_dev_1_ident->fpr);
  28.154 -    TEST_ASSERT_MSG(alice_fpr.compare(alice_dev_1_ident->fpr) == 0,
  28.155 -                    "set_own_key does not seem to have set alice's key for device 1.");
  28.156 -                
  28.157 -    second_device->grab_context(first_device);
  28.158 -
  28.159 -    pEp_identity* alice_dev_2_ident = new_identity(alice_email.c_str(), NULL, PEP_OWN_USERID, "Alice Miller");
  28.160 -    // Second device is one Alice is setting up (we'll use this model for keysync tests, so why not?)
  28.161 -
  28.162 -    status = myself(second_device->session, alice_dev_2_ident);
  28.163 -
  28.164 -    TEST_ASSERT_MSG(alice_dev_2_ident->fpr, "No fpr for alice on second device");
  28.165 -    TEST_ASSERT_MSG(alice_fpr.compare(alice_dev_2_ident->fpr) != 0,
  28.166 -                    "myself did not generate new key for alice on device 2; alice's old key was found.");
  28.167 -    
  28.168 -    const char* alice_2_fpr = alice_dev_2_ident->fpr;
  28.169 -    
  28.170 -    first_device->grab_context(second_device);
  28.171 -    
  28.172 -    stringlist_t* keylist = NULL;
  28.173 -    
  28.174 -    status = find_keys(first_device->session, alice_2_fpr, &keylist);
  28.175 -    
  28.176 -    TEST_ASSERT(!keylist);
  28.177 -    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  28.178 -    free_stringlist(keylist);
  28.179 -    keylist = NULL;
  28.180 -
  28.181 -    second_device->grab_context(first_device);
  28.182 -    
  28.183 -    char* alice_2_keydata = NULL;
  28.184 -    size_t alice_2_keydata_size = 0;
  28.185 -    
  28.186 -    status = export_key(second_device->session, alice_2_fpr, &alice_2_keydata, &alice_2_keydata_size);
  28.187 -
  28.188 -    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  28.189 -    TEST_ASSERT(alice_2_keydata);
  28.190 -    
  28.191 -    first_device->grab_context(second_device);
  28.192 -
  28.193 -    status = import_key(first_device->session, alice_2_keydata, alice_2_keydata_size, NULL);
  28.194 -
  28.195 -    free(alice_2_keydata);
  28.196 -    alice_2_keydata = NULL;
  28.197 -
  28.198 -    status = find_keys(first_device->session, alice_2_fpr, &keylist);    
  28.199 -    TEST_ASSERT(keylist);
  28.200 -    TEST_ASSERT(status == PEP_STATUS_OK);
  28.201 -    free_stringlist(keylist);
  28.202 -    keylist = NULL;
  28.203 -
  28.204 -    second_device->grab_context(first_device);
  28.205 -    TEST_ASSERT_MSG(slurp_and_import_key(second_device->session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"),
  28.206 -                    "Alice's first pubkey not imported for second device.");
  28.207 -
  28.208 -    // Ok, so, we're relatively certain we have all that set up. Now let's have both
  28.209 -    // import Bob's key, but only one of them trust it. Then we're sure we have 
  28.210 -    // different, functioning trust dbs, and we're done with this case and ready 
  28.211 -    // to move on to checking mboxes
  28.212 -    string bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
  28.213 -    TEST_ASSERT_MSG(slurp_and_import_key(second_device->session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"), 
  28.214 -                    "Second device couldn't import Bob's pubkey");
  28.215 -    pEp_identity* bob_id = new_identity("pep.test.bob@pep-project.org", NULL, NULL, "Bob Barker");    
  28.216 -    status = update_identity(second_device->session, bob_id);
  28.217 -    TEST_ASSERT(status == PEP_STATUS_OK);
  28.218 -    TEST_ASSERT(bob_id->fpr);
  28.219 -    TEST_ASSERT(bob_fpr.compare(bob_id->fpr) == 0);
  28.220 -
  28.221 -    status = trust_personal_key(second_device->session, bob_id);
  28.222 -    TEST_ASSERT(status == PEP_STATUS_OK);
  28.223 -    status = update_identity(second_device->session, bob_id);
  28.224 -    TEST_ASSERT(status == PEP_STATUS_OK);
  28.225 -    TEST_ASSERT(bob_id->comm_type == PEP_ct_OpenPGP);    
  28.226 -    
  28.227 -    first_device->grab_context(second_device);
  28.228 -    TEST_ASSERT_MSG(slurp_and_import_key(first_device->session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"), 
  28.229 -                    "First device couldn't import Bob's pubkey");
  28.230 -    pEp_identity* bob_id_2 = new_identity("pep.test.bob@pep-project.org", NULL, NULL, "Bob Barker");    
  28.231 -    status = update_identity(first_device->session, bob_id_2);
  28.232 -    TEST_ASSERT(status == PEP_STATUS_OK);
  28.233 -    TEST_ASSERT(bob_id_2->comm_type == PEP_ct_OpenPGP_unconfirmed);    
  28.234 -
  28.235 -    free_identity(alice_dev_1_ident);                  
  28.236 -    free_identity(alice_dev_2_ident);
  28.237 -    free_identity(bob_id);
  28.238 -    free_identity(bob_id_2);              
  28.239 -}
  28.240 -
  28.241 -void DeviceModelTests::check_mbox() {
  28.242 -    // Set up devices and shared mailbox
  28.243 -    pEpTestDevice* first_device = new pEpTestDevice(temp_test_home, "Device");
  28.244 -    devices.push_back(first_device);
  28.245 -    
  28.246 -    first_device->set_mailbox_dir(first_device->device_dir + "/mbox");
  28.247 -
  28.248 -    string alice_email = "pep.test.alice@pep-project.org";
  28.249 -    string alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
  28.250 -    
  28.251 -    slurp_and_import_key(first_device->session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
  28.252 -    slurp_and_import_key(first_device->session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
  28.253 -    
  28.254 -    pEp_identity* alice_ident = new_identity(alice_email.c_str(), alice_fpr.c_str(), "ALICE", "Alice From Mel's Diner");    
  28.255 -    PEP_STATUS status = set_own_key(first_device->session, alice_ident, alice_fpr.c_str());    
  28.256 -    TEST_ASSERT_MSG(status == PEP_STATUS_OK, 
  28.257 -        (string("Unable to set own key. status is ") + tl_status_string(status)).c_str());
  28.258 -        
  28.259 -    message* new_msg = new_message(PEP_dir_outgoing);
  28.260 -    
  28.261 -    new_msg->from = alice_ident;
  28.262 -    new_msg->to = new_identity_list(identity_dup(alice_ident));
  28.263 -    new_msg->longmsg = strdup("Some dumb message.\nBlahblahblah.");
  28.264 -    new_msg->shortmsg = strdup("hello, world");
  28.265 -    new_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  28.266 -
  28.267 -    message* enc_msg = NULL;
  28.268 -    
  28.269 -    status = encrypt_message(first_device->session, new_msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  28.270 -
  28.271 -    TEST_ASSERT(status == PEP_STATUS_OK);
  28.272 -    TEST_ASSERT(enc_msg);
  28.273 -    char* msg_text = NULL;
  28.274 -    mime_encode_message(enc_msg, false, &msg_text);
  28.275 -    TEST_ASSERT(msg_text);
  28.276 -    
  28.277 -    string filename = first_device->receive_mail(msg_text);
  28.278 -    TEST_ASSERT(!filename.empty());
  28.279 -
  28.280 -    vector<string> curr_mail_received;
  28.281 -    first_device->check_mail(curr_mail_received);
  28.282 -    TEST_ASSERT_MSG(curr_mail_received.size() == 1, 
  28.283 -                    (string("Received ") + to_string(curr_mail_received.size()) + " emails, should have received 1.").c_str());
  28.284 -
  28.285 -    first_device->receive_mail(msg_text);
  28.286 -    first_device->receive_mail(msg_text);
  28.287 -    first_device->receive_mail(msg_text);
  28.288 -    first_device->check_mail(curr_mail_received);
  28.289 -    TEST_ASSERT_MSG(curr_mail_received.size() == 3, 
  28.290 -                    (string("Received ") + to_string(curr_mail_received.size()) + " emails, should have received 3.").c_str());
  28.291 -    
  28.292 -    first_device->receive_mail(msg_text);
  28.293 -    first_device->receive_mail(msg_text);
  28.294 -    first_device->check_mail(curr_mail_received);
  28.295 -    TEST_ASSERT_MSG(curr_mail_received.size() == 2, 
  28.296 -                    (string("Received ") + to_string(curr_mail_received.size()) + " emails, should have received 2.").c_str());
  28.297 -}
  28.298 -
  28.299 -void DeviceModelTests::check_three_device_mbox_with_send() {
  28.300 -    try {
  28.301 -        // Set up devices and shared mailbox
  28.302 -        pEpTestDevice* first_device = new pEpTestDevice(temp_test_home, "Alex");
  28.303 -        devices.push_back(first_device);    
  28.304 -        first_device->set_mailbox_dir(first_device->device_dir + "/mbox");
  28.305 -        string alex_email = "alex@darthmama.cool";
  28.306 -        pEp_identity* alex_identity = new_identity(alex_email.c_str(), NULL, "AlexID", "Alex Braithwaite");
  28.307 -        PEP_STATUS status = myself(first_device->session, alex_identity);
  28.308 -        
  28.309 -        pEpTestDevice* second_device = new pEpTestDevice(temp_test_home, "Bree");
  28.310 -        devices.push_back(second_device);    
  28.311 -        second_device->set_mailbox_dir(second_device->device_dir + "/mbox");
  28.312 -        string bree_email = "bree@cheese.melted";
  28.313 -        pEp_identity* bree_identity = new_identity(bree_email.c_str(), NULL, "BreeID", "Briana Cheeserton");
  28.314 -        status = myself(second_device->session, bree_identity);
  28.315 -        
  28.316 -        pEpTestDevice* third_device = new pEpTestDevice(temp_test_home, "Charmander");
  28.317 -        devices.push_back(third_device);    
  28.318 -        third_device->set_mailbox_dir(third_device->device_dir + "/mbox");
  28.319 -        string charm_email = "charmander@poke.mon";
  28.320 -        pEp_identity* charm_identity = new_identity(charm_email.c_str(), NULL, "CharmID", "Charmander T. Pokemon");
  28.321 -        status = myself(third_device->session, charm_identity);
  28.322 -        first_device->grab_context(third_device);
  28.323 -
  28.324 -        map<string,string> address_maps = {
  28.325 -            {alex_email,first_device->mbox_dir},
  28.326 -            {bree_email,second_device->mbox_dir},
  28.327 -            {charm_email,third_device->mbox_dir},
  28.328 -        };
  28.329 -
  28.330 -        // this just simulates the ability to address and deliver, so everyone has
  28.331 -        // the same maps.
  28.332 -        first_device->address_to_mbox_map = second_device->address_to_mbox_map =
  28.333 -            third_device->address_to_mbox_map = address_maps;
  28.334 -        // Note to self - I'll bet this is some C++ mem nightmare.
  28.335 -        
  28.336 -        message* msg = new_message(PEP_dir_outgoing);
  28.337 -        msg->from = identity_dup(alex_identity);
  28.338 -        msg->to = new_identity_list(new_identity(bree_email.c_str(), NULL, "ItsBree", "Bree Cheeserton"));
  28.339 -        msg->shortmsg = strdup("First test message!");
  28.340 -        msg->longmsg = strdup("Yo Bree! This is Alex! Hi!\nEr, hi!\n");
  28.341 -        msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  28.342 -
  28.343 -        // engine_passthrough
  28.344 -        message* enc_msg = NULL;
  28.345 -        status = encrypt_message(first_device->session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  28.346 -        TEST_ASSERT(status == PEP_UNENCRYPTED);
  28.347 -        TEST_ASSERT(enc_msg == NULL);
  28.348 -
  28.349 -        // when sent, msg is freed, so do NOT free it after this.
  28.350 -        first_device->add_message_to_send_queue(msg);
  28.351 -        second_device->grab_context(first_device);
  28.352 -        msg = NULL;
  28.353 -        
  28.354 -        vector<string> inbox_list;
  28.355 -        second_device->check_mail(inbox_list);
  28.356 -
  28.357 -        vector<message*> inbox_mails;
  28.358 -        stringlist_t* keylist = NULL;
  28.359 -        PEP_rating rating;
  28.360 -        PEP_decrypt_flags_t flags;
  28.361 -        
  28.362 -        second_device->read_mail(inbox_list, inbox_mails);
  28.363 -        remove_sync_mails(inbox_mails);
  28.364 -        TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
  28.365 -        
  28.366 -        // Get Alex's key
  28.367 -        status = decrypt_message(second_device->session,
  28.368 -                                 inbox_mails.at(0), &msg, &keylist,
  28.369 -                                 &rating, &flags);
  28.370 -        TEST_ASSERT(status == PEP_UNENCRYPTED);
  28.371 -        TEST_ASSERT(msg == NULL);
  28.372 -
  28.373 -        inbox_list.clear();
  28.374 -        free(inbox_mails.at(0));
  28.375 -        inbox_mails.clear();
  28.376 -        
  28.377 -        third_device->grab_context(second_device);
  28.378 -            
  28.379 -        msg = new_message(PEP_dir_outgoing);
  28.380 -        msg->from = identity_dup(charm_identity);
  28.381 -        msg->to = new_identity_list(new_identity(bree_email.c_str(), NULL, "SuperBree", "Bree Cheeserton"));
  28.382 -        msg->shortmsg = strdup("First test message!");
  28.383 -        msg->longmsg = strdup("Yo Bree! This is Charmander! I'm a cool Pokemon! Hi!\nEr, hi!\n");
  28.384 -        msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  28.385 -
  28.386 -        // engine_passthrough
  28.387 -        enc_msg = NULL;
  28.388 -        status = encrypt_message(third_device->session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  28.389 -        TEST_ASSERT(status == PEP_UNENCRYPTED);
  28.390 -        TEST_ASSERT(enc_msg == NULL);
  28.391 -
  28.392 -        // when sent, msg is freed, so do NOT free it after this.
  28.393 -        third_device->add_message_to_send_queue(msg);
  28.394 -        second_device->grab_context(third_device);
  28.395 -        msg = NULL;
  28.396 -            
  28.397 -        second_device->check_mail(inbox_list);
  28.398 -            
  28.399 -        keylist = NULL;
  28.400 -        flags = 0;
  28.401 -        
  28.402 -        second_device->read_mail(inbox_list, inbox_mails);
  28.403 -        
  28.404 -        remove_sync_mails(inbox_mails);
  28.405 -        
  28.406 -        TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
  28.407 -        
  28.408 -        // Get Charmander's key
  28.409 -        status = decrypt_message(second_device->session,
  28.410 -                                 inbox_mails.at(0), &msg, &keylist,
  28.411 -                                 &rating, &flags);
  28.412 -        TEST_ASSERT(status == PEP_UNENCRYPTED);
  28.413 -        TEST_ASSERT(msg == NULL);
  28.414 -
  28.415 -        inbox_list.clear();
  28.416 -        free(inbox_mails.at(0));
  28.417 -        inbox_mails.clear();    
  28.418 -
  28.419 -        // Ok, now, revenge of encrypting Bree
  28.420 -        msg = new_message(PEP_dir_outgoing);
  28.421 -        msg->from = identity_dup(bree_identity);
  28.422 -        msg->to = new_identity_list(new_identity(alex_email.c_str(), NULL, "Alexei", "Alex Braithwaite is a char in a bad novel"));
  28.423 -        identity_list_add(msg->to, new_identity(charm_email.c_str(), NULL, "Charming", "Charmanderpoke E. Mon is NOT a Pokemon"));
  28.424 -        msg->shortmsg = strdup("Last test message!");
  28.425 -        msg->longmsg = strdup("You guys are fools :)\n");
  28.426 -        msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  28.427 -
  28.428 -        enc_msg = NULL;
  28.429 -        status = encrypt_message(second_device->session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  28.430 -        TEST_ASSERT(status == PEP_STATUS_OK);
  28.431 -        TEST_ASSERT(enc_msg);
  28.432 -         
  28.433 -        free_message(msg);
  28.434 -        msg = NULL;
  28.435 -        free_stringlist(keylist);
  28.436 -        flags = 0;
  28.437 -        keylist = NULL;
  28.438 -        
  28.439 -        // when sent, enc_msg is freed, so do NOT free it after this.
  28.440 -        second_device->add_message_to_send_queue(enc_msg);
  28.441 -        first_device->grab_context(second_device);
  28.442 -        enc_msg = NULL;
  28.443 -
  28.444 -        first_device->check_mail(inbox_list);            
  28.445 -        first_device->read_mail(inbox_list, inbox_mails);
  28.446 -        remove_sync_mails(inbox_mails);
  28.447 -        TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
  28.448 -        
  28.449 -        status = decrypt_message(first_device->session,
  28.450 -                                 inbox_mails.at(0), &msg, &keylist,
  28.451 -                                 &rating, &flags);
  28.452 -        TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  28.453 -        TEST_ASSERT_MSG(rating == PEP_rating_reliable, tl_rating_string(rating));
  28.454 -        TEST_ASSERT(msg);
  28.455 -
  28.456 -        free_message(msg);
  28.457 -        inbox_list.clear();
  28.458 -        free(inbox_mails.at(0));
  28.459 -        inbox_mails.clear();    
  28.460 -
  28.461 -        msg = NULL;
  28.462 -        free_stringlist(keylist);
  28.463 -        flags = 0;
  28.464 -        keylist = NULL;
  28.465 -        
  28.466 -        third_device->grab_context(first_device);
  28.467 -
  28.468 -        third_device->check_mail(inbox_list);
  28.469 -            
  28.470 -        third_device->read_mail(inbox_list, inbox_mails);
  28.471 -        remove_sync_mails(inbox_mails);
  28.472 -
  28.473 -        TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
  28.474 -        
  28.475 -        status = decrypt_message(third_device->session,
  28.476 -                                 inbox_mails.at(0), &msg, &keylist,
  28.477 -                                 &rating, &flags);
  28.478 -        TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  28.479 -        TEST_ASSERT_MSG(rating == PEP_rating_reliable, tl_rating_string(rating));
  28.480 -        TEST_ASSERT(msg);
  28.481 -
  28.482 -        free_message(msg);
  28.483 -        inbox_list.clear();
  28.484 -        free(inbox_mails.at(0));
  28.485 -        inbox_mails.clear();    
  28.486 -        free_stringlist(keylist);
  28.487 -    }
  28.488 -    catch (const runtime_error& error) {
  28.489 -        TEST_ASSERT_MSG(false, error.what());
  28.490 -    }
  28.491 -}
  28.492 -
  28.493 -void DeviceModelTests::check_switch_context() {
  28.494 -    try {
  28.495 -        // Set up devices and shared mailbox
  28.496 -        pEpTestDevice* first_device = new pEpTestDevice(temp_test_home, "Alex");
  28.497 -        devices.push_back(first_device);    
  28.498 -        first_device->set_mailbox_dir(first_device->device_dir + "/mbox");
  28.499 -        string alex_email = "alex@darthmama.cool";
  28.500 -        pEp_identity* alex_identity = new_identity(alex_email.c_str(), NULL, "AlexID", "Alex Braithwaite");
  28.501 -        PEP_STATUS status = myself(first_device->session, alex_identity);
  28.502 -        
  28.503 -        pEpTestDevice* second_device = new pEpTestDevice(temp_test_home, "Bree");
  28.504 -        devices.push_back(second_device);    
  28.505 -        second_device->set_mailbox_dir(second_device->device_dir + "/mbox");
  28.506 -        string bree_email = "bree@cheese.melted";
  28.507 -        pEp_identity* bree_identity = new_identity(bree_email.c_str(), NULL, "BreeID", "Briana Cheeserton");
  28.508 -        status = myself(second_device->session, bree_identity);
  28.509 -        
  28.510 -        pEpTestDevice* third_device = new pEpTestDevice(temp_test_home, "Charmander");
  28.511 -        devices.push_back(third_device);    
  28.512 -        third_device->set_mailbox_dir(third_device->device_dir + "/mbox");
  28.513 -        string charm_email = "charmander@poke.mon";
  28.514 -        pEp_identity* charm_identity = new_identity(charm_email.c_str(), NULL, "CharmID", "Charmander T. Pokemon");
  28.515 -        status = myself(third_device->session, charm_identity);
  28.516 -        
  28.517 -        pEpTestDevice::switch_context(first_device);
  28.518 -
  28.519 -        map<string,string> address_maps = {
  28.520 -            {alex_email,first_device->mbox_dir},
  28.521 -            {bree_email,second_device->mbox_dir},
  28.522 -            {charm_email,third_device->mbox_dir},
  28.523 -        };
  28.524 -
  28.525 -        // this just simulates the ability to address and deliver, so everyone has
  28.526 -        // the same maps.
  28.527 -        first_device->address_to_mbox_map = second_device->address_to_mbox_map =
  28.528 -            third_device->address_to_mbox_map = address_maps;
  28.529 -        // Note to self - I'll bet this is some C++ mem nightmare.
  28.530 -        
  28.531 -        message* msg = new_message(PEP_dir_outgoing);
  28.532 -        msg->from = identity_dup(alex_identity);
  28.533 -        msg->to = new_identity_list(new_identity(bree_email.c_str(), NULL, "ItsBree", "Bree Cheeserton"));
  28.534 -        msg->shortmsg = strdup("First test message!");
  28.535 -        msg->longmsg = strdup("Yo Bree! This is Alex! Hi!\nEr, hi!\n");
  28.536 -        msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  28.537 -
  28.538 -        // engine_passthrough
  28.539 -        message* enc_msg = NULL;
  28.540 -        status = encrypt_message(pEpTestDevice::active->session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  28.541 -        TEST_ASSERT(status == PEP_UNENCRYPTED);
  28.542 -        TEST_ASSERT(enc_msg == NULL);
  28.543 -
  28.544 -        // when sent, msg is freed, so do NOT free it after this.
  28.545 -        pEpTestDevice::active->add_message_to_send_queue(msg);
  28.546 -        pEpTestDevice::switch_context(second_device);
  28.547 -
  28.548 -        msg = NULL;
  28.549 -        
  28.550 -        vector<string> inbox_list;
  28.551 -        pEpTestDevice::active->check_mail(inbox_list);
  28.552 -
  28.553 -        vector<message*> inbox_mails;
  28.554 -        stringlist_t* keylist = NULL;
  28.555 -        PEP_rating rating;
  28.556 -        PEP_decrypt_flags_t flags;
  28.557 -        pEpTestDevice::active->read_mail(inbox_list, inbox_mails);
  28.558 -        remove_sync_mails(inbox_mails);
  28.559 -
  28.560 -        TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
  28.561 -        
  28.562 -        // Get Alex's key
  28.563 -        status = decrypt_message(pEpTestDevice::active->session,
  28.564 -                                 inbox_mails.at(0), &msg, &keylist,
  28.565 -                                 &rating, &flags);
  28.566 -        TEST_ASSERT(status == PEP_UNENCRYPTED);
  28.567 -        TEST_ASSERT(msg == NULL);
  28.568 -
  28.569 -        inbox_list.clear();
  28.570 -        free(inbox_mails.at(0));
  28.571 -        inbox_mails.clear();
  28.572 -        
  28.573 -        pEpTestDevice::switch_context(third_device);
  28.574 -            
  28.575 -        msg = new_message(PEP_dir_outgoing);
  28.576 -        msg->from = identity_dup(charm_identity);
  28.577 -        msg->to = new_identity_list(new_identity(bree_email.c_str(), NULL, "SuperBree", "Bree Cheeserton"));
  28.578 -        msg->shortmsg = strdup("First test message!");
  28.579 -        msg->longmsg = strdup("Yo Bree! This is Charmander! I'm a cool Pokemon! Hi!\nEr, hi!\n");
  28.580 -        msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  28.581 -
  28.582 -        // engine_passthrough
  28.583 -        enc_msg = NULL;
  28.584 -        status = encrypt_message(pEpTestDevice::active->session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  28.585 -        TEST_ASSERT(status == PEP_UNENCRYPTED);
  28.586 -        TEST_ASSERT(enc_msg == NULL);
  28.587 -
  28.588 -        // when sent, msg is freed, so do NOT free it after this.
  28.589 -        pEpTestDevice::active->add_message_to_send_queue(msg);
  28.590 -
  28.591 -        pEpTestDevice::switch_context(second_device);
  28.592 -        msg = NULL;
  28.593 -            
  28.594 -        pEpTestDevice::active->check_mail(inbox_list);    
  28.595 -        keylist = NULL;
  28.596 -        flags = 0;
  28.597 -        pEpTestDevice::active->read_mail(inbox_list, inbox_mails);
  28.598 -        remove_sync_mails(inbox_mails);
  28.599 -
  28.600 -        TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
  28.601 -        
  28.602 -        // Get Charmander's key
  28.603 -        status = decrypt_message(pEpTestDevice::active->session,
  28.604 -                                 inbox_mails.at(0), &msg, &keylist,
  28.605 -                                 &rating, &flags);
  28.606 -        TEST_ASSERT(status == PEP_UNENCRYPTED);
  28.607 -        TEST_ASSERT(msg == NULL);
  28.608 -
  28.609 -        inbox_list.clear();
  28.610 -        free(inbox_mails.at(0));
  28.611 -        inbox_mails.clear();    
  28.612 -
  28.613 -        // Ok, now, revenge of encrypting Bree
  28.614 -        msg = new_message(PEP_dir_outgoing);
  28.615 -        msg->from = identity_dup(bree_identity);
  28.616 -        msg->to = new_identity_list(new_identity(alex_email.c_str(), NULL, "Alexei", "Alex Braithwaite is a char in a bad novel"));
  28.617 -        identity_list_add(msg->to, new_identity(charm_email.c_str(), NULL, "Charming", "Charmanderpoke E. Mon is NOT a Pokemon"));
  28.618 -        msg->shortmsg = strdup("Last test message!");
  28.619 -        msg->longmsg = strdup("You guys are fools :)\n");
  28.620 -        msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
  28.621 -
  28.622 -        enc_msg = NULL;
  28.623 -        status = encrypt_message(pEpTestDevice::active->session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
  28.624 -        TEST_ASSERT(status == PEP_STATUS_OK);
  28.625 -        TEST_ASSERT(enc_msg);
  28.626 -         
  28.627 -        free_message(msg);
  28.628 -        msg = NULL;
  28.629 -        free_stringlist(keylist);
  28.630 -        flags = 0;
  28.631 -        keylist = NULL;
  28.632 -        
  28.633 -        // when sent, enc_msg is freed, so do NOT free it after this.
  28.634 -        pEpTestDevice::active->add_message_to_send_queue(enc_msg);
  28.635 -
  28.636 -        pEpTestDevice::switch_context(first_device);
  28.637 -                
  28.638 -        enc_msg = NULL;
  28.639 -
  28.640 -        pEpTestDevice::active->check_mail(inbox_list);
  28.641 -            
  28.642 -        pEpTestDevice::active->read_mail(inbox_list, inbox_mails);
  28.643 -        remove_sync_mails(inbox_mails);
  28.644 -        TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
  28.645 -        
  28.646 -        status = decrypt_message(pEpTestDevice::active->session,
  28.647 -                                 inbox_mails.at(0), &msg, &keylist,
  28.648 -                                 &rating, &flags);
  28.649 -        TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  28.650 -        TEST_ASSERT_MSG(rating == PEP_rating_reliable, tl_rating_string(rating));
  28.651 -        TEST_ASSERT(msg);
  28.652 -
  28.653 -        free_message(msg);
  28.654 -        inbox_list.clear();
  28.655 -        free(inbox_mails.at(0));
  28.656 -        inbox_mails.clear();    
  28.657 -
  28.658 -        msg = NULL;
  28.659 -        free_stringlist(keylist);
  28.660 -        flags = 0;
  28.661 -        keylist = NULL;
  28.662 -        
  28.663 -        pEpTestDevice::switch_context(third_device);
  28.664 -
  28.665 -        pEpTestDevice::active->check_mail(inbox_list);
  28.666 -        pEpTestDevice::active->read_mail(inbox_list, inbox_mails);
  28.667 -        remove_sync_mails(inbox_mails);
  28.668 -        TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
  28.669 -        
  28.670 -        status = decrypt_message(pEpTestDevice::active->session,
  28.671 -                                 inbox_mails.at(0), &msg, &keylist,
  28.672 -                                 &rating, &flags);
  28.673 -        TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
  28.674 -        TEST_ASSERT_MSG(rating == PEP_rating_reliable, tl_rating_string(rating));
  28.675 -        TEST_ASSERT(msg);
  28.676 -
  28.677 -        free_message(msg);
  28.678 -        inbox_list.clear();
  28.679 -        free(inbox_mails.at(0));
  28.680 -        inbox_mails.clear();    
  28.681 -        free_stringlist(keylist);
  28.682 -    }
  28.683 -    catch (const runtime_error& error) {
  28.684 -        TEST_ASSERT_MSG(false, error.what());
  28.685 -    }
  28.686 -}
    29.1 --- a/test/src/engine_tests/EncryptAttachPrivateKeyTests.cc	Sat Mar 09 11:50:11 2019 +0100
    29.2 +++ b/test/src/engine_tests/EncryptAttachPrivateKeyTests.cc	Fri Mar 15 12:43:56 2019 +0100
    29.3 @@ -12,7 +12,7 @@
    29.4  #include "mime.h"
    29.5  #include "message_api.h"
    29.6  #include "keymanagement.h"
    29.7 -#include "TestUtils.h"
    29.8 +#include "test_util.h"
    29.9  
   29.10  #include "EngineTestSessionSuite.h"
   29.11  #include "EncryptAttachPrivateKeyTests.h"
    30.1 --- a/test/src/engine_tests/EncryptForIdentityTests.cc	Sat Mar 09 11:50:11 2019 +0100
    30.2 +++ b/test/src/engine_tests/EncryptForIdentityTests.cc	Fri Mar 15 12:43:56 2019 +0100
    30.3 @@ -13,7 +13,7 @@
    30.4  #include "mime.h"
    30.5  #include "message_api.h"
    30.6  #include "keymanagement.h"
    30.7 -#include "TestUtils.h"
    30.8 +#include "test_util.h"
    30.9  
   30.10  #include <cpptest.h>
   30.11  #include "EngineTestSessionSuite.h"
    31.1 --- a/test/src/engine_tests/EncryptMissingPrivateKeyTests.cc	Sat Mar 09 11:50:11 2019 +0100
    31.2 +++ b/test/src/engine_tests/EncryptMissingPrivateKeyTests.cc	Fri Mar 15 12:43:56 2019 +0100
    31.3 @@ -14,7 +14,7 @@
    31.4  #include "keymanagement.h"
    31.5  #include "message_api.h"
    31.6  #include "mime.h"
    31.7 -#include "TestUtils.h"
    31.8 +#include "test_util.h"
    31.9  
   31.10  #include "pEpEngine.h"
   31.11  
    32.1 --- a/test/src/engine_tests/Engine358Tests.cc	Sat Mar 09 11:50:11 2019 +0100
    32.2 +++ b/test/src/engine_tests/Engine358Tests.cc	Fri Mar 15 12:43:56 2019 +0100
    32.3 @@ -9,7 +9,7 @@
    32.4  
    32.5  #include "pEpEngine.h"
    32.6  
    32.7 -#include "TestUtils.h"
    32.8 +#include "test_util.h"
    32.9  #include "EngineTestIndividualSuite.h"
   32.10  #include "Engine358Tests.h"
   32.11  
    33.1 --- a/test/src/engine_tests/Engine463Tests.cc	Sat Mar 09 11:50:11 2019 +0100
    33.2 +++ b/test/src/engine_tests/Engine463Tests.cc	Fri Mar 15 12:43:56 2019 +0100
    33.3 @@ -7,7 +7,7 @@
    33.4  
    33.5  #include "pEpEngine.h"
    33.6  #include "pEp_internal.h"
    33.7 -#include "TestUtils.h"
    33.8 +#include "test_util.h"
    33.9  #include "message.h"
   33.10  
   33.11  #include "EngineTestIndividualSuite.h"
    34.1 --- a/test/src/engine_tests/ExpiredSubkeyTests.cc	Sat Mar 09 11:50:11 2019 +0100
    34.2 +++ b/test/src/engine_tests/ExpiredSubkeyTests.cc	Fri Mar 15 12:43:56 2019 +0100
    34.3 @@ -5,7 +5,7 @@
    34.4  #include <stdlib.h>
    34.5  #include <string>
    34.6  #include <cpptest.h>
    34.7 -#include "TestUtils.h"
    34.8 +#include "test_util.h"
    34.9  
   34.10  #include "pEpEngine.h"
   34.11  
    35.1 --- a/test/src/engine_tests/ExternalRevokeTests.cc	Sat Mar 09 11:50:11 2019 +0100
    35.2 +++ b/test/src/engine_tests/ExternalRevokeTests.cc	Fri Mar 15 12:43:56 2019 +0100
    35.3 @@ -11,7 +11,7 @@
    35.4  #include <fstream>
    35.5  #include "mime.h"
    35.6  #include "message_api.h"
    35.7 -#include "TestUtils.h"
    35.8 +#include "test_util.h"
    35.9  
   35.10  #include "pEpEngine.h"
   35.11  
    36.1 --- a/test/src/engine_tests/HeaderKeyImportTests.cc	Sat Mar 09 11:50:11 2019 +0100
    36.2 +++ b/test/src/engine_tests/HeaderKeyImportTests.cc	Fri Mar 15 12:43:56 2019 +0100
    36.3 @@ -12,7 +12,7 @@
    36.4  #include "bloblist.h"
    36.5  #include "base64.h"
    36.6  
    36.7 -#include "TestUtils.h"
    36.8 +#include "test_util.h"
    36.9  #include "EngineTestIndividualSuite.h"
   36.10  #include "HeaderKeyImportTests.h"
   36.11  
    37.1 --- a/test/src/engine_tests/IntegrityTests.do.not.run.before.ENGINE-434	Sat Mar 09 11:50:11 2019 +0100
    37.2 +++ b/test/src/engine_tests/IntegrityTests.do.not.run.before.ENGINE-434	Fri Mar 15 12:43:56 2019 +0100
    37.3 @@ -9,7 +9,7 @@
    37.4  #include "pEpEngine.h"
    37.5  #include "message_api.h"
    37.6  
    37.7 -#include "TestUtils.h"
    37.8 +#include "test_util.h"
    37.9  
   37.10  #include "EngineTestIndividualSuite.h"
   37.11  #include "IntegrityTests.h"
    38.1 --- a/test/src/engine_tests/KeyAttachmentTests.cc	Sat Mar 09 11:50:11 2019 +0100
    38.2 +++ b/test/src/engine_tests/KeyAttachmentTests.cc	Fri Mar 15 12:43:56 2019 +0100
    38.3 @@ -13,7 +13,7 @@
    38.4  #include "mime.h"
    38.5  
    38.6  #include <cpptest.h>
    38.7 -#include "TestUtils.h"
    38.8 +#include "test_util.h"
    38.9  #include "EngineTestIndividualSuite.h"
   38.10  #include "KeyAttachmentTests.h"
   38.11  
    39.1 --- a/test/src/engine_tests/KeyResetMessageTests.cc	Sat Mar 09 11:50:11 2019 +0100
    39.2 +++ b/test/src/engine_tests/KeyResetMessageTests.cc	Fri Mar 15 12:43:56 2019 +0100
    39.3 @@ -12,7 +12,7 @@
    39.4  #include "mime.h"
    39.5  #include "keymanagement.h"
    39.6  
    39.7 -#include "TestUtils.h"
    39.8 +#include "test_util.h"
    39.9  #include "EngineTestIndividualSuite.h"
   39.10  #include "KeyResetMessageTests.h"
   39.11  
   39.12 @@ -46,24 +46,18 @@
   39.13                                                                        static_cast<Func>(&KeyResetMessageTests::check_multiple_resets_single_key)));                                                                      
   39.14                                                                        
   39.15      fake_this = this;                                                                  
   39.16 +    
   39.17 +    cached_messageToSend = &KeyResetMessageTests::message_send_callback;
   39.18  }
   39.19  
   39.20 -// PEP_STATUS KeyResetMessageTests::message_send_callback(message* msg) {
   39.21 -//     fake_this->device->send_queue.push_back(msg);
   39.22 -//     return PEP_STATUS_OK;    
   39.23 -// }
   39.24 +PEP_STATUS KeyResetMessageTests::message_send_callback(message* msg) {
   39.25 +    fake_this->m_queue.push_back(msg);
   39.26 +    return PEP_STATUS_OK;    
   39.27 +}
   39.28  
   39.29  void KeyResetMessageTests::setup() {
   39.30      EngineTestIndividualSuite::setup();
   39.31 -//    device->send_queue.clear();
   39.32 -//    device->message_to_send = &KeyResetMessageTests::message_send_callback;
   39.33 -//    session->messageToSend = device->message_to_send;
   39.34 -}
   39.35 -
   39.36 -void KeyResetMessageTests::tear_down() {
   39.37 -//    device->device_messageToSend = NULL;
   39.38 -//    session->messageToSend = NULL;
   39.39 -    EngineTestIndividualSuite::tear_down();
   39.40 +    m_queue.clear();
   39.41  }
   39.42  
   39.43  void KeyResetMessageTests::send_setup() {
   39.44 @@ -176,9 +170,8 @@
   39.45      outgoing_msg->to = send_idents;
   39.46      outgoing_msg->shortmsg = strdup("Well isn't THIS a useless message...");
   39.47      outgoing_msg->longmsg = strdup("Hi Mom...\n");
   39.48 -    outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   39.49 -    // that's illegal - VB. 
   39.50 -    // I got this from your tests, and IIRC, there was some reason you guys always put it in there. - KB
   39.51 +    // outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   39.52 +    // that's illegal - VB.
   39.53      cout << "Message created.\n\n";
   39.54      cout << "Encrypting message as MIME multipart…\n";
   39.55      message* enc_outgoing_msg = nullptr;
   39.56 @@ -211,7 +204,7 @@
   39.57      
   39.58      status = key_reset(session, alice_fpr, from_ident);
   39.59      TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   39.60 -    TEST_ASSERT(device->send_queue.size() > 0);
   39.61 +    TEST_ASSERT(m_queue.size() > 0);
   39.62      status = myself(session, from_ident);
   39.63      string new_fpr = from_ident->fpr;
   39.64      TEST_ASSERT_MSG((strcmp(alice_fpr, new_fpr.c_str()) != 0), new_fpr.c_str());
   39.65 @@ -225,9 +218,9 @@
   39.66      hashmap[fenris_user_id] = false;
   39.67      
   39.68      // Number of messages we SHOULD be sending.
   39.69 -    TEST_ASSERT(device->send_queue.size() == 4);
   39.70 +    TEST_ASSERT(m_queue.size() == 4);
   39.71      
   39.72 -    for (vector<message*>::iterator it = device->send_queue.begin(); it != device->send_queue.end(); it++) {
   39.73 +    for (vector<message*>::iterator it = m_queue.begin(); it != m_queue.end(); it++) {
   39.74          message* curr_sent_msg = *it;
   39.75          TEST_ASSERT(curr_sent_msg);
   39.76          TEST_ASSERT(curr_sent_msg->to);
   39.77 @@ -257,7 +250,7 @@
   39.78      }
   39.79      
   39.80      // MESSAGE LIST NOW INVALID.
   39.81 -    device->send_queue.clear();
   39.82 +    m_queue.clear();
   39.83      
   39.84      // Make sure we have messages only to desired recips
   39.85      TEST_ASSERT(hashmap[alice_user_id] == false);
   39.86 @@ -424,7 +417,7 @@
   39.87  
   39.88      status = key_reset(session, alice_fpr, from_ident);
   39.89      TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   39.90 -    device->send_queue.clear();
   39.91 +    m_queue.clear();
   39.92      
   39.93      string received_mail = slurp("test_files/398_gabrielle_to_alice.eml");
   39.94      char* decrypted_msg = NULL;
   39.95 @@ -434,7 +427,7 @@
   39.96      PEP_decrypt_flags_t flags;
   39.97      status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
   39.98                                    &decrypted_msg, &keylist, &rating, &flags, &modified_src);
   39.99 -    TEST_ASSERT(device->send_queue.size() == 0);
  39.100 +    TEST_ASSERT(m_queue.size() == 0);
  39.101      free(decrypted_msg);
  39.102      free(modified_src);
  39.103      free_stringlist(keylist);
  39.104 @@ -488,8 +481,8 @@
  39.105  
  39.106      status = key_reset(session, alice_fpr, from_ident);
  39.107      TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
  39.108 -    TEST_ASSERT(device->send_queue.size() == 0);
  39.109 -    device->send_queue.clear();
  39.110 +    TEST_ASSERT(m_queue.size() == 0);
  39.111 +    m_queue.clear();
  39.112  
  39.113      // Now we get mail from Gabi, who only has our old key AND has become
  39.114      // a pEp user in the meantime...
  39.115 @@ -502,8 +495,8 @@
  39.116      status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
  39.117                                    &decrypted_msg, &keylist, &rating, &flags, &modified_src);
  39.118      
  39.119 -    TEST_ASSERT(device->send_queue.size() == 1);
  39.120 -    vector<message*>::iterator it = device->send_queue.begin();
  39.121 +    TEST_ASSERT(m_queue.size() == 1);
  39.122 +    vector<message*>::iterator it = m_queue.begin();
  39.123      message* reset_msg = *it;
  39.124      TEST_ASSERT(reset_msg);    
  39.125      TEST_ASSERT(reset_msg->from);    
    40.1 --- a/test/src/engine_tests/LeastColorGroupTests.cc	Sat Mar 09 11:50:11 2019 +0100
    40.2 +++ b/test/src/engine_tests/LeastColorGroupTests.cc	Fri Mar 15 12:43:56 2019 +0100
    40.3 @@ -10,7 +10,7 @@
    40.4  #include "keymanagement.h"
    40.5  #include "message_api.h"
    40.6  #include "mime.h"
    40.7 -#include "TestUtils.h"
    40.8 +#include "test_util.h"
    40.9  
   40.10  #include "pEpEngine.h"
   40.11  
    41.1 --- a/test/src/engine_tests/LeastCommonDenomColorTests.cc	Sat Mar 09 11:50:11 2019 +0100
    41.2 +++ b/test/src/engine_tests/LeastCommonDenomColorTests.cc	Fri Mar 15 12:43:56 2019 +0100
    41.3 @@ -12,7 +12,7 @@
    41.4  #include "keymanagement.h"
    41.5  #include "message_api.h"
    41.6  #include "mime.h"
    41.7 -#include "TestUtils.h"
    41.8 +#include "test_util.h"
    41.9  
   41.10  #include <cpptest.h>
   41.11  #include "EngineTestIndividualSuite.h"
    42.1 --- a/test/src/engine_tests/MessageApiTests.cc	Sat Mar 09 11:50:11 2019 +0100
    42.2 +++ b/test/src/engine_tests/MessageApiTests.cc	Fri Mar 15 12:43:56 2019 +0100
    42.3 @@ -12,7 +12,7 @@
    42.4  #include "platform.h"
    42.5  #include "mime.h"
    42.6  #include "message_api.h"
    42.7 -#include "TestUtils.h"
    42.8 +#include "test_util.h"
    42.9  
   42.10  #include <cpptest.h>
   42.11  #include "EngineTestSessionSuite.h"
    43.1 --- a/test/src/engine_tests/MessageNullFromTests.cc	Sat Mar 09 11:50:11 2019 +0100
    43.2 +++ b/test/src/engine_tests/MessageNullFromTests.cc	Fri Mar 15 12:43:56 2019 +0100
    43.3 @@ -8,7 +8,7 @@
    43.4  #include <assert.h>
    43.5  
    43.6  #include "pEpEngine.h"
    43.7 -#include "TestUtils.h"
    43.8 +#include "test_util.h"
    43.9  
   43.10  #include "EngineTestIndividualSuite.h"
   43.11  #include "MessageNullFromTests.h"
    44.1 --- a/test/src/engine_tests/MessageTwoPointOhTests.cc	Sat Mar 09 11:50:11 2019 +0100
    44.2 +++ b/test/src/engine_tests/MessageTwoPointOhTests.cc	Fri Mar 15 12:43:56 2019 +0100
    44.3 @@ -13,7 +13,7 @@
    44.4  #include "mime.h"
    44.5  #include "message_api.h"
    44.6  #include "keymanagement.h"
    44.7 -#include "TestUtils.h"
    44.8 +#include "test_util.h"
    44.9  
   44.10  #include <cpptest.h>
   44.11  #include "EngineTestSessionSuite.h"
    45.1 --- a/test/src/engine_tests/NewUpdateIdAndMyselfTests.cc	Sat Mar 09 11:50:11 2019 +0100
    45.2 +++ b/test/src/engine_tests/NewUpdateIdAndMyselfTests.cc	Fri Mar 15 12:43:56 2019 +0100
    45.3 @@ -11,7 +11,7 @@
    45.4  #include "pEpEngine.h"
    45.5  #include "message_api.h"
    45.6  #include "keymanagement.h"
    45.7 -#include "TestUtils.h"
    45.8 +#include "test_util.h"
    45.9  
   45.10  #include <cpptest.h>
   45.11  #include "EngineTestSessionSuite.h"
    46.1 --- a/test/src/engine_tests/PepSubjectReceivedTests.cc	Sat Mar 09 11:50:11 2019 +0100
    46.2 +++ b/test/src/engine_tests/PepSubjectReceivedTests.cc	Fri Mar 15 12:43:56 2019 +0100
    46.3 @@ -12,7 +12,7 @@
    46.4  #include "keymanagement.h"
    46.5  #include "message_api.h"
    46.6  #include "mime.h"
    46.7 -#include "TestUtils.h" // for slurp()
    46.8 +#include "test_util.h" // for slurp()
    46.9  
   46.10  #include <cpptest.h>
   46.11  #include "EngineTestSessionSuite.h"
    47.1 --- a/test/src/engine_tests/ReencryptPlusExtraKeysTests.cc	Sat Mar 09 11:50:11 2019 +0100
    47.2 +++ b/test/src/engine_tests/ReencryptPlusExtraKeysTests.cc	Fri Mar 15 12:43:56 2019 +0100
    47.3 @@ -12,7 +12,7 @@
    47.4  #include "mime.h"
    47.5  #include "message_api.h"
    47.6  #include "keymanagement.h"
    47.7 -#include "TestUtils.h"
    47.8 +#include "test_util.h"
    47.9  
   47.10  #include <cpptest.h>
   47.11  #include "EngineTestSessionSuite.h"
    48.1 --- a/test/src/engine_tests/RevokeRegenAttachTests.cc	Sat Mar 09 11:50:11 2019 +0100
    48.2 +++ b/test/src/engine_tests/RevokeRegenAttachTests.cc	Fri Mar 15 12:43:56 2019 +0100
    48.3 @@ -15,7 +15,7 @@
    48.4  #include "mime.h"
    48.5  #include "message_api.h"
    48.6  
    48.7 -#include "TestUtils.h"
    48.8 +#include "test_util.h"
    48.9  
   48.10  #include <cpptest.h>
   48.11  #include "EngineTestSessionSuite.h"
    49.1 --- a/test/src/engine_tests/SignOnlyTests.cc	Sat Mar 09 11:50:11 2019 +0100
    49.2 +++ b/test/src/engine_tests/SignOnlyTests.cc	Fri Mar 15 12:43:56 2019 +0100
    49.3 @@ -9,7 +9,7 @@
    49.4  
    49.5  #include "pEpEngine.h"
    49.6  
    49.7 -#include "TestUtils.h"
    49.8 +#include "test_util.h"
    49.9  #include "EngineTestIndividualSuite.h"
   49.10  #include "SignOnlyTests.h"
   49.11  
    50.1 --- a/test/src/engine_tests/SimpleBodyNotAltTests.cc	Sat Mar 09 11:50:11 2019 +0100
    50.2 +++ b/test/src/engine_tests/SimpleBodyNotAltTests.cc	Fri Mar 15 12:43:56 2019 +0100
    50.3 @@ -10,7 +10,7 @@
    50.4  #include "pEpEngine.h"
    50.5  #include "message.h"
    50.6  #include "mime.h"
    50.7 -#include "TestUtils.h"
    50.8 +#include "test_util.h"
    50.9  
   50.10  #include "EngineTestIndividualSuite.h"
   50.11  #include "SimpleBodyNotAltTests.h"
    51.1 --- a/test/src/engine_tests/SubkeyRatingEvalTests.cc	Sat Mar 09 11:50:11 2019 +0100
    51.2 +++ b/test/src/engine_tests/SubkeyRatingEvalTests.cc	Fri Mar 15 12:43:56 2019 +0100
    51.3 @@ -8,7 +8,7 @@
    51.4  #include "pEpEngine.h"
    51.5  
    51.6  #include <cpptest.h>
    51.7 -#include "TestUtils.h"
    51.8 +#include "test_util.h"
    51.9  
   51.10  #include "EngineTestIndividualSuite.h"
   51.11  #include "SubkeyRatingEvalTests.h"
    52.1 --- a/test/src/engine_tests/SyncDeviceTests.cc	Sat Mar 09 11:50:11 2019 +0100
    52.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.3 @@ -1,31 +0,0 @@
    52.4 -// This file is under GNU General Public License 3.0
    52.5 -// see LICENSE.txt
    52.6 -
    52.7 -#include <stdlib.h>
    52.8 -#include <string>
    52.9 -
   52.10 -#include <cpptest.h>
   52.11 -
   52.12 -#include <cstring>
   52.13 -
   52.14 -#include "pEpEngine.h"
   52.15 -
   52.16 -#include "TestUtils.h"
   52.17 -
   52.18 -#include "pEpTestDevice.h"
   52.19 -
   52.20 -#include "EngineTestIndividualSuite.h"
   52.21 -#include "SyncDeviceTests.h"
   52.22 -
   52.23 -using namespace std;
   52.24 -
   52.25 -SyncDeviceTests::SyncDeviceTests(string suitename, string test_home_dir) :
   52.26 -    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
   52.27 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SyncDeviceTests::check_sync_device"),
   52.28 -                                                                      static_cast<Func>(&SyncDeviceTests::check_sync_device)));
   52.29 -}
   52.30 -
   52.31 -void SyncDeviceTests::check_sync_device() {
   52.32 -    TEST_ASSERT(true);
   52.33 -}
   52.34 -
    53.1 --- a/test/src/engine_tests/TrustManipulationTests.cc	Sat Mar 09 11:50:11 2019 +0100
    53.2 +++ b/test/src/engine_tests/TrustManipulationTests.cc	Fri Mar 15 12:43:56 2019 +0100
    53.3 @@ -10,7 +10,7 @@
    53.4  #include <fstream>
    53.5  #include "mime.h"
    53.6  #include "message_api.h"
    53.7 -#include "TestUtils.h"
    53.8 +#include "test_util.h"
    53.9  
   53.10  #include "EngineTestSuite.h"
   53.11  #include "EngineTestSessionSuite.h"
    54.1 --- a/test/src/engine_tests/UserIDAliasTests.cc	Sat Mar 09 11:50:11 2019 +0100
    54.2 +++ b/test/src/engine_tests/UserIDAliasTests.cc	Fri Mar 15 12:43:56 2019 +0100
    54.3 @@ -10,7 +10,7 @@
    54.4  #include "pEpEngine.h"
    54.5  #include "message_api.h"
    54.6  #include "keymanagement.h"
    54.7 -#include "TestUtils.h"
    54.8 +#include "test_util.h"
    54.9  
   54.10  #include "EngineTestSuite.h"
   54.11  #include "EngineTestSessionSuite.h"
    55.1 --- a/test/src/engine_tests/UserIdCollisionTests.cc	Sat Mar 09 11:50:11 2019 +0100
    55.2 +++ b/test/src/engine_tests/UserIdCollisionTests.cc	Fri Mar 15 12:43:56 2019 +0100
    55.3 @@ -8,7 +8,7 @@
    55.4  
    55.5  #include "pEpEngine.h"
    55.6  
    55.7 -#include "TestUtils.h"
    55.8 +#include "test_util.h"
    55.9  #include "EngineTestIndividualSuite.h"
   55.10  #include "UserIdCollisionTests.h"
   55.11  
    56.1 --- a/test/src/pEpTestDevice.cc	Sat Mar 09 11:50:11 2019 +0100
    56.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    56.3 @@ -1,414 +0,0 @@
    56.4 -#include <stdlib.h>
    56.5 -#include <sys/stat.h>
    56.6 -#include <errno.h>
    56.7 -#include <unistd.h>
    56.8 -#include <ftw.h>
    56.9 -#include <assert.h>
   56.10 -#include <fstream>
   56.11 -#include <iostream>
   56.12 -#include <sys/types.h>
   56.13 -#include <dirent.h>
   56.14 -
   56.15 -#include <string>
   56.16 -#include <vector>
   56.17 -#include <utility>
   56.18 -
   56.19 -#include "platform_unix.h"
   56.20 -
   56.21 -#include "TestUtils.h"
   56.22 -#include "pEpTestDevice.h"
   56.23 -#include "pEpTestStatic.h"
   56.24 -#include <algorithm>
   56.25 -#include "TestConstants.h"
   56.26 -#include "mime.h"
   56.27 -#include "sync_api.h"
   56.28 -#include "Sync_event.h"
   56.29 -#include "locked_queue.hh"
   56.30 -#include "KeySync_fsm.h"
   56.31 -#include <chrono>
   56.32 -
   56.33 -// Static stuff
   56.34 -pEpTestDevice* pEpTestDevice::active = NULL;
   56.35 -
   56.36 -PEP_STATUS pEpTestDevice::message_to_send(struct _message* msg) {
   56.37 -    pEpTestDevice::active->add_message_to_send_queue(msg);
   56.38 -    return PEP_STATUS_OK;
   56.39 -}
   56.40 -
   56.41 -PEP_STATUS pEpTestDevice::notify_handshake(pEp_identity* me,
   56.42 -                                    pEp_identity* partner,
   56.43 -                                    sync_handshake_signal signal) {
   56.44 -    // 
   56.45 -    // switch(signal) {
   56.46 -    //     case SYNC_NOTIFY_UNDEFINED:
   56.47 -    //     case SYNC_NOTIFY_TIMEOUT:
   56.48 -    //     case SYNC_NOTIFY_OVERTAKEN:
   56.49 -    //     case SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED:
   56.50 -    //     case SYNC_NOTIFY_ACCEPTED_GROUP_CREATED:
   56.51 -    //     case SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED:   
   56.52 -    //         return SYNC_HANDSHAKE_CANCEL;
   56.53 -    // 
   56.54 -    //     // We don't simulate the handshake process here.
   56.55 -    //     // If we need to, this is a TODO.
   56.56 -    //     case SYNC_NOTIFY_INIT_ADD_OUR_DEVICE:
   56.57 -    //     case SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE:
   56.58 -    //     case SYNC_NOTIFY_INIT_FORM_GROUP:
   56.59 -    //     case SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE:
   56.60 -    //         return SYNC_HANDSHAKE_ACCEPTED;
   56.61 -    // 
   56.62 -    //     default:    
   56.63 -    //         return SYNC_HANDSHAKE_REJECTED;
   56.64 -    // }
   56.65 -    return PEP_STATUS_OK;
   56.66 -}
   56.67 -
   56.68 -Sync_event_t* pEpTestDevice::retrieve_next_sync_event(void *management, unsigned int threshold)
   56.69 -{
   56.70 -    time_t started = time(nullptr);
   56.71 -    bool timeout = false;
   56.72 -    
   56.73 -    while (active->q.empty()) {
   56.74 -        int i = 0;
   56.75 -        ++i;
   56.76 -        if (i > 10) {
   56.77 -            if (time(nullptr) > started + threshold) {
   56.78 -                timeout = true;
   56.79 -                break;
   56.80 -            }   
   56.81 -            i = 0;
   56.82 -        }   
   56.83 -        nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
   56.84 -    }
   56.85 -    if (timeout)
   56.86 -        return new_sync_timeout_event();
   56.87 -
   56.88 -    return pEpTestDevice::active->q.pop_front();
   56.89 -}
   56.90 -
   56.91 -int pEpTestDevice::inject_sync_event(Sync_event* ev, void* management) {
   56.92 -    Sync_event_t *_ev = ev;
   56.93 -    switch (_ev->fsm) {
   56.94 -        case Sync_PR_keysync:
   56.95 -//            cout << "injecting event " << KeySync_event_name(_ev->event) << "\n";
   56.96 -            break;
   56.97 -        default:
   56.98 -            throw std::runtime_error("Unknown state machine.");
   56.99 -    }
  56.100 -    pEpTestDevice::active->q.push_front(ev);
  56.101 -    return 0;
  56.102 -}
  56.103 -// End static stuff
  56.104 -
  56.105 -pEpTestDevice::pEpTestDevice(string test_dir, 
  56.106 -                             string my_name)                
  56.107 -{
  56.108 -    root_test_dir = test_dir;
  56.109 -    // FIXME: do we have to worry about dirlen now?
  56.110 -    device_dir = test_dir + "/" + my_name;
  56.111 -    device_name = my_name;
  56.112 -    // device_messageToSend = mess_send_func;
  56.113 -    // device_inject_sync_event = inject_sync_ev_func;
  56.114 -    
  56.115 -    if (active)
  56.116 -        pEpTestDevice::active->unset_device_environment();
  56.117 -        
  56.118 -    set_device_environment();    
  56.119 -}
  56.120 -
  56.121 -pEpTestDevice::~pEpTestDevice() {
  56.122 -    unset_device_environment();
  56.123 -    // FIXME: Remove homedir
  56.124 -    nftw((device_dir).c_str(), util_delete_filepath, 100, FTW_DEPTH);
  56.125 -    active = NULL;
  56.126 -}
  56.127 -
  56.128 -void pEpTestDevice::switch_context(pEpTestDevice* switch_to) {
  56.129 -    switch_to->grab_context(active);
  56.130 -}
  56.131 -
  56.132 -void pEpTestDevice::set_device_environment() {
  56.133 -    pEpTestDevice::active = this;
  56.134 -    int success = 0;
  56.135 -    struct stat dirchk;
  56.136 -    
  56.137 -//    set_my_name();
  56.138 -
  56.139 -// FIXME
  56.140 -#ifndef USE_NETPGP
  56.141 -    success = system("gpgconf --kill all");
  56.142 -    if (success != 0)
  56.143 -        throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");    
  56.144 -#endif
  56.145 -
  56.146 -    if (stat(device_dir.c_str(), &dirchk) == 0) {
  56.147 -        if (!S_ISDIR(dirchk.st_mode))
  56.148 -            throw std::runtime_error(("The test directory, " + device_dir + "exists, but is not a directory.").c_str()); 
  56.149 -                    
  56.150 -        // struct stat buf;
  56.151 -        // 
  56.152 -        // if (stat(device_dir.c_str(), &buf) == 0) {
  56.153 -        //     int success = nftw((device_dir + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
  56.154 -        // }
  56.155 -    }
  56.156 -    else {
  56.157 -        int errchk = mkdir(device_dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  56.158 -        cout << errchk << endl;
  56.159 -        if (errchk != 0)
  56.160 -            throw std::runtime_error("Error creating a test directory.");
  56.161 -    }
  56.162 -        
  56.163 -    struct stat buf;
  56.164 -        
  56.165 -    success = setenv("GNUPGHOME", (device_dir + "/gnupg").c_str(), 1);
  56.166 -
  56.167 -    if (success != 0)
  56.168 -        throw std::runtime_error("SETUP: Error when setting GNUPGHOME.");
  56.169 -
  56.170 -    cout << "New GNUPGHOME is " << getenv("GNUPGHOME") << endl << endl;
  56.171 -        
  56.172 -    success = setenv("HOME", device_dir.c_str(), 1);
  56.173 -    if (success != 0)
  56.174 -        throw std::runtime_error("SETUP: Cannot set copy_fil for init.");
  56.175 -            
  56.176 -    unix_local_db(true);
  56.177 -    gpg_conf(true);
  56.178 -    gpg_agent_conf(true);
  56.179 -        
  56.180 -    PEP_STATUS status = init(&session, message_to_send, inject_sync_event);
  56.181 -    if (status != PEP_STATUS_OK)
  56.182 -        throw std::runtime_error("init() exploded! Bad!");
  56.183 -    status = register_sync_callbacks(session, (void*)(&(active->q)),
  56.184 -                                     notify_handshake, retrieve_next_sync_event);
  56.185 -    if (status != PEP_STATUS_OK)
  56.186 -        throw std::runtime_error("Couldn't register sync callbacks, possible because we dunno WTF we're doing.");
  56.187 -
  56.188 -
  56.189 -#ifndef USE_NETPGP            
  56.190 -    success = system("gpgconf --create-socketdir");
  56.191 -    if (success != 0)
  56.192 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --create-socketdir'.");        
  56.193 -    system("gpg-connect-agent /bye");   // Just in case - otherwise, we die on MacOS sometimes. Is this enough??
  56.194 -#endif
  56.195 -
  56.196 -    assert(status == PEP_STATUS_OK);
  56.197 -    assert(session);
  56.198 -}
  56.199 -
  56.200 -void pEpTestDevice::grab_context(pEpTestDevice* victim) {
  56.201 -    victim->process_send_queue();
  56.202 -    victim->unset_device_environment();
  56.203 -    set_device_environment();
  56.204 -}
  56.205 -
  56.206 -void pEpTestDevice::unset_device_environment() {
  56.207 -    if (session)
  56.208 -        release(session);
  56.209 -    session = NULL;
  56.210 -        
  56.211 -    int success = 0;    
  56.212 -
  56.213 -#ifndef USE_NETPGP        
  56.214 -    success = system("gpgconf --kill all");
  56.215 -    if (success != 0)
  56.216 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
  56.217 -    success = system("gpgconf --remove-socketdir");            
  56.218 -    if (success != 0)
  56.219 -        throw std::runtime_error("RESTORE: Error when executing 'gpgconf --remove-socketdir'.");    
  56.220 -#endif
  56.221 -
  56.222 -    unix_local_db(true);
  56.223 -    gpg_conf(true);
  56.224 -    gpg_agent_conf(true);
  56.225 -}
  56.226 -
  56.227 -void pEpTestDevice::set_mailbox_dir(string mbox_dirname) {
  56.228 -    mbox_dir = mbox_dirname;
  56.229 -    struct stat dirchk;
  56.230 -    
  56.231 -    if (stat(mbox_dir.c_str(), &dirchk) == 0) {
  56.232 -        if (!S_ISDIR(dirchk.st_mode))
  56.233 -            throw std::runtime_error(("The mbox directory, " + device_dir + "exists, but is not a directory.").c_str());                     
  56.234 -    }
  56.235 -    else {
  56.236 -        int errchk = mkdir(mbox_dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  56.237 -        cout << errchk << endl;
  56.238 -        if (errchk != 0)
  56.239 -            throw std::runtime_error("Error creating an mbox directory.");
  56.240 -    }    
  56.241 -}
  56.242 -
  56.243 -string pEpTestDevice::receive_mail(string mail) {
  56.244 -    return save_mail_to_mailbox(mbox_dir, mail);
  56.245 -}
  56.246 -
  56.247 -PEP_STATUS pEpTestDevice::send_mail(message* mail) {
  56.248 -    if (!mail->to)
  56.249 -        return PEP_ILLEGAL_VALUE;
  56.250 -        
  56.251 -    identity_list* to_list = mail->to;
  56.252 -    if (!to_list)
  56.253 -        return PEP_ILLEGAL_VALUE;
  56.254 -
  56.255 -    char* msg_str = NULL;
  56.256 -    PEP_STATUS status = mime_encode_message(mail, false, &msg_str);
  56.257 -    if (status != PEP_STATUS_OK)
  56.258 -        return status;
  56.259 -    if (!msg_str)
  56.260 -        return PEP_UNKNOWN_ERROR;
  56.261 -    
  56.262 -    for (identity_list* tl_curr = to_list; tl_curr; tl_curr = tl_curr->next) {
  56.263 -        if (!tl_curr->ident)
  56.264 -            return PEP_ILLEGAL_VALUE;
  56.265 -        const char* to = tl_curr->ident->address;
  56.266 -        if (!to || to[0] == '\0')
  56.267 -            return PEP_ILLEGAL_VALUE;
  56.268 -            
  56.269 -        std::map<string,string>::iterator it = address_to_mbox_map.find(to);
  56.270 -        if (it == address_to_mbox_map.end() || it->second.empty())
  56.271 -            return PEP_RECORD_NOT_FOUND;
  56.272 -        string mbox = it->second;
  56.273 -        if (save_mail_to_mailbox(mbox, msg_str).empty())
  56.274 -            return PEP_CANNOT_CREATE_TEMP_FILE;
  56.275 -    }    
  56.276 -    return PEP_STATUS_OK;
  56.277 -}
  56.278 -
  56.279 -PEP_STATUS pEpTestDevice::process_send_queue() {
  56.280 -    for (vector<message*>::iterator it = send_queue.begin(); it != send_queue.end(); it++) {
  56.281 -        if (*it) {
  56.282 -            PEP_STATUS status = send_mail(*it);
  56.283 -            if (status != PEP_STATUS_OK)
  56.284 -                return status;
  56.285 -        }
  56.286 -        free_message(*it);
  56.287 -        *it = NULL;
  56.288 -    }
  56.289 -    send_queue.clear();
  56.290 -    return PEP_STATUS_OK;
  56.291 -}
  56.292 -
  56.293 -string pEpTestDevice::save_mail_to_mailbox(string mailbox_path, string mail) {
  56.294 -    if (mail.empty())
  56.295 -        throw std::runtime_error("Attempt to write empty mail to mailbox.");
  56.296 -
  56.297 -    struct stat dirchk;
  56.298 -    
  56.299 -    if (mailbox_path.empty() || stat(mailbox_path.c_str(), &dirchk) != 0) {
  56.300 -        cerr << "ERROR: " << mailbox_path << endl;
  56.301 -        throw std::runtime_error("pEpTestDevice: mailbox dir not initialised or removed."); 
  56.302 -    }                    
  56.303 -
  56.304 -    chrono::milliseconds timestamp = chrono::duration_cast< chrono::milliseconds >(
  56.305 -                                        chrono::system_clock::now().time_since_epoch());
  56.306 -    
  56.307 -    string outfile_name = mailbox_path + "/" + to_string(timestamp.count()) + ".eml";
  56.308 -
  56.309 -    ofstream outfile;
  56.310 -    
  56.311 -    outfile.open(outfile_name);
  56.312 -    outfile << mail;
  56.313 -    outfile.flush();
  56.314 -    outfile.close(); 
  56.315 -    cout << "Wrote " + outfile_name << endl;
  56.316 -    usleep(1000); // guarantees change in filename
  56.317 -    return outfile_name;
  56.318 -}
  56.319 -
  56.320 -// Presumes everything in mbox dir is a .eml file
  56.321 -// and was written in above ts form. We can change later if needed.
  56.322 -void pEpTestDevice::check_mail(vector<string> &unread) {
  56.323 -    unread.clear();
  56.324 -    mail_to_read.clear();
  56.325 -    struct stat dirchk;
  56.326 -
  56.327 -    if (mbox_dir.empty() || stat(mbox_dir.c_str(), &dirchk) != 0) {
  56.328 -        cerr << "ERROR: " << mbox_dir << endl;        
  56.329 -        throw std::runtime_error("pEpTestDevice: mailbox dir not initialised or removed.");                     
  56.330 -    }
  56.331 -    DIR* dir;   
  56.332 -    dirent* pdir;
  56.333 - 
  56.334 -    dir = opendir(mbox_dir.c_str()); 
  56.335 -    while ((pdir = readdir(dir))) {
  56.336 -        struct stat dirchk2;
  56.337 -        const char* fname = pdir->d_name;
  56.338 -        if (strcmp(fname, ".") && strcmp(fname, "..")) {
  56.339 -            stat((mbox_dir + fname).c_str(), &dirchk2);
  56.340 -            cout << "I see " << fname << endl;
  56.341 -            if (!S_ISDIR(dirchk2.st_mode)) {
  56.342 -                unread.push_back(fname); 
  56.343 -                cout << "I pushed " << fname << endl; 
  56.344 -            }    
  56.345 -        }        
  56.346 -    }    
  56.347 -
  56.348 -    if (unread.empty())
  56.349 -        return;
  56.350 -    else    
  56.351 -        sort(unread.begin(), unread.end());
  56.352 -    
  56.353 -    if (!mbox_last_read.empty()) {
  56.354 -    
  56.355 -        string last_read_time_str = 
  56.356 -            mbox_last_read.substr(0, mbox_last_read.find_last_of("."));
  56.357 -        unsigned long long last_read_ts = strtoull(last_read_time_str.c_str(), NULL, 10);
  56.358 -        
  56.359 -        int i = 0;
  56.360 -        
  56.361 -        for (vector<string>::iterator it = unread.begin();
  56.362 -             it != unread.end(); it++, i++) {
  56.363 -            string fname = *it;
  56.364 -            if (fname.empty())
  56.365 -                continue; // ??
  56.366 -
  56.367 -            // I don't want to think about how to format to do a strcmp atm
  56.368 -            size_t dot_pos = fname.find_last_of(".");
  56.369 -            string ts_str = fname.substr(0, dot_pos);
  56.370 -            
  56.371 -            unsigned long long file_ts = strtoull(ts_str.c_str(), NULL, 10);
  56.372 -            
  56.373 -            if (file_ts > last_read_ts)
  56.374 -                break;
  56.375 -        }
  56.376 -        
  56.377 -        if (i > unread.size())
  56.378 -            unread.clear();
  56.379 -        else {
  56.380 -            if (i != 0) {
  56.381 -                unread.erase(unread.begin(), unread.begin() + i);
  56.382 -                cout << "Unread contains: " << endl;
  56.383 -                for (vector<string>::iterator it = unread.begin();
  56.384 -                     it != unread.end(); it++) {
  56.385 -                    cout << *it << endl;
  56.386 -                }
  56.387 -            }
  56.388 -        }     
  56.389 -    }
  56.390 -    
  56.391 -    mbox_last_read = string(unread.back());    
  56.392 -}
  56.393 -
  56.394 -void pEpTestDevice::read_mail(vector<string> mails, vector<message*> &to_read) {
  56.395 -    to_read.clear();
  56.396 -    for (vector<string>::iterator it = mails.begin();
  56.397 -         it != mails.end(); it++) {
  56.398 -        string mail = slurp(mbox_dir + "/" + *it);
  56.399 -        if (mail.empty())
  56.400 -            continue;
  56.401 -        message* msg = NULL;
  56.402 -        PEP_STATUS status = mime_decode_message(mail.c_str(), mail.size(), &msg);    
  56.403 -        if (status != PEP_STATUS_OK) {
  56.404 -            free(msg);
  56.405 -            continue;
  56.406 -        }
  56.407 -        to_read.push_back(msg);
  56.408 -    }
  56.409 -}
  56.410 -
  56.411 -void pEpTestDevice::add_message_to_send_queue(message* msg) {
  56.412 -    if (!msg)
  56.413 -        return;
  56.414 -    send_queue.push_back(msg);
  56.415 -}
  56.416 -
  56.417 -    
    57.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    57.2 +++ b/test/src/util/test_util.cc	Fri Mar 15 12:43:56 2019 +0100
    57.3 @@ -0,0 +1,419 @@
    57.4 +#include "pEpEngine_test.h"
    57.5 +#include "pEpEngine.h"
    57.6 +#include "pEp_internal.h"
    57.7 +#include "message_api.h"
    57.8 +#include "test_util.h"
    57.9 +#include "TestConstants.h"
   57.10 +
   57.11 +#include <fstream>
   57.12 +#include <sstream>
   57.13 +#include <stdexcept>
   57.14 +#include <stdlib.h>
   57.15 +#include <sys/stat.h>
   57.16 +#include <errno.h>
   57.17 +#include <stdlib.h>
   57.18 +#include <unistd.h>
   57.19 +#include <ftw.h>
   57.20 +
   57.21 +PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname) {
   57.22 +    const std::string key = slurp(fname);
   57.23 +    PEP_STATUS status = (key.empty() ? PEP_KEY_NOT_FOUND : PEP_STATUS_OK);
   57.24 +    if (status == PEP_STATUS_OK)
   57.25 +        status = import_key(session, key.c_str(), key.size(), NULL);
   57.26 +    return status;    
   57.27 +}
   57.28 +
   57.29 +PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session,
   57.30 +                                     const char* key_fname,
   57.31 +                                     const char* address,
   57.32 +                                     const char* fpr,
   57.33 +                                     const char* user_id,
   57.34 +                                     const char* username,
   57.35 +                                     pEp_identity** ret_ident,
   57.36 +                                     bool is_priv) {
   57.37 +    PEP_STATUS status = read_file_and_import_key(session,key_fname);
   57.38 +    if (status != PEP_KEY_IMPORTED)
   57.39 +        return status;
   57.40 +    else
   57.41 +        status = PEP_STATUS_OK;
   57.42 +    
   57.43 +    pEp_identity* ident = new_identity(address, fpr, user_id, username);
   57.44 +    if (is_priv && fpr) {
   57.45 +        status = set_own_key(session, ident, fpr);
   57.46 +        if (status == PEP_STATUS_OK)
   57.47 +            status = myself(session, ident);
   57.48 +    }
   57.49 +    else    
   57.50 +        status = update_identity(session, ident);
   57.51 +
   57.52 +    if (status != PEP_STATUS_OK)
   57.53 +        goto pep_free;
   57.54 +        
   57.55 +    if (!ident || !ident->fpr) {
   57.56 +        status = PEP_CANNOT_FIND_IDENTITY;
   57.57 +        goto pep_free;
   57.58 +    }
   57.59 +    
   57.60 +    if (ret_ident)
   57.61 +        *ret_ident = ident;
   57.62 +        
   57.63 +pep_free:
   57.64 +    if (!ret_ident)
   57.65 +        free_identity(ident);
   57.66 +    return status;    
   57.67 +}
   57.68 +
   57.69 +
   57.70 +bool file_exists(std::string filename) {
   57.71 +    struct stat buffer;
   57.72 +    return (stat(filename.c_str(), &buffer) == 0);
   57.73 +}
   57.74 +
   57.75 +char* str_to_lower(const char* str) {
   57.76 +    if (!str)
   57.77 +        return NULL;
   57.78 +    int str_len = strlen(str);
   57.79 +    if (str_len == 0)
   57.80 +        return strdup("");
   57.81 +    int i;
   57.82 +    
   57.83 +    char* retval = (char*) calloc(1, str_len + 1);
   57.84 +    for (i = 0; i < str_len; i++) {
   57.85 +        retval[i] = tolower(str[i]);
   57.86 +    }    
   57.87 +    return retval;
   57.88 +}
   57.89 +
   57.90 +// Because annoyed
   57.91 +bool _streq(const char* str1, const char* str2) {
   57.92 +    if (!str1) {
   57.93 +        if (str2)
   57.94 +            return false;
   57.95 +        return true;
   57.96 +    }
   57.97 +    if (!str2)
   57.98 +        return false;
   57.99 +        
  57.100 +    return (strcmp(str1, str2) == 0);
  57.101 +}
  57.102 +
  57.103 +bool _strceq(const char* str1, const char* str2) {
  57.104 +    char* str1_dup = str_to_lower(str1);
  57.105 +    char* str2_dup = str_to_lower(str2);
  57.106 +
  57.107 +    bool retval = _streq(str_to_lower(str1_dup), str_to_lower(str2_dup));
  57.108 +    free(str1_dup);
  57.109 +    free(str2_dup);
  57.110 +    return retval;
  57.111 +}
  57.112 +
  57.113 +void test_init() {
  57.114 +    unlink ("../test_home/.pEp_management.db");
  57.115 +    unlink ("../test_home/.pEp_management.db-shm");
  57.116 +    unlink ("../test_home/.pEp_management.db-wal");
  57.117 +}
  57.118 +
  57.119 +std::string slurp(const std::string& filename)
  57.120 +{
  57.121 +	std::ifstream input(filename.c_str());
  57.122 +	if(!input)
  57.123 +	{
  57.124 +		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
  57.125 +	}
  57.126 +	
  57.127 +	std::stringstream sstr;
  57.128 +	sstr << input.rdbuf();
  57.129 +	return sstr.str();
  57.130 +}
  57.131 +
  57.132 +void dump_out(const char* filename, const char* outdata)
  57.133 +{
  57.134 +	std::ofstream outfile(filename);
  57.135 +	if(!outfile)
  57.136 +	{
  57.137 +		throw std::runtime_error("Cannot open output file!");
  57.138 +	}
  57.139 +	
  57.140 +	outfile << outdata;
  57.141 +    outfile.close();
  57.142 +}
  57.143 +
  57.144 +char* get_new_uuid() {
  57.145 +    char* new_uuid = (char*)calloc(37, 1);
  57.146 +    pEpUUID uuid;
  57.147 +    uuid_generate_random(uuid);
  57.148 +    uuid_unparse_upper(uuid, new_uuid);
  57.149 +    return new_uuid;
  57.150 +}
  57.151 +
  57.152 +const char* tl_status_string(PEP_STATUS status) {
  57.153 +    switch (status) {
  57.154 +        case PEP_STATUS_OK:
  57.155 +            return "PEP_STATUS_OK";
  57.156 +        case PEP_INIT_CANNOT_LOAD_GPGME:
  57.157 +            return "PEP_INIT_CANNOT_LOAD_GPGME";
  57.158 +        case PEP_INIT_GPGME_INIT_FAILED:
  57.159 +            return "PEP_INIT_GPGME_INIT_FAILED";
  57.160 +        case PEP_INIT_NO_GPG_HOME:
  57.161 +            return "PEP_INIT_NO_GPG_HOME";
  57.162 +        case PEP_INIT_NETPGP_INIT_FAILED:
  57.163 +            return "PEP_INIT_NETPGP_INIT_FAILED";
  57.164 +        case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
  57.165 +            return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
  57.166 +        case PEP_INIT_CANNOT_OPEN_DB:
  57.167 +            return "PEP_INIT_CANNOT_OPEN_DB";
  57.168 +        case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
  57.169 +            return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
  57.170 +        case PEP_KEY_NOT_FOUND:
  57.171 +            return "PEP_KEY_NOT_FOUND";
  57.172 +        case PEP_KEY_HAS_AMBIG_NAME:
  57.173 +            return "PEP_KEY_HAS_AMBIG_NAME";
  57.174 +        case PEP_GET_KEY_FAILED:
  57.175 +            return "PEP_GET_KEY_FAILED";
  57.176 +        case PEP_CANNOT_EXPORT_KEY:
  57.177 +            return "PEP_CANNOT_EXPORT_KEY";
  57.178 +        case PEP_CANNOT_EDIT_KEY:
  57.179 +            return "PEP_CANNOT_EDIT_KEY";
  57.180 +        case PEP_CANNOT_FIND_IDENTITY:
  57.181 +            return "PEP_CANNOT_FIND_IDENTITY";
  57.182 +        case PEP_CANNOT_SET_PERSON:
  57.183 +            return "PEP_CANNOT_SET_PERSON";
  57.184 +        case PEP_CANNOT_SET_PGP_KEYPAIR:
  57.185 +            return "PEP_CANNOT_SET_PGP_KEYPAIR";
  57.186 +        case PEP_CANNOT_SET_IDENTITY:
  57.187 +            return "PEP_CANNOT_SET_IDENTITY";
  57.188 +        case PEP_CANNOT_SET_TRUST:
  57.189 +            return "PEP_CANNOT_SET_TRUST";
  57.190 +        case PEP_KEY_BLACKLISTED:
  57.191 +            return "PEP_KEY_BLACKLISTED";
  57.192 +        case PEP_UNENCRYPTED:
  57.193 +            return "PEP_UNENCRYPTED";
  57.194 +        case PEP_VERIFIED:
  57.195 +            return "PEP_VERIFIED";
  57.196 +        case PEP_DECRYPTED:
  57.197 +            return "PEP_DECRYPTED";
  57.198 +        case PEP_DECRYPTED_AND_VERIFIED:
  57.199 +            return "PEP_DECRYPTED_AND_VERIFIED";
  57.200 +        case PEP_DECRYPT_WRONG_FORMAT:
  57.201 +            return "PEP_DECRYPT_WRONG_FORMAT";
  57.202 +        case PEP_DECRYPT_NO_KEY:
  57.203 +            return "PEP_DECRYPT_NO_KEY";
  57.204 +        case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
  57.205 +            return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
  57.206 +//        case PEP_DECRYPTED_BUT_UNSIGNED:
  57.207 +//            return "PEP_DECRYPTED_BUT_UNSIGNED";
  57.208 +//        case PEP_DECRYPT_MODIFICATION_DETECTED:
  57.209 +//            return "PEP_DECRYPT_MODIFICATION_DETECTED";
  57.210 +//        case PEP_DECRYPT_NO_KEY_FOR_SIGNER:
  57.211 +//            return "PEP_DECRYPT_NO_KEY_FOR_SIGNER";
  57.212 +        case PEP_VERIFY_NO_KEY:
  57.213 +            return "PEP_VERIFY_NO_KEY";
  57.214 +        case PEP_VERIFIED_AND_TRUSTED:
  57.215 +            return "PEP_VERIFIED_AND_TRUSTED";
  57.216 +        case PEP_CANNOT_DECRYPT_UNKNOWN:
  57.217 +            return "PEP_CANNOT_DECRYPT_UNKNOWN";
  57.218 +        case PEP_TRUSTWORD_NOT_FOUND:
  57.219 +            return "PEP_TRUSTWORD_NOT_FOUND";
  57.220 +        case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
  57.221 +            return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
  57.222 +        case PEP_CANNOT_CREATE_KEY:
  57.223 +            return "PEP_CANNOT_CREATE_KEY";
  57.224 +        case PEP_CANNOT_SEND_KEY:
  57.225 +            return "PEP_CANNOT_SEND_KEY";
  57.226 +        case PEP_PHRASE_NOT_FOUND:
  57.227 +            return "PEP_PHRASE_NOT_FOUND";
  57.228 +        case PEP_SEND_FUNCTION_NOT_REGISTERED:
  57.229 +            return "PEP_SEND_FUNCTION_NOT_REGISTERED";
  57.230 +        case PEP_CONTRAINTS_VIOLATED:
  57.231 +            return "PEP_CONTRAINTS_VIOLATED";
  57.232 +        case PEP_CANNOT_ENCODE:
  57.233 +            return "PEP_CANNOT_ENCODE";
  57.234 +        case PEP_SYNC_NO_NOTIFY_CALLBACK:
  57.235 +            return "PEP_SYNC_NO_NOTIFY_CALLBACK";
  57.236 +        case PEP_SYNC_ILLEGAL_MESSAGE:
  57.237 +            return "PEP_SYNC_ILLEGAL_MESSAGE";
  57.238 +        case PEP_SYNC_NO_INJECT_CALLBACK:
  57.239 +            return "PEP_SYNC_NO_INJECT_CALLBACK";
  57.240 +        case PEP_CANNOT_INCREASE_SEQUENCE:
  57.241 +            return "PEP_CANNOT_INCREASE_SEQUENCE";
  57.242 +        case PEP_STATEMACHINE_ERROR:
  57.243 +            return "PEP_STATEMACHINE_ERROR";
  57.244 +        case PEP_NO_TRUST:
  57.245 +            return "PEP_NO_TRUST";
  57.246 +        case PEP_STATEMACHINE_INVALID_STATE:
  57.247 +            return "PEP_STATEMACHINE_INVALID_STATE";
  57.248 +        case PEP_STATEMACHINE_INVALID_EVENT:
  57.249 +            return "PEP_STATEMACHINE_INVALID_EVENT";
  57.250 +        case PEP_STATEMACHINE_INVALID_CONDITION:
  57.251 +            return "PEP_STATEMACHINE_INVALID_CONDITION";
  57.252 +        case PEP_STATEMACHINE_INVALID_ACTION:
  57.253 +            return "PEP_STATEMACHINE_INVALID_ACTION";
  57.254 +        case PEP_STATEMACHINE_INHIBITED_EVENT:
  57.255 +            return "PEP_STATEMACHINE_INHIBITED_EVENT";
  57.256 +        case PEP_COMMIT_FAILED:
  57.257 +            return "PEP_COMMIT_FAILED";
  57.258 +        case PEP_MESSAGE_CONSUME:
  57.259 +            return "PEP_MESSAGE_CONSUME";
  57.260 +        case PEP_MESSAGE_IGNORE:
  57.261 +            return "PEP_MESSAGE_IGNORE";
  57.262 +        case PEP_RECORD_NOT_FOUND:
  57.263 +            return "PEP_RECORD_NOT_FOUND";
  57.264 +        case PEP_CANNOT_CREATE_TEMP_FILE:
  57.265 +            return "PEP_CANNOT_CREATE_TEMP_FILE";
  57.266 +        case PEP_ILLEGAL_VALUE:
  57.267 +            return "PEP_ILLEGAL_VALUE";
  57.268 +        case PEP_BUFFER_TOO_SMALL:
  57.269 +            return "PEP_BUFFER_TOO_SMALL";
  57.270 +        case PEP_OUT_OF_MEMORY:
  57.271 +            return "PEP_OUT_OF_MEMORY";
  57.272 +        case PEP_UNKNOWN_ERROR:
  57.273 +            return "PEP_UNKNOWN_ERROR";    
  57.274 +        default:
  57.275 + 
  57.276 +            return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
  57.277 +    }
  57.278 +}
  57.279 +const char* tl_rating_string(PEP_rating rating) {
  57.280 +    switch (rating) {
  57.281 +        case PEP_rating_undefined:
  57.282 +            return "PEP_rating_undefined";
  57.283 +        case PEP_rating_cannot_decrypt:
  57.284 +            return "PEP_rating_cannot_decrypt";
  57.285 +        case PEP_rating_have_no_key:
  57.286 +            return "PEP_rating_have_no_key";
  57.287 +        case PEP_rating_unencrypted:
  57.288 +            return "PEP_rating_unencrypted";
  57.289 +        case PEP_rating_unencrypted_for_some:
  57.290 +            return "PEP_rating_unencrypted_for_some";
  57.291 +        case PEP_rating_unreliable:
  57.292 +            return "PEP_rating_unreliable";
  57.293 +        case PEP_rating_reliable:
  57.294 +            return "PEP_rating_reliable";
  57.295 +        case PEP_rating_trusted:
  57.296 +            return "PEP_rating_trusted";
  57.297 +        case PEP_rating_trusted_and_anonymized:
  57.298 +            return "PEP_rating_trusted_and_anonymized";
  57.299 +        case PEP_rating_fully_anonymous:
  57.300 +            return "PEP_rating_fully_anonymous";
  57.301 +        case PEP_rating_mistrust:
  57.302 +            return "PEP_rating_mistrust";
  57.303 +        case PEP_rating_b0rken:
  57.304 +            return "PEP_rating_b0rken";
  57.305 +        case PEP_rating_under_attack:
  57.306 +            return "PEP_rating_under_attack";
  57.307 +        default:
  57.308 +            return "PEP_rating_OMGWTFBBQ - in other words, INVALID RATING VALUE!!!\n\nSomething bad is going on here, or a new rating value has been added to the enum and not the test function.";
  57.309 +    }
  57.310 +}
  57.311 +
  57.312 +const char* tl_ct_string(PEP_comm_type ct) {
  57.313 +    switch (ct) {
  57.314 +        case PEP_ct_unknown:
  57.315 +            return "PEP_ct_unknown";
  57.316 +        case PEP_ct_no_encryption:
  57.317 +            return "PEP_ct_no_encryption";
  57.318 +        case PEP_ct_no_encrypted_channel:
  57.319 +            return "PEP_ct_no_encrypted_channel";
  57.320 +        case PEP_ct_key_not_found:
  57.321 +            return "PEP_ct_key_not_found";
  57.322 +        case PEP_ct_key_expired:
  57.323 +            return "PEP_ct_key_expired";
  57.324 +        case PEP_ct_key_revoked:
  57.325 +            return "PEP_ct_key_revoked";
  57.326 +        case PEP_ct_key_b0rken:
  57.327 +            return "PEP_ct_key_b0rken";
  57.328 +        case PEP_ct_my_key_not_included:
  57.329 +            return "PEP_ct_my_key_not_included";
  57.330 +        case PEP_ct_security_by_obscurity:
  57.331 +            return "PEP_ct_security_by_obscurity";
  57.332 +        case PEP_ct_b0rken_crypto:
  57.333 +            return "PEP_ct_b0rken_crypto";
  57.334 +        case PEP_ct_key_too_short:
  57.335 +            return "PEP_ct_key_too_short";
  57.336 +        case PEP_ct_compromised:
  57.337 +            return "PEP_ct_compromised";
  57.338 +        case PEP_ct_mistrusted:
  57.339 +            return "PEP_ct_mistrusted";
  57.340 +        case PEP_ct_unconfirmed_encryption:
  57.341 +            return "PEP_ct_unconfirmed_encryption";
  57.342 +        case PEP_ct_OpenPGP_weak_unconfirmed:
  57.343 +            return "PEP_ct_OpenPGP_weak_unconfirmed";
  57.344 +        case PEP_ct_to_be_checked:
  57.345 +            return "PEP_ct_to_be_checked";
  57.346 +        case PEP_ct_SMIME_unconfirmed:
  57.347 +            return "PEP_ct_SMIME_unconfirmed";
  57.348 +        case PEP_ct_CMS_unconfirmed:
  57.349 +            return "PEP_ct_CMS_unconfirmed";
  57.350 +        case PEP_ct_strong_but_unconfirmed:
  57.351 +            return "PEP_ct_strong_but_unconfirmed";
  57.352 +        case PEP_ct_OpenPGP_unconfirmed:
  57.353 +            return "PEP_ct_OpenPGP_unconfirmed";
  57.354 +        case PEP_ct_OTR_unconfirmed:
  57.355 +            return "PEP_ct_OTR_unconfirmed";
  57.356 +        case PEP_ct_unconfirmed_enc_anon:
  57.357 +            return "PEP_ct_unconfirmed_enc_anon";
  57.358 +        case PEP_ct_pEp_unconfirmed:
  57.359 +            return "PEP_ct_pEp_unconfirmed";
  57.360 +        case PEP_ct_confirmed:
  57.361 +            return "PEP_ct_pEp_confirmed";
  57.362 +        case PEP_ct_confirmed_encryption:
  57.363 +            return "PEP_ct_confirmed_encryption";
  57.364 +        case PEP_ct_OpenPGP_weak:
  57.365 +            return "PEP_ct_OpenPGP_weak";
  57.366 +        case PEP_ct_to_be_checked_confirmed:
  57.367 +            return "PEP_ct_to_be_checked_confirmed";
  57.368 +        case PEP_ct_SMIME:
  57.369 +            return "PEP_ct_SMIME";
  57.370 +        case PEP_ct_CMS:
  57.371 +            return "PEP_ct_CMS";
  57.372 +        case PEP_ct_strong_encryption:
  57.373 +            return "PEP_ct_strong_encryption";
  57.374 +        case PEP_ct_OpenPGP:
  57.375 +            return "PEP_ct_OpenPGP";
  57.376 +        case PEP_ct_OTR:
  57.377 +            return "PEP_ct_OTR";
  57.378 +        case PEP_ct_confirmed_enc_anon:
  57.379 +            return "PEP_ct_confirmed_enc_anon";
  57.380 +        case PEP_ct_pEp:
  57.381 +            return "PEP_ct_pEp";
  57.382 +        default:
  57.383 +            return "PEP_ct_OMGWTFBBQ\n\nIn other words, comm type is invalid. Either something's corrupt or a new ct value has been added to the enum but not to the test function.";
  57.384 +    }
  57.385 +}
  57.386 +
  57.387 +bool slurp_and_import_key(PEP_SESSION session, const char* key_filename) {
  57.388 +    std::string keyfile = slurp(key_filename);
  57.389 +    if (import_key(session, keyfile.c_str(), keyfile.size(), NULL) != PEP_TEST_KEY_IMPORT_SUCCESS)
  57.390 +        return false;
  57.391 +    return true;
  57.392 +}
  57.393 +
  57.394 +bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename) {
  57.395 +    bool ok = true;
  57.396 +    message = slurp(message_fname);
  57.397 +    if (key_filename)
  57.398 +        ok = slurp_and_import_key(session, key_filename);
  57.399 +    return ok;
  57.400 +}
  57.401 +
  57.402 +
  57.403 +
  57.404 +int util_delete_filepath(const char *filepath, 
  57.405 +                         const struct stat *file_stat, 
  57.406 +                         int ftw_info, 
  57.407 +                         struct FTW * ftw_struct) {
  57.408 +    int retval = 0;
  57.409 +    switch (ftw_info) {
  57.410 +        case FTW_DP:
  57.411 +            retval = rmdir(filepath);
  57.412 +            break;
  57.413 +        case FTW_F:
  57.414 +        case FTW_SLN:
  57.415 +            retval = unlink(filepath);
  57.416 +            break;    
  57.417 +        default:
  57.418 +            retval = -1;
  57.419 +    }
  57.420 +    
  57.421 +    return retval;
  57.422 +}