test/message_api_test.cc
author Volker Birk <vb@pep-project.org>
Tue, 12 May 2015 13:42:48 +0200
changeset 267 31d89e1b5e08
parent 260 75481f577114
child 281 9f7691853773
permissions -rw-r--r--
return value of decrypt_message()
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@260
    70
    PEP_STATUS status4 = decrypt_message(session, enc_msg2, &msg4, &keylist4, &color);
vb@267
    71
    assert(status4 == PEP_STATUS_OK);
vb@166
    72
    assert(msg4);
vb@241
    73
    assert(keylist4);
vb@267
    74
    assert(color);
vb@241
    75
vb@241
    76
    cout << "keys used:";
vb@241
    77
    stringlist_t *kl4;
vb@241
    78
    for (kl4 = keylist4; kl4 && kl4->value; kl4 = kl4->next)
vb@241
    79
        cout << " " << kl4->value;
vb@241
    80
    cout << "\n\n";
vb@241
    81
vb@241
    82
    free_stringlist(keylist4);
vb@166
    83
vb@40
    84
    cout << "freeing messages…\n";
vb@166
    85
    free_message(msg4);
vb@116
    86
    free_message(msg3);
vb@112
    87
    free_message(msg2);
vb@112
    88
    free_message(enc_msg2);
vb@40
    89
    cout << "done.\n";
vb@39
    90
vb@39
    91
    cout << "calling release()\n";
vb@39
    92
    release(session);
vb@39
    93
    return 0;
vb@39
    94
}
vb@39
    95