TVerdict CEntryStatusStep::doTestStepL()
{
// don't continue if previous phases have aborted
if (TestStepResult() != EPass)
{
return TestStepResult();
}
// Delay briefly to ensure that any update entry steps in concurrent tests can
// check first (which sets the state to EAwaitingApproval.)
User::After(KStateCheckDelay);
_LIT(KCancelMessage, "Cancelling...");
// Cancel if set to do so before checking state.
if (iCancelPoint == EAfterOpen)
{
Logger().Write(KCancelMessage);
Session().Cancel();
}
iState = Session().GetStateL();
// log the action
_LIT(KMessageFmt, "State of cache entry for certificate '%S' is %d.");
Logger().WriteFormat(KMessageFmt, SubjectLC(), iState);
CleanupStack::PopAndDestroy(1); // subject
if (iCancelPoint == EAfterGetState)
{
Logger().Write(KCancelMessage);
Session().Cancel();
iState = Session().GetStateL();
Logger().WriteFormat(KMessageFmt, SubjectLC(), iState);
CleanupStack::PopAndDestroy(1); // subject
}
else if (iRequestChangeNotify)
{
if (iState == EEntryAwaitingApproval || !iRequirePendingApproval)
{
TRequestStatus status;
Session().RequestNotify(status);
if (iCancelPoint == EAfterChangeNotify)
{
Logger().Write(KCancelMessage);
Session().Cancel();
}
User::WaitForRequest(status);
User::LeaveIfError(status.Int());
iState = Session().GetStateL();
// log the action
_LIT(KMessageFormat, "Got cache change notify for certificate '%S', state = %d.");
Logger().WriteFormat(KMessageFormat, SubjectLC(), iState);
CleanupStack::PopAndDestroy(1); // certificate status
}
else
{
// log the action
_LIT(KMessageFormat, "Cannot wait for change notify, entry state is not %d (EEntryAwaitingApproval.)");
Logger().WriteFormat(KMessageFormat, EEntryAwaitingApproval);
SetTestStepResult(EFail) ;
}
}
return TestStepResult();
}
enum TVerdict CEsockTest11_4::easyTestStepL()
{
//
// Out Of Memory Test on open() RSocket //
//
TVerdict verdict = EPass;
Logger().WriteFormat(_L("TE_ESock: test 11.4"));
Logger().WriteFormat(_L("RSocket Open"));
#if defined (_DEBUG_SOCKET_FUNCTIONS)
RSocketServ socketHelper;
CleanupClosePushL(socketHelper);
TInt ret = socketHelper.Connect();
TESTEL(KErrNone == ret, ret);
// Create a socket on the helper to get the DND up & running
RSocket sockHelper;
CleanupClosePushL(sockHelper);
ret = sockHelper.Open(socketHelper, KAfInet, KSockStream, KProtocolInetTcp);
TESTEL(KErrNone == ret, ret);
// Short wait for DND settle down
User::After(5000000);
socketHelper.__DbgMarkHeap();
RSocketServ socketServer;
CleanupClosePushL(socketServer);
ret = socketServer.Connect();
TESTEL(KErrNone == ret, ret);
// See if we can crash the server:
RSocket sock;
CleanupClosePushL(sock);
TInt failure = 0;
verdict = EInconclusive;
TInt prevResult = KErrNoMemory;
TInt prevOccurs = 0;
while (EInconclusive == verdict)
{
socketServer.__DbgFailNext(failure++);
ret = sock.Open(socketServer, KAfInet, KSockStream, KProtocolInetTcp);
if ((prevResult != ret) || (++prevOccurs >= 1000))
{
Logger().WriteFormat(_L("%d loop(s), open socket returned %d"), prevOccurs, prevResult);
if (KErrNone == ret)
{
verdict = EPass;
}
else if (KErrServerTerminated == ret)
{
verdict = EFail;
}
else if (prevResult != ret)
{
prevResult = ret;
prevOccurs = 1;
}
else
{
prevOccurs = 0;
}
}
};
socketServer.__DbgFailNext(-1);
// wait for protocol families to unload - it's via an async callback and dependent upon the IP stack, which
// may also be killing off DND. So a big delay is needed. If it proves unreliable in future then the really
// strong approach would be shutting down ESOCK - it'll panic if it has allocations outstanding
User::After(5000000);
socketHelper.__DbgMarkEnd(0);
CleanupStack::PopAndDestroy(4, &socketHelper);
#else
Logger().WriteFormat(_L("Test disabled on release build."));
#endif
return verdict;
}
void DoneCombatTurn() {
Logger().debugStream() << "AIInterface::DoneCombatTurn()";
AIClientApp::GetApp()->StartCombatTurn(); // encodes combat order sets and sends combat turn orders message. "done" the combat turn for the client, but "starts" the combat turn for the server
}
CombatInfo::CombatInfo(int system_id_, int turn_) :
turn(turn_),
system_id(system_id_)
{
TemporaryPtr<System> system = ::GetSystem(system_id);
if (!system) {
Logger().errorStream() << "CombatInfo constructed with invalid system id: " << system_id;
return;
}
// add system to full / complete objects in combat - NOTE: changed from copy of system
objects.Insert(system);
// find ships and their owners in system
std::vector<TemporaryPtr<Ship> > ships =
Objects().FindObjects<Ship>(system->ShipIDs());
for (std::vector<TemporaryPtr<Ship> >::const_iterator ship_it = ships.begin();
ship_it != ships.end(); ++ship_it)
{
TemporaryPtr<Ship> ship = *ship_it;
// add owner to empires that have assets in this battle
empire_ids.insert(ship->Owner());
objects.Insert(ship);
}
// find planets and their owners in system
std::vector<TemporaryPtr<Planet> > planets =
Objects().FindObjects<Planet>(system->PlanetIDs());
for (std::vector<TemporaryPtr<Planet> >::const_iterator planet_it = planets.begin();
planet_it != planets.end(); ++planet_it)
{
TemporaryPtr<Planet> planet = *planet_it;
// if planet is populated, add owner to empires that have assets in this battle
if (planet->CurrentMeterValue(METER_POPULATION) > 0.0)
empire_ids.insert(planet->Owner());
objects.Insert(planet);
}
// TODO: should buildings be considered separately?
// now that all participants in the battle have been found, loop through
// objects again to assemble each participant empire's latest
// known information about all objects in this battle
// system
for (std::set<int>::const_iterator empire_it = empire_ids.begin();
empire_it != empire_ids.end(); ++empire_it)
{
int empire_id = *empire_it;
if (empire_id == ALL_EMPIRES)
continue;
empire_known_objects[empire_id].Insert(GetEmpireKnownSystem(system->ID(), empire_id));
}
// ships
for (std::vector<TemporaryPtr<Ship> >::const_iterator it = ships.begin();
it != ships.end(); ++it)
{
TemporaryPtr<Ship> ship = *it;
int ship_id = ship->ID();
TemporaryPtr<const Fleet> fleet = GetFleet(ship->FleetID());
if (!fleet) {
Logger().errorStream() << "CombatInfo::CombatInfo couldn't get fleet with id "
<< ship->FleetID() << " in system " << system->Name() << " (" << system_id << ")";
continue;
}
for (std::set<int>::const_iterator empire_it = empire_ids.begin();
empire_it != empire_ids.end(); ++empire_it)
{
int empire_id = *empire_it;
if (empire_id == ALL_EMPIRES)
continue;
if (GetUniverse().GetObjectVisibilityByEmpire(ship_id, empire_id) >= VIS_BASIC_VISIBILITY ||
(fleet->Aggressive() &&
(empire_id == ALL_EMPIRES ||
fleet->Unowned() ||
Empires().GetDiplomaticStatus(empire_id, fleet->Owner()) == DIPLO_WAR)))
{ empire_known_objects[empire_id].Insert(GetEmpireKnownShip(ship->ID(), empire_id));}
}
}
// planets
for (std::vector<TemporaryPtr<Planet> >::const_iterator it = planets.begin();
it != planets.end(); ++it)
{
TemporaryPtr<Planet> planet = *it;
int planet_id = planet->ID();
for (std::set<int>::const_iterator empire_it = empire_ids.begin(); empire_it != empire_ids.end(); ++empire_it) {
int empire_id = *empire_it;
if (empire_id == ALL_EMPIRES)
continue;
if (GetUniverse().GetObjectVisibilityByEmpire(planet_id, empire_id) >= VIS_BASIC_VISIBILITY) {
empire_known_objects[empire_id].Insert(GetEmpireKnownPlanet(planet->ID(), empire_id));
//.........这里部分代码省略.........
void AutoResolveCombat(CombatInfo& combat_info) {
if (combat_info.objects.Empty())
return;
TemporaryPtr<const System> system = combat_info.objects.Object<System>(combat_info.system_id);
if (!system)
Logger().errorStream() << "AutoResolveCombat couldn't get system with id " << combat_info.system_id;
else
Logger().debugStream() << "AutoResolveCombat at " << system->Name();
if (GetOptionsDB().Get<bool>("verbose-logging")) {
Logger().debugStream() << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
Logger().debugStream() << "AutoResolveCombat objects before resolution: " << combat_info.objects.Dump();
}
// reasonably unpredictable but reproducible random seeding
const int base_seed = combat_info.objects.begin()->ID() + CurrentTurn();
// compile list of valid objects to attack or be attacked in this combat
std::set<int> valid_target_object_ids; // all objects that can be attacked
std::set<int> valid_attacker_object_ids; // all objects that can attack
std::map<int, std::set<int> > empire_valid_attacker_object_ids; // objects that can attack that each empire owns
float monster_detection = 0.0;
for (ObjectMap::iterator<> it = combat_info.objects.begin(); it != combat_info.objects.end(); ++it) {
TemporaryPtr<const UniverseObject> obj = *it;
//Logger().debugStream() << "Considerting object " << obj->Name() << " owned by " << obj->Owner();
if (ObjectCanAttack(obj)) {
//Logger().debugStream() << "... can attack";
valid_attacker_object_ids.insert(it->ID());
empire_valid_attacker_object_ids[obj->Owner()].insert(it->ID());
}
if (ObjectCanBeAttacked(obj)) {
//Logger().debugStream() << "... can be attacked";
valid_target_object_ids.insert(it->ID());
}
if (obj->Unowned() && obj->ObjectType() == OBJ_SHIP)
monster_detection = std::max(monster_detection, obj->CurrentMeterValue(METER_DETECTION));
}
// map from empire to set of IDs of objects that empire's objects
// could potentially target.
std::map<int, std::set<int> > empire_valid_target_object_ids; // objects that each empire can attack
for (std::set<int>::const_iterator target_it = valid_target_object_ids.begin();
target_it != valid_target_object_ids.end(); ++target_it)
{
int object_id = *target_it;
TemporaryPtr<const UniverseObject> obj = combat_info.objects.Object(object_id);
//Logger().debugStream() << "Considering attackability of object " << obj->Name() << " owned by " << obj->Owner();
// for all empires, can they attack this object?
for (std::set<int>::const_iterator empire_it = combat_info.empire_ids.begin();
empire_it != combat_info.empire_ids.end(); ++empire_it)
{
int attacking_empire_id = *empire_it;
if (attacking_empire_id == ALL_EMPIRES) {
if (ObjectAttackableByMonsters(obj, monster_detection)) {
//Logger().debugStream() << "object: " << obj->Name() << " attackable by monsters";
empire_valid_target_object_ids[ALL_EMPIRES].insert(object_id);
}
} else {
// call function to find if empires can attack objects...
if (ObjectAttackableByEmpire(obj, attacking_empire_id)) {
//Logger().debugStream() << "object: " << obj->Name() << " attackable by empire " << attacking_empire_id;
empire_valid_target_object_ids[attacking_empire_id].insert(object_id);
}
}
}
}
// Each combat "round" a randomly-selected object in the battle attacks
// something, if it is able to do so. The number of rounds scales with the
// number of objects, so the total actions per object is independent of
// number of objects in the battle
const int NUM_COMBAT_ROUNDS = 3*valid_attacker_object_ids.size();
for (int round = 1; round <= NUM_COMBAT_ROUNDS; ++round) {
Seed(base_seed + round); // ensure each combat round produces different results
// ensure something can attack and something can be attacked
if (valid_attacker_object_ids.empty()) {
if (GetOptionsDB().Get<bool>("verbose-logging"))
Logger().debugStream() << "Nothing left can attack; combat over";
break;
}
if (empire_valid_target_object_ids.empty()) {
if (GetOptionsDB().Get<bool>("verbose-logging"))
Logger().debugStream() << "Nothing left can be attacked; combat over";
break;
}
// empires may have valid targets, but nothing to attack with. If all
// empires have no attackers or no valid targers, combat is over
bool someone_can_attack_something = false;
for (std::map<int, std::set<int> >::const_iterator attacker_it = empire_valid_attacker_object_ids.begin();
attacker_it != empire_valid_attacker_object_ids.end(); ++attacker_it)
{
//.........这里部分代码省略.........
请发表评论