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