From a0bd22a15219c519655b72bf8242fd5da47eee9f Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Thu, 15 Dec 2016 16:01:44 +0100 Subject: [PATCH] Added test for trim_left() and trim_right() functions. --- test/MUtilitiesTest_VS2015.vcxproj | 21 +++++--- test/src/MUtilitiesTest.cpp | 103 +++++++++++++++++++++++++++++++++++-- 2 files changed, 112 insertions(+), 12 deletions(-) diff --git a/test/MUtilitiesTest_VS2015.vcxproj b/test/MUtilitiesTest_VS2015.vcxproj index 4d5529b..442e13b 100644 --- a/test/MUtilitiesTest_VS2015.vcxproj +++ b/test/MUtilitiesTest_VS2015.vcxproj @@ -17,6 +17,11 @@ + + + {55405fe1-149f-434c-9d72-4b64348d2a08} + + {B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89} Win32Proj @@ -82,7 +87,7 @@ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories) + $(SolutionDir)\include;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories) MultiThreadedDebugDLL NoExtensions @@ -102,7 +107,7 @@ true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories) + $(SolutionDir)\include;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories) MultiThreadedDLL NoExtensions false @@ -115,8 +120,8 @@ true true true - $(SolutionDir)\..\Prerequisites\GoogleTest\$(PlatformToolset)\Shared;%(AdditionalLibraryDirectories) - gtest.lib;%(AdditionalDependencies) + $(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Shared\lib;$(SolutionDir)\..\Prerequisites\GoogleTest\$(PlatformToolset)\Shared;%(AdditionalLibraryDirectories) + gtest.lib;notelemetry.obj;QtCore4.lib;QtGui4.lib;%(AdditionalDependencies) @@ -127,8 +132,8 @@ Full true true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - $(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;MUTILS_STATIC_LIB;QT_GUI_LIB;QT_CORE_LIB;QT_THREAD_SUPPORT;QT_NODLL;QT_NO_DEBUG;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(QTDIR)\include;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(SolutionDir)\..\Prerequisites\GoogleTest\include;%(AdditionalIncludeDirectories) MultiThreaded NoExtensions false @@ -141,8 +146,8 @@ true true true - $(SolutionDir)\..\Prerequisites\GoogleTest\lib\$(PlatformToolset)\Static;%(AdditionalLibraryDirectories) - gtest.lib;%(AdditionalDependencies) + $(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Static\lib;$(SolutionDir)\..\Prerequisites\GoogleTest\lib\$(PlatformToolset)\Static;%(AdditionalLibraryDirectories) + gtest.lib;notelemetry.obj;QtCore.lib;QtGui.lib;Ws2_32.lib;Winmm.lib;Imm32.lib;PowrProf.lib;Version.lib;Psapi.lib;Sensapi.lib;%(AdditionalDependencies) diff --git a/test/src/MUtilitiesTest.cpp b/test/src/MUtilitiesTest.cpp index db3c6f1..4fb0cd6 100644 --- a/test/src/MUtilitiesTest.cpp +++ b/test/src/MUtilitiesTest.cpp @@ -19,14 +19,109 @@ // http://www.gnu.org/licenses/lgpl-2.1.txt ////////////////////////////////////////////////////////////////////////////////// +//Google Test #include -TEST(FactorialTest, Zero) { - EXPECT_EQ(1, 1); +//MUtils +#include +#include + +//CRT +#include + +//Utilities +#define ASSERT_QSTR(X,Y) ASSERT_EQ((X).compare(QLatin1String(Y)), 0); + +//=========================================================================== +// Trim String +//=========================================================================== + +TEST(Global, TrimStringLeft) +{ + { + QString test(""); + MUtils::trim_left(test); + ASSERT_QSTR(test, ""); + } + { + QString test(" "); + MUtils::trim_left(test); + ASSERT_QSTR(test, ""); + } + { + QString test("! test !"); + MUtils::trim_left(test); + ASSERT_QSTR(test, "! test !"); + } + { + QString test(" test "); + MUtils::trim_left(test); + ASSERT_QSTR(test, "test "); + } + { + QString test(" ! test ! "); + MUtils::trim_left(test); + ASSERT_QSTR(test, "! test ! "); + } + { + const QString test(" test "); + ASSERT_QSTR(MUtils::trim_left(test), "test "); + } +} + +TEST(Global, TrimStringRight) +{ + { + QString test(""); + MUtils::trim_right(test); + ASSERT_QSTR(test, ""); + } + { + QString test(" "); + MUtils::trim_right(test); + ASSERT_QSTR(test, ""); + } + { + QString test("! test !"); + MUtils::trim_right(test); + ASSERT_QSTR(test, "! test !"); + } + { + QString test(" test "); + MUtils::trim_right(test); + ASSERT_QSTR(test, " test"); + } + { + QString test(" ! test ! "); + MUtils::trim_right(test); + ASSERT_QSTR(test, " ! test !"); + } + { + const QString test(" test "); + ASSERT_QSTR(MUtils::trim_right(test), " test"); + } } -//MAIN -int main(int argc, char **argv) { +//=========================================================================== +// Main function +//=========================================================================== + +int main(int argc, char **argv) +{ + printf("MuldeR's Utilities for Qt - Test Suite\n"); + printf("Copyright (C) 2004-2016 LoRd_MuldeR \n\n"); + + printf("Using MUtils v%u.%02u, built %s at %s, %s [%s]\n\n", + MUtils::Version::lib_version_major(), MUtils::Version::lib_version_minor(), + MUTILS_UTF8(MUtils::Version::lib_build_date().toString(Qt::ISODate)), MUTILS_UTF8(MUtils::Version::lib_build_time().toString(Qt::ISODate)), + MUtils::Version::compiler_version(), MUtils::Version::compiler_arch() + ); + + printf("This library is free software; you can redistribute it and/or\n"); + printf("modify it under the terms of the GNU Lesser General Public\n"); + printf("License as published by the Free Software Foundation; either\n"); + printf("version 2.1 of the License, or (at your option) any later version.\n\n"); + ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } -- 2.11.4.GIT