From 98a7753a55758ece4e89fac4ba1dd1ca442379ad Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 9 Nov 2022 02:56:41 +0000 Subject: [PATCH] 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 --- src/ssb.db.c | 1 + src/ssb.tests.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ssb.db.c b/src/ssb.db.c index b8961fa4..a483934c 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -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); diff --git a/src/ssb.tests.c b/src/ssb.tests.c index 98cfad6b..62624309 100644 --- a/src/ssb.tests.c +++ b/src/ssb.tests.c @@ -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;