Project
Loading...
Searching...
No Matches
testDataPointGenerator.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test DCS DataPointGenerator
13#define BOOST_TEST_MAIN
14
15#define BOOST_TEST_DYN_LINK
16
17#include <boost/test/unit_test.hpp>
18#include <boost/test/data/test_case.hpp>
19#include <iostream>
21#include <algorithm>
22#include <fmt/format.h>
23
24BOOST_AUTO_TEST_CASE(GenerateDouble)
25{
26 double fmin = 1620.0;
27 double fmax = 1710.5;
28 auto fbi = o2::dcs::generateRandomDataPoints({"TST/SECTOR[00..06]/CRATE[0..3]/voltage"}, fmin, fmax, "2022-November-18 12:34:56");
29
30 BOOST_CHECK_EQUAL(fbi.size(), 28);
31
32 for (auto dp : fbi) {
33 BOOST_CHECK_EQUAL(dp.id.get_type(), o2::dcs::DeliveryType::DPVAL_DOUBLE);
34 double value = o2::dcs::getValue<double>(dp);
35 BOOST_CHECK(value >= fmin && value <= fmax);
36 }
37}
38
40{
41 float fmin = 1620.0f;
42 float fmax = 1710.5f;
43 auto fbi = o2::dcs::generateRandomDataPoints({"TST/SECTOR[00..06]/CRATE[0..3]/voltage"}, fmin, fmax, "2022-November-18 12:34:56");
44
45 BOOST_CHECK_EQUAL(fbi.size(), 28);
46
47 for (auto dp : fbi) {
48 BOOST_CHECK_EQUAL(dp.id.get_type(), o2::dcs::DeliveryType::DPVAL_FLOAT);
49 float value = o2::dcs::getValue<float>(dp);
50 BOOST_TEST_INFO(fmt::format("value={}", value));
51 BOOST_CHECK(value >= fmin && value <= fmax);
52 }
53}
54
56{
57 int32_t imin = 0;
58 int32_t imax = 3;
59 auto fbi = o2::dcs::generateRandomDataPoints({"TST/SECTOR[00..06]/CRATE[0..3]/current"}, imin, imax, "2022-November-18 12:34:56");
60
61 BOOST_CHECK_EQUAL(fbi.size(), 28);
62
63 for (auto dp : fbi) {
64 BOOST_CHECK_EQUAL(dp.id.get_type(), o2::dcs::DeliveryType::DPVAL_INT);
65 double value = o2::dcs::getValue<int32_t>(dp);
66 BOOST_CHECK(value >= imin && value <= imax);
67 BOOST_CHECK_THROW(o2::dcs::getValue<double>(dp), std::runtime_error);
68 BOOST_CHECK_THROW(o2::dcs::getValue<uint32_t>(dp), std::runtime_error);
69 }
70}
71
73{
74 uint32_t imin = 0;
75 uint32_t imax = 3;
76 auto fbi = o2::dcs::generateRandomDataPoints({"TST/SECTOR[00..06]/CRATE[0..3]/current"}, imin, imax, "2022-November-18 12:34:56");
77
78 BOOST_CHECK_EQUAL(fbi.size(), 28);
79
80 for (auto dp : fbi) {
81 BOOST_CHECK_EQUAL(dp.id.get_type(), o2::dcs::DeliveryType::DPVAL_UINT);
82 double value = o2::dcs::getValue<uint32_t>(dp);
83 BOOST_CHECK(value >= imin && value <= imax);
84 BOOST_CHECK_THROW(o2::dcs::getValue<double>(dp), std::runtime_error);
85 BOOST_CHECK_THROW(o2::dcs::getValue<int32_t>(dp), std::runtime_error);
86 }
87}
88
90{
91 auto fbi = o2::dcs::generateRandomDataPoints<bool>({"TST/SECTOR[00..06]/status"}, 0, 1, "2022-November-18 12:34:56");
92
93 BOOST_CHECK_EQUAL(fbi.size(), 7);
94
95 for (auto dp : fbi) {
96 BOOST_CHECK_EQUAL(dp.id.get_type(), o2::dcs::DeliveryType::DPVAL_BOOL);
97 BOOST_CHECK_NO_THROW(o2::dcs::getValue<bool>(dp));
98 BOOST_CHECK_THROW(o2::dcs::getValue<int>(dp), std::runtime_error);
99 }
100}
101
102BOOST_AUTO_TEST_CASE(GenerateString)
103{
104 auto fbi = o2::dcs::generateRandomDataPoints<std::string>({"TST/SECTOR[00..06]/name"}, "123", "1234567", "2022-November-18 12:34:56");
105
106 BOOST_CHECK_EQUAL(fbi.size(), 7);
107
108 for (auto dp : fbi) {
109 BOOST_CHECK_EQUAL(dp.id.get_type(), o2::dcs::DeliveryType::DPVAL_STRING);
110 BOOST_CHECK_NO_THROW(o2::dcs::getValue<std::string>(dp));
111 BOOST_CHECK_THROW(o2::dcs::getValue<int>(dp), std::runtime_error);
112 auto value = o2::dcs::getValue<std::string>(dp);
113 BOOST_CHECK(value.size() >= 3);
114 BOOST_CHECK(value.size() <= 7);
115 }
116}
GLsizei const GLfloat * value
Definition glcorearb.h:819
std::vector< o2::dcs::DataPointCompositeObject > generateRandomDataPoints< bool >(const std::vector< std::string > &aliases, bool minValue, bool maxValue, std::string refDate)
std::vector< DataPointCompositeObject > generateRandomDataPoints(const std::vector< std::string > &aliases, T min, T max, std::string refDate="")
std::vector< o2::dcs::DataPointCompositeObject > generateRandomDataPoints< std::string >(const std::vector< std::string > &aliases, std::string minLength, std::string maxLength, std::string refDate)
BOOST_AUTO_TEST_CASE(GenerateDouble)
BOOST_CHECK_NO_THROW(algorithm::merge(target, other))
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())