test/test_util.cc
branchENGINE-209
changeset 1812 925ad845e3ec
parent 1656 ea7d229bed3f
child 2282 eed4a7047201
     1.1 --- a/test/test_util.cc	Wed May 31 17:47:42 2017 +0200
     1.2 +++ b/test/test_util.cc	Thu Jun 01 19:52:13 2017 +0200
     1.3 @@ -1,4 +1,6 @@
     1.4  #include "pEpEngine_test.h"
     1.5 +#include "pEpEngine.h"
     1.6 +#include "message_api.h"
     1.7  #include <fstream>
     1.8  #include <sstream>
     1.9  #include <stdexcept>
    1.10 @@ -15,3 +17,237 @@
    1.11  	sstr << input.rdbuf();
    1.12  	return sstr.str();
    1.13  }
    1.14 +
    1.15 +const char* tl_status_string(PEP_STATUS status) {
    1.16 +    switch (status) {
    1.17 +        case PEP_STATUS_OK:
    1.18 +            return "PEP_STATUS_OK";
    1.19 +        case PEP_INIT_CANNOT_LOAD_GPGME:
    1.20 +            return "PEP_INIT_CANNOT_LOAD_GPGME";
    1.21 +        case PEP_INIT_GPGME_INIT_FAILED:
    1.22 +            return "PEP_INIT_GPGME_INIT_FAILED";
    1.23 +        case PEP_INIT_NO_GPG_HOME:
    1.24 +            return "PEP_INIT_NO_GPG_HOME";
    1.25 +        case PEP_INIT_NETPGP_INIT_FAILED:
    1.26 +            return "PEP_INIT_NETPGP_INIT_FAILED";
    1.27 +        case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
    1.28 +            return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
    1.29 +        case PEP_INIT_CANNOT_OPEN_DB:
    1.30 +            return "PEP_INIT_CANNOT_OPEN_DB";
    1.31 +        case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
    1.32 +            return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
    1.33 +        case PEP_KEY_NOT_FOUND:
    1.34 +            return "PEP_KEY_NOT_FOUND";
    1.35 +        case PEP_KEY_HAS_AMBIG_NAME:
    1.36 +            return "PEP_KEY_HAS_AMBIG_NAME";
    1.37 +        case PEP_GET_KEY_FAILED:
    1.38 +            return "PEP_GET_KEY_FAILED";
    1.39 +        case PEP_CANNOT_EXPORT_KEY:
    1.40 +            return "PEP_CANNOT_EXPORT_KEY";
    1.41 +        case PEP_CANNOT_EDIT_KEY:
    1.42 +            return "PEP_CANNOT_EDIT_KEY";
    1.43 +        case PEP_CANNOT_FIND_IDENTITY:
    1.44 +            return "PEP_CANNOT_FIND_IDENTITY";
    1.45 +        case PEP_CANNOT_SET_PERSON:
    1.46 +            return "PEP_CANNOT_SET_PERSON";
    1.47 +        case PEP_CANNOT_SET_PGP_KEYPAIR:
    1.48 +            return "PEP_CANNOT_SET_PGP_KEYPAIR";
    1.49 +        case PEP_CANNOT_SET_IDENTITY:
    1.50 +            return "PEP_CANNOT_SET_IDENTITY";
    1.51 +        case PEP_CANNOT_SET_TRUST:
    1.52 +            return "PEP_CANNOT_SET_TRUST";
    1.53 +        case PEP_KEY_BLACKLISTED:
    1.54 +            return "PEP_KEY_BLACKLISTED";
    1.55 +        case PEP_UNENCRYPTED:
    1.56 +            return "PEP_UNENCRYPTED";
    1.57 +        case PEP_VERIFIED:
    1.58 +            return "PEP_VERIFIED";
    1.59 +        case PEP_DECRYPTED:
    1.60 +            return "PEP_DECRYPTED";
    1.61 +        case PEP_DECRYPTED_AND_VERIFIED:
    1.62 +            return "PEP_DECRYPTED_AND_VERIFIED";
    1.63 +        case PEP_DECRYPT_WRONG_FORMAT:
    1.64 +            return "PEP_DECRYPT_WRONG_FORMAT";
    1.65 +        case PEP_DECRYPT_NO_KEY:
    1.66 +            return "PEP_DECRYPT_NO_KEY";
    1.67 +        case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
    1.68 +            return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
    1.69 +        case PEP_VERIFY_NO_KEY:
    1.70 +            return "PEP_VERIFY_NO_KEY";
    1.71 +        case PEP_VERIFIED_AND_TRUSTED:
    1.72 +            return "PEP_VERIFIED_AND_TRUSTED";
    1.73 +        case PEP_CANNOT_DECRYPT_UNKNOWN:
    1.74 +            return "PEP_CANNOT_DECRYPT_UNKNOWN";
    1.75 +        case PEP_TRUSTWORD_NOT_FOUND:
    1.76 +            return "PEP_TRUSTWORD_NOT_FOUND";
    1.77 +        case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
    1.78 +            return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
    1.79 +        case PEP_CANNOT_CREATE_KEY:
    1.80 +            return "PEP_CANNOT_CREATE_KEY";
    1.81 +        case PEP_CANNOT_SEND_KEY:
    1.82 +            return "PEP_CANNOT_SEND_KEY";
    1.83 +        case PEP_PHRASE_NOT_FOUND:
    1.84 +            return "PEP_PHRASE_NOT_FOUND";
    1.85 +        case PEP_SEND_FUNCTION_NOT_REGISTERED:
    1.86 +            return "PEP_SEND_FUNCTION_NOT_REGISTERED";
    1.87 +        case PEP_CONTRAINTS_VIOLATED:
    1.88 +            return "PEP_CONTRAINTS_VIOLATED";
    1.89 +        case PEP_CANNOT_ENCODE:
    1.90 +            return "PEP_CANNOT_ENCODE";
    1.91 +        case PEP_SYNC_NO_NOTIFY_CALLBACK:
    1.92 +            return "PEP_SYNC_NO_NOTIFY_CALLBACK";
    1.93 +        case PEP_SYNC_ILLEGAL_MESSAGE:
    1.94 +            return "PEP_SYNC_ILLEGAL_MESSAGE";
    1.95 +        case PEP_SYNC_NO_INJECT_CALLBACK:
    1.96 +            return "PEP_SYNC_NO_INJECT_CALLBACK";
    1.97 +        case PEP_SEQUENCE_VIOLATED:
    1.98 +            return "PEP_SEQUENCE_VIOLATED";
    1.99 +        case PEP_CANNOT_INCREASE_SEQUENCE:
   1.100 +            return "PEP_CANNOT_INCREASE_SEQUENCE";
   1.101 +        case PEP_CANNOT_SET_SEQUENCE_VALUE:
   1.102 +            return "PEP_CANNOT_SET_SEQUENCE_VALUE";
   1.103 +        case PEP_OWN_SEQUENCE:
   1.104 +            return "PEP_OWN_SEQUENCE";
   1.105 +        case PEP_SYNC_STATEMACHINE_ERROR:
   1.106 +            return "PEP_SYNC_STATEMACHINE_ERROR";
   1.107 +        case PEP_SYNC_NO_TRUST:
   1.108 +            return "PEP_SYNC_NO_TRUST";
   1.109 +        case PEP_STATEMACHINE_INVALID_STATE:
   1.110 +            return "PEP_STATEMACHINE_INVALID_STATE";
   1.111 +        case PEP_STATEMACHINE_INVALID_EVENT:
   1.112 +            return "PEP_STATEMACHINE_INVALID_EVENT";
   1.113 +        case PEP_STATEMACHINE_INVALID_CONDITION:
   1.114 +            return "PEP_STATEMACHINE_INVALID_CONDITION";
   1.115 +        case PEP_STATEMACHINE_INVALID_ACTION:
   1.116 +            return "PEP_STATEMACHINE_INVALID_ACTION";
   1.117 +        case PEP_STATEMACHINE_INHIBITED_EVENT:
   1.118 +            return "PEP_STATEMACHINE_INHIBITED_EVENT";
   1.119 +        case PEP_COMMIT_FAILED:
   1.120 +            return "PEP_COMMIT_FAILED";
   1.121 +        case PEP_MESSAGE_CONSUME:
   1.122 +            return "PEP_MESSAGE_CONSUME";
   1.123 +        case PEP_MESSAGE_IGNORE:
   1.124 +            return "PEP_MESSAGE_IGNORE";
   1.125 +        case PEP_RECORD_NOT_FOUND:
   1.126 +            return "PEP_RECORD_NOT_FOUND";
   1.127 +        case PEP_CANNOT_CREATE_TEMP_FILE:
   1.128 +            return "PEP_CANNOT_CREATE_TEMP_FILE";
   1.129 +        case PEP_ILLEGAL_VALUE:
   1.130 +            return "PEP_ILLEGAL_VALUE";
   1.131 +        case PEP_BUFFER_TOO_SMALL:
   1.132 +            return "PEP_BUFFER_TOO_SMALL";
   1.133 +        case PEP_OUT_OF_MEMORY:
   1.134 +            return "PEP_OUT_OF_MEMORY";
   1.135 +        case PEP_UNKNOWN_ERROR:
   1.136 +            return "PEP_UNKNOWN_ERROR";
   1.137 +        default:
   1.138 +            return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
   1.139 +    }
   1.140 +}
   1.141 +const char* tl_rating_string(PEP_rating rating) {
   1.142 +    switch (rating) {
   1.143 +        case PEP_rating_undefined:
   1.144 +            return "PEP_rating_undefined";
   1.145 +        case PEP_rating_cannot_decrypt:
   1.146 +            return "PEP_rating_cannot_decrypt";
   1.147 +        case PEP_rating_have_no_key:
   1.148 +            return "PEP_rating_have_no_key";
   1.149 +        case PEP_rating_unencrypted:
   1.150 +            return "PEP_rating_unencrypted";
   1.151 +        case PEP_rating_unencrypted_for_some:
   1.152 +            return "PEP_rating_unencrypted_for_some";
   1.153 +        case PEP_rating_unreliable:
   1.154 +            return "PEP_rating_unreliable";
   1.155 +        case PEP_rating_reliable:
   1.156 +            return "PEP_rating_reliable";
   1.157 +        case PEP_rating_trusted:
   1.158 +            return "PEP_rating_trusted";
   1.159 +        case PEP_rating_trusted_and_anonymized:
   1.160 +            return "PEP_rating_trusted_and_anonymized";
   1.161 +        case PEP_rating_fully_anonymous:
   1.162 +            return "PEP_rating_fully_anonymous";
   1.163 +        case PEP_rating_mistrust:
   1.164 +            return "PEP_rating_mistrust";
   1.165 +        case PEP_rating_b0rken:
   1.166 +            return "PEP_rating_b0rken";
   1.167 +        case PEP_rating_under_attack:
   1.168 +            return "PEP_rating_under_attack";
   1.169 +        default:
   1.170 +            return "PEP_rating_OMGWTFBBQ - in other words, INVALID RATING VALUE!!!\n\nSomething bad is going on here, or a new rating value has been added to the enum and not the test function.";
   1.171 +    }
   1.172 +}
   1.173 +
   1.174 +const char* tl_ct_string(PEP_comm_type ct) {
   1.175 +    switch (ct) {
   1.176 +        case PEP_ct_unknown:
   1.177 +            return "PEP_ct_unknown";
   1.178 +        case PEP_ct_no_encryption:
   1.179 +            return "PEP_ct_no_encryption";
   1.180 +        case PEP_ct_no_encrypted_channel:
   1.181 +            return "PEP_ct_no_encrypted_channel";
   1.182 +        case PEP_ct_key_not_found:
   1.183 +            return "PEP_ct_key_not_found";
   1.184 +        case PEP_ct_key_expired:
   1.185 +            return "PEP_ct_key_expired";
   1.186 +        case PEP_ct_key_revoked:
   1.187 +            return "PEP_ct_key_revoked";
   1.188 +        case PEP_ct_key_b0rken:
   1.189 +            return "PEP_ct_key_b0rken";
   1.190 +        case PEP_ct_my_key_not_included:
   1.191 +            return "PEP_ct_my_key_not_included";
   1.192 +        case PEP_ct_security_by_obscurity:
   1.193 +            return "PEP_ct_security_by_obscurity";
   1.194 +        case PEP_ct_b0rken_crypto:
   1.195 +            return "PEP_ct_b0rken_crypto";
   1.196 +        case PEP_ct_key_too_short:
   1.197 +            return "PEP_ct_key_too_short";
   1.198 +        case PEP_ct_compromized:
   1.199 +            return "PEP_ct_compromized";
   1.200 +        case PEP_ct_mistrusted:
   1.201 +            return "PEP_ct_mistrusted";
   1.202 +        case PEP_ct_unconfirmed_encryption:
   1.203 +            return "PEP_ct_unconfirmed_encryption";
   1.204 +        case PEP_ct_OpenPGP_weak_unconfirmed:
   1.205 +            return "PEP_ct_OpenPGP_weak_unconfirmed";
   1.206 +        case PEP_ct_to_be_checked:
   1.207 +            return "PEP_ct_to_be_checked";
   1.208 +        case PEP_ct_SMIME_unconfirmed:
   1.209 +            return "PEP_ct_SMIME_unconfirmed";
   1.210 +        case PEP_ct_CMS_unconfirmed:
   1.211 +            return "PEP_ct_CMS_unconfirmed";
   1.212 +        case PEP_ct_strong_but_unconfirmed:
   1.213 +            return "PEP_ct_strong_but_unconfirmed";
   1.214 +        case PEP_ct_OpenPGP_unconfirmed:
   1.215 +            return "PEP_ct_OpenPGP_unconfirmed";
   1.216 +        case PEP_ct_OTR_unconfirmed:
   1.217 +            return "PEP_ct_OTR_unconfirmed";
   1.218 +        case PEP_ct_unconfirmed_enc_anon:
   1.219 +            return "PEP_ct_unconfirmed_enc_anon";
   1.220 +        case PEP_ct_pEp_unconfirmed:
   1.221 +            return "PEP_ct_pEp_unconfirmed";
   1.222 +        case PEP_ct_confirmed:
   1.223 +            return "PEP_ct_pEp_confirmed";
   1.224 +        case PEP_ct_confirmed_encryption:
   1.225 +            return "PEP_ct_confirmed_encryption";
   1.226 +        case PEP_ct_OpenPGP_weak:
   1.227 +            return "PEP_ct_OpenPGP_weak";
   1.228 +        case PEP_ct_to_be_checked_confirmed:
   1.229 +            return "PEP_ct_to_be_checked_confirmed";
   1.230 +        case PEP_ct_SMIME:
   1.231 +            return "PEP_ct_SMIME";
   1.232 +        case PEP_ct_CMS:
   1.233 +            return "PEP_ct_CMS";
   1.234 +        case PEP_ct_strong_encryption:
   1.235 +            return "PEP_ct_strong_encryption";
   1.236 +        case PEP_ct_OpenPGP:
   1.237 +            return "PEP_ct_OpenPGP";
   1.238 +        case PEP_ct_OTR:
   1.239 +            return "PEP_ct_OTR";
   1.240 +        case PEP_ct_confirmed_enc_anon:
   1.241 +            return "PEP_ct_confirmed_enc_anon";
   1.242 +        case PEP_ct_pEp:
   1.243 +            return "PEP_ct_pEp";
   1.244 +        default:
   1.245 +            return "PEP_ct_OMGWTFBBQ\n\nIn other words, comm type is invalid. Either something's corrupt or a new ct value has been added to the enum but not to the test function.";
   1.246 +    }
   1.247 +}