summaryrefslogtreecommitdiff
path: root/infra/module_manager/test
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-09-29 14:18:20 +0800
committeryangwei <[email protected]>2024-09-29 14:18:20 +0800
commit2ea8d96c5cd4a12a0b1f3cfb5a0fdc4bdaf40ec5 (patch)
tree294d7faf4344b4fe0ffca8d8b9ebb1d3dc050198 /infra/module_manager/test
parentdc4805fbb880714331876b6c3795037ddd95a99e (diff)
✨ feat(module manager internal API): remove new_with_file
Diffstat (limited to 'infra/module_manager/test')
-rw-r--r--infra/module_manager/test/gtest_module_manager_main.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/infra/module_manager/test/gtest_module_manager_main.cpp b/infra/module_manager/test/gtest_module_manager_main.cpp
index 9ee7bef..40a2f21 100644
--- a/infra/module_manager/test/gtest_module_manager_main.cpp
+++ b/infra/module_manager/test/gtest_module_manager_main.cpp
@@ -5,6 +5,10 @@
#include "module_manager/module_manager_interna.h"
+#include <unistd.h>
+#include <stdlib.h>
+
+
/***********************************
* TEST MODUEL MANAGER INTERNAL API *
***********************************/
@@ -20,22 +24,27 @@ const char *gtest_mock_spec_toml =
TEST(module_manager_internal, stellar_module_manager_new_with_toml) {
struct mq_schema *mq_schema=NULL;
- 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);
+ char toml_template[] = "./stellar.toml.XXXXXX";
+ int fd = mkstemp(toml_template);
+ EXPECT_TRUE(fd>=0);
+ write(fd, gtest_mock_spec_toml, strlen(gtest_mock_spec_toml));
+ close(fd);
+
+ struct stellar_module_manager *mod_mgr=stellar_module_manager_new(toml_template, 10, mq_schema);
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);
EXPECT_EQ(stellar_module_manager_get_mq_schema(mod_mgr), mq_schema);
+ EXPECT_STREQ(stellar_module_manager_get_toml_path(mod_mgr), toml_template);
EXPECT_EQ(stellar_module_manager_get_thread_id(mod_mgr), -1);// no thread registered
EXPECT_TRUE(stellar_module_manager_get_mq_runtime(mod_mgr)==NULL);
stellar_module_manager_free(mod_mgr);
+ unlink(toml_template);
}
/***********************************
@@ -148,18 +157,21 @@ TEST(module_manager, basic_module) {
struct mq_schema *mq_schema=(struct mq_schema *)1;
- FILE *fp = fmemopen((void *)gtest_module_spec_toml, strlen(gtest_module_spec_toml), "r");
- EXPECT_TRUE(fp!=NULL);
+ char toml_template[] = "./stellar.toml.XXXXXX";
+ int fd = mkstemp(toml_template);
+ EXPECT_TRUE(fd>=0);
+ write(fd, gtest_module_spec_toml, strlen(gtest_module_spec_toml));
+ close(fd);
- struct stellar_module_manager *mod_mgr=stellar_module_manager_new_with_file(fp, 10, mq_schema);
- fclose(fp);
+ struct stellar_module_manager *mod_mgr=stellar_module_manager_new(toml_template, 10, mq_schema);
EXPECT_TRUE(mod_mgr!=NULL);
EXPECT_TRUE(stellar_module_manager_get_module(mod_mgr, "gtest")!=NULL);
EXPECT_EQ(stellar_module_manager_get_max_thread_num(mod_mgr), 10);
EXPECT_EQ((long)stellar_module_manager_get_mq_schema(mod_mgr), 1);
-
+ EXPECT_STREQ(stellar_module_manager_get_toml_path(mod_mgr), toml_template);
+
struct mq_runtime *mq_rt = (struct mq_runtime*)2;
stellar_module_manager_register_thread(mod_mgr, 1, mq_rt);
@@ -167,7 +179,7 @@ TEST(module_manager, basic_module) {
EXPECT_EQ((long)stellar_module_manager_get_mq_runtime(mod_mgr), 2);
stellar_module_manager_free(mod_mgr);
-
+ unlink(toml_template);
}
/**********************************************