test/message_api_test.cc
author Volker Birk <vb@pep-project.org>
Mon, 30 Mar 2015 17:28:04 +0200
changeset 166 fefff48448e3
parent 165 f0894860af4a
child 221 498615df9416
permissions -rw-r--r--
fixing seperate_short_and_long()
     1 #include "platform.h"
     2 #include <iostream>
     3 #include <fstream>
     4 #include <assert.h>
     5 #include "message_api.h"
     6 
     7 using namespace std;
     8 
     9 int main() {
    10     cout << "\n*** message_api_test ***\n\n";
    11 
    12     PEP_SESSION session;
    13     
    14     cout << "calling init()\n";
    15     PEP_STATUS status1 = init(&session);   
    16     assert(status1 == PEP_STATUS_OK);
    17     assert(session);
    18     cout << "init() completed.\n";
    19 
    20     // message_api test code
    21 
    22     cout << "creating message…\n";
    23     pEp_identity * me2 = new_identity("outlooktest@dingens.org", NULL, "23", "Outlook Test");
    24     me2->me = true;
    25     identity_list *to2 = new_identity_list(new_identity("vb@dingens.org", NULL, "42", "Volker Birk"));
    26     message *msg2 = new_message(PEP_dir_outgoing, me2, to2, "hello, world");
    27     assert(msg2);
    28     cout << "message created.\n";
    29 
    30     char *text2;
    31     PEP_STATUS status2 = mime_encode_message(msg2, false, &text2);
    32     assert(status2 == PEP_STATUS_OK);
    33     assert(text2);
    34 
    35     cout << "decrypted:\n\n";
    36     cout << text2 << "\n";
    37 
    38     free(text2);
    39 
    40     cout << "encrypting message as MIME multipart…\n";
    41     message *enc_msg2;
    42     cout << "calling encrypt_message()\n";
    43     status2 = encrypt_message(session, msg2, NULL, &enc_msg2, PEP_enc_PGP_MIME);
    44     assert(status2 == PEP_STATUS_OK);
    45     assert(enc_msg2);
    46     cout << "message encrypted.\n";
    47     
    48     status2 = mime_encode_message(enc_msg2, false, &text2);
    49     assert(status2 == PEP_STATUS_OK);
    50     assert(text2);
    51 
    52     cout << "encrypted:\n\n";
    53     cout << text2 << "\n";
    54 
    55     message *msg3;
    56     PEP_STATUS status3 = mime_decode_message(text2, &msg3);
    57     assert(status3 == PEP_STATUS_OK);
    58     string string3 = text2;
    59     free(text2);
    60 
    61     unlink("msg4.asc");
    62     ofstream outFile3("msg4.asc");
    63     outFile3.write(string3.c_str(), string3.size());
    64     outFile3.close();
    65 
    66     message *msg4;
    67     PEP_STATUS status4 = decrypt_message(session, enc_msg2, PEP_MIME_none, &msg4);
    68     assert(status4 == PEP_STATUS_OK);
    69     assert(msg4);
    70 
    71     cout << "freeing messages…\n";
    72     free_message(msg4);
    73     free_message(msg3);
    74     free_message(msg2);
    75     free_message(enc_msg2);
    76     cout << "done.\n";
    77 
    78     cout << "calling release()\n";
    79     release(session);
    80     return 0;
    81 }
    82