test/trustwords_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 19 Jan 2018 14:12:02 +0100
changeset 2418 05678e77bc6a
parent 1865 6e6773656dff
permissions -rw-r--r--
fixed update_identity call that could be called on a myself value in outgoing_message_rating
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <iostream>
     5 #include <string>
     6 #include <cassert>
     7 #include "pEpEngine.h"
     8 #include "message_api.h"
     9 
    10 using namespace std;
    11 
    12 
    13 int main() {
    14     cout << "\n*** get_trustwords test ***\n\n";
    15 
    16     PEP_SESSION session = nullptr;
    17     PEP_STATUS status;
    18     
    19     cout << "calling init()\n";
    20     PEP_STATUS status1 = init(&session);
    21     assert(status1 == PEP_STATUS_OK);
    22     assert(session);
    23     cout << "init() completed.\n";
    24     
    25     pEp_identity* identity1  = new_identity(
    26         "leon.schumacher@digitalekho.com",
    27         "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
    28         "23",
    29         "Leon Schumacher");
    30     
    31     pEp_identity* identity2 = new_identity(
    32         "krista@kgrothoff.org",
    33         "62D4932086185C15917B72D30571AFBCA5493553",
    34         "blargh",
    35         "Krista Grothoff");
    36     
    37     pEp_identity* identity2_with_spaces = new_identity(
    38         "krista@kgrothoff.org",
    39         " 62D4932086185C159 17B72D30571A FBCA    5493553   ",
    40         "blargh",
    41         "Krista Grothoff");
    42     
    43     string fingerprint1 = identity1->fpr;
    44     string fingerprint2 = identity2->fpr;
    45     char* words1 = nullptr;
    46     char* words2 = nullptr;
    47     char* full_wordlist = nullptr;
    48     size_t wsize1 = 0;
    49     size_t wsize2 = 0;
    50     size_t wsize_full = 0;
    51     
    52     cout << "\nTest 1: fpr1 > fpr2, short" << endl;
    53     
    54     cout << "\nfinding German trustwords for " << fingerprint1 << "...\n";
    55     trustwords(session, fingerprint1.c_str(), "de", &words1, &wsize1, 5);
    56     assert(words1);
    57     cout << words1 << "\n";
    58 
    59     free(words1);
    60     words1 = nullptr;
    61     
    62     cout << "\nfinding German trustwords for " << fingerprint2 << "...\n";
    63     trustwords(session, fingerprint2.c_str(), "de", &words2, &wsize2, 5);
    64     assert(words2);
    65     cout << words2 << "\n";
    66 
    67     free(words2);
    68     words1 = nullptr;
    69 
    70     cout << "\nfinding German trustwords for " << identity1->address << " and " << identity2->address << "...\n";
    71     get_trustwords(session, identity1, identity2, "de", &full_wordlist, &wsize_full, false);
    72     assert(full_wordlist);
    73     cout << full_wordlist << "\n";
    74 
    75     free(full_wordlist);
    76     full_wordlist = nullptr;
    77 
    78     cout << "\nfinding English trustwords for " << identity1->address << " and " << identity2->address << "... with spaces\n";
    79     get_trustwords(session, identity1, identity2_with_spaces, "en", &full_wordlist, &wsize_full, false);
    80     assert(full_wordlist);
    81     cout << full_wordlist << "\n";
    82 
    83     free(full_wordlist);
    84     full_wordlist = nullptr;
    85     
    86     cout << "\nTest 2: fpr1 == fpr1, short" << endl;
    87     
    88     cout << "\nfinding French trustwords for " << fingerprint2 << "...\n";
    89     trustwords(session, fingerprint1.c_str(), "fr", &words1, &wsize1, 5);
    90     assert(words1);
    91     cout << words1 << "\n";
    92         
    93     cout << "\nfinding French trustwords for " << identity2->address << " and " << identity2->address << "...\n";
    94     status = get_trustwords(session, identity2, identity2, "fr", &full_wordlist, &wsize_full, false);
    95     assert(status == PEP_TRUSTWORDS_DUPLICATE_FPR);
    96     cout << "Discovered duplicate fprs as desired" << endl;
    97 
    98     cout << "\nfinding English trustwords for " << identity2->address << " and " << identity2->address << "... with spaces\n";
    99     get_trustwords(session, identity2, identity2_with_spaces, "en", &full_wordlist, &wsize_full, false);
   100     assert(status == PEP_TRUSTWORDS_DUPLICATE_FPR);
   101     cout << "Discovered duplicate fprs as desired" << endl;
   102 
   103     pEp_free(words1);
   104     words1 = nullptr;
   105     pEp_free(full_wordlist);
   106     full_wordlist = nullptr;
   107 
   108     cout << "\nTest 3: fpr1 < fpr2, long" << endl;
   109     
   110     cout << "\nfinding English trustwords for " << fingerprint2 << "...\n";
   111     trustwords(session, fingerprint2.c_str(), "en", &words1, &wsize1, 0);
   112     assert(words1);
   113     cout << words1 << "\n";
   114     
   115     cout << "\nfinding English trustwords for " << fingerprint1 << "...\n";
   116     trustwords(session, fingerprint1.c_str(), "en", &words2, &wsize2, 0);
   117     assert(words2);
   118     cout << words2 << "\n";
   119     
   120     cout << "\nfinding English trustwords for " << identity2->address << " and " << identity1->address << "...\n";
   121     get_trustwords(session, identity2, identity1, "en", &full_wordlist, &wsize_full, true);
   122     assert(full_wordlist);
   123     cout << full_wordlist << "\n";
   124     
   125     cout << "\nfinding English trustwords for " << identity2->address << " and " << identity1->address << "... with spaces\n";
   126     get_trustwords(session, identity2_with_spaces, identity1, "en", &full_wordlist, &wsize_full, true);
   127     assert(full_wordlist);
   128     cout << full_wordlist << "\n";
   129     
   130     pEp_free(words1);
   131     words1 = nullptr;
   132     pEp_free(words2);
   133     words2 = nullptr;
   134     pEp_free(full_wordlist);
   135     full_wordlist = nullptr;
   136     
   137     cout << "\nTest 4: fpr1 < fpr2, leading zeros (fpr1 has more), long" << endl;
   138     
   139     pEp_identity* identity3 = new_identity(
   140         "nobody@kgrothoff.org",
   141         "000F932086185C15917B72D30571AFBCA5493553",
   142         "blargh",
   143         "Krista Grothoff");
   144     
   145     pEp_identity* identity4 = new_identity(
   146         "nobody2@kgrothoff.org",
   147         "001F932086185C15917B72D30571AFBCA5493553",
   148         "blargh",
   149         "Krista Grothoff");
   150     
   151     pEp_identity* identity5 = new_identity(
   152         "nobody3@kgrothoff.org",
   153         "001F732086185C15917B72D30571AFBCA5493553",
   154         "blargh",
   155         "Krista Grothoff");
   156 
   157     string fingerprint3 = identity3->fpr;
   158     string fingerprint4 = identity4->fpr;
   159     string fingerprint5 = identity5->fpr; 
   160         
   161     cout << "\nfinding Catalan trustwords for " << fingerprint3 << "...\n";
   162     trustwords(session, fingerprint3.c_str(), "ca", &words1, &wsize1, 0);
   163     assert(words1);
   164     cout << words1 << "\n";
   165     
   166     cout << "\nfinding Catalan trustwords for " << fingerprint4 << "...\n";
   167     trustwords(session, fingerprint4.c_str(), "ca", &words2, &wsize2, 0);
   168     assert(words2);
   169     cout << words2 << "\n";
   170     
   171     cout << "\nfinding Catalan trustwords for " << identity3->address << " and " << identity4->address << "...\n";
   172     get_trustwords(session, identity3, identity4, "ca", &full_wordlist, &wsize_full, true);
   173     assert(full_wordlist);
   174     cout << full_wordlist << "\n";
   175 
   176     pEp_free(words1);
   177     words1 = nullptr;
   178     pEp_free(words2);
   179     words2 = nullptr;
   180     pEp_free(full_wordlist);
   181     full_wordlist = nullptr;
   182 
   183     cout << "\nTest 5: fpr1 > fpr2, leading zeros (same number), interior digit difference, short" << endl;
   184     
   185     cout << "\nfinding Turkish trustwords for " << fingerprint4 << "...\n";
   186     trustwords(session, fingerprint4.c_str(), "tr", &words1, &wsize1, 5);
   187     assert(words1);
   188     cout << words1 << "\n";
   189     
   190     cout << "\nfinding Turkish trustwords for " << fingerprint5 << "...\n";
   191     trustwords(session, fingerprint5.c_str(), "tr", &words2, &wsize2, 5);
   192     assert(words2);
   193     cout << words2 << "\n";
   194     
   195     cout << "\nfinding Turkish trustwords for " << identity4->address << " and " << identity5->address << "...\n";
   196     get_trustwords(session, identity4, identity5, "tr", &full_wordlist, &wsize_full, false);
   197     assert(full_wordlist);
   198     cout << full_wordlist << "\n";
   199     
   200     pEp_free(words1);
   201     words1 = nullptr;
   202     pEp_free(words2);
   203     words2 = nullptr;
   204     pEp_free(full_wordlist);
   205     full_wordlist = nullptr;
   206 
   207     cout << "\nTest 6: fpr2 is shorter" << endl;
   208     
   209     pEp_identity* identity6 = new_identity(
   210         "nobody4@kgrothoff.org",
   211         "F1F932086185c15917B72D30571AFBCA5493553",
   212         "blargh",
   213         "Krista Grothoff");
   214     
   215     cout << "\nfinding Turkish trustwords for " << identity5->address << " and " << identity6->address << "...\n";
   216     PEP_STATUS status6 = get_trustwords(session, identity5, identity6, "tr", &full_wordlist, &wsize_full, false);
   217     assert(status6 == PEP_STATUS_OK);
   218     cout << full_wordlist << endl;
   219     
   220     pEp_identity* identity7 = new_identity(
   221         "nobody5@kgrothoff.org",
   222         "F01X932086185C15917B72D30571AFBCA5493553",
   223         "blargh",
   224         "Krista Grothoff");
   225 
   226     cout << "\nTest 7: fpr2 has a non-hex character" << endl;
   227     
   228     cout << "\nfinding Turkish trustwords for " << identity1->address << " and " << identity7->address << "...\n";
   229     PEP_STATUS status7 = get_trustwords(session, identity1, identity7, "tr", &full_wordlist, &wsize_full, true);
   230     assert(status7 == PEP_ILLEGAL_VALUE);
   231     cout << "Illegal digit value correctly recognised." << "\n";
   232     
   233     
   234     free_identity(identity1);
   235     free_identity(identity2);
   236     free_identity(identity3);
   237     free_identity(identity4);
   238     free_identity(identity5);
   239     free_identity(identity6);
   240     free_identity(identity7);
   241     
   242     cout << "calling release()\n";
   243     release(session);
   244     return 0;
   245 }