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