|
| 1 | +// Copyright 2021 The MediaPipe Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "mediapipe/framework/calculator_framework.h" |
| 16 | +#include "mediapipe/framework/calculator_runner.h" |
| 17 | +#include "mediapipe/framework/port/canonical_errors.h" |
| 18 | +#include "mediapipe/framework/port/gmock.h" |
| 19 | +#include "mediapipe/framework/port/gtest.h" |
| 20 | +#include "mediapipe/framework/port/status.h" |
| 21 | +#include "mediapipe/framework/port/status_matchers.h" |
| 22 | +#include "mediapipe/framework/timestamp.h" |
| 23 | +#include "mediapipe/framework/tool/validate_type.h" |
| 24 | +#include "mediapipe/util/packet_test_util.h" |
| 25 | +#include "mediapipe/util/time_series_test_util.h" |
| 26 | + |
| 27 | +namespace mediapipe { |
| 28 | + |
| 29 | +class MakePairCalculatorTest |
| 30 | + : public mediapipe::TimeSeriesCalculatorTest<mediapipe::NoOptions> { |
| 31 | + protected: |
| 32 | + void SetUp() override { |
| 33 | + calculator_name_ = "MakePairCalculator"; |
| 34 | + num_input_streams_ = 2; |
| 35 | + } |
| 36 | +}; |
| 37 | + |
| 38 | +TEST_F(MakePairCalculatorTest, ProducesExpectedPairs) { |
| 39 | + InitializeGraph(); |
| 40 | + AppendInputPacket(new std::string("first packet"), Timestamp(1), |
| 41 | + /* input_index= */ 0); |
| 42 | + AppendInputPacket(new std::string("second packet"), Timestamp(5), |
| 43 | + /* input_index= */ 0); |
| 44 | + AppendInputPacket(new int(10), Timestamp(1), /* input_index= */ 1); |
| 45 | + AppendInputPacket(new int(20), Timestamp(5), /* input_index= */ 1); |
| 46 | + |
| 47 | + MP_ASSERT_OK(RunGraph()); |
| 48 | + |
| 49 | + EXPECT_THAT( |
| 50 | + output().packets, |
| 51 | + ::testing::ElementsAre( |
| 52 | + mediapipe::PacketContainsTimestampAndPayload< |
| 53 | + std::pair<Packet, Packet>>( |
| 54 | + Timestamp(1), |
| 55 | + ::testing::Pair( |
| 56 | + mediapipe::PacketContainsTimestampAndPayload<std::string>( |
| 57 | + Timestamp(1), std::string("first packet")), |
| 58 | + mediapipe::PacketContainsTimestampAndPayload<int>( |
| 59 | + Timestamp(1), 10))), |
| 60 | + mediapipe::PacketContainsTimestampAndPayload< |
| 61 | + std::pair<Packet, Packet>>( |
| 62 | + Timestamp(5), |
| 63 | + ::testing::Pair( |
| 64 | + mediapipe::PacketContainsTimestampAndPayload<std::string>( |
| 65 | + Timestamp(5), std::string("second packet")), |
| 66 | + mediapipe::PacketContainsTimestampAndPayload<int>( |
| 67 | + Timestamp(5), 20))))); |
| 68 | +} |
| 69 | + |
| 70 | +} // namespace mediapipe |
0 commit comments