MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / test_cachedb_api

Function test_cachedb_api

cachedb/test/test_cachedb.c:595–657  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593}
594
595static void test_cachedb_api(const char *cachedb_name, const char *group1,
596 const char *group2)
597{
598 str key = str_init("foo"),
599 val = str_init("bar");
600 str cdb_str, cdb_gr1, str_gr1, str_gr2 = {0,0};
601 cachedb_engine *cde;
602 cachedb_con *con1 = NULL, *con2 = NULL;
603
604 init_str(&cdb_str, cachedb_name);
605
606 if (group1) {
607 cdb_gr1.len = strlen(cachedb_name) + strlen(group1) + 1;
608 cdb_gr1.s = pkg_malloc(cdb_gr1.len);
609 snprintf(cdb_gr1.s, cdb_gr1.len+1, "%s:%s", cachedb_name, group1);
610
611 init_str(&str_gr1, group1);
612 init_str(&str_gr2, group2);
613 } else
614 init_str(&cdb_gr1, cachedb_name);
615
616 /* high-level cachedb API (called by script, MI) */
617
618 /* TODO: write tests for signed integers (may be broken in current Mongo) */
619
620 ok(cachedb_store(&cdb_gr1, &key, &val, 0) == 1, "store key");
621
622 memset(&val, 0, sizeof val);
623 ok(cachedb_fetch(&cdb_gr1, &key, &val) == 1, "fetch key");
624 cmp_mem(val.s, "bar", 3, "check fetched value");
625
626 ok(cachedb_remove(&cdb_gr1, &key) == 1, "remove key");
627
628 ok(cachedb_fetch(&cdb_gr1, &key, &val) == -2, "fetch non-existing key");
629
630 /* low-level cachedb API (called by core and modules) */
631
632 cde = lookup_cachedb(&cdb_str);
633 if (!ok(cde != NULL, "have cachedb engine"))
634 return;
635
636 if (group1) {
637 con1 = cachedb_get_connection(cde, &str_gr1);
638 if (!ok(con1 != NULL, "engine has con"))
639 return;
640
641 con2 = cachedb_get_connection(cde, &str_gr2);
642 if (!ok(con2 != NULL, "engine has con"))
643 return;
644 } else {
645 con1 = cachedb_get_connection(cde, NULL);
646 if (!ok(con1 != NULL, "engine has con"))
647 return;
648 }
649
650 if (CACHEDB_CAPABILITY(&cde->cdb_func, CACHEDB_CAP_COL_ORIENTED))
651 ok(test_column_ops(&cde->cdb_func, con1, con2, cachedb_name),
652 "column-oriented tests");

Callers 1

test_cachedb_backendsFunction · 0.85

Calls 8

init_strFunction · 0.85
cachedb_storeFunction · 0.85
cachedb_fetchFunction · 0.85
cachedb_removeFunction · 0.85
lookup_cachedbFunction · 0.85
cachedb_get_connectionFunction · 0.85
test_column_opsFunction · 0.85
test_map_opsFunction · 0.85

Tested by

no test coverage detected