CYCAMORE
src/deploy_inst_tests.cc
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include "context.h"
4 #include "deploy_inst.h"
5 #include "institution_tests.h"
6 #include "agent_tests.h"
7 
8 // make sure that the deployed agent's prototype name is identical to the
9 // originally specified prototype name - this is important to test because
10 // DeployInst does some mucking around with registering name-modded prototypes
11 // in order to deal with lifetime setting.
12 TEST(DeployInstTests, ProtoNames) {
13  std::string config =
14  "<prototypes> <val>foobar</val> </prototypes>"
15  "<build_times> <val>1</val> </build_times>"
16  "<n_build> <val>3</val> </n_build>"
17  "<lifetimes> <val>2</val> </lifetimes>"
18  ;
19 
20  int simdur = 5;
21  cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
22  sim.DummyProto("foobar");
23  int id = sim.Run();
24 
25  cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
26  "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar';"
27  );
28  stmt->Step();
29  EXPECT_EQ(3, stmt->GetInt(0));
30 }
31 
32 TEST(DeployInstTests, BuildTimes) {
33  std::string config =
34  "<prototypes> <val>foobar</val> <val>foobar</val> </prototypes>"
35  "<build_times> <val>1</val> <val>3</val> </build_times>"
36  "<n_build> <val>1</val> <val>7</val> </n_build>"
37  ;
38 
39  int simdur = 5;
40  cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
41  sim.DummyProto("foobar");
42  int id = sim.Run();
43 
44  cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
45  "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 1;"
46  );
47  stmt->Step();
48  EXPECT_EQ(1, stmt->GetInt(0));
49 
50  stmt = sim.db().db().Prepare(
51  "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 3;"
52  );
53  stmt->Step();
54  EXPECT_EQ(7, stmt->GetInt(0));
55 }
56 
57 // make sure that specified lifetimes are honored both in agent's table record
58 // and in decommissioning.
59 TEST(DeployInstTests, FiniteLifetimes) {
60  std::string config =
61  "<prototypes> <val>foobar</val> <val>foobar</val> <val>foobar</val> </prototypes>"
62  "<build_times> <val>1</val> <val>1</val> <val>2</val> </build_times>"
63  "<n_build> <val>1</val> <val>7</val> <val>3</val> </n_build>"
64  "<lifetimes> <val>1</val> <val>2</val> <val>-1</val> </lifetimes>"
65  ;
66 
67  int simdur = 5;
68  cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
69  sim.DummyProto("foobar");
70  int id = sim.Run();
71 
72  // check agent deployment
73  cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
74  "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 1 AND Lifetime = 1;"
75  );
76  stmt->Step();
77  EXPECT_EQ(1, stmt->GetInt(0));
78 
79  stmt = sim.db().db().Prepare(
80  "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 1 AND Lifetime = 2;"
81  );
82  stmt->Step();
83  EXPECT_EQ(7, stmt->GetInt(0));
84 
85  stmt = sim.db().db().Prepare(
86  "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = 2 AND Lifetime = -1;"
87  );
88  stmt->Step();
89  EXPECT_EQ(3, stmt->GetInt(0));
90 
91  // check decommissioning
92  stmt = sim.db().db().Prepare(
93  "SELECT COUNT(*) FROM AgentEntry As e JOIN AgentExit AS x ON x.AgentId = e.AgentId WHERE e.Prototype = 'foobar' AND x.ExitTime = 1;"
94  );
95  stmt->Step();
96  EXPECT_EQ(1, stmt->GetInt(0));
97 
98  stmt = sim.db().db().Prepare(
99  "SELECT COUNT(*) FROM AgentEntry As e JOIN AgentExit AS x ON x.AgentId = e.AgentId WHERE e.Prototype = 'foobar' AND x.ExitTime = 2;"
100  );
101  stmt->Step();
102  EXPECT_EQ(7, stmt->GetInt(0));
103 
104  // agent with -1 lifetime should not be in AgentExit table
105  stmt = sim.db().db().Prepare(
106  "SELECT COUNT(*) FROM AgentExit;"
107  );
108  stmt->Step();
109  EXPECT_EQ(8, stmt->GetInt(0));
110 }
111 
112 TEST(DeployInstTests, NoDupProtos) {
113  std::string config =
114  "<prototypes> <val>foobar</val> <val>foobar</val> <val>foobar</val> </prototypes>"
115  "<build_times> <val>1</val> <val>1</val> <val>2</val> </build_times>"
116  "<n_build> <val>1</val> <val>7</val> <val>3</val> </n_build>"
117  "<lifetimes> <val>1</val> <val>1</val> <val>-1</val> </lifetimes>"
118  ;
119 
120  int simdur = 5;
121  cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
122  sim.DummyProto("foobar");
123  int id = sim.Run();
124 
125  // don't duplicate same prototypes with same custom lifetime
126  cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
127  "SELECT COUNT(*) FROM Prototypes WHERE Prototype = 'foobar_life_1';"
128  );
129  stmt->Step();
130  EXPECT_EQ(1, stmt->GetInt(0));
131 
132  // don't duplicate custom lifetimes that are identical to original prototype
133  // lifetime.
134  stmt = sim.db().db().Prepare(
135  "SELECT COUNT(*) FROM Prototypes WHERE Prototype = 'foobar';"
136  );
137  stmt->Step();
138  EXPECT_EQ(1, stmt->GetInt(0));
139 }
140 
141 // required to get functionality in cyclus agent unit tests library
142 cyclus::Agent* DeployInstitutionConstructor(cyclus::Context* ctx) {
143  return new cycamore::DeployInst(ctx);
144 }
145 
146 #ifndef CYCLUS_AGENT_TESTS_CONNECTED
147 int ConnectAgentTests();
149 #define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected
150 #endif // CYCLUS_AGENT_TESTS_CONNECTED
151 
152 INSTANTIATE_TEST_CASE_P(DeployInst, InstitutionTests,
154 INSTANTIATE_TEST_CASE_P(DeployInst, AgentTests,
int ConnectAgentTests()
cyclus::Agent * DeployInstitutionConstructor(cyclus::Context *ctx)
static int cyclus_agent_tests_connected
cycamore::GrowthRegion string
INSTANTIATE_TEST_CASE_P(DeployInst, InstitutionTests, Values(&DeployInstitutionConstructor))
TEST(DeployInstTests, ProtoNames)