-
Notifications
You must be signed in to change notification settings - Fork 256
/
test_fd_plugins.cc
129 lines (102 loc) · 3.71 KB
/
test_fd_plugins.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2007-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation, which is
listed in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* extracted the TEST_PROGRAM functionality from filed/fd_plugins.cc
* and adapted for gtest
*
* Andreas Rogge, Feb 2019
*/
/**
* @file
* Bareos pluginloader
*/
#if defined(HAVE_MINGW)
#include "include/bareos.h"
#include "gtest/gtest.h"
#else
#include "gtest/gtest.h"
#include "include/bareos.h"
#endif
#include "filed/filed.h"
#include "filed/filed_globals.h"
#include "filed/accurate.h"
#include "filed/heartbeat.h"
#include "filed/fileset.h"
#include "filed/heartbeat.h"
#include "findlib/attribs.h"
#include "findlib/find.h"
#include "findlib/find_one.h"
#include "findlib/hardlink.h"
/**
* Function pointers to be set here (findlib)
*/
extern int (*plugin_bopen)(BareosWinFilePacket* bfd,
const char* fname,
int flags,
mode_t mode);
extern int (*plugin_bclose)(BareosWinFilePacket* bfd);
extern ssize_t (*plugin_bread)(BareosWinFilePacket* bfd,
void* buf,
size_t count);
extern ssize_t (*plugin_bwrite)(BareosWinFilePacket* bfd,
void* buf,
size_t count);
extern boffset_t (*plugin_blseek)(BareosWinFilePacket* bfd,
boffset_t offset,
int whence);
extern char* exepath;
extern char* version;
namespace filedaemon {
int SaveFile(JobControlRecord*, FindFilesPacket*, bool);
bool SetCmdPlugin(BareosWinFilePacket*, JobControlRecord*);
/* Exported variables */
ClientResource* me; /* my resource */
int SaveFile(JobControlRecord*, FindFilesPacket*, bool) { return 0; }
bool AccurateMarkFileAsSeen(JobControlRecord*, char*) { return true; }
bool AccurateMarkAllFilesAsSeen(JobControlRecord*) { return true; }
bool accurate_unMarkFileAsSeen(JobControlRecord*, char*) { return true; }
bool accurate_unMarkAllFilesAsSeen(JobControlRecord*) { return true; }
bool SetCmdPlugin(BareosWinFilePacket*, JobControlRecord*) { return true; }
TEST(fd, fd_plugins)
{
char plugin_dir[PATH_MAX];
JobControlRecord mjcr1, mjcr2;
JobControlRecord* jcr1 = &mjcr1;
JobControlRecord* jcr2 = &mjcr2;
InitMsg(NULL, NULL);
OSDependentInit();
(void)!getcwd(plugin_dir, sizeof(plugin_dir) - 1);
LoadFdPlugins(plugin_dir, NULL);
jcr1->JobId = 111;
NewPlugins(jcr1);
jcr2->JobId = 222;
NewPlugins(jcr2);
EXPECT_EQ(GeneratePluginEvent(jcr1, bEventJobStart, (void*)"Start Job 1"),
bRC_OK);
EXPECT_EQ(GeneratePluginEvent(jcr1, bEventJobEnd), bRC_OK);
EXPECT_EQ(GeneratePluginEvent(jcr2, bEventJobStart, (void*)"Start Job 2"),
bRC_OK);
FreePlugins(jcr1);
EXPECT_EQ(GeneratePluginEvent(jcr2, bEventJobEnd), bRC_OK);
FreePlugins(jcr2);
UnloadFdPlugins();
TermMsg();
CloseMemoryPool();
}
} /* namespace filedaemon */