Merged in ENGINE-189 for test util functions
authorKrista Grothoff <krista@pep-project.org>
Mon, 13 Mar 2017 22:44:12 +0100
changeset 166601779e4c5940
parent 1665 bf5c8d3fb0d2
parent 1664 9263048febb8
child 1668 156a5b29f796
child 1669 99c54cb90ff3
child 1670 8e2509f0ddad
Merged in ENGINE-189 for test util functions
     1.1 --- a/test/Makefile	Mon Mar 13 22:39:57 2017 +0100
     1.2 +++ b/test/Makefile	Mon Mar 13 22:44:12 2017 +0100
     1.3 @@ -31,6 +31,9 @@
     1.4  
     1.5  .PHONY: clean
     1.6  
     1.7 +# don't delete .o files!
     1.8 +.PRECIOUS: %.o
     1.9 +
    1.10  clean:
    1.11  	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
    1.12  	rm -Rf *.dSYM .imported pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
    1.13 @@ -42,9 +45,13 @@
    1.14  test: pEpEngineTest .imported
    1.15  	LD_LIBRARY_PATH=~/lib:../src ./pEpEngineTest
    1.16  
    1.17 +%_test : %_test.o test_util.o
    1.18 +	 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
    1.19 +
    1.20  %_test_run : %_test
    1.21  	LD_LIBRARY_PATH=~/lib:../src ./$<
    1.22  
    1.23 +
    1.24  %_test_lldb : %_test
    1.25  	LD_LIBRARY_PATH=~/lib:../src lldb ./$<
    1.26  
     2.1 --- a/test/apple_mail_test.cc	Mon Mar 13 22:39:57 2017 +0100
     2.2 +++ b/test/apple_mail_test.cc	Mon Mar 13 22:44:12 2017 +0100
     2.3 @@ -8,11 +8,11 @@
     2.4  #include "keymanagement.h"
     2.5  #include "message_api.h"
     2.6  #include "mime.h"
     2.7 +#include "test_util.h" // for slurp()
     2.8  
     2.9  using namespace std;
    2.10  
    2.11  int main(int argc, char** argv) {
    2.12 -    
    2.13  
    2.14      const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
    2.15      
    2.16 @@ -24,36 +24,13 @@
    2.17      assert(session);
    2.18      cout << "init() completed.\n";
    2.19  
    2.20 -    ifstream infilekey1("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
    2.21 -    string keytextkey1;
    2.22 -    while (!infilekey1.eof()) {
    2.23 -        static string line;
    2.24 -        getline(infilekey1, line);
    2.25 -        keytextkey1 += line + "\n";
    2.26 -    }
    2.27 -    infilekey1.close(); 
    2.28 -    
    2.29 -    ifstream infilekey2("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
    2.30 -    string keytextkey2;
    2.31 -    while (!infilekey2.eof()) {
    2.32 -        static string line;
    2.33 -        getline(infilekey2, line);
    2.34 -        keytextkey2 += line + "\n";
    2.35 -    }
    2.36 -    infilekey2.close(); 
    2.37 +    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
    2.38 +    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
    2.39  
    2.40      PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    2.41      PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    2.42          
    2.43 -    ifstream infile(mailfile);
    2.44 -    string mailtext;
    2.45 -    while (!infile.eof()) {
    2.46 -        static string line;
    2.47 -        getline(infile, line);
    2.48 -        mailtext += line + "\n";
    2.49 -    }
    2.50 -    infile.close(); 
    2.51 -
    2.52 +    const string mailtext = slurp(mailfile);
    2.53      pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", NULL, PEP_OWN_USERID, "pEp Test Recipient");    
    2.54      me->me = true;    
    2.55      PEP_STATUS status = update_identity(session, me);
    2.56 @@ -100,15 +77,7 @@
    2.57      rating = PEP_rating_unreliable;
    2.58      
    2.59      const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
    2.60 -    
    2.61 -    ifstream infile2(mailfile2);
    2.62 -    string mailtext2;
    2.63 -    while (!infile2.eof()) {
    2.64 -        static string line;
    2.65 -        getline(infile2, line);
    2.66 -        mailtext2 += line + "\n";
    2.67 -    }
    2.68 -    infile2.close(); 
    2.69 +    const string mailtext2 = slurp(mailfile2);
    2.70      
    2.71      status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
    2.72      assert(status == PEP_STATUS_OK);
     3.1 --- a/test/blacklist_accept_new_key_test.cc	Mon Mar 13 22:39:57 2017 +0100
     3.2 +++ b/test/blacklist_accept_new_key_test.cc	Mon Mar 13 22:44:12 2017 +0100
     3.3 @@ -11,6 +11,7 @@
     3.4  #include "keymanagement.h"
     3.5  #include "message_api.h"
     3.6  #include "mime.h"
     3.7 +#include "test_util.h"
     3.8  
     3.9  using namespace std;
    3.10  
    3.11 @@ -32,14 +33,7 @@
    3.12      // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    3.13  
    3.14      /* read the key into memory */
    3.15 -    ifstream infile("blacklisted_pub.asc");
    3.16 -    string keytext;
    3.17 -    while (!infile.eof()) {
    3.18 -        static string line;
    3.19 -        getline(infile, line);
    3.20 -        keytext += line + "\n";
    3.21 -    }
    3.22 -    infile.close(); 
    3.23 +    const string keytext = slurp("blacklisted_pub.asc");
    3.24      
    3.25      /* import it into pep */
    3.26      PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    3.27 @@ -58,17 +52,8 @@
    3.28  
    3.29      /* identity is blacklisted. Now let's read in a message which contains a new key for that ID. */
    3.30      
    3.31 -    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";    
    3.32 -    
    3.33 -    ifstream infile2("test_mails/blacklist_new_key_attached.eml");
    3.34 -    string mailtext;
    3.35 -    while (!infile2.eof()) {
    3.36 -        static string line;
    3.37 -        getline(infile2, line);
    3.38 -        mailtext += line + "\n";
    3.39 -    }
    3.40 -    infile2.close(); 
    3.41 -
    3.42 +    const char* new_key = "634FAC4417E9B2A5DC2BD4AAC4AEEBBE7E62701B";
    3.43 +    const string mailtext = slurp("test_mails/blacklist_new_key_attached.eml");
    3.44      pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    3.45  
    3.46      PEP_STATUS status = update_identity(session, me1);
    3.47 @@ -102,4 +87,3 @@
    3.48      release(session);
    3.49      return 0;
    3.50  }
    3.51 -
     4.1 --- a/test/blacklist_test.cc	Mon Mar 13 22:39:57 2017 +0100
     4.2 +++ b/test/blacklist_test.cc	Mon Mar 13 22:44:12 2017 +0100
     4.3 @@ -9,6 +9,7 @@
     4.4  #include <assert.h>
     4.5  #include "blacklist.h"
     4.6  #include "keymanagement.h"
     4.7 +#include "test_util.h"
     4.8  
     4.9  using namespace std;
    4.10  
    4.11 @@ -66,15 +67,7 @@
    4.12      
    4.13      // 2797 65A2 FEB5 B7C7 31B8  61D9 3E4C EFD9 F7AF 4684 - this is the blacklisted key in blacklisted_pub.asc
    4.14  
    4.15 -    /* read the key into memory */
    4.16 -    ifstream infile("blacklisted_pub.asc");
    4.17 -    string keytext;
    4.18 -    while (!infile.eof()) {
    4.19 -        static string line;
    4.20 -        getline(infile, line);
    4.21 -        keytext += line + "\n";
    4.22 -    }
    4.23 -    infile.close(); 
    4.24 +    const string keytext = slurp("blacklisted_pub.asc");
    4.25      
    4.26      /* FIXME: put in automated test stuff (N.B. only gdb mem examination to this point to get
    4.27       *        fix in */
    4.28 @@ -95,7 +88,7 @@
    4.29      blacklisted_identity->comm_type = PEP_ct_pEp;
    4.30  
    4.31      PEP_STATUS status99 = set_identity(session, blacklisted_identity);
    4.32 -        
    4.33 +    
    4.34      trust_personal_key(session, blacklisted_identity);
    4.35  
    4.36      PEP_STATUS status999 = update_identity(session, blacklisted_identity);
    4.37 @@ -111,16 +104,7 @@
    4.38      else
    4.39          cout << "blacklisted identity's fpr successfully wiped by update_identity" << endl;
    4.40  
    4.41 -    /* read the key into memory */
    4.42 -    ifstream infile2("blacklisted_pub2.asc");
    4.43 -    string keytext2;
    4.44 -    while (!infile2.eof()) {
    4.45 -        static string line2;
    4.46 -        getline(infile2, line2);
    4.47 -        keytext2 += line2 + "\n";
    4.48 -    }
    4.49 -    infile2.close(); 
    4.50 -    
    4.51 +    const string keytext2 = slurp("blacklisted_pub2.asc");
    4.52      PEP_STATUS status14 = import_key(session, keytext2.c_str(), keytext2.length(), NULL);
    4.53      
    4.54      pEp_identity* blacklisted_identity2 = new_identity("blacklistedkeys@kgrothoff.org",
     5.1 --- a/test/encrypt_for_identity_test.cc	Mon Mar 13 22:39:57 2017 +0100
     5.2 +++ b/test/encrypt_for_identity_test.cc	Mon Mar 13 22:44:12 2017 +0100
     5.3 @@ -9,6 +9,7 @@
     5.4  #include <assert.h>
     5.5  #include "mime.h"
     5.6  #include "message_api.h"
     5.7 +#include "test_util.h"
     5.8  
     5.9  using namespace std;
    5.10  
    5.11 @@ -119,18 +120,7 @@
    5.12  
    5.13      cout << "Reading in alice_bob_encrypt_test_plaintext_mime.eml..." << endl;
    5.14      
    5.15 -    ifstream inFile("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
    5.16 -    assert(inFile.is_open());
    5.17 -
    5.18 -    string mimetext;
    5.19 -
    5.20 -    cout << "reading mime mail\n";
    5.21 -    while (!inFile.eof()) {
    5.22 -        static string line;
    5.23 -        getline(inFile, line);
    5.24 -        mimetext += line + "\n";
    5.25 -    }
    5.26 -    inFile.close();
    5.27 +    const string mimetext = slurp("test_mails/alice_bob_encrypt_test_plaintext_mime.eml");
    5.28  
    5.29      cout << "Text read:" << endl;
    5.30      cout << mimetext.c_str() << endl;
     6.1 --- a/test/encrypt_missing_private_key_test.cc	Mon Mar 13 22:39:57 2017 +0100
     6.2 +++ b/test/encrypt_missing_private_key_test.cc	Mon Mar 13 22:44:12 2017 +0100
     6.3 @@ -11,6 +11,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 @@ -31,15 +32,7 @@
    6.12      
    6.13      // B252066DE0513BECA2954F30E8E18177B28D9B9D - this is the blacklisted key in blacklisted_self.asc
    6.14  
    6.15 -    /* read the key into memory */
    6.16 -    ifstream infile("test_keys/priv/blacklist_self.asc");
    6.17 -    string keytext;
    6.18 -    while (!infile.eof()) {
    6.19 -        static string line;
    6.20 -        getline(infile, line);
    6.21 -        keytext += line + "\n";
    6.22 -    }
    6.23 -    infile.close(); 
    6.24 +    const string keytext = slurp("test_keys/priv/blacklist_self.asc");
    6.25      
    6.26      /* import it into pep */
    6.27      PEP_STATUS status7 = import_key(session, keytext.c_str(), keytext.length(), NULL);
    6.28 @@ -59,16 +52,9 @@
    6.29  
    6.30      /* identity is blacklisted. Now let's try to encrypt a message. */
    6.31      
    6.32 -    const char* new_key = NULL;    
    6.33 +    const char* new_key = NULL;
    6.34      
    6.35 -    ifstream infile2("test_mails/blacklist_no_key.eml");
    6.36 -    string mailtext;
    6.37 -    while (!infile2.eof()) {
    6.38 -        static string line;
    6.39 -        getline(infile2, line);
    6.40 -        mailtext += line + "\n";
    6.41 -    }     infile2.close(); 
    6.42 -
    6.43 +    const string mailtext = slurp("test_mails/blacklist_no_key.eml");
    6.44      
    6.45      message* tmp_msg = NULL;
    6.46      message* enc_msg = NULL;
    6.47 @@ -77,7 +63,6 @@
    6.48      assert(status == PEP_STATUS_OK);
    6.49      
    6.50      
    6.51 -    
    6.52      // This isn't incoming, though... so we need to reverse the direction
    6.53      tmp_msg->dir = PEP_dir_outgoing;
    6.54      status = encrypt_message(session,
    6.55 @@ -88,7 +73,6 @@
    6.56                               0);
    6.57      assert(status == PEP_STATUS_OK);
    6.58      
    6.59 -    
    6.60  //    PEP_STATUS status69 = MIME_encrypt_message(session, mailtext.c_str(), mailtext.length(), NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    6.61  //    pEp_identity * me1 = new_identity("blacklist_test@kgrothoff.org", NULL, PEP_OWN_USERID, "Blacklisted Key Message Recipient");    
    6.62  
    6.63 @@ -121,4 +105,3 @@
    6.64      release(session);
    6.65      return 0;
    6.66  }
    6.67 -
     7.1 --- a/test/least_color_group_test.cc	Mon Mar 13 22:39:57 2017 +0100
     7.2 +++ b/test/least_color_group_test.cc	Mon Mar 13 22:44:12 2017 +0100
     7.3 @@ -1,13 +1,13 @@
     7.4  #include <iostream>
     7.5  #include <iostream>
     7.6 -#include <fstream>
     7.7 -#include <string>
     7.8 +#include <vector>
     7.9  #include <cstring> // for strcmp()
    7.10  #include <assert.h>
    7.11  #include "blacklist.h"
    7.12  #include "keymanagement.h"
    7.13  #include "message_api.h"
    7.14  #include "mime.h"
    7.15 +#include "test_util.h"
    7.16  
    7.17  using namespace std;
    7.18  
    7.19 @@ -16,15 +16,14 @@
    7.20      
    7.21      const char* mailfile = "test_mails/color_test.eml";
    7.22      
    7.23 -    const char* keynames[] = {"test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
    7.24 +    const std::vector<const char*> keynames = {
    7.25 +                              "test_keys/priv/pep.color.test.P-0x3EBE215C_priv.asc",
    7.26                                "test_keys/pub/pep.color.test.H-0xD17E598E_pub.asc",
    7.27                                "test_keys/pub/pep.color.test.L-0xE9CDB4CE_pub.asc",
    7.28                                "test_keys/pub/pep.color.test.P-0x3EBE215C_pub.asc",
    7.29                                "test_keys/pub/pep.color.test.V-0x71FC6D28_pub.asc"
    7.30                            };
    7.31      
    7.32 -    const int num_keyfiles = 5;
    7.33 -        
    7.34      PEP_SESSION session;
    7.35      
    7.36      cout << "calling init()\n";
    7.37 @@ -33,36 +32,20 @@
    7.38      assert(session);
    7.39      cout << "init() completed.\n";
    7.40      
    7.41 -    int i = 0;
    7.42 -    
    7.43 -    for ( ; i < num_keyfiles; i++) {
    7.44 -        cout << "\t read keyfile #" << i << ": \"" << keynames[i] << "\"..." << std::endl;
    7.45 -        ifstream infilekey(keynames[i]);
    7.46 -        string keytextkey;
    7.47 -        while (!infilekey.eof()) {
    7.48 -            static string line;
    7.49 -            getline(infilekey, line);
    7.50 -            keytextkey += line + "\n";
    7.51 -        }
    7.52 -        infilekey.close(); 
    7.53 +    for (auto name : keynames) {
    7.54 +        cout << "\t read keyfile \"" << name << "\"..." << std::endl;
    7.55 +        const string keytextkey = slurp(name);
    7.56          PEP_STATUS statuskey = import_key(session, keytextkey.c_str(), keytextkey.length(), NULL);
    7.57          assert(statuskey == PEP_STATUS_OK);
    7.58      }
    7.59      
    7.60      cout << "\t read keyfile mailfile \"" << mailfile << "\"..." << std::endl;
    7.61 -    ifstream infile(mailfile);
    7.62 -    string mailtext;
    7.63 -    while (!infile.eof()) {
    7.64 -        static string line;
    7.65 -        getline(infile, line);
    7.66 -        mailtext += line + "\n";
    7.67 -    }
    7.68 -    infile.close(); 
    7.69 +    const string mailtext = slurp(mailfile);
    7.70      cout << "\t All files read successfully." << std::endl;
    7.71  
    7.72      pEp_identity * me1 = new_identity("pep.color.test.P@kgrothoff.org", NULL, 
    7.73                                        PEP_OWN_USERID, "Pep Color Test P (recip)");
    7.74 -    me1->me = true;    
    7.75 +    me1->me = true;
    7.76      PEP_STATUS status = update_identity(session, me1);
    7.77      trust_personal_key(session, me1);
    7.78      status = update_identity(session, me1);
    7.79 @@ -74,7 +57,7 @@
    7.80      sender1->me = false;
    7.81      status = update_identity(session, sender1);
    7.82      trust_personal_key(session, sender1);
    7.83 -    status = update_identity(session, sender1);    
    7.84 +    status = update_identity(session, sender1);
    7.85      
    7.86      message* msg_ptr = nullptr;
    7.87      message* dest_msg = nullptr;
    7.88 @@ -95,10 +78,11 @@
    7.89      cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    7.90      cout << "rating: " << rating << endl << endl;
    7.91      cout << "keys used: " << endl;
    7.92 -    i = 0;
    7.93 +    
    7.94 +    int i = 0;
    7.95      for (stringlist_t* k = keylist; k; k = k->next) {
    7.96          if (i == 0)
    7.97 -       	    cout << "\t Signer (key 0):\t" << k->value << endl;
    7.98 +            cout << "\t Signer (key 0):\t" << k->value << endl;
    7.99          else
   7.100              cout << "\t #" << i << ":\t" << k->value << endl;
   7.101          i++;
     8.1 --- a/test/least_common_denom_color_test.cc	Mon Mar 13 22:39:57 2017 +0100
     8.2 +++ b/test/least_common_denom_color_test.cc	Mon Mar 13 22:44:12 2017 +0100
     8.3 @@ -8,6 +8,7 @@
     8.4  #include "keymanagement.h"
     8.5  #include "message_api.h"
     8.6  #include "mime.h"
     8.7 +#include "test_util.h"
     8.8  
     8.9  using namespace std;
    8.10  
    8.11 @@ -24,42 +25,10 @@
    8.12      cout << "init() completed.\n";
    8.13      
    8.14      // import keys
    8.15 -
    8.16 -    ifstream infilekey1("test_keys/pub/banmeonce-0x07B29090_pub.asc");
    8.17 -    string keytextkey1;
    8.18 -    while (!infilekey1.eof()) {
    8.19 -        static string line;
    8.20 -        getline(infilekey1, line);
    8.21 -        keytextkey1 += line + "\n";
    8.22 -    }
    8.23 -    infilekey1.close(); 
    8.24 -    
    8.25 -    ifstream infilekey2("test_keys/pub/banmetwice-0x4080C3E7_pub.asc");
    8.26 -    string keytextkey2;
    8.27 -    while (!infilekey2.eof()) {
    8.28 -        static string line;
    8.29 -        getline(infilekey2, line);
    8.30 -        keytextkey2 += line + "\n";
    8.31 -    }
    8.32 -    infilekey2.close(); 
    8.33 -
    8.34 -    ifstream infilekey3("test_keys/pub/pep.never.me.test-0x79C11D1D_pub.asc");
    8.35 -    string keytextkey3;
    8.36 -    while (!infilekey3.eof()) {
    8.37 -        static string line;
    8.38 -        getline(infilekey3, line);
    8.39 -        keytextkey3 += line + "\n";
    8.40 -    }
    8.41 -    infilekey3.close(); 
    8.42 -    
    8.43 -    ifstream infilekey4("test_keys/priv/pep.never.me.test-0x79C11D1D_priv.asc");
    8.44 -    string keytextkey4;
    8.45 -    while (!infilekey4.eof()) {
    8.46 -        static string line;
    8.47 -        getline(infilekey4, line);
    8.48 -        keytextkey4 += line + "\n";
    8.49 -    }
    8.50 -    infilekey4.close(); 
    8.51 +    const string keytextkey1 = slurp("test_keys/pub/banmeonce-0x07B29090_pub.asc");
    8.52 +    const string keytextkey2 = slurp("test_keys/pub/banmetwice-0x4080C3E7_pub.asc");
    8.53 +    const string keytextkey3 = slurp("test_keys/pub/pep.never.me.test-0x79C11D1D_pub.asc");
    8.54 +    const string keytextkey4 = slurp("test_keys/priv/pep.never.me.test-0x79C11D1D_priv.asc");
    8.55  
    8.56      PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    8.57      PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    8.58 @@ -81,14 +50,7 @@
    8.59      status = update_identity(session, recip2);
    8.60      key_reset_trust(session, recip2);
    8.61          
    8.62 -    ifstream infile(mailfile);
    8.63 -    string mailtext;
    8.64 -    while (!infile.eof()) {
    8.65 -        static string line;
    8.66 -        getline(infile, line);
    8.67 -        mailtext += line + "\n";
    8.68 -    }
    8.69 -    infile.close(); 
    8.70 +    const string mailtext = slurp(mailfile);
    8.71  
    8.72      // trust_personal_key(session, you);
    8.73      // 
    8.74 @@ -153,7 +115,7 @@
    8.75      final_ptr = nullptr;
    8.76      keylist = nullptr;
    8.77      rating = PEP_rating_unreliable;
    8.78 -        
    8.79 +    
    8.80      cout << "calling release()\n";
    8.81      release(session);
    8.82      return 0;
     9.1 --- a/test/pEpEngine_test.h	Mon Mar 13 22:39:57 2017 +0100
     9.2 +++ b/test/pEpEngine_test.h	Mon Mar 13 22:44:12 2017 +0100
     9.3 @@ -1,4 +1,3 @@
     9.4  #include <iomanip>
     9.5  
     9.6  #define ASSERT_STATUS(status) { cout << setfill('0') << "status: 0x" << hex << setw(4) << status << "\n"; assert(status == PEP_STATUS_OK); }
     9.7 -
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/test_util.cc	Mon Mar 13 22:44:12 2017 +0100
    10.3 @@ -0,0 +1,17 @@
    10.4 +#include "pEpEngine_test.h"
    10.5 +#include <fstream>
    10.6 +#include <sstream>
    10.7 +#include <stdexcept>
    10.8 +
    10.9 +std::string slurp(const std::string& filename)
   10.10 +{
   10.11 +	std::ifstream input(filename.c_str());
   10.12 +	if(!input)
   10.13 +	{
   10.14 +		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
   10.15 +	}
   10.16 +	
   10.17 +	std::stringstream sstr;
   10.18 +	sstr << input.rdbuf();
   10.19 +	return sstr.str();
   10.20 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/test_util.h	Mon Mar 13 22:44:12 2017 +0100
    11.3 @@ -0,0 +1,5 @@
    11.4 +#include <string>
    11.5 +
    11.6 +// reads a whole file and returns it as std::string
    11.7 +// throws std::runtime_error() if the file cannot be read. Empty file is not an error.
    11.8 +std::string slurp(const std::string& filename);