CYCAMORE
Loading...
Searching...
No Matches
src/deploy_inst_tests.cc
Go to the documentation of this file.
1#include "deploy_inst_tests.h"
2
3// make sure that the deployed agent's prototype name is identical to the
4// originally specified prototype name - this is important to test because
5// DeployInst does some mucking around with registering name-modded prototypes
6// in order to deal with lifetime setting.
7
8// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 ctx_ = new cyclus::Context(&ti_, &rec_);
13 commodity = cyclus::toolkit::Commodity("commod");
14 capacity = 5;
15 producer->cyclus::toolkit::CommodityProducer::Add(commodity);
16 producer->SetCapacity(commodity, capacity);
17}
18
19// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21 delete producer;
22 delete src_inst;
23 delete ctx_;
24}
25
26using cyclus::QueryResult;
27
28TEST_F(DeployInstTests, ProtoNames) {
29 std::string config =
30 "<prototypes> <val>foobar</val> </prototypes>"
31 "<build_times> <val>1</val> </build_times>"
32 "<n_build> <val>3</val> </n_build>"
33 "<lifetimes> <val>2</val> </lifetimes>"
34 ;
35
36 int simdur = 5;
37 cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
38 sim.DummyProto("foobar");
39 int id = sim.Run();
40
41 cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
42 "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar';"
43 );
44 stmt->Step();
45 EXPECT_EQ(3, stmt->GetInt(0));
46}
47
48TEST_F(DeployInstTests, BuildTimes) {
49 std::string config =
50 "<prototypes> <val>foobar</val> <val>foobar</val> </prototypes>"
51 "<build_times> <val>1</val> <val>3</val> </build_times>"
52 "<n_build> <val>1</val> <val>7</val> </n_build>"
53 ;
54
55 int simdur = 5;
56 cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
57 sim.DummyProto("foobar");
58 int id = sim.Run();
59
60 cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
61 "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 1;"
62 );
63 stmt->Step();
64 EXPECT_EQ(1, stmt->GetInt(0));
65
66 stmt = sim.db().db().Prepare(
67 "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 3;"
68 );
69 stmt->Step();
70 EXPECT_EQ(7, stmt->GetInt(0));
71}
72
73// make sure that specified lifetimes are honored both in agent's table record
74// and in decommissioning.
75TEST_F(DeployInstTests, FiniteLifetimes) {
76 std::string config =
77 "<prototypes> <val>foobar</val> <val>foobar</val> <val>foobar</val> </prototypes>"
78 "<build_times> <val>1</val> <val>1</val> <val>2</val> </build_times>"
79 "<n_build> <val>1</val> <val>7</val> <val>3</val> </n_build>"
80 "<lifetimes> <val>1</val> <val>2</val> <val>-1</val> </lifetimes>"
81 ;
82
83 int simdur = 5;
84 cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
85 sim.DummyProto("foobar");
86 int id = sim.Run();
87
88 // check agent deployment
89 cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
90 "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 1 AND Lifetime = 1;"
91 );
92 stmt->Step();
93 EXPECT_EQ(1, stmt->GetInt(0));
94
95 stmt = sim.db().db().Prepare(
96 "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 1 AND Lifetime = 2;"
97 );
98 stmt->Step();
99 EXPECT_EQ(7, stmt->GetInt(0));
100
101 stmt = sim.db().db().Prepare(
102 "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 2 AND Lifetime = -1;"
103 );
104 stmt->Step();
105 EXPECT_EQ(3, stmt->GetInt(0));
106
107 // check decommissioning
108 stmt = sim.db().db().Prepare(
109 "SELECT COUNT(*) FROM AgentEntry As e JOIN AgentExit AS x ON x.AgentId = e.AgentId WHERE e.Prototype = 'foobar' AND x.ExitTime = 1;"
110 );
111 stmt->Step();
112 EXPECT_EQ(1, stmt->GetInt(0));
113
114 stmt = sim.db().db().Prepare(
115 "SELECT COUNT(*) FROM AgentEntry As e JOIN AgentExit AS x ON x.AgentId = e.AgentId WHERE e.Prototype = 'foobar' AND x.ExitTime = 2;"
116 );
117 stmt->Step();
118 EXPECT_EQ(7, stmt->GetInt(0));
119
120 // agent with -1 lifetime should not be in AgentExit table
121 stmt = sim.db().db().Prepare(
122 "SELECT COUNT(*) FROM AgentExit;"
123 );
124 stmt->Step();
125 EXPECT_EQ(8, stmt->GetInt(0));
126}
127
128TEST_F(DeployInstTests, NoDupProtos) {
129 std::string config =
130 "<prototypes> <val>foobar</val> <val>foobar</val> <val>foobar</val> </prototypes>"
131 "<build_times> <val>1</val> <val>1</val> <val>2</val> </build_times>"
132 "<n_build> <val>1</val> <val>7</val> <val>3</val> </n_build>"
133 "<lifetimes> <val>1</val> <val>1</val> <val>-1</val> </lifetimes>"
134 ;
135
136 int simdur = 5;
137 cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
138 sim.DummyProto("foobar");
139 int id = sim.Run();
140
141 // don't duplicate same prototypes with same custom lifetime
142 cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
143 "SELECT COUNT(*) FROM Prototypes WHERE Prototype = 'foobar_life_1';"
144 );
145 stmt->Step();
146 EXPECT_EQ(1, stmt->GetInt(0));
147
148 // don't duplicate custom lifetimes that are identical to original prototype
149 // lifetime.
150 stmt = sim.db().db().Prepare(
151 "SELECT COUNT(*) FROM Prototypes WHERE Prototype = 'foobar';"
152 );
153 stmt->Step();
154 EXPECT_EQ(1, stmt->GetInt(0));
155}
156
157TEST_F(DeployInstTests, PositionInitialize) {
158 std::string config =
159 "<prototypes> <val>foobar</val> </prototypes>"
160 "<build_times> <val>1</val> </build_times>"
161 "<n_build> <val>3</val> </n_build>"
162 "<lifetimes> <val>2</val> </lifetimes>";
163
164 int simdur = 5;
165 cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
166 sim.DummyProto("foobar");
167 int id = sim.Run();
168
169 QueryResult qr = sim.db().Query("AgentPosition", NULL);
170 EXPECT_EQ(qr.GetVal<double>("Latitude"), 0.0);
171 EXPECT_EQ(qr.GetVal<double>("Longitude"), 0.0);
172}
173
174TEST_F(DeployInstTests, PositionInitialize2) {
175 std::string config =
176 "<prototypes> <val>foobar</val> </prototypes>"
177 "<longitude> -20.0 </longitude>"
178 "<latitude> 2.0 </latitude>"
179 "<build_times> <val>1</val> </build_times>"
180 "<n_build> <val>3</val> </n_build>"
181 "<lifetimes> <val>2</val> </lifetimes>";
182
183 int simdur = 5;
184 cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
185 sim.DummyProto("foobar");
186 int id = sim.Run();
187
188 QueryResult qr = sim.db().Query("AgentPosition", NULL);
189 EXPECT_EQ(qr.GetVal<double>("Latitude"), 2.0);
190 EXPECT_EQ(qr.GetVal<double>("Longitude"), -20.0);
191}
192
193TEST_F(DeployInstTests, producerexists) {
194 using std::set;
195 ctx_->AddPrototype("foop", producer);
196 set<cyclus::toolkit::CommodityProducer*>::iterator it;
197 for (it = src_inst->cyclus::toolkit::CommodityProducerManager::
198 producers().begin();
199 it != src_inst->cyclus::toolkit::CommodityProducerManager::
200 producers().end();
201 it++) {
202 EXPECT_EQ(dynamic_cast<TestProducer*>(*it)->prototype(),
203 producer->prototype());
204 }
205}
206
207TEST_F(DeployInstTests, productioncapacity) {
208 EXPECT_EQ(src_inst->TotalCapacity(commodity), 0);
209 src_inst->BuildNotify(producer);
210 EXPECT_EQ(src_inst->TotalCapacity(commodity), capacity);
211 src_inst->DecomNotify(producer);
212 EXPECT_EQ(src_inst->TotalCapacity(commodity), 0);
213}
214
215// required to get functionality in cyclus agent unit tests library
216cyclus::Agent* DeployInstitutionConstructor(cyclus::Context* ctx) {
217 return new cycamore::DeployInst(ctx);
218}
219
220#ifndef CYCLUS_AGENT_TESTS_CONNECTED
223#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected
224#endif // CYCLUS_AGENT_TESTS_CONNECTED
225
226INSTANTIATE_TEST_SUITE_P(DeployInst, InstitutionTests,
228INSTANTIATE_TEST_SUITE_P(DeployInst, AgentTests,
cyclus::toolkit::Commodity commodity
cycamore::DeployInst * src_inst
static int cyclus_agent_tests_connected
INSTANTIATE_TEST_SUITE_P(DeployInst, InstitutionTests, Values(&DeployInstitutionConstructor))
TEST_F(DeployInstTests, ProtoNames)
cyclus::Agent * DeployInstitutionConstructor(cyclus::Context *ctx)
int ConnectAgentTests()