test/keyedit_test.cc
changeset 205 69abe9ef3be2
child 211 a022e853f81e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/keyedit_test.cc	Mon Apr 20 21:03:13 2015 +0200
     1.3 @@ -0,0 +1,64 @@
     1.4 +#include "platform.h"
     1.5 +
     1.6 +#include <iostream>
     1.7 +#include <fstream>
     1.8 +#include <string>
     1.9 +#include <assert.h>
    1.10 +
    1.11 +#include "pEpEngine.h"
    1.12 +
    1.13 +using namespace std;
    1.14 +
    1.15 +int main() {
    1.16 +    cout << "\n*** keyedit_test ***\n\n";
    1.17 +
    1.18 +    PEP_SESSION session;
    1.19 +    
    1.20 +    cout << "calling init()\n";
    1.21 +    PEP_STATUS status1 = init(&session);   
    1.22 +    assert(status1 == PEP_STATUS_OK);
    1.23 +    assert(session);
    1.24 +    cout << "init() completed.\n";
    1.25 +
    1.26 +    // generate test key
    1.27 +
    1.28 +    cout << "\ngenerating key for expire test\n";
    1.29 +    pEp_identity *identity = new_identity(
    1.30 +            "expire@dingens.org",
    1.31 +            NULL,
    1.32 +            "423",
    1.33 +            "expire test key"
    1.34 +        );
    1.35 +    assert(identity);
    1.36 +    PEP_STATUS generate_status = generate_keypair(session, identity);
    1.37 +    cout << "generate_keypair() exits with " << generate_status << "\n";
    1.38 +    assert(generate_status == PEP_STATUS_OK);
    1.39 +    cout << "generated key is " << identity->fpr << "\n";
    1.40 +
    1.41 +    string key(identity->fpr);
    1.42 +    free_identity(identity);
    1.43 +
    1.44 +    // keyedit test code
    1.45 +
    1.46 +    timestamp *ts = new_timestamp(time(0));
    1.47 +    ts->tm_year += 2;
    1.48 +
    1.49 +    cout << "key shell expire on " << asctime(ts) << "\n";
    1.50 +
    1.51 +    PEP_STATUS status2 = renew_key(session, key.c_str(), ts);
    1.52 +    cout << "renew_key() exited with " << status2 << "\n";
    1.53 +    assert(status2 == PEP_STATUS_OK);
    1.54 +    free_timestamp(ts);
    1.55 +
    1.56 +    cout << "key renewed.\n";
    1.57 +
    1.58 +    cout << "deleting key pair " << key.c_str() << "\n";
    1.59 +    PEP_STATUS delete_status = delete_keypair(session, key.c_str());
    1.60 +    cout << "delete_keypair() exits with " << delete_status << "\n";
    1.61 +    assert(delete_status == PEP_STATUS_OK);
    1.62 +
    1.63 +    cout << "calling release()\n";
    1.64 +    release(session);
    1.65 +    return 0;
    1.66 +}
    1.67 +