File indexing completed on 2024-05-12 04:57:16

0001 /*
0002     SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
0003     SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef MAIN_TESTS_H
0009 #define MAIN_TESTS_H
0010 
0011 #include "core/range.h"
0012 #include "core/rangelist.h"
0013 #include "core/richstring.h"
0014 #include "core/subtitle.h"
0015 #include "core/subtitleline.h"
0016 #include "core/subtitleiterator.h"
0017 
0018 #include <QGlobal>
0019 #include <QtCore/QString>
0020 
0021 #include <QDebug>
0022 
0023 using namespace SubtitleComposer;
0024 
0025 void
0026 showRanges(const RangeList &ranges)
0027 {
0028     QString aux;
0029     for(RangeList::ConstIterator it = ranges.begin(), end = ranges.end(); it != end; ++it)
0030         aux += QString(" [%1,%2]").arg(it->start()).arg(it->end());
0031 
0032     qDebug() << QString("Showing ranges: %1").arg(aux.trimmed());
0033 }
0034 
0035 void
0036 showSubtitle(const Subtitle &subtitle)
0037 {
0038     qDebug() << "Showing subtitle";
0039     for(int index = 0, size = subtitle.linesCount(); index < size; ++index)
0040         qDebug() << QString("Line: %1").arg(subtitle.line(index)->primaryText().richString());
0041     qDebug() << "--------------------------";
0042 }
0043 
0044 void
0045 iterateSubtitle(const Subtitle &subtitle, const RangeList &ranges)
0046 {
0047     showRanges(ranges);
0048 
0049 //  for ( int idx=0; idx < 3; ++idx )
0050     {
0051         qDebug() << "Iterating subtitle forwards from ranges";
0052         for(SubtitleIterator it(subtitle, ranges); it.current(); ++it)
0053             qDebug() << QString("Line: %1").arg(it.current()->primaryText().richString());
0054 
0055         qDebug() << "Iterating subtitle backwards from ranges";
0056         for(SubtitleIterator it(subtitle, ranges, true); it.current(); --it)
0057             qDebug() << QString("Line: %1").arg(it.current()->primaryText().richString());
0058     }
0059 
0060     qDebug() << "--------------------------";
0061 }
0062 
0063 void
0064 testSubtitleIterator()
0065 {
0066     Subtitle subtitle;
0067 
0068     for(int index = 0; index < 20; ++index)
0069         subtitle.insertLine(new SubtitleLine(QString("Line %1").arg(index)));
0070 
0071     showSubtitle(subtitle);
0072 
0073     iterateSubtitle(subtitle, Range::full());
0074     iterateSubtitle(subtitle, Range::lower(10));
0075     iterateSubtitle(subtitle, Range::upper(10));
0076     iterateSubtitle(subtitle, Range::lower(50));
0077     iterateSubtitle(subtitle, Range::upper(50));
0078     RangeList ranges;
0079     ranges << Range(1, 3);
0080     ranges << Range(5, 5);
0081     ranges << Range(11, 17);
0082     iterateSubtitle(subtitle, ranges);
0083 
0084 //  SubtitleIterator it( subtitle, ranges, true );
0085 //  for ( int idx = 0; idx < 100; ++idx )
0086 //      ++it;
0087 //  for ( int idx = 0; idx < 200; ++idx )
0088 //      --it;
0089 
0090 //  SubtitleIterator it( subtitle, Range( 1, 50 ), true );
0091 //  for ( int idx = 0; idx < 100; ++idx )
0092 //      ++it;
0093 //  for ( int idx = 0; idx < 200; ++idx )
0094 //      --it;
0095 
0096     /*QTime time;
0097        time.start();
0098 
0099        for ( SubtitleIterator it( subtitle, Range::full(), true ); it.current(); --it )
0100        it.current()->text();
0101 
0102        qDebug() << time.elapsed();
0103 
0104        for ( SubtitleIterator it( subtitle, Range::full(), true ); it.current(); --it )
0105        it.current()->text();
0106 
0107        qDebug() << time.elapsed(); */
0108 }
0109 
0110 int
0111 main(int, char **)
0112 {
0113     // testSubtitleIterator();
0114 }
0115 
0116 #endif