This commit is contained in:
Chris Jones 2010-05-22 14:35:40 -05:00
Родитель 91c7c512cc
Коммит 7b752496f2
19 изменённых файлов: 613 добавлений и 113 удалений

Просмотреть файл

@ -58,12 +58,6 @@
#endif
namespace mozilla {
// XXX might want to move these to nscore.h or something, they can be
// generally useful
struct void_t { };
struct null_t { };
namespace plugins {
enum ScriptableObjectType
@ -653,32 +647,6 @@ struct ParamTraits<NPVariant>
}
};
template<>
struct ParamTraits<mozilla::void_t>
{
typedef mozilla::void_t paramType;
static void Write(Message* aMsg, const paramType& aParam) { }
static bool
Read(const Message* aMsg, void** aIter, paramType* aResult)
{
*aResult = paramType();
return true;
}
};
template<>
struct ParamTraits<mozilla::null_t>
{
typedef mozilla::null_t paramType;
static void Write(Message* aMsg, const paramType& aParam) { }
static bool
Read(const Message* aMsg, void** aIter, paramType* aResult)
{
*aResult = paramType();
return true;
}
};
template <>
struct ParamTraits<mozilla::plugins::IPCByteRange>
{

Просмотреть файл

@ -50,6 +50,16 @@
#pragma warning( disable : 4800 )
#endif
namespace mozilla {
// XXX there are out of place and might be generally useful. Could
// move to nscore.h or something.
struct void_t { };
struct null_t { };
} // namespace mozilla
namespace IPC {
template<>
@ -317,6 +327,32 @@ struct ParamTraits<gfxMatrix>
}
};
template<>
struct ParamTraits<mozilla::void_t>
{
typedef mozilla::void_t paramType;
static void Write(Message* aMsg, const paramType& aParam) { }
static bool
Read(const Message* aMsg, void** aIter, paramType* aResult)
{
*aResult = paramType();
return true;
}
};
template<>
struct ParamTraits<mozilla::null_t>
{
typedef mozilla::null_t paramType;
static void Write(Message* aMsg, const paramType& aParam) { }
static bool
Read(const Message* aMsg, void** aIter, paramType* aResult)
{
*aResult = paramType();
return true;
}
};
} /* namespace IPC */
#endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */

Просмотреть файл

@ -63,6 +63,7 @@ IPDLTESTS = \
TestDataStructures \
TestDesc \
TestHangs \
TestJSON \
TestLatency \
TestManyChildAllocs \
TestMultiMgrs \

Просмотреть файл

@ -0,0 +1,14 @@
include protocol PTestJSON;
namespace mozilla {
namespace _ipdltest {
protocol PTestHandle {
manager PTestJSON;
child:
__delete__();
};
} // namespace mozilla
} // namespace _ipdltest

Просмотреть файл

@ -0,0 +1,54 @@
include protocol PTestHandle;
using mozilla::void_t;
using mozilla::null_t;
namespace mozilla {
namespace _ipdltest {
union Key {
// int;
// double;
nsString;
};
struct KeyValue {
Key key;
JSONVariant value;
};
union JSONVariant {
void_t;
null_t;
bool;
int;
double;
nsString;
PTestHandle;
KeyValue[];
JSONVariant[];
};
sync protocol PTestJSON {
manages PTestHandle;
child:
async Start();
parent:
async PTestHandle();
sync Test(JSONVariant i)
returns (JSONVariant o);
async __delete__();
state START:
send Start goto TEST;
state TEST:
recv PTestHandle goto TEST;
recv Test goto TEST;
recv __delete__;
};
} // namespace mozilla
} // namespace _ipdltest

Просмотреть файл

@ -283,8 +283,8 @@ bool TestDataStructuresParent::RecvTest11(
const SIntDouble& i,
SIntDouble* o)
{
test_assert(1 == i.i, "wrong value");
test_assert(2.0 == i.d, "wrong value");
test_assert(1 == i.i(), "wrong value");
test_assert(2.0 == i.d(), "wrong value");
*o = i;
return true;
}
@ -303,9 +303,9 @@ bool TestDataStructuresParent::RecvTest12(
ad.AppendElement(1.0);
ad.AppendElement(2.0);
test_assert(42 == i.i, "wrong value");
assert_arrays_equal(ai, i.ai);
assert_arrays_equal(ad, i.ad);
test_assert(42 == i.i(), "wrong value");
assert_arrays_equal(ai, i.ai());
assert_arrays_equal(ad, i.ad());
*o = i;
@ -319,9 +319,9 @@ bool TestDataStructuresParent::RecvTest13(
nsTArray<int> ai;
ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
test_assert(42 == i.i, "wrong value");
assert_arrays_equal(ai, i.ai);
assert_arrays_equal(mKids, i.apParent);
test_assert(42 == i.i(), "wrong value");
assert_arrays_equal(ai, i.ai());
assert_arrays_equal(mKids, i.apParent());
*o = i;
@ -335,14 +335,14 @@ bool TestDataStructuresParent::RecvTest14(
nsTArray<int> ai;
ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
test_assert(42 == i.i, "wrong value");
assert_arrays_equal(ai, i.ai);
assert_arrays_equal(mKids, i.apParent);
test_assert(42 == i.i(), "wrong value");
assert_arrays_equal(ai, i.ai());
assert_arrays_equal(mKids, i.apParent());
const SActors& ia = i.aa[0];
test_assert(42 == ia.i, "wrong value");
assert_arrays_equal(ai, ia.ai);
assert_arrays_equal(mKids, ia.apParent);
const SActors& ia = i.aa()[0];
test_assert(42 == ia.i(), "wrong value");
assert_arrays_equal(ai, ia.ai());
assert_arrays_equal(mKids, ia.apParent());
*o = i;
@ -369,19 +369,19 @@ bool TestDataStructuresParent::RecvTest15(
assert_arrays_equal(i3.get_ArrayOfPTestDataStructuresSubParent(), mKids);
const SActors& ia = i4.get_ArrayOfSActors()[0];
test_assert(42 == ia.i, "wrong value");
assert_arrays_equal(ai, ia.ai);
assert_arrays_equal(mKids, ia.apParent);
test_assert(42 == ia.i(), "wrong value");
assert_arrays_equal(ai, ia.ai());
assert_arrays_equal(mKids, ia.apParent());
const Structs& is = i5.get_ArrayOfStructs()[0];
test_assert(42 == is.i, "wrong value");
assert_arrays_equal(ai, is.ai);
assert_arrays_equal(mKids, is.apParent);
test_assert(42 == is.i(), "wrong value");
assert_arrays_equal(ai, is.ai());
assert_arrays_equal(mKids, is.apParent());
const SActors& isa = is.aa[0];
test_assert(42 == isa.i, "wrong value");
assert_arrays_equal(ai, isa.ai);
assert_arrays_equal(mKids, isa.apParent);
const SActors& isa = is.aa()[0];
test_assert(42 == isa.i(), "wrong value");
assert_arrays_equal(ai, isa.ai());
assert_arrays_equal(mKids, isa.apParent());
*o1 = i1;
*o2 = i2;
@ -396,17 +396,17 @@ bool TestDataStructuresParent::RecvTest16(
const WithUnions& i,
WithUnions* o)
{
test_assert(i.i == 42, "wrong value");
test_assert(i.i() == 42, "wrong value");
nsTArray<int> ai;
ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
assert_arrays_equal(ai, i.ai);
assert_arrays_equal(ai, i.ai());
assert_arrays_equal(i.apParent, mKids);
assert_arrays_equal(i.apParent(), mKids);
assert_arrays_equal(mKids, i.aa[0].get_ArrayOfPTestDataStructuresSubParent());
assert_arrays_equal(mKids, i.aa()[0].get_ArrayOfPTestDataStructuresSubParent());
const nsTArray<Unions>& iau = i.au;
const nsTArray<Unions>& iau = i.au();
test_assert(iau[0] == 42, "wrong value");
assert_arrays_equal(ai, iau[1].get_ArrayOfint());
assert_arrays_equal(mKids, iau[2].get_ArrayOfPTestDataStructuresSubParent());
@ -695,7 +695,7 @@ TestDataStructuresChild::Test11()
if (!SendTest11(i, &o))
fail("sending Test11");
test_assert(i.i == o.i && i.d == o.d, "wrong values");
test_assert(1 == o.i() && 2.0 == o.d(), "wrong values");
printf(" passed %s\n", __FUNCTION__);
}
@ -715,9 +715,9 @@ TestDataStructuresChild::Test12()
if (!SendTest12(i, &o))
fail("sending Test12");
test_assert(i.i == o.i, "wrong value");
assert_arrays_equal(ai, o.ai);
assert_arrays_equal(ad, o.ad);
test_assert(42 == o.i(), "wrong value");
assert_arrays_equal(ai, o.ai());
assert_arrays_equal(ad, o.ad());
printf(" passed %s\n", __FUNCTION__);
}
@ -729,17 +729,17 @@ TestDataStructuresChild::Test13()
ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
SActors i;
i.i = 42;
i.ai = ai;
i.apChild = mKids;
i.i() = 42;
i.ai() = ai;
i.apChild() = mKids;
SActors o;
if (!SendTest13(i, &o))
fail("can't send Test13");
test_assert(42 == o.i, "wrong value");
assert_arrays_equal(ai, o.ai);
assert_arrays_equal(mKids, o.apChild);
test_assert(42 == o.i(), "wrong value");
assert_arrays_equal(ai, o.ai());
assert_arrays_equal(mKids, o.apChild());
printf(" passed %s\n", __FUNCTION__);
}
@ -751,29 +751,29 @@ TestDataStructuresChild::Test14()
ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
SActors ia;
ia.i = 42;
ia.ai = ai;
ia.apChild = mKids;
ia.i() = 42;
ia.ai() = ai;
ia.apChild() = mKids;
nsTArray<SActors> aa; aa.AppendElement(ia);
Structs i;
i.i = 42;
i.ai = ai;
i.apChild = mKids;
i.aa = aa;
i.i() = 42;
i.ai() = ai;
i.apChild() = mKids;
i.aa() = aa;
Structs o;
if (!SendTest14(i, &o))
fail("can't send Test14");
test_assert(42 == o.i, "wrong value");
assert_arrays_equal(ai, o.ai);
assert_arrays_equal(mKids, o.apChild);
test_assert(42 == o.i(), "wrong value");
assert_arrays_equal(ai, o.ai());
assert_arrays_equal(mKids, o.apChild());
const SActors& os = o.aa[0];
test_assert(42 == os.i, "wrong value");
assert_arrays_equal(ai, os.ai);
assert_arrays_equal(mKids, os.apChild);
const SActors& os = o.aa()[0];
test_assert(42 == os.i(), "wrong value");
assert_arrays_equal(ai, os.ai());
assert_arrays_equal(mKids, os.apChild());
printf(" passed %s\n", __FUNCTION__);
}
@ -785,16 +785,16 @@ TestDataStructuresChild::Test15()
ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
SActors ia;
ia.i = 42;
ia.ai = ai;
ia.apChild = mKids;
ia.i() = 42;
ia.ai() = ai;
ia.apChild() = mKids;
nsTArray<SActors> iaa; iaa.AppendElement(ia);
Structs is;
is.i = 42;
is.ai = ai;
is.apChild = mKids;
is.aa = iaa;
is.i() = 42;
is.ai() = ai;
is.apChild() = mKids;
is.aa() = iaa;
nsTArray<Structs> isa; isa.AppendElement(is);
WithStructs o1, o2, o3, o4, o5;
@ -811,19 +811,19 @@ TestDataStructuresChild::Test15()
assert_arrays_equal(o3.get_ArrayOfPTestDataStructuresSubChild(), mKids);
const SActors& oa = o4.get_ArrayOfSActors()[0];
test_assert(42 == oa.i, "wrong value");
assert_arrays_equal(ai, oa.ai);
assert_arrays_equal(mKids, oa.apChild);
test_assert(42 == oa.i(), "wrong value");
assert_arrays_equal(ai, oa.ai());
assert_arrays_equal(mKids, oa.apChild());
const Structs& os = o5.get_ArrayOfStructs()[0];
test_assert(42 == os.i, "wrong value");
assert_arrays_equal(ai, os.ai);
assert_arrays_equal(mKids, os.apChild);
test_assert(42 == os.i(), "wrong value");
assert_arrays_equal(ai, os.ai());
assert_arrays_equal(mKids, os.apChild());
const SActors& osa = os.aa[0];
test_assert(42 == osa.i, "wrong value");
assert_arrays_equal(ai, osa.ai);
assert_arrays_equal(mKids, osa.apChild);
const SActors& osa = os.aa()[0];
test_assert(42 == osa.i(), "wrong value");
assert_arrays_equal(ai, osa.ai());
assert_arrays_equal(mKids, osa.apChild());
printf(" passed %s\n", __FUNCTION__);
}
@ -833,37 +833,37 @@ TestDataStructuresChild::Test16()
{
WithUnions i;
i.i = 42;
i.i() = 42;
nsTArray<int> ai;
ai.AppendElement(1); ai.AppendElement(2); ai.AppendElement(3);
i.ai = ai;
i.ai() = ai;
i.apChild = mKids;
i.apChild() = mKids;
nsTArray<Actors> iaa;
iaa.AppendElement(mKids);
i.aa = iaa;
i.aa() = iaa;
nsTArray<Unions> iau;
iau.AppendElement(int(42));
iau.AppendElement(ai);
iau.AppendElement(mKids);
iau.AppendElement(iaa);
i.au = iau;
i.au() = iau;
WithUnions o;
if (!SendTest16(i, &o))
fail("sending Test16");
test_assert(42 == o.i, "wrong value");
assert_arrays_equal(o.ai, ai);
assert_arrays_equal(o.apChild, mKids);
test_assert(42 == o.i(), "wrong value");
assert_arrays_equal(o.ai(), ai);
assert_arrays_equal(o.apChild(), mKids);
const Actors& oaa = o.aa[0];
const Actors& oaa = o.aa()[0];
assert_arrays_equal(oaa.get_ArrayOfPTestDataStructuresSubChild(), mKids);
const nsTArray<Unions>& oau = o.au;
const nsTArray<Unions>& oau = o.au();
test_assert(oau[0] == 42, "wrong value");
assert_arrays_equal(oau[1].get_ArrayOfint(), ai);
assert_arrays_equal(oau[2].get_ArrayOfPTestDataStructuresSubChild(),

Просмотреть файл

@ -0,0 +1,189 @@
#include <algorithm> // std::equal
#include "TestJSON.h"
#include "IPDLUnitTests.h" // fail etc.
#define test_assert(_cond, _msg) \
if (!(_cond)) fail(_msg)
namespace mozilla {
namespace _ipdltest {
// XXX move me into nsTArray
template<typename T>
bool
operator==(const nsTArray<T>& a, const nsTArray<T>& b)
{
return (a.Length() == b.Length() &&
std::equal(a.Elements(), a.Elements() + a.Length(),
b.Elements()));
}
bool
operator==(const Key& a, const Key& b)
{
return a.get_nsString() == b.get_nsString();
}
bool operator==(const JSONVariant& a, const JSONVariant& b);
bool
operator==(const KeyValue& a, const KeyValue& b)
{
return a.key() == b.key() && a.value() == b.value();
}
// XXX start generating me in IPDL code
bool
operator==(const JSONVariant& a, const JSONVariant& b)
{
typedef JSONVariant t;
if (a.type() != b.type())
return false;
switch(a.type()) {
case t::Tvoid_t:
case t::Tnull_t:
return true;
case t::Tbool:
return a.get_bool() == b.get_bool();
case t::Tint:
return a.get_int() == b.get_int();
case t::Tdouble:
return a.get_double() == b.get_double();
case t::TnsString:
return a.get_nsString() == b.get_nsString();
case t::TPTestHandleParent:
return a.get_PTestHandleParent() == b.get_PTestHandleParent();
case t::TPTestHandleChild:
return a.get_PTestHandleChild() == b.get_PTestHandleChild();
case t::TArrayOfKeyValue:
return a.get_ArrayOfKeyValue() == b.get_ArrayOfKeyValue();
case t::TArrayOfJSONVariant:
return a.get_ArrayOfJSONVariant() == b.get_ArrayOfJSONVariant();
default:
NS_RUNTIMEABORT("unreached");
return false;
}
}
static nsString
String(const char* const str)
{
return NS_ConvertUTF8toUTF16(str);
}
static nsTArray<JSONVariant>
Array123()
{
nsTArray<JSONVariant> a123;
a123.AppendElement(1); a123.AppendElement(2); a123.AppendElement(3);
test_assert(a123 == a123, "operator== is broken");
return a123;
}
template<class HandleT>
JSONVariant
MakeTestVariant(HandleT* handle)
{
// In JS syntax:
//
// return [
// undefined, null, true, 1.25, "test string",
// handle,
// [ 1, 2, 3 ],
// { "undefined" : undefined,
// "null" : null,
// "true" : true,
// "1.25" : 1.25,
// "string" : "string"
// "handle" : handle,
// "array" : [ 1, 2, 3 ]
// }
// ]
//
nsTArray<JSONVariant> outer;
outer.AppendElement(void_t());
outer.AppendElement(null_t());
outer.AppendElement(true);
outer.AppendElement(1.25);
outer.AppendElement(String("test string"));
outer.AppendElement(handle);
outer.AppendElement(Array123());
nsTArray<KeyValue> obj;
obj.AppendElement(KeyValue(String("undefined"), void_t()));
obj.AppendElement(KeyValue(String("null"), null_t()));
obj.AppendElement(KeyValue(String("true"), true));
obj.AppendElement(KeyValue(String("1.25"), 1.25));
obj.AppendElement(KeyValue(String("string"), String("value")));
obj.AppendElement(KeyValue(String("handle"), handle));
obj.AppendElement(KeyValue(String("array"), Array123()));
outer.AppendElement(obj);
test_assert(outer == outer, "operator== is broken");
return JSONVariant(outer);
}
//-----------------------------------------------------------------------------
// parent
void
TestJSONParent::Main()
{
if (!SendStart())
fail("sending Start");
}
bool
TestJSONParent::RecvTest(const JSONVariant& i,
JSONVariant* o)
{
test_assert(i == i, "operator== is broken");
test_assert(i == MakeTestVariant(mKid), "inparam mangled en route");
*o = i;
test_assert(i == *o, "operator= is broken");
return true;
}
//-----------------------------------------------------------------------------
// child
bool
TestJSONChild::RecvStart()
{
if (!SendPTestHandleConstructor())
fail("sending Handle ctor");
JSONVariant i(MakeTestVariant(mKid));
test_assert(i == i, "operator== is broken");
test_assert(i == MakeTestVariant(mKid), "copy ctor is broken");
JSONVariant o;
if (!SendTest(i, &o))
fail("sending Test");
test_assert(i == o, "round-trip mangled input data");
test_assert(o == MakeTestVariant(mKid), "outparam mangled en route");
Close();
return true;
}
} // namespace _ipdltest
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,113 @@
#ifndef mozilla__ipdltest_TestJSON_h
#define mozilla__ipdltest_TestJSON_h 1
#include "mozilla/_ipdltest/IPDLUnitTests.h"
#include "mozilla/_ipdltest/PTestJSONParent.h"
#include "mozilla/_ipdltest/PTestJSONChild.h"
#include "mozilla/_ipdltest/PTestHandleParent.h"
#include "mozilla/_ipdltest/PTestHandleChild.h"
namespace mozilla {
namespace _ipdltest {
class TestHandleParent :
public PTestHandleParent
{
public:
TestHandleParent() { }
virtual ~TestHandleParent() { }
};
class TestJSONParent :
public PTestJSONParent
{
public:
TestJSONParent() { }
virtual ~TestJSONParent() { }
void Main();
protected:
NS_OVERRIDE
virtual bool
RecvTest(const JSONVariant& i,
JSONVariant* o);
NS_OVERRIDE
virtual PTestHandleParent* AllocPTestHandle()
{
return mKid = new TestHandleParent();
}
NS_OVERRIDE
virtual bool DeallocPTestHandle(PTestHandleParent* actor)
{
delete actor;
return true;
}
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
passed("ok");
QuitParent();
}
PTestHandleParent* mKid;
};
class TestHandleChild :
public PTestHandleChild
{
public:
TestHandleChild() { }
virtual ~TestHandleChild() { }
};
class TestJSONChild :
public PTestJSONChild
{
public:
TestJSONChild() { }
virtual ~TestJSONChild() { }
protected:
NS_OVERRIDE
virtual bool
RecvStart();
NS_OVERRIDE
virtual PTestHandleChild* AllocPTestHandle()
{
return mKid = new TestHandleChild();
}
NS_OVERRIDE
virtual bool DeallocPTestHandle(PTestHandleChild* actor)
{
delete actor;
return true;
}
NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why)
{
if (NormalShutdown != why)
fail("unexpected destruction!");
QuitChild();
}
PTestHandleChild* mKid;
};
} // namespace _ipdltest
} // namespace mozilla
#endif // ifndef mozilla__ipdltest_TestJSON_h

Просмотреть файл

@ -6,7 +6,9 @@ IPDLSRCS = \
PTestDesc.ipdl \
PTestDescSub.ipdl \
PTestDescSubsub.ipdl \
PTestHandle.ipdl \
PTestHangs.ipdl \
PTestJSON.ipdl \
PTestLatency.ipdl \
PTestManyChildAllocs.ipdl \
PTestManyChildAllocsSub.ipdl \

Просмотреть файл

@ -0,0 +1,20 @@
struct X {
int i;
Y[] y;
};
struct Y {
X x;
Z z;
};
struct Z {
double d;
X x;
};
protocol mutualRecStruct {
child:
Test(X x, Y y, Z z);
__delete__();
};

Просмотреть файл

@ -0,0 +1,20 @@
struct X {
int i;
Y[] y;
};
union Y {
X;
Z;
};
struct Z {
double d;
X x;
};
protocol mutualRecStructUnion {
child:
Test(X x, Y y, Z z);
__delete__();
};

Просмотреть файл

@ -0,0 +1,7 @@
struct X { Y y; };
struct Y { Z z; };
struct Z { X x; };
protocol undefMutualRecStruct {
child: __delete__(X x);
};

Просмотреть файл

@ -0,0 +1,7 @@
struct X { Y y; };
union Y { Z; };
struct Z { X x; };
protocol undefMutualRecStructUnion {
child: __delete__(X x);
};

Просмотреть файл

@ -0,0 +1,7 @@
union X { Y; };
union Y { Z; };
union Z { X; };
protocol undefMutualRecUnion {
child: __delete__(X x);
};

Просмотреть файл

@ -0,0 +1,5 @@
struct X { X x; };
protocol undefSelfRecStruct {
child: __delete__(X x);
};

Просмотреть файл

@ -0,0 +1,5 @@
union X { X; };
protocol undefSelfRecUnion {
child: __delete__(X x);
};

Просмотреть файл

@ -0,0 +1,21 @@
struct X {
int i;
Y[] y;
};
union Y {
double;
X;
Z;
};
struct Z {
X x;
Y y;
};
protocol mutualRecStructUnion {
child:
Test(X x, Y y, Z z);
__delete__();
};

Просмотреть файл

@ -0,0 +1,20 @@
union X {
int;
Y[];
};
union Y {
X;
Z;
};
union Z {
double;
X;
};
protocol mutualRecUnion {
child:
Test(X x, Y y, Z z);
__delete__();
};

Просмотреть файл

@ -0,0 +1,11 @@
union R {
int;
double;
R;
};
protocol selfRecUnion {
child:
Test(R r);
__delete__();
};