Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better fix for MythDate::formatTime to handle overflows.
Fixes #520.
- Loading branch information
1 parent
2d7a09e
commit 65b9c73
Showing
8 changed files
with
163 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test_mythdate |
59 changes: 59 additions & 0 deletions
59
mythtv/libs/libmythbase/test/test_mythdate/test_mythdate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Class TestMythDate | ||
* | ||
* Copyright (c) David Hampton 2022 | ||
* | ||
* 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, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
#include "test_mythdate.h" | ||
|
||
void TestMythDate::formatting_data(void) | ||
{ | ||
QTest::addColumn<std::chrono::milliseconds>("msecs"); | ||
QTest::addColumn<QString>("fmt"); | ||
QTest::addColumn<QString>("expected"); | ||
|
||
QTest::newRow( "m:ss") << 192876ms << "m:ss" << "3:12"; | ||
QTest::newRow( "mm:ss") << 192876ms << "mm:ss" << "03:12"; | ||
QTest::newRow( "mm:ss oflow") << 17112876ms << "mm:ss" << "285:12"; | ||
QTest::newRow(" H:mm:ss") << 17112876ms << "H:mm:ss" << "4:45:12"; | ||
QTest::newRow("HH:mm:ss") << 17112876ms << "HH:mm:ss" << "04:45:12"; | ||
QTest::newRow(" H:mm:ss oflow") << 1169112876ms << "H:mm:ss" << "324:45:12"; | ||
QTest::newRow("HH:mm:ss oflow") << 1169112876ms << "HH:mm:ss" << "324:45:12"; | ||
|
||
QTest::newRow("HH:mm:ss.") << 17112876ms << "HH:mm:ss." << "04:45:12."; | ||
QTest::newRow("HH:mm:ss.z") << 17112876ms << "HH:mm:ss.z" << "04:45:12.8"; | ||
QTest::newRow("HH:mm:ss.zz") << 17112876ms << "HH:mm:ss.zz" << "04:45:12.87"; | ||
QTest::newRow("HH:mm:ss.zzz") << 17112876ms << "HH:mm:ss.zzz" << "04:45:12.876"; | ||
QTest::newRow("HH:mm:ss.000") << 17112000ms << "HH:mm:ss.zzz" << "04:45:12.000"; | ||
QTest::newRow("HH:mm:ss.05") << 17112050ms << "HH:mm:ss.zz" << "04:45:12.05"; | ||
|
||
// Precison maxes out at 3. This is a millisecond function. | ||
QTest::newRow("HH:mm:ss.zzzzzz")<< 17112876ms << "HH:mm:ss.zzzzzz" << "04:45:12.876"; | ||
QTest::newRow("silly overflow") << 1169112876ms << "HHHHHHHH:mm:ss.z" << "00000324:45:12.8"; | ||
QTest::newRow("random chars") << 1169112876ms << "!HH@mm#ss%zzzzzz" << "!324@45#12%876"; | ||
} | ||
|
||
void TestMythDate::formatting(void) | ||
{ | ||
QFETCH(std::chrono::milliseconds, msecs); | ||
QFETCH(QString, fmt); | ||
QFETCH(QString, expected); | ||
|
||
QString actual = MythDate::formatTime(std::chrono::milliseconds(msecs), fmt); | ||
QCOMPARE(actual, expected); | ||
} | ||
|
||
QTEST_APPLESS_MAIN(TestMythDate) |
33 changes: 33 additions & 0 deletions
33
mythtv/libs/libmythbase/test/test_mythdate/test_mythdate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Class TestMythDate | ||
* | ||
* Copyright (c) David Hampton 2022 | ||
* | ||
* 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, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include <QtTest/QtTest> | ||
#include <iostream> | ||
|
||
#include "mythdate.h" | ||
|
||
class TestMythDate : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private slots: | ||
static void formatting_data(void); | ||
static void formatting(void); | ||
}; |
20 changes: 20 additions & 0 deletions
20
mythtv/libs/libmythbase/test/test_mythdate/test_mythdate.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
include ( ../../../../settings.pro ) | ||
include ( ../../../../test.pro ) | ||
|
||
QT += testlib | ||
|
||
TEMPLATE = app | ||
TARGET = test_mythdate | ||
DEPENDPATH += . ../.. | ||
INCLUDEPATH += . ../.. | ||
LIBS += -L../.. -lmythbase-$$LIBVERSION | ||
LIBS += -Wl,$$_RPATH_$${PWD}/../.. | ||
|
||
# Input | ||
HEADERS += test_mythdate.h | ||
SOURCES += test_mythdate.cpp | ||
|
||
QMAKE_CLEAN += $(TARGET) | ||
QMAKE_CLEAN += ; ( cd $(OBJECTS_DIR) && rm -f *.gcov *.gcda *.gcno ) | ||
|
||
LIBS += $$EXTRA_LIBS $$LATE_LIBS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65b9c73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mythdate.cpp:264:
static constexpr std::array<int,4> divisor = {1000, 100, 10, 1};
is failing to compile with
error: constexpr variable cannot have non-literal type 'const std::array<int, 4>'
(llvm/clang 13.0.1 MacOS 12.1)
Solved by adding
#include <array>
at the top of the file or in mythdate.h