Project import generated by Copybara.
GitOrigin-RevId: d8caa66de45839696f5bd0786ad3bfbcb9cff632
This commit is contained in:
@@ -145,7 +145,7 @@ struct UnregisteredPairStruct {
|
||||
std::string first;
|
||||
bool second;
|
||||
};
|
||||
MEDIAPIPE_REGISTER_TYPE(::mediapipe::RegisteredPairStruct,
|
||||
MEDIAPIPE_REGISTER_TYPE(mediapipe::RegisteredPairStruct,
|
||||
"::mediapipe::RegisteredPairStruct", nullptr, nullptr);
|
||||
MEDIAPIPE_REGISTER_TYPE(int, "int", nullptr, nullptr);
|
||||
MEDIAPIPE_REGISTER_TYPE(float, "float", nullptr, nullptr);
|
||||
@@ -210,8 +210,8 @@ TEST(PacketTest, ValidateAsProtoMessageLite) {
|
||||
Packet packet = Adopt(proto_ptr.release());
|
||||
MP_EXPECT_OK(packet.ValidateAsProtoMessageLite());
|
||||
Packet packet2 = MakePacket<int>(3);
|
||||
::mediapipe::Status status = packet2.ValidateAsProtoMessageLite();
|
||||
EXPECT_EQ(status.code(), ::mediapipe::StatusCode::kInvalidArgument);
|
||||
mediapipe::Status status = packet2.ValidateAsProtoMessageLite();
|
||||
EXPECT_EQ(status.code(), mediapipe::StatusCode::kInvalidArgument);
|
||||
}
|
||||
|
||||
TEST(PacketTest, SyncedPacket) {
|
||||
@@ -283,11 +283,11 @@ TEST(PacketTest, TestPacketMoveConstructor) {
|
||||
TEST(PacketTest, TestPacketConsume) {
|
||||
Packet packet1 = MakePacket<int>(33);
|
||||
Packet packet_copy = packet1;
|
||||
::mediapipe::StatusOr<std::unique_ptr<int>> result1 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int>> result1 =
|
||||
packet_copy.Consume<int>();
|
||||
// Both packet1 and packet_copy own the data, Consume() should return error.
|
||||
::mediapipe::Status status1 = result1.status();
|
||||
EXPECT_EQ(status1.code(), ::mediapipe::StatusCode::kFailedPrecondition);
|
||||
mediapipe::Status status1 = result1.status();
|
||||
EXPECT_EQ(status1.code(), mediapipe::StatusCode::kFailedPrecondition);
|
||||
EXPECT_THAT(status1.message(),
|
||||
testing::HasSubstr("isn't the sole owner of the holder"));
|
||||
ASSERT_FALSE(packet1.IsEmpty());
|
||||
@@ -297,7 +297,7 @@ TEST(PacketTest, TestPacketConsume) {
|
||||
|
||||
Packet packet2 = MakePacket<int>(33);
|
||||
// Types don't match (int vs float).
|
||||
::mediapipe::StatusOr<std::unique_ptr<float>> result2 =
|
||||
mediapipe::StatusOr<std::unique_ptr<float>> result2 =
|
||||
packet2.Consume<float>();
|
||||
EXPECT_THAT(
|
||||
result2.status().message(),
|
||||
@@ -307,7 +307,7 @@ TEST(PacketTest, TestPacketConsume) {
|
||||
|
||||
// packet3 is the sole owner of the data.
|
||||
Packet packet3 = MakePacket<int>(42);
|
||||
::mediapipe::StatusOr<std::unique_ptr<int>> result3 = packet3.Consume<int>();
|
||||
mediapipe::StatusOr<std::unique_ptr<int>> result3 = packet3.Consume<int>();
|
||||
// After Consume(), packet3 should be empty and result3 owns the data.
|
||||
EXPECT_TRUE(result3.ok());
|
||||
ASSERT_NE(nullptr, result3.ValueOrDie());
|
||||
@@ -319,7 +319,7 @@ TEST(PacketTest, TestPacketConsumeOrCopy) {
|
||||
Packet packet1 = MakePacket<int>(33);
|
||||
Packet packet_copy = packet1;
|
||||
bool was_copied1 = false;
|
||||
::mediapipe::StatusOr<std::unique_ptr<int>> result1 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int>> result1 =
|
||||
packet_copy.ConsumeOrCopy<int>(&was_copied1);
|
||||
// Both packet1 and packet_copy own the data, ConsumeOrCopy() returns a copy
|
||||
// of the data and sets packet_copy to empty.
|
||||
@@ -334,7 +334,7 @@ TEST(PacketTest, TestPacketConsumeOrCopy) {
|
||||
|
||||
Packet packet2 = MakePacket<int>(33);
|
||||
// Types don't match (int vs float).
|
||||
::mediapipe::StatusOr<std::unique_ptr<float>> result2 =
|
||||
mediapipe::StatusOr<std::unique_ptr<float>> result2 =
|
||||
packet2.ConsumeOrCopy<float>();
|
||||
EXPECT_THAT(
|
||||
result2.status().message(),
|
||||
@@ -346,7 +346,7 @@ TEST(PacketTest, TestPacketConsumeOrCopy) {
|
||||
bool was_copied3 = false;
|
||||
// packet3 is the sole owner of the data. ConsumeOrCopy() transfers the
|
||||
// ownership to result3 and makes packet3 empty.
|
||||
::mediapipe::StatusOr<std::unique_ptr<int>> result3 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int>> result3 =
|
||||
packet3.ConsumeOrCopy<int>(&was_copied3);
|
||||
EXPECT_FALSE(was_copied3);
|
||||
EXPECT_TRUE(result3.ok());
|
||||
@@ -358,9 +358,9 @@ TEST(PacketTest, TestPacketConsumeOrCopy) {
|
||||
TEST(PacketTest, TestConsumeForeignHolder) {
|
||||
std::unique_ptr<int> data(new int(33));
|
||||
Packet packet = PointToForeign(data.get());
|
||||
::mediapipe::StatusOr<std::unique_ptr<int>> result = packet.Consume<int>();
|
||||
mediapipe::StatusOr<std::unique_ptr<int>> result = packet.Consume<int>();
|
||||
EXPECT_FALSE(result.ok());
|
||||
EXPECT_EQ(result.status().code(), ::mediapipe::StatusCode::kInternal);
|
||||
EXPECT_EQ(result.status().code(), mediapipe::StatusCode::kInternal);
|
||||
EXPECT_EQ(result.status().message(),
|
||||
"Foreign holder can't release data ptr without ownership.");
|
||||
ASSERT_FALSE(packet.IsEmpty());
|
||||
@@ -372,7 +372,7 @@ TEST(PacketTest, TestForeignHolderConsumeOrCopy) {
|
||||
Packet packet1 = PointToForeign(data1.get());
|
||||
Packet packet_copy = packet1;
|
||||
bool was_copied1 = false;
|
||||
::mediapipe::StatusOr<std::unique_ptr<int>> result1 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int>> result1 =
|
||||
packet_copy.ConsumeOrCopy<int>(&was_copied1);
|
||||
// After ConsumeOrCopy(), result1 gets the copy of packet_copy's data and
|
||||
// packet_copy is set to empty.
|
||||
@@ -388,7 +388,7 @@ TEST(PacketTest, TestForeignHolderConsumeOrCopy) {
|
||||
std::unique_ptr<int> data2(new int(33));
|
||||
Packet packet2 = PointToForeign(data2.get());
|
||||
bool was_copied2 = false;
|
||||
::mediapipe::StatusOr<std::unique_ptr<int>> result2 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int>> result2 =
|
||||
packet2.ConsumeOrCopy<int>(&was_copied2);
|
||||
// After ConsumeOrCopy(), result2 gets the copy of packet2's data and packet2
|
||||
// is set to empty.
|
||||
@@ -402,11 +402,11 @@ TEST(PacketTest, TestForeignHolderConsumeOrCopy) {
|
||||
TEST(PacketTest, TestConsumeBoundedArray) {
|
||||
Packet packet1 = MakePacket<int[3]>(10, 20, 30);
|
||||
Packet packet_copy = packet1;
|
||||
::mediapipe::StatusOr<std::unique_ptr<int[3]>> result1 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int[3]>> result1 =
|
||||
packet_copy.Consume<int[3]>();
|
||||
// Both packet1 and packet_copy own the data, Consume() should return error.
|
||||
::mediapipe::Status status1 = result1.status();
|
||||
EXPECT_EQ(status1.code(), ::mediapipe::StatusCode::kFailedPrecondition);
|
||||
mediapipe::Status status1 = result1.status();
|
||||
EXPECT_EQ(status1.code(), mediapipe::StatusCode::kFailedPrecondition);
|
||||
EXPECT_THAT(status1.message(),
|
||||
testing::HasSubstr("isn't the sole owner of the holder"));
|
||||
ASSERT_FALSE(packet1.IsEmpty());
|
||||
@@ -422,7 +422,7 @@ TEST(PacketTest, TestConsumeBoundedArray) {
|
||||
|
||||
Packet packet2 = MakePacket<int[3]>(40, 50, 60);
|
||||
// After Consume(), packet2 should be empty and result2 owns the data.
|
||||
::mediapipe::StatusOr<std::unique_ptr<int[3]>> result2 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int[3]>> result2 =
|
||||
packet2.Consume<int[3]>();
|
||||
ASSERT_NE(nullptr, result2.ValueOrDie());
|
||||
auto value3 = result2.ValueOrDie().get();
|
||||
@@ -436,7 +436,7 @@ TEST(PacketTest, TestConsumeOrCopyBoundedArray) {
|
||||
Packet packet1 = MakePacket<int[3]>(10, 20, 30);
|
||||
Packet packet_copy = packet1;
|
||||
bool was_copied1 = false;
|
||||
::mediapipe::StatusOr<std::unique_ptr<int[3]>> result1 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int[3]>> result1 =
|
||||
packet_copy.ConsumeOrCopy<int[3]>(&was_copied1);
|
||||
// Both packet1 and packet_copy own the data, ConsumeOrCopy() returns a copy
|
||||
// of the data and sets packet_copy to empty.
|
||||
@@ -459,7 +459,7 @@ TEST(PacketTest, TestConsumeOrCopyBoundedArray) {
|
||||
bool was_copied2 = false;
|
||||
// packet2 is the sole owner of the data. ConsumeOrCopy() transfers the
|
||||
// ownership to result2 and makes packet2 empty.
|
||||
::mediapipe::StatusOr<std::unique_ptr<int[3]>> result2 =
|
||||
mediapipe::StatusOr<std::unique_ptr<int[3]>> result2 =
|
||||
packet2.ConsumeOrCopy<int[3]>(&was_copied2);
|
||||
EXPECT_TRUE(result2.ok());
|
||||
EXPECT_FALSE(was_copied2);
|
||||
|
||||
Reference in New Issue
Block a user