#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "build/build_config.h"
#include "ipc/ipc_message_protobuf_utils.h"
#include <initializer_list>
#include "ipc/test_proto.pb.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace IPC {
template <>
struct ParamTraits<ipc_message_utils_test::TestMessage1> {
typedef ipc_message_utils_test::TestMessage1 param_type;
static void Write(base::Pickle* m, const param_type& p) {
WriteParam(m, p.number());
}
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* r) {
int number;
if (!iter->ReadInt(&number))
return false;
r->set_number(number);
return true;
}
};
template <>
struct ParamTraits<ipc_message_utils_test::TestMessage2> {
typedef ipc_message_utils_test::TestMessage2 param_type;
static void Write(base::Pickle* m, const param_type& p) {
WriteParam(m, p.numbers());
WriteParam(m, p.strings());
WriteParam(m, p.messages());
}
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
param_type* r) {
return ReadParam(m, iter, r->mutable_numbers()) &&
ReadParam(m, iter, r->mutable_strings()) &&
ReadParam(m, iter, r->mutable_messages());
}
};
namespace {
template <class P1, class P2>
void AssertEqual(const P1& left, const P2& right) { … }
template<>
void AssertEqual(const int& left,
const ipc_message_utils_test::TestMessage1& right) { … }
template <template<class> class RepeatedFieldLike, class P1, class P2>
void AssertRepeatedFieldEquals(std::initializer_list<P1> expected,
const RepeatedFieldLike<P2>& fields) { … }
TEST(IPCMessageRepeatedFieldUtilsTest, RepeatedFieldShouldBeSerialized) { … }
TEST(IPCMessageRepeatedFieldUtilsTest,
PartialEmptyRepeatedFieldShouldBeSerialized) { … }
TEST(IPCMessageRepeatedFieldUtilsTest, EmptyRepeatedFieldShouldBeSerialized) { … }
TEST(IPCMessageRepeatedFieldUtilsTest,
InvalidPickleShouldNotCrashRepeatedFieldDeserialization) { … }
TEST(IPCMessageRepeatedFieldUtilsTest,
DISABLED_InvalidPickleShouldNotCrashRepeatedFieldDeserialization2) { … }
}
}