예제 #1
0
static void consistsOf(std::vector<v8> parts, const v8& data) {
	auto it = data.begin();
	while (it != data.end()) {
		if (parts.empty()) {
			FAIL() << "Unexpected elements left in data: "
			       << testing::PrintToString(v8(it, data.end())) << std::endl;
			return;
		}

		std::vector<v8>::iterator found = findElement(it, parts);
		if (found == parts.end()) {
			ADD_FAILURE() << "None of the following values could be found at position "
		                << std::distance(data.begin(), it) << " of data:\n"
										<< testing::PrintToString(v8(it, data.end())) << "\n";
			for (auto part : parts)
				std::cerr << testing::PrintToString(part) << "\n";

			return;
		}

		it += found->size();
		parts.erase(found);
	}

	ASSERT_TRUE(parts.empty());
}
예제 #2
0
파일: amftest.hpp 프로젝트: Ventero/amf-cpp
void deserialize(const T& expected, const v8& data, int expectedLeft = 0,
		SerializationContext* ctx = nullptr) {
	SerializationContext sctx;
	SCOPED_TRACE(::testing::PrintToString(expected.serialize(sctx)) + " = " + ::testing::PrintToString(data));

	std::unique_ptr<SerializationContext> dummy;
	if (!ctx) {
		dummy.reset(new SerializationContext());
		ctx = dummy.get();
	}

	auto it = data.begin();
	try {
		T i = T::deserialize(it, data.end(), *ctx);
		ASSERT_EQ(expected, i);
	} catch(std::exception& e) {
		FAIL() << "Deserialization threw exception:\n"
		       << e.what() ;
	}

	ASSERT_EQ(expectedLeft, data.end() - it)
		<< "Expected " << expectedLeft
		<< " bytes left, got " << (data.end() - it)
		<< " bytes left";
}