SpModTest.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "precompile.h"
  2. #include "sp_mod.h"
  3. #include <gtest/gtest.h>
  4. #include "sp_shm.h"
  5. TEST(SpModTest, ImitateMemoryShare)
  6. {
  7. auto range = sp_shm_get_range(0xffffffff);
  8. ASSERT_TRUE(range != 0);
  9. auto hint_addr = sp_shm_init(range, TRUE);
  10. ASSERT_TRUE(hint_addr != NULL);
  11. std::cout << "hint address: " << hint_addr << std::endl;
  12. //sp_shm_term();
  13. }
  14. TEST(SpModTest, LoadModuleTest)
  15. {
  16. sp_mod_mgr_t* mgr = NULL;
  17. sp_cfg_shell_entity_t* ent = NULL;
  18. sp_cfg_shell_module_t* mod = NULL;
  19. auto rc = sp_mod_mgr_create(&mgr);
  20. ASSERT_TRUE(rc == 0) << "create mod mgr failed!" << std::endl;
  21. ASSERT_FALSE(sp_mod_mgr_find_module_by_name(mgr, "test_mod_name") != NULL);
  22. ASSERT_FALSE(sp_mod_mgr_find_entity_by_name(mgr, "test_entity_name") != NULL);
  23. mod = (sp_cfg_shell_module_t*)malloc(sizeof(sp_cfg_shell_module_t));
  24. memset(mod, 0, sizeof(sp_cfg_shell_module_t));
  25. sp_version_t ver = { 1, 0, 1, 0 };
  26. sp_version_copy(&mod->version, &ver);
  27. mod->author = strdup("tester");
  28. mod->company = strdup("tester");
  29. mod->name = strdup("test_mod_name");
  30. mod->mem_trace = 0;
  31. mod->idx = 1;
  32. ent = (sp_cfg_shell_entity_t*)malloc(sizeof(sp_cfg_shell_entity_t));
  33. ASSERT_TRUE(ent != NULL);
  34. memset(ent, 0, sizeof(sp_cfg_shell_entity_t));
  35. ent->mod = mod;
  36. ent->name = strdup("test_entity_name");
  37. ent->idx = 1;
  38. ent->privilege = 1;
  39. ent->debug_level = 0;
  40. EXPECT_TRUE(Error_NotExist == sp_mod_mgr_add_entity(mgr, ent));
  41. EXPECT_TRUE(0 == sp_mod_mgr_add_module(mgr, mod));
  42. EXPECT_TRUE(Error_Duplication == sp_mod_mgr_add_module(mgr, mod));
  43. EXPECT_TRUE(0 == sp_mod_mgr_add_entity(mgr, ent));
  44. EXPECT_TRUE(Error_Duplication == sp_mod_mgr_add_entity(mgr, ent));
  45. ASSERT_TRUE(sp_mod_mgr_find_module_by_name(mgr, "test_mod_name") != NULL);
  46. ASSERT_TRUE(sp_mod_mgr_find_entity_by_name(mgr, "test_entity_name") != NULL);
  47. EXPECT_TRUE(0 == sp_mod_mgr_remove_entity(mgr, "test_entity_name"));
  48. EXPECT_TRUE(Error_NotExist == sp_mod_mgr_remove_entity(mgr, "test_entity_name"));
  49. EXPECT_TRUE(0 == sp_mod_mgr_remove_module(mgr, "test_mod_name"));
  50. EXPECT_TRUE(Error_NotExist == sp_mod_mgr_remove_module(mgr, "test_mod_name"));
  51. ASSERT_FALSE(sp_mod_mgr_find_module_by_name(mgr, "test_mod_name") != NULL);
  52. ASSERT_FALSE(sp_mod_mgr_find_entity_by_name(mgr, "test_entity_name") != NULL);
  53. free(ent->name);
  54. free(ent);
  55. free(mod->name);
  56. free(mod);
  57. sp_mod_mgr_destroy(mgr);
  58. }
  59. TEST(SpModTest, EndMemoryShare)
  60. {
  61. sp_shm_term();
  62. }