1 /*
2 BAREOS® - Backup Archiving REcovery Open Sourced
3
4 Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
5 Copyright (C) 2011-2012 Planets Communications B.V.
6 Copyright (C) 2013-2019 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 /* originally Kern Sibbald, October 2007 */
24
25 #if defined(HAVE_MINGW)
26 #include "include/bareos.h"
27 #include "gtest/gtest.h"
28 #else
29 #include "gtest/gtest.h"
30 #include "include/bareos.h"
31 #endif
32
33
34 #include "stored/stored.h"
35 #include "stored/stored_globals.h"
36 #include "stored/sd_plugins.h"
37 #include "lib/crypto_cache.h"
38 #include "stored/sd_stats.h"
39 #include "lib/edit.h"
40 #include "include/jcr.h"
41
42 namespace storagedaemon {
43
TEST(sd,sd_plugins)44 TEST(sd, sd_plugins)
45 {
46 char plugin_dir[1000];
47 JobControlRecord mjcr1, mjcr2;
48 JobControlRecord* jcr1 = &mjcr1;
49 JobControlRecord* jcr2 = &mjcr2;
50
51 InitMsg(NULL, NULL);
52
53 OSDependentInit();
54
55 #pragma GCC diagnostic push
56 #pragma GCC diagnostic ignored "-Wunused-variable"
57 char* cwd = getcwd(plugin_dir, sizeof(plugin_dir) - 1);
58 #pragma GCC diagnostic pop
59
60 LoadSdPlugins(plugin_dir, NULL);
61
62 jcr1->JobId = 111;
63 NewPlugins(jcr1);
64
65 jcr2->JobId = 222;
66 NewPlugins(jcr2);
67
68 EXPECT_EQ(GeneratePluginEvent(jcr1, bsdEventJobStart, (void*)"Start Job 1"),
69 bRC_OK);
70 EXPECT_EQ(GeneratePluginEvent(jcr1, bsdEventJobEnd), bRC_OK);
71 EXPECT_EQ(GeneratePluginEvent(jcr2, bsdEventJobStart, (void*)"Start Job 1"),
72 bRC_OK);
73 FreePlugins(jcr1);
74 EXPECT_EQ(GeneratePluginEvent(jcr2, bsdEventJobEnd), bRC_OK);
75 FreePlugins(jcr2);
76
77 UnloadSdPlugins();
78
79 TermMsg();
80 CloseMemoryPool();
81 }
82
83 } /* namespace storagedaemon */
84