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