Files
zoneminder/tests/zm_event_score.cpp
T
Isaac ConnorandClaude Opus 5.5 3a3ac45593 Merge master into event-section-rollover-counts
Resolve the conflicts in src/zm_event.h and tests/zm_event_score.cpp by
keeping both sides: master's ClampSectionLength, EventNamePrefixLength and
BuildNotes tests next to this branch's EventCountsFrameStats and
EventKeepsDraining. Brings in the NEON blend fix the macOS job needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 12:17:56 -05:00

126 lines
4.5 KiB
C++

/*
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "zm_catch2.h"
#include "zm_event.h"
TEST_CASE("EventMaxScoreForDb") {
// An event closed before its first frame still has max_score -1; the
// unsigned Events.MaxScore column must get 0.
REQUIRE(EventMaxScoreForDb(-1) == 0);
REQUIRE(EventMaxScoreForDb(0) == 0);
REQUIRE(EventMaxScoreForDb(42) == 42);
}
TEST_CASE("ClampSectionLength") {
// SectionLength=0 is accepted by the monitor form and used as a modulo.
REQUIRE(ClampSectionLength(Seconds(0)) == Seconds(1));
REQUIRE(ClampSectionLength(Seconds(1)) == Seconds(1));
REQUIRE(ClampSectionLength(Seconds(600)) == Seconds(600));
}
TEST_CASE("Event::BuildNotes") {
Event::StringSetMap notes;
REQUIRE(Event::BuildNotes(notes) == "");
notes["Motion"] = {"Zone1", "Zone2"};
REQUIRE(Event::BuildNotes(notes) == "Motion: Zone1, Zone2");
// Groups must not run together, e.g. "Motion: Zone2Signal: Lost".
notes["Signal"] = {"Lost"};
REQUIRE(Event::BuildNotes(notes) == "Motion: Zone1, Zone2; Signal: Lost");
}
TEST_CASE("EventNamePrefixLength") {
// Events.Name is varchar(64) and the id suffix must survive truncation.
REQUIRE(EventNamePrefixLength(0) == 63);
REQUIRE(EventNamePrefixLength(9) == 63);
REQUIRE(EventNamePrefixLength(10) == 62);
REQUIRE(EventNamePrefixLength(995000206) == 55);
REQUIRE(EventNamePrefixLength(UINT64_MAX) == 44);
}
TEST_CASE("EventCountsFrameStats") {
const auto t0 = std::chrono::system_clock::time_point(std::chrono::seconds(1000));
const auto boundary = t0 + std::chrono::seconds(5);
SECTION("no boundary counts everything") {
CHECK(EventCountsFrameStats(t0, SystemTimePoint()));
CHECK(EventCountsFrameStats(boundary, SystemTimePoint()));
CHECK(EventCountsFrameStats(boundary + std::chrono::seconds(1), SystemTimePoint()));
}
SECTION("earlier than boundary is not counted") {
CHECK_FALSE(EventCountsFrameStats(t0, boundary));
CHECK_FALSE(EventCountsFrameStats(boundary - std::chrono::milliseconds(1), boundary));
}
SECTION("equal to and later than boundary are counted") {
CHECK(EventCountsFrameStats(boundary, boundary));
CHECK(EventCountsFrameStats(boundary + std::chrono::milliseconds(1), boundary));
CHECK(EventCountsFrameStats(boundary + std::chrono::seconds(10), boundary));
}
}
TEST_CASE("EventKeepsDraining") {
const auto t0 = std::chrono::system_clock::time_point(std::chrono::seconds(1000));
const auto boundary = t0 + std::chrono::seconds(5);
ZMPacket packet;
packet.decoded = true;
packet.analyzed = true;
packet.timestamp = t0;
SECTION("not terminated keeps running") {
CHECK(EventKeepsDraining(false, SystemTimePoint(), nullptr));
CHECK(EventKeepsDraining(false, boundary, nullptr));
CHECK(EventKeepsDraining(false, boundary, &packet));
}
SECTION("terminated with zero drain_until stops immediately") {
CHECK_FALSE(EventKeepsDraining(true, SystemTimePoint(), nullptr));
CHECK_FALSE(EventKeepsDraining(true, SystemTimePoint(), &packet));
}
SECTION("terminated with non-zero drain_until stops on null or unanalyzed or boundary") {
CHECK_FALSE(EventKeepsDraining(true, boundary, nullptr));
packet.decoded = false;
CHECK_FALSE(EventKeepsDraining(true, boundary, &packet));
packet.decoded = true;
packet.analyzed = false;
CHECK_FALSE(EventKeepsDraining(true, boundary, &packet));
packet.analyzed = true;
packet.timestamp = boundary;
CHECK_FALSE(EventKeepsDraining(true, boundary, &packet));
packet.timestamp = boundary + std::chrono::seconds(1);
CHECK_FALSE(EventKeepsDraining(true, boundary, &packet));
}
SECTION("terminated with non-zero drain_until keeps draining earlier analyzed packet") {
packet.timestamp = t0;
CHECK(EventKeepsDraining(true, boundary, &packet));
packet.timestamp = boundary - std::chrono::milliseconds(1);
CHECK(EventKeepsDraining(true, boundary, &packet));
}
}