Skip to content

Commit

Permalink
BpmFilterNode: adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Apr 4, 2024
1 parent c1718e5 commit e74b713
Showing 1 changed file with 55 additions and 10 deletions.
65 changes: 55 additions & 10 deletions src/test/searchqueryparsertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ TEST_F(SearchQueryParserTest, NumericFilter) {
pTrack->setBitrate(127);
EXPECT_TRUE(pQuery->match(pTrack));

EXPECT_STREQ( // half/double BPM, half
EXPECT_STREQ(
qPrintable(QString("bitrate = 127")),
qPrintable(pQuery->toSql()));
}
Expand Down Expand Up @@ -497,21 +497,36 @@ TEST_F(SearchQueryParserTest, NumericRangeFilter) {
TEST_F(SearchQueryParserTest, BpmFilter) {
m_parser.setSearchColumns({"artist", "album"});

// Test (implicit) half/double BPM match
auto pQuery(m_parser.parseQuery("bpm:127.12", QString()));
// Test BpmFilter's MatchModes:
// HalveDouble
auto pQuery(m_parser.parseQuery("bpm:127", QString()));
TrackPointer pTrack = newTestTrack();
EXPECT_FALSE(pQuery->match(pTrack));
pTrack->trySetBpm(127.13);
EXPECT_TRUE(pQuery->match(pTrack));

EXPECT_STREQ(
qPrintable(QString("(bpm > 126.95 AND bpm < 128) OR "
"(bpm BETWEEN 63 AND 64) OR "
"(bpm BETWEEN 253 AND 255)")),
qPrintable(pQuery->toSql()));

// HalveDoubleStrict
auto pQuery(m_parser.parseQuery("bpm:127.12", QString()));

Check failure on line 515 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

conflicting declaration ‘auto pQuery’

Check failure on line 515 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 x64

redefinition of 'pQuery'

Check failure on line 515 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

redefinition of 'pQuery'

Check failure on line 515 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / coverage

conflicting declaration ‘auto pQuery’

Check failure on line 515 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'pQuery': redefinition; different basic types
TrackPointer pTrack = newTestTrack();

Check failure on line 516 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

redeclaration of ‘TrackPointer pTrack’

Check failure on line 516 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 x64

redefinition of 'pTrack'

Check failure on line 516 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

redefinition of 'pTrack'

Check failure on line 516 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / coverage

redeclaration of ‘TrackPointer pTrack’

Check failure on line 516 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'pTrack': redefinition; multiple initialization
EXPECT_FALSE(pQuery->match(pTrack));

Check failure on line 517 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'match': is not a member of 'std::unique_ptr<QueryNode,std::default_delete<QueryNode>>'

Check failure on line 517 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'testing::AssertionResult': no appropriate default constructor available

Check failure on line 517 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'gtest_ar_': const object must be initialized
pTrack->trySetBpm(127.12);
EXPECT_TRUE(pQuery->match(pTrack));
EXPECT_FALSE(pQuery->match(pTrack));

Check failure on line 519 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'match': is not a member of 'std::unique_ptr<QueryNode,std::default_delete<QueryNode>>'

Check failure on line 519 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'testing::AssertionResult': no appropriate default constructor available

Check failure on line 519 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'gtest_ar_': const object must be initialized

EXPECT_STREQ(

Check failure on line 521 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'toSql': is not a member of 'std::unique_ptr<QueryNode,std::default_delete<QueryNode>>'

Check failure on line 521 in src/test/searchqueryparsertest.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'testing::internal::CmpHelperSTREQ': no overloaded function takes 3 arguments
qPrintable(QString("(bpm BETWEEN 127.115 AND 127.125) OR "
"(bpm BETWEEN 63 AND 64) OR "
"(bpm BETWEEN 254 AND 255)")),
"(bpm BETWEEN 63.555 AND 63.565) OR "
"(bpm BETWEEN 254.235 AND 254.245)")),
qPrintable(pQuery->toSql()));

// Test (explicit) exact match
// ExplicitStrict
// '=' omits halve/double ==> MatchMode::Explicit
// decimals engage Strict mode
pQuery = m_parser.parseQuery("bpm:=127.12", QString());
EXPECT_TRUE(pQuery->match(pTrack));
pTrack->trySetBpm(127.13);
Expand All @@ -521,7 +536,7 @@ TEST_F(SearchQueryParserTest, BpmFilter) {
qPrintable(QString("bpm BETWEEN 127.115 AND 127.125")),
qPrintable(pQuery->toSql()));

// Test BPM range
// Range
pQuery = m_parser.parseQuery("bpm:127.12-129", QString());
pTrack->trySetBpm(125);
EXPECT_FALSE(pQuery->match(pTrack));
Expand All @@ -534,7 +549,7 @@ TEST_F(SearchQueryParserTest, BpmFilter) {
qPrintable(QString("bpm BETWEEN 127.12 AND 129")),
qPrintable(pQuery->toSql()));

// Test fuzzy BPM match
// Fuzzy
// Should be enabled by default and default range is 6% (= 75% of default
// pitch slider range)
pQuery = m_parser.parseQuery("~bpm:100", QString());
Expand All @@ -548,13 +563,43 @@ TEST_F(SearchQueryParserTest, BpmFilter) {
qPrintable(QString("bpm BETWEEN 94 AND 106")),
qPrintable(pQuery->toSql()));

// Test empty BPM
// Test empty BPM (incomplete query)
pQuery = m_parser.parseQuery("bpm:", QString());
EXPECT_TRUE(pQuery->match(pTrack));

EXPECT_STREQ(
qPrintable(QString("")),
qPrintable(pQuery->toSql()));

// Null
pQuery = m_parser.parseQuery("bpm:\"\"", QString());
EXPECT_FALSE(pQuery->match(pTrack));

EXPECT_STREQ(
qPrintable(QString("bpm IS 0")),
qPrintable(pQuery->toSql()));
// Null
pQuery = m_parser.parseQuery("bpm:00.0", QString());
EXPECT_FALSE(pQuery->match(pTrack));

EXPECT_STREQ(
qPrintable(QString("bpm IS 0")),
qPrintable(pQuery->toSql()));
// Null
pQuery = m_parser.parseQuery("bpm:-", QString());
EXPECT_FALSE(pQuery->match(pTrack));

EXPECT_STREQ(
qPrintable(QString("bpm IS 0")),
qPrintable(pQuery->toSql()));

// Invalid ~bpm:= | ~bpm:12-34
pQuery = m_parser.parseQuery("~bpm:=106", QString());
EXPECT_FALSE(pQuery->match(pTrack));

EXPECT_STREQ(
qPrintable(QString("bpm IS NULL")),
qPrintable(pQuery->toSql()));
}

TEST_F(SearchQueryParserTest, MultipleFilters) {
Expand Down

0 comments on commit e74b713

Please sign in to comment.