test/trustwords_test.cc
author Roker <roker@pep-project.org>
Mon, 19 Dec 2016 08:36:53 +0100
changeset 1496 eacf1934b6cc
parent 1315 d42e1163f3f3
child 1513 e7f7e42385b5
permissions -rw-r--r--
free(identity) -> free_identity(identity)
     1 #include <iostream>
     2 #include <string>
     3 #include <cassert>
     4 #include "pEpEngine.h"
     5 #include "message_api.h"
     6 
     7 using namespace std;
     8 
     9 
    10 int main() {
    11     cout << "\n*** get_trustwords test ***\n\n";
    12 
    13     PEP_SESSION session = nullptr;
    14     
    15     cout << "calling init()\n";
    16     PEP_STATUS status1 = init(&session);
    17     assert(status1 == PEP_STATUS_OK);
    18     assert(session);
    19     cout << "init() completed.\n";
    20     
    21     pEp_identity* identity1  = new_identity(
    22         "leon.schumacher@digitalekho.com",
    23         "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
    24         "23",
    25         "Leon Schumacher");
    26     
    27     pEp_identity* identity2 = new_identity(
    28         "krista@kgrothoff.org",
    29         "62D4932086185C15917B72D30571AFBCA5493553",
    30         "blargh",
    31         "Krista Grothoff");
    32     
    33     string fingerprint1 = identity1->fpr;
    34     string fingerprint2 = identity2->fpr;
    35     char* words1 = nullptr;
    36     char* words2 = nullptr;
    37     char* full_wordlist = nullptr;
    38     size_t wsize1 = 0;
    39     size_t wsize2 = 0;
    40     size_t wsize_full = 0;
    41     
    42     cout << "\nTest 1: fpr1 > fpr2, short" << endl;
    43     
    44     cout << "\nfinding German trustwords for " << fingerprint1 << "...\n";
    45     trustwords(session, fingerprint1.c_str(), "de", &words1, &wsize1, 5);
    46     assert(words1);
    47     cout << words1 << "\n";
    48 
    49     cout << "\nfinding German trustwords for " << fingerprint2 << "...\n";
    50     trustwords(session, fingerprint2.c_str(), "de", &words2, &wsize2, 5);
    51     assert(words2);
    52     cout << words2 << "\n";
    53 
    54     cout << "\nfinding German trustwords for " << identity1->address << " and " << identity2->address << "...\n";
    55     get_trustwords(session, identity1, identity2, "de", &full_wordlist, &wsize_full, false);
    56     assert(full_wordlist);
    57     cout << full_wordlist << "\n";
    58     
    59     
    60     pEp_free(words1);
    61     words1 = nullptr;
    62     pEp_free(words2);
    63     words2 = nullptr;
    64     pEp_free(full_wordlist);
    65     full_wordlist = nullptr;
    66 
    67     cout << "\nTest 2: fpr1 == fpr1, short" << endl;
    68     
    69     cout << "\nfinding French trustwords for " << fingerprint2 << "...\n";
    70     trustwords(session, fingerprint1.c_str(), "fr", &words1, &wsize1, 5);
    71     assert(words1);
    72     cout << words1 << "\n";
    73         
    74     cout << "\nfinding French trustwords for " << identity2->address << " and " << identity2->address << "...\n";
    75     get_trustwords(session, identity2, identity2, "fr", &full_wordlist, &wsize_full, false);
    76     assert(full_wordlist);
    77     cout << full_wordlist << "\n";
    78 
    79     pEp_free(words1);
    80     words1 = nullptr;
    81     pEp_free(full_wordlist);
    82     full_wordlist = nullptr;
    83 
    84     cout << "\nTest 3: fpr1 < fpr2, long" << endl;
    85     
    86     cout << "\nfinding English trustwords for " << fingerprint2 << "...\n";
    87     trustwords(session, fingerprint2.c_str(), "en", &words1, &wsize1, 0);
    88     assert(words1);
    89     cout << words1 << "\n";
    90     
    91     cout << "\nfinding English trustwords for " << fingerprint1 << "...\n";
    92     trustwords(session, fingerprint1.c_str(), "en", &words2, &wsize2, 0);
    93     assert(words2);
    94     cout << words2 << "\n";
    95     
    96     cout << "\nfinding English trustwords for " << identity2->address << " and " << identity2->address << "...\n";
    97     get_trustwords(session, identity2, identity1, "en", &full_wordlist, &wsize_full, true);
    98     assert(full_wordlist);
    99     cout << full_wordlist << "\n";
   100     
   101     pEp_free(words1);
   102     words1 = nullptr;
   103     pEp_free(words2);
   104     words2 = nullptr;
   105     pEp_free(full_wordlist);
   106     full_wordlist = nullptr;
   107     
   108     cout << "\nTest 4: fpr1 < fpr2, leading zeros (fpr1 has more), long" << endl;
   109     
   110     pEp_identity* identity3 = new_identity(
   111         "nobody@kgrothoff.org",
   112         "000F932086185C15917B72D30571AFBCA5493553",
   113         "blargh",
   114         "Krista Grothoff");
   115     
   116     pEp_identity* identity4 = new_identity(
   117         "nobody2@kgrothoff.org",
   118         "001F932086185C15917B72D30571AFBCA5493553",
   119         "blargh",
   120         "Krista Grothoff");
   121     
   122     pEp_identity* identity5 = new_identity(
   123         "nobody3@kgrothoff.org",
   124         "001F732086185C15917B72D30571AFBCA5493553",
   125         "blargh",
   126         "Krista Grothoff");
   127 
   128     string fingerprint3 = identity3->fpr;
   129     string fingerprint4 = identity4->fpr;
   130     string fingerprint5 = identity5->fpr; 
   131         
   132     cout << "\nfinding Catalan trustwords for " << fingerprint3 << "...\n";
   133     trustwords(session, fingerprint3.c_str(), "ca", &words1, &wsize1, 0);
   134     assert(words1);
   135     cout << words1 << "\n";
   136     
   137     cout << "\nfinding Catalan trustwords for " << fingerprint4 << "...\n";
   138     trustwords(session, fingerprint4.c_str(), "ca", &words2, &wsize2, 0);
   139     assert(words2);
   140     cout << words2 << "\n";
   141     
   142     cout << "\nfinding Catalan trustwords for " << identity3->address << " and " << identity4->address << "...\n";
   143     get_trustwords(session, identity3, identity4, "ca", &full_wordlist, &wsize_full, true);
   144     assert(full_wordlist);
   145     cout << full_wordlist << "\n";
   146 
   147     pEp_free(words1);
   148     words1 = nullptr;
   149     pEp_free(words2);
   150     words2 = nullptr;
   151     pEp_free(full_wordlist);
   152     full_wordlist = nullptr;
   153 
   154     cout << "\nTest 5: fpr1 > fpr2, leading zeros (same number), interior digit difference, short" << endl;
   155     
   156     cout << "\nfinding Turkish trustwords for " << fingerprint4 << "...\n";
   157     trustwords(session, fingerprint4.c_str(), "tr", &words1, &wsize1, 5);
   158     assert(words1);
   159     cout << words1 << "\n";
   160     
   161     cout << "\nfinding Turkish trustwords for " << fingerprint5 << "...\n";
   162     trustwords(session, fingerprint5.c_str(), "tr", &words2, &wsize2, 5);
   163     assert(words2);
   164     cout << words2 << "\n";
   165     
   166     cout << "\nfinding Turkish trustwords for " << identity4->address << " and " << identity5->address << "...\n";
   167     get_trustwords(session, identity4, identity5, "tr", &full_wordlist, &wsize_full, false);
   168     assert(full_wordlist);
   169     cout << full_wordlist << "\n";
   170     
   171     pEp_free(words1);
   172     words1 = nullptr;
   173     pEp_free(words2);
   174     words2 = nullptr;
   175     pEp_free(full_wordlist);
   176     full_wordlist = nullptr;
   177 
   178     cout << "\nTest 6: fpr2 is too short" << endl;
   179     
   180     pEp_identity* identity6 = new_identity(
   181         "nobody4@kgrothoff.org",
   182         "01F932086185C15917B72D30571AFBCA5493553",
   183         "blargh",
   184         "Krista Grothoff");
   185     
   186     cout << "\nfinding Turkish trustwords for " << identity5->address << " and " << identity6->address << "...\n";
   187     PEP_STATUS status6 = get_trustwords(session, identity5, identity6, "tr", &full_wordlist, &wsize_full, false);
   188     assert(status6 == PEP_TRUSTWORDS_FPR_WRONG_LENGTH);
   189     cout << "Bad fpr length correctly recognised." << "\n";
   190     
   191     pEp_identity* identity7 = new_identity(
   192         "nobody5@kgrothoff.org",
   193         "F01X932086185C15917B72D30571AFBCA5493553",
   194         "blargh",
   195         "Krista Grothoff");
   196 
   197     cout << "\nTest 7: fpr2 has a non-hex character" << endl;
   198     
   199     cout << "\nfinding Turkish trustwords for " << identity1->address << " and " << identity7->address << "...\n";
   200     PEP_STATUS status7 = get_trustwords(session, identity1, identity7, "tr", &full_wordlist, &wsize_full, true);
   201     assert(status7 == PEP_ILLEGAL_VALUE);
   202     cout << "Illegal digit value correctly recognised." << "\n";
   203     
   204     
   205     free_identity(identity1);
   206     free_identity(identity2);
   207     free_identity(identity3);
   208     free_identity(identity4);
   209     free_identity(identity5);
   210     free_identity(identity6);
   211     free_identity(identity7);
   212     
   213     cout << "calling release()\n";
   214     release(session);
   215     return 0;
   216 }
   217