OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
TestOpalVariableRFCavity.cpp
Go to the documentation of this file.
1//
2// Unit tests for OpalVariableRFCavity element definition
3//
4// Copyright (c) 2014, Chris Rogers, STFC Rutherford Appleton Laboratory, Didcot, UK
5// All rights reserved.
6//
7// This file is part of OPAL.
8//
9// OPAL 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// You should have received a copy of the GNU General Public License
15// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16//
21#include "Structure/DataSink.h"
22#include "gtest/gtest.h"
23
24class TestOpalVariableRFCavity : public testing::Test {
25public:
27
28 static void SetUpTestSuite() {
29 int argc = 0;
30 char** argv = nullptr;
31 ippl::initialize(argc, argv);
32 // Many OPAL writers assume `gmsg` is initialized (see SDDSWriter/StatWriter).
33 // Unit tests normally don't set this up via Main().
34 gmsg = new Inform(nullptr, -1);
35 }
36 static void TearDownTestSuite() {
37 delete gmsg;
38 gmsg = nullptr;
39 ippl::finalize();
40 }
41};
42
43TEST_F(TestOpalVariableRFCavity, ConstructorDestructor) {
45 EXPECT_EQ(cav1.getOpalName(), "VARIABLE_RF_CAVITY");
46 OpalVariableRFCavity cav2("name", &cav1);
47 EXPECT_EQ(cav2.getOpalName(), "name");
48 const std::unique_ptr<OpalVariableRFCavity> cav3{cav2.clone()};
49 EXPECT_EQ(cav3->getOpalName(), "name");
50 const std::unique_ptr<OpalVariableRFCavity> cav4{cav2.clone("other_name")};
51 EXPECT_EQ(cav4->getOpalName(), "other_name");
52}
53
55 // Declare some time dependencies
56 auto pd1 = std::make_shared<PolynomialTimeDependence>(std::vector{1.0});
57 auto pd2 = std::make_shared<PolynomialTimeDependence>(std::vector{2.0});
58 auto pd3 = std::make_shared<PolynomialTimeDependence>(std::vector{3.0});
62 // Make the UI
64 // Set the attributes
71 // Update the cavity
72 EXPECT_NO_THROW(ui.update());
73 // Check the values
74 auto* myCavity = dynamic_cast<VariableRFCavity*>(ui.getElement());
75 EXPECT_TRUE(myCavity);
76 EXPECT_NO_THROW(myCavity->initialiseTimeDependencies());
77 EXPECT_DOUBLE_EQ(myCavity->getPhaseModel()->getValue(0.0), 1.0);
78 EXPECT_DOUBLE_EQ(myCavity->getAmplitudeModel()->getValue(0.0), 2.0);
79 EXPECT_DOUBLE_EQ(myCavity->getFrequencyModel()->getValue(0.0), 3.0);
80 EXPECT_DOUBLE_EQ(myCavity->getWidth(), 4.0);
81 EXPECT_DOUBLE_EQ(myCavity->getHeight(), 5.0);
82 EXPECT_DOUBLE_EQ(myCavity->getLength(), 6.0);
83}
Inform * gmsg
Definition changes.cpp:7
TEST_F(TestOpalVariableRFCavity, ConstructorDestructor)
static void setTimeDependence(const std::string &name, std::shared_ptr< AbstractTimeDependence > time_dep)
ElementBase * getElement() const
Return the embedded OPALX element.
Definition Element.h:119
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:267
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
OpalVariableRFCavity * clone()
TestOpalVariableRFCavity()=default
void setUpperCaseString(Attribute &attr, const std::string &val)
Set uppercase string value.
void setReal(Attribute &attr, double val)
Set real value.