typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;
typedef int intptr_t;
typedef unsigned int uintptr_t;
typedef __WINT_TYPE__ wint_t;
typedef __SIZE_TYPE__ size_t;
typedef __SIZE_TYPE__ rsize_t;
typedef long ssize_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef unsigned int dev_t;
typedef int off_t;
typedef long clock_t;
typedef int time_t;
typedef long suseconds_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef long int64_t;
typedef unsigned long uint64_t;
namespace std {
template <class T>
struct allocator {};
template <class T, class A = allocator<T>>
struct vector {};
template <class F, class S>
struct pair {};
}
namespace base {
class Pickle {};
template <class T, class... Ts>
struct Tuple {
T value;
};
}
namespace IPC {
template <class... T>
struct CheckedTuple {
typedef base::Tuple<T...> Tuple;
};
template <class T>
struct ParamTraits {
static void Write(base::Pickle*, const T&) {}
};
template <class T>
void WriteParam(base::Pickle* pickle, const T& value) {
ParamTraits<T>::Write(pickle, value);
}
}
struct Data {
uint32_t value;
size_t size;
};
template <>
struct IPC::ParamTraits<Data> {
static void Write(base::Pickle* pickle, const Data& p) {
WriteParam(pickle, p.value); WriteParam(pickle, p.size); }
};
template <class T>
struct Container {
T value;
};
template <class T>
struct IPC::ParamTraits<Container<T>> {
static void Write(base::Pickle* pickle, const Container<T>& container) {
IPC::WriteParam(pickle, container.value); WriteParam(pickle, container.value);
IPC::WriteParam<T>(pickle, container.value); WriteParam<T>(pickle, container.value);
WriteParam(pickle, static_cast<uint32_t>(container.value));
WriteParam(pickle, static_cast<long>(container.value)); }
};
template <class T, class... Ts>
struct MultiContainer {
T value;
};
template <class T, class... Ts>
struct IPC::ParamTraits<MultiContainer<T, Ts...>> {
static void Write(base::Pickle* pickle,
const MultiContainer<T, Ts...>& container) {
bool helper[] = {
(WriteParam<Ts>(pickle, container.value), true)... };
(void)helper;
}
};
template <class T>
struct SomeClass {
static void Write(base::Pickle* pickle) {
IPC::WriteParam(pickle, T(0));
IPC::WriteParam(pickle, size_t(0)); IPC::WriteParam(pickle, uint64_t(0)); }
template <class U>
static void WriteEx(base::Pickle* pickle) {
IPC::WriteParam(pickle, U(0));
IPC::WriteParam(pickle, time_t(0)); IPC::WriteParam(pickle, uint32_t(0)); }
};
template <class T>
void SomeWriteFunction(base::Pickle* pickle) {
IPC::WriteParam(pickle, T(0));
IPC::WriteParam(pickle, long(0)); IPC::WriteParam(pickle, char(0));
[&](){
IPC::WriteParam(pickle, T(0));
IPC::WriteParam(pickle, clock_t(0)); IPC::WriteParam(pickle, int64_t(0)); }();
}
void TestWriteParamInTemplates() {
SomeClass<long>::Write(nullptr);
SomeClass<long>::WriteEx<uint64_t>(nullptr);
SomeWriteFunction<uint64_t>(nullptr);
}
#define IPC_TUPLE(...) IPC::CheckedTuple<__VA_ARGS__>::Tuple
#define IPC_MESSAGE_DECL(name, id, in_tuple) \
struct name ## Meta_ ## id { \
using InTuple = in_tuple; \
};
#define IPC_TEST_MESSAGE(id, in) \
IPC_MESSAGE_DECL(TestMessage, id, IPC_TUPLE in)
struct Empty {};
IPC_TEST_MESSAGE(__COUNTER__, (bool, size_t, Empty, long))
typedef std::vector<long> long1D;
typedef std::vector<long1D> long2D;
IPC_TEST_MESSAGE(__COUNTER__, (bool, long2D))
IPC_TEST_MESSAGE(__COUNTER__, (char, short, std::pair<size_t, bool>))
IPC_TEST_MESSAGE(__COUNTER__, (std::vector<std::vector<long&>&>&))
void TestWriteParamArgument() {
#define CALL_WRITEPARAM(Type) \
{ \
Type p; \
IPC::WriteParam(nullptr, p); \
}
CALL_WRITEPARAM(long) CALL_WRITEPARAM(unsigned long) CALL_WRITEPARAM(intmax_t) CALL_WRITEPARAM(uintmax_t) CALL_WRITEPARAM(intptr_t) CALL_WRITEPARAM(uintptr_t) CALL_WRITEPARAM(wint_t) CALL_WRITEPARAM(size_t) CALL_WRITEPARAM(rsize_t) CALL_WRITEPARAM(ssize_t) CALL_WRITEPARAM(ptrdiff_t) CALL_WRITEPARAM(dev_t) CALL_WRITEPARAM(off_t) CALL_WRITEPARAM(clock_t) CALL_WRITEPARAM(time_t) CALL_WRITEPARAM(suseconds_t)
typedef size_t my_size;
CALL_WRITEPARAM(my_size)
{
uint64_t p = 0;
IPC::WriteParam(nullptr, p + 1); }
{
typedef size_t my_size_base;
typedef const my_size_base my_size;
typedef my_size& my_size_ref;
my_size_ref p = 0;
IPC::WriteParam(nullptr, p); }
CALL_WRITEPARAM(std::vector<long>) CALL_WRITEPARAM(std::vector<size_t>)
typedef long my_long;
CALL_WRITEPARAM(my_long)
CALL_WRITEPARAM(char) CALL_WRITEPARAM(int) CALL_WRITEPARAM(uint32_t) CALL_WRITEPARAM(int64_t)
{
typedef uint32_t my_int_base;
typedef const my_int_base my_int;
typedef my_int& my_int_ref;
my_int_ref p = 0;
IPC::WriteParam(nullptr, p); }
CALL_WRITEPARAM(std::vector<char>) CALL_WRITEPARAM(std::vector<my_long>)
#undef CALL_WRITEPARAM
}
struct Provider {
typedef unsigned int flags;
short get_short() const { return 0; }
uint64_t get_uint64() const { return 0; }
long get_long() const { return 0; }
unsigned int get_uint() const { return 0; }
flags get_flags() const { return 0; }
size_t get_size() const { return 0; }
const std::vector<size_t>& get_sizes() const { return sizes_data; }
const std::vector<uint64_t>& get_uint64s() const { return uint64s_data; }
template <class T>
T get() const { return T(); }
short short_data;
unsigned int uint_data;
flags flags_data;
long long_data;
size_t size_data;
uint64_t uint64_data;
std::vector<size_t> sizes_data;
std::vector<uint64_t> uint64s_data;
};
void TestWriteParamMemberArgument() {
Provider p;
IPC::WriteParam(nullptr, p.get<short>()); IPC::WriteParam(nullptr, p.get_short()); IPC::WriteParam(nullptr, p.short_data);
IPC::WriteParam(nullptr, p.get<unsigned int>()); IPC::WriteParam(nullptr, p.get_uint()); IPC::WriteParam(nullptr, p.uint_data);
IPC::WriteParam(nullptr, p.get<Provider::flags>()); IPC::WriteParam(nullptr, p.get_flags()); IPC::WriteParam(nullptr, p.flags_data);
IPC::WriteParam(nullptr, p.get<long>()); IPC::WriteParam(nullptr, p.get_long()); IPC::WriteParam(nullptr, p.long_data);
IPC::WriteParam(nullptr, p.get_size()); IPC::WriteParam(nullptr, p.size_data);
IPC::WriteParam(nullptr, p.get<uint64_t>()); IPC::WriteParam(nullptr, p.get_uint64()); IPC::WriteParam(nullptr, p.uint64_data);
IPC::WriteParam(nullptr, p.get<std::vector<uint64_t>>()); IPC::WriteParam(nullptr, p.get_uint64s()); IPC::WriteParam(nullptr, p.uint64s_data);
IPC::WriteParam(nullptr, p.get_sizes()); IPC::WriteParam(nullptr, p.sizes_data); }