library_manager_unittest.cc 22 KB

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