test: add KVMGR_KEY_INT coverage to kvmgr_capture_keys tests
Adds test_capture_keys_int_kvmgr() to verify integer-keyed kvmgr path. Tests that kvmgr_capture_keys() correctly formats integer keys as decimal strings via snprintf (PRId64), and validates key_len == strlen(key) + 1. All 4 kvmgr_capture tests pass.
This commit is contained in:
parent
eaf1801d6d
commit
813a5a3359
1 changed files with 60 additions and 0 deletions
|
|
@ -171,6 +171,65 @@ static void test_capture_keys_are_deep_copies(void)
|
|||
free(keys);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* test 4: capture from an integer-keyed kvmgr with 3 entries */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
static void test_capture_keys_int_kvmgr(void)
|
||||
{
|
||||
kvmgr_params_t params = { .key_type = KVMGR_KEY_INT,
|
||||
.nslots = 8,
|
||||
.delta = 4,
|
||||
.datakiller = NULL };
|
||||
var kvmgr = makeInstance(&xkvmgr_type, ¶ms);
|
||||
TEST_ASSERT_NOT_NULL(kvmgr);
|
||||
|
||||
/* Add 3 integer-keyed entries; the integer keys are jobids.
|
||||
For integer-keyed kvmgrs, key_add expects a (void*)(long)intval. */
|
||||
int64_t jobid_1001 = 1001;
|
||||
int64_t jobid_1002 = 1002;
|
||||
int64_t jobid_1003 = 1003;
|
||||
|
||||
int idx_1001 =
|
||||
key_add(kvmgr, (void*)(long)jobid_1001, (void*)"data_1001");
|
||||
int idx_1002 =
|
||||
key_add(kvmgr, (void*)(long)jobid_1002, (void*)"data_1002");
|
||||
int idx_1003 =
|
||||
key_add(kvmgr, (void*)(long)jobid_1003, (void*)"data_1003");
|
||||
TEST_ASSERT_TRUE(idx_1001 >= 0);
|
||||
TEST_ASSERT_TRUE(idx_1002 >= 0);
|
||||
TEST_ASSERT_TRUE(idx_1003 >= 0);
|
||||
|
||||
slot_key_t* keys = NULL;
|
||||
size_t n_keys = 0;
|
||||
int rc = kvmgr_capture_keys(kvmgr, &keys, &n_keys);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT(0, rc);
|
||||
TEST_ASSERT_EQUAL_size_t(3, n_keys);
|
||||
TEST_ASSERT_NOT_NULL(keys);
|
||||
|
||||
/* Every inserted integer key must appear as a decimal string with the
|
||||
correct index */
|
||||
int found_idx = -1;
|
||||
TEST_ASSERT_TRUE(find_key_in_captured(keys, n_keys, "1001", &found_idx));
|
||||
TEST_ASSERT_EQUAL_INT(idx_1001, found_idx);
|
||||
|
||||
TEST_ASSERT_TRUE(find_key_in_captured(keys, n_keys, "1002", &found_idx));
|
||||
TEST_ASSERT_EQUAL_INT(idx_1002, found_idx);
|
||||
|
||||
TEST_ASSERT_TRUE(find_key_in_captured(keys, n_keys, "1003", &found_idx));
|
||||
TEST_ASSERT_EQUAL_INT(idx_1003, found_idx);
|
||||
|
||||
/* key_len must equal strlen(key)+1 */
|
||||
size_t i;
|
||||
for (i = 0; i < n_keys; i++) {
|
||||
TEST_ASSERT_EQUAL_size_t(strlen(keys[i].key) + 1, keys[i].key_len);
|
||||
}
|
||||
|
||||
free(keys);
|
||||
destroy(kvmgr);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* entry point called from test.c */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
|
@ -181,4 +240,5 @@ void test_kvmgr_capture(void)
|
|||
RUN_TEST(test_capture_keys_string_kvmgr);
|
||||
RUN_TEST(test_capture_keys_empty_kvmgr);
|
||||
RUN_TEST(test_capture_keys_are_deep_copies);
|
||||
RUN_TEST(test_capture_keys_int_kvmgr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue