Skip to content

Commit

Permalink
move CUtil tests to gtest unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
notspiff committed Apr 10, 2015
1 parent ecddae2 commit df8f577
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 70 deletions.
64 changes: 0 additions & 64 deletions xbmc/Util.cpp
Expand Up @@ -327,42 +327,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)
{
}
Expand Down Expand Up @@ -980,34 +944,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> &parameters)
{
std::string paramString;
Expand Down
6 changes: 0 additions & 6 deletions xbmc/Util.h
Expand Up @@ -161,12 +161,6 @@ class CUtil
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
Expand Down
1 change: 1 addition & 0 deletions xbmc/test/CMakeLists.txt
Expand Up @@ -2,6 +2,7 @@ set(SOURCES TestBasicEnvironment.cpp
TestFileItem.cpp
TestTextureUtils.cpp
TestURL.cpp
TestUtil.cpp
TestUtils.cpp)

core_add_test_library(xbmc_test)
100 changes: 100 additions & 0 deletions 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)");
}

0 comments on commit df8f577

Please sign in to comment.