File moves local_cpptest
authorKrista Bennett <krista@pep-project.org>
Mon, 30 Apr 2018 09:23:34 +0200
branchlocal_cpptest
changeset 263504e6df2957e8
parent 2634 b754efa45304
child 2637 30db80f1a874
File moves
.hgignore
test/DecorateTests.cc
test/DecorateTests.h
test/EngineTestIndividualSuite.cc
test/EngineTestIndividualSuite.h
test/EngineTestSessionSuite.cc
test/EngineTestSessionSuite.h
test/EngineTestSuite.cc
test/EngineTestSuite.h
test/SuiteMaker.cc
test/SuiteMaker.h
test/TestDriver.cc
test/TestDriver.h
test/include/DecorateTests.h
test/include/EngineTestIndividualSuite.h
test/include/EngineTestSessionSuite.h
test/include/EngineTestSuite.h
test/include/SuiteMaker.h
test/include/TestDriver.h
test/include/test_util.h
test/src/EngineTestIndividualSuite.cc
test/src/EngineTestSessionSuite.cc
test/src/EngineTestSuite.cc
test/src/SuiteMaker.cc
test/src/TestDriver.cc
test/src/engine_tests/DecorateTests.cc
test/src/util/test_util.cc
test/test_util.cc
test/test_util.h
     1.1 --- a/.hgignore	Thu Apr 26 17:30:42 2018 +0200
     1.2 +++ b/.hgignore	Mon Apr 30 09:23:34 2018 +0200
     1.3 @@ -61,4 +61,4 @@
     1.4  __pycache__
     1.5  *.pyc
     1.6  test/python_tests/test?
     1.7 -
     1.8 +GNUMakefile
     2.1 --- a/test/DecorateTests.cc	Thu Apr 26 17:30:42 2018 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,78 +0,0 @@
     2.4 -// This file is under GNU General Public License 3.0
     2.5 -// see LICENSE.txt
     2.6 -
     2.7 -#include <stdlib.h>
     2.8 -#include <string.h>
     2.9 -#include "platform.h"
    2.10 -#include <iostream>
    2.11 -#include <fstream>
    2.12 -#include <TEST_ASSERT.h>
    2.13 -#include <sstream>
    2.14 -#include "mime.h"
    2.15 -#include "message_api.h"
    2.16 -#include "test_util.h"
    2.17 -
    2.18 -using namespace std;
    2.19 -
    2.20 -DecorateTests::DecorateTests(string suitename, string test_home_dir) : 
    2.21 -    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
    2.22 -    TEST_ADD(DecorateTests::check_decorate);
    2.23 -}
    2.24 -
    2.25 -void DecorateTests::check_decorate() {
    2.26 -
    2.27 -    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    2.28 -    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
    2.29 -    const string bob_pub_key = slurp("test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
    2.30 -    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
    2.31 -    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
    2.32 -    PEP_STATUS statusbob = import_key(session, bob_pub_key.c_str(), bob_pub_key.length(), NULL);
    2.33 -    TEST_ASSERT(statuspub == PEP_STATUS_OK);
    2.34 -    TEST_ASSERT(statuspriv == PEP_STATUS_OK);
    2.35 -    TEST_ASSERT(statusbob == PEP_STATUS_OK);
    2.36 -
    2.37 -    cout << "creating message…\n";
    2.38 -    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
    2.39 -    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
    2.40 -    alice->me = true;
    2.41 -    identity_list* to_list = new_identity_list(bob); // to bob
    2.42 -    message* outgoing_message = new_message(PEP_dir_outgoing);
    2.43 -    TEST_ASSERT(outgoing_message);
    2.44 -    outgoing_message->from = alice;
    2.45 -    outgoing_message->to = to_list;
    2.46 -    outgoing_message->shortmsg = strdup("Greetings, humans!");
    2.47 -    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    2.48 -    outgoing_message->longmsg = strdup("This is a dumb message.\nBut it's done.\n");
    2.49 -    TEST_ASSERT(outgoing_message->longmsg);
    2.50 -    cout << "message created.\n";
    2.51 -
    2.52 -    char* encoded_text = nullptr;
    2.53 -
    2.54 -    message* encrypted_msg = nullptr;
    2.55 -    cout << "calling encrypt_message\n";
    2.56 -    PEP_STATUS status = encrypt_message (session, outgoing_message, NULL, &encrypted_msg, PEP_enc_PGP_MIME, 0);
    2.57 -    cout << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
    2.58 -    TEST_ASSERT(status == PEP_STATUS_OK);
    2.59 -    TEST_ASSERT(encrypted_msg);
    2.60 -    cout << "message encrypted.\n";
    2.61 -    
    2.62 -    status = mime_encode_message(encrypted_msg, false, &encoded_text);
    2.63 -    TEST_ASSERT(status == PEP_STATUS_OK);
    2.64 -    TEST_ASSERT(encoded_text);
    2.65 -    
    2.66 -    bool contains_version = false;
    2.67 -    
    2.68 -    const char* version_str = "X-pEp-Version: ";
    2.69 -    size_t version_prefix_len = strlen(version_str);
    2.70 -    
    2.71 -    istringstream f(encoded_text);
    2.72 -    string enc_string;
    2.73 -    while (getline(f, enc_string)) {
    2.74 -        if (strncmp(enc_string.c_str(), version_str, version_prefix_len) == 0)
    2.75 -            contains_version = true;
    2.76 -    }
    2.77 -    TEST_ASSERT(contains_version);
    2.78 -    
    2.79 -    if (contains_version)
    2.80 -        cout << "Version string in encrypted message, as it should be." << endl;    
    2.81 -}
     3.1 --- a/test/DecorateTests.h	Thu Apr 26 17:30:42 2018 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,21 +0,0 @@
     3.4 -// This file is under GNU General Public License 3.0
     3.5 -// see LICENSE.txt
     3.6 -
     3.7 -#include <stdlib.h>
     3.8 -#include <string.h>
     3.9 -#include "platform.h"
    3.10 -#include <iostream>
    3.11 -#include <fstream>
    3.12 -#include <sstream>
    3.13 -#include "mime.h"
    3.14 -#include "message_api.h"
    3.15 -#include "test_util.h"
    3.16 -
    3.17 -using namespace std;
    3.18 -
    3.19 -class DecorateTests : public EngineTestSessionSuite {
    3.20 -    public:
    3.21 -        DecorateTests(string suitename, string test_home_dir);
    3.22 -    private:
    3.23 -        void check_decorate();
    3.24 -};
     4.1 --- a/test/EngineTestIndividualSuite.cc	Thu Apr 26 17:30:42 2018 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,16 +0,0 @@
     4.4 -#include <stdlib.h>
     4.5 -#include <unistd.h>
     4.6 -#include <ftw.h>
     4.7 -
     4.8 -#include "EngineTest.h"
     4.9 -using namespace std;
    4.10 -
    4.11 -void EngineTestIndividualSuite::setup() {
    4.12 -    set_full_env(); // This will be called by default before every test
    4.13 -}
    4.14 -
    4.15 -void EngineTestIndividualSuite::tear_down() {
    4.16 -    cout << "calling release()\n";
    4.17 -    release(session);
    4.18 -    restore_full_env();
    4.19 -}
     5.1 --- a/test/EngineTestIndividualSuite.h	Thu Apr 26 17:30:42 2018 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,18 +0,0 @@
     5.4 -#ifndef ENGINE_INDIVIDUAL_SESSION_SUITE_H
     5.5 -#define ENGINE_INDIVIDUAL_SESSION_SUITE_H
     5.6 -
     5.7 -#include <cpptest-suite.h>
     5.8 -#include <string>
     5.9 -#include "pEpEngine.h"
    5.10 -
    5.11 -using namespace std;
    5.12 -
    5.13 -class EngineTestIndividualSuite : public EngineTestSuite {
    5.14 -    public:
    5.15 -        EngineIndividualTestSuite(string suitename, string test_home_dir);
    5.16 -        ~EngineIndividualTestSuite();
    5.17 -    protected:
    5.18 -        virtual void setup();
    5.19 -        virtual void tear_down();
    5.20 -};
    5.21 -#endif
     6.1 --- a/test/EngineTestSessionSuite.cc	Thu Apr 26 17:30:42 2018 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,16 +0,0 @@
     6.4 -#include <stdlib.h>
     6.5 -#include <unistd.h>
     6.6 -#include <ftw.h>
     6.7 -
     6.8 -#include "EngineTestSuite.h"
     6.9 -using namespace std;
    6.10 -
    6.11 -// Constructor
    6.12 -EngineTestSessionSuite::EngineTestSessionSuite(string suitename, string test_home_dir) :
    6.13 -    EngineTestSuite::EngineTestSuite(suitename, test_home_dir) {
    6.14 -    set_full_env();
    6.15 -}
    6.16 -
    6.17 -EngineTestSessionSuite::~EngineTestSessionSuite() {
    6.18 -    restore_full_env();
    6.19 -}
     7.1 --- a/test/EngineTestSessionSuite.h	Thu Apr 26 17:30:42 2018 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,15 +0,0 @@
     7.4 -#ifndef ENGINE_TEST_SESSION_SUITE_H
     7.5 -#define ENGINE_TEST_SESSION_SUITE_H
     7.6 -
     7.7 -#include <cpptest-suite.h>
     7.8 -#include <string>
     7.9 -#include "pEpEngine.h"
    7.10 -
    7.11 -using namespace std;
    7.12 -
    7.13 -class EngineTestSessionSuite : public EngineTestSuite {
    7.14 -    public:
    7.15 -        EngineTestSessionSuite(string suitename, string test_home_dir);
    7.16 -        ~EngineTestSessionSuite();
    7.17 -};
    7.18 -#endif
     8.1 --- a/test/EngineTestSuite.cc	Thu Apr 26 17:30:42 2018 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,94 +0,0 @@
     8.4 -#include <stdlib.h>
     8.5 -#include <unistd.h>
     8.6 -#include <ftw.h>
     8.7 -
     8.8 -#include "EngineTestSuite.h"
     8.9 -using namespace std;
    8.10 -
    8.11 -// Constructor
    8.12 -EngineTestSuite::EngineTestSuite(string suitename, string test_home_dir) {
    8.13 -    // FIXME: deal with base
    8.14 -    test_home = test_home_dir;
    8.15 -    
    8.16 -    // TODO: This is *nix specific, which the current testing env is anyway,
    8.17 -    // but it needn't remain so forever and always.
    8.18 -    prev_gpg_home = getenv("GNUPGHOME");
    8.19 -}
    8.20 -
    8.21 -void EngineTestSuite::set_full_env() {
    8.22 -
    8.23 -    if (test_home.empty())
    8.24 -        throw "SETUP: BAD INITIALISATION. No test home.";
    8.25 -    
    8.26 -    int success = system("gpgconf --kill all");
    8.27 -    if (success != 0)
    8.28 -        throw "SETUP: Error when executing 'gpgconf --kill all'.";
    8.29 -    
    8.30 -    string home = getenv("HOME");
    8.31 -    if (test_home.compare(home) == 0 || test_home.compare(home + "/") == 0 ||
    8.32 -        test_home.compare(home + "/.gnupg") == 0 || test_home.compare(home + ".gnupg") == 0 ||
    8.33 -        test_home.compare(prev_gpg_home) == 0 || test_home.compare(prev_gpg_home + "/.gnupg") == 0 ||
    8.34 -        test_home.compare(prev_gpg_home + ".gnupg") == 0)
    8.35 -        throw "SETUP: new GNUPGHOME threatens to mess up user GNUPGHOME (and delete all their keys). NO DICE.";
    8.36 -    
    8.37 -    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;
    8.38 -    
    8.39 -    struct stat buf;
    8.40 -    if (stat(test_home.c_str(), &buf) == 0) {
    8.41 -        cout << test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
    8.42 -        success = nftw(test_home.c_str(), util_delete_filepath, 100, FTW_DEPTH);
    8.43 -        if (success != 0)
    8.44 -            throw "SETUP: can't delete the whole directory.";
    8.45 -    }
    8.46 -    
    8.47 -    success = setenv("GNUPGHOME", (test_home + "/.gnupg").c_str(), 1);
    8.48 -    if (success != 0)
    8.49 -        throw "SETUP: Error when setting GNUPGHOME.";
    8.50 -
    8.51 -    success = setenv("HOME", test_home.c_str(), 1);
    8.52 -    if (success != 0)
    8.53 -        throw "SETUP: Cannot set test_home for init.";
    8.54 -    
    8.55 -    cout << "calling init()\n";
    8.56 -    PEP_STATUS status = init(&session);
    8.57 -    // assert(status == PEP_STATUS_OK);
    8.58 -    // assert(session);
    8.59 -    cout << "init() completed.\n";
    8.60 -
    8.61 -    success = setenv("HOME", home.c_str(), 1);
    8.62 -    if (success != 0)
    8.63 -        throw "SETUP: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!";    
    8.64 -}
    8.65 -
    8.66 -void EngineTestSuite::restore_full_env() {
    8.67 -    int success = system("gpgconf --kill all");
    8.68 -    if (success != 0)
    8.69 -        throw "RESTORE: Error when executing 'gpgconf --kill all'.";
    8.70 -
    8.71 -    success = setenv("GNUPGHOME", prev_gpg_home.c_str(), 1);
    8.72 -    if (success != 0)
    8.73 -        throw "RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!";
    8.74 -}
    8.75 -
    8.76 -int EngineTestSuite::util_delete_filepath(const char *filepath, 
    8.77 -                                     const struct stat *file_stat, 
    8.78 -                                     int ftw_info, 
    8.79 -                                     struct FTW * ftw_struct) {
    8.80 -    int retval = 0;
    8.81 -    switch (ftw_info) {
    8.82 -        case FTW_DP:
    8.83 -            retval = rmdir(filepath);
    8.84 -            break;
    8.85 -        case FTW_F:
    8.86 -        case FTW_SLN:
    8.87 -            retval = unlink(filepath);
    8.88 -            break;    
    8.89 -        default:
    8.90 -            retval = -1;
    8.91 -    }
    8.92 -    
    8.93 -    return retval;
    8.94 -}
    8.95 -
    8.96 -void EngineTestSuite::setup() {}
    8.97 -void EngineTestSuite::tear_down() {}
     9.1 --- a/test/EngineTestSuite.h	Thu Apr 26 17:30:42 2018 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,32 +0,0 @@
     9.4 -#ifndef ENGINE_TEST_SUITE_H
     9.5 -#define ENGINE_TEST_SUITE_H
     9.6 -
     9.7 -#include <cpptest-suite.h>
     9.8 -#include <string>
     9.9 -#include "pEpEngine.h"
    9.10 -
    9.11 -using namespace std;
    9.12 -
    9.13 -class EngineTestSuite : public Test::Suite {
    9.14 -    public:
    9.15 -        EngineTestSuite(string suitename, string test_home_dir);
    9.16 -        
    9.17 -    protected:
    9.18 -        PEP_SESSION session;
    9.19 -        string test_home;
    9.20 -        string prev_gpg_home;
    9.21 -        string name;
    9.22 -        
    9.23 -        virtual void setup();
    9.24 -        virtual void tear_down();
    9.25 -        void set_full_env();
    9.26 -        void restore_full_env();
    9.27 -        void initialise_test_home();
    9.28 -        
    9.29 -    private:
    9.30 -        static int util_delete_filepath(const char *filepath, 
    9.31 -                                        const struct stat *file_stat, 
    9.32 -                                        int ftw_info, 
    9.33 -                                        struct FTW * ftw_struct);
    9.34 -};
    9.35 -#endif
    10.1 --- a/test/SuiteMaker.cc	Thu Apr 26 17:30:42 2018 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,16 +0,0 @@
    10.4 -#include <cpptest-suite.h>
    10.5 -#include <string>
    10.6 -#include <sys/stat.h>
    10.7 -#include <errno.h>
    10.8 -#include "EngineTestSuite.h"
    10.9 -#include "EngineTestIndividualSuite.h"
   10.10 -#include "EngineTestSessionSuite.h"
   10.11 -
   10.12 -// Begin where we should generate stuff
   10.13 -#include "DecorateTests.h"
   10.14 -
   10.15 -static EngineTestSuite* build(const char* test_class_name, const char* test_home) {
   10.16 -    if (strcmp(test_class_name, "DecorateTests") == 0)
   10.17 -        return new DecorateTests(test_class_name, test_home);
   10.18 -    return NULL;
   10.19 -}
    11.1 --- a/test/SuiteMaker.h	Thu Apr 26 17:30:42 2018 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,16 +0,0 @@
    11.4 -#include <cpptest-suite.h>
    11.5 -#include <string>
    11.6 -#include <sys/stat.h>
    11.7 -#include <errno.h>
    11.8 -#include "EngineTestSuite.h"
    11.9 -#include "EngineTestIndividualSuite.h"
   11.10 -#include "EngineTestSessionSuite.h"
   11.11 -
   11.12 -// Begin where we should generate stuff
   11.13 -#include "DecorateTests.h"
   11.14 -
   11.15 -class SuiteMaker {
   11.16 -    public:
   11.17 -        static EngineTestSuite* build(const char* test_class_name, 
   11.18 -                                      const char* test_home);
   11.19 -};
    12.1 --- a/test/TestDriver.cc	Thu Apr 26 17:30:42 2018 +0200
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,71 +0,0 @@
    12.4 -#include <cpptest-suite.h>
    12.5 -#include <string>
    12.6 -#include <sys/stat.h>
    12.7 -#include <errno.h>
    12.8 -#include "EngineTestSuite.h"
    12.9 -#include "EngineTestIndividualSuite.h"
   12.10 -#include "EngineTestSessionSuite.h"
   12.11 -
   12.12 -using namespace std;
   12.13 -
   12.14 -string common_test_home = "~/pEp_tests";
   12.15 -
   12.16 -void usage() {
   12.17 -    throw "Bad usage. Fix me, you loser developer.";
   12.18 -}
   12.19 -
   12.20 -EngineTestSuite* 
   12.21 -
   12.22 -
   12.23 -
   12.24 -int main(int argc, char** argv) {
   12.25 -    const int MIN_ARGC = 1;
   12.26 -    if (argc < MIN_ARGC)
   12.27 -        usage();
   12.28 -
   12.29 -    int start_index = 1;
   12.30 -    
   12.31 -
   12.32 -    if (argc > 1) {
   12.33 -        string tmpstr = argv[1];
   12.34 -        if (tmpstr.compare(0,10,"--testdir=")) {
   12.35 -            try {
   12.36 -                tmpstr = tmpstr.substr(10);
   12.37 -            } 
   12.38 -            catch (std::out_of_range o) {
   12.39 -                usage();
   12.40 -            }
   12.41 -            common_test_home = tmpstr;
   12.42 -            start_index++;
   12.43 -        }
   12.44 -    }
   12.45 -
   12.46 -    struct stat dirchk;
   12.47 -    if (stat(common_test_home.c_str(), &dirchk) == 0) {
   12.48 -        if (!S_ISDIR(dirchk.st_mode))
   12.49 -            throw ("The test directory, " + common_test_home + "exists, but is not a directory.").c_str(); 
   12.50 -    }
   12.51 -    else if (common_test_home.compare("~/pEp_tests")) {
   12.52 -        int errchk = mkdir(common_test_home);
   12.53 -        if (errchk != 0)
   12.54 -            throw "Error creating a test directory.";
   12.55 -    }
   12.56 -    else
   12.57 -        throw "Test directory does not exist. Test directories from the command line must be created first. Because we're lazy.";
   12.58 -        
   12.59 -            
   12.60 -    EngineTestSuite* test_runner = new EngineTestSuite("MainTestDriver", test_home);
   12.61 -        
   12.62 -    for (int i = start_index; i < argc; i++) {
   12.63 -        char* curr_arg = argv[i];
   12.64 -        EngineTestSuite* test_suite = SuiteMaker.build(argv[i], common_test_home);
   12.65 -        if (!test_suite)
   12.66 -            throw "Could not create a test suite instance."; // FIXME, better error, cleanup, obviously
   12.67 -        test_runner.add(test_suite);
   12.68 -        test_suite = NULL;
   12.69 -    }
   12.70 -
   12.71 -    Test::TextOutput output(Test::TextOutput::Terse);
   12.72 -    return test_runner.run(output) ? 1 : 0;
   12.73 -    
   12.74 -}
    13.1 --- a/test/TestDriver.h	Thu Apr 26 17:30:42 2018 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,11 +0,0 @@
    13.4 -#include <cpptest-suite.h>
    13.5 -#include <string>
    13.6 -#include <map>
    13.7 -#include "EngineTestSuite.h"
    13.8 -#include "EngineTestIndividualSuite.h"
    13.9 -#include "EngineTestSessionSuite.h"
   13.10 -
   13.11 -using namespace std;
   13.12 -
   13.13 -typedef map<string, EngineTestSuite> SuiteMap;
   13.14 -typedef set<string> NameSet;
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/include/DecorateTests.h	Mon Apr 30 09:23:34 2018 +0200
    14.3 @@ -0,0 +1,21 @@
    14.4 +// This file is under GNU General Public License 3.0
    14.5 +// see LICENSE.txt
    14.6 +
    14.7 +#include <stdlib.h>
    14.8 +#include <string.h>
    14.9 +#include "platform.h"
   14.10 +#include <iostream>
   14.11 +#include <fstream>
   14.12 +#include <sstream>
   14.13 +#include "mime.h"
   14.14 +#include "message_api.h"
   14.15 +#include "test_util.h"
   14.16 +
   14.17 +using namespace std;
   14.18 +
   14.19 +class DecorateTests : public EngineTestSessionSuite {
   14.20 +    public:
   14.21 +        DecorateTests(string suitename, string test_home_dir);
   14.22 +    private:
   14.23 +        void check_decorate();
   14.24 +};
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/test/include/EngineTestIndividualSuite.h	Mon Apr 30 09:23:34 2018 +0200
    15.3 @@ -0,0 +1,18 @@
    15.4 +#ifndef ENGINE_INDIVIDUAL_SESSION_SUITE_H
    15.5 +#define ENGINE_INDIVIDUAL_SESSION_SUITE_H
    15.6 +
    15.7 +#include <cpptest-suite.h>
    15.8 +#include <string>
    15.9 +#include "pEpEngine.h"
   15.10 +
   15.11 +using namespace std;
   15.12 +
   15.13 +class EngineTestIndividualSuite : public EngineTestSuite {
   15.14 +    public:
   15.15 +        EngineIndividualTestSuite(string suitename, string test_home_dir);
   15.16 +        ~EngineIndividualTestSuite();
   15.17 +    protected:
   15.18 +        virtual void setup();
   15.19 +        virtual void tear_down();
   15.20 +};
   15.21 +#endif
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/include/EngineTestSessionSuite.h	Mon Apr 30 09:23:34 2018 +0200
    16.3 @@ -0,0 +1,15 @@
    16.4 +#ifndef ENGINE_TEST_SESSION_SUITE_H
    16.5 +#define ENGINE_TEST_SESSION_SUITE_H
    16.6 +
    16.7 +#include <cpptest-suite.h>
    16.8 +#include <string>
    16.9 +#include "pEpEngine.h"
   16.10 +
   16.11 +using namespace std;
   16.12 +
   16.13 +class EngineTestSessionSuite : public EngineTestSuite {
   16.14 +    public:
   16.15 +        EngineTestSessionSuite(string suitename, string test_home_dir);
   16.16 +        ~EngineTestSessionSuite();
   16.17 +};
   16.18 +#endif
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/include/EngineTestSuite.h	Mon Apr 30 09:23:34 2018 +0200
    17.3 @@ -0,0 +1,32 @@
    17.4 +#ifndef ENGINE_TEST_SUITE_H
    17.5 +#define ENGINE_TEST_SUITE_H
    17.6 +
    17.7 +#include <cpptest-suite.h>
    17.8 +#include <string>
    17.9 +#include "pEpEngine.h"
   17.10 +
   17.11 +using namespace std;
   17.12 +
   17.13 +class EngineTestSuite : public Test::Suite {
   17.14 +    public:
   17.15 +        EngineTestSuite(string suitename, string test_home_dir);
   17.16 +        
   17.17 +    protected:
   17.18 +        PEP_SESSION session;
   17.19 +        string test_home;
   17.20 +        string prev_gpg_home;
   17.21 +        string name;
   17.22 +        
   17.23 +        virtual void setup();
   17.24 +        virtual void tear_down();
   17.25 +        void set_full_env();
   17.26 +        void restore_full_env();
   17.27 +        void initialise_test_home();
   17.28 +        
   17.29 +    private:
   17.30 +        static int util_delete_filepath(const char *filepath, 
   17.31 +                                        const struct stat *file_stat, 
   17.32 +                                        int ftw_info, 
   17.33 +                                        struct FTW * ftw_struct);
   17.34 +};
   17.35 +#endif
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/test/include/SuiteMaker.h	Mon Apr 30 09:23:34 2018 +0200
    18.3 @@ -0,0 +1,16 @@
    18.4 +#include <cpptest-suite.h>
    18.5 +#include <string>
    18.6 +#include <sys/stat.h>
    18.7 +#include <errno.h>
    18.8 +#include "EngineTestSuite.h"
    18.9 +#include "EngineTestIndividualSuite.h"
   18.10 +#include "EngineTestSessionSuite.h"
   18.11 +
   18.12 +// Begin where we should generate stuff
   18.13 +#include "DecorateTests.h"
   18.14 +
   18.15 +class SuiteMaker {
   18.16 +    public:
   18.17 +        static EngineTestSuite* build(const char* test_class_name, 
   18.18 +                                      const char* test_home);
   18.19 +};
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/test/include/TestDriver.h	Mon Apr 30 09:23:34 2018 +0200
    19.3 @@ -0,0 +1,11 @@
    19.4 +#include <cpptest-suite.h>
    19.5 +#include <string>
    19.6 +#include <map>
    19.7 +#include "EngineTestSuite.h"
    19.8 +#include "EngineTestIndividualSuite.h"
    19.9 +#include "EngineTestSessionSuite.h"
   19.10 +
   19.11 +using namespace std;
   19.12 +
   19.13 +typedef map<string, EngineTestSuite> SuiteMap;
   19.14 +typedef set<string> NameSet;
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/test/include/test_util.h	Mon Apr 30 09:23:34 2018 +0200
    20.3 @@ -0,0 +1,29 @@
    20.4 +#include <string>
    20.5 +#include "pEpEngine.h"
    20.6 +#include "message_api.h"
    20.7 +
    20.8 +void test_init();
    20.9 +
   20.10 +// string equality (case and non-case sensitive)
   20.11 +bool _streq(const char* str1, const char* str2);
   20.12 +bool _strceq(const char* str1, const char* str2);
   20.13 +
   20.14 +// reads a whole file and returns it as std::string
   20.15 +// throws std::runtime_error() if the file cannot be read. Empty file is not an error.
   20.16 +std::string slurp(const std::string& filename);
   20.17 +
   20.18 +// dumps char* to file
   20.19 +// throws std::runtime_error() if the file cannot be opened.
   20.20 +void dump_out(const char* filename, const char* outdata);
   20.21 +
   20.22 +// Returns the string value of the input rating enum value. 
   20.23 +const char* tl_rating_string(PEP_rating rating);
   20.24 +
   20.25 +// Returns the string value of the input comm_type enum value. 
   20.26 +const char* tl_ct_string(PEP_comm_type ct);
   20.27 +
   20.28 +// Returns the string value of the input status enum value. 
   20.29 +const char* tl_status_string(PEP_STATUS status);
   20.30 +
   20.31 +// Grabs a new uuid for your randomish string needs.
   20.32 +char* get_new_uuid();
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/test/src/EngineTestIndividualSuite.cc	Mon Apr 30 09:23:34 2018 +0200
    21.3 @@ -0,0 +1,16 @@
    21.4 +#include <stdlib.h>
    21.5 +#include <unistd.h>
    21.6 +#include <ftw.h>
    21.7 +
    21.8 +#include "EngineTest.h"
    21.9 +using namespace std;
   21.10 +
   21.11 +void EngineTestIndividualSuite::setup() {
   21.12 +    set_full_env(); // This will be called by default before every test
   21.13 +}
   21.14 +
   21.15 +void EngineTestIndividualSuite::tear_down() {
   21.16 +    cout << "calling release()\n";
   21.17 +    release(session);
   21.18 +    restore_full_env();
   21.19 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/test/src/EngineTestSessionSuite.cc	Mon Apr 30 09:23:34 2018 +0200
    22.3 @@ -0,0 +1,16 @@
    22.4 +#include <stdlib.h>
    22.5 +#include <unistd.h>
    22.6 +#include <ftw.h>
    22.7 +
    22.8 +#include "EngineTestSuite.h"
    22.9 +using namespace std;
   22.10 +
   22.11 +// Constructor
   22.12 +EngineTestSessionSuite::EngineTestSessionSuite(string suitename, string test_home_dir) :
   22.13 +    EngineTestSuite::EngineTestSuite(suitename, test_home_dir) {
   22.14 +    set_full_env();
   22.15 +}
   22.16 +
   22.17 +EngineTestSessionSuite::~EngineTestSessionSuite() {
   22.18 +    restore_full_env();
   22.19 +}
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/test/src/EngineTestSuite.cc	Mon Apr 30 09:23:34 2018 +0200
    23.3 @@ -0,0 +1,94 @@
    23.4 +#include <stdlib.h>
    23.5 +#include <unistd.h>
    23.6 +#include <ftw.h>
    23.7 +
    23.8 +#include "EngineTestSuite.h"
    23.9 +using namespace std;
   23.10 +
   23.11 +// Constructor
   23.12 +EngineTestSuite::EngineTestSuite(string suitename, string test_home_dir) {
   23.13 +    // FIXME: deal with base
   23.14 +    test_home = test_home_dir;
   23.15 +    
   23.16 +    // TODO: This is *nix specific, which the current testing env is anyway,
   23.17 +    // but it needn't remain so forever and always.
   23.18 +    prev_gpg_home = getenv("GNUPGHOME");
   23.19 +}
   23.20 +
   23.21 +void EngineTestSuite::set_full_env() {
   23.22 +
   23.23 +    if (test_home.empty())
   23.24 +        throw "SETUP: BAD INITIALISATION. No test home.";
   23.25 +    
   23.26 +    int success = system("gpgconf --kill all");
   23.27 +    if (success != 0)
   23.28 +        throw "SETUP: Error when executing 'gpgconf --kill all'.";
   23.29 +    
   23.30 +    string home = getenv("HOME");
   23.31 +    if (test_home.compare(home) == 0 || test_home.compare(home + "/") == 0 ||
   23.32 +        test_home.compare(home + "/.gnupg") == 0 || test_home.compare(home + ".gnupg") == 0 ||
   23.33 +        test_home.compare(prev_gpg_home) == 0 || test_home.compare(prev_gpg_home + "/.gnupg") == 0 ||
   23.34 +        test_home.compare(prev_gpg_home + ".gnupg") == 0)
   23.35 +        throw "SETUP: new GNUPGHOME threatens to mess up user GNUPGHOME (and delete all their keys). NO DICE.";
   23.36 +    
   23.37 +    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;
   23.38 +    
   23.39 +    struct stat buf;
   23.40 +    if (stat(test_home.c_str(), &buf) == 0) {
   23.41 +        cout << test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
   23.42 +        success = nftw(test_home.c_str(), util_delete_filepath, 100, FTW_DEPTH);
   23.43 +        if (success != 0)
   23.44 +            throw "SETUP: can't delete the whole directory.";
   23.45 +    }
   23.46 +    
   23.47 +    success = setenv("GNUPGHOME", (test_home + "/.gnupg").c_str(), 1);
   23.48 +    if (success != 0)
   23.49 +        throw "SETUP: Error when setting GNUPGHOME.";
   23.50 +
   23.51 +    success = setenv("HOME", test_home.c_str(), 1);
   23.52 +    if (success != 0)
   23.53 +        throw "SETUP: Cannot set test_home for init.";
   23.54 +    
   23.55 +    cout << "calling init()\n";
   23.56 +    PEP_STATUS status = init(&session);
   23.57 +    // assert(status == PEP_STATUS_OK);
   23.58 +    // assert(session);
   23.59 +    cout << "init() completed.\n";
   23.60 +
   23.61 +    success = setenv("HOME", home.c_str(), 1);
   23.62 +    if (success != 0)
   23.63 +        throw "SETUP: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!";    
   23.64 +}
   23.65 +
   23.66 +void EngineTestSuite::restore_full_env() {
   23.67 +    int success = system("gpgconf --kill all");
   23.68 +    if (success != 0)
   23.69 +        throw "RESTORE: Error when executing 'gpgconf --kill all'.";
   23.70 +
   23.71 +    success = setenv("GNUPGHOME", prev_gpg_home.c_str(), 1);
   23.72 +    if (success != 0)
   23.73 +        throw "RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!";
   23.74 +}
   23.75 +
   23.76 +int EngineTestSuite::util_delete_filepath(const char *filepath, 
   23.77 +                                     const struct stat *file_stat, 
   23.78 +                                     int ftw_info, 
   23.79 +                                     struct FTW * ftw_struct) {
   23.80 +    int retval = 0;
   23.81 +    switch (ftw_info) {
   23.82 +        case FTW_DP:
   23.83 +            retval = rmdir(filepath);
   23.84 +            break;
   23.85 +        case FTW_F:
   23.86 +        case FTW_SLN:
   23.87 +            retval = unlink(filepath);
   23.88 +            break;    
   23.89 +        default:
   23.90 +            retval = -1;
   23.91 +    }
   23.92 +    
   23.93 +    return retval;
   23.94 +}
   23.95 +
   23.96 +void EngineTestSuite::setup() {}
   23.97 +void EngineTestSuite::tear_down() {}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/test/src/SuiteMaker.cc	Mon Apr 30 09:23:34 2018 +0200
    24.3 @@ -0,0 +1,16 @@
    24.4 +#include <cpptest-suite.h>
    24.5 +#include <string>
    24.6 +#include <sys/stat.h>
    24.7 +#include <errno.h>
    24.8 +#include "EngineTestSuite.h"
    24.9 +#include "EngineTestIndividualSuite.h"
   24.10 +#include "EngineTestSessionSuite.h"
   24.11 +
   24.12 +// Begin where we should generate stuff
   24.13 +#include "DecorateTests.h"
   24.14 +
   24.15 +static EngineTestSuite* build(const char* test_class_name, const char* test_home) {
   24.16 +    if (strcmp(test_class_name, "DecorateTests") == 0)
   24.17 +        return new DecorateTests(test_class_name, test_home);
   24.18 +    return NULL;
   24.19 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/test/src/TestDriver.cc	Mon Apr 30 09:23:34 2018 +0200
    25.3 @@ -0,0 +1,71 @@
    25.4 +#include <cpptest-suite.h>
    25.5 +#include <string>
    25.6 +#include <sys/stat.h>
    25.7 +#include <errno.h>
    25.8 +#include "EngineTestSuite.h"
    25.9 +#include "EngineTestIndividualSuite.h"
   25.10 +#include "EngineTestSessionSuite.h"
   25.11 +
   25.12 +using namespace std;
   25.13 +
   25.14 +string common_test_home = "~/pEp_tests";
   25.15 +
   25.16 +void usage() {
   25.17 +    throw "Bad usage. Fix me, you loser developer.";
   25.18 +}
   25.19 +
   25.20 +EngineTestSuite* 
   25.21 +
   25.22 +
   25.23 +
   25.24 +int main(int argc, char** argv) {
   25.25 +    const int MIN_ARGC = 1;
   25.26 +    if (argc < MIN_ARGC)
   25.27 +        usage();
   25.28 +
   25.29 +    int start_index = 1;
   25.30 +    
   25.31 +
   25.32 +    if (argc > 1) {
   25.33 +        string tmpstr = argv[1];
   25.34 +        if (tmpstr.compare(0,10,"--testdir=")) {
   25.35 +            try {
   25.36 +                tmpstr = tmpstr.substr(10);
   25.37 +            } 
   25.38 +            catch (std::out_of_range o) {
   25.39 +                usage();
   25.40 +            }
   25.41 +            common_test_home = tmpstr;
   25.42 +            start_index++;
   25.43 +        }
   25.44 +    }
   25.45 +
   25.46 +    struct stat dirchk;
   25.47 +    if (stat(common_test_home.c_str(), &dirchk) == 0) {
   25.48 +        if (!S_ISDIR(dirchk.st_mode))
   25.49 +            throw ("The test directory, " + common_test_home + "exists, but is not a directory.").c_str(); 
   25.50 +    }
   25.51 +    else if (common_test_home.compare("~/pEp_tests")) {
   25.52 +        int errchk = mkdir(common_test_home);
   25.53 +        if (errchk != 0)
   25.54 +            throw "Error creating a test directory.";
   25.55 +    }
   25.56 +    else
   25.57 +        throw "Test directory does not exist. Test directories from the command line must be created first. Because we're lazy.";
   25.58 +        
   25.59 +            
   25.60 +    EngineTestSuite* test_runner = new EngineTestSuite("MainTestDriver", test_home);
   25.61 +        
   25.62 +    for (int i = start_index; i < argc; i++) {
   25.63 +        char* curr_arg = argv[i];
   25.64 +        EngineTestSuite* test_suite = SuiteMaker.build(argv[i], common_test_home);
   25.65 +        if (!test_suite)
   25.66 +            throw "Could not create a test suite instance."; // FIXME, better error, cleanup, obviously
   25.67 +        test_runner.add(test_suite);
   25.68 +        test_suite = NULL;
   25.69 +    }
   25.70 +
   25.71 +    Test::TextOutput output(Test::TextOutput::Terse);
   25.72 +    return test_runner.run(output) ? 1 : 0;
   25.73 +    
   25.74 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/test/src/engine_tests/DecorateTests.cc	Mon Apr 30 09:23:34 2018 +0200
    26.3 @@ -0,0 +1,78 @@
    26.4 +// This file is under GNU General Public License 3.0
    26.5 +// see LICENSE.txt
    26.6 +
    26.7 +#include <stdlib.h>
    26.8 +#include <string.h>
    26.9 +#include "platform.h"
   26.10 +#include <iostream>
   26.11 +#include <fstream>
   26.12 +#include <TEST_ASSERT.h>
   26.13 +#include <sstream>
   26.14 +#include "mime.h"
   26.15 +#include "message_api.h"
   26.16 +#include "test_util.h"
   26.17 +
   26.18 +using namespace std;
   26.19 +
   26.20 +DecorateTests::DecorateTests(string suitename, string test_home_dir) : 
   26.21 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
   26.22 +    TEST_ADD(DecorateTests::check_decorate);
   26.23 +}
   26.24 +
   26.25 +void DecorateTests::check_decorate() {
   26.26 +
   26.27 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   26.28 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   26.29 +    const string bob_pub_key = slurp("test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
   26.30 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   26.31 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   26.32 +    PEP_STATUS statusbob = import_key(session, bob_pub_key.c_str(), bob_pub_key.length(), NULL);
   26.33 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   26.34 +    TEST_ASSERT(statuspriv == PEP_STATUS_OK);
   26.35 +    TEST_ASSERT(statusbob == PEP_STATUS_OK);
   26.36 +
   26.37 +    cout << "creating message…\n";
   26.38 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
   26.39 +    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
   26.40 +    alice->me = true;
   26.41 +    identity_list* to_list = new_identity_list(bob); // to bob
   26.42 +    message* outgoing_message = new_message(PEP_dir_outgoing);
   26.43 +    TEST_ASSERT(outgoing_message);
   26.44 +    outgoing_message->from = alice;
   26.45 +    outgoing_message->to = to_list;
   26.46 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
   26.47 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   26.48 +    outgoing_message->longmsg = strdup("This is a dumb message.\nBut it's done.\n");
   26.49 +    TEST_ASSERT(outgoing_message->longmsg);
   26.50 +    cout << "message created.\n";
   26.51 +
   26.52 +    char* encoded_text = nullptr;
   26.53 +
   26.54 +    message* encrypted_msg = nullptr;
   26.55 +    cout << "calling encrypt_message\n";
   26.56 +    PEP_STATUS status = encrypt_message (session, outgoing_message, NULL, &encrypted_msg, PEP_enc_PGP_MIME, 0);
   26.57 +    cout << "encrypt_message() returns " << tl_status_string(status) << '.' << endl;
   26.58 +    TEST_ASSERT(status == PEP_STATUS_OK);
   26.59 +    TEST_ASSERT(encrypted_msg);
   26.60 +    cout << "message encrypted.\n";
   26.61 +    
   26.62 +    status = mime_encode_message(encrypted_msg, false, &encoded_text);
   26.63 +    TEST_ASSERT(status == PEP_STATUS_OK);
   26.64 +    TEST_ASSERT(encoded_text);
   26.65 +    
   26.66 +    bool contains_version = false;
   26.67 +    
   26.68 +    const char* version_str = "X-pEp-Version: ";
   26.69 +    size_t version_prefix_len = strlen(version_str);
   26.70 +    
   26.71 +    istringstream f(encoded_text);
   26.72 +    string enc_string;
   26.73 +    while (getline(f, enc_string)) {
   26.74 +        if (strncmp(enc_string.c_str(), version_str, version_prefix_len) == 0)
   26.75 +            contains_version = true;
   26.76 +    }
   26.77 +    TEST_ASSERT(contains_version);
   26.78 +    
   26.79 +    if (contains_version)
   26.80 +        cout << "Version string in encrypted message, as it should be." << endl;    
   26.81 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/test/src/util/test_util.cc	Mon Apr 30 09:23:34 2018 +0200
    27.3 @@ -0,0 +1,319 @@
    27.4 +#include "pEpEngine_test.h"
    27.5 +#include "pEpEngine.h"
    27.6 +#include "pEp_internal.h"
    27.7 +#include "message_api.h"
    27.8 +#include <fstream>
    27.9 +#include <sstream>
   27.10 +#include <stdexcept>
   27.11 +
   27.12 +char* str_to_lower(const char* str) {
   27.13 +    if (!str)
   27.14 +        return NULL;
   27.15 +    int str_len = strlen(str);
   27.16 +    if (str_len == 0)
   27.17 +        return strdup("");
   27.18 +    int i;
   27.19 +    
   27.20 +    char* retval = (char*) calloc(1, str_len + 1);
   27.21 +    for (i = 0; i < str_len; i++) {
   27.22 +        retval[i] = tolower(str[i]);
   27.23 +    }    
   27.24 +    return retval;
   27.25 +}
   27.26 +
   27.27 +// Because annoyed
   27.28 +bool _streq(const char* str1, const char* str2) {
   27.29 +    if (!str1) {
   27.30 +        if (str2)
   27.31 +            return false;
   27.32 +        return true;
   27.33 +    }
   27.34 +    if (!str2)
   27.35 +        return false;
   27.36 +        
   27.37 +    return (strcmp(str1, str2) == 0);
   27.38 +}
   27.39 +
   27.40 +bool _strceq(const char* str1, const char* str2) {
   27.41 +    char* str1_dup = str_to_lower(str1);
   27.42 +    char* str2_dup = str_to_lower(str2);
   27.43 +
   27.44 +    bool retval = _streq(str_to_lower(str1_dup), str_to_lower(str2_dup));
   27.45 +    free(str1_dup);
   27.46 +    free(str2_dup);
   27.47 +    return retval;
   27.48 +}
   27.49 +
   27.50 +void test_init() {
   27.51 +    unlink ("../test_home/.pEp_management.db");
   27.52 +    unlink ("../test_home/.pEp_management.db-shm");
   27.53 +    unlink ("../test_home/.pEp_management.db-wal");
   27.54 +}
   27.55 +
   27.56 +std::string slurp(const std::string& filename)
   27.57 +{
   27.58 +	std::ifstream input(filename.c_str());
   27.59 +	if(!input)
   27.60 +	{
   27.61 +		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
   27.62 +	}
   27.63 +	
   27.64 +	std::stringstream sstr;
   27.65 +	sstr << input.rdbuf();
   27.66 +	return sstr.str();
   27.67 +}
   27.68 +
   27.69 +void dump_out(const char* filename, const char* outdata)
   27.70 +{
   27.71 +	std::ofstream outfile(filename);
   27.72 +	if(!outfile)
   27.73 +	{
   27.74 +		throw std::runtime_error("Cannot open output file!");
   27.75 +	}
   27.76 +	
   27.77 +	outfile << outdata;
   27.78 +    outfile.close();
   27.79 +}
   27.80 +
   27.81 +char* get_new_uuid() {
   27.82 +    char* new_uuid = (char*)calloc(37, 1);
   27.83 +    pEpUUID uuid;
   27.84 +    uuid_generate_random(uuid);
   27.85 +    uuid_unparse_upper(uuid, new_uuid);
   27.86 +    return new_uuid;
   27.87 +}
   27.88 +
   27.89 +const char* tl_status_string(PEP_STATUS status) {
   27.90 +    switch (status) {
   27.91 +        case PEP_STATUS_OK:
   27.92 +            return "PEP_STATUS_OK";
   27.93 +        case PEP_INIT_CANNOT_LOAD_GPGME:
   27.94 +            return "PEP_INIT_CANNOT_LOAD_GPGME";
   27.95 +        case PEP_INIT_GPGME_INIT_FAILED:
   27.96 +            return "PEP_INIT_GPGME_INIT_FAILED";
   27.97 +        case PEP_INIT_NO_GPG_HOME:
   27.98 +            return "PEP_INIT_NO_GPG_HOME";
   27.99 +        case PEP_INIT_NETPGP_INIT_FAILED:
  27.100 +            return "PEP_INIT_NETPGP_INIT_FAILED";
  27.101 +        case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
  27.102 +            return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
  27.103 +        case PEP_INIT_CANNOT_OPEN_DB:
  27.104 +            return "PEP_INIT_CANNOT_OPEN_DB";
  27.105 +        case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
  27.106 +            return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
  27.107 +        case PEP_KEY_NOT_FOUND:
  27.108 +            return "PEP_KEY_NOT_FOUND";
  27.109 +        case PEP_KEY_HAS_AMBIG_NAME:
  27.110 +            return "PEP_KEY_HAS_AMBIG_NAME";
  27.111 +        case PEP_GET_KEY_FAILED:
  27.112 +            return "PEP_GET_KEY_FAILED";
  27.113 +        case PEP_CANNOT_EXPORT_KEY:
  27.114 +            return "PEP_CANNOT_EXPORT_KEY";
  27.115 +        case PEP_CANNOT_EDIT_KEY:
  27.116 +            return "PEP_CANNOT_EDIT_KEY";
  27.117 +        case PEP_CANNOT_FIND_IDENTITY:
  27.118 +            return "PEP_CANNOT_FIND_IDENTITY";
  27.119 +        case PEP_CANNOT_SET_PERSON:
  27.120 +            return "PEP_CANNOT_SET_PERSON";
  27.121 +        case PEP_CANNOT_SET_PGP_KEYPAIR:
  27.122 +            return "PEP_CANNOT_SET_PGP_KEYPAIR";
  27.123 +        case PEP_CANNOT_SET_IDENTITY:
  27.124 +            return "PEP_CANNOT_SET_IDENTITY";
  27.125 +        case PEP_CANNOT_SET_TRUST:
  27.126 +            return "PEP_CANNOT_SET_TRUST";
  27.127 +        case PEP_KEY_BLACKLISTED:
  27.128 +            return "PEP_KEY_BLACKLISTED";
  27.129 +        case PEP_UNENCRYPTED:
  27.130 +            return "PEP_UNENCRYPTED";
  27.131 +        case PEP_VERIFIED:
  27.132 +            return "PEP_VERIFIED";
  27.133 +        case PEP_DECRYPTED:
  27.134 +            return "PEP_DECRYPTED";
  27.135 +        case PEP_DECRYPTED_AND_VERIFIED:
  27.136 +            return "PEP_DECRYPTED_AND_VERIFIED";
  27.137 +        case PEP_DECRYPT_WRONG_FORMAT:
  27.138 +            return "PEP_DECRYPT_WRONG_FORMAT";
  27.139 +        case PEP_DECRYPT_NO_KEY:
  27.140 +            return "PEP_DECRYPT_NO_KEY";
  27.141 +        case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
  27.142 +            return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
  27.143 +        case PEP_VERIFY_NO_KEY:
  27.144 +            return "PEP_VERIFY_NO_KEY";
  27.145 +        case PEP_VERIFIED_AND_TRUSTED:
  27.146 +            return "PEP_VERIFIED_AND_TRUSTED";
  27.147 +        case PEP_CANNOT_DECRYPT_UNKNOWN:
  27.148 +            return "PEP_CANNOT_DECRYPT_UNKNOWN";
  27.149 +        case PEP_TRUSTWORD_NOT_FOUND:
  27.150 +            return "PEP_TRUSTWORD_NOT_FOUND";
  27.151 +        case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
  27.152 +            return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
  27.153 +        case PEP_CANNOT_CREATE_KEY:
  27.154 +            return "PEP_CANNOT_CREATE_KEY";
  27.155 +        case PEP_CANNOT_SEND_KEY:
  27.156 +            return "PEP_CANNOT_SEND_KEY";
  27.157 +        case PEP_PHRASE_NOT_FOUND:
  27.158 +            return "PEP_PHRASE_NOT_FOUND";
  27.159 +        case PEP_SEND_FUNCTION_NOT_REGISTERED:
  27.160 +            return "PEP_SEND_FUNCTION_NOT_REGISTERED";
  27.161 +        case PEP_CONTRAINTS_VIOLATED:
  27.162 +            return "PEP_CONTRAINTS_VIOLATED";
  27.163 +        case PEP_CANNOT_ENCODE:
  27.164 +            return "PEP_CANNOT_ENCODE";
  27.165 +        case PEP_SYNC_NO_NOTIFY_CALLBACK:
  27.166 +            return "PEP_SYNC_NO_NOTIFY_CALLBACK";
  27.167 +        case PEP_SYNC_ILLEGAL_MESSAGE:
  27.168 +            return "PEP_SYNC_ILLEGAL_MESSAGE";
  27.169 +        case PEP_SYNC_NO_INJECT_CALLBACK:
  27.170 +            return "PEP_SYNC_NO_INJECT_CALLBACK";
  27.171 +        case PEP_SEQUENCE_VIOLATED:
  27.172 +            return "PEP_SEQUENCE_VIOLATED";
  27.173 +        case PEP_CANNOT_INCREASE_SEQUENCE:
  27.174 +            return "PEP_CANNOT_INCREASE_SEQUENCE";
  27.175 +        case PEP_CANNOT_SET_SEQUENCE_VALUE:
  27.176 +            return "PEP_CANNOT_SET_SEQUENCE_VALUE";
  27.177 +        case PEP_OWN_SEQUENCE:
  27.178 +            return "PEP_OWN_SEQUENCE";
  27.179 +        case PEP_SYNC_STATEMACHINE_ERROR:
  27.180 +            return "PEP_SYNC_STATEMACHINE_ERROR";
  27.181 +        case PEP_SYNC_NO_TRUST:
  27.182 +            return "PEP_SYNC_NO_TRUST";
  27.183 +        case PEP_STATEMACHINE_INVALID_STATE:
  27.184 +            return "PEP_STATEMACHINE_INVALID_STATE";
  27.185 +        case PEP_STATEMACHINE_INVALID_EVENT:
  27.186 +            return "PEP_STATEMACHINE_INVALID_EVENT";
  27.187 +        case PEP_STATEMACHINE_INVALID_CONDITION:
  27.188 +            return "PEP_STATEMACHINE_INVALID_CONDITION";
  27.189 +        case PEP_STATEMACHINE_INVALID_ACTION:
  27.190 +            return "PEP_STATEMACHINE_INVALID_ACTION";
  27.191 +        case PEP_STATEMACHINE_INHIBITED_EVENT:
  27.192 +            return "PEP_STATEMACHINE_INHIBITED_EVENT";
  27.193 +        case PEP_COMMIT_FAILED:
  27.194 +            return "PEP_COMMIT_FAILED";
  27.195 +        case PEP_MESSAGE_CONSUME:
  27.196 +            return "PEP_MESSAGE_CONSUME";
  27.197 +        case PEP_MESSAGE_IGNORE:
  27.198 +            return "PEP_MESSAGE_IGNORE";
  27.199 +        case PEP_RECORD_NOT_FOUND:
  27.200 +            return "PEP_RECORD_NOT_FOUND";
  27.201 +        case PEP_CANNOT_CREATE_TEMP_FILE:
  27.202 +            return "PEP_CANNOT_CREATE_TEMP_FILE";
  27.203 +        case PEP_ILLEGAL_VALUE:
  27.204 +            return "PEP_ILLEGAL_VALUE";
  27.205 +        case PEP_BUFFER_TOO_SMALL:
  27.206 +            return "PEP_BUFFER_TOO_SMALL";
  27.207 +        case PEP_OUT_OF_MEMORY:
  27.208 +            return "PEP_OUT_OF_MEMORY";
  27.209 +        case PEP_UNKNOWN_ERROR:
  27.210 +            return "PEP_UNKNOWN_ERROR";
  27.211 +        default:
  27.212 + 
  27.213 +            return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
  27.214 +    }
  27.215 +}
  27.216 +const char* tl_rating_string(PEP_rating rating) {
  27.217 +    switch (rating) {
  27.218 +        case PEP_rating_undefined:
  27.219 +            return "PEP_rating_undefined";
  27.220 +        case PEP_rating_cannot_decrypt:
  27.221 +            return "PEP_rating_cannot_decrypt";
  27.222 +        case PEP_rating_have_no_key:
  27.223 +            return "PEP_rating_have_no_key";
  27.224 +        case PEP_rating_unencrypted:
  27.225 +            return "PEP_rating_unencrypted";
  27.226 +        case PEP_rating_unencrypted_for_some:
  27.227 +            return "PEP_rating_unencrypted_for_some";
  27.228 +        case PEP_rating_unreliable:
  27.229 +            return "PEP_rating_unreliable";
  27.230 +        case PEP_rating_reliable:
  27.231 +            return "PEP_rating_reliable";
  27.232 +        case PEP_rating_trusted:
  27.233 +            return "PEP_rating_trusted";
  27.234 +        case PEP_rating_trusted_and_anonymized:
  27.235 +            return "PEP_rating_trusted_and_anonymized";
  27.236 +        case PEP_rating_fully_anonymous:
  27.237 +            return "PEP_rating_fully_anonymous";
  27.238 +        case PEP_rating_mistrust:
  27.239 +            return "PEP_rating_mistrust";
  27.240 +        case PEP_rating_b0rken:
  27.241 +            return "PEP_rating_b0rken";
  27.242 +        case PEP_rating_under_attack:
  27.243 +            return "PEP_rating_under_attack";
  27.244 +        default:
  27.245 +            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.";
  27.246 +    }
  27.247 +}
  27.248 +
  27.249 +const char* tl_ct_string(PEP_comm_type ct) {
  27.250 +    switch (ct) {
  27.251 +        case PEP_ct_unknown:
  27.252 +            return "PEP_ct_unknown";
  27.253 +        case PEP_ct_no_encryption:
  27.254 +            return "PEP_ct_no_encryption";
  27.255 +        case PEP_ct_no_encrypted_channel:
  27.256 +            return "PEP_ct_no_encrypted_channel";
  27.257 +        case PEP_ct_key_not_found:
  27.258 +            return "PEP_ct_key_not_found";
  27.259 +        case PEP_ct_key_expired:
  27.260 +            return "PEP_ct_key_expired";
  27.261 +        case PEP_ct_key_revoked:
  27.262 +            return "PEP_ct_key_revoked";
  27.263 +        case PEP_ct_key_b0rken:
  27.264 +            return "PEP_ct_key_b0rken";
  27.265 +        case PEP_ct_my_key_not_included:
  27.266 +            return "PEP_ct_my_key_not_included";
  27.267 +        case PEP_ct_security_by_obscurity:
  27.268 +            return "PEP_ct_security_by_obscurity";
  27.269 +        case PEP_ct_b0rken_crypto:
  27.270 +            return "PEP_ct_b0rken_crypto";
  27.271 +        case PEP_ct_key_too_short:
  27.272 +            return "PEP_ct_key_too_short";
  27.273 +        case PEP_ct_compromised:
  27.274 +            return "PEP_ct_compromised";
  27.275 +        case PEP_ct_mistrusted:
  27.276 +            return "PEP_ct_mistrusted";
  27.277 +        case PEP_ct_unconfirmed_encryption:
  27.278 +            return "PEP_ct_unconfirmed_encryption";
  27.279 +        case PEP_ct_OpenPGP_weak_unconfirmed:
  27.280 +            return "PEP_ct_OpenPGP_weak_unconfirmed";
  27.281 +        case PEP_ct_to_be_checked:
  27.282 +            return "PEP_ct_to_be_checked";
  27.283 +        case PEP_ct_SMIME_unconfirmed:
  27.284 +            return "PEP_ct_SMIME_unconfirmed";
  27.285 +        case PEP_ct_CMS_unconfirmed:
  27.286 +            return "PEP_ct_CMS_unconfirmed";
  27.287 +        case PEP_ct_strong_but_unconfirmed:
  27.288 +            return "PEP_ct_strong_but_unconfirmed";
  27.289 +        case PEP_ct_OpenPGP_unconfirmed:
  27.290 +            return "PEP_ct_OpenPGP_unconfirmed";
  27.291 +        case PEP_ct_OTR_unconfirmed:
  27.292 +            return "PEP_ct_OTR_unconfirmed";
  27.293 +        case PEP_ct_unconfirmed_enc_anon:
  27.294 +            return "PEP_ct_unconfirmed_enc_anon";
  27.295 +        case PEP_ct_pEp_unconfirmed:
  27.296 +            return "PEP_ct_pEp_unconfirmed";
  27.297 +        case PEP_ct_confirmed:
  27.298 +            return "PEP_ct_pEp_confirmed";
  27.299 +        case PEP_ct_confirmed_encryption:
  27.300 +            return "PEP_ct_confirmed_encryption";
  27.301 +        case PEP_ct_OpenPGP_weak:
  27.302 +            return "PEP_ct_OpenPGP_weak";
  27.303 +        case PEP_ct_to_be_checked_confirmed:
  27.304 +            return "PEP_ct_to_be_checked_confirmed";
  27.305 +        case PEP_ct_SMIME:
  27.306 +            return "PEP_ct_SMIME";
  27.307 +        case PEP_ct_CMS:
  27.308 +            return "PEP_ct_CMS";
  27.309 +        case PEP_ct_strong_encryption:
  27.310 +            return "PEP_ct_strong_encryption";
  27.311 +        case PEP_ct_OpenPGP:
  27.312 +            return "PEP_ct_OpenPGP";
  27.313 +        case PEP_ct_OTR:
  27.314 +            return "PEP_ct_OTR";
  27.315 +        case PEP_ct_confirmed_enc_anon:
  27.316 +            return "PEP_ct_confirmed_enc_anon";
  27.317 +        case PEP_ct_pEp:
  27.318 +            return "PEP_ct_pEp";
  27.319 +        default:
  27.320 +            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.";
  27.321 +    }
  27.322 +}
    28.1 --- a/test/test_util.cc	Thu Apr 26 17:30:42 2018 +0200
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,319 +0,0 @@
    28.4 -#include "pEpEngine_test.h"
    28.5 -#include "pEpEngine.h"
    28.6 -#include "pEp_internal.h"
    28.7 -#include "message_api.h"
    28.8 -#include <fstream>
    28.9 -#include <sstream>
   28.10 -#include <stdexcept>
   28.11 -
   28.12 -char* str_to_lower(const char* str) {
   28.13 -    if (!str)
   28.14 -        return NULL;
   28.15 -    int str_len = strlen(str);
   28.16 -    if (str_len == 0)
   28.17 -        return strdup("");
   28.18 -    int i;
   28.19 -    
   28.20 -    char* retval = (char*) calloc(1, str_len + 1);
   28.21 -    for (i = 0; i < str_len; i++) {
   28.22 -        retval[i] = tolower(str[i]);
   28.23 -    }    
   28.24 -    return retval;
   28.25 -}
   28.26 -
   28.27 -// Because annoyed
   28.28 -bool _streq(const char* str1, const char* str2) {
   28.29 -    if (!str1) {
   28.30 -        if (str2)
   28.31 -            return false;
   28.32 -        return true;
   28.33 -    }
   28.34 -    if (!str2)
   28.35 -        return false;
   28.36 -        
   28.37 -    return (strcmp(str1, str2) == 0);
   28.38 -}
   28.39 -
   28.40 -bool _strceq(const char* str1, const char* str2) {
   28.41 -    char* str1_dup = str_to_lower(str1);
   28.42 -    char* str2_dup = str_to_lower(str2);
   28.43 -
   28.44 -    bool retval = _streq(str_to_lower(str1_dup), str_to_lower(str2_dup));
   28.45 -    free(str1_dup);
   28.46 -    free(str2_dup);
   28.47 -    return retval;
   28.48 -}
   28.49 -
   28.50 -void test_init() {
   28.51 -    unlink ("../test_home/.pEp_management.db");
   28.52 -    unlink ("../test_home/.pEp_management.db-shm");
   28.53 -    unlink ("../test_home/.pEp_management.db-wal");
   28.54 -}
   28.55 -
   28.56 -std::string slurp(const std::string& filename)
   28.57 -{
   28.58 -	std::ifstream input(filename.c_str());
   28.59 -	if(!input)
   28.60 -	{
   28.61 -		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
   28.62 -	}
   28.63 -	
   28.64 -	std::stringstream sstr;
   28.65 -	sstr << input.rdbuf();
   28.66 -	return sstr.str();
   28.67 -}
   28.68 -
   28.69 -void dump_out(const char* filename, const char* outdata)
   28.70 -{
   28.71 -	std::ofstream outfile(filename);
   28.72 -	if(!outfile)
   28.73 -	{
   28.74 -		throw std::runtime_error("Cannot open output file!");
   28.75 -	}
   28.76 -	
   28.77 -	outfile << outdata;
   28.78 -    outfile.close();
   28.79 -}
   28.80 -
   28.81 -char* get_new_uuid() {
   28.82 -    char* new_uuid = (char*)calloc(37, 1);
   28.83 -    pEpUUID uuid;
   28.84 -    uuid_generate_random(uuid);
   28.85 -    uuid_unparse_upper(uuid, new_uuid);
   28.86 -    return new_uuid;
   28.87 -}
   28.88 -
   28.89 -const char* tl_status_string(PEP_STATUS status) {
   28.90 -    switch (status) {
   28.91 -        case PEP_STATUS_OK:
   28.92 -            return "PEP_STATUS_OK";
   28.93 -        case PEP_INIT_CANNOT_LOAD_GPGME:
   28.94 -            return "PEP_INIT_CANNOT_LOAD_GPGME";
   28.95 -        case PEP_INIT_GPGME_INIT_FAILED:
   28.96 -            return "PEP_INIT_GPGME_INIT_FAILED";
   28.97 -        case PEP_INIT_NO_GPG_HOME:
   28.98 -            return "PEP_INIT_NO_GPG_HOME";
   28.99 -        case PEP_INIT_NETPGP_INIT_FAILED:
  28.100 -            return "PEP_INIT_NETPGP_INIT_FAILED";
  28.101 -        case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
  28.102 -            return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
  28.103 -        case PEP_INIT_CANNOT_OPEN_DB:
  28.104 -            return "PEP_INIT_CANNOT_OPEN_DB";
  28.105 -        case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
  28.106 -            return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
  28.107 -        case PEP_KEY_NOT_FOUND:
  28.108 -            return "PEP_KEY_NOT_FOUND";
  28.109 -        case PEP_KEY_HAS_AMBIG_NAME:
  28.110 -            return "PEP_KEY_HAS_AMBIG_NAME";
  28.111 -        case PEP_GET_KEY_FAILED:
  28.112 -            return "PEP_GET_KEY_FAILED";
  28.113 -        case PEP_CANNOT_EXPORT_KEY:
  28.114 -            return "PEP_CANNOT_EXPORT_KEY";
  28.115 -        case PEP_CANNOT_EDIT_KEY:
  28.116 -            return "PEP_CANNOT_EDIT_KEY";
  28.117 -        case PEP_CANNOT_FIND_IDENTITY:
  28.118 -            return "PEP_CANNOT_FIND_IDENTITY";
  28.119 -        case PEP_CANNOT_SET_PERSON:
  28.120 -            return "PEP_CANNOT_SET_PERSON";
  28.121 -        case PEP_CANNOT_SET_PGP_KEYPAIR:
  28.122 -            return "PEP_CANNOT_SET_PGP_KEYPAIR";
  28.123 -        case PEP_CANNOT_SET_IDENTITY:
  28.124 -            return "PEP_CANNOT_SET_IDENTITY";
  28.125 -        case PEP_CANNOT_SET_TRUST:
  28.126 -            return "PEP_CANNOT_SET_TRUST";
  28.127 -        case PEP_KEY_BLACKLISTED:
  28.128 -            return "PEP_KEY_BLACKLISTED";
  28.129 -        case PEP_UNENCRYPTED:
  28.130 -            return "PEP_UNENCRYPTED";
  28.131 -        case PEP_VERIFIED:
  28.132 -            return "PEP_VERIFIED";
  28.133 -        case PEP_DECRYPTED:
  28.134 -            return "PEP_DECRYPTED";
  28.135 -        case PEP_DECRYPTED_AND_VERIFIED:
  28.136 -            return "PEP_DECRYPTED_AND_VERIFIED";
  28.137 -        case PEP_DECRYPT_WRONG_FORMAT:
  28.138 -            return "PEP_DECRYPT_WRONG_FORMAT";
  28.139 -        case PEP_DECRYPT_NO_KEY:
  28.140 -            return "PEP_DECRYPT_NO_KEY";
  28.141 -        case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
  28.142 -            return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
  28.143 -        case PEP_VERIFY_NO_KEY:
  28.144 -            return "PEP_VERIFY_NO_KEY";
  28.145 -        case PEP_VERIFIED_AND_TRUSTED:
  28.146 -            return "PEP_VERIFIED_AND_TRUSTED";
  28.147 -        case PEP_CANNOT_DECRYPT_UNKNOWN:
  28.148 -            return "PEP_CANNOT_DECRYPT_UNKNOWN";
  28.149 -        case PEP_TRUSTWORD_NOT_FOUND:
  28.150 -            return "PEP_TRUSTWORD_NOT_FOUND";
  28.151 -        case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
  28.152 -            return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
  28.153 -        case PEP_CANNOT_CREATE_KEY:
  28.154 -            return "PEP_CANNOT_CREATE_KEY";
  28.155 -        case PEP_CANNOT_SEND_KEY:
  28.156 -            return "PEP_CANNOT_SEND_KEY";
  28.157 -        case PEP_PHRASE_NOT_FOUND:
  28.158 -            return "PEP_PHRASE_NOT_FOUND";
  28.159 -        case PEP_SEND_FUNCTION_NOT_REGISTERED:
  28.160 -            return "PEP_SEND_FUNCTION_NOT_REGISTERED";
  28.161 -        case PEP_CONTRAINTS_VIOLATED:
  28.162 -            return "PEP_CONTRAINTS_VIOLATED";
  28.163 -        case PEP_CANNOT_ENCODE:
  28.164 -            return "PEP_CANNOT_ENCODE";
  28.165 -        case PEP_SYNC_NO_NOTIFY_CALLBACK:
  28.166 -            return "PEP_SYNC_NO_NOTIFY_CALLBACK";
  28.167 -        case PEP_SYNC_ILLEGAL_MESSAGE:
  28.168 -            return "PEP_SYNC_ILLEGAL_MESSAGE";
  28.169 -        case PEP_SYNC_NO_INJECT_CALLBACK:
  28.170 -            return "PEP_SYNC_NO_INJECT_CALLBACK";
  28.171 -        case PEP_SEQUENCE_VIOLATED:
  28.172 -            return "PEP_SEQUENCE_VIOLATED";
  28.173 -        case PEP_CANNOT_INCREASE_SEQUENCE:
  28.174 -            return "PEP_CANNOT_INCREASE_SEQUENCE";
  28.175 -        case PEP_CANNOT_SET_SEQUENCE_VALUE:
  28.176 -            return "PEP_CANNOT_SET_SEQUENCE_VALUE";
  28.177 -        case PEP_OWN_SEQUENCE:
  28.178 -            return "PEP_OWN_SEQUENCE";
  28.179 -        case PEP_SYNC_STATEMACHINE_ERROR:
  28.180 -            return "PEP_SYNC_STATEMACHINE_ERROR";
  28.181 -        case PEP_SYNC_NO_TRUST:
  28.182 -            return "PEP_SYNC_NO_TRUST";
  28.183 -        case PEP_STATEMACHINE_INVALID_STATE:
  28.184 -            return "PEP_STATEMACHINE_INVALID_STATE";
  28.185 -        case PEP_STATEMACHINE_INVALID_EVENT:
  28.186 -            return "PEP_STATEMACHINE_INVALID_EVENT";
  28.187 -        case PEP_STATEMACHINE_INVALID_CONDITION:
  28.188 -            return "PEP_STATEMACHINE_INVALID_CONDITION";
  28.189 -        case PEP_STATEMACHINE_INVALID_ACTION:
  28.190 -            return "PEP_STATEMACHINE_INVALID_ACTION";
  28.191 -        case PEP_STATEMACHINE_INHIBITED_EVENT:
  28.192 -            return "PEP_STATEMACHINE_INHIBITED_EVENT";
  28.193 -        case PEP_COMMIT_FAILED:
  28.194 -            return "PEP_COMMIT_FAILED";
  28.195 -        case PEP_MESSAGE_CONSUME:
  28.196 -            return "PEP_MESSAGE_CONSUME";
  28.197 -        case PEP_MESSAGE_IGNORE:
  28.198 -            return "PEP_MESSAGE_IGNORE";
  28.199 -        case PEP_RECORD_NOT_FOUND:
  28.200 -            return "PEP_RECORD_NOT_FOUND";
  28.201 -        case PEP_CANNOT_CREATE_TEMP_FILE:
  28.202 -            return "PEP_CANNOT_CREATE_TEMP_FILE";
  28.203 -        case PEP_ILLEGAL_VALUE:
  28.204 -            return "PEP_ILLEGAL_VALUE";
  28.205 -        case PEP_BUFFER_TOO_SMALL:
  28.206 -            return "PEP_BUFFER_TOO_SMALL";
  28.207 -        case PEP_OUT_OF_MEMORY:
  28.208 -            return "PEP_OUT_OF_MEMORY";
  28.209 -        case PEP_UNKNOWN_ERROR:
  28.210 -            return "PEP_UNKNOWN_ERROR";
  28.211 -        default:
  28.212 - 
  28.213 -            return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
  28.214 -    }
  28.215 -}
  28.216 -const char* tl_rating_string(PEP_rating rating) {
  28.217 -    switch (rating) {
  28.218 -        case PEP_rating_undefined:
  28.219 -            return "PEP_rating_undefined";
  28.220 -        case PEP_rating_cannot_decrypt:
  28.221 -            return "PEP_rating_cannot_decrypt";
  28.222 -        case PEP_rating_have_no_key:
  28.223 -            return "PEP_rating_have_no_key";
  28.224 -        case PEP_rating_unencrypted:
  28.225 -            return "PEP_rating_unencrypted";
  28.226 -        case PEP_rating_unencrypted_for_some:
  28.227 -            return "PEP_rating_unencrypted_for_some";
  28.228 -        case PEP_rating_unreliable:
  28.229 -            return "PEP_rating_unreliable";
  28.230 -        case PEP_rating_reliable:
  28.231 -            return "PEP_rating_reliable";
  28.232 -        case PEP_rating_trusted:
  28.233 -            return "PEP_rating_trusted";
  28.234 -        case PEP_rating_trusted_and_anonymized:
  28.235 -            return "PEP_rating_trusted_and_anonymized";
  28.236 -        case PEP_rating_fully_anonymous:
  28.237 -            return "PEP_rating_fully_anonymous";
  28.238 -        case PEP_rating_mistrust:
  28.239 -            return "PEP_rating_mistrust";
  28.240 -        case PEP_rating_b0rken:
  28.241 -            return "PEP_rating_b0rken";
  28.242 -        case PEP_rating_under_attack:
  28.243 -            return "PEP_rating_under_attack";
  28.244 -        default:
  28.245 -            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.";
  28.246 -    }
  28.247 -}
  28.248 -
  28.249 -const char* tl_ct_string(PEP_comm_type ct) {
  28.250 -    switch (ct) {
  28.251 -        case PEP_ct_unknown:
  28.252 -            return "PEP_ct_unknown";
  28.253 -        case PEP_ct_no_encryption:
  28.254 -            return "PEP_ct_no_encryption";
  28.255 -        case PEP_ct_no_encrypted_channel:
  28.256 -            return "PEP_ct_no_encrypted_channel";
  28.257 -        case PEP_ct_key_not_found:
  28.258 -            return "PEP_ct_key_not_found";
  28.259 -        case PEP_ct_key_expired:
  28.260 -            return "PEP_ct_key_expired";
  28.261 -        case PEP_ct_key_revoked:
  28.262 -            return "PEP_ct_key_revoked";
  28.263 -        case PEP_ct_key_b0rken:
  28.264 -            return "PEP_ct_key_b0rken";
  28.265 -        case PEP_ct_my_key_not_included:
  28.266 -            return "PEP_ct_my_key_not_included";
  28.267 -        case PEP_ct_security_by_obscurity:
  28.268 -            return "PEP_ct_security_by_obscurity";
  28.269 -        case PEP_ct_b0rken_crypto:
  28.270 -            return "PEP_ct_b0rken_crypto";
  28.271 -        case PEP_ct_key_too_short:
  28.272 -            return "PEP_ct_key_too_short";
  28.273 -        case PEP_ct_compromised:
  28.274 -            return "PEP_ct_compromised";
  28.275 -        case PEP_ct_mistrusted:
  28.276 -            return "PEP_ct_mistrusted";
  28.277 -        case PEP_ct_unconfirmed_encryption:
  28.278 -            return "PEP_ct_unconfirmed_encryption";
  28.279 -        case PEP_ct_OpenPGP_weak_unconfirmed:
  28.280 -            return "PEP_ct_OpenPGP_weak_unconfirmed";
  28.281 -        case PEP_ct_to_be_checked:
  28.282 -            return "PEP_ct_to_be_checked";
  28.283 -        case PEP_ct_SMIME_unconfirmed:
  28.284 -            return "PEP_ct_SMIME_unconfirmed";
  28.285 -        case PEP_ct_CMS_unconfirmed:
  28.286 -            return "PEP_ct_CMS_unconfirmed";
  28.287 -        case PEP_ct_strong_but_unconfirmed:
  28.288 -            return "PEP_ct_strong_but_unconfirmed";
  28.289 -        case PEP_ct_OpenPGP_unconfirmed:
  28.290 -            return "PEP_ct_OpenPGP_unconfirmed";
  28.291 -        case PEP_ct_OTR_unconfirmed:
  28.292 -            return "PEP_ct_OTR_unconfirmed";
  28.293 -        case PEP_ct_unconfirmed_enc_anon:
  28.294 -            return "PEP_ct_unconfirmed_enc_anon";
  28.295 -        case PEP_ct_pEp_unconfirmed:
  28.296 -            return "PEP_ct_pEp_unconfirmed";
  28.297 -        case PEP_ct_confirmed:
  28.298 -            return "PEP_ct_pEp_confirmed";
  28.299 -        case PEP_ct_confirmed_encryption:
  28.300 -            return "PEP_ct_confirmed_encryption";
  28.301 -        case PEP_ct_OpenPGP_weak:
  28.302 -            return "PEP_ct_OpenPGP_weak";
  28.303 -        case PEP_ct_to_be_checked_confirmed:
  28.304 -            return "PEP_ct_to_be_checked_confirmed";
  28.305 -        case PEP_ct_SMIME:
  28.306 -            return "PEP_ct_SMIME";
  28.307 -        case PEP_ct_CMS:
  28.308 -            return "PEP_ct_CMS";
  28.309 -        case PEP_ct_strong_encryption:
  28.310 -            return "PEP_ct_strong_encryption";
  28.311 -        case PEP_ct_OpenPGP:
  28.312 -            return "PEP_ct_OpenPGP";
  28.313 -        case PEP_ct_OTR:
  28.314 -            return "PEP_ct_OTR";
  28.315 -        case PEP_ct_confirmed_enc_anon:
  28.316 -            return "PEP_ct_confirmed_enc_anon";
  28.317 -        case PEP_ct_pEp:
  28.318 -            return "PEP_ct_pEp";
  28.319 -        default:
  28.320 -            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.";
  28.321 -    }
  28.322 -}
    29.1 --- a/test/test_util.h	Thu Apr 26 17:30:42 2018 +0200
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,29 +0,0 @@
    29.4 -#include <string>
    29.5 -#include "pEpEngine.h"
    29.6 -#include "message_api.h"
    29.7 -
    29.8 -void test_init();
    29.9 -
   29.10 -// string equality (case and non-case sensitive)
   29.11 -bool _streq(const char* str1, const char* str2);
   29.12 -bool _strceq(const char* str1, const char* str2);
   29.13 -
   29.14 -// reads a whole file and returns it as std::string
   29.15 -// throws std::runtime_error() if the file cannot be read. Empty file is not an error.
   29.16 -std::string slurp(const std::string& filename);
   29.17 -
   29.18 -// dumps char* to file
   29.19 -// throws std::runtime_error() if the file cannot be opened.
   29.20 -void dump_out(const char* filename, const char* outdata);
   29.21 -
   29.22 -// Returns the string value of the input rating enum value. 
   29.23 -const char* tl_rating_string(PEP_rating rating);
   29.24 -
   29.25 -// Returns the string value of the input comm_type enum value. 
   29.26 -const char* tl_ct_string(PEP_comm_type ct);
   29.27 -
   29.28 -// Returns the string value of the input status enum value. 
   29.29 -const char* tl_status_string(PEP_STATUS status);
   29.30 -
   29.31 -// Grabs a new uuid for your randomish string needs.
   29.32 -char* get_new_uuid();