slurp slurp all files, except \r\n MIME test filey, yet... ENGINE-189
authorRoker <roker@pep-project.org>
Mon, 13 Mar 2017 20:48:39 +0100
branchENGINE-189
changeset 1660e153b77f3e52
parent 1659 2d123f24b05f
child 1662 edbdbb6ee0aa
slurp slurp all files, except \r\n MIME test filey, yet...
test/apple_mail_test.cc
test/blacklist_accept_new_key_test.cc
test/blacklist_test.cc
test/encrypt_for_identity_test.cc
test/encrypt_missing_private_key_test.cc
test/least_common_denom_color_test.cc
     1.1 --- a/test/apple_mail_test.cc	Mon Mar 13 20:47:49 2017 +0100
     1.2 +++ b/test/apple_mail_test.cc	Mon Mar 13 20:48:39 2017 +0100
     1.3 @@ -8,11 +8,11 @@
     1.4  #include "keymanagement.h"
     1.5  #include "message_api.h"
     1.6  #include "mime.h"
     1.7 +#include "test_util.h" // for slurp()
     1.8  
     1.9  using namespace std;
    1.10  
    1.11  int main(int argc, char** argv) {
    1.12 -    
    1.13  
    1.14      const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
    1.15      
    1.16 @@ -24,36 +24,13 @@
    1.17      assert(session);
    1.18      cout << "init() completed.\n";
    1.19  
    1.20 -    ifstream infilekey1("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
    1.21 -    string keytextkey1;
    1.22 -    while (!infilekey1.eof()) {
    1.23 -        static string line;
    1.24 -        getline(infilekey1, line);
    1.25 -        keytextkey1 += line + "\n";
    1.26 -    }
    1.27 -    infilekey1.close(); 
    1.28 -    
    1.29 -    ifstream infilekey2("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
    1.30 -    string keytextkey2;
    1.31 -    while (!infilekey2.eof()) {
    1.32 -        static string line;
    1.33 -        getline(infilekey2, line);
    1.34 -        keytextkey2 += line + "\n";
    1.35 -    }
    1.36 -    infilekey2.close(); 
    1.37 +    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
    1.38 +    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
    1.39  
    1.40      PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    1.41      PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    1.42          
    1.43 -    ifstream infile(mailfile);
    1.44 -    string mailtext;
    1.45 -    while (!infile.eof()) {
    1.46 -        static string line;
    1.47 -        getline(infile, line);
    1.48 -        mailtext += line + "\n";
    1.49 -    }
    1.50 -    infile.close(); 
    1.51 -
    1.52 +    const string mailtext = slurp(mailfile);
    1.53      pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", NULL, PEP_OWN_USERID, "pEp Test Recipient");    
    1.54      me->me = true;    
    1.55      PEP_STATUS status = update_identity(session, me);
    1.56 @@ -100,15 +77,7 @@
    1.57      rating = PEP_rating_unreliable;
    1.58      
    1.59      const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
    1.60 -    
    1.61 -    ifstream infile2(mailfile2);
    1.62 -    string mailtext2;
    1.63 -    while (!infile2.eof()) {
    1.64 -        static string line;
    1.65 -        getline(infile2, line);
    1.66 -        mailtext2 += line + "\n";
    1.67 -    }
    1.68 -    infile2.close(); 
    1.69 +    const string mailtext2 = slurp(mailfile2);
    1.70      
    1.71      status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
    1.72      assert(status == PEP_STATUS_OK);
     2.1 --- a/test/blacklist_accept_new_key_test.cc	Mon Mar 13 20:47:49 2017 +0100
     2.2 +++ b/test/blacklist_accept_new_key_test.cc	Mon Mar 13 20:48:39 2017 +0100
     2.3 @@ -11,6 +11,7 @@
     2.4  #include "keymanagement.h"
     2.5  #include "message_api.h"
     2.6  #include "mime.h"
     2.7 +#include "test_util.h"
     2.8  
     2.9  using namespace std;
    2.10  
    2.11 @@ -32,14 +33,7 @@
    2.12      // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    2.13  
    2.14      /* read the key into memory */
    2.15 -    ifstream infile("blacklisted_pub.asc");
    2.16 -    string keytext;
    2.17 -    while (!infile.eof()) {
    2.18 -        static string line;
    2.19 -        getline(infile, line);
    2.20 -        keytext += line + "\n";
    2.21 -    }
    2.22 -    infile.close(); 
    2.23 +    const string keytext = slurp("blacklisted_pub.asc");
    2.24      
    2.25      /* import it into pep */
    2.26      PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    2.27 @@ -58,17 +52,8 @@
    2.28  
    2.29      /* identity is blacklisted. Now let's read in a message which contains a new key for that ID. */
    2.30      
    2.31 -    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";    
    2.32 -    
    2.33 -    ifstream infile2("test_mails/blacklist_new_key_attached.eml");
    2.34 -    string mailtext;
    2.35 -    while (!infile2.eof()) {
    2.36 -        static string line;
    2.37 -        getline(infile2, line);
    2.38 -        mailtext += line + "\n";
    2.39 -    }
    2.40 -    infile2.close(); 
    2.41 -
    2.42 +    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
    2.43 +    const string mailtext = slurp("test_mails/blacklist_new_key_attached.eml");
    2.44      pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    2.45  
    2.46      PEP_STATUS status = update_identity(session, me1);
    2.47 @@ -102,4 +87,3 @@
    2.48      release(session);
    2.49      return 0;
    2.50  }
    2.51 -
     3.1 --- a/test/blacklist_test.cc	Mon Mar 13 20:47:49 2017 +0100
     3.2 +++ b/test/blacklist_test.cc	Mon Mar 13 20:48:39 2017 +0100
     3.3 @@ -9,6 +9,7 @@
     3.4  #include <assert.h>
     3.5  #include "blacklist.h"
     3.6  #include "keymanagement.h"
     3.7 +#include "test_util.h"
     3.8  
     3.9  using namespace std;
    3.10  
    3.11 @@ -66,15 +67,7 @@
    3.12      
    3.13      // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    3.14  
    3.15 -    /* read the key into memory */
    3.16 -    ifstream infile("blacklisted_pub.asc");
    3.17 -    string keytext;
    3.18 -    while (!infile.eof()) {
    3.19 -        static string line;
    3.20 -        getline(infile, line);
    3.21 -        keytext += line + "\n";
    3.22 -    }
    3.23 -    infile.close(); 
    3.24 +    const string keytext = slurp("blacklisted_pub.asc");
    3.25      
    3.26      /* FIXME: put in automated test stuff (N.B. only gdb mem examination to this point to get
    3.27       *        fix in */
    3.28 @@ -95,7 +88,7 @@
    3.29      blacklisted_identity->comm_type = PEP_ct_pEp;
    3.30  
    3.31      PEP_STATUS status99 = set_identity(session, blacklisted_identity);
    3.32 -        
    3.33 +    
    3.34      trust_personal_key(session, blacklisted_identity);
    3.35  
    3.36      PEP_STATUS status999 = update_identity(session, blacklisted_identity);
    3.37 @@ -111,16 +104,7 @@
    3.38      else
    3.39          cout << "blacklisted identity's fpr successfully wiped by update_identity" << endl;
    3.40  
    3.41 -    /* read the key into memory */
    3.42 -    ifstream infile2("blacklisted_pub2.asc");
    3.43 -    string keytext2;
    3.44 -    while (!infile2.eof()) {
    3.45 -        static string line2;
    3.46 -        getline(infile2, line2);
    3.47 -        keytext2 += line2 + "\n";
    3.48 -    }
    3.49 -    infile2.close(); 
    3.50 -    
    3.51 +    const string keytext2 = slurp("blacklisted_pub2.asc");
    3.52      PEP_STATUS status14 = import_key(session, keytext2.c_str(), keytext2.length(), NULL);
    3.53      
    3.54      pEp_identity* blacklisted_identity2 = new_identity("blacklistedkeys@kgrothoff.org",
     4.1 --- a/test/encrypt_for_identity_test.cc	Mon Mar 13 20:47:49 2017 +0100
     4.2 +++ b/test/encrypt_for_identity_test.cc	Mon Mar 13 20:48:39 2017 +0100
     4.3 @@ -9,6 +9,7 @@
     4.4  #include <assert.h>
     4.5  #include "mime.h"
     4.6  #include "message_api.h"
     4.7 +#include "test_util.h"
     4.8  
     4.9  using namespace std;
    4.10  
    4.11 @@ -119,18 +120,7 @@
    4.12  
    4.13      cout << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl;
    4.14      
    4.15 -    ifstream inFile("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
    4.16 -    assert(inFile.is_open());
    4.17 -
    4.18 -    string mimetext;
    4.19 -
    4.20 -    cout << "reading mime mail\n";
    4.21 -    while (!inFile.eof()) {
    4.22 -        static string line;
    4.23 -        getline(inFile, line);
    4.24 -        mimetext += line + "\n";
    4.25 -    }
    4.26 -    inFile.close();
    4.27 +    const string mimetext = slurp("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
    4.28  
    4.29      cout << "Text read:" << endl;
    4.30      cout << mimetext.c_str() << endl;
     5.1 --- a/test/encrypt_missing_private_key_test.cc	Mon Mar 13 20:47:49 2017 +0100
     5.2 +++ b/test/encrypt_missing_private_key_test.cc	Mon Mar 13 20:48:39 2017 +0100
     5.3 @@ -11,6 +11,7 @@
     5.4  #include "keymanagement.h"
     5.5  #include "message_api.h"
     5.6  #include "mime.h"
     5.7 +#include "test_util.h"
     5.8  
     5.9  using namespace std;
    5.10  
    5.11 @@ -31,15 +32,7 @@
    5.12      
    5.13      // B252066DE0513BECA2954F30E8E18177B28D9B9D - this is the blacklisted key in blacklisted_self.asc
    5.14  
    5.15 -    /* read the key into memory */
    5.16 -    ifstream infile("test_keys/priv/blacklist_self.asc");
    5.17 -    string keytext;
    5.18 -    while (!infile.eof()) {
    5.19 -        static string line;
    5.20 -        getline(infile, line);
    5.21 -        keytext += line + "\n";
    5.22 -    }
    5.23 -    infile.close(); 
    5.24 +    const string keytext = slurp("test_keys/priv/blacklist_self.asc");
    5.25      
    5.26      /* import it into pep */
    5.27      PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    5.28 @@ -59,16 +52,9 @@
    5.29  
    5.30      /* identity is blacklisted. Now let's try to encrypt a message. */
    5.31      
    5.32 -    const char* new_key = NULL;    
    5.33 +    const char* new_key = NULL;
    5.34      
    5.35 -    ifstream infile2("test_mails/blacklist_no_key.eml");
    5.36 -    string mailtext;
    5.37 -    while (!infile2.eof()) {
    5.38 -        static string line;
    5.39 -        getline(infile2, line);
    5.40 -        mailtext += line + "\n";
    5.41 -    }     infile2.close(); 
    5.42 -
    5.43 +    const string mailtext = slurp("test_mails/blacklist_no_key.eml");
    5.44      
    5.45      message* tmp_msg = NULL;
    5.46      message* enc_msg = NULL;
    5.47 @@ -77,7 +63,6 @@
    5.48      assert(status == PEP_STATUS_OK);
    5.49      
    5.50      
    5.51 -    
    5.52      // This isn't incoming, though... so we need to reverse the direction
    5.53      tmp_msg->dir = PEP_dir_outgoing;
    5.54      status = encrypt_message(session,
    5.55 @@ -88,7 +73,6 @@
    5.56                               0);
    5.57      assert(status == PEP_STATUS_OK);
    5.58      
    5.59 -    
    5.60  //    PEP_STATUS status69 = MIME_encrypt_message(session, mailtext.c_str(), mailtext.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    5.61  //    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    5.62  
    5.63 @@ -121,4 +105,3 @@
    5.64      release(session);
    5.65      return 0;
    5.66  }
    5.67 -
     6.1 --- a/test/least_common_denom_color_test.cc	Mon Mar 13 20:47:49 2017 +0100
     6.2 +++ b/test/least_common_denom_color_test.cc	Mon Mar 13 20:48:39 2017 +0100
     6.3 @@ -8,6 +8,7 @@
     6.4  #include "keymanagement.h"
     6.5  #include "message_api.h"
     6.6  #include "mime.h"
     6.7 +#include "test_util.h"
     6.8  
     6.9  using namespace std;
    6.10  
    6.11 @@ -24,42 +25,10 @@
    6.12      cout << "init() completed.\n";
    6.13      
    6.14      // import keys
    6.15 -
    6.16 -    ifstream infilekey1("test_keys/pub/banmeonce-0x07B29090_pub.asc");
    6.17 -    string keytextkey1;
    6.18 -    while (!infilekey1.eof()) {
    6.19 -        static string line;
    6.20 -        getline(infilekey1, line);
    6.21 -        keytextkey1 += line + "\n";
    6.22 -    }
    6.23 -    infilekey1.close(); 
    6.24 -    
    6.25 -    ifstream infilekey2("test_keys/pub/banmetwice-0x4080C3E7_pub.asc");
    6.26 -    string keytextkey2;
    6.27 -    while (!infilekey2.eof()) {
    6.28 -        static string line;
    6.29 -        getline(infilekey2, line);
    6.30 -        keytextkey2 += line + "\n";
    6.31 -    }
    6.32 -    infilekey2.close(); 
    6.33 -
    6.34 -    ifstream infilekey3("test_keys/pub/pep.never.me.test-0x79C11D1D_pub.asc");
    6.35 -    string keytextkey3;
    6.36 -    while (!infilekey3.eof()) {
    6.37 -        static string line;
    6.38 -        getline(infilekey3, line);
    6.39 -        keytextkey3 += line + "\n";
    6.40 -    }
    6.41 -    infilekey3.close(); 
    6.42 -    
    6.43 -    ifstream infilekey4("test_keys/priv/pep.never.me.test-0x79C11D1D_priv.asc");
    6.44 -    string keytextkey4;
    6.45 -    while (!infilekey4.eof()) {
    6.46 -        static string line;
    6.47 -        getline(infilekey4, line);
    6.48 -        keytextkey4 += line + "\n";
    6.49 -    }
    6.50 -    infilekey4.close(); 
    6.51 +    const string keytextkey1 = slurp("test_keys/pub/banmeonce-0x07B29090_pub.asc");
    6.52 +    const string keytextkey2 = slurp("test_keys/pub/banmetwice-0x4080C3E7_pub.asc");
    6.53 +    const string keytextkey3 = slurp("test_keys/pub/pep.never.me.test-0x79C11D1D_pub.asc");
    6.54 +    const string keytextkey4 = slurp("test_keys/priv/pep.never.me.test-0x79C11D1D_priv.asc");
    6.55  
    6.56      PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    6.57      PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    6.58 @@ -81,14 +50,7 @@
    6.59      status = update_identity(session, recip2);
    6.60      key_reset_trust(session, recip2);
    6.61          
    6.62 -    ifstream infile(mailfile);
    6.63 -    string mailtext;
    6.64 -    while (!infile.eof()) {
    6.65 -        static string line;
    6.66 -        getline(infile, line);
    6.67 -        mailtext += line + "\n";
    6.68 -    }
    6.69 -    infile.close(); 
    6.70 +    const string mailtext = slurp(mailfile);
    6.71  
    6.72      // trust_personal_key(session, you);
    6.73      // 
    6.74 @@ -153,7 +115,7 @@
    6.75      final_ptr = nullptr;
    6.76      keylist = nullptr;
    6.77      rating = PEP_rating_unreliable;
    6.78 -        
    6.79 +    
    6.80      cout << "calling release()\n";
    6.81      release(session);
    6.82      return 0;