Test that blobs actually round trip data. I want to rewrite a thing.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4025 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-11-09 02:56:41 +00:00
parent d3d4b1a13c
commit 98a7753a55
2 changed files with 16 additions and 1 deletions

View File

@ -378,6 +378,7 @@ bool tf_ssb_db_blob_get(tf_ssb_t* ssb, const char* id, uint8_t** out_blob, size_
{
const uint8_t* blob = sqlite3_column_blob(statement, 0);
int size = sqlite3_column_bytes(statement, 0);
printf("bytes = %d\n", size);
if (out_blob)
{
*out_blob = tf_malloc(size + 1);

View File

@ -184,8 +184,13 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
tf_ssb_append_message(ssb0, message);
JS_FreeValue(context, message);
b = tf_ssb_db_blob_get(ssb0, blob_id, NULL, NULL);
uint8_t* b0;
size_t s0 = 0;
b = tf_ssb_db_blob_get(ssb0, blob_id, &b0, &s0);
assert(b);
assert(s0 == strlen(k_blob));
assert(memcmp(b0, k_blob, strlen(k_blob)) == 0);
tf_free(b0);
b = !tf_ssb_db_blob_get(ssb1, blob_id, NULL, NULL);
assert(b);
tf_ssb_server_open(ssb0, 12347);
@ -214,6 +219,15 @@ void tf_ssb_test_ssb(const tf_test_options_t* options)
uv_run(&loop, UV_RUN_ONCE);
}
uint8_t* b1;
size_t s1 = 0;
b = tf_ssb_db_blob_get(ssb1, blob_id, &b1, &s1);
assert(b);
printf("s1 = %zd sl = %zd\n", s1, strlen(k_blob));
assert(s1 == strlen(k_blob));
assert(memcmp(b1, k_blob, strlen(k_blob)) == 0);
tf_free(b1);
printf("Waiting for message to self.\n");
int count0 = 0;
int count1 = 0;