1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2016 Planets Communications B.V.
6    Copyright (C) 2013-2020 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation, which is
11    listed in the file LICENSE.
12 
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22 */
23 /*
24  * Kern Sibbald, October 2007
25  */
26 /** @file
27  * BAREOS pluginloader
28  */
29 #if defined(HAVE_MINGW)
30 #  include "include/bareos.h"
31 #  include "gtest/gtest.h"
32 #else
33 #  include "gtest/gtest.h"
34 #  include "include/bareos.h"
35 #endif
36 
37 #include "dird/dird.h"
38 #include "dird/dird_globals.h"
39 #include "dird/dir_plugins.h"
40 #include "lib/edit.h"
41 
42 namespace directordaemon {
43 
44 DirectorResource* me = nullptr;
45 
46 bool DbGetPoolRecord(JobControlRecord*, BareosDb*, PoolDbRecord*);
DbGetPoolRecord(JobControlRecord *,BareosDb *,PoolDbRecord *)47 bool DbGetPoolRecord(JobControlRecord*, BareosDb*, PoolDbRecord*)
48 {
49   return true;
50 }
51 
TEST(dir,dir_plugins)52 TEST(dir, dir_plugins)
53 {
54   me = new DirectorResource;
55   ASSERT_NE(me, nullptr);
56 
57   char plugin_dir[PATH_MAX];
58   JobControlRecord mjcr1, mjcr2;
59   JobControlRecord* jcr1 = &mjcr1;
60   JobControlRecord* jcr2 = &mjcr2;
61 
62   InitMsg(NULL, NULL);
63 
64   OSDependentInit();
65   (void)!getcwd(plugin_dir, sizeof(plugin_dir) - 1);
66 
67   LoadDirPlugins(plugin_dir, NULL);
68 
69   jcr1->JobId = 111;
70   NewPlugins(jcr1);
71 
72   jcr2->JobId = 222;
73   NewPlugins(jcr2);
74 
75   EXPECT_EQ(GeneratePluginEvent(jcr1, bDirEventJobStart, (void*)"Start Job 1"),
76             bRC_OK);
77   EXPECT_EQ(GeneratePluginEvent(jcr1, bDirEventJobEnd), bRC_OK);
78   EXPECT_EQ(GeneratePluginEvent(jcr2, bDirEventJobStart, (void*)"Start Job 1"),
79             bRC_OK);
80   FreePlugins(jcr1);
81   EXPECT_EQ(GeneratePluginEvent(jcr2, bDirEventJobEnd), bRC_OK);
82   FreePlugins(jcr2);
83 
84   UnloadDirPlugins();
85 
86   TermMsg();
87   CloseMemoryPool();
88 }
89 
90 } /* namespace directordaemon */
91