Intermittent check-in - more tests added (this is just wrapping them in the scaffold for now) local_cpptest
authorKrista Bennett <krista@pep-project.org>
Thu, 03 May 2018 16:37:35 +0200
branchlocal_cpptest
changeset 2650cafe06d8b209
parent 2649 52ca3faa2a2d
child 2651 b05ebb3c2a8d
Intermittent check-in - more tests added (this is just wrapping them in the scaffold for now)
.hgignore
test/bloblist_test.cc
test/case_and_dot_address_test.cc
test/include/AppleMailTests.h
test/include/BloblistTests.h
test/include/CaseAndDotAddressTests.h
test/include/StringpairListTests.h
test/include/TrustManipulationTests.h
test/include/TrustwordsTests.h
test/include/UserIDAliasTests.h
test/src/SuiteMaker.cc
test/src/engine_tests/BloblistTests.cc
test/src/engine_tests/CaseAndDotAddressTests.cc
test/src/engine_tests/StringpairListTests.cc
test/src/engine_tests/TrustManipulationTests.cc
test/src/engine_tests/TrustwordsTests.cc
test/src/engine_tests/UserIDAliasTests.cc
test/stringpair_list_test.cc
test/trust_manipulation_test.cc
test/trustwords_test.cc
test/userid_alias_test.cc
     1.1 --- a/.hgignore	Thu May 03 14:41:57 2018 +0200
     1.2 +++ b/.hgignore	Thu May 03 16:37:35 2018 +0200
     1.3 @@ -61,4 +61,5 @@
     1.4  __pycache__
     1.5  *.pyc
     1.6  test/python_tests/test?
     1.7 -GNUMakefile
     1.8 +test/pEp_test_home
     1.9 +test/TestDriver
     2.1 --- a/test/bloblist_test.cc	Thu May 03 14:41:57 2018 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,134 +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 <assert.h>
    2.13 -
    2.14 -#include "bloblist.h"
    2.15 -
    2.16 -using namespace std;
    2.17 -
    2.18 -/*
    2.19 - *     char *address;              // C string with address UTF-8 encoded
    2.20 -    char *fpr;                  // C string with fingerprint UTF-8 encoded
    2.21 -    char *user_id;              // C string with user ID UTF-8 encoded
    2.22 -    char *username;             // C string with user name UTF-8 encoded
    2.23 -    PEP_comm_type comm_type;    // type of communication with this ID
    2.24 -    char lang[3];               // language of conversation
    2.25 -                                // ISO 639-1 ALPHA-2, last byte is 0
    2.26 -    bool me;                    // if this is the local user herself/himself
    2.27 -    */
    2.28 -
    2.29 -bool test_blob_equals(size_t size1, char* blob1, size_t size2, char* blob2) {
    2.30 -    if (size1 != size2)
    2.31 -        return false;
    2.32 -    size_t i;
    2.33 -    for (i = 0; i < size1; i++) {
    2.34 -        if (blob1[i] != blob2[i])
    2.35 -            return false;
    2.36 -    }
    2.37 -    return true;
    2.38 -}
    2.39 -
    2.40 -bool test_bloblist_node_equals(bloblist_t* val1, bloblist_t* val2) {
    2.41 -    assert(val1);
    2.42 -    assert(val2);
    2.43 -    assert(val1->size == val2->size);
    2.44 -    assert(test_blob_equals(val1->size, val1->value, val2->size, val2->value));
    2.45 -    return( ((!val1->mime_type && !val2->mime_type) || (strcmp(val1->mime_type, val2->mime_type) == 0))
    2.46 -        && ((!val1->filename && !val2->filename) || (strcmp(val1->filename, val2->filename) == 0)));
    2.47 -}
    2.48 -
    2.49 -int main() {
    2.50 -    cout << "\n*** data structures: bloblist_test ***\n\n";
    2.51 -    char* text1 = strdup("This is just some text.");
    2.52 -    char* text2 = strdup("More text.");
    2.53 -    char* text3 = strdup("Unpleasant news and witty one-liners.");
    2.54 -    char* text4 = strdup("I AM URDNOT WREX AND THIS IS MY PLANET!");
    2.55 -    bloblist_t* bl1 = new_bloblist(text1, strlen(text1) + 1, "text/plain", NULL);
    2.56 -    bloblist_t* bl2 = new_bloblist(text2, strlen(text2) + 1, "text/richtext", "bob.rtf");
    2.57 -    bloblist_t* bl3 = new_bloblist(text3, strlen(text3) + 1, NULL, "dummy.bin");
    2.58 -    bloblist_t* bl4 = new_bloblist(text4, strlen(text4) + 1, NULL, NULL);
    2.59 -    
    2.60 -    bloblist_t* bl_arr[4] = {bl1, bl2, bl3, bl4};
    2.61 -        
    2.62 -    int i;
    2.63 -        
    2.64 -    cout << "duping one-element bloblist...\n";
    2.65 -    
    2.66 -    bloblist_t* new_bl = bloblist_dup(bl1);
    2.67 -    assert(new_bl);
    2.68 -    assert(test_bloblist_node_equals(bl1, new_bl));
    2.69 -    assert(new_bl->next == NULL);
    2.70 -    assert(bl1->value != new_bl->value);
    2.71 -    assert(bl1->mime_type != new_bl->mime_type || !(bl1->mime_type || new_bl->mime_type));
    2.72 -    assert(bl1->filename != new_bl->filename || !(bl1->filename || new_bl->filename));
    2.73 -    cout << "one-element bloblist duplicated.\n\n";
    2.74 -    
    2.75 -    cout << "freeing bloblist...\n";
    2.76 -    free_bloblist(new_bl);
    2.77 -    new_bl = NULL;
    2.78 -    
    2.79 -    bloblist_t* p;
    2.80 -    cout << "\ncreating four-element list...\n";
    2.81 -    bloblist_t* to_copy = bl_arr[0];
    2.82 -    new_bl = bloblist_add(new_bl, strdup(to_copy->value), to_copy->size, to_copy->mime_type, to_copy->filename);
    2.83 -    for (i = 1; i < 4; i++) {
    2.84 -        to_copy = bl_arr[i];
    2.85 -        p = bloblist_add(new_bl, strdup(to_copy->value), to_copy->size, to_copy->mime_type, to_copy->filename);
    2.86 -
    2.87 -        assert(p);
    2.88 -    }
    2.89 -    
    2.90 -    p = new_bl;
    2.91 -    
    2.92 -    for (i = 0; i < 4; i++) {
    2.93 -        assert(p);
    2.94 -        
    2.95 -        assert(test_bloblist_node_equals(p, bl_arr[i]));
    2.96 -        assert(p->value != bl_arr[i]->value);
    2.97 -        assert(p->mime_type != bl_arr[i]->mime_type || !(p->mime_type || bl_arr[i]->mime_type));
    2.98 -        assert(p->filename != bl_arr[i]->filename || !(p->filename || bl_arr[i]->filename));
    2.99 -        
   2.100 -        p = p->next;
   2.101 -    }
   2.102 -    assert(p == NULL);
   2.103 -    
   2.104 -    cout << "\nduplicating four-element list...\n\n";
   2.105 -    bloblist_t* duplist = bloblist_dup(new_bl);
   2.106 -    
   2.107 -    p = new_bl;
   2.108 -    bloblist_t* dup_p = duplist;
   2.109 -    
   2.110 -    while (dup_p) {
   2.111 -        assert(test_bloblist_node_equals(p, dup_p));
   2.112 -        assert(p != dup_p);
   2.113 -        assert(p->value != dup_p->value);
   2.114 -        assert(p->mime_type != dup_p->mime_type || !(p->mime_type || dup_p->mime_type));
   2.115 -        assert(p->filename != dup_p->filename || !(p->filename || dup_p->filename));
   2.116 -
   2.117 -        dup_p = dup_p->next;
   2.118 -        p = p->next;
   2.119 -        assert((p == NULL) == (dup_p == NULL));
   2.120 -    }
   2.121 -    cout << "\nfour-element bloblist successfully duplicated.\n\n";
   2.122 -
   2.123 -    cout << "freeing bloblists...\n";
   2.124 -    free_bloblist(new_bl);
   2.125 -    free_bloblist(duplist);
   2.126 -    new_bl = NULL;
   2.127 -    duplist = NULL;
   2.128 -    free(text1);
   2.129 -    free(text2);
   2.130 -    free(text3);
   2.131 -    free(text4);    
   2.132 -    cout << "done.\n";
   2.133 -        
   2.134 -    
   2.135 -    return 0;
   2.136 -}
   2.137 -
     3.1 --- a/test/case_and_dot_address_test.cc	Thu May 03 14:41:57 2018 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,88 +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 <time.h>
    3.10 -#include "platform.h"
    3.11 -#include <iostream>
    3.12 -#include <fstream>
    3.13 -#include <assert.h>
    3.14 -#include "mime.h"
    3.15 -#include "message_api.h"
    3.16 -#include "test_util.h"
    3.17 -
    3.18 -using namespace std;
    3.19 -
    3.20 -int main() {
    3.21 -    cout << "\n*** case_and_dot_address_test.cc ***\n\n";
    3.22 -
    3.23 -    PEP_SESSION session;
    3.24 -    
    3.25 -    cout << "calling init()\n";
    3.26 -    PEP_STATUS status = init(&session);   
    3.27 -    assert(status == PEP_STATUS_OK);
    3.28 -    assert(session);
    3.29 -    cout << "init() completed.\n";
    3.30 -    
    3.31 -    char* user_id = get_new_uuid();
    3.32 -    
    3.33 -    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    3.34 -
    3.35 -    const char* alice_email_case = "pEp.teST.AlICe@pEP-pRoJeCt.ORG";
    3.36 -    const char* alice_email_dot = "pe.p.te.st.a.l.i.ce@pep-project.org";
    3.37 -    const char* alice_email_dotless = "peptestalice@pep-project.org";
    3.38 -    const char* alice_email_case_and_dot = "PE.p.teS.t.ALICE@pep-project.OrG";
    3.39 -
    3.40 -    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
    3.41 -    assert(statuspub == PEP_STATUS_OK);
    3.42 -
    3.43 -    pEp_identity * alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
    3.44 -
    3.45 -    status = trust_personal_key(session, alice_id);
    3.46 -
    3.47 -    pEp_identity * new_alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
    3.48 -    status = update_identity(session, new_alice_id);
    3.49 -    assert(new_alice_id->fpr);
    3.50 -    assert(strcmp(new_alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    3.51 -    free_identity(new_alice_id);
    3.52 -    free_identity(alice_id);
    3.53 -    alice_id = NULL;
    3.54 -    new_alice_id = NULL;
    3.55 -
    3.56 -    alice_id = new_identity(alice_email_case, NULL, user_id, "Alice Test");
    3.57 -    status = update_identity(session, alice_id);
    3.58 -    assert(alice_id->fpr);
    3.59 -    cout << "Alice email: " << alice_email_case << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
    3.60 -    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    3.61 -    free_identity(alice_id);
    3.62 -    alice_id = NULL;
    3.63 -
    3.64 -    alice_id = new_identity(alice_email_dot, NULL, user_id, "Alice Test");
    3.65 -    status = update_identity(session, alice_id);
    3.66 -    assert(alice_id->fpr);
    3.67 -    cout << "Alice email: " << alice_email_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
    3.68 -    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    3.69 -    free_identity(alice_id);
    3.70 -    alice_id = NULL;
    3.71 -
    3.72 -    alice_id = new_identity(alice_email_dotless, NULL, user_id, "Alice Test");
    3.73 -    status = update_identity(session, alice_id);
    3.74 -    assert(alice_id->fpr);
    3.75 -    cout << "Alice email: " << alice_email_dotless << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
    3.76 -    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    3.77 -    free_identity(alice_id);
    3.78 -    alice_id = NULL;
    3.79 -
    3.80 -    alice_id = new_identity(alice_email_case_and_dot, NULL, user_id, "Alice Test");
    3.81 -    status = update_identity(session, alice_id);
    3.82 -    assert(alice_id->fpr);
    3.83 -    cout << "Alice email: " << alice_email_case_and_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
    3.84 -    assert(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    3.85 -    free_identity(alice_id);
    3.86 -    alice_id = NULL;
    3.87 -    
    3.88 -    release(session);
    3.89 -
    3.90 -    return 0;
    3.91 -}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/include/AppleMailTests.h	Thu May 03 16:37:35 2018 +0200
     4.3 @@ -0,0 +1,29 @@
     4.4 +// This file is under GNU General Public License 3.0
     4.5 +// see LICENSE.txt
     4.6 +
     4.7 +#ifndef APPLE_MAIL_TESTS_H
     4.8 +#define APPLE_MAIL_TESTS_H
     4.9 +
    4.10 +#include <stdlib.h>
    4.11 +#include <string.h>
    4.12 +#include "platform.h"
    4.13 +#include <iostream>
    4.14 +#include <fstream>
    4.15 +#include <sstream>
    4.16 +#include <cpptest.h>
    4.17 +#include <cpptest-suite.h>
    4.18 +#include <cpptest-textoutput.h>
    4.19 +#include "mime.h"
    4.20 +#include "message_api.h"
    4.21 +#include "test_util.h"
    4.22 +
    4.23 +using namespace std;
    4.24 +
    4.25 +class AppleMailTests : public EngineTestIndividualSuite {
    4.26 +    public:
    4.27 +        AppleMailTests(string suitename, string test_home_dir);
    4.28 +    private:
    4.29 +        void check_apple_mail();
    4.30 +};
    4.31 +
    4.32 +#endif
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/include/BloblistTests.h	Thu May 03 16:37:35 2018 +0200
     5.3 @@ -0,0 +1,21 @@
     5.4 +// This file is under GNU General Public License 3.0
     5.5 +// see LICENSE.txt
     5.6 +
     5.7 +#ifndef BLOBLIST_TESTS_H
     5.8 +#define BLOBLIST_TESTS_H
     5.9 +
    5.10 +#include <string>
    5.11 +#include "EngineTestSuite.h"
    5.12 +
    5.13 +using namespace std;
    5.14 +
    5.15 +class BloblistTests : public EngineTestSuite {
    5.16 +    public:
    5.17 +        BloblistTests(string suitename, string test_home_dir);
    5.18 +    private:
    5.19 +        void check_bloblists();
    5.20 +        bool test_blob_equals(size_t size1, char* blob1, size_t size2, char* blob2);
    5.21 +        bool test_bloblist_node_equals(bloblist_t* val1, bloblist_t* val2);
    5.22 +};
    5.23 +
    5.24 +#endif
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/include/CaseAndDotAddressTests.h	Thu May 03 16:37:35 2018 +0200
     6.3 @@ -0,0 +1,19 @@
     6.4 +// This file is under GNU General Public License 3.0
     6.5 +// see LICENSE.txt
     6.6 +
     6.7 +#ifndef CASE_AND_DOT_ADDRESS_TESTS_H
     6.8 +#define CASE_AND_DOT_ADDRESS_TESTS_H
     6.9 +
    6.10 +#include <string>
    6.11 +#include "EngineTestIndividualSuite.h"
    6.12 +
    6.13 +using namespace std;
    6.14 +
    6.15 +class CaseAndDotAddressTests : public EngineTestIndividualSuite {
    6.16 +    public:
    6.17 +        CaseAndDotAddressTests(string suitename, string test_home_dir);
    6.18 +    private:
    6.19 +        void check_case_and_dot_address();
    6.20 +};
    6.21 +
    6.22 +#endif
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/include/StringpairListTests.h	Thu May 03 16:37:35 2018 +0200
     7.3 @@ -0,0 +1,20 @@
     7.4 +// This file is under GNU General Public License 3.0
     7.5 +// see LICENSE.txt
     7.6 +
     7.7 +#ifndef STRINGPAIR_LIST_TESTS_H
     7.8 +#define STRINGPAIR_LIST_TESTS_H
     7.9 +
    7.10 +#include <string>
    7.11 +#include "EngineTestSuite.h"
    7.12 +
    7.13 +using namespace std;
    7.14 +
    7.15 +class StringpairListTests : public EngineTestSuite {
    7.16 +    public:
    7.17 +        StringpairListTests(string suitename, string test_home_dir);
    7.18 +    private:
    7.19 +        void check_stringpair_lists();
    7.20 +        bool test_stringpair_equals(stringpair_t* val1, stringpair_t* val2);
    7.21 +};
    7.22 +
    7.23 +#endif
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/include/TrustManipulationTests.h	Thu May 03 16:37:35 2018 +0200
     8.3 @@ -0,0 +1,19 @@
     8.4 +// This file is under GNU General Public License 3.0
     8.5 +// see LICENSE.txt
     8.6 +
     8.7 +#ifndef TRUST_MANIPULATION_TESTS_H
     8.8 +#define TRUST_MANIPULATION_TESTS_H
     8.9 +
    8.10 +#include <string>
    8.11 +#include "EngineTestIndividualSuite.h"
    8.12 +
    8.13 +using namespace std;
    8.14 +
    8.15 +class TrustManipulationTests : public EngineTestIndividualSuite {
    8.16 +    public:
    8.17 +        TrustManipulationTests(string suitename, string test_home_dir);
    8.18 +    private:
    8.19 +        void check_trust_manipulation();
    8.20 +};
    8.21 +
    8.22 +#endif
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/include/TrustwordsTests.h	Thu May 03 16:37:35 2018 +0200
     9.3 @@ -0,0 +1,19 @@
     9.4 +// This file is under GNU General Public License 3.0
     9.5 +// see LICENSE.txt
     9.6 +
     9.7 +#ifndef TRUSTWORDS_TESTS_H
     9.8 +#define TRUSTWORDS_TESTS_H
     9.9 +
    9.10 +#include <string>
    9.11 +#include "EngineTestIndividualSuite.h"
    9.12 +
    9.13 +using namespace std;
    9.14 +
    9.15 +class TrustwordsTests : public EngineTestIndividualSuite {
    9.16 +    public:
    9.17 +        TrustwordsTests(string suitename, string test_home_dir);
    9.18 +    private:
    9.19 +        void check_trustwords();
    9.20 +};
    9.21 +
    9.22 +#endif
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/include/UserIDAliasTests.h	Thu May 03 16:37:35 2018 +0200
    10.3 @@ -0,0 +1,19 @@
    10.4 +// This file is under GNU General Public License 3.0
    10.5 +// see LICENSE.txt
    10.6 +
    10.7 +#ifndef USERID_ALIAS_TESTS_H
    10.8 +#define USERID_ALIAS_TESTS_H
    10.9 +
   10.10 +#include <string>
   10.11 +#include "EngineTestIndividualSuite.h"
   10.12 +
   10.13 +using namespace std;
   10.14 +
   10.15 +class UserIDAliasTests : public EngineTestIndividualSuite {
   10.16 +    public:
   10.17 +        UserIDAliasTests(string suitename, string test_home_dir);
   10.18 +    private:
   10.19 +        void check_userid_aliases();
   10.20 +};
   10.21 +
   10.22 +#endif
    11.1 --- a/test/src/SuiteMaker.cc	Thu May 03 14:41:57 2018 +0200
    11.2 +++ b/test/src/SuiteMaker.cc	Thu May 03 16:37:35 2018 +0200
    11.3 @@ -14,21 +14,45 @@
    11.4  // Begin where we generate stuff
    11.5  #include "DecorateTests.h"
    11.6  #include "AppleMailTests.h"
    11.7 +#include "CaseAndDotAddressTests.h"
    11.8 +#include "StringpairListTests.h"
    11.9 +#include "BloblistTests.h"
   11.10 +#include "TrustwordsTests.h"
   11.11 +#include "TrustManipulationTests.h"
   11.12 +#include "UserIDAliasTests.h"
   11.13  
   11.14  
   11.15  const char* SuiteMaker::all_suites[] = {
   11.16      "DecorateTests",
   11.17      "AppleMailTests",
   11.18 +    "CaseAndDotAddressTests",
   11.19 +    "StringpairListTests",
   11.20 +    "BloblistTests",
   11.21 +    "TrustwordsTests",
   11.22 +    "TrustManipulationTests",
   11.23 +    "UserIDAliasTests",
   11.24  };
   11.25  
   11.26  // This file is generated, so magic constants are ok.
   11.27 -int SuiteMaker::num_suites = 2;
   11.28 +int SuiteMaker::num_suites = 8;
   11.29  
   11.30  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
   11.31      if (strcmp(test_class_name, "DecorateTests") == 0)
   11.32          *test_suite = new DecorateTests(test_class_name, test_home);
   11.33      else if (strcmp(test_class_name, "AppleMailTests") == 0)
   11.34          *test_suite = new AppleMailTests(test_class_name, test_home);
   11.35 +    else if (strcmp(test_class_name, "CaseAndDotAddressTests") == 0)
   11.36 +        *test_suite = new CaseAndDotAddressTests(test_class_name, test_home);
   11.37 +    else if (strcmp(test_class_name, "StringpairListTests") == 0)
   11.38 +        *test_suite = new StringpairListTests(test_class_name, test_home);
   11.39 +    else if (strcmp(test_class_name, "BloblistTests") == 0)
   11.40 +        *test_suite = new BloblistTests(test_class_name, test_home);
   11.41 +    else if (strcmp(test_class_name, "TrustwordsTests") == 0)
   11.42 +        *test_suite = new TrustwordsTests(test_class_name, test_home);
   11.43 +    else if (strcmp(test_class_name, "TrustManipulationTests") == 0)
   11.44 +        *test_suite = new TrustManipulationTests(test_class_name, test_home);
   11.45 +    else if (strcmp(test_class_name, "UserIDAliasTests") == 0)
   11.46 +        *test_suite = new UserIDAliasTests(test_class_name, test_home);
   11.47  }
   11.48  
   11.49  void SuiteMaker::suitemaker_buildlist(const char** test_class_names, int num_to_run, const char* test_home, std::vector<Test::Suite*>& test_suites) {
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/src/engine_tests/BloblistTests.cc	Thu May 03 16:37:35 2018 +0200
    12.3 @@ -0,0 +1,128 @@
    12.4 +// This file is under GNU General Public License 3.0
    12.5 +// see LICENSE.txt
    12.6 +
    12.7 +#include <stdlib.h>
    12.8 +#include <string.h>
    12.9 +#include "platform.h"
   12.10 +#include <iostream>
   12.11 +#include <fstream>
   12.12 +#include <assert.h>
   12.13 +
   12.14 +#include "bloblist.h"
   12.15 +
   12.16 +#include "EngineTestSuite.h"
   12.17 +#include "EngineTestIndividualSuite.h"
   12.18 +#include "BloblistTests.h"
   12.19 +
   12.20 +using namespace std;
   12.21 +
   12.22 +BloblistTests::BloblistTests(string suitename, string test_home_dir) : 
   12.23 +    EngineTestSuite::EngineTestSuite(suitename, test_home_dir) {            
   12.24 +    TEST_ADD(BloblistTests::check_bloblists);
   12.25 +}
   12.26 +
   12.27 +bool BloblistTests::test_blob_equals(size_t size1, char* blob1, size_t size2, char* blob2) {
   12.28 +    if (size1 != size2)
   12.29 +        return false;
   12.30 +    size_t i;
   12.31 +    for (i = 0; i < size1; i++) {
   12.32 +        if (blob1[i] != blob2[i])
   12.33 +            return false;
   12.34 +    }
   12.35 +    return true;
   12.36 +}
   12.37 +
   12.38 +bool BloblistTests::test_bloblist_node_equals(bloblist_t* val1, bloblist_t* val2) {
   12.39 +    assert(val1);
   12.40 +    assert(val2);
   12.41 +    assert(val1->size == val2->size);
   12.42 +    assert(test_blob_equals(val1->size, val1->value, val2->size, val2->value));
   12.43 +    return( ((!val1->mime_type && !val2->mime_type) || (strcmp(val1->mime_type, val2->mime_type) == 0))
   12.44 +        && ((!val1->filename && !val2->filename) || (strcmp(val1->filename, val2->filename) == 0)));
   12.45 +}
   12.46 +
   12.47 +void BloblistTests::check_bloblists() {
   12.48 +    cout << "\n*** data structures: bloblist_test ***\n\n";
   12.49 +    char* text1 = strdup("This is just some text.");
   12.50 +    char* text2 = strdup("More text.");
   12.51 +    char* text3 = strdup("Unpleasant news and witty one-liners.");
   12.52 +    char* text4 = strdup("I AM URDNOT WREX AND THIS IS MY PLANET!");
   12.53 +    bloblist_t* bl1 = new_bloblist(text1, strlen(text1) + 1, "text/plain", NULL);
   12.54 +    bloblist_t* bl2 = new_bloblist(text2, strlen(text2) + 1, "text/richtext", "bob.rtf");
   12.55 +    bloblist_t* bl3 = new_bloblist(text3, strlen(text3) + 1, NULL, "dummy.bin");
   12.56 +    bloblist_t* bl4 = new_bloblist(text4, strlen(text4) + 1, NULL, NULL);
   12.57 +    
   12.58 +    bloblist_t* bl_arr[4] = {bl1, bl2, bl3, bl4};
   12.59 +        
   12.60 +    int i;
   12.61 +        
   12.62 +    cout << "duping one-element bloblist...\n";
   12.63 +    
   12.64 +    bloblist_t* new_bl = bloblist_dup(bl1);
   12.65 +    TEST_ASSERT(new_bl);
   12.66 +    TEST_ASSERT(test_bloblist_node_equals(bl1, new_bl));
   12.67 +    TEST_ASSERT(new_bl->next == NULL);
   12.68 +    TEST_ASSERT(bl1->value != new_bl->value);
   12.69 +    TEST_ASSERT(bl1->mime_type != new_bl->mime_type || !(bl1->mime_type || new_bl->mime_type));
   12.70 +    TEST_ASSERT(bl1->filename != new_bl->filename || !(bl1->filename || new_bl->filename));
   12.71 +    cout << "one-element bloblist duplicated.\n\n";
   12.72 +    
   12.73 +    cout << "freeing bloblist...\n";
   12.74 +    free_bloblist(new_bl);
   12.75 +    new_bl = NULL;
   12.76 +    
   12.77 +    bloblist_t* p;
   12.78 +    cout << "\ncreating four-element list...\n";
   12.79 +    bloblist_t* to_copy = bl_arr[0];
   12.80 +    new_bl = bloblist_add(new_bl, strdup(to_copy->value), to_copy->size, to_copy->mime_type, to_copy->filename);
   12.81 +    for (i = 1; i < 4; i++) {
   12.82 +        to_copy = bl_arr[i];
   12.83 +        p = bloblist_add(new_bl, strdup(to_copy->value), to_copy->size, to_copy->mime_type, to_copy->filename);
   12.84 +
   12.85 +        TEST_ASSERT(p);
   12.86 +    }
   12.87 +    
   12.88 +    p = new_bl;
   12.89 +    
   12.90 +    for (i = 0; i < 4; i++) {
   12.91 +        TEST_ASSERT(p);
   12.92 +        
   12.93 +        TEST_ASSERT(test_bloblist_node_equals(p, bl_arr[i]));
   12.94 +        TEST_ASSERT(p->value != bl_arr[i]->value);
   12.95 +        TEST_ASSERT(p->mime_type != bl_arr[i]->mime_type || !(p->mime_type || bl_arr[i]->mime_type));
   12.96 +        TEST_ASSERT(p->filename != bl_arr[i]->filename || !(p->filename || bl_arr[i]->filename));
   12.97 +        
   12.98 +        p = p->next;
   12.99 +    }
  12.100 +    TEST_ASSERT(p == NULL);
  12.101 +    
  12.102 +    cout << "\nduplicating four-element list...\n\n";
  12.103 +    bloblist_t* duplist = bloblist_dup(new_bl);
  12.104 +    
  12.105 +    p = new_bl;
  12.106 +    bloblist_t* dup_p = duplist;
  12.107 +    
  12.108 +    while (dup_p) {
  12.109 +        TEST_ASSERT(test_bloblist_node_equals(p, dup_p));
  12.110 +        TEST_ASSERT(p != dup_p);
  12.111 +        TEST_ASSERT(p->value != dup_p->value);
  12.112 +        TEST_ASSERT(p->mime_type != dup_p->mime_type || !(p->mime_type || dup_p->mime_type));
  12.113 +        TEST_ASSERT(p->filename != dup_p->filename || !(p->filename || dup_p->filename));
  12.114 +
  12.115 +        dup_p = dup_p->next;
  12.116 +        p = p->next;
  12.117 +        TEST_ASSERT((p == NULL) == (dup_p == NULL));
  12.118 +    }
  12.119 +    cout << "\nfour-element bloblist successfully duplicated.\n\n";
  12.120 +
  12.121 +    cout << "freeing bloblists...\n";
  12.122 +    free_bloblist(new_bl);
  12.123 +    free_bloblist(duplist);
  12.124 +    new_bl = NULL;
  12.125 +    duplist = NULL;
  12.126 +    free(text1);
  12.127 +    free(text2);
  12.128 +    free(text3);
  12.129 +    free(text4);    
  12.130 +    cout << "done.\n";
  12.131 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/src/engine_tests/CaseAndDotAddressTests.cc	Thu May 03 16:37:35 2018 +0200
    13.3 @@ -0,0 +1,84 @@
    13.4 +// This file is under GNU General Public License 3.0
    13.5 +// see LICENSE.txt
    13.6 +
    13.7 +#include <stdlib.h>
    13.8 +#include <string.h>
    13.9 +#include <time.h>
   13.10 +#include "platform.h"
   13.11 +#include <iostream>
   13.12 +#include <fstream>
   13.13 +#include "mime.h"
   13.14 +#include "message_api.h"
   13.15 +#include "test_util.h"
   13.16 +
   13.17 +#include "EngineTestSuite.h"
   13.18 +#include "EngineTestIndividualSuite.h"
   13.19 +#include "CaseAndDotAddressTests.h"
   13.20 +
   13.21 +using namespace std;
   13.22 +
   13.23 +CaseAndDotAddressTests::CaseAndDotAddressTests(string suitename, string test_home_dir) : 
   13.24 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   13.25 +    TEST_ADD(CaseAndDotAddressTests::check_case_and_dot_address);
   13.26 +}
   13.27 +
   13.28 +void CaseAndDotAddressTests::check_case_and_dot_address() {
   13.29 +    cout << "\n*** case_and_dot_address_test.cc ***\n\n";
   13.30 +    
   13.31 +    char* user_id = get_new_uuid();
   13.32 +    
   13.33 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   13.34 +
   13.35 +    const char* alice_email_case = "pEp.teST.AlICe@pEP-pRoJeCt.ORG";
   13.36 +    const char* alice_email_dot = "pe.p.te.st.a.l.i.ce@pep-project.org";
   13.37 +    const char* alice_email_dotless = "peptestalice@pep-project.org";
   13.38 +    const char* alice_email_case_and_dot = "PE.p.teS.t.ALICE@pep-project.OrG";
   13.39 +
   13.40 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   13.41 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   13.42 +
   13.43 +    pEp_identity * alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
   13.44 +
   13.45 +    PEP_STATUS status = trust_personal_key(session, alice_id);
   13.46 +
   13.47 +    pEp_identity * new_alice_id = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", user_id, "Alice Test");
   13.48 +    status = update_identity(session, new_alice_id);
   13.49 +    TEST_ASSERT(new_alice_id->fpr);
   13.50 +    TEST_ASSERT(strcmp(new_alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
   13.51 +    free_identity(new_alice_id);
   13.52 +    free_identity(alice_id);
   13.53 +    alice_id = NULL;
   13.54 +    new_alice_id = NULL;
   13.55 +
   13.56 +    alice_id = new_identity(alice_email_case, NULL, user_id, "Alice Test");
   13.57 +    status = update_identity(session, alice_id);
   13.58 +    TEST_ASSERT(alice_id->fpr);
   13.59 +    cout << "Alice email: " << alice_email_case << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
   13.60 +    TEST_ASSERT(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
   13.61 +    free_identity(alice_id);
   13.62 +    alice_id = NULL;
   13.63 +
   13.64 +    alice_id = new_identity(alice_email_dot, NULL, user_id, "Alice Test");
   13.65 +    status = update_identity(session, alice_id);
   13.66 +    TEST_ASSERT(alice_id->fpr);
   13.67 +    cout << "Alice email: " << alice_email_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
   13.68 +    TEST_ASSERT(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
   13.69 +    free_identity(alice_id);
   13.70 +    alice_id = NULL;
   13.71 +
   13.72 +    alice_id = new_identity(alice_email_dotless, NULL, user_id, "Alice Test");
   13.73 +    status = update_identity(session, alice_id);
   13.74 +    TEST_ASSERT(alice_id->fpr);
   13.75 +    cout << "Alice email: " << alice_email_dotless << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
   13.76 +    TEST_ASSERT(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
   13.77 +    free_identity(alice_id);
   13.78 +    alice_id = NULL;
   13.79 +
   13.80 +    alice_id = new_identity(alice_email_case_and_dot, NULL, user_id, "Alice Test");
   13.81 +    status = update_identity(session, alice_id);
   13.82 +    TEST_ASSERT(alice_id->fpr);
   13.83 +    cout << "Alice email: " << alice_email_case_and_dot << " Alice fpr (should be 4ABE3AAF59AC32CFE4F86500A9411D176FF00E97): " << alice_id->fpr << endl;
   13.84 +    TEST_ASSERT(strcmp(alice_id->fpr, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
   13.85 +    free_identity(alice_id);
   13.86 +    alice_id = NULL;
   13.87 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/src/engine_tests/StringpairListTests.cc	Thu May 03 16:37:35 2018 +0200
    14.3 @@ -0,0 +1,146 @@
    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 <assert.h>
   14.13 +
   14.14 +#include "stringpair.h"
   14.15 +
   14.16 +#include "EngineTestSuite.h"
   14.17 +#include "EngineTestIndividualSuite.h"
   14.18 +#include "StringpairListTests.h"
   14.19 +
   14.20 +using namespace std;
   14.21 +
   14.22 +StringpairListTests::StringpairListTests(string suitename, string test_home_dir) : 
   14.23 +    EngineTestSuite::EngineTestSuite(suitename, test_home_dir) {            
   14.24 +    TEST_ADD(StringpairListTests::check_stringpair_lists);
   14.25 +}
   14.26 +
   14.27 +bool StringpairListTests::test_stringpair_equals(stringpair_t* val1, stringpair_t* val2) {
   14.28 +    assert(val1);
   14.29 +    assert(val2);
   14.30 +    assert(val1->key);
   14.31 +    assert(val2->key);
   14.32 +    assert(val1->value);
   14.33 +    assert(val2->value);
   14.34 +    return((strcmp(val1->key, val2->key) == 0) && (strcmp(val1->value, val2->value) == 0));
   14.35 +}
   14.36 +
   14.37 +void StringpairListTests::check_stringpair_lists() {
   14.38 +    cout << "\n*** data structures: stringpair_list_test ***\n\n";
   14.39 +
   14.40 +    const char* val_1_arr[4] = {"I am your father, Luke",
   14.41 +                                "These are not the droids you're looking for",
   14.42 +                                "Swooping is bad",
   14.43 +                                "I should go."};
   14.44 +    const char* val_2_arr[4] = {"Had to be me.",
   14.45 +                                "Someone else might have gotten it wrong",
   14.46 +                                "Na via lerno victoria",
   14.47 +                                "I was told that there would be cake."};
   14.48 +                                
   14.49 +//    const stringpair_t* stringpair_arr[4];
   14.50 +    
   14.51 +    int i;
   14.52 +    
   14.53 +//    for (i = 0; i < 4; i++) {
   14.54 +//        stringpair_arr[i] = new stringpair(val_1_arr[i], val_2_arr[i]);
   14.55 +//    }
   14.56 +    
   14.57 +    cout << "creating one-element stringpair_list...\n";
   14.58 +    
   14.59 +    stringpair_t* strpair = new_stringpair(val_1_arr[0], val_2_arr[0]);
   14.60 +    TEST_ASSERT(strpair);
   14.61 +    stringpair_list_t* pairlist = new_stringpair_list(strpair);
   14.62 +    TEST_ASSERT(pairlist->value);
   14.63 +    TEST_ASSERT(test_stringpair_equals(strpair, pairlist->value));
   14.64 +    TEST_ASSERT(pairlist->next == NULL);
   14.65 +    cout << "one-element stringpair_list created, next element is NULL\n\n";
   14.66 +    
   14.67 +    cout << "duplicating one-element list...\n";
   14.68 +    stringpair_list_t* duplist = stringpair_list_dup(pairlist);
   14.69 +    stringpair_t* srcpair = pairlist->value;
   14.70 +    stringpair_t* dstpair = duplist->value;
   14.71 +    TEST_ASSERT(dstpair);
   14.72 +    TEST_ASSERT(dstpair->value);
   14.73 +    TEST_ASSERT(test_stringpair_equals(srcpair, dstpair));
   14.74 +    TEST_ASSERT(srcpair->key != dstpair->key);   // test deep copies (to be fixed in next 2 commits)
   14.75 +    TEST_ASSERT(srcpair->value != dstpair->value);
   14.76 +    TEST_ASSERT(duplist->next == NULL);
   14.77 +    cout << "one-element stringpair_list duplicated.\n\n";
   14.78 +    
   14.79 +    cout << "freeing stringpair_lists...\n";
   14.80 +    free_stringpair_list(pairlist); // will free strpair
   14.81 +    free_stringpair_list(duplist);
   14.82 +    pairlist = NULL;
   14.83 +    duplist = NULL;
   14.84 +    strpair = NULL;
   14.85 +    
   14.86 +    stringpair_list_t* p;
   14.87 +    cout << "\ncreating four-element list...\n";
   14.88 +    pairlist = stringpair_list_add(pairlist, new_stringpair(val_1_arr[0], val_2_arr[0]));
   14.89 +    for (i = 1; i < 4; i++) {
   14.90 +        p = stringpair_list_add(pairlist, new_stringpair(val_1_arr[i], val_2_arr[i]));
   14.91 +        TEST_ASSERT(p);
   14.92 +    }
   14.93 +    
   14.94 +    p = pairlist;
   14.95 +    
   14.96 +    for (i = 0; i < 4; i++) {
   14.97 +        TEST_ASSERT(p);
   14.98 +        
   14.99 +        strpair = p->value;
  14.100 +        TEST_ASSERT(strpair);
  14.101 +        
  14.102 +        TEST_ASSERT(strpair->key);
  14.103 +        TEST_ASSERT(strcmp(val_1_arr[i], strpair->key) == 0);
  14.104 +        
  14.105 +        TEST_ASSERT(strpair->value);
  14.106 +        TEST_ASSERT(strcmp(val_2_arr[i], strpair->value) == 0);
  14.107 +        
  14.108 +        TEST_ASSERT(val_1_arr[i] != strpair->key);
  14.109 +        TEST_ASSERT(val_2_arr[i] != strpair->value);
  14.110 +        
  14.111 +        p = p->next;
  14.112 +    }
  14.113 +    TEST_ASSERT(p == NULL);
  14.114 +    
  14.115 +    cout << "\nduplicating four-element list...\n\n";
  14.116 +    duplist = stringpair_list_dup(pairlist);
  14.117 +    
  14.118 +    p = pairlist;
  14.119 +    stringpair_list_t* dup_p = duplist;
  14.120 +    
  14.121 +    while (dup_p) {
  14.122 +        srcpair = p->value;
  14.123 +        dstpair = dup_p->value;
  14.124 +
  14.125 +        TEST_ASSERT(dstpair);
  14.126 +        TEST_ASSERT(dstpair->value);
  14.127 +        
  14.128 +        cout << srcpair->key << ":" << srcpair->value << " / " << dstpair->key << ":" << dstpair->value << "\n";
  14.129 +        TEST_ASSERT(test_stringpair_equals(srcpair, dstpair));
  14.130 +
  14.131 +        TEST_ASSERT(srcpair->key != dstpair->key);   // test deep copies (to be fixed in next 2 commits)
  14.132 +        TEST_ASSERT(srcpair->value != dstpair->value);
  14.133 +
  14.134 +        i++;
  14.135 +        p = p->next;
  14.136 +
  14.137 +        dup_p = dup_p->next;
  14.138 +        TEST_ASSERT((p == NULL) == (dup_p == NULL));
  14.139 +    }
  14.140 +    cout << "\nfour-element stringpair_list successfully duplicated.\n\n";
  14.141 +
  14.142 +    cout << "freeing stringpair_lists...\n";
  14.143 +    free_stringpair_list(pairlist); // will free strpair
  14.144 +    free_stringpair_list(duplist);
  14.145 +    pairlist = NULL;
  14.146 +    duplist = NULL;
  14.147 +    
  14.148 +    cout << "done.\n";
  14.149 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/test/src/engine_tests/TrustManipulationTests.cc	Thu May 03 16:37:35 2018 +0200
    15.3 @@ -0,0 +1,113 @@
    15.4 +// This file is under GNU General Public License 3.0
    15.5 +// see LICENSE.txt
    15.6 +
    15.7 +#include <stdlib.h>
    15.8 +#include <string.h>
    15.9 +#include <time.h>
   15.10 +#include "platform.h"
   15.11 +#include <iostream>
   15.12 +#include <fstream>
   15.13 +#include "mime.h"
   15.14 +#include "message_api.h"
   15.15 +#include "test_util.h"
   15.16 +
   15.17 +#include "EngineTestSuite.h"
   15.18 +#include "EngineTestIndividualSuite.h"
   15.19 +#include "TrustManipulationTests.h"
   15.20 +
   15.21 +using namespace std;
   15.22 +
   15.23 +TrustManipulationTests::TrustManipulationTests(string suitename, string test_home_dir) : 
   15.24 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   15.25 +    TEST_ADD(TrustManipulationTests::check_trust_manipulation);
   15.26 +}
   15.27 +
   15.28 +void TrustManipulationTests::check_trust_manipulation() {
   15.29 +    cout << "\n*** trust manipulation test ***\n\n";
   15.30 +
   15.31 +    char* user_id = get_new_uuid();
   15.32 +    
   15.33 +    PEP_STATUS status = PEP_STATUS_OK;
   15.34 +
   15.35 +    cout << "creating id for : ";
   15.36 +    char *uniqname = strdup("AAAAtestuser@testdomain.org");
   15.37 +    srandom(time(NULL));
   15.38 +    for(int i=0; i < 4;i++)
   15.39 +        uniqname[i] += random() & 0xf;
   15.40 +    
   15.41 +    cout << uniqname << "\n";
   15.42 +    pEp_identity * user = new_identity(uniqname, NULL, user_id, "Test User");
   15.43 +    status = generate_keypair(session, user);
   15.44 +    TEST_ASSERT(user->fpr);
   15.45 +
   15.46 +    char* keypair1 = strdup(user->fpr);
   15.47 +    cout << "generated fingerprint \n";
   15.48 +    cout << user->fpr << "\n";
   15.49 +
   15.50 +    cout << "Setting key 1 (" << user->fpr << ") as the default for the identity." << endl;
   15.51 +    // Put identity in the DB
   15.52 +    status = set_identity(session, user);
   15.53 +
   15.54 +    cout << "creating second keypair for : " << uniqname << endl;
   15.55 +    
   15.56 +    pEp_identity * user_again = new_identity(uniqname, NULL, user_id, "Test User");
   15.57 +    status = generate_keypair(session, user_again);
   15.58 +    TEST_ASSERT(user_again->fpr);
   15.59 +
   15.60 +    char* keypair2 = strdup(user_again->fpr);
   15.61 +    cout << "generated fingerprint \n";
   15.62 +    cout << user_again->fpr << "\n";
   15.63 +
   15.64 +    TEST_ASSERT(strcmp(user->fpr, user_again->fpr) != 0);
   15.65 +    update_identity(session, user);
   15.66 +    TEST_ASSERT(strcmp(user->fpr, keypair1) == 0);
   15.67 +    cout << "Key 1 (" << user->fpr << ") is still the default for the identity after update_identity." << endl;
   15.68 +
   15.69 +    // First, trust the SECOND key; make sure it replaces as the default
   15.70 +    cout << "Set trust bit for key 2 (" << keypair2 << ") and ensure it replaces key 1 as the default." << endl;
   15.71 +    status = trust_personal_key(session, user_again);
   15.72 +    status = update_identity(session, user);
   15.73 +    TEST_ASSERT(user->comm_type == PEP_ct_OpenPGP);
   15.74 +    TEST_ASSERT(strcmp(user->fpr, keypair2) == 0);
   15.75 +    cout << "Key 2 (" << user->fpr << ") is now the default for the identity after update_identity, and its comm_type is PEP_ct_OpenPGP (trust bit set!)." << endl;
   15.76 +
   15.77 +    cout << "Now make key 2 not trusted (which also removes it as a default everywhere)." << endl;
   15.78 +    status = key_reset_trust(session, user);
   15.79 +    status = get_trust(session, user);
   15.80 +    TEST_ASSERT(strcmp(user->fpr, keypair2) == 0);
   15.81 +    TEST_ASSERT(user->comm_type == PEP_ct_OpenPGP_unconfirmed);
   15.82 +    cout << "Key 2 is untrusted in the DB." << endl;
   15.83 +
   15.84 +    cout << "Now let's mistrust key 2 in the DB." << endl;
   15.85 +    // Now let's mistrust the second key.
   15.86 +    status = key_mistrusted(session, user);
   15.87 +    status = get_trust(session, user);
   15.88 +    TEST_ASSERT(strcmp(user->fpr, keypair2) == 0);
   15.89 +    TEST_ASSERT(user->comm_type == PEP_ct_mistrusted);
   15.90 +    cout << "Hoorah, we now do not trust key 2. (We never liked key 2 anyway.)" << endl;
   15.91 +    cout << "Now we call update_identity to see what gifts it gives us (should be key 1 with key 1's initial trust.)" << endl;    
   15.92 +    status = update_identity(session, user);
   15.93 +    TEST_ASSERT(strcmp(user->fpr, keypair1) == 0);
   15.94 +    TEST_ASSERT(user->comm_type == PEP_ct_OpenPGP_unconfirmed);
   15.95 +    cout << "Yup, got key 1, and the trust status is PEP_ct_OpenPGP_unconfirmed." << endl;
   15.96 +    
   15.97 +    cout << "Let's mistrust key 1 too. It's been acting shifty lately." << endl;
   15.98 +    status = key_mistrusted(session, user);
   15.99 +    status = get_trust(session, user);
  15.100 +    TEST_ASSERT(strcmp(user->fpr, keypair1) == 0);
  15.101 +    TEST_ASSERT(user->comm_type == PEP_ct_mistrusted);
  15.102 +    cout << "Hoorah, we now do not trust key 1. (TRUST NO ONE)" << endl;
  15.103 +    cout << "Now we call update_identity to see what gifts it gives us (should be an empty key and a key not found comm_type.)" << endl;    
  15.104 +    status = update_identity(session, user);
  15.105 +    TEST_ASSERT(user->fpr == NULL);
  15.106 +    TEST_ASSERT(user->comm_type == PEP_ct_key_not_found);
  15.107 +    cout << "Yup, we trust no keys from " << uniqname << endl;
  15.108 +    
  15.109 +    cout << "TODO: Add cases where we have multiple user_ids addressing a single key, and multiple identities with that key + mistrust" << endl;
  15.110 +    cout << "Passed all of our exciting messing with the trust DB. Moving on..." << endl;
  15.111 + 
  15.112 +    free(user_id);
  15.113 +    free(keypair1);
  15.114 +    free(uniqname);
  15.115 +    free_identity(user);
  15.116 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/src/engine_tests/TrustwordsTests.cc	Thu May 03 16:37:35 2018 +0200
    16.3 @@ -0,0 +1,241 @@
    16.4 +// This file is under GNU General Public License 3.0
    16.5 +// see LICENSE.txt
    16.6 +
    16.7 +#include <iostream>
    16.8 +#include <string>
    16.9 +#include "pEpEngine.h"
   16.10 +#include "message_api.h"
   16.11 +
   16.12 +#include "EngineTestSuite.h"
   16.13 +#include "EngineTestIndividualSuite.h"
   16.14 +#include "TrustwordsTests.h"
   16.15 +
   16.16 +using namespace std;
   16.17 +
   16.18 +TrustwordsTests::TrustwordsTests(string suitename, string test_home_dir) : 
   16.19 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   16.20 +    TEST_ADD(TrustwordsTests::check_trustwords);
   16.21 +}
   16.22 +
   16.23 +void TrustwordsTests::check_trustwords() {
   16.24 +    cout << "\n*** get_trustwords test ***\n\n";
   16.25 +
   16.26 +    PEP_STATUS status;
   16.27 +        
   16.28 +    pEp_identity* identity1  = new_identity(
   16.29 +        "leon.schumacher@digitalekho.com",
   16.30 +        "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
   16.31 +        "23",
   16.32 +        "Leon Schumacher");
   16.33 +    
   16.34 +    pEp_identity* identity2 = new_identity(
   16.35 +        "krista@kgrothoff.org",
   16.36 +        "62D4932086185C15917B72D30571AFBCA5493553",
   16.37 +        "blargh",
   16.38 +        "Krista Grothoff");
   16.39 +    
   16.40 +    pEp_identity* identity2_with_spaces = new_identity(
   16.41 +        "krista@kgrothoff.org",
   16.42 +        " 62D4932086185C159 17B72D30571A FBCA    5493553   ",
   16.43 +        "blargh",
   16.44 +        "Krista Grothoff");
   16.45 +    
   16.46 +    string fingerprint1 = identity1->fpr;
   16.47 +    string fingerprint2 = identity2->fpr;
   16.48 +    char* words1 = nullptr;
   16.49 +    char* words2 = nullptr;
   16.50 +    char* full_wordlist = nullptr;
   16.51 +    size_t wsize1 = 0;
   16.52 +    size_t wsize2 = 0;
   16.53 +    size_t wsize_full = 0;
   16.54 +    
   16.55 +    cout << "\nTest 1: fpr1 > fpr2, short" << endl;
   16.56 +    
   16.57 +    cout << "\nfinding German trustwords for " << fingerprint1 << "...\n";
   16.58 +    trustwords(session, fingerprint1.c_str(), "de", &words1, &wsize1, 5);
   16.59 +    TEST_ASSERT(words1);
   16.60 +    cout << words1 << "\n";
   16.61 +
   16.62 +    free(words1);
   16.63 +    words1 = nullptr;
   16.64 +    
   16.65 +    cout << "\nfinding German trustwords for " << fingerprint2 << "...\n";
   16.66 +    trustwords(session, fingerprint2.c_str(), "de", &words2, &wsize2, 5);
   16.67 +    TEST_ASSERT(words2);
   16.68 +    cout << words2 << "\n";
   16.69 +
   16.70 +    free(words2);
   16.71 +    words1 = nullptr;
   16.72 +
   16.73 +    cout << "\nfinding German trustwords for " << identity1->address << " and " << identity2->address << "...\n";
   16.74 +    get_trustwords(session, identity1, identity2, "de", &full_wordlist, &wsize_full, false);
   16.75 +    TEST_ASSERT(full_wordlist);
   16.76 +    cout << full_wordlist << "\n";
   16.77 +
   16.78 +    free(full_wordlist);
   16.79 +    full_wordlist = nullptr;
   16.80 +
   16.81 +    cout << "\nfinding English trustwords for " << identity1->address << " and " << identity2->address << "... with spaces\n";
   16.82 +    get_trustwords(session, identity1, identity2_with_spaces, "en", &full_wordlist, &wsize_full, false);
   16.83 +    TEST_ASSERT(full_wordlist);
   16.84 +    cout << full_wordlist << "\n";
   16.85 +
   16.86 +    free(full_wordlist);
   16.87 +    full_wordlist = nullptr;
   16.88 +    
   16.89 +    cout << "\nTest 2: fpr1 == fpr1, short" << endl;
   16.90 +    
   16.91 +    cout << "\nfinding French trustwords for " << fingerprint2 << "...\n";
   16.92 +    trustwords(session, fingerprint1.c_str(), "fr", &words1, &wsize1, 5);
   16.93 +    TEST_ASSERT(words1);
   16.94 +    cout << words1 << "\n";
   16.95 +        
   16.96 +    cout << "\nfinding French trustwords for " << identity2->address << " and " << identity2->address << "...\n";
   16.97 +    status = get_trustwords(session, identity2, identity2, "fr", &full_wordlist, &wsize_full, false);
   16.98 +    TEST_ASSERT(status == PEP_TRUSTWORDS_DUPLICATE_FPR);
   16.99 +    cout << "Discovered duplicate fprs as desired" << endl;
  16.100 +
  16.101 +    cout << "\nfinding English trustwords for " << identity2->address << " and " << identity2->address << "... with spaces\n";
  16.102 +    get_trustwords(session, identity2, identity2_with_spaces, "en", &full_wordlist, &wsize_full, false);
  16.103 +    TEST_ASSERT(status == PEP_TRUSTWORDS_DUPLICATE_FPR);
  16.104 +    cout << "Discovered duplicate fprs as desired" << endl;
  16.105 +
  16.106 +    pEp_free(words1);
  16.107 +    words1 = nullptr;
  16.108 +    pEp_free(full_wordlist);
  16.109 +    full_wordlist = nullptr;
  16.110 +
  16.111 +    cout << "\nTest 3: fpr1 < fpr2, long" << endl;
  16.112 +    
  16.113 +    cout << "\nfinding English trustwords for " << fingerprint2 << "...\n";
  16.114 +    trustwords(session, fingerprint2.c_str(), "en", &words1, &wsize1, 0);
  16.115 +    TEST_ASSERT(words1);
  16.116 +    cout << words1 << "\n";
  16.117 +    
  16.118 +    cout << "\nfinding English trustwords for " << fingerprint1 << "...\n";
  16.119 +    trustwords(session, fingerprint1.c_str(), "en", &words2, &wsize2, 0);
  16.120 +    TEST_ASSERT(words2);
  16.121 +    cout << words2 << "\n";
  16.122 +    
  16.123 +    cout << "\nfinding English trustwords for " << identity2->address << " and " << identity1->address << "...\n";
  16.124 +    get_trustwords(session, identity2, identity1, "en", &full_wordlist, &wsize_full, true);
  16.125 +    TEST_ASSERT(full_wordlist);
  16.126 +    cout << full_wordlist << "\n";
  16.127 +    
  16.128 +    cout << "\nfinding English trustwords for " << identity2->address << " and " << identity1->address << "... with spaces\n";
  16.129 +    get_trustwords(session, identity2_with_spaces, identity1, "en", &full_wordlist, &wsize_full, true);
  16.130 +    TEST_ASSERT(full_wordlist);
  16.131 +    cout << full_wordlist << "\n";
  16.132 +    
  16.133 +    pEp_free(words1);
  16.134 +    words1 = nullptr;
  16.135 +    pEp_free(words2);
  16.136 +    words2 = nullptr;
  16.137 +    pEp_free(full_wordlist);
  16.138 +    full_wordlist = nullptr;
  16.139 +    
  16.140 +    cout << "\nTest 4: fpr1 < fpr2, leading zeros (fpr1 has more), long" << endl;
  16.141 +    
  16.142 +    pEp_identity* identity3 = new_identity(
  16.143 +        "nobody@kgrothoff.org",
  16.144 +        "000F932086185C15917B72D30571AFBCA5493553",
  16.145 +        "blargh",
  16.146 +        "Krista Grothoff");
  16.147 +    
  16.148 +    pEp_identity* identity4 = new_identity(
  16.149 +        "nobody2@kgrothoff.org",
  16.150 +        "001F932086185C15917B72D30571AFBCA5493553",
  16.151 +        "blargh",
  16.152 +        "Krista Grothoff");
  16.153 +    
  16.154 +    pEp_identity* identity5 = new_identity(
  16.155 +        "nobody3@kgrothoff.org",
  16.156 +        "001F732086185C15917B72D30571AFBCA5493553",
  16.157 +        "blargh",
  16.158 +        "Krista Grothoff");
  16.159 +
  16.160 +    string fingerprint3 = identity3->fpr;
  16.161 +    string fingerprint4 = identity4->fpr;
  16.162 +    string fingerprint5 = identity5->fpr; 
  16.163 +        
  16.164 +    cout << "\nfinding Catalan trustwords for " << fingerprint3 << "...\n";
  16.165 +    trustwords(session, fingerprint3.c_str(), "ca", &words1, &wsize1, 0);
  16.166 +    TEST_ASSERT(words1);
  16.167 +    cout << words1 << "\n";
  16.168 +    
  16.169 +    cout << "\nfinding Catalan trustwords for " << fingerprint4 << "...\n";
  16.170 +    trustwords(session, fingerprint4.c_str(), "ca", &words2, &wsize2, 0);
  16.171 +    TEST_ASSERT(words2);
  16.172 +    cout << words2 << "\n";
  16.173 +    
  16.174 +    cout << "\nfinding Catalan trustwords for " << identity3->address << " and " << identity4->address << "...\n";
  16.175 +    get_trustwords(session, identity3, identity4, "ca", &full_wordlist, &wsize_full, true);
  16.176 +    TEST_ASSERT(full_wordlist);
  16.177 +    cout << full_wordlist << "\n";
  16.178 +
  16.179 +    pEp_free(words1);
  16.180 +    words1 = nullptr;
  16.181 +    pEp_free(words2);
  16.182 +    words2 = nullptr;
  16.183 +    pEp_free(full_wordlist);
  16.184 +    full_wordlist = nullptr;
  16.185 +
  16.186 +    cout << "\nTest 5: fpr1 > fpr2, leading zeros (same number), interior digit difference, short" << endl;
  16.187 +    
  16.188 +    cout << "\nfinding Turkish trustwords for " << fingerprint4 << "...\n";
  16.189 +    trustwords(session, fingerprint4.c_str(), "tr", &words1, &wsize1, 5);
  16.190 +    TEST_ASSERT(words1);
  16.191 +    cout << words1 << "\n";
  16.192 +    
  16.193 +    cout << "\nfinding Turkish trustwords for " << fingerprint5 << "...\n";
  16.194 +    trustwords(session, fingerprint5.c_str(), "tr", &words2, &wsize2, 5);
  16.195 +    TEST_ASSERT(words2);
  16.196 +    cout << words2 << "\n";
  16.197 +    
  16.198 +    cout << "\nfinding Turkish trustwords for " << identity4->address << " and " << identity5->address << "...\n";
  16.199 +    get_trustwords(session, identity4, identity5, "tr", &full_wordlist, &wsize_full, false);
  16.200 +    TEST_ASSERT(full_wordlist);
  16.201 +    cout << full_wordlist << "\n";
  16.202 +    
  16.203 +    pEp_free(words1);
  16.204 +    words1 = nullptr;
  16.205 +    pEp_free(words2);
  16.206 +    words2 = nullptr;
  16.207 +    pEp_free(full_wordlist);
  16.208 +    full_wordlist = nullptr;
  16.209 +
  16.210 +    cout << "\nTest 6: fpr2 is shorter" << endl;
  16.211 +    
  16.212 +    pEp_identity* identity6 = new_identity(
  16.213 +        "nobody4@kgrothoff.org",
  16.214 +        "F1F932086185c15917B72D30571AFBCA5493553",
  16.215 +        "blargh",
  16.216 +        "Krista Grothoff");
  16.217 +    
  16.218 +    cout << "\nfinding Turkish trustwords for " << identity5->address << " and " << identity6->address << "...\n";
  16.219 +    PEP_STATUS status6 = get_trustwords(session, identity5, identity6, "tr", &full_wordlist, &wsize_full, false);
  16.220 +    TEST_ASSERT(status6 == PEP_STATUS_OK);
  16.221 +    cout << full_wordlist << endl;
  16.222 +    
  16.223 +    pEp_identity* identity7 = new_identity(
  16.224 +        "nobody5@kgrothoff.org",
  16.225 +        "F01X932086185C15917B72D30571AFBCA5493553",
  16.226 +        "blargh",
  16.227 +        "Krista Grothoff");
  16.228 +
  16.229 +    cout << "\nTest 7: fpr2 has a non-hex character" << endl;
  16.230 +    
  16.231 +    cout << "\nfinding Turkish trustwords for " << identity1->address << " and " << identity7->address << "...\n";
  16.232 +    PEP_STATUS status7 = get_trustwords(session, identity1, identity7, "tr", &full_wordlist, &wsize_full, true);
  16.233 +    TEST_ASSERT(status7 == PEP_ILLEGAL_VALUE);
  16.234 +    cout << "Illegal digit value correctly recognised." << "\n";
  16.235 +    
  16.236 +    
  16.237 +    free_identity(identity1);
  16.238 +    free_identity(identity2);
  16.239 +    free_identity(identity3);
  16.240 +    free_identity(identity4);
  16.241 +    free_identity(identity5);
  16.242 +    free_identity(identity6);
  16.243 +    free_identity(identity7);    
  16.244 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/src/engine_tests/UserIDAliasTests.cc	Thu May 03 16:37:35 2018 +0200
    17.3 @@ -0,0 +1,85 @@
    17.4 +// This file is under GNU General Public License 3.0
    17.5 +// see LICENSE.txt
    17.6 +
    17.7 +#include <iostream>
    17.8 +#include <iostream>
    17.9 +#include <fstream>
   17.10 +#include <string>
   17.11 +#include <cstring> // for strcmp()
   17.12 +#include "pEpEngine.h"
   17.13 +#include "message_api.h"
   17.14 +#include "keymanagement.h"
   17.15 +#include "test_util.h"
   17.16 +
   17.17 +#include "EngineTestSuite.h"
   17.18 +#include "EngineTestIndividualSuite.h"
   17.19 +#include "UserIDAliasTests.h"
   17.20 +
   17.21 +using namespace std;
   17.22 +
   17.23 +UserIDAliasTests::UserIDAliasTests(string suitename, string test_home_dir) : 
   17.24 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
   17.25 +    TEST_ADD(UserIDAliasTests::check_userid_aliases);
   17.26 +}
   17.27 +
   17.28 +void UserIDAliasTests::check_userid_aliases() {
   17.29 +    cout << "\n*** userid_alias_test ***\n\n";
   17.30 +
   17.31 +    PEP_STATUS status = PEP_STATUS_OK;
   17.32 +
   17.33 +    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   17.34 +    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   17.35 +    
   17.36 +    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   17.37 +    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   17.38 +    TEST_ASSERT(statuspub == PEP_STATUS_OK);
   17.39 +    TEST_ASSERT(statuspriv == PEP_STATUS_OK);
   17.40 +
   17.41 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
   17.42 +
   17.43 +    const char* alias1 = "TheBigCheese";
   17.44 +    const char* alias2 = "PEBKAC";
   17.45 +
   17.46 +    char* own_id = NULL;
   17.47 +    status = get_default_own_userid(session, &own_id);
   17.48 +    if (!own_id)
   17.49 +        own_id = strdup(PEP_OWN_USERID);
   17.50 +    
   17.51 +    cout << "First, set up an identity with PEP_OWN_USERID as user_id." << endl;
   17.52 +    status = myself(session, alice);
   17.53 +    TEST_ASSERT(status == PEP_STATUS_OK);
   17.54 +    cout << "After myself, user_id is " << alice->user_id << endl;
   17.55 +    TEST_ASSERT(strcmp(alice->user_id, own_id) == 0);
   17.56 +    
   17.57 +    cout << "Now set up an identity with " << alias1 << " as user_id." << endl;
   17.58 +    free(alice->user_id);
   17.59 +    
   17.60 +    alice->user_id = strdup(alias1);
   17.61 +    status = myself(session, alice);
   17.62 +    TEST_ASSERT(status == PEP_STATUS_OK);
   17.63 +    cout << "After myself, user_id is " << alice->user_id << endl;
   17.64 +    TEST_ASSERT(strcmp(alice->user_id, own_id) == 0);
   17.65 +
   17.66 +    cout << "Now set up an identity with " << alias2 << " as user_id." << endl;
   17.67 +    free(alice->user_id);
   17.68 +    
   17.69 +    alice->user_id = strdup(alias2);
   17.70 +    status = myself(session, alice);
   17.71 +    TEST_ASSERT(status == PEP_STATUS_OK);
   17.72 +    cout << "After myself, user_id is " << alice->user_id << endl;
   17.73 +    TEST_ASSERT(strcmp(alice->user_id, own_id) == 0);    
   17.74 +
   17.75 +    char* default_id = NULL;
   17.76 +    status = get_userid_alias_default(session, alias1, &default_id);
   17.77 +    TEST_ASSERT(status == PEP_STATUS_OK);
   17.78 +    cout << "Default user_id for " << alias1 << " is " << default_id << endl;
   17.79 +    TEST_ASSERT(strcmp(default_id, own_id) == 0);
   17.80 +    
   17.81 +    free(default_id);
   17.82 +    default_id = NULL;
   17.83 +    status = get_userid_alias_default(session, alias2, &default_id);
   17.84 +    TEST_ASSERT(status == PEP_STATUS_OK);
   17.85 +    cout << "Default user_id for " << alias2 << " is " << default_id << endl;
   17.86 +    TEST_ASSERT(strcmp(default_id, own_id) == 0);
   17.87 +    
   17.88 +}
    18.1 --- a/test/stringpair_list_test.cc	Thu May 03 14:41:57 2018 +0200
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,141 +0,0 @@
    18.4 -// This file is under GNU General Public License 3.0
    18.5 -// see LICENSE.txt
    18.6 -
    18.7 -#include <stdlib.h>
    18.8 -#include <string.h>
    18.9 -#include "platform.h"
   18.10 -#include <iostream>
   18.11 -#include <fstream>
   18.12 -#include <assert.h>
   18.13 -
   18.14 -#include "stringpair.h"
   18.15 -
   18.16 -using namespace std;
   18.17 -
   18.18 -int test_stringpair_equals(stringpair_t* val1, stringpair_t* val2) {
   18.19 -    assert(val1);
   18.20 -    assert(val2);
   18.21 -    assert(val1->key);
   18.22 -    assert(val2->key);
   18.23 -    assert(val1->value);
   18.24 -    assert(val2->value);
   18.25 -    return((strcmp(val1->key, val2->key) == 0) && (strcmp(val1->value, val2->value) == 0));
   18.26 -}
   18.27 -
   18.28 -int main() {
   18.29 -    cout << "\n*** data structures: stringpair_list_test ***\n\n";
   18.30 -
   18.31 -    const char* val_1_arr[4] = {"I am your father, Luke",
   18.32 -                                "These are not the droids you're looking for",
   18.33 -                                "Swooping is bad",
   18.34 -                                "I should go."};
   18.35 -    const char* val_2_arr[4] = {"Had to be me.",
   18.36 -                                "Someone else might have gotten it wrong",
   18.37 -                                "Na via lerno victoria",
   18.38 -                                "I was told that there would be cake."};
   18.39 -                                
   18.40 -//    const stringpair_t* stringpair_arr[4];
   18.41 -    
   18.42 -    int i;
   18.43 -    
   18.44 -//    for (i = 0; i < 4; i++) {
   18.45 -//        stringpair_arr[i] = new stringpair(val_1_arr[i], val_2_arr[i]);
   18.46 -//    }
   18.47 -    
   18.48 -    cout << "creating one-element stringpair_list...\n";
   18.49 -    
   18.50 -    stringpair_t* strpair = new_stringpair(val_1_arr[0], val_2_arr[0]);
   18.51 -    assert(strpair);
   18.52 -    stringpair_list_t* pairlist = new_stringpair_list(strpair);
   18.53 -    assert(pairlist->value);
   18.54 -    assert(test_stringpair_equals(strpair, pairlist->value));
   18.55 -    assert(pairlist->next == NULL);
   18.56 -    cout << "one-element stringpair_list created, next element is NULL\n\n";
   18.57 -    
   18.58 -    cout << "duplicating one-element list...\n";
   18.59 -    stringpair_list_t* duplist = stringpair_list_dup(pairlist);
   18.60 -    stringpair_t* srcpair = pairlist->value;
   18.61 -    stringpair_t* dstpair = duplist->value;
   18.62 -    assert(dstpair);
   18.63 -    assert(dstpair->value);
   18.64 -    assert(test_stringpair_equals(srcpair, dstpair));
   18.65 -    assert(srcpair->key != dstpair->key);   // test deep copies (to be fixed in next 2 commits)
   18.66 -    assert(srcpair->value != dstpair->value);
   18.67 -    assert(duplist->next == NULL);
   18.68 -    cout << "one-element stringpair_list duplicated.\n\n";
   18.69 -    
   18.70 -    cout << "freeing stringpair_lists...\n";
   18.71 -    free_stringpair_list(pairlist); // will free strpair
   18.72 -    free_stringpair_list(duplist);
   18.73 -    pairlist = NULL;
   18.74 -    duplist = NULL;
   18.75 -    strpair = NULL;
   18.76 -    
   18.77 -    stringpair_list_t* p;
   18.78 -    cout << "\ncreating four-element list...\n";
   18.79 -    pairlist = stringpair_list_add(pairlist, new_stringpair(val_1_arr[0], val_2_arr[0]));
   18.80 -    for (i = 1; i < 4; i++) {
   18.81 -        p = stringpair_list_add(pairlist, new_stringpair(val_1_arr[i], val_2_arr[i]));
   18.82 -        assert(p);
   18.83 -    }
   18.84 -    
   18.85 -    p = pairlist;
   18.86 -    
   18.87 -    for (i = 0; i < 4; i++) {
   18.88 -        assert(p);
   18.89 -        
   18.90 -        strpair = p->value;
   18.91 -        assert(strpair);
   18.92 -        
   18.93 -        assert(strpair->key);
   18.94 -        assert(strcmp(val_1_arr[i], strpair->key) == 0);
   18.95 -        
   18.96 -        assert(strpair->value);
   18.97 -        assert(strcmp(val_2_arr[i], strpair->value) == 0);
   18.98 -        
   18.99 -        assert(val_1_arr[i] != strpair->key);
  18.100 -        assert(val_2_arr[i] != strpair->value);
  18.101 -        
  18.102 -        p = p->next;
  18.103 -    }
  18.104 -    assert(p == NULL);
  18.105 -    
  18.106 -    cout << "\nduplicating four-element list...\n\n";
  18.107 -    duplist = stringpair_list_dup(pairlist);
  18.108 -    
  18.109 -    p = pairlist;
  18.110 -    stringpair_list_t* dup_p = duplist;
  18.111 -    
  18.112 -    while (dup_p) {
  18.113 -        srcpair = p->value;
  18.114 -        dstpair = dup_p->value;
  18.115 -
  18.116 -        assert(dstpair);
  18.117 -        assert(dstpair->value);
  18.118 -        
  18.119 -        cout << srcpair->key << ":" << srcpair->value << " / " << dstpair->key << ":" << dstpair->value << "\n";
  18.120 -        assert(test_stringpair_equals(srcpair, dstpair));
  18.121 -
  18.122 -        assert(srcpair->key != dstpair->key);   // test deep copies (to be fixed in next 2 commits)
  18.123 -        assert(srcpair->value != dstpair->value);
  18.124 -
  18.125 -        i++;
  18.126 -        p = p->next;
  18.127 -
  18.128 -        dup_p = dup_p->next;
  18.129 -        assert((p == NULL) == (dup_p == NULL));
  18.130 -    }
  18.131 -    cout << "\nfour-element stringpair_list successfully duplicated.\n\n";
  18.132 -
  18.133 -    cout << "freeing stringpair_lists...\n";
  18.134 -    free_stringpair_list(pairlist); // will free strpair
  18.135 -    free_stringpair_list(duplist);
  18.136 -    pairlist = NULL;
  18.137 -    duplist = NULL;
  18.138 -    
  18.139 -    cout << "done.\n";
  18.140 -        
  18.141 -    
  18.142 -    return 0;
  18.143 -}
  18.144 -
    19.1 --- a/test/trust_manipulation_test.cc	Thu May 03 14:41:57 2018 +0200
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,114 +0,0 @@
    19.4 -// This file is under GNU General Public License 3.0
    19.5 -// see LICENSE.txt
    19.6 -
    19.7 -#include <stdlib.h>
    19.8 -#include <string.h>
    19.9 -#include <time.h>
   19.10 -#include "platform.h"
   19.11 -#include <iostream>
   19.12 -#include <fstream>
   19.13 -#include <assert.h>
   19.14 -#include "mime.h"
   19.15 -#include "message_api.h"
   19.16 -#include "test_util.h"
   19.17 -
   19.18 -using namespace std;
   19.19 -
   19.20 -int main() {
   19.21 -    cout << "\n*** trust manipulation test ***\n\n";
   19.22 -
   19.23 -    PEP_SESSION session;
   19.24 -
   19.25 -    char* user_id = get_new_uuid();
   19.26 -    
   19.27 -    cout << "calling init()\n";
   19.28 -    PEP_STATUS status = init(&session);   
   19.29 -    assert(status == PEP_STATUS_OK);
   19.30 -    assert(session);
   19.31 -    cout << "init() completed.\n";
   19.32 -
   19.33 -    cout << "creating id for : ";
   19.34 -    char *uniqname = strdup("AAAAtestuser@testdomain.org");
   19.35 -    srandom(time(NULL));
   19.36 -    for(int i=0; i < 4;i++)
   19.37 -        uniqname[i] += random() & 0xf;
   19.38 -    
   19.39 -    cout << uniqname << "\n";
   19.40 -    pEp_identity * user = new_identity(uniqname, NULL, user_id, "Test User");
   19.41 -    status = generate_keypair(session, user);
   19.42 -    assert(user->fpr);
   19.43 -
   19.44 -    char* keypair1 = strdup(user->fpr);
   19.45 -    cout << "generated fingerprint \n";
   19.46 -    cout << user->fpr << "\n";
   19.47 -
   19.48 -    cout << "Setting key 1 (" << user->fpr << ") as the default for the identity." << endl;
   19.49 -    // Put identity in the DB
   19.50 -    status = set_identity(session, user);
   19.51 -
   19.52 -    cout << "creating second keypair for : " << uniqname << endl;
   19.53 -    
   19.54 -    pEp_identity * user_again = new_identity(uniqname, NULL, user_id, "Test User");
   19.55 -    status = generate_keypair(session, user_again);
   19.56 -    assert(user_again->fpr);
   19.57 -
   19.58 -    char* keypair2 = strdup(user_again->fpr);
   19.59 -    cout << "generated fingerprint \n";
   19.60 -    cout << user_again->fpr << "\n";
   19.61 -
   19.62 -    assert(strcmp(user->fpr, user_again->fpr) != 0);
   19.63 -    update_identity(session, user);
   19.64 -    assert(strcmp(user->fpr, keypair1) == 0);
   19.65 -    cout << "Key 1 (" << user->fpr << ") is still the default for the identity after update_identity." << endl;
   19.66 -
   19.67 -    // First, trust the SECOND key; make sure it replaces as the default
   19.68 -    cout << "Set trust bit for key 2 (" << keypair2 << ") and ensure it replaces key 1 as the default." << endl;
   19.69 -    status = trust_personal_key(session, user_again);
   19.70 -    status = update_identity(session, user);
   19.71 -    assert(user->comm_type == PEP_ct_OpenPGP);
   19.72 -    assert(strcmp(user->fpr, keypair2) == 0);
   19.73 -    cout << "Key 2 (" << user->fpr << ") is now the default for the identity after update_identity, and its comm_type is PEP_ct_OpenPGP (trust bit set!)." << endl;
   19.74 -
   19.75 -    cout << "Now make key 2 not trusted (which also removes it as a default everywhere)." << endl;
   19.76 -    status = key_reset_trust(session, user);
   19.77 -    status = get_trust(session, user);
   19.78 -    assert(strcmp(user->fpr, keypair2) == 0);
   19.79 -    assert(user->comm_type == PEP_ct_OpenPGP_unconfirmed);
   19.80 -    cout << "Key 2 is untrusted in the DB." << endl;
   19.81 -
   19.82 -    cout << "Now let's mistrust key 2 in the DB." << endl;
   19.83 -    // Now let's mistrust the second key.
   19.84 -    status = key_mistrusted(session, user);
   19.85 -    status = get_trust(session, user);
   19.86 -    assert(strcmp(user->fpr, keypair2) == 0);
   19.87 -    assert(user->comm_type == PEP_ct_mistrusted);
   19.88 -    cout << "Hoorah, we now do not trust key 2. (We never liked key 2 anyway.)" << endl;
   19.89 -    cout << "Now we call update_identity to see what gifts it gives us (should be key 1 with key 1's initial trust.)" << endl;    
   19.90 -    status = update_identity(session, user);
   19.91 -    assert(strcmp(user->fpr, keypair1) == 0);
   19.92 -    assert(user->comm_type == PEP_ct_OpenPGP_unconfirmed);
   19.93 -    cout << "Yup, got key 1, and the trust status is PEP_ct_OpenPGP_unconfirmed." << endl;
   19.94 -    
   19.95 -    cout << "Let's mistrust key 1 too. It's been acting shifty lately." << endl;
   19.96 -    status = key_mistrusted(session, user);
   19.97 -    status = get_trust(session, user);
   19.98 -    assert(strcmp(user->fpr, keypair1) == 0);
   19.99 -    assert(user->comm_type == PEP_ct_mistrusted);
  19.100 -    cout << "Hoorah, we now do not trust key 1. (TRUST NO ONE)" << endl;
  19.101 -    cout << "Now we call update_identity to see what gifts it gives us (should be an empty key and a key not found comm_type.)" << endl;    
  19.102 -    status = update_identity(session, user);
  19.103 -    assert(user->fpr == NULL);
  19.104 -    assert(user->comm_type == PEP_ct_key_not_found);
  19.105 -    cout << "Yup, we trust no keys from " << uniqname << endl;
  19.106 -    
  19.107 -    cout << "TODO: Add cases where we have multiple user_ids addressing a single key, and multiple identities with that key + mistrust" << endl;
  19.108 -    cout << "Passed all of our exciting messing with the trust DB. Moving on..." << endl;
  19.109 - 
  19.110 -    free(user_id);
  19.111 -    free(keypair1);
  19.112 -    free(uniqname);
  19.113 -    free_identity(user);
  19.114 -    release(session);
  19.115 -    
  19.116 -    return 0;
  19.117 -}
    20.1 --- a/test/trustwords_test.cc	Thu May 03 14:41:57 2018 +0200
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,245 +0,0 @@
    20.4 -// This file is under GNU General Public License 3.0
    20.5 -// see LICENSE.txt
    20.6 -
    20.7 -#include <iostream>
    20.8 -#include <string>
    20.9 -#include <cassert>
   20.10 -#include "pEpEngine.h"
   20.11 -#include "message_api.h"
   20.12 -
   20.13 -using namespace std;
   20.14 -
   20.15 -
   20.16 -int main() {
   20.17 -    cout << "\n*** get_trustwords test ***\n\n";
   20.18 -
   20.19 -    PEP_SESSION session = nullptr;
   20.20 -    PEP_STATUS status;
   20.21 -    
   20.22 -    cout << "calling init()\n";
   20.23 -    PEP_STATUS status1 = init(&session);
   20.24 -    assert(status1 == PEP_STATUS_OK);
   20.25 -    assert(session);
   20.26 -    cout << "init() completed.\n";
   20.27 -    
   20.28 -    pEp_identity* identity1  = new_identity(
   20.29 -        "leon.schumacher@digitalekho.com",
   20.30 -        "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
   20.31 -        "23",
   20.32 -        "Leon Schumacher");
   20.33 -    
   20.34 -    pEp_identity* identity2 = new_identity(
   20.35 -        "krista@kgrothoff.org",
   20.36 -        "62D4932086185C15917B72D30571AFBCA5493553",
   20.37 -        "blargh",
   20.38 -        "Krista Grothoff");
   20.39 -    
   20.40 -    pEp_identity* identity2_with_spaces = new_identity(
   20.41 -        "krista@kgrothoff.org",
   20.42 -        " 62D4932086185C159 17B72D30571A FBCA    5493553   ",
   20.43 -        "blargh",
   20.44 -        "Krista Grothoff");
   20.45 -    
   20.46 -    string fingerprint1 = identity1->fpr;
   20.47 -    string fingerprint2 = identity2->fpr;
   20.48 -    char* words1 = nullptr;
   20.49 -    char* words2 = nullptr;
   20.50 -    char* full_wordlist = nullptr;
   20.51 -    size_t wsize1 = 0;
   20.52 -    size_t wsize2 = 0;
   20.53 -    size_t wsize_full = 0;
   20.54 -    
   20.55 -    cout << "\nTest 1: fpr1 > fpr2, short" << endl;
   20.56 -    
   20.57 -    cout << "\nfinding German trustwords for " << fingerprint1 << "...\n";
   20.58 -    trustwords(session, fingerprint1.c_str(), "de", &words1, &wsize1, 5);
   20.59 -    assert(words1);
   20.60 -    cout << words1 << "\n";
   20.61 -
   20.62 -    free(words1);
   20.63 -    words1 = nullptr;
   20.64 -    
   20.65 -    cout << "\nfinding German trustwords for " << fingerprint2 << "...\n";
   20.66 -    trustwords(session, fingerprint2.c_str(), "de", &words2, &wsize2, 5);
   20.67 -    assert(words2);
   20.68 -    cout << words2 << "\n";
   20.69 -
   20.70 -    free(words2);
   20.71 -    words1 = nullptr;
   20.72 -
   20.73 -    cout << "\nfinding German trustwords for " << identity1->address << " and " << identity2->address << "...\n";
   20.74 -    get_trustwords(session, identity1, identity2, "de", &full_wordlist, &wsize_full, false);
   20.75 -    assert(full_wordlist);
   20.76 -    cout << full_wordlist << "\n";
   20.77 -
   20.78 -    free(full_wordlist);
   20.79 -    full_wordlist = nullptr;
   20.80 -
   20.81 -    cout << "\nfinding English trustwords for " << identity1->address << " and " << identity2->address << "... with spaces\n";
   20.82 -    get_trustwords(session, identity1, identity2_with_spaces, "en", &full_wordlist, &wsize_full, false);
   20.83 -    assert(full_wordlist);
   20.84 -    cout << full_wordlist << "\n";
   20.85 -
   20.86 -    free(full_wordlist);
   20.87 -    full_wordlist = nullptr;
   20.88 -    
   20.89 -    cout << "\nTest 2: fpr1 == fpr1, short" << endl;
   20.90 -    
   20.91 -    cout << "\nfinding French trustwords for " << fingerprint2 << "...\n";
   20.92 -    trustwords(session, fingerprint1.c_str(), "fr", &words1, &wsize1, 5);
   20.93 -    assert(words1);
   20.94 -    cout << words1 << "\n";
   20.95 -        
   20.96 -    cout << "\nfinding French trustwords for " << identity2->address << " and " << identity2->address << "...\n";
   20.97 -    status = get_trustwords(session, identity2, identity2, "fr", &full_wordlist, &wsize_full, false);
   20.98 -    assert(status == PEP_TRUSTWORDS_DUPLICATE_FPR);
   20.99 -    cout << "Discovered duplicate fprs as desired" << endl;
  20.100 -
  20.101 -    cout << "\nfinding English trustwords for " << identity2->address << " and " << identity2->address << "... with spaces\n";
  20.102 -    get_trustwords(session, identity2, identity2_with_spaces, "en", &full_wordlist, &wsize_full, false);
  20.103 -    assert(status == PEP_TRUSTWORDS_DUPLICATE_FPR);
  20.104 -    cout << "Discovered duplicate fprs as desired" << endl;
  20.105 -
  20.106 -    pEp_free(words1);
  20.107 -    words1 = nullptr;
  20.108 -    pEp_free(full_wordlist);
  20.109 -    full_wordlist = nullptr;
  20.110 -
  20.111 -    cout << "\nTest 3: fpr1 < fpr2, long" << endl;
  20.112 -    
  20.113 -    cout << "\nfinding English trustwords for " << fingerprint2 << "...\n";
  20.114 -    trustwords(session, fingerprint2.c_str(), "en", &words1, &wsize1, 0);
  20.115 -    assert(words1);
  20.116 -    cout << words1 << "\n";
  20.117 -    
  20.118 -    cout << "\nfinding English trustwords for " << fingerprint1 << "...\n";
  20.119 -    trustwords(session, fingerprint1.c_str(), "en", &words2, &wsize2, 0);
  20.120 -    assert(words2);
  20.121 -    cout << words2 << "\n";
  20.122 -    
  20.123 -    cout << "\nfinding English trustwords for " << identity2->address << " and " << identity1->address << "...\n";
  20.124 -    get_trustwords(session, identity2, identity1, "en", &full_wordlist, &wsize_full, true);
  20.125 -    assert(full_wordlist);
  20.126 -    cout << full_wordlist << "\n";
  20.127 -    
  20.128 -    cout << "\nfinding English trustwords for " << identity2->address << " and " << identity1->address << "... with spaces\n";
  20.129 -    get_trustwords(session, identity2_with_spaces, identity1, "en", &full_wordlist, &wsize_full, true);
  20.130 -    assert(full_wordlist);
  20.131 -    cout << full_wordlist << "\n";
  20.132 -    
  20.133 -    pEp_free(words1);
  20.134 -    words1 = nullptr;
  20.135 -    pEp_free(words2);
  20.136 -    words2 = nullptr;
  20.137 -    pEp_free(full_wordlist);
  20.138 -    full_wordlist = nullptr;
  20.139 -    
  20.140 -    cout << "\nTest 4: fpr1 < fpr2, leading zeros (fpr1 has more), long" << endl;
  20.141 -    
  20.142 -    pEp_identity* identity3 = new_identity(
  20.143 -        "nobody@kgrothoff.org",
  20.144 -        "000F932086185C15917B72D30571AFBCA5493553",
  20.145 -        "blargh",
  20.146 -        "Krista Grothoff");
  20.147 -    
  20.148 -    pEp_identity* identity4 = new_identity(
  20.149 -        "nobody2@kgrothoff.org",
  20.150 -        "001F932086185C15917B72D30571AFBCA5493553",
  20.151 -        "blargh",
  20.152 -        "Krista Grothoff");
  20.153 -    
  20.154 -    pEp_identity* identity5 = new_identity(
  20.155 -        "nobody3@kgrothoff.org",
  20.156 -        "001F732086185C15917B72D30571AFBCA5493553",
  20.157 -        "blargh",
  20.158 -        "Krista Grothoff");
  20.159 -
  20.160 -    string fingerprint3 = identity3->fpr;
  20.161 -    string fingerprint4 = identity4->fpr;
  20.162 -    string fingerprint5 = identity5->fpr; 
  20.163 -        
  20.164 -    cout << "\nfinding Catalan trustwords for " << fingerprint3 << "...\n";
  20.165 -    trustwords(session, fingerprint3.c_str(), "ca", &words1, &wsize1, 0);
  20.166 -    assert(words1);
  20.167 -    cout << words1 << "\n";
  20.168 -    
  20.169 -    cout << "\nfinding Catalan trustwords for " << fingerprint4 << "...\n";
  20.170 -    trustwords(session, fingerprint4.c_str(), "ca", &words2, &wsize2, 0);
  20.171 -    assert(words2);
  20.172 -    cout << words2 << "\n";
  20.173 -    
  20.174 -    cout << "\nfinding Catalan trustwords for " << identity3->address << " and " << identity4->address << "...\n";
  20.175 -    get_trustwords(session, identity3, identity4, "ca", &full_wordlist, &wsize_full, true);
  20.176 -    assert(full_wordlist);
  20.177 -    cout << full_wordlist << "\n";
  20.178 -
  20.179 -    pEp_free(words1);
  20.180 -    words1 = nullptr;
  20.181 -    pEp_free(words2);
  20.182 -    words2 = nullptr;
  20.183 -    pEp_free(full_wordlist);
  20.184 -    full_wordlist = nullptr;
  20.185 -
  20.186 -    cout << "\nTest 5: fpr1 > fpr2, leading zeros (same number), interior digit difference, short" << endl;
  20.187 -    
  20.188 -    cout << "\nfinding Turkish trustwords for " << fingerprint4 << "...\n";
  20.189 -    trustwords(session, fingerprint4.c_str(), "tr", &words1, &wsize1, 5);
  20.190 -    assert(words1);
  20.191 -    cout << words1 << "\n";
  20.192 -    
  20.193 -    cout << "\nfinding Turkish trustwords for " << fingerprint5 << "...\n";
  20.194 -    trustwords(session, fingerprint5.c_str(), "tr", &words2, &wsize2, 5);
  20.195 -    assert(words2);
  20.196 -    cout << words2 << "\n";
  20.197 -    
  20.198 -    cout << "\nfinding Turkish trustwords for " << identity4->address << " and " << identity5->address << "...\n";
  20.199 -    get_trustwords(session, identity4, identity5, "tr", &full_wordlist, &wsize_full, false);
  20.200 -    assert(full_wordlist);
  20.201 -    cout << full_wordlist << "\n";
  20.202 -    
  20.203 -    pEp_free(words1);
  20.204 -    words1 = nullptr;
  20.205 -    pEp_free(words2);
  20.206 -    words2 = nullptr;
  20.207 -    pEp_free(full_wordlist);
  20.208 -    full_wordlist = nullptr;
  20.209 -
  20.210 -    cout << "\nTest 6: fpr2 is shorter" << endl;
  20.211 -    
  20.212 -    pEp_identity* identity6 = new_identity(
  20.213 -        "nobody4@kgrothoff.org",
  20.214 -        "F1F932086185c15917B72D30571AFBCA5493553",
  20.215 -        "blargh",
  20.216 -        "Krista Grothoff");
  20.217 -    
  20.218 -    cout << "\nfinding Turkish trustwords for " << identity5->address << " and " << identity6->address << "...\n";
  20.219 -    PEP_STATUS status6 = get_trustwords(session, identity5, identity6, "tr", &full_wordlist, &wsize_full, false);
  20.220 -    assert(status6 == PEP_STATUS_OK);
  20.221 -    cout << full_wordlist << endl;
  20.222 -    
  20.223 -    pEp_identity* identity7 = new_identity(
  20.224 -        "nobody5@kgrothoff.org",
  20.225 -        "F01X932086185C15917B72D30571AFBCA5493553",
  20.226 -        "blargh",
  20.227 -        "Krista Grothoff");
  20.228 -
  20.229 -    cout << "\nTest 7: fpr2 has a non-hex character" << endl;
  20.230 -    
  20.231 -    cout << "\nfinding Turkish trustwords for " << identity1->address << " and " << identity7->address << "...\n";
  20.232 -    PEP_STATUS status7 = get_trustwords(session, identity1, identity7, "tr", &full_wordlist, &wsize_full, true);
  20.233 -    assert(status7 == PEP_ILLEGAL_VALUE);
  20.234 -    cout << "Illegal digit value correctly recognised." << "\n";
  20.235 -    
  20.236 -    
  20.237 -    free_identity(identity1);
  20.238 -    free_identity(identity2);
  20.239 -    free_identity(identity3);
  20.240 -    free_identity(identity4);
  20.241 -    free_identity(identity5);
  20.242 -    free_identity(identity6);
  20.243 -    free_identity(identity7);
  20.244 -    
  20.245 -    cout << "calling release()\n";
  20.246 -    release(session);
  20.247 -    return 0;
  20.248 -}
    21.1 --- a/test/userid_alias_test.cc	Thu May 03 14:41:57 2018 +0200
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,85 +0,0 @@
    21.4 -// This file is under GNU General Public License 3.0
    21.5 -// see LICENSE.txt
    21.6 -
    21.7 -#include <iostream>
    21.8 -#include <iostream>
    21.9 -#include <fstream>
   21.10 -#include <string>
   21.11 -#include <cstring> // for strcmp()
   21.12 -#include <assert.h>
   21.13 -#include "pEpEngine.h"
   21.14 -#include "message_api.h"
   21.15 -#include "keymanagement.h"
   21.16 -#include "test_util.h"
   21.17 -
   21.18 -using namespace std;
   21.19 -
   21.20 -int main() {
   21.21 -    cout << "\n*** userid_alias_test ***\n\n";
   21.22 -
   21.23 -    PEP_SESSION session;
   21.24 -    
   21.25 -    cout << "calling init()\n";
   21.26 -    PEP_STATUS status = init(&session);
   21.27 -    assert(status == PEP_STATUS_OK);
   21.28 -    assert(session);
   21.29 -    cout << "init() completed.\n";
   21.30 -
   21.31 -    const string alice_pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   21.32 -    const string alice_priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
   21.33 -    
   21.34 -    PEP_STATUS statuspub = import_key(session, alice_pub_key.c_str(), alice_pub_key.length(), NULL);
   21.35 -    PEP_STATUS statuspriv = import_key(session, alice_priv_key.c_str(), alice_priv_key.length(), NULL);
   21.36 -    assert(statuspub == PEP_STATUS_OK);
   21.37 -    assert(statuspriv == PEP_STATUS_OK);
   21.38 -
   21.39 -    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
   21.40 -
   21.41 -    const char* alias1 = "TheBigCheese";
   21.42 -    const char* alias2 = "PEBKAC";
   21.43 -
   21.44 -    char* own_id = NULL;
   21.45 -    status = get_default_own_userid(session, &own_id);
   21.46 -    if (!own_id)
   21.47 -        own_id = strdup(PEP_OWN_USERID);
   21.48 -    
   21.49 -    cout << "First, set up an identity with PEP_OWN_USERID as user_id." << endl;
   21.50 -    status = myself(session, alice);
   21.51 -    assert(status == PEP_STATUS_OK);
   21.52 -    cout << "After myself, user_id is " << alice->user_id << endl;
   21.53 -    assert(strcmp(alice->user_id, own_id) == 0);
   21.54 -    
   21.55 -    cout << "Now set up an identity with " << alias1 << " as user_id." << endl;
   21.56 -    free(alice->user_id);
   21.57 -    
   21.58 -    alice->user_id = strdup(alias1);
   21.59 -    status = myself(session, alice);
   21.60 -    assert(status == PEP_STATUS_OK);
   21.61 -    cout << "After myself, user_id is " << alice->user_id << endl;
   21.62 -    assert(strcmp(alice->user_id, own_id) == 0);
   21.63 -
   21.64 -    cout << "Now set up an identity with " << alias2 << " as user_id." << endl;
   21.65 -    free(alice->user_id);
   21.66 -    
   21.67 -    alice->user_id = strdup(alias2);
   21.68 -    status = myself(session, alice);
   21.69 -    assert(status == PEP_STATUS_OK);
   21.70 -    cout << "After myself, user_id is " << alice->user_id << endl;
   21.71 -    assert(strcmp(alice->user_id, own_id) == 0);    
   21.72 -
   21.73 -    char* default_id = NULL;
   21.74 -    status = get_userid_alias_default(session, alias1, &default_id);
   21.75 -    assert(status == PEP_STATUS_OK);
   21.76 -    cout << "Default user_id for " << alias1 << " is " << default_id << endl;
   21.77 -    assert(strcmp(default_id, own_id) == 0);
   21.78 -    
   21.79 -    free(default_id);
   21.80 -    default_id = NULL;
   21.81 -    status = get_userid_alias_default(session, alias2, &default_id);
   21.82 -    assert(status == PEP_STATUS_OK);
   21.83 -    cout << "Default user_id for " << alias2 << " is " << default_id << endl;
   21.84 -    assert(strcmp(default_id, own_id) == 0);
   21.85 -    
   21.86 -    
   21.87 -    return 0;
   21.88 -}