You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, our unit/functional tests use if statements to check certain conditions after an operation has been completed. For example:
if ((ret=atclient_atkey_from_string(&atkey, atkeystr)) !=0) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient_atkey_from_string failed\n");
goto exit;
}
if (atkey.metadata.iscached!= true) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey.metadata.iscached is not 1\n");
goto exit;
}
if (atkey.metadata.ispublic!= true) {
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atkey.metadata.ispublic is not 1, it is %d\n",
atkey.metadata.ispublic);
goto exit;
}
Proposed Implementation:
// function implementationstaticintassert_equals_bool(constchar*name, constboolactual, constboolexpected) [
if(actual==expected) {
atlogger_log(TAG, INFO, "%s is %d as expected.\n", name, actual);
return0;
} else {
atlogger_log(TAG, ERROR, "%s id %d when it was expected to be %d.\n", name, actual, expected);
return1;
}
}
// example usageif((ret=assert_equals_bool(atkey.metadata.iscached, true)) !=0) {
exit(1);
}
We would need an atassert library to hold our assert functions. The headers would look something like this:
Not only would we have to use the assertion library in our unit/functional tests, but we should also use them in the "Arguments Validation" of each function.
For example:
This code currently:
if (atclient==NULL) {
ret=1;
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient is NULL\n");
goto exit;
}
if (!atclient_is_atsign_initialized(atclient)) {
ret=1;
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atserver_connection is not connected\n");
goto exit;
}
would transform to this:
if ((ret=assert_non_null(atclient)) !=0) {
ret=1;
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atclient is NULL\n");
goto exit;
}
if ((ret=assert_true(atclient_is_atserver_connection_started(atclient)) !=0) {
ret=1;
atlogger_log(TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "atserver_connection is not connected\n");
goto exit;
}
Some refactors:
Rename to test_aes_ctr_decrypt.c
Rename to test_aes_ctr.c
Rename to test_rsa_decrypt.c
Rename to test_rsa_encrypt.c
Rename to test_rsa_private_key_populate.c
Rename to test_rsa_public_key_populate.c
Rename to test_rsa_sign.c
Rename to test_rsa_verify.c
Rename to test_string_utils.c
Todos:
Create a atassert package which contains our assertion function
atassert.h
atassert.c
Refactor atclient unit tests to use assertion library
Refactor atchops unit tests to use assertion library
Refactor functional tests to use assertion library
Todos Part 2:
Use this assertion library in our arguments validation
The text was updated successfully, but these errors were encountered:
JeremyTubongbanua
changed the title
at_c: use assertion library instead of if statements in our unit tests
at_c: use assertion library instead of if statements in our unit tests and when validating arguments of functions
Jul 22, 2024
JeremyTubongbanua
changed the title
at_c: use assertion library instead of if statements in our unit tests and when validating arguments of functions
at_c: use assertion library in tests
Jul 30, 2024
JeremyTubongbanua
changed the title
at_c: use assertion library in tests
at_c: use assertion library in tests and arguments validation
Jul 30, 2024
Currently, our unit/functional tests use if statements to check certain conditions after an operation has been completed. For example:
Proposed Implementation:
We would need an
atassert
library to hold our assert functions. The headers would look something like this:Not only would we have to use the assertion library in our unit/functional tests, but we should also use them in the "Arguments Validation" of each function.
For example:
This code currently:
would transform to this:
Some refactors:
test_aes_ctr_decrypt.c
test_aes_ctr.c
test_rsa_decrypt.c
test_rsa_encrypt.c
test_rsa_private_key_populate.c
test_rsa_public_key_populate.c
test_rsa_sign.c
test_rsa_verify.c
test_string_utils.c
Todos:
atassert
package which contains our assertion functionTodos Part 2:
The text was updated successfully, but these errors were encountered: