From e3fdd8d5fe5b739b28c67539bbdb0b596f9dacbe Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 31 Mar 2016 16:06:01 +0200 Subject: WINTERMUTE: Add tests for engines/wintermute/path_utils.h --- test/engines/wintermute/path_utils.h | 200 +++++++++++++++++++++++++++++++++++ test/module.mk | 4 +- 2 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 test/engines/wintermute/path_utils.h (limited to 'test') diff --git a/test/engines/wintermute/path_utils.h b/test/engines/wintermute/path_utils.h new file mode 100644 index 0000000000..c3f1776231 --- /dev/null +++ b/test/engines/wintermute/path_utils.h @@ -0,0 +1,200 @@ +#include +#include "engines/wintermute/utils/path_util.h" +/** + * Test suite for the functions in engines/wintermute/utils/path_util.h + * + * NOTE: This is not a prescription; + * this was not written by the original engine author; + * this was not written by the engine porter. + * + * It might, however, help to spot variations in behavior that are introduced by modifications + */ + +class PathUtilTestSuite : public CxxTest::TestSuite { + public: + const Common::String unixPath; + const Common::String unixCapPath; + const Common::String windowsPath; + const Common::String windowsCapPath; + const Common::String emptyString; + const Common::String dualExtPath; + const Common::String manyExtPath; + const Common::String mixedSlashesPath1; + const Common::String mixedSlashesPath2; + const Common::String unixRelativePath; + const Common::String windowsRelativePath; + PathUtilTestSuite () : + unixPath("/some/file.ext"), + unixCapPath("/SOME/FILE.EXT"), + windowsPath("C:\\some\\file.ext"), + windowsCapPath("C:\\SOME\\FILE.EXT"), + emptyString(""), + dualExtPath("/some/file.tar.gz"), + manyExtPath("/some/file.tar.bz2.gz.zip"), + mixedSlashesPath1("C:\\this/IS_REALLY\\weird.exe"), + mixedSlashesPath2("/pretty\\weird/indeed.txt"), + unixRelativePath("some/file.ext"), + windowsRelativePath("some\\file.ext") + {} + void test_getdirectoryname() { + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(unixPath), + Common::String("/some/") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(unixCapPath), + Common::String("/SOME/") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(windowsPath), + Common::String("C:\\some\\") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(windowsCapPath), + Common::String("C:\\SOME\\") + ); + } + + void test_getfilename() { + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(unixPath), + Common::String("file.ext") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(unixCapPath), + Common::String("FILE.EXT") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(windowsPath), + Common::String("file.ext") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(windowsCapPath), + Common::String("FILE.EXT") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(unixRelativePath), + Common::String("file.ext") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(windowsRelativePath), + Common::String("file.ext") + ); + } + + void test_getextension() { + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getExtension(windowsPath), + Common::String("ext") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getExtension(windowsCapPath), + Common::String("EXT") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getExtension(dualExtPath), + Common::String("gz") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getExtension(manyExtPath), + Common::String("zip") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getExtension(unixRelativePath), + Common::String("ext") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getExtension(windowsRelativePath), + Common::String("ext") + ); + } + + void test_getfilenamewithoutextension() { + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileNameWithoutExtension(windowsPath), + Common::String("file") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileNameWithoutExtension(windowsCapPath), + Common::String("FILE") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileNameWithoutExtension(dualExtPath), + Common::String("file.tar") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileNameWithoutExtension(manyExtPath), + Common::String("file.tar.bz2.gz") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileNameWithoutExtension(unixRelativePath), + Common::String("file") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileNameWithoutExtension(windowsRelativePath), + Common::String("file") + ); + } + + void test_combine_identity() { + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(windowsPath) + + Wintermute::PathUtil::getFileNameWithoutExtension(windowsPath) + + "." + + Wintermute::PathUtil::getExtension(windowsPath), + windowsPath + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(windowsCapPath) + + Wintermute::PathUtil::getFileNameWithoutExtension(windowsCapPath) + + "." + + Wintermute::PathUtil::getExtension(windowsCapPath), + windowsCapPath + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(unixCapPath) + + Wintermute::PathUtil::getFileNameWithoutExtension(unixCapPath) + + "." + + Wintermute::PathUtil::getExtension(unixCapPath), + unixCapPath + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(manyExtPath) + + Wintermute::PathUtil::getFileNameWithoutExtension(manyExtPath) + + "." + + Wintermute::PathUtil::getExtension(manyExtPath), + manyExtPath + ); + } + + void test_normalize() { + TS_ASSERT_EQUALS( + Wintermute::PathUtil::normalizeFileName(windowsCapPath), + Common::String("c:/some/file.ext") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::normalizeFileName(windowsPath), + Common::String("c:/some/file.ext") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::normalizeFileName(mixedSlashesPath1), + Common::String("c:/this/is_really/weird.exe") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::normalizeFileName(mixedSlashesPath2), + Common::String("/pretty/weird/indeed.txt") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::normalizeFileName(emptyString), + emptyString + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::normalizeFileName(unixRelativePath), + unixRelativePath + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::normalizeFileName(windowsRelativePath), + unixRelativePath // NOT windows + ); + } +}; diff --git a/test/module.mk b/test/module.mk index 11ee6bd200..da469b4263 100644 --- a/test/module.mk +++ b/test/module.mk @@ -5,8 +5,8 @@ # ###################################################################### -TESTS := $(srcdir)/test/common/*.h $(srcdir)/test/audio/*.h -TEST_LIBS := audio/libaudio.a common/libcommon.a +TESTS := $(srcdir)/test/common/*.h $(srcdir)/test/audio/*.h $(srcdir)/test/engines/wintermute/*.h +TEST_LIBS := audio/libaudio.a common/libcommon.a engines/wintermute/libwintermute.a # TEST_FLAGS := --runner=StdioPrinter --no-std --no-eh --include=$(srcdir)/test/cxxtest_mingw.h -- cgit v1.2.3 From 93394902368a0fb2c25647f0d6205f5a43282933 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 26 Dec 2016 10:42:29 +0100 Subject: WINTERMUTE: only access -1th char of string if length > 0 in getFileName Fixes #6594 --- test/engines/wintermute/path_utils.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/engines/wintermute/path_utils.h b/test/engines/wintermute/path_utils.h index c3f1776231..3cacf47fd9 100644 --- a/test/engines/wintermute/path_utils.h +++ b/test/engines/wintermute/path_utils.h @@ -53,6 +53,10 @@ class PathUtilTestSuite : public CxxTest::TestSuite { Wintermute::PathUtil::getDirectoryName(windowsCapPath), Common::String("C:\\SOME\\") ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(emptyString), + Common::String("") + ); } void test_getfilename() { @@ -72,6 +76,10 @@ class PathUtilTestSuite : public CxxTest::TestSuite { Wintermute::PathUtil::getFileName(windowsCapPath), Common::String("FILE.EXT") ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(emptyString), + Common::String("") + ); TS_ASSERT_EQUALS( Wintermute::PathUtil::getFileName(unixRelativePath), Common::String("file.ext") @@ -80,6 +88,14 @@ class PathUtilTestSuite : public CxxTest::TestSuite { Wintermute::PathUtil::getFileName(windowsRelativePath), Common::String("file.ext") ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(windowsDirPath), + Common::String("") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileName(unixDirPath), + Common::String("") + ); } void test_getextension() { @@ -91,6 +107,10 @@ class PathUtilTestSuite : public CxxTest::TestSuite { Wintermute::PathUtil::getExtension(windowsCapPath), Common::String("EXT") ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getExtension(emptyString), + Common::String("") + ); TS_ASSERT_EQUALS( Wintermute::PathUtil::getExtension(dualExtPath), Common::String("gz") @@ -118,6 +138,10 @@ class PathUtilTestSuite : public CxxTest::TestSuite { Wintermute::PathUtil::getFileNameWithoutExtension(windowsCapPath), Common::String("FILE") ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getFileNameWithoutExtension(emptyString), + Common::String("") + ); TS_ASSERT_EQUALS( Wintermute::PathUtil::getFileNameWithoutExtension(dualExtPath), Common::String("file.tar") -- cgit v1.2.3 From 72376681afad3e57ffa2134d76ad649a38c86023 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 26 Dec 2016 11:55:06 +0100 Subject: WINTERMUTE: Try to "correctly" handle dir paths I put scare quotes around "correctly" because I can't swear this is the intended behaviour of the original interpreter. I don't think accessing filenames that end with / in the .DCPs is even defined behaviour, so this is a best guess. --- test/engines/wintermute/path_utils.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/engines/wintermute/path_utils.h b/test/engines/wintermute/path_utils.h index 3cacf47fd9..26f3404396 100644 --- a/test/engines/wintermute/path_utils.h +++ b/test/engines/wintermute/path_utils.h @@ -23,6 +23,8 @@ class PathUtilTestSuite : public CxxTest::TestSuite { const Common::String mixedSlashesPath2; const Common::String unixRelativePath; const Common::String windowsRelativePath; + const Common::String unixDirPath; + const Common::String windowsDirPath; PathUtilTestSuite () : unixPath("/some/file.ext"), unixCapPath("/SOME/FILE.EXT"), @@ -34,7 +36,9 @@ class PathUtilTestSuite : public CxxTest::TestSuite { mixedSlashesPath1("C:\\this/IS_REALLY\\weird.exe"), mixedSlashesPath2("/pretty\\weird/indeed.txt"), unixRelativePath("some/file.ext"), - windowsRelativePath("some\\file.ext") + windowsRelativePath("some\\file.ext"), + unixDirPath("/some/dir/"), + windowsDirPath("C:\\some\\dir\\") {} void test_getdirectoryname() { TS_ASSERT_EQUALS( @@ -57,6 +61,14 @@ class PathUtilTestSuite : public CxxTest::TestSuite { Wintermute::PathUtil::getDirectoryName(emptyString), Common::String("") ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(unixDirPath), + Common::String("/some/dir/") + ); + TS_ASSERT_EQUALS( + Wintermute::PathUtil::getDirectoryName(windowsDirPath), + Common::String("C:\\some\\dir\\") + ); } void test_getfilename() { -- cgit v1.2.3