File indexing completed on 2024-12-22 04:10:25

0001 /*
0002  *  SPDX-License-Identifier: GPL-3.0-or-later
0003  */
0004 
0005 #include "kis_time_span_test.h"
0006 #include "kis_time_span.h"
0007 
0008 void KisTimeSpanTest::testCreationMethods()
0009 {
0010     {   // Test fromTimeToTime..
0011         const int start = 20;
0012         const int end = 100;
0013         KisTimeSpan span = KisTimeSpan::fromTimeToTime(start, end);
0014         QVERIFY(span.start() == start);
0015         QVERIFY(span.end() == end);
0016     }
0017 
0018     {   // Test fromTimeWithDuration..
0019         const int start = 20;
0020         const int end = 150;
0021         const int length = (end - start) + 1; // +1 since end is inclusive..
0022         KisTimeSpan span = KisTimeSpan::fromTimeWithDuration(start, length);
0023         QVERIFY(span.start() == start);
0024         QVERIFY(span.end() == end);
0025     }
0026 
0027     {   //Test infinite..
0028 
0029         const int start = 20;
0030         KisTimeSpan span = KisTimeSpan::infinite(start);
0031         QVERIFY(span.isInfinite());
0032         QVERIFY(span.start() == start);
0033     }
0034 
0035     {   // Test scenarios where time spans should be invalid.
0036 
0037         // Test invalid specifying from a time to a time less than the start time.
0038         QVERIFY(KisTimeSpan::fromTimeToTime(10, 5).isValid() == false);
0039 
0040         // Test invalid specifying a time with a negative length.
0041         QVERIFY(KisTimeSpan::fromTimeWithDuration(10, -5).isValid() == false);
0042     }
0043 
0044 
0045 }
0046 
0047 void KisTimeSpanTest::testTimeSpanOperators()
0048 {
0049     const KisTimeSpan spanA = KisTimeSpan::fromTimeToTime(0, 25);
0050     const KisTimeSpan spanB = KisTimeSpan::fromTimeToTime(15, 30);
0051 
0052     {   // Union test..
0053         KisTimeSpan spanABU = spanA | spanB;
0054         QCOMPARE(spanABU.start(), spanA.start());
0055         QCOMPARE(spanABU.end(), spanB.end());
0056 
0057         const KisTimeSpan spanC = KisTimeSpan::fromTimeToTime(20, 60);
0058         spanABU |= spanC;
0059 
0060         QCOMPARE(spanABU.start(), spanA.start());
0061         QCOMPARE(spanABU.end(), spanC.end());
0062     }
0063 
0064     {   // Intersection test..
0065         KisTimeSpan spanABI = spanA & spanB; // Span should be 15 => 25
0066 
0067         QCOMPARE(spanABI.start(), spanB.start());
0068         QCOMPARE(spanABI.end(), spanA.end());
0069 
0070         const KisTimeSpan spanC = KisTimeSpan::fromTimeToTime(0, 20);
0071         spanABI &= spanC; // Span should be 15 => 20
0072 
0073         QCOMPARE(spanABI.start(), spanB.start());
0074         QCOMPARE(spanABI.end(), spanC.end());
0075     }
0076 }
0077 
0078 SIMPLE_TEST_MAIN(KisTimeSpanTest)