Skip to content

Commit

Permalink
FramePos: Ensure that all invalid frame positions are equal
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jul 3, 2021
1 parent a710a02 commit 7c5f330
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/audio/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ inline bool operator>=(FramePos frame1, FramePos frame2) {
}

inline bool operator==(FramePos frame1, FramePos frame2) {
return frame1.value() == frame2.value();
if (frame1.isValid() && frame1.isValid()) {
return frame1.value() == frame2.value();
}

if (!frame1.isValid() && !frame1.isValid()) {
return true;
}

return false;
}

inline bool operator!=(FramePos frame1, FramePos frame2) {
Expand Down
31 changes: 31 additions & 0 deletions src/test/frametest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,34 @@ TEST_F(FrameTest, TestFramePosFractional) {
EXPECT_TRUE(mixxx::audio::FramePos(128.5).isFractional());
EXPECT_TRUE(mixxx::audio::FramePos(135.67).isFractional());
}

TEST_F(FrameTest, TestFramePosEquality) {
EXPECT_EQ(mixxx::audio::FramePos(0), mixxx::audio::FramePos(0));
EXPECT_EQ(mixxx::audio::FramePos(-100), mixxx::audio::FramePos(-100));
EXPECT_EQ(mixxx::audio::FramePos(100), mixxx::audio::FramePos(100));
EXPECT_EQ(mixxx::audio::FramePos(50) * 2, mixxx::audio::FramePos(100));

EXPECT_NE(mixxx::audio::FramePos(100), mixxx::audio::FramePos(200));
EXPECT_NE(mixxx::audio::FramePos(100), mixxx::audio::FramePos());
EXPECT_NE(mixxx::audio::FramePos(0), mixxx::audio::FramePos());

// Check that invalid positions are equal to each other
EXPECT_EQ(mixxx::audio::FramePos(), mixxx::audio::kInvalidFramePos);
EXPECT_EQ(mixxx::audio::FramePos(), mixxx::audio::kInvalidFramePos / 2);
EXPECT_EQ(mixxx::audio::FramePos(),
mixxx::audio::FramePos(mixxx::audio::FramePos::kInvalidValue));
EXPECT_EQ(mixxx::audio::FramePos(),
mixxx::audio::FramePos(std::numeric_limits<
mixxx::audio::FramePos::value_t>::quiet_NaN()));
EXPECT_EQ(mixxx::audio::FramePos(),
mixxx::audio::FramePos(std::numeric_limits<
mixxx::audio::FramePos::value_t>::infinity()));
EXPECT_EQ(mixxx::audio::FramePos(),
mixxx::audio::FramePos(
-std::numeric_limits<
mixxx::audio::FramePos::value_t>::infinity()));
EXPECT_EQ(mixxx::audio::FramePos(std::numeric_limits<
mixxx::audio::FramePos::value_t>::quiet_NaN()),
mixxx::audio::FramePos(std::numeric_limits<
mixxx::audio::FramePos::value_t>::infinity()));
}

0 comments on commit 7c5f330

Please sign in to comment.