13 open my $in, '<', "$FindBin::Bin/milscan.html" or die "Can't read file: $!";
18 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
19 or die "Cannot create handle: $DBI::errstr\n";
22 my @fleets = parseMilScan($milscan);
24 #print Dumper(\@fleets), "\n";
26 is ($fleets[0]->{name}, 'Base');
27 is (scalar @{$fleets[0]->{ships}}, 4);
28 is ($fleets[0]->{ships}->[0]->{ship}, 'Centaur');
29 is ($fleets[0]->{ships}->[0]->{amount}, 199900);
30 is ($fleets[0]->{amount}, 253901);
31 is ($fleets[0]->{mission}, 'Military');
32 is ($fleets[1]->{name}, 'Fleet 1');
33 is (scalar @{$fleets[1]->{ships}}, 1);
34 is ($fleets[1]->{ships}->[0]->{ship}, 'Chimera');
35 is ($fleets[1]->{ships}->[0]->{amount}, 54500);
36 is ($fleets[1]->{amount}, 54500);
37 is ($fleets[1]->{mission}, 'Military');
38 is ($fleets[2]->{name}, 'Fleet 2');
39 is ($fleets[2]->{amount}, 0);
40 is ($fleets[2]->{mission}, 'Military');
41 is ($fleets[3]->{name}, 'Fleet 3');
42 is ($fleets[3]->{amount}, 0);
43 is ($fleets[3]->{mission}, 'Military');
44 is ($fleets[4]->{name}, 'Military');
45 is ($fleets[4]->{mission}, 'Full fleet');
46 is ($fleets[4]->{amount}, 253901+54500);
50 my $scan = {id => 31337, type => 'Military', pid => 1337, tick => 123};
52 $dbh->{mock_add_resultset} = {
53 sql => qr/^INSERT INTO fleets \(name, mission, pid, tick, amount\)/i,
54 results => [['fid'], [$fid]],
56 doMilScan($dbh, $scan, $milscan);
57 my $history = $dbh->{mock_all_history};
58 is(scalar(@{$history}), 3, 'Add military scan');
60 #print Dumper($history), "\n";
62 my $sth = $history->[0];
63 my $exec_history = $sth->{execution_history};
65 qr{^INSERT INTO fleets \(name, mission, pid, tick, amount\)}ism,
67 is(scalar(@{$exec_history}), 3);
68 is(scalar(@{$exec_history->[0]->{params}}), 5);
69 is($exec_history->[0]->{params}->[0], "Base");
70 is($exec_history->[0]->{params}->[1], "Military");
71 is($exec_history->[0]->{params}->[2], $scan->{pid});
72 is($exec_history->[0]->{params}->[3], $scan->{tick});
73 is($exec_history->[0]->{params}->[4], 253901);
75 is($exec_history->[1]->{params}->[0], "Fleet 1");
76 is($exec_history->[1]->{params}->[1], "Military");
77 is($exec_history->[1]->{params}->[2], $scan->{pid});
78 is($exec_history->[1]->{params}->[3], $scan->{tick});
79 is($exec_history->[1]->{params}->[4], 54500);
81 is($exec_history->[2]->{params}->[0], "Military");
82 is($exec_history->[2]->{params}->[1], "Full fleet");
83 is($exec_history->[2]->{params}->[2], $scan->{pid});
84 is($exec_history->[2]->{params}->[3], $scan->{tick});
85 is($exec_history->[2]->{params}->[4], 253901+54500);
89 my $sth = $history->[1];
90 my $exec_history = $sth->{execution_history};
92 qr{^INSERT INTO fleet_scans \(fid, id\)}ism,
94 is(scalar(@{$exec_history}), 3);
95 is(scalar(@{$exec_history->[0]->{params}}), 2);
96 is($exec_history->[0]->{params}->[0], $fid);
97 is($exec_history->[0]->{params}->[1], $scan->{id});
98 is($exec_history->[1]->{params}->[0], $fid);
99 is($exec_history->[1]->{params}->[1], $scan->{id});
100 is($exec_history->[2]->{params}->[0], $fid);
101 is($exec_history->[2]->{params}->[1], $scan->{id});
104 my $sth = $history->[2];
105 my $exec_history = $sth->{execution_history};
106 like($sth->statement,
107 qr{^INSERT INTO fleet_ships \(fid, ship, amount\)}ism,
109 is(scalar(@{$exec_history}), 10);
110 is(scalar(@{$exec_history->[0]->{params}}), 3);
111 is($exec_history->[0]->{params}->[0], $fid);
112 is($exec_history->[0]->{params}->[1], 'Centaur');
113 is($exec_history->[0]->{params}->[2], 199900);
114 is($exec_history->[1]->{params}->[0], $fid);
115 is($exec_history->[1]->{params}->[1], 'Titan');
116 is($exec_history->[1]->{params}->[2], 50000);
117 is($exec_history->[2]->{params}->[0], $fid);
118 is($exec_history->[2]->{params}->[1], 'Wyvern');
119 is($exec_history->[2]->{params}->[2], 3000);
120 is($exec_history->[3]->{params}->[0], $fid);
121 is($exec_history->[3]->{params}->[1], 'Medusa');
122 is($exec_history->[3]->{params}->[2], 1001);
123 is($exec_history->[4]->{params}->[0], $fid);
124 is($exec_history->[4]->{params}->[1], 'Chimera');
125 is($exec_history->[4]->{params}->[2], 54500);
126 is($exec_history->[5]->{params}->[0], $fid);
127 is($exec_history->[5]->{params}->[1], 'Centaur');
128 is($exec_history->[5]->{params}->[2], 199900);
129 is($exec_history->[6]->{params}->[0], $fid);
130 is($exec_history->[6]->{params}->[1], 'Chimera');
131 is($exec_history->[6]->{params}->[2], 54500);
132 is($exec_history->[7]->{params}->[0], $fid);
133 is($exec_history->[7]->{params}->[1], 'Titan');
134 is($exec_history->[7]->{params}->[2], 50000);
135 is($exec_history->[8]->{params}->[0], $fid);
136 is($exec_history->[8]->{params}->[1], 'Wyvern');
137 is($exec_history->[8]->{params}->[2], 3000);
138 is($exec_history->[9]->{params}->[0], $fid);
139 is($exec_history->[9]->{params}->[1], 'Medusa');
140 is($exec_history->[9]->{params}->[2], 1001);
145 my $planetscan = do {
146 open my $in, '<', "$FindBin::Bin/planetscan.html" or die "Can't read file: $!";
151 $dbh->{mock_clear_history} = 1;
153 my $scan = {id => 31337, type => 'Planet', pid => 1337, tick => 123};
154 doPlanetScan($dbh, $scan, $planetscan);
155 my $history = $dbh->{mock_all_history};
156 is(scalar(@{$history}), 1, 'Add planet scan');
158 my $sth = $history->[0];
159 my $exec_history = $sth->{execution_history};
160 like($sth->statement,
161 qr{\QINSERT INTO planet_scans\E\s*
162 \(id,tick,pid,metal_roids,metal,crystal_roids,crystal,eonium_roids,eonium
163 \s*,agents,guards,light,medium,heavy,hidden\).*}xsi,
165 is(scalar(@{$exec_history}), 1);
166 is(scalar(@{$exec_history->[0]->{params}}), 15);
167 is($exec_history->[0]->{params}->[0], $scan->{id});
168 is($exec_history->[0]->{params}->[1], $scan->{tick});
169 is($exec_history->[0]->{params}->[2], $scan->{pid});
170 is($exec_history->[0]->{params}->[3], 100);
171 is($exec_history->[0]->{params}->[4], 78363);
172 is($exec_history->[0]->{params}->[5], 130);
173 is($exec_history->[0]->{params}->[6], 147874);
174 is($exec_history->[0]->{params}->[7], 100);
175 is($exec_history->[0]->{params}->[8], 169077);
176 is($exec_history->[0]->{params}->[9], 100);
177 is($exec_history->[0]->{params}->[10], 805);
178 is($exec_history->[0]->{params}->[11], 'None');
179 is($exec_history->[0]->{params}->[12], 'High');
180 is($exec_history->[0]->{params}->[13], 'None');
181 is($exec_history->[0]->{params}->[14], '4612500');