library_manager_unittest.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. // Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #include <hooks/callout_handle.h>
  7. #include <hooks/callout_manager.h>
  8. #include <hooks/library_manager.h>
  9. #include <hooks/server_hooks.h>
  10. #include <hooks/tests/common_test_class.h>
  11. #include <hooks/tests/marker_file.h>
  12. #include <hooks/tests/test_libraries.h>
  13. #include <log/message_dictionary.h>
  14. #include <log/message_initializer.h>
  15. #include <gtest/gtest.h>
  16. #include <algorithm>
  17. #include <fstream>
  18. #include <string>
  19. #include <unistd.h>
  20. using namespace isc;
  21. using namespace isc::hooks;
  22. using namespace isc::log;
  23. using namespace std;
  24. namespace {
  25. /// @brief Library manager test class
  26. class LibraryManagerTest : public ::testing::Test,
  27. public HooksCommonTestClass {
  28. public:
  29. /// @brief Constructor
  30. ///
  31. /// Initializes the CalloutManager object used in the tests. It sets it
  32. /// up with the hooks initialized in the HooksCommonTestClass object and
  33. /// with four libraries.
  34. LibraryManagerTest() {
  35. callout_manager_.reset(new CalloutManager(4));
  36. // Ensure the marker file is not present at the start of a test.
  37. static_cast<void>(remove(MARKER_FILE));
  38. }
  39. /// @brief Destructor
  40. ///
  41. /// Ensures a marker file is removed after each test.
  42. ~LibraryManagerTest() {
  43. static_cast<void>(remove(MARKER_FILE));
  44. }
  45. /// @brief Marker file present
  46. ///
  47. /// Convenience function to check whether a marker file is present. It
  48. /// does this by opening the file.
  49. ///
  50. /// @return true if the marker file is present.
  51. bool markerFilePresent() const {
  52. // Try to open it.
  53. std::fstream marker;
  54. marker.open(MARKER_FILE, std::fstream::in);
  55. // Check if it is open and close it if so.
  56. bool exists = marker.is_open();
  57. if (exists) {
  58. marker.close();
  59. }
  60. return (exists);
  61. }
  62. /// @brief Call callouts test
  63. ///
  64. /// A wrapper around the method of the same name in the HooksCommonTestClass
  65. /// object, this passes this class's CalloutManager to that method.
  66. ///
  67. /// @param r0...r3, d1..d3 Values and intermediate values expected. They
  68. /// are ordered so that the variables appear in the argument list in
  69. /// the order they are used. See HooksCommonTestClass::execute for
  70. /// a full description. (rN is used to indicate an expected result,
  71. /// dN is data to be passed to the calculation.)
  72. void executeCallCallouts(int r0, int d1, int r1, int d2, int r2, int d3,
  73. int r3) {
  74. HooksCommonTestClass::executeCallCallouts(callout_manager_, r0, d1,
  75. r1, d2, r2, d3, r3);
  76. }
  77. /// Callout manager used for the test.
  78. boost::shared_ptr<CalloutManager> callout_manager_;
  79. };
  80. /// @brief Library manager class
  81. ///
  82. /// This is an instance of the LibraryManager class but with the protected
  83. /// methods made public for test purposes.
  84. class PublicLibraryManager : public isc::hooks::LibraryManager {
  85. public:
  86. /// @brief Constructor
  87. ///
  88. /// Stores the library name. The actual loading is done in loadLibrary().
  89. ///
  90. /// @param name Name of the library to load. This should be an absolute
  91. /// path name.
  92. /// @param index Index of this library. For all these tests, it will be
  93. /// zero, as we are only using one library.
  94. /// @param manager CalloutManager object
  95. PublicLibraryManager(const std::string& name, int index,
  96. const boost::shared_ptr<CalloutManager>& manager)
  97. : LibraryManager(name, index, manager)
  98. {}
  99. /// Public methods that call protected methods on the superclass.
  100. using LibraryManager::openLibrary;
  101. using LibraryManager::closeLibrary;
  102. using LibraryManager::checkVersion;
  103. using LibraryManager::registerStandardCallouts;
  104. using LibraryManager::runLoad;
  105. using LibraryManager::runUnload;
  106. };
  107. // Check that openLibrary() reports an error when it can't find the specified
  108. // library.
  109. TEST_F(LibraryManagerTest, NoLibrary) {
  110. PublicLibraryManager lib_manager(std::string(NOT_PRESENT_LIBRARY),
  111. 0, callout_manager_);
  112. EXPECT_FALSE(lib_manager.openLibrary());
  113. }
  114. // Check that the openLibrary() and closeLibrary() methods work.
  115. TEST_F(LibraryManagerTest, OpenClose) {
  116. PublicLibraryManager lib_manager(std::string(BASIC_CALLOUT_LIBRARY),
  117. 0, callout_manager_);
  118. // Open and close the library
  119. EXPECT_TRUE(lib_manager.openLibrary());
  120. EXPECT_TRUE(lib_manager.closeLibrary());
  121. // Check that a second close on an already closed library does not report
  122. // an error.
  123. EXPECT_TRUE(lib_manager.closeLibrary());
  124. }
  125. // Check that the code handles the case of a library with no version function.
  126. TEST_F(LibraryManagerTest, NoVersion) {
  127. PublicLibraryManager lib_manager(std::string(NO_VERSION_LIBRARY),
  128. 0, callout_manager_);
  129. // Open should succeed.
  130. EXPECT_TRUE(lib_manager.openLibrary());
  131. // Version check should fail.
  132. EXPECT_FALSE(lib_manager.checkVersion());
  133. // Tidy up.
  134. EXPECT_TRUE(lib_manager.closeLibrary());
  135. }
  136. // Check that the code handles the case of a library with a version function
  137. // that returns an incorrect version number.
  138. TEST_F(LibraryManagerTest, WrongVersion) {
  139. PublicLibraryManager lib_manager(std::string(INCORRECT_VERSION_LIBRARY),
  140. 0, callout_manager_);
  141. // Open should succeed.
  142. EXPECT_TRUE(lib_manager.openLibrary());
  143. // Version check should fail.
  144. EXPECT_FALSE(lib_manager.checkVersion());
  145. // Tidy up.
  146. EXPECT_TRUE(lib_manager.closeLibrary());
  147. }
  148. // Check that the code handles the case of a library where the version function
  149. // throws an exception.
  150. TEST_F(LibraryManagerTest, VersionException) {
  151. PublicLibraryManager lib_manager(std::string(FRAMEWORK_EXCEPTION_LIBRARY),
  152. 0, callout_manager_);
  153. // Open should succeed.
  154. EXPECT_TRUE(lib_manager.openLibrary());
  155. // Version check should fail.
  156. EXPECT_FALSE(lib_manager.checkVersion());
  157. // Tidy up.
  158. EXPECT_TRUE(lib_manager.closeLibrary());
  159. }
  160. // Tests that checkVersion() function succeeds in the case of a library with a
  161. // version function that returns the correct version number.
  162. TEST_F(LibraryManagerTest, CorrectVersionReturned) {
  163. PublicLibraryManager lib_manager(std::string(BASIC_CALLOUT_LIBRARY),
  164. 0, callout_manager_);
  165. // Open should succeed.
  166. EXPECT_TRUE(lib_manager.openLibrary());
  167. // Version check should succeed.
  168. EXPECT_TRUE(lib_manager.checkVersion());
  169. // Tidy up.
  170. EXPECT_TRUE(lib_manager.closeLibrary());
  171. }
  172. // Checks the registration of standard callouts.
  173. TEST_F(LibraryManagerTest, RegisterStandardCallouts) {
  174. // Load the only library, specifying the index of 0 as it's the only
  175. // library. This should load all callouts.
  176. PublicLibraryManager lib_manager(std::string(BASIC_CALLOUT_LIBRARY),
  177. 0, callout_manager_);
  178. EXPECT_TRUE(lib_manager.openLibrary());
  179. // Check the version of the library.
  180. EXPECT_TRUE(lib_manager.checkVersion());
  181. // Load the standard callouts
  182. EXPECT_NO_THROW(lib_manager.registerStandardCallouts());
  183. // Now execute the callouts in the order expected. The library performs
  184. // the calculation:
  185. //
  186. // r3 = (10 + d1) * d2 - d3
  187. executeCallCallouts(10, 5, 15, 7, 105, 17, 88);
  188. // Tidy up
  189. EXPECT_TRUE(lib_manager.closeLibrary());
  190. }
  191. // Test that the "load" function is called correctly.
  192. TEST_F(LibraryManagerTest, CheckLoadCalled) {
  193. // Load the only library, specifying the index of 0 as it's the only
  194. // library. This should load all callouts.
  195. PublicLibraryManager lib_manager(std::string(LOAD_CALLOUT_LIBRARY),
  196. 0, callout_manager_);
  197. EXPECT_TRUE(lib_manager.openLibrary());
  198. // Check the version of the library.
  199. EXPECT_TRUE(lib_manager.checkVersion());
  200. // Load the standard callouts
  201. EXPECT_NO_THROW(lib_manager.registerStandardCallouts());
  202. // Check that only context_create and hookpt_one have callouts registered.
  203. EXPECT_TRUE(callout_manager_->calloutsPresent(
  204. ServerHooks::CONTEXT_CREATE));
  205. EXPECT_TRUE(callout_manager_->calloutsPresent(hookpt_one_index_));
  206. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_two_index_));
  207. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_three_index_));
  208. EXPECT_FALSE(callout_manager_->calloutsPresent(
  209. ServerHooks::CONTEXT_DESTROY));
  210. // Call the runLoad() method to run the load() function.
  211. EXPECT_TRUE(lib_manager.runLoad());
  212. EXPECT_TRUE(callout_manager_->calloutsPresent(
  213. ServerHooks::CONTEXT_CREATE));
  214. EXPECT_TRUE(callout_manager_->calloutsPresent(hookpt_one_index_));
  215. EXPECT_TRUE(callout_manager_->calloutsPresent(hookpt_two_index_));
  216. EXPECT_TRUE(callout_manager_->calloutsPresent(hookpt_three_index_));
  217. EXPECT_FALSE(callout_manager_->calloutsPresent(
  218. ServerHooks::CONTEXT_DESTROY));
  219. // Now execute the callouts in the order expected. The library performs
  220. // the calculation:
  221. //
  222. // r3 = (5 * d1 + d2) * d3
  223. executeCallCallouts(5, 5, 25, 7, 32, 10, 320);
  224. // Tidy up
  225. EXPECT_TRUE(lib_manager.closeLibrary());
  226. }
  227. // Check handling of a "load" function that throws an exception
  228. TEST_F(LibraryManagerTest, CheckLoadException) {
  229. // Load the only library, specifying the index of 0 as it's the only
  230. // library. This should load all callouts.
  231. PublicLibraryManager lib_manager(std::string(FRAMEWORK_EXCEPTION_LIBRARY),
  232. 0, callout_manager_);
  233. EXPECT_TRUE(lib_manager.openLibrary());
  234. // Running the load function should fail.
  235. EXPECT_FALSE(lib_manager.runLoad());
  236. // Tidy up
  237. EXPECT_TRUE(lib_manager.closeLibrary());
  238. }
  239. // Check handling of a "load" function that returns an error.
  240. TEST_F(LibraryManagerTest, CheckLoadError) {
  241. // Load the only library, specifying the index of 0 as it's the only
  242. // library. This should load all callouts.
  243. PublicLibraryManager lib_manager(std::string(LOAD_ERROR_CALLOUT_LIBRARY),
  244. 0, callout_manager_);
  245. EXPECT_TRUE(lib_manager.openLibrary());
  246. // Check that we catch a load error
  247. EXPECT_FALSE(lib_manager.runLoad());
  248. // Tidy up
  249. EXPECT_TRUE(lib_manager.closeLibrary());
  250. }
  251. // No unload function
  252. TEST_F(LibraryManagerTest, CheckNoUnload) {
  253. // Load the only library, specifying the index of 0 as it's the only
  254. // library. This should load all callouts.
  255. PublicLibraryManager lib_manager(std::string(BASIC_CALLOUT_LIBRARY),
  256. 0, callout_manager_);
  257. EXPECT_TRUE(lib_manager.openLibrary());
  258. // Check that no unload function returns true.
  259. EXPECT_TRUE(lib_manager.runUnload());
  260. // Tidy up
  261. EXPECT_TRUE(lib_manager.closeLibrary());
  262. }
  263. // Unload function returns an error
  264. TEST_F(LibraryManagerTest, CheckUnloadError) {
  265. // Load the only library, specifying the index of 0 as it's the only
  266. // library. This should load all callouts.
  267. PublicLibraryManager lib_manager(std::string(LOAD_ERROR_CALLOUT_LIBRARY),
  268. 0, callout_manager_);
  269. EXPECT_TRUE(lib_manager.openLibrary());
  270. // Check that unload function returning an error returns false.
  271. EXPECT_FALSE(lib_manager.runUnload());
  272. // Tidy up
  273. EXPECT_TRUE(lib_manager.closeLibrary());
  274. }
  275. // Unload function throws an exception.
  276. TEST_F(LibraryManagerTest, CheckUnloadException) {
  277. // Load the only library, specifying the index of 0 as it's the only
  278. // library. This should load all callouts.
  279. PublicLibraryManager lib_manager(std::string(FRAMEWORK_EXCEPTION_LIBRARY),
  280. 0, callout_manager_);
  281. EXPECT_TRUE(lib_manager.openLibrary());
  282. // Check that we detect that the unload function throws an exception.
  283. EXPECT_FALSE(lib_manager.runUnload());
  284. // Tidy up
  285. EXPECT_TRUE(lib_manager.closeLibrary());
  286. }
  287. // Check that the case of the library's unload() function returning a
  288. // success is handled correctly.
  289. TEST_F(LibraryManagerTest, CheckUnload) {
  290. // Load the only library, specifying the index of 0 as it's the only
  291. // library. This should load all callouts.
  292. PublicLibraryManager lib_manager(std::string(UNLOAD_CALLOUT_LIBRARY),
  293. 0, callout_manager_);
  294. EXPECT_TRUE(lib_manager.openLibrary());
  295. // Check that the marker file is not present (at least that the file
  296. // open fails).
  297. EXPECT_FALSE(markerFilePresent());
  298. // Check that unload function runs and returns a success
  299. EXPECT_TRUE(lib_manager.runUnload());
  300. // Check that the marker file was created.
  301. EXPECT_TRUE(markerFilePresent());
  302. // Tidy up
  303. EXPECT_TRUE(lib_manager.closeLibrary());
  304. }
  305. // Test the operation of unloadLibrary(). We load a library with a set
  306. // of callouts then unload it. We need to check that the callouts have been
  307. // removed. We'll also check that the library's unload() function was called
  308. // as well.
  309. TEST_F(LibraryManagerTest, LibUnload) {
  310. // Load the only library, specifying the index of 0 as it's the only
  311. // library. This should load all callouts.
  312. PublicLibraryManager lib_manager(std::string(FULL_CALLOUT_LIBRARY),
  313. 0, callout_manager_);
  314. EXPECT_TRUE(lib_manager.openLibrary());
  315. // Check the version of the library.
  316. EXPECT_TRUE(lib_manager.checkVersion());
  317. // No callouts should be registered at the moment.
  318. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_one_index_));
  319. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_two_index_));
  320. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_three_index_));
  321. // Load the single standard callout and check it is registered correctly.
  322. EXPECT_NO_THROW(lib_manager.registerStandardCallouts());
  323. EXPECT_TRUE(callout_manager_->calloutsPresent(hookpt_one_index_));
  324. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_two_index_));
  325. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_three_index_));
  326. // Call the load function to load the other callouts.
  327. EXPECT_TRUE(lib_manager.runLoad());
  328. EXPECT_TRUE(callout_manager_->calloutsPresent(hookpt_one_index_));
  329. EXPECT_TRUE(callout_manager_->calloutsPresent(hookpt_two_index_));
  330. EXPECT_TRUE(callout_manager_->calloutsPresent(hookpt_three_index_));
  331. // Unload the library and check that the callouts have been removed from
  332. // the CalloutManager.
  333. lib_manager.unloadLibrary();
  334. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_one_index_));
  335. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_two_index_));
  336. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_three_index_));
  337. }
  338. // Now come the loadLibrary() tests that make use of all the methods tested
  339. // above. These tests are really to make sure that the methods have been
  340. // tied together correctly.
  341. // First test the basic error cases - no library, no version function, version
  342. // function returning an error.
  343. TEST_F(LibraryManagerTest, LoadLibraryNoLibrary) {
  344. LibraryManager lib_manager(std::string(NOT_PRESENT_LIBRARY), 0,
  345. callout_manager_);
  346. EXPECT_FALSE(lib_manager.loadLibrary());
  347. }
  348. // Check that the code handles the case of a library with no version function.
  349. TEST_F(LibraryManagerTest, LoadLibraryNoVersion) {
  350. LibraryManager lib_manager(std::string(NO_VERSION_LIBRARY), 0,
  351. callout_manager_);
  352. EXPECT_FALSE(lib_manager.loadLibrary());
  353. }
  354. // Check that the code handles the case of a library with a version function
  355. // that returns an incorrect version number.
  356. TEST_F(LibraryManagerTest, LoadLibraryWrongVersion) {
  357. LibraryManager lib_manager(std::string(INCORRECT_VERSION_LIBRARY), 0,
  358. callout_manager_);
  359. EXPECT_FALSE(lib_manager.loadLibrary());
  360. }
  361. // Check that the full loadLibrary call works.
  362. TEST_F(LibraryManagerTest, LoadLibrary) {
  363. LibraryManager lib_manager(std::string(FULL_CALLOUT_LIBRARY), 0,
  364. callout_manager_);
  365. EXPECT_TRUE(lib_manager.loadLibrary());
  366. // Now execute the callouts in the order expected. The library performs
  367. // the calculation:
  368. //
  369. // r3 = (7 * d1 - d2) * d3
  370. executeCallCallouts(7, 5, 35, 9, 26, 3, 78);
  371. EXPECT_TRUE(lib_manager.unloadLibrary());
  372. // Check that the callouts have been removed from the callout manager.
  373. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_one_index_));
  374. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_two_index_));
  375. EXPECT_FALSE(callout_manager_->calloutsPresent(hookpt_three_index_));
  376. }
  377. // Now test for multiple libraries. We'll load the full callout library
  378. // first, then load some of the libraries with missing framework functions.
  379. // This will check that when searching for framework functions, only the
  380. // specified library is checked, not other loaded libraries. We will
  381. // load a second library with suitable callouts and check that the callouts
  382. // are added correctly. Finally, we'll unload one of the libraries and
  383. // check that only the callouts belonging to that library were removed.
  384. TEST_F(LibraryManagerTest, LoadMultipleLibraries) {
  385. // Load a library with all framework functions.
  386. LibraryManager lib_manager_1(std::string(FULL_CALLOUT_LIBRARY), 0,
  387. callout_manager_);
  388. EXPECT_TRUE(lib_manager_1.loadLibrary());
  389. // Attempt to load a library with no version() function. We should detect
  390. // this and not end up calling the function from the already loaded
  391. // library.
  392. LibraryManager lib_manager_2(std::string(NO_VERSION_LIBRARY), 1,
  393. callout_manager_);
  394. EXPECT_FALSE(lib_manager_2.loadLibrary());
  395. // Attempt to load the library with an incorrect version. This should
  396. // be detected.
  397. LibraryManager lib_manager_3(std::string(INCORRECT_VERSION_LIBRARY), 1,
  398. callout_manager_);
  399. EXPECT_FALSE(lib_manager_3.loadLibrary());
  400. // Load the basic callout library. This only has standard callouts so,
  401. // if the first library's load() function gets called, some callouts
  402. // will be registered twice and lead to incorrect results.
  403. LibraryManager lib_manager_4(std::string(BASIC_CALLOUT_LIBRARY), 1,
  404. callout_manager_);
  405. EXPECT_TRUE(lib_manager_4.loadLibrary());
  406. // Execute the callouts. The first library implements the calculation.
  407. //
  408. // r3 = (7 * d1 - d2) * d3
  409. //
  410. // The last-loaded library implements the calculation
  411. //
  412. // r3 = (10 + d1) * d2 - d3
  413. //
  414. // Putting the processing for each library together in the appropriate
  415. // order, we get:
  416. //
  417. // r3 = ((10 * d1 + d1) - d2) * d2 * d3 - d3
  418. executeCallCallouts(10, 3, 33, 2, 62, 3, 183);
  419. // All done, so unload the first library.
  420. EXPECT_TRUE(lib_manager_1.unloadLibrary());
  421. // Now execute the callouts again and check that the results are as
  422. // expected for the new calculation.
  423. executeCallCallouts(10, 5, 15, 7, 105, 17, 88);
  424. // ... and tidy up.
  425. EXPECT_TRUE(lib_manager_4.unloadLibrary());
  426. }
  427. // Check that libraries can be validated.
  428. TEST_F(LibraryManagerTest, validateLibraries) {
  429. EXPECT_TRUE(LibraryManager::validateLibrary(BASIC_CALLOUT_LIBRARY));
  430. EXPECT_TRUE(LibraryManager::validateLibrary(FULL_CALLOUT_LIBRARY));
  431. EXPECT_FALSE(LibraryManager::validateLibrary(FRAMEWORK_EXCEPTION_LIBRARY));
  432. EXPECT_FALSE(LibraryManager::validateLibrary(INCORRECT_VERSION_LIBRARY));
  433. EXPECT_TRUE(LibraryManager::validateLibrary(LOAD_CALLOUT_LIBRARY));
  434. EXPECT_TRUE(LibraryManager::validateLibrary(LOAD_ERROR_CALLOUT_LIBRARY));
  435. EXPECT_FALSE(LibraryManager::validateLibrary(NOT_PRESENT_LIBRARY));
  436. EXPECT_FALSE(LibraryManager::validateLibrary(NO_VERSION_LIBRARY));
  437. EXPECT_TRUE(LibraryManager::validateLibrary(UNLOAD_CALLOUT_LIBRARY));
  438. EXPECT_TRUE(LibraryManager::validateLibrary(CALLOUT_PARAMS_LIBRARY));
  439. }
  440. // Check that log messages are properly registered and unregistered.
  441. TEST_F(LibraryManagerTest, libraryLoggerSetup) {
  442. // Load a library with all framework functions.
  443. LibraryManager lib_manager(std::string(BASIC_CALLOUT_LIBRARY), 0,
  444. callout_manager_);
  445. EXPECT_TRUE(lib_manager.loadLibrary());
  446. // After loading the library, the global logging dictionary should
  447. // contain log messages registerd for this library.
  448. const MessageDictionaryPtr& dict = MessageDictionary::globalDictionary();
  449. EXPECT_EQ("basic callout load %1", dict->getText("BCL_LOAD_START"));
  450. EXPECT_EQ("basic callout load end", dict->getText("BCL_LOAD_END"));
  451. // Some of the messages defined by the hook library are duplicates. But,
  452. // the loadLibrary function should have logged the duplicates and clear
  453. // the duplicates list. By checking that the list of duplicates is empty
  454. // we test that the LibraryManager handles the duplicates (logs and
  455. // clears them).
  456. EXPECT_TRUE(MessageInitializer::getDuplicates().empty());
  457. // After unloading the library, the messages should be unregistered.
  458. EXPECT_TRUE(lib_manager.unloadLibrary());
  459. EXPECT_TRUE(dict->getText("BCL_LOAD_START").empty());
  460. EXPECT_TRUE(dict->getText("BCL_LOAD_END").empty());
  461. }
  462. } // Anonymous namespace