[test suite] added 'getset' versions of fko_ int/short wrapper functions
This commit is contained in:
parent
8f3ea42b3f
commit
bf9fa57ca8
@ -20,12 +20,24 @@
|
||||
static void display_ctx(fko_ctx_t ctx);
|
||||
static void test_loop(int new_ctx_flag, int destroy_ctx_flag);
|
||||
static void ctx_update(fko_ctx_t *ctx, int new_ctx_flag, int destroy_ctx_flag);
|
||||
static void spa_func_exec_int(fko_ctx_t *ctx, char *name,
|
||||
|
||||
static void spa_func_int(fko_ctx_t *ctx, char *name,
|
||||
int (*spa_func)(fko_ctx_t ctx, const int modifier), int min, int max,
|
||||
int final_val, int new_ctx_flag, int destroy_ctx_flag);
|
||||
static void spa_func_exec_short(fko_ctx_t *ctx, char *name,
|
||||
static void spa_func_getset_int(fko_ctx_t *ctx, char *set_name,
|
||||
int (*spa_set)(fko_ctx_t ctx, const int modifier),
|
||||
char *get_name, int (*spa_get)(fko_ctx_t ctx, int *val),
|
||||
int min, int max, int final_val, int new_ctx_flag, int destroy_ctx_flag);
|
||||
|
||||
static void spa_func_short(fko_ctx_t *ctx, char *name,
|
||||
int (*spa_func)(fko_ctx_t ctx, const short modifier), int min, int max,
|
||||
int final_val, int new_ctx_flag, int destroy_ctx_flag);
|
||||
static void spa_func_getset_short(fko_ctx_t *ctx, char *set_name,
|
||||
int (*spa_set)(fko_ctx_t ctx, const short modifier),
|
||||
char *get_name, int (*spa_get)(fko_ctx_t ctx, short *val),
|
||||
int min, int max, int final_val, int new_ctx_flag, int destroy_ctx_flag);
|
||||
|
||||
int spa_calls = 0;
|
||||
|
||||
int main(void) {
|
||||
int i;
|
||||
@ -40,6 +52,8 @@ int main(void) {
|
||||
for (i=-5; i < FKO_LAST_ERROR+5; i++)
|
||||
printf("libfko error (%d): %s\n", i, fko_errstr(i));
|
||||
|
||||
printf("\n[+] Total libfko function calls: %d\n\n", spa_calls);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -55,16 +69,18 @@ test_loop(int new_ctx_flag, int destroy_ctx_flag)
|
||||
ctx = NULL;
|
||||
printf("fko_new(): %s\n", fko_errstr(fko_new(&ctx)));
|
||||
|
||||
spa_func_exec_int(&ctx, "fko_set_spa_client_timeout",
|
||||
&fko_set_spa_client_timeout, -F_INT, F_INT, 10,
|
||||
spa_func_getset_int(&ctx, "fko_set_spa_client_timeout",
|
||||
&fko_set_spa_client_timeout, "fko_get_spa_client_timeout",
|
||||
&fko_get_spa_client_timeout, -F_INT, F_INT, 10,
|
||||
new_ctx_flag, destroy_ctx_flag);
|
||||
|
||||
spa_func_exec_short(&ctx, "fko_set_spa_message_type",
|
||||
&fko_set_spa_message_type, FKO_COMMAND_MSG-F_INT,
|
||||
spa_func_getset_short(&ctx, "fko_set_spa_message_type",
|
||||
&fko_set_spa_message_type, "fko_get_spa_message_type",
|
||||
&fko_get_spa_message_type, FKO_COMMAND_MSG-F_INT,
|
||||
FKO_LAST_MSG_TYPE+F_INT, FKO_ACCESS_MSG,
|
||||
new_ctx_flag, destroy_ctx_flag);
|
||||
|
||||
spa_func_exec_int(&ctx, "fko_set_timestamp",
|
||||
spa_func_int(&ctx, "fko_set_timestamp",
|
||||
&fko_set_spa_client_timeout, -F_INT, F_INT, 10,
|
||||
new_ctx_flag, destroy_ctx_flag);
|
||||
|
||||
@ -98,13 +114,14 @@ test_loop(int new_ctx_flag, int destroy_ctx_flag)
|
||||
}
|
||||
}
|
||||
|
||||
spa_func_exec_short(&ctx, "fko_set_spa_encryption_type",
|
||||
spa_func_short(&ctx, "fko_set_spa_encryption_type",
|
||||
&fko_set_spa_encryption_type, FKO_ENCRYPTION_INVALID_DATA-F_INT,
|
||||
FKO_LAST_ENCRYPTION_TYPE+F_INT, FKO_ENCRYPTION_RIJNDAEL,
|
||||
new_ctx_flag, destroy_ctx_flag);
|
||||
|
||||
spa_func_exec_int(&ctx, "fko_set_spa_encryption_mode",
|
||||
&fko_set_spa_encryption_mode, FKO_ENC_MODE_UNKNOWN-F_INT,
|
||||
spa_func_getset_int(&ctx, "fko_set_spa_encryption_mode",
|
||||
&fko_set_spa_encryption_mode, "fko_get_spa_encryption_mode",
|
||||
&fko_get_spa_encryption_mode, FKO_ENC_MODE_UNKNOWN-F_INT,
|
||||
FKO_LAST_ENC_MODE+F_INT, FKO_ENC_MODE_CBC,
|
||||
new_ctx_flag, destroy_ctx_flag);
|
||||
|
||||
@ -141,13 +158,15 @@ test_loop(int new_ctx_flag, int destroy_ctx_flag)
|
||||
}
|
||||
}
|
||||
|
||||
spa_func_exec_short(&ctx, "fko_set_spa_digest_type",
|
||||
&fko_set_spa_digest_type, FKO_DIGEST_INVALID_DATA-F_INT,
|
||||
spa_func_getset_short(&ctx, "fko_set_spa_digest_type",
|
||||
&fko_set_spa_digest_type, "fko_get_spa_digest_type",
|
||||
&fko_get_spa_digest_type, FKO_DIGEST_INVALID_DATA-F_INT,
|
||||
FKO_LAST_DIGEST_TYPE+F_INT, FKO_DEFAULT_DIGEST,
|
||||
new_ctx_flag, destroy_ctx_flag);
|
||||
|
||||
spa_func_exec_short(&ctx, "fko_set_spa_hmac_type",
|
||||
&fko_set_spa_hmac_type, FKO_HMAC_INVALID_DATA-F_INT,
|
||||
spa_func_getset_short(&ctx, "fko_set_spa_hmac_type",
|
||||
&fko_set_spa_hmac_type, "fko_get_spa_hmac_type",
|
||||
&fko_get_spa_hmac_type, FKO_HMAC_INVALID_DATA-F_INT,
|
||||
FKO_LAST_HMAC_MODE+F_INT, FKO_HMAC_SHA256,
|
||||
new_ctx_flag, destroy_ctx_flag);
|
||||
|
||||
@ -240,18 +259,45 @@ test_loop(int new_ctx_flag, int destroy_ctx_flag)
|
||||
static void ctx_update(fko_ctx_t *ctx, int new_ctx_flag, int destroy_ctx_flag)
|
||||
{
|
||||
if (destroy_ctx_flag == CTX_DESTROY) {
|
||||
fko_destroy(*ctx);
|
||||
printf("fko_destroy(): %s\n", fko_errstr(fko_destroy(*ctx)));
|
||||
*ctx = NULL;
|
||||
}
|
||||
if (new_ctx_flag == NEW_CTX) {
|
||||
fko_destroy(*ctx); /* always destroy before re-creating */
|
||||
/* always destroy before re-creating */
|
||||
printf("fko_destroy(): %s\n", fko_errstr(fko_destroy(*ctx)));
|
||||
*ctx = NULL;
|
||||
printf("fko_new(): %s\n", fko_errstr(fko_new(ctx)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void spa_func_exec_int(fko_ctx_t *ctx, char *name,
|
||||
static void spa_func_getset_int(fko_ctx_t *ctx, char *set_name,
|
||||
int (*spa_set)(fko_ctx_t ctx, const int modifier),
|
||||
char *get_name, int (*spa_get)(fko_ctx_t ctx, int *val),
|
||||
int min, int max, int final_val, int new_ctx_flag, int destroy_ctx_flag)
|
||||
{
|
||||
int get_val;
|
||||
int i, res;
|
||||
|
||||
printf("[+] calling libfko get/set: %s/%s\n", get_name, set_name);
|
||||
for (i=min; i <= max; i++) {
|
||||
get_val = 1234; /* meaningless default */
|
||||
printf("%s(%d): %s\n", set_name, i, fko_errstr((spa_set)(*ctx, i)));
|
||||
printf("%s(%d): %s (DUPE)\n", set_name, i, fko_errstr((spa_set)(*ctx, i)));
|
||||
res = (spa_get)(*ctx, &get_val);
|
||||
printf("%s(%d): %s\n", get_name, get_val, fko_errstr(res));
|
||||
|
||||
ctx_update(ctx, new_ctx_flag, destroy_ctx_flag);
|
||||
spa_calls += 3;
|
||||
}
|
||||
printf("%s(%d): %s (FINAL)\n", set_name, final_val,
|
||||
fko_errstr((spa_set)(*ctx, final_val)));
|
||||
|
||||
display_ctx(*ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
static void spa_func_int(fko_ctx_t *ctx, char *name,
|
||||
int (*spa_func)(fko_ctx_t ctx, const int modifier), int min, int max,
|
||||
int final_val, int new_ctx_flag, int destroy_ctx_flag)
|
||||
{
|
||||
@ -263,6 +309,7 @@ static void spa_func_exec_int(fko_ctx_t *ctx, char *name,
|
||||
printf("%s(%d): %s (DUPE)\n", name, i, fko_errstr((spa_func)(*ctx, i)));
|
||||
|
||||
ctx_update(ctx, new_ctx_flag, destroy_ctx_flag);
|
||||
spa_calls += 2;
|
||||
}
|
||||
printf("%s(%d): %s (FINAL)\n", name, final_val,
|
||||
fko_errstr((spa_func)(*ctx, final_val)));
|
||||
@ -270,7 +317,33 @@ static void spa_func_exec_int(fko_ctx_t *ctx, char *name,
|
||||
return;
|
||||
}
|
||||
|
||||
static void spa_func_exec_short(fko_ctx_t *ctx, char *name,
|
||||
static void spa_func_getset_short(fko_ctx_t *ctx, char *set_name,
|
||||
int (*spa_set)(fko_ctx_t ctx, const short modifier),
|
||||
char *get_name, int (*spa_get)(fko_ctx_t ctx, short *val),
|
||||
int min, int max, int final_val, int new_ctx_flag, int destroy_ctx_flag)
|
||||
{
|
||||
short get_val;
|
||||
int i, res;
|
||||
|
||||
printf("[+] calling libfko get/set: %s/%s\n", get_name, set_name);
|
||||
for (i=min; i <= max; i++) {
|
||||
get_val = 1234; /* meaningless default */
|
||||
printf("%s(%d): %s\n", set_name, i, fko_errstr((spa_set)(*ctx, i)));
|
||||
printf("%s(%d): %s (DUPE)\n", set_name, i, fko_errstr((spa_set)(*ctx, i)));
|
||||
res = (spa_get)(*ctx, &get_val);
|
||||
printf("%s(%d): %s\n", get_name, get_val, fko_errstr(res));
|
||||
|
||||
ctx_update(ctx, new_ctx_flag, destroy_ctx_flag);
|
||||
spa_calls += 3;
|
||||
}
|
||||
printf("%s(%d): %s (FINAL)\n", set_name, final_val,
|
||||
fko_errstr((spa_set)(*ctx, final_val)));
|
||||
|
||||
display_ctx(*ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
static void spa_func_short(fko_ctx_t *ctx, char *name,
|
||||
int (*spa_func)(fko_ctx_t ctx, const short modifier), int min, int max,
|
||||
int final_val, int new_ctx_flag, int destroy_ctx_flag)
|
||||
{
|
||||
@ -282,6 +355,7 @@ static void spa_func_exec_short(fko_ctx_t *ctx, char *name,
|
||||
printf("%s(%d): %s (DUPE)\n", name, i, fko_errstr((spa_func)(*ctx, i)));
|
||||
|
||||
ctx_update(ctx, new_ctx_flag, destroy_ctx_flag);
|
||||
spa_calls += 2;
|
||||
}
|
||||
printf("%s(%d): %s (FINAL)\n", name, final_val,
|
||||
fko_errstr((spa_func)(*ctx, final_val)));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user