diff options
author | Arne Morten Kvarving <cptspiff@gmail.com> | 2015-03-27 21:56:02 +0100 |
---|---|---|
committer | Arne Morten Kvarving <cptspiff@gmail.com> | 2015-04-10 16:42:20 +0200 |
commit | 377d9fec80d10a6589632c02ba2ff633209f0290 (patch) | |
tree | 6c2982da868360ca6f3e1d784634dfcbd07afa0e | |
parent | d38eafcdbd1ffc5e1c26c0b99c53f0f8b5fd83a1 (diff) |
move CUtil tests to gtest unit tests
-rw-r--r-- | xbmc/Util.cpp | 64 | ||||
-rw-r--r-- | xbmc/Util.h | 6 | ||||
-rw-r--r-- | xbmc/test/Makefile | 1 | ||||
-rw-r--r-- | xbmc/test/TestUtil.cpp | 100 |
4 files changed, 101 insertions, 70 deletions
diff --git a/xbmc/Util.cpp b/xbmc/Util.cpp index 4d085554ea..90fe9989a8 100644 --- a/xbmc/Util.cpp +++ b/xbmc/Util.cpp @@ -343,42 +343,6 @@ void CUtil::GetQualifiedFilename(const std::string &strBasePath, std::string &st } } -#ifdef UNIT_TESTING -bool CUtil::TestGetQualifiedFilename() -{ - std::string file = "../foo"; GetQualifiedFilename("smb://", file); - if (file != "foo") return false; - file = "C:\\foo\\bar"; GetQualifiedFilename("smb://", file); - if (file != "C:\\foo\\bar") return false; - file = "../foo/./bar"; GetQualifiedFilename("smb://my/path", file); - if (file != "smb://my/foo/bar") return false; - file = "smb://foo/bar/"; GetQualifiedFilename("upnp://", file); - if (file != "smb://foo/bar/") return false; - return true; -} - -bool CUtil::TestMakeLegalPath() -{ - std::string path; -#ifdef TARGET_WINDOWS - path = "C:\\foo\\bar"; path = MakeLegalPath(path); - if (path != "C:\\foo\\bar") return false; - path = "C:\\foo:\\bar\\"; path = MakeLegalPath(path); - if (path != "C:\\foo_\\bar\\") return false; -#elif - path = "/foo/bar/"; path = MakeLegalPath(path); - if (path != "/foo/bar/") return false; - path = "/foo?/bar"; path = MakeLegalPath(path); - if (path != "/foo_/bar") return false; -#endif - path = "smb://foo/bar"; path = MakeLegalPath(path); - if (path != "smb://foo/bar") return false; - path = "smb://foo/bar?/"; path = MakeLegalPath(path); - if (path != "smb://foo/bar_/") return false; - return true; -} -#endif - void CUtil::RunShortcut(const char* szShortcutPath) { } @@ -996,34 +960,6 @@ bool CUtil::IsUsingTTFSubtitles() return URIUtils::HasExtension(CSettings::Get().GetString("subtitles.font"), ".ttf"); } -#ifdef UNIT_TESTING -bool CUtil::TestSplitExec() -{ - std::string function; - vector<std::string> params; - CUtil::SplitExecFunction("ActivateWindow(Video, \"C:\\test\\foo\")", function, params); - if (function != "ActivateWindow" || params.size() != 2 || params[0] != "Video" || params[1] != "C:\\test\\foo") - return false; - params.clear(); - CUtil::SplitExecFunction("ActivateWindow(Video, \"C:\\test\\foo\\\")", function, params); - if (function != "ActivateWindow" || params.size() != 2 || params[0] != "Video" || params[1] != "C:\\test\\foo\"") - return false; - CUtil::SplitExecFunction("ActivateWindow(Video, \"C:\\\\test\\\\foo\\\\\")", function, params); - if (function != "ActivateWindow" || params.size() != 2 || params[0] != "Video" || params[1] != "C:\\test\\foo\\") - return false; - CUtil::SplitExecFunction("ActivateWindow(Video, \"C:\\\\\\\\test\\\\\\foo\\\\\")", function, params); - if (function != "ActivateWindow" || params.size() != 2 || params[0] != "Video" || params[1] != "C:\\\\test\\\\foo\\") - return false; - CUtil::SplitExecFunction("SetProperty(Foo,\"\")", function, params); - if (function != "SetProperty" || params.size() != 2 || params[0] != "Foo" || params[1] != "") - return false; - CUtil::SplitExecFunction("SetProperty(foo,ba(\"ba black )\",sheep))", function, params); - if (function != "SetProperty" || params.size() != 2 || params[0] != "foo" || params[1] != "ba(\"ba black )\",sheep)") - return false; - return true; -} -#endif - void CUtil::SplitExecFunction(const std::string &execString, std::string &function, vector<string> ¶meters) { std::string paramString; diff --git a/xbmc/Util.h b/xbmc/Util.h index cd6edf49c2..af0a5b00ed 100644 --- a/xbmc/Util.h +++ b/xbmc/Util.h @@ -161,12 +161,6 @@ public: static bool SupportsReadFileOperations(const std::string& strPath); static std::string GetDefaultFolderThumb(const std::string &folderThumb); -#ifdef UNIT_TESTING - static bool TestSplitExec(); - static bool TestGetQualifiedFilename(); - static bool TestMakeLegalPath(); -#endif - static void InitRandomSeed(); // Get decimal integer representation of roman digit, ivxlcdm are valid diff --git a/xbmc/test/Makefile b/xbmc/test/Makefile index da46e42c21..cfcbef4801 100644 --- a/xbmc/test/Makefile +++ b/xbmc/test/Makefile @@ -3,6 +3,7 @@ SRCS= \ TestFileItem.cpp \ TestTextureUtils.cpp \ TestURL.cpp \ + TestUtil.cpp \ TestUtils.cpp \ xbmc-test.cpp diff --git a/xbmc/test/TestUtil.cpp b/xbmc/test/TestUtil.cpp new file mode 100644 index 0000000000..bd44f5a2cb --- /dev/null +++ b/xbmc/test/TestUtil.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2005-2013 Team XBMC + * http://xbmc.org + * + * 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, 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 XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "Util.h" + +#include "gtest/gtest.h" + +TEST(TestUtil, GetQualifiedFilename) +{ + std::string file = "../foo"; + CUtil::GetQualifiedFilename("smb://", file); + EXPECT_EQ(file, "foo"); + file = "C:\\foo\\bar"; + CUtil::GetQualifiedFilename("smb://", file); + EXPECT_EQ(file, "C:\\foo\\bar"); + file = "../foo/./bar"; + CUtil::GetQualifiedFilename("smb://my/path", file); + EXPECT_EQ(file, "smb://my/foo/bar"); + file = "smb://foo/bar/"; + CUtil::GetQualifiedFilename("upnp://", file); + EXPECT_EQ(file, "smb://foo/bar/"); +} + +TEST(TestUtil, MakeLegalPath) +{ + std::string path; +#ifdef TARGET_WINDOWS + path = "C:\\foo\\bar"; + EXPECT_EQ(CUtil::MakeLegalPath(path), "C:\\foo\\bar"); + path = "C:\\foo:\\bar\\"; + EXPECT_EQ(CUtil::MakeLegalPath(path), "C:\\foo_\\bar\\"); +#else + path = "/foo/bar/"; + EXPECT_EQ(CUtil::MakeLegalPath(path),"/foo/bar/"); + path = "/foo?/bar"; + EXPECT_EQ(CUtil::MakeLegalPath(path),"/foo_/bar"); +#endif + path = "smb://foo/bar"; + EXPECT_EQ(CUtil::MakeLegalPath(path), "smb://foo/bar"); + path = "smb://foo/bar?/"; + EXPECT_EQ(CUtil::MakeLegalPath(path), "smb://foo/bar_/"); +} + +TEST(TestUtil, SplitExec) +{ + std::string function; + std::vector<std::string> params; + CUtil::SplitExecFunction("ActivateWindow(Video, \"C:\\test\\foo\")", function, params); + EXPECT_EQ(function, "ActivateWindow"); + EXPECT_EQ(params.size(), 2); + EXPECT_EQ(params[0], "Video"); + EXPECT_EQ(params[1], "C:\\test\\foo"); + params.clear(); + CUtil::SplitExecFunction("ActivateWindow(Video, \"C:\\test\\foo\\\")", function, params); + EXPECT_EQ(function, "ActivateWindow"); + EXPECT_EQ(params.size(), 2); + EXPECT_EQ(params[0], "Video"); + EXPECT_EQ(params[1], "C:\\test\\foo"); + params.clear(); + CUtil::SplitExecFunction("ActivateWindow(Video, \"C:\\\\test\\\\foo\\\\\")", function, params); + EXPECT_EQ(function, "ActivateWindow"); + EXPECT_EQ(params.size(), 2); + EXPECT_EQ(params[0], "Video"); + EXPECT_EQ(params[1], "C:\\test\\foo\\"); + params.clear(); + CUtil::SplitExecFunction("ActivateWindow(Video, \"C:\\\\\\\\test\\\\\\foo\\\\\")", function, params); + EXPECT_EQ(function, "ActivateWindow"); + EXPECT_EQ(params.size(), 2); + EXPECT_EQ(params[0], "Video"); + EXPECT_EQ(params[1], "C:\\\\test\\\\foo\\"); + params.clear(); + CUtil::SplitExecFunction("SetProperty(Foo,\"\")", function, params); + EXPECT_EQ(function, "SetProperty"); + EXPECT_EQ(params.size(), 2); + EXPECT_EQ(params[0], "Foo"); + EXPECT_EQ(params[1], ""); + params.clear(); + CUtil::SplitExecFunction("SetProperty(foo,ba(\"ba black )\",sheep))", function, params); + EXPECT_EQ(function, "SetProperty"); + EXPECT_EQ(params.size(), 2); + EXPECT_EQ(params[0], "foo"); + EXPECT_EQ(params[1], "ba(\"ba black )\",sheep)"); +} |