test/mime_test.cc
author vb
Mon, 09 Mar 2015 23:20:08 +0100
changeset 94 9ec29aa10b58
parent 89 aef5a4bc78f3
child 113 4bee48270834
permissions -rw-r--r--
...
     1 #include <iostream>
     2 #include <fstream>
     3 #include <string>
     4 #include <assert.h>
     5 #include "mime.h"
     6 
     7 using namespace std;
     8 
     9 int main() {
    10     cout << "\n*** mime_test ***\n\n";
    11 
    12     PEP_SESSION session;
    13     
    14     cout << "calling init()\n";
    15     PEP_STATUS status1 = init(&session);   
    16     assert(status1 == PEP_STATUS_OK);
    17     assert(session);
    18     cout << "init() completed.\n";
    19 
    20     // mime test code
    21 
    22     // testing multipart/alternative
    23 
    24     message *msg2 = new_message(PEP_dir_incoming,
    25             new_identity("vb@dingens.org", NULL, NULL, "Volker Birk"),
    26             new_identity_list(new_identity("trischa@dingens.org", NULL, NULL, "Patricia Bädnar")),
    27             "my sübject");
    28     assert(msg2);
    29     string text2 = "my mèssage to yoü";
    30     msg2->longmsg = strdup(text2.c_str());
    31     string html2 = "<html><body><p>my message to you</p></body></html>";
    32     msg2->longmsg_formatted = strdup(html2.c_str());
    33     assert(msg2->longmsg_formatted);
    34 
    35     cout << "encoding message…\n";
    36     char *result2;
    37     PEP_STATUS status2 = mime_encode_message(msg2, &result2);
    38     assert(result2);
    39     assert(status2 == PEP_STATUS_OK);
    40 
    41     cout << "result:\n";
    42     cout << result2 << "\n";
    43 
    44     free(result2);
    45     free_message(msg2);
    46 
    47     cout << "opening mime_sample.txt for reading\n";
    48     ifstream inFile3 ("mime_sample.txt");
    49     assert(inFile3.is_open());
    50 
    51     string mimetext3;
    52 
    53     cout << "reading mime sample\n";
    54     while (!inFile3.eof()) {
    55         static string line;
    56         getline(inFile3, line);
    57         mimetext3 += line + "\n";
    58     }
    59     inFile3.close();
    60 
    61     message *msg3;
    62     PEP_STATUS status3 = mime_decode_message(mimetext3.c_str(), &msg3);
    63 
    64     cout << "calling release()\n";
    65     release(session);
    66     return 0;
    67 }
    68