STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_environmental_config.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <stdexcept>
3#include <string>
4
5#include "config/Config.hpp"
6
7using namespace fsw::config;
8
9void require(bool condition) {
10 if (!condition)
11 throw std::runtime_error("Environmental config assertion failed");
12}
13
14std::string board(const std::string& name, const std::string& id, bool enabled = true) {
15 return "[boards." + name + "]\ntype = \"ENVIRONMENTAL\"\n" + id +
16 "\nenabled = " + (enabled ? "true" : "false") + "\nactive_connectors = [1]\n";
17}
18
19int main() {
20 for (const auto& id :
21 {"board_id = 0", "board_id = -1", "board_id = 256", "board_id = 4294967321",
22 "board_id = 25.5", "board_id = 25.0", "board_id = \"25\"", "board_id = true", ""}) {
23 bool rejected = false;
24 try {
25 load_from_string(board("env", id));
26 } catch (const std::invalid_argument& e) {
27 rejected = std::string(e.what()).find("integer from 1 to 255") != std::string::npos;
28 }
29 require(rejected);
30 }
31 bool duplicate_rejected = false;
32 try {
33 load_from_string(board("first", "board_id = 25") + board("second", "id = 25"));
34 } catch (const std::invalid_argument& e) {
35 duplicate_rejected = std::string(e.what()).find("claimed by both") != std::string::npos;
36 }
37 require(duplicate_rejected);
38
39 auto cfg = load_from_string(board("one", "board_id = 1") + board("max", "board_id = 255") +
40 board("first", "board_id = 25") + board("second", "board_id = 35") +
41 board("disabled", "board_id = 25", false) +
42 board("invalid_disabled", "board_id = 256", false));
44 for (auto& b : cfg.boards)
45 if (b.enabled) {
46 b.board_id = 256;
47 break;
48 }
49 bool narrowing_rejected = false;
50 try {
51 active_boards(cfg);
52 } catch (const std::invalid_argument&) {
53 narrowing_rejected = true;
54 }
55 require(narrowing_rejected);
56 std::cout << "Environmental ID validation passed\n";
57}
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
Definition json.hpp:13878
T & at(const key_type &key)
Definition json.hpp:19110
std::map< ActiveBoardKind, std::vector< elodin::BoardChannels > > active_boards(const Config &cfg)
Derive the active-board table (enabled boards -> Elodin BoardChannels), with the same slot-collision ...
Definition Config.cpp:468
Config load_from_string(const std::string &text)
Parse config from an in-memory TOML string (SequencerService / ActuatorCommander hold it so).
Definition Config.cpp:458
std::string board(const std::string &name, const std::string &id, bool enabled=true)
void require(bool condition)