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[1]->{name}, 'Fleet 1');
32 is (scalar @{$fleets[1]->{ships}}, 1);
33 is ($fleets[1]->{ships}->[0]->{ship}, 'Chimera');
34 is ($fleets[1]->{ships}->[0]->{amount}, 54500);
35 is ($fleets[1]->{amount}, 54500);
36 is ($fleets[2]->{name}, 'Fleet 2');
37 is ($fleets[2]->{amount}, 0);
38 is ($fleets[3]->{name}, 'Fleet 3');
39 is ($fleets[3]->{amount}, 0);
43 my $scan = {id => 31337, type => 'Military', pid => 1337, tick => 123};
45 $dbh->{mock_add_resultset} = {
46 sql => qr/^INSERT INTO fleets \(name, mission, pid, tick, amount\)/i,
47 results => [['fid'], [$fid]],
49 doMilScan($dbh, $scan, $milscan);
50 my $history = $dbh->{mock_all_history};
51 is(scalar(@{$history}), 3, 'Correct number of statements executed');
53 #print Dumper($history), "\n";
55 my $sth = $history->[0];
56 my $exec_history = $sth->{execution_history};
58 qr{INSERT INTO fleets \(name, mission, pid, tick, amount\).*}sm,
60 is(scalar(@{$exec_history}), 2);
61 is($exec_history->[0]->{params}->[0], "Base");
62 is($exec_history->[0]->{params}->[1], "Military");
63 is($exec_history->[0]->{params}->[2], $scan->{pid});
64 is($exec_history->[0]->{params}->[3], $scan->{tick});
65 is($exec_history->[0]->{params}->[4], 253901);
67 is($exec_history->[1]->{params}->[0], "Fleet 1");
68 is($exec_history->[1]->{params}->[1], "Military");
69 is($exec_history->[1]->{params}->[2], $scan->{pid});
70 is($exec_history->[1]->{params}->[3], $scan->{tick});
71 is($exec_history->[1]->{params}->[4], 54500);
75 my $sth = $history->[1];
76 my $exec_history = $sth->{execution_history};
78 qr{INSERT INTO fleet_scans \(fid, id\).*}sm,
80 is(scalar(@{$exec_history}), 2);
81 is($exec_history->[0]->{params}->[0], $fid);
82 is($exec_history->[0]->{params}->[1], $scan->{id});
83 is($exec_history->[1]->{params}->[0], $fid);
84 is($exec_history->[1]->{params}->[1], $scan->{id});
87 my $sth = $history->[2];
88 my $exec_history = $sth->{execution_history};
90 qr{INSERT INTO fleet_ships \(fid, ship, amount\).*}sm,
92 is(scalar(@{$exec_history}), 5);
93 is($exec_history->[0]->{params}->[0], $fid);
94 is($exec_history->[0]->{params}->[1], 'Centaur');
95 is($exec_history->[0]->{params}->[2], 199900);
96 is($exec_history->[1]->{params}->[0], $fid);
97 is($exec_history->[1]->{params}->[1], 'Titan');
98 is($exec_history->[1]->{params}->[2], 50000);
99 is($exec_history->[2]->{params}->[0], $fid);
100 is($exec_history->[2]->{params}->[1], 'Wyvern');
101 is($exec_history->[2]->{params}->[2], 3000);
102 is($exec_history->[3]->{params}->[0], $fid);
103 is($exec_history->[3]->{params}->[1], 'Medusa');
104 is($exec_history->[3]->{params}->[2], 1001);
105 is($exec_history->[4]->{params}->[0], $fid);
106 is($exec_history->[4]->{params}->[1], 'Chimera');
107 is($exec_history->[4]->{params}->[2], 54500);
112 my $planetscan = do {
113 open my $in, '<', "$FindBin::Bin/planetscan.html" or die "Can't read file: $!";
118 $dbh->{mock_clear_history} = 1;
120 my $scan = {id => 31337, type => 'Planet', pid => 1337, tick => 123};
121 doPlanetScan($dbh, $scan, $planetscan);
122 my $history = $dbh->{mock_all_history};
123 is(scalar(@{$history}), 1, 'Add planet scan');
125 my $sth = $history->[0];
126 my $exec_history = $sth->{execution_history};
127 like($sth->statement,
128 qr{\QINSERT INTO planet_scans\E\s*
129 \(id,tick,pid,metal_roids,metal,crystal_roids,crystal,eonium_roids,eonium
130 \s*,agents,guards,light,medium,heavy,hidden\).*}xsi,
132 is(scalar(@{$exec_history}), 1);
133 is(scalar(@{$exec_history->[0]->{params}}), 15);
134 is($exec_history->[0]->{params}->[0], $scan->{id});
135 is($exec_history->[0]->{params}->[1], $scan->{tick});
136 is($exec_history->[0]->{params}->[2], $scan->{pid});
137 is($exec_history->[0]->{params}->[3], 100);
138 is($exec_history->[0]->{params}->[4], 78363);
139 is($exec_history->[0]->{params}->[5], 130);
140 is($exec_history->[0]->{params}->[6], 147874);
141 is($exec_history->[0]->{params}->[7], 100);
142 is($exec_history->[0]->{params}->[8], 169077);
143 is($exec_history->[0]->{params}->[9], 100);
144 is($exec_history->[0]->{params}->[10], 805);
145 is($exec_history->[0]->{params}->[11], 'None');
146 is($exec_history->[0]->{params}->[12], 'High');
147 is($exec_history->[0]->{params}->[13], 'None');
148 is($exec_history->[0]->{params}->[14], '4612500');