1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
#include <Ice/Ice.h>
#include <TestControllerI.h>
#include <TestHelper.h>
#include <vector>
#include <string>
using namespace Ice;
using namespace Test;
using namespace std;
//
// TODO: More test cases.
//
TestControllerI::TestControllerI(const string& endpoint)
{
TestConfiguration current;
current.description = "No filters at all";
current.cases.push_back(TestCase("foo/bar:" + endpoint, true));
_configurations.push_back(current);
current = TestConfiguration();
current.description = "Category filter";
current.cases.push_back(TestCase("foo/barA:" + endpoint, true));
current.cases.push_back(TestCase("bar/fooA:" + endpoint, false));
current.cases.push_back(TestCase("\"a cat with spaces/fooX\":" + endpoint, true));
current.categoryFiltersAccept.push_back("foo");
current.categoryFiltersAccept.push_back("a cat with spaces");
_configurations.push_back(current);
current = TestConfiguration();
current.description = "Adapter id filter";
current.cases.push_back(TestCase("fooB @ bar", true));
current.cases.push_back(TestCase("bazB @ baz", false));
current.adapterIdFiltersAccept.push_back("bar");
_configurations.push_back(current);
current = TestConfiguration();
current.description = "Object id filter";
current.cases.push_back(TestCase("foo/barC:" + endpoint, true));
current.cases.push_back(TestCase("bar/fooC:" + endpoint, false));
Identity id;
id.category = "foo";
id.name = "barC";
current.objectIdFiltersAccept.push_back(id);
_configurations.push_back(current);
};
void
TestControllerI::step(const Glacier2::SessionPrx& currentSession, const TestToken& currentState, TestToken& newState,
const Ice::Current&)
{
switch(currentState.code)
{
case Test::Finished:
{
assert(false);
break;
}
case Test::Running:
{
TestConfiguration& config = _configurations[static_cast<size_t>(currentState.config)];
assert(!config.description.empty());
bool found = false;
SessionTuple session;
{
IceUtil::Mutex::Lock sync(_mutex);
for(vector<SessionTuple>::const_iterator i = _sessions.begin(); i != _sessions.end() && !found; ++i)
{
if(i->session == currentSession)
{
session = *i;
found = true;
}
}
}
assert(found);
//
// New sessions force configuration step.
//
bool reconfigure = !session.configured;
//
// We start with the previous known state.
//
newState = currentState;
++newState.caseIndex;
if(!(newState.caseIndex < (long)config.cases.size()))
{
//
// We are out of test cases for this configuration. Move to
// the next configuration.
//
++newState.config;
if(!(newState.config < (long)_configurations.size()))
{
newState.code = Test::Finished;
newState.expectedResult = false;
newState.description = "No more tests";
newState.testReference = "";
newState.config = -1;
newState.caseIndex = -1;
return;
}
//
// New test configuration!
//
config = _configurations[static_cast<size_t>(newState.config)];
newState.description = config.description;
newState.caseIndex = 0;
reconfigure = true;
}
newState.expectedResult = config.cases[static_cast<size_t>(newState.caseIndex)].expectedResult;
newState.testReference = config.cases[static_cast<size_t>(newState.caseIndex)].proxy;
if(reconfigure)
{
Glacier2::StringSetPrx categories = session.sessionControl->categories();
categories->add(config.categoryFiltersAccept);
Glacier2::StringSetPrx adapterIds = session.sessionControl->adapterIds();
adapterIds->add(config.adapterIdFiltersAccept);
Glacier2::IdentitySetPrx ids = session.sessionControl->identities();
ids->add(config.objectIdFiltersAccept);
session.configured = true;
}
break;
}
default:
{
newState.code = Running;
newState.config = 0;
newState.caseIndex = 0;
newState.testReference = "";
newState.description = "Initial running state";
newState.expectedResult = false;
break;
}
}
}
void
TestControllerI::shutdown(const Ice::Current& current)
{
current.adapter->getCommunicator()->shutdown();
}
void
TestControllerI::addSession(const SessionTuple& s)
{
IceUtil::Mutex::Lock sync(_mutex);
_sessions.push_back(s);
}
void
TestControllerI::notifyDestroy(const Glacier2::SessionControlPrx& control)
{
IceUtil::Mutex::Lock sync(_mutex);
for (vector<SessionTuple>::iterator i = _sessions.begin(); i != _sessions.end(); ++i)
{
if(i->sessionControl == control)
{
_sessions.erase(i);
break;
}
}
}
|