From 1efecaef1f867cb218366e2b4ab4b901fdd2835f Mon Sep 17 00:00:00 2001 From: tanaka takashi Date: Sat, 4 Jul 2026 14:54:45 +0900 Subject: 途中経過コミット MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/storage_test.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/storage_test.c') diff --git a/tests/storage_test.c b/tests/storage_test.c index 0e93ad9..0343f46 100644 --- a/tests/storage_test.c +++ b/tests/storage_test.c @@ -98,6 +98,40 @@ main(void) input.content = duplicate_string("second"); CHECK(tiny_store_write(store, &input, &second_message) == TINY_STORE_OK); CHECK(strcmp(first.message_id, second_message.message_id) < 0); + { + tiny_message_patch_t patch; + tiny_message_t updated; + tiny_metadata_t metadata = first.metadata; + tiny_sys_io_counters_t counters; + bool changed = false; + metadata.importance = 80; + memset(&patch, 0, sizeof(patch)); + patch.metadata = &metadata; + patch.metadata_mask = TINY_METADATA_IMPORTANCE; + patch.expected_revision = 1; + patch.has_expected_revision = true; + tiny_message_init(&updated); + tiny_sys_io_counters_reset(); + CHECK(tiny_store_update(store, first.message_id, &patch, &updated, &changed) == TINY_STORE_OK); + tiny_sys_io_counters_get(&counters); + CHECK(changed && updated.revision == 2 && updated.metadata.importance == 80); + CHECK(counters.flush_calls == 1 && counters.write_calls == 2); + CHECK(counters.write_bytes < 8192); + tiny_message_free(&updated); + + patch.expected_revision = 2; + changed = true; + tiny_sys_io_counters_reset(); + CHECK(tiny_store_update(store, first.message_id, &patch, &updated, &changed) == TINY_STORE_OK); + tiny_sys_io_counters_get(&counters); + CHECK(!changed && counters.write_bytes == 0 && counters.write_calls == 0 + && counters.flush_calls == 0); + tiny_message_free(&updated); + + patch.expected_revision = 1; + CHECK(tiny_store_update(store, first.message_id, &patch, &updated, &changed) + == TINY_STORE_CONFLICT); + } tiny_message_free(&input); tiny_message_free(&first); tiny_message_free(&second_message); @@ -106,6 +140,8 @@ main(void) CHECK(tiny_store_open(&store, directory) == TINY_STORE_OK); CHECK(tiny_store_entry_count(store) == 2); + CHECK(tiny_store_entry(store, 0)->message.revision == 2); + CHECK(tiny_store_entry(store, 0)->message.metadata.importance == 80); { size_t failure_index; bool built = false; -- cgit v1.2.3