Skip to content

Commit

Permalink
Add Utilities, clean up testing (#604)
Browse files Browse the repository at this point in the history
* Update CMakeLists.txt with version 3.6.0 (patch 1)

* Update cmake/CMakeLists.txt library version

* Updated the Installation instructions based on user feedback.  Also fixed a problem with the isis3VarInit.py script.

* Updates made in accordance with requests made on this PR by other developers.

* Fix tgo cassis unit test correctly

* Fix tgo cassis unit test correctly (#544)

* Fixed two bug with AutoReg. One occurs with one dimensional pattern cubes and the other causes the revious registration sample/line to be returned on sub-pixel registration failure.

* Fix tgo cassis camera truth again (#554)

* Update docsys Makefile to support wwwdoc (#559)

The documentation is installed under `docs`, not `doc`, so this file has been updated.
`setisis isis3.6.0` and running `make wwwdoc` in `$ISISROOT/../isis/src/docsys` will properly sync the documentation to our web server.

* Update isis3VarInit.py

Unnecessary 'touch'ing, the '>' redirect will create the file if it doesn't exist.
Also, the first redirect should be the single '>'.  Otherwise, multiple runs of this program will continue appending to these files.  They still work, its just a lot of setting and unsetting for no good reason.

* Fixed isis3Startup scripts

* Removed unneeded LineEquation include

* Make this program more pythonic (#589)

* Updated documentation, user interaction, and made the file and directory
handling more 'pythonic'.

* Correcting for PR comments.

* Fixed broken links in the Installation instructions due to the hyperlinks to our GitHub wiki changing.

* Removed unused Parabola class

* Removed old license, added new unlicense (#594)

* Fixed issue with the License change (#599)

* Removed old license, added new unlicense

* Fixed cmake looking for license in the wrong place

* Added TestUtilities and used in Color tests

* Fixed an issue where app xmls were not being copied

* Tweaked IException test failure messages
  • Loading branch information
jessemapel authored and SgStapleton committed Nov 21, 2018
1 parent 1609f34 commit ec67013
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 30 deletions.
4 changes: 2 additions & 2 deletions isis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,13 @@ add_custom_target(clean_source COMMAND rm -rf "${CMAKE_BINARY_DIR}/*" "${CMAKE_I
# Set up a few top level files for installation.
EXECUTE_PROCESS(COMMAND cp -f ${CMAKE_SOURCE_DIR}/IsisPreferences ${CMAKE_BINARY_DIR})
EXECUTE_PROCESS(COMMAND cp -rf ${CMAKE_SOURCE_DIR}/scripts ${CMAKE_BINARY_DIR})
EXECUTE_PROCESS(COMMAND cp -f ${CMAKE_SOURCE_DIR}/license.txt ${CMAKE_BINARY_DIR})
EXECUTE_PROCESS(COMMAND cp -f ${CMAKE_SOURCE_DIR}/../LICENSE.txt ${CMAKE_BINARY_DIR})
EXECUTE_PROCESS(COMMAND cp -f ${CMAKE_SOURCE_DIR}/version ${CMAKE_BINARY_DIR})
EXECUTE_PROCESS(COMMAND cp -rf ${CMAKE_SOURCE_DIR}/make ${CMAKE_BINARY_DIR})

# Copy the files on make install as well
install(FILES ${CMAKE_SOURCE_DIR}/IsisPreferences DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${CMAKE_SOURCE_DIR}/license.txt DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${CMAKE_SOURCE_DIR}/../LICENSE.txt DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${CMAKE_SOURCE_DIR}/version DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/scripts DESTINATION ${CMAKE_INSTALL_PREFIX})

Expand Down
3 changes: 2 additions & 1 deletion isis/cmake/AddIsisModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ function(add_isis_app folder libDependencies)
get_filename_component(appName ${folder} NAME)
set(internalAppName ${appName}_app)

# Get the source and header files
# Get the main and xml files
file(GLOB sources "${folder}/main.cpp")
file(GLOB xmlFiles "${folder}/*.xml")

# All the XML files need to be copied to the install directory
# - They also need be put in the source folder for the app tests
Expand Down
58 changes: 31 additions & 27 deletions isis/tests/ColorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,60 @@

#include "Color.h"
#include "IException.h"
#include "TestUtilities.h"

#include <QDebug>
#include <QColor>


namespace Isis{


class QStringQColorPair: public ::testing::TestWithParam<std::pair<QString, QColor> > {
// Intentionally left empty
};


class InvalidColorString: public ::testing::TestWithParam<QString> {
// Intentionally left empty
};


TEST_P (QStringQColorPair, ValidColorToString) {
EXPECT_EQ(GetParam().first, Color::toRGBAString(GetParam().second));
EXPECT_PRED_FORMAT2(AssertQStringsEqual, GetParam().first, Color::toRGBAString(GetParam().second));
}


TEST (ColorTests, InvalidColorToString) {
QString message = "Can not convert an invalid color to an RGBA string. "
"There is no string representation of an invalid color";
try {
Color::toRGBAString(QColor());
FAIL() << "Expected an IException";
}
catch(IException &e) {
EXPECT_TRUE(e.toString().toLatin1().contains("Can not convert an invalid color to an RGBA "
"string. There is no string representation of "
"an invalid color")) << e.toString().toStdString();
EXPECT_PRED_FORMAT3(
AssertIException,
e,
message,
IException::Unknown);
}
catch(...) {
FAIL() << "Expected error message: \"Can not convert an invalid color to an RGBA string. "
"There is no string representation of an invalid color.\"";
FAIL() << "Expected error message: \"" << message.toStdString() << "\"";
}
}


TEST_P (QStringQColorPair, ValidStringToColor) {
EXPECT_EQ(GetParam().second, Color::fromRGBAString(GetParam().first));
}


TEST_P (InvalidColorString, InvalidStringToColor) {
EXPECT_EQ(QColor(QColor::Invalid), Color::fromRGBAString(GetParam()));
}


TEST_P (QStringQColorPair, ValidColorRGBAFormat) {
EXPECT_TRUE(Color::colorRGBAFormat().exactMatch(GetParam().first));
}
Expand All @@ -60,22 +64,22 @@ namespace Isis{
TEST_P (InvalidColorString, InvalidColorRGBAFormat) {
EXPECT_FALSE(Color::colorRGBAFormat().exactMatch(GetParam()));
}
INSTANTIATE_TEST_CASE_P (QStringQColorPairInstantiation,
QStringQColorPair,
::testing::Values(std::make_pair(QString("#000000ff"), QColor(0, 0, 0)),


INSTANTIATE_TEST_CASE_P (Color,
QStringQColorPair,
::testing::Values(std::make_pair(QString("#000000ff"), QColor(0, 0, 0)),
std::make_pair(QString("#00000000"), QColor(0, 0, 0, 0)),
std::make_pair(QString("#ff000000"), QColor(255, 0, 0, 0)),
std::make_pair(QString("#00ff0000"), QColor(0, 255, 0, 0)),
std::make_pair(QString("#0000ff00"), QColor(0, 0, 255, 0)),
std::make_pair(QString("#000000ff"), QColor(0, 0, 0, 255)),
std::make_pair(QString("#ffffffff"), QColor(255, 255, 255, 255)),
std::make_pair(QString("#0a141e28"), QColor(10, 20, 30, 40))));
INSTANTIATE_TEST_CASE_P (InvalidColorStringInstantiation,
InvalidColorString,


INSTANTIATE_TEST_CASE_P (Color,
InvalidColorString,
::testing::Values(QString("#rrggbbaa"),
QString(" 00112233"),
QString(""),
Expand Down
61 changes: 61 additions & 0 deletions isis/tests/TestUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef TestUtilities_h
#define TestUtilities_h

#include "gtest/gtest.h"

#include <string>

#include <QString>

#include "IException.h"

namespace Isis {

/**
* Custom IException assertion that checks the exception message contains
* a substring and that the error type is correct.
*/
::testing::AssertionResult AssertIException(
const char* e_expr,
const char* contents_expr,
const char* errorCode_expr,
IException &e,
QString contents,
int errorCode) {
if ( !e.toString().contains(contents) ) {
return ::testing::AssertionFailure() << "IException " << e_expr
<< "\'s error message (" << e.toString().toStdString()
<< ") does not contain " << contents_expr << " ("
<< contents.toStdString() << ").";
}

if( e.errorType()!=errorCode ) {
return ::testing::AssertionFailure() << "IException " << e_expr
<< "\'s error code (" << std::to_string(e.errorType())
<< ") does not equal " << errorCode_expr << " ("
<< std::to_string(errorCode) << ").";
}

return ::testing::AssertionSuccess();
}

/**
* Custom QString assertion that properly outputs them as string if they
* are different.
*/
::testing::AssertionResult AssertQStringsEqual(
const char* string1_expr,
const char* string2_expr,
QString string1,
QString string2) {
if (string1 != string2) {
return ::testing::AssertionFailure() << "QStrings " << string1_expr
<< " (" << string1.toStdString() << ") and " << string2_expr
<< " (" << string2.toStdString() << ") are not the same.";
}

return ::testing::AssertionSuccess();
}
}

#endif

0 comments on commit ec67013

Please sign in to comment.