| 27 | } // namespace |
| 28 | |
| 29 | int main() |
| 30 | { |
| 31 | bool ok = true; |
| 32 | |
| 33 | // --- parseRule ------------------------------------------------------ |
| 34 | { |
| 35 | const auto r = NetRecurrence::parseRule("FREQ=WEEKLY;BYDAY=TU"); |
| 36 | ok &= expect(r.isValid() && r.freq == NetRecurrence::ParsedRule::Freq::Weekly, |
| 37 | "weekly rule parses"); |
| 38 | ok &= expect(r.weekdays.size() == 1 && r.weekdays.first() == 2, |
| 39 | "weekly BYDAY=TU maps to Qt day 2"); |
| 40 | } |
| 41 | { |
| 42 | const auto r = NetRecurrence::parseRule("FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,WE,FR"); |
| 43 | ok &= expect(r.interval == 2 && r.weekdays.size() == 3, |
| 44 | "weekly interval + multi BYDAY parse"); |
| 45 | } |
| 46 | { |
| 47 | const auto r = NetRecurrence::parseRule("FREQ=MONTHLY;BYDAY=1SU"); |
| 48 | ok &= expect(r.isValid() && r.monthlyOrdinal == 1 && r.monthlyWeekday == 7, |
| 49 | "monthly first-Sunday parses"); |
| 50 | } |
| 51 | { |
| 52 | const auto r = NetRecurrence::parseRule("FREQ=MONTHLY;BYDAY=-1WE"); |
| 53 | ok &= expect(r.isValid() && r.monthlyOrdinal == -1 && r.monthlyWeekday == 3, |
| 54 | "monthly last-Wednesday parses"); |
| 55 | } |
| 56 | { |
| 57 | ok &= expect(!NetRecurrence::parseRule("FREQ=YEARLY").isValid(), |
| 58 | "unsupported FREQ is invalid"); |
| 59 | ok &= expect(!NetRecurrence::parseRule("garbage").isValid(), |
| 60 | "garbage rule is invalid"); |
| 61 | ok &= expect(!NetRecurrence::parseRule("FREQ=MONTHLY").isValid(), |
| 62 | "monthly without BYDAY is invalid"); |
| 63 | } |
| 64 | |
| 65 | // --- weekly next occurrence ---------------------------------------- |
| 66 | { |
| 67 | // Tuesdays 20:00 UTC. After 2026-06-01 00:00Z → Tue Jun 2 20:00Z. |
| 68 | const QDateTime occ = NetRecurrence::nextOccurrence( |
| 69 | "FREQ=WEEKLY;BYDAY=TU", "20:00", "Etc/UTC", QDate(), utc(2026, 6, 1, 0, 0)); |
| 70 | ok &= expect(occ.toUTC() == utc(2026, 6, 2, 20, 0), |
| 71 | "weekly Tuesday picks the next Tuesday at 20:00 UTC"); |
| 72 | } |
| 73 | { |
| 74 | // Same day but earlier than the time → still fires today. |
| 75 | const QDateTime occ = NetRecurrence::nextOccurrence( |
| 76 | "FREQ=WEEKLY;BYDAY=TU", "20:00", "Etc/UTC", QDate(), utc(2026, 6, 2, 10, 0)); |
| 77 | ok &= expect(occ.toUTC() == utc(2026, 6, 2, 20, 0), |
| 78 | "same-day occurrence later than now is returned"); |
| 79 | } |
| 80 | { |
| 81 | // Strictly after: at exactly the occurrence, return the next week. |
| 82 | const QDateTime occ = NetRecurrence::nextOccurrence( |
| 83 | "FREQ=WEEKLY;BYDAY=TU", "20:00", "Etc/UTC", QDate(), utc(2026, 6, 2, 20, 0)); |
| 84 | ok &= expect(occ.toUTC() == utc(2026, 6, 9, 20, 0), |
| 85 | "occurrence is strictly after the reference instant"); |
| 86 | } |
nothing calls this directly
no test coverage detected