feat(module manager): API new with file

This commit is contained in:
yangwei
2024-09-27 19:09:50 +08:00
parent 7aeb5949ee
commit 849df6b9cc
4 changed files with 84 additions and 85 deletions

View File

@@ -8,16 +8,6 @@
/***********************************
* TEST MODUEL MANAGER INTERNAL API *
***********************************/
TEST(module_manager_internal, toml_parse_filepath_null) {
toml_table_t *conf = toml_parse_file_path("");
EXPECT_TRUE(conf==NULL);
}
TEST(module_manager_internal, toml_parse_filepath_dev_null) {
toml_table_t *conf = toml_parse_file_path("/dev/null");
EXPECT_TRUE(conf!=NULL);
toml_free(conf);
}
extern "C" struct stellar_module *gtest_mock_init(struct stellar_module_manager *mod_mgr){return NULL;}
extern "C" void gtest_mock_exit(struct stellar_module_manager *mod_mgr, struct stellar_module *mod){}
@@ -29,11 +19,12 @@ const char *gtest_mock_spec_toml =
TEST(module_manager_internal, module_specs_load) {
toml_table_t *conf = toml_parse((char*)gtest_mock_spec_toml, NULL, 0);
EXPECT_TRUE(conf!=NULL);
FILE *fp = fmemopen((void *)gtest_mock_spec_toml, strlen(gtest_mock_spec_toml), "r");
EXPECT_TRUE(fp!=NULL);
struct module_spec_load *specs=NULL;
int mod_num=module_specs_load(conf, &specs);
int mod_num=module_specs_load(fp, &specs);
fclose(fp);
EXPECT_EQ(mod_num, 1);
EXPECT_EQ(specs[0].on_init_cb, gtest_mock_init);
@@ -44,18 +35,18 @@ TEST(module_manager_internal, module_specs_load) {
if(specs->init_cb_name)free(specs->init_cb_name);
if(specs->exit_cb_name)free(specs->exit_cb_name);
free(specs);
toml_free(conf);
}
TEST(module_manager_internal, stellar_module_manager_new_with_toml) {
struct mq_schema *mq_schema=NULL;
toml_table_t *conf = toml_parse((char*)gtest_mock_spec_toml, NULL, 0);
EXPECT_TRUE(conf!=NULL);
struct stellar_module_manager *mod_mgr=stellar_module_manager_new_with_toml(conf, 10, mq_schema);
FILE *fp = fmemopen((void *)gtest_mock_spec_toml, strlen(gtest_mock_spec_toml), "r");
EXPECT_TRUE(fp!=NULL);
struct stellar_module_manager *mod_mgr=stellar_module_manager_new_with_file(fp, 10, mq_schema);
fclose(fp);
EXPECT_TRUE(mod_mgr!=NULL);
EXPECT_TRUE(stellar_module_manager_get_module(mod_mgr, "test")==NULL);
EXPECT_EQ(stellar_module_manager_get_max_thread_num(mod_mgr), 10);
@@ -65,7 +56,6 @@ TEST(module_manager_internal, stellar_module_manager_new_with_toml) {
EXPECT_TRUE(stellar_module_manager_get_mq_runtime(mod_mgr)==NULL);
stellar_module_manager_free(mod_mgr);
toml_free(conf);
}
@@ -178,10 +168,12 @@ const char *gtest_module_spec_toml =
TEST(module_manager, basic_module) {
struct mq_schema *mq_schema=(struct mq_schema *)1;
toml_table_t *conf = toml_parse((char*)gtest_module_spec_toml, NULL, 0);
EXPECT_TRUE(conf!=NULL);
struct stellar_module_manager *mod_mgr=stellar_module_manager_new_with_toml(conf, 10, mq_schema);
FILE *fp = fmemopen((void *)gtest_module_spec_toml, strlen(gtest_module_spec_toml), "r");
EXPECT_TRUE(fp!=NULL);
struct stellar_module_manager *mod_mgr=stellar_module_manager_new_with_file(fp, 10, mq_schema);
fclose(fp);
EXPECT_TRUE(mod_mgr!=NULL);
EXPECT_TRUE(stellar_module_manager_get_module(mod_mgr, "gtest")!=NULL);
@@ -196,7 +188,6 @@ TEST(module_manager, basic_module) {
EXPECT_EQ((long)stellar_module_manager_get_mq_runtime(mod_mgr), 2);
stellar_module_manager_free(mod_mgr);
toml_free(conf);
}