test_yaml_export.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifdef YAML_SUPPORT
26 
27 #include <corbo-core/macros.h>
28 
29 #include <corbo-core/signals.h>
30 #include <corbo-core/yaml_export.h>
31 
32 #include "gtest/gtest.h"
33 
34 
35 
36 class TestYAMLExport : public testing::Test
37 {
38  protected:
39  // You can do set-up work for each test here.
40  TestYAMLExport() {}
41  // You can do clean-up work that doesn't throw exceptions here.
42  virtual ~TestYAMLExport() {}
43  // If the constructor and destructor are not enough for setting up
44  // and cleaning up each test, you can define the following methods:
45 
46  // Code here will be called immediately after the constructor (right
47  // before each test).
48  // virtual void SetUp() {}
49  // Code here will be called immediately after each test (right
50  // before the destructor).
51  // virtual void TearDown();
52 };
53 
54 TEST_F(TestYAMLExport, test1)
55 {
56  corbo::YamlExporter yaml_exporter;
57  corbo::TimeSeriesSignal ts_signal;
58 
59  std::string filename = "testfile.yaml";
60 
61  EXPECT_TRUE(yaml_exporter.exportTimeSeriesSignal(filename, ts_signal));
62 }
63 
64 TEST_F(TestYAMLExport, export_matrix)
65 {
66  corbo::YamlExporter yaml_exporter;
67  std::string filename = "testfile.yaml";
68 
69  Eigen::Matrix3d mat = Eigen::Matrix3d::Identity();
70  mat(0, 1) = 2; // for testing column/row major
71  corbo::MatrixSignal mat_sig(mat, "test_matrix");
72  mat_sig.header.name = "test_header_name";
73  mat_sig.header.time = corbo::Time(1);
74 
75  EXPECT_TRUE(yaml_exporter.exportMatrixSignal(filename, mat_sig));
76 }
77 
78 TEST_F(TestYAMLExport, export_matrix_set)
79 {
80  corbo::YamlExporter yaml_exporter;
81  std::string filename = "testfile.yaml";
82 
83  Eigen::Matrix3d mat = Eigen::Matrix3d::Identity();
84  mat(0, 1) = 2; // for testing column/row major
85  corbo::MatrixSignal::Ptr mat_sig = std::make_shared<corbo::MatrixSignal>(mat, "test_matrix");
86  mat_sig->header.name = "mat_sig_name";
87  mat_sig->header.time = corbo::Time(1);
88 
89  corbo::MatrixSetSignal mat_set_sig;
90  mat_set_sig.header.name = "mat_set_sig_name";
91  mat_sig->header.time = corbo::Time(2);
92 
93  mat_set_sig.add(mat_sig);
94  mat_set_sig.add(mat_sig);
95 
96  Eigen::Matrix2d mat2d;
97  mat2d << 1, 2, 3, 4;
98  mat_set_sig.add(mat2d, "2d_mat");
99 
100  EXPECT_TRUE(yaml_exporter.exportMatrixSetSignal(filename, mat_set_sig));
101 }
102 
103 #endif // YAML_SUPPORT
bool exportTimeSeriesSignal(const std::string &filename, const TimeSeriesSignal &signal) override
bool exportMatrixSetSignal(const std::string &filename, const MatrixSetSignal &signal) override
Representation of time stamps.
Definition: time.h:251
Signal containing a set of matrices.
Definition: signals.h:607
SignalHeader header
The header of the signal.
Definition: signals.h:149
bool exportMatrixSignal(const std::string &filename, const MatrixSignal &signal) override
Export yaml files.
Definition: yaml_export.h:44
std::shared_ptr< MatrixSignal > Ptr
Definition: signals.h:542
Time Series signal (trajectory resp. sequence of values w.r.t. time)
Definition: signals.h:244
TEST_F(FooTest, blabla)
Signal containing a simple matrix.
Definition: signals.h:539
else mat
Definition: eigenvalues.cpp:43
std::string name
Unique signal identifier.
Definition: signals.h:77
void add(MatrixSignal::Ptr &matrix_signal)
Add matrix signal.
Definition: signals.cpp:252


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Mon Feb 28 2022 22:07:52