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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
#include "avatarTest.h"
#include "signalHelpers.h"
#include "testUtils.h"
#include "signalHelpers.h"
#include "setupHelpers.h"
#include "viewTest.h"
#include "controller.h"
#include <Eris/Account.h>
#include <Eris/Avatar.h>
#include <Eris/Entity.h>
#include <Eris/Operations.h>
#include <Eris/View.h>
#include <Eris/TypeInfo.h>
#include <Eris/PollDefault.h>
#include <sigc++/functors/mem_fun.h>
#include <Atlas/Objects/Operation.h>
#include <Atlas/Objects/Anonymous.h>
#include <Atlas/Objects/Entity.h>
#include <wfmath/timestamp.h>
using WFMath::TimeStamp;
using WFMath::TimeDiff;
using namespace Atlas::Objects::Operation;
using Atlas::Objects::Entity::Anonymous;
using Atlas::Objects::Root;
void testWield(Controller& ctl)
{
AutoConnection con = stdConnect();
AutoAccount acc = stdLogin("account_B", "sweede", con.get());
ctl.setEntityVisibleToAvatar("_hut_01", "acc_b_character");
ctl.setEntityVisibleToAvatar("_hammer_1", "acc_b_character");
AutoAvatar av = AvatarGetter(acc.get()).take("acc_b_character");
Eris::View* v = av->getView();
{
WaitForAppearance wf(v, "_hammer_1");
wf.run();
}
Eris::EntityRef hammerRef(v->getEntity("_hammer_1"));
assert(hammerRef);
av->wield(hammerRef.get());
TimeStamp end = TimeStamp::now() + TimeDiff(5 * 1000);
while (!av->getWielded() && (TimeStamp::now() < end)) {
Eris::PollDefault::poll();
}
assert(av->getWielded()->getId() == "_hammer_1");
const Eris::TypeInfoArray& ops = av->getWielded()->getUseOperations();
assert(ops[0]->getName() == "strike");
assert(ops[1]->getName() == "tap");
}
void testDeleteWielded(Controller& ctl)
{
AutoConnection con = stdConnect();
AutoAccount acc = stdLogin("account_B", "sweede", con.get());
ctl.setEntityVisibleToAvatar("_hut_01", "acc_b_character");
ctl.setEntityVisibleToAvatar("_hammer_1", "acc_b_character");
AutoAvatar av = AvatarGetter(acc.get()).take("acc_b_character");
Eris::View* v = av->getView();
{
WaitForAppearance wf(v, "_hammer_1");
wf.run();
}
Eris::EntityRef hammerRef(v->getEntity("_hammer_1"));
assert(hammerRef);
av->wield(hammerRef.get());
TimeStamp end = TimeStamp::now() + TimeDiff(5 * 1000);
while (!av->getWielded() && (TimeStamp::now() < end)) {
Eris::PollDefault::poll();
}
Eris::TestInjector i(con.get());
SignalCounter0 hammerDeleted, hammerRefChanged;
hammerRef->BeingDeleted.connect(sigc::mem_fun(hammerDeleted, &SignalCounter0::fired));
hammerRef.Changed.connect(sigc::mem_fun(hammerRefChanged, &SignalCounter0::fired));
{
Delete del;
Anonymous arg;
arg->setId("_hammer_1");
del->setArgs1(arg);
Sight st;
st->setArgs1(del);
st->setTo("acc_b_character");
i.inject(st);
}
assert(hammerDeleted.fireCount());
assert(!hammerRef);
assert(hammerRefChanged.fireCount());
assert(!av->getWielded());
}
class Hearer : public sigc::trackable
{
public:
Hearer() :
m_count(0),
m_source(NULL)
{;}
void fired(Eris::Entity* ent, const RootOperation& op)
{
++m_count;
m_op = op;
m_source = ent;
}
int fireCount() const
{ return m_count; }
const RootOperation argOp() const
{
return m_op;
}
Eris::Entity* source() const
{
return m_source;
}
void reset()
{
m_count = 0;
}
private:
int m_count;
RootOperation m_op;
Eris::Entity* m_source;
};
void testHear(Controller& ctl)
{
AutoConnection con = stdConnect();
AutoAccount acc = stdLogin("account_B", "sweede", con.get());
ctl.setEntityVisibleToAvatar("_hut_01", "acc_b_character");
ctl.setEntityVisibleToAvatar("_table_1", "acc_b_character");
ctl.setEntityVisibleToAvatar("_vase_1", "acc_b_character");
AutoAvatar av = AvatarGetter(acc.get()).take("acc_b_character");
Eris::View* v = av->getView();
{
WaitForAppearance wf(v, "_vase_1");
wf.run();
}
Eris::TestInjector i(con.get());
Hearer heard;
av->Hear.connect(sigc::mem_fun(heard, &Hearer::fired));
{
Talk talk;
Atlas::Objects::Entity::Anonymous arg;
arg->setAttr("what", "shitcock!");
talk->setArgs1(arg);
talk->setFrom("_vase_1");
Sound snd;
snd->setArgs1(talk);
snd->setTo("acc_b_character");
snd->setFrom("_vase_1");
i.inject(snd);
}
assert(heard.fireCount());
RootOperation heardOp = heard.argOp();
assert(heardOp->getClassNo() == TALK_NO);
const std::vector<Root>& args = heardOp->getArgs();
assert(args.front()->hasAttr("what"));
assert(args.front()->getAttr("what") == "shitcock!");
assert(heard.source()->getId() == "_vase_1");
}
|