shelving local_cpptest
authorKrista Bennett <krista@pep-project.org>
Wed, 02 May 2018 11:07:57 +0200
branchlocal_cpptest
changeset 2641f249c4bcc819
parent 2640 1bf5b0421bd8
child 2642 7dbfc6c3f3c8
shelving
test/apple_mail_test.cc
test/include/DecorateTests.h
test/include/EngineTestIndividualSuite.h
test/src/EngineTestIndividualSuite.cc
test/src/SuiteMaker.cc
test/src/engine_tests/AppleMailTests.cc
test/src/engine_tests/DecorateTests.cc
     1.1 --- a/test/apple_mail_test.cc	Wed May 02 10:06:34 2018 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,114 +0,0 @@
     1.4 -#include <iostream>
     1.5 -#include <iostream>
     1.6 -#include <fstream>
     1.7 -#include <string>
     1.8 -#include <cstring> // for strcmp()
     1.9 -#include <assert.h>
    1.10 -#include "blacklist.h"
    1.11 -#include "keymanagement.h"
    1.12 -#include "message_api.h"
    1.13 -#include "mime.h"
    1.14 -#include "test_util.h" // for slurp()
    1.15 -
    1.16 -using namespace std;
    1.17 -
    1.18 -int main(int argc, char** argv) {
    1.19 -
    1.20 -    const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
    1.21 -    
    1.22 -    PEP_SESSION session;
    1.23 -    
    1.24 -    cout << "calling init()\n";
    1.25 -    PEP_STATUS status1 = init(&session);   
    1.26 -    assert(status1 == PEP_STATUS_OK);
    1.27 -    assert(session);
    1.28 -    cout << "init() completed.\n";
    1.29 -
    1.30 -    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
    1.31 -    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
    1.32 -    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
    1.33 -
    1.34 -    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    1.35 -    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    1.36 -    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
    1.37 -        
    1.38 -    const string mailtext = slurp(mailfile);
    1.39 -    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");    
    1.40 -    me->me = true;    
    1.41 -    PEP_STATUS status = set_own_key(session, me, "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE");
    1.42 -    
    1.43 -    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "pep.test.apple@pep-project.org", "pEp Apple Test");    
    1.44 -    you->me = false;    
    1.45 -    status = update_identity(session, you);
    1.46 -
    1.47 -    trust_personal_key(session, you);
    1.48 -    
    1.49 -    status = update_identity(session, you);
    1.50 -    
    1.51 -    message* msg_ptr = nullptr;
    1.52 -    message* dest_msg = nullptr;
    1.53 -    message* final_ptr = nullptr;
    1.54 -    stringlist_t* keylist = nullptr;
    1.55 -    PEP_rating rating;
    1.56 -    PEP_decrypt_flags_t flags;
    1.57 -    
    1.58 -    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    1.59 -    assert(status == PEP_STATUS_OK);
    1.60 -    assert(msg_ptr);
    1.61 -    
    1.62 -    update_identity(session, msg_ptr->from);
    1.63 -    update_identity(session, msg_ptr->to->ident);
    1.64 -    
    1.65 -    final_ptr = msg_ptr;
    1.66 -    
    1.67 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    1.68 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
    1.69 -  
    1.70 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    1.71 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    1.72 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    1.73 -
    1.74 -    assert(color_from_rating(rating) == PEP_color_green);
    1.75 -
    1.76 -    if (final_ptr == dest_msg)
    1.77 -    	free_message(dest_msg);
    1.78 -    free_message(msg_ptr);
    1.79 -    free_stringlist(keylist);
    1.80 -
    1.81 -    msg_ptr = nullptr;
    1.82 -    dest_msg = nullptr;
    1.83 -    final_ptr = nullptr;
    1.84 -    keylist = nullptr;
    1.85 -    rating = PEP_rating_unreliable;
    1.86 -    
    1.87 -    const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
    1.88 -    const string mailtext2 = slurp(mailfile2);
    1.89 -    
    1.90 -    status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
    1.91 -    assert(status == PEP_STATUS_OK);
    1.92 -    assert(msg_ptr);
    1.93 -    final_ptr = msg_ptr;
    1.94 -    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    1.95 -    final_ptr = dest_msg ? dest_msg : msg_ptr;
    1.96 -  
    1.97 -    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    1.98 -    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    1.99 -    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   1.100 -
   1.101 -    assert(color_from_rating(rating) == PEP_color_green);
   1.102 -
   1.103 -    if (final_ptr == dest_msg)
   1.104 -    	free_message(dest_msg);
   1.105 -    free_message(msg_ptr);
   1.106 -    free_stringlist(keylist);
   1.107 -
   1.108 -    msg_ptr = nullptr;
   1.109 -    dest_msg = nullptr;
   1.110 -    final_ptr = nullptr;
   1.111 -    keylist = nullptr;
   1.112 -    rating = PEP_rating_unreliable;
   1.113 -        
   1.114 -    cout << "calling release()\n";
   1.115 -    release(session);
   1.116 -    return 0;
   1.117 -}
     2.1 --- a/test/include/DecorateTests.h	Wed May 02 10:06:34 2018 +0200
     2.2 +++ b/test/include/DecorateTests.h	Wed May 02 11:07:57 2018 +0200
     2.3 @@ -18,7 +18,7 @@
     2.4  
     2.5  using namespace std;
     2.6  
     2.7 -class DecorateTests : public EngineTestSessionSuite {
     2.8 +class DecorateTests : public EngineTestIndividualSuite {
     2.9      public:
    2.10          DecorateTests(string suitename, string test_home_dir);
    2.11      private:
     3.1 --- a/test/include/EngineTestIndividualSuite.h	Wed May 02 10:06:34 2018 +0200
     3.2 +++ b/test/include/EngineTestIndividualSuite.h	Wed May 02 11:07:57 2018 +0200
     3.3 @@ -13,7 +13,7 @@
     3.4  class EngineTestIndividualSuite : public EngineTestSuite {
     3.5      public:
     3.6          EngineTestIndividualSuite(string suitename, string test_home_dir);
     3.7 -        ~EngineTestIndividualSuite();
     3.8 +        virtual ~EngineTestIndividualSuite();
     3.9      protected:
    3.10          virtual void setup();
    3.11          virtual void tear_down();
     4.1 --- a/test/src/EngineTestIndividualSuite.cc	Wed May 02 10:06:34 2018 +0200
     4.2 +++ b/test/src/EngineTestIndividualSuite.cc	Wed May 02 11:07:57 2018 +0200
     4.3 @@ -10,6 +10,15 @@
     4.4  
     4.5  using namespace std;
     4.6  
     4.7 +// Constructor
     4.8 +EngineTestIndividualSuite::EngineTestIndividualSuite(string suitename, string test_home_dir) 
     4.9 +    : EngineTestSuite(suitename, test_home_dir) { 
    4.10 +}
    4.11 +
    4.12 +EngineTestIndividualSuite::~EngineTestIndividualSuite() {
    4.13 +    
    4.14 +}
    4.15 +
    4.16  void EngineTestIndividualSuite::setup() {
    4.17      set_full_env(); // This will be called by default before every test
    4.18  }
     5.1 --- a/test/src/SuiteMaker.cc	Wed May 02 10:06:34 2018 +0200
     5.2 +++ b/test/src/SuiteMaker.cc	Wed May 02 11:07:57 2018 +0200
     5.3 @@ -17,4 +17,6 @@
     5.4  void suitemaker_build(const char* test_class_name, const char* test_home, std::auto_ptr<Test::Suite>& test_suite) {
     5.5      if (strcmp(test_class_name, "DecorateTests") == 0)
     5.6          test_suite = auto_ptr<Test::Suite> (new DecorateTests(test_class_name, test_home));
     5.7 +    else if (strcmp(test_class_name, "AppleMailTests") == 0)
     5.8 +        test_suite = auto_ptr<Test::Suite> (new DecorateTests(test_class_name, test_home));    
     5.9  }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/src/engine_tests/AppleMailTests.cc	Wed May 02 11:07:57 2018 +0200
     6.3 @@ -0,0 +1,120 @@
     6.4 +// This file is under GNU General Public License 3.0
     6.5 +// see LICENSE.txt
     6.6 +
     6.7 +#include <cpptest.h>
     6.8 +#include <cpptest-suite.h>
     6.9 +#include <cpptest-textoutput.h>
    6.10 +#include <stdlib.h>
    6.11 +#include <string.h>
    6.12 +#include <iostream>
    6.13 +#include <fstream>
    6.14 +#include <string>
    6.15 +#include <cstring> // for strcmp()
    6.16 +#include "platform.h"
    6.17 +#include <iostream>
    6.18 +#include <fstream>
    6.19 +#include <sstream>
    6.20 +#include "keymanagement.h"
    6.21 +#include "message_api.h"
    6.22 +#include "mime.h"
    6.23 +#include "test_util.h" // for slurp()
    6.24 +
    6.25 +#include "EngineTestSuite.h"
    6.26 +#include "EngineTestIndividualSuite.h"
    6.27 +#include "AppleMailTests.h"
    6.28 +
    6.29 +using namespace std;
    6.30 +
    6.31 +AppleMailTests::AppleMailTests(string suitename, string test_home_dir) : 
    6.32 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
    6.33 +    TEST_ADD(AppleMailTests::check_apple_mail);
    6.34 +}
    6.35 +
    6.36 +void AppleMailTests::check_apple_mail() {
    6.37 +    
    6.38 +    const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
    6.39 +    
    6.40 +    const string keytextkey1 = slurp("test_keys/pub/pep-test-apple-0x1CCBC7D7_pub.asc");
    6.41 +    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
    6.42 +    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
    6.43 +
    6.44 +    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
    6.45 +    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
    6.46 +    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
    6.47 +        
    6.48 +    const string mailtext = slurp(mailfile);
    6.49 +    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");    
    6.50 +    me->me = true;    
    6.51 +    PEP_STATUS status = set_own_key(session, me, "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE");
    6.52 +    
    6.53 +    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "pep.test.apple@pep-project.org", "pEp Apple Test");    
    6.54 +    you->me = false;    
    6.55 +    status = update_identity(session, you);
    6.56 +
    6.57 +    trust_personal_key(session, you);
    6.58 +    
    6.59 +    status = update_identity(session, you);
    6.60 +    
    6.61 +    message* msg_ptr = nullptr;
    6.62 +    message* dest_msg = nullptr;
    6.63 +    message* final_ptr = nullptr;
    6.64 +    stringlist_t* keylist = nullptr;
    6.65 +    PEP_rating rating;
    6.66 +    PEP_decrypt_flags_t flags;
    6.67 +    
    6.68 +    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
    6.69 +    TEST_ASSERT(status == PEP_STATUS_OK);
    6.70 +    TEST_ASSERT(msg_ptr);
    6.71 +    
    6.72 +    update_identity(session, msg_ptr->from);
    6.73 +    update_identity(session, msg_ptr->to->ident);
    6.74 +    
    6.75 +    final_ptr = msg_ptr;
    6.76 +    
    6.77 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
    6.78 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
    6.79 +  
    6.80 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
    6.81 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
    6.82 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
    6.83 +
    6.84 +    TEST_ASSERT(color_from_rating(rating) == PEP_color_green);
    6.85 +
    6.86 +    if (final_ptr == dest_msg)
    6.87 +    	free_message(dest_msg);
    6.88 +    free_message(msg_ptr);
    6.89 +    free_stringlist(keylist);
    6.90 +
    6.91 +    msg_ptr = nullptr;
    6.92 +    dest_msg = nullptr;
    6.93 +    final_ptr = nullptr;
    6.94 +    keylist = nullptr;
    6.95 +    rating = PEP_rating_unreliable;
    6.96 +    
    6.97 +    const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
    6.98 +    const string mailtext2 = slurp(mailfile2);
    6.99 +    
   6.100 +    status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
   6.101 +    TEST_ASSERT(status == PEP_STATUS_OK);
   6.102 +    TEST_ASSERT(msg_ptr);
   6.103 +    final_ptr = msg_ptr;
   6.104 +    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
   6.105 +    final_ptr = dest_msg ? dest_msg : msg_ptr;
   6.106 +  
   6.107 +    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
   6.108 +    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
   6.109 +    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
   6.110 +
   6.111 +    TEST_ASSERT(color_from_rating(rating) == PEP_color_green);
   6.112 +
   6.113 +    if (final_ptr == dest_msg)
   6.114 +    	free_message(dest_msg);
   6.115 +    free_message(msg_ptr);
   6.116 +    free_stringlist(keylist);
   6.117 +
   6.118 +    msg_ptr = nullptr;
   6.119 +    dest_msg = nullptr;
   6.120 +    final_ptr = nullptr;
   6.121 +    keylist = nullptr;
   6.122 +    rating = PEP_rating_unreliable;        
   6.123 +}
     7.1 --- a/test/src/engine_tests/DecorateTests.cc	Wed May 02 10:06:34 2018 +0200
     7.2 +++ b/test/src/engine_tests/DecorateTests.cc	Wed May 02 11:07:57 2018 +0200
     7.3 @@ -16,13 +16,13 @@
     7.4  #include "test_util.h"
     7.5  
     7.6  #include "EngineTestSuite.h"
     7.7 -#include "EngineTestSessionSuite.h"
     7.8 +#include "EngineTestIndividualSuite.h"
     7.9  #include "DecorateTests.h"
    7.10  
    7.11  using namespace std;
    7.12  
    7.13  DecorateTests::DecorateTests(string suitename, string test_home_dir) : 
    7.14 -    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {            
    7.15 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {            
    7.16      TEST_ADD(DecorateTests::check_decorate);
    7.17  }
    7.18