test/message_api_test.cc
author vb
Sat, 14 Mar 2015 11:28:14 +0100
changeset 112 d001ca329a48
parent 71 3a036da3e479
child 113 4bee48270834
permissions -rw-r--r--
message formats
     1 #include <iostream>
     2 #include <assert.h>
     3 #include "message_api.h"
     4 
     5 using namespace std;
     6 
     7 int main() {
     8     cout << "\n*** message_api_test ***\n\n";
     9 
    10     PEP_SESSION session;
    11     
    12     cout << "calling init()\n";
    13     PEP_STATUS status1 = init(&session);   
    14     assert(status1 == PEP_STATUS_OK);
    15     assert(session);
    16     cout << "init() completed.\n";
    17 
    18     // message_api test code
    19 
    20     cout << "creating message…\n";
    21     pEp_identity * me2 = new_identity("outlooktest@dingens.org", NULL, "23", "Outlook Test");
    22     me2->me = true;
    23     identity_list *to2 = new_identity_list(new_identity("vb@dingens.org", NULL, "42", "Volker Birk"));
    24     message *msg2 = new_message(PEP_dir_outgoing, me2, to2, "hello, world");
    25     assert(msg2);
    26     cout << "message created.\n";
    27 
    28     char *text2;
    29     PEP_STATUS status2 = mime_encode_message(msg2, &text2);
    30     assert(status2 == PEP_STATUS_OK);
    31     assert(text2);
    32 
    33     cout << "decrypted:\n\n";
    34     cout << text2 << "\n";
    35 
    36     free(text2);
    37 
    38     cout << "encrypting message as MIME multipart…\n";
    39     message *enc_msg2;
    40     cout << "calling encrypt_message()\n";
    41     status2 = encrypt_message(session, msg2, NULL, &enc_msg2, PEP_enc_MIME_multipart);
    42     assert(status2 == PEP_STATUS_OK);
    43     assert(enc_msg2);
    44     cout << "message encrypted.\n";
    45     
    46     status2 = mime_encode_message(enc_msg2, &text2);
    47     assert(status2 == PEP_STATUS_OK);
    48     assert(text2);
    49 
    50     cout << "encrypted:\n\n";
    51     cout << text2 << "\n";
    52 
    53     free(text2);
    54 
    55     cout << "freeing messages…\n";
    56     free_message(msg2);
    57     free_message(enc_msg2);
    58     cout << "done.\n";
    59 
    60     cout << "calling release()\n";
    61     release(session);
    62     return 0;
    63 }
    64