-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathtestUserCodeInterface.cxx
More file actions
100 lines (82 loc) · 2.75 KB
/
testUserCodeInterface.cxx
File metadata and controls
100 lines (82 loc) · 2.75 KB
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
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file testCommonInterface.cxx
/// \author Barthelemy von Haller
///
#include "QualityControl/UserCodeInterface.h"
#define BOOST_TEST_MODULE CommonInterface test
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <TObject.h>
#include <string>
#include <TROOT.h>
#include <TH1F.h>
#include <QualityControl/CcdbDatabase.h>
#include <QualityControl/CustomParameters.h>
using namespace std;
using namespace o2::quality_control::repository;
using namespace o2::quality_control::core;
namespace o2::quality_control
{
namespace test
{
class TestInterface : public core::UserCodeInterface
{
public:
/// Default constructor
TestInterface() = default;
/// Destructor
~TestInterface() override = default;
// Override interface
void configure() override
{
configured = true;
}
string get(std::string key)
{
return mCustomParameters.at(key);
}
bool configured = false;
};
struct MyGlobalFixture {
void teardown()
{
auto backend = std::make_unique<CcdbDatabase>();
backend->connect("ccdb-test.cern.ch:8080", "", "", "");
backend->truncate("qc/TST/MO/Test/pid" + std::to_string(getpid()), "*");
}
};
BOOST_TEST_GLOBAL_FIXTURE(MyGlobalFixture);
BOOST_AUTO_TEST_CASE(test_invoke_all_methods)
{
test::TestInterface testInterface;
BOOST_CHECK_EQUAL(testInterface.configured, false);
TH1F* h1 = new TH1F("asdf", "asdf", 100, 0, 99);
auto pid = std::to_string(getpid());
auto taskName = "Test/pid" + pid;
shared_ptr<MonitorObject> mo1 = make_shared<MonitorObject>(h1, taskName, "task", "TST");
auto backend = std::make_unique<CcdbDatabase>();
backend->connect("ccdb-test.cern.ch:8080", "", "", "");
backend->storeMO(mo1);
// setting custom parameters should configure
CustomParameters customParameters;
customParameters["test"] = "asdf";
testInterface.setCustomParameters(customParameters);
BOOST_CHECK_EQUAL(testInterface.configured, true);
BOOST_CHECK_EQUAL(testInterface.get("test"), "asdf");
testInterface.setCcdbUrl("ccdb-test.cern.ch:8080");
auto obj = testInterface.retrieveConditionAny<TObject>("qc/TST/MO/" + taskName + "/asdf");
BOOST_CHECK_NE(obj, nullptr);
}
} /* namespace test */
} /* namespace o2::quality_control */