print the status in hex if >0, to ease debugging because in pEpEngine.h the values are in hex, too.
authorRoker <roker@pep-project.org>
Wed, 19 Apr 2017 10:14:47 +0200
changeset 1710990bd6357969
parent 1709 dcebe0692d63
child 1712 af3d488f90d8
child 1716 df5bc17b384b
print the status in hex if >0, to ease debugging because in pEpEngine.h the values are in hex, too.
test/pEpEngineTest.cc
     1.1 --- a/test/pEpEngineTest.cc	Tue Apr 18 16:40:32 2017 +0200
     1.2 +++ b/test/pEpEngineTest.cc	Wed Apr 19 10:14:47 2017 +0200
     1.3 @@ -26,7 +26,25 @@
     1.4          snprintf(buf,31, "%lu", u);
     1.5          return buf;
     1.6      }
     1.7 -}
     1.8 +    
     1.9 +    std::string status(PEP_STATUS status)
    1.10 +    {
    1.11 +        char buf[32] = {0};
    1.12 +        if(status==0)
    1.13 +        {
    1.14 +            return "PEP_STATUS_OK";
    1.15 +        }else{
    1.16 +            if(status>0)
    1.17 +            {
    1.18 +                snprintf(buf,31, "%u (0x%x)", status, status);
    1.19 +            }else{
    1.20 +                snprintf(buf,31, "%d", status);
    1.21 +            }
    1.22 +        }
    1.23 +        return buf;
    1.24 +    }
    1.25 +
    1.26 +} // end of anonymous namespace
    1.27  
    1.28  
    1.29  Buffer ReadFileIntoMem(const char *fname){
    1.30 @@ -66,13 +84,13 @@
    1.31      cout << "calling init()\n";
    1.32      PEP_STATUS init_result = init(&session);
    1.33      
    1.34 -    cout << "returning from init() with result == " << init_result << "\n";
    1.35 +    cout << "returning from init() with result == " << status(init_result) << endl;
    1.36      assert(init_result == PEP_STATUS_OK);
    1.37  
    1.38      PEP_SESSION second_session;
    1.39      cout << "second session test\n";
    1.40      PEP_STATUS second_init_result = init(&second_session);
    1.41 -    cout << "returning from second init() with result == " << second_init_result << "\n";
    1.42 +    cout << "returning from second init() with result == " << status(second_init_result) << endl;
    1.43      assert(second_init_result == PEP_STATUS_OK);
    1.44      assert(second_session);
    1.45      cout << "dropping second session\n";
    1.46 @@ -125,14 +143,14 @@
    1.47      cout << "calling decrypt_and_verify()\n";
    1.48      PEP_STATUS decrypt_result = decrypt_and_verify(session, cipher_buffer.data(), cipher_buffer.size(), NULL, 0, &buf_text, &buf_size, &keylist);
    1.49  
    1.50 -    cout << "returning from decrypt_and_verify() with result == 0x" << std::hex << decrypt_result << "\n";
    1.51 +    cout << "returning from decrypt_and_verify() with result == " << status(decrypt_result) << endl;
    1.52      assert(decrypt_result == PEP_DECRYPTED_AND_VERIFIED);
    1.53      assert(buf_text);
    1.54      assert(keylist);
    1.55  
    1.56      for (stringlist_t *_keylist=keylist; _keylist!=NULL; _keylist=_keylist->next) {
    1.57          assert(_keylist->value);
    1.58 -        cout << "signed with " << _keylist->value << "\n";
    1.59 +        cout << "signed with " << _keylist->value << endl;
    1.60      }
    1.61  
    1.62      free_stringlist(keylist);
    1.63 @@ -146,10 +164,10 @@
    1.64  
    1.65      cout << "\ncalling verify_text()\n";
    1.66      PEP_STATUS verify_result = verify_text(session, t1_buffer.data(), t1_buffer.size(), sig_buffer.data(), sig_buffer.size(), &keylist);
    1.67 -    cout << "returning from verify_text() with result == " << verify_result << "\n";
    1.68 +    cout << "returning from verify_text() with result == " << status(verify_result) << endl;
    1.69      assert(verify_result == PEP_VERIFIED || verify_result == PEP_VERIFIED_AND_TRUSTED);
    1.70      assert(keylist->value);
    1.71 -    cout << "signed with " << keylist->value << "\n";
    1.72 +    cout << "signed with " << keylist->value << endl;
    1.73      free_stringlist(keylist);
    1.74  
    1.75      const Buffer t2_buffer = ReadFileIntoMem("t2.txt");
    1.76 @@ -168,7 +186,7 @@
    1.77  
    1.78      cout << "\ncalling encrypt_and_sign()\n";
    1.79      PEP_STATUS encrypt_result = encrypt_and_sign(session, keylist, plain.c_str(), plain.length(), &buf_text, &buf_size);
    1.80 -    cout << "returning from encrypt_and_sign() with result == " << encrypt_result << "\n";
    1.81 +    cout << "returning from encrypt_and_sign() with result == " << status(encrypt_result) << endl;
    1.82      assert(encrypt_result == PEP_STATUS_OK);
    1.83      free_stringlist(keylist);
    1.84  
    1.85 @@ -182,12 +200,12 @@
    1.86      size_t wsize;
    1.87      trustword(session, 2342, "en", &word, &wsize);
    1.88      assert(word);
    1.89 -    cout << "the English trustword for 2342 is " << word << "\n";
    1.90 +    cout << "the English trustword for 2342 is " << word << endl;
    1.91      pEp_free(word);
    1.92      cout << "\nfinding French trustword for 2342...\n";
    1.93      trustword(session, 2342, "fr", &word, &wsize);
    1.94      assert(word);
    1.95 -    cout << "the French trustword for 2342 is " << word << "\n";
    1.96 +    cout << "the French trustword for 2342 is " << word << endl;
    1.97      pEp_free(word);
    1.98  
    1.99      const string fingerprint = "4942 2235 FC99 585B 891C  6653 0C7B 109B FA72 61F7";
   1.100 @@ -196,7 +214,7 @@
   1.101      cout << "\nfinding German trustwords for " << fingerprint << "...\n";
   1.102      trustwords(session, fingerprint.c_str(), "de", &words, &wsize, 5);
   1.103      assert(words);
   1.104 -    cout << words << "\n";
   1.105 +    cout << words << endl;
   1.106      pEp_free(words);
   1.107  
   1.108      pEp_identity* identity  = new_identity(
   1.109 @@ -213,11 +231,11 @@
   1.110      free_identity(identity);
   1.111      get_identity(session, "leon.schumacher@digitalekho.com", "23", &identity);
   1.112      assert(identity);
   1.113 -    cout << "set: " << identity->address << ", " << identity->fpr << ", " << identity->user_id << ", " << identity->username << "\n";
   1.114 +    cout << "set: " << identity->address << ", " << identity->fpr << ", " << identity->user_id << ", " << identity->username << endl;
   1.115  
   1.116      PEP_STATUS get_trust_result = get_trust(session, identity);
   1.117      assert(get_trust_result == PEP_STATUS_OK);
   1.118 -    cout << "trust of " << identity->user_id << " is " << identity->comm_type << "\n";
   1.119 +    cout << "trust of " << identity->user_id << " is " << identity->comm_type << endl;
   1.120  
   1.121      free_identity(identity);
   1.122  
   1.123 @@ -231,9 +249,9 @@
   1.124  
   1.125      assert(identity);
   1.126      PEP_STATUS generate_status = generate_keypair(session, identity);
   1.127 -    cout << "generate_keypair() exits with " << generate_status << "\n";
   1.128 +    cout << "generate_keypair() exits with " << status(generate_status) << endl;
   1.129      assert(generate_status == PEP_STATUS_OK);
   1.130 -    cout << "generated key is " << identity->fpr << "\n";
   1.131 +    cout << "generated key is " << identity->fpr << endl;
   1.132  
   1.133      const string key(identity->fpr);
   1.134      free_identity(identity);
   1.135 @@ -243,13 +261,13 @@
   1.136  
   1.137      cout << "export_key()\n\n";
   1.138      PEP_STATUS export_status = export_key(session, key.c_str(), &key_data, &size);
   1.139 -    cout << "export_key() exits with " << export_status << "\n";
   1.140 +    cout << "export_key() exits with " << status(export_status) << endl;
   1.141      assert(export_status == PEP_STATUS_OK);
   1.142      cout << key_data << "\n\n";
   1.143  
   1.144 -    cout << "deleting key pair " << key.c_str() << "\n";
   1.145 +    cout << "deleting key pair " << key.c_str() << endl;
   1.146      PEP_STATUS delete_status = delete_keypair(session, key.c_str());
   1.147 -    cout << "delete_keypair() exits with " << delete_status << "\n";
   1.148 +    cout << "delete_keypair() exits with " << status(delete_status) << endl;
   1.149      assert(delete_status == PEP_STATUS_OK);
   1.150      
   1.151      cout << "import_key()\n";
   1.152 @@ -262,31 +280,31 @@
   1.153  
   1.154      cout << "deleting key " << key.c_str() << " again\n";
   1.155      delete_status = delete_keypair(session, key.c_str());
   1.156 -    cout << "delete_keypair() exits with " << delete_status << "\n";
   1.157 +    cout << "delete_keypair() exits with " << status(delete_status) << endl;
   1.158      assert(delete_status == PEP_STATUS_OK);
   1.159  
   1.160      cout << "finding key for pep.test.john@pep-project.org\n";
   1.161      PEP_STATUS find_keys_status = find_keys(session, "pep.test.john@pep-project.org", &keylist);
   1.162 -    cout << "find_keys() exits with " << find_keys_status << "\n";
   1.163 +    cout << "find_keys() exits with " << status(find_keys_status) << endl;
   1.164      assert(find_keys_status == PEP_STATUS_OK);
   1.165      assert(keylist);
   1.166 -    cout << "found: " << keylist->value << "\n";
   1.167 +    cout << "found: " << keylist->value << endl;
   1.168      assert(keylist->next == NULL);
   1.169      free_stringlist(keylist);
   1.170  
   1.171      cout << "searching for vb@ulm.ccc.de on keyserver\n";
   1.172      PEP_STATUS recv_key_status = recv_key(session, "vb@ulm.ccc.de");
   1.173 -    cout << "recv_key() exits with " << recv_key_status << "\n";
   1.174 +    cout << "recv_key() exits with " << status(recv_key_status) << endl;
   1.175      assert(recv_key_status == PEP_STATUS_OK);
   1.176  
   1.177      cout << "sending vb@ulm.ccc.de to keyserver\n";
   1.178      PEP_STATUS send_key_status = send_key(session, "vb@ulm.ccc.de");
   1.179 -    cout << "send_key() exits with " << send_key_status << "\n";
   1.180 +    cout << "send_key() exits with " << status(send_key_status) << endl;
   1.181      assert(send_key_status == PEP_STATUS_OK);
   1.182  
   1.183      PEP_comm_type tcomm_type;
   1.184      PEP_STATUS tstatus = get_key_rating(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &tcomm_type);
   1.185 -    cout << "get_key_rating() exits with " << tstatus << "\n";
   1.186 +    cout << "get_key_rating() exits with " << tstatus << endl;
   1.187      assert(tstatus == PEP_STATUS_OK);
   1.188      assert(tcomm_type == PEP_ct_OpenPGP_unconfirmed);
   1.189