Skip to content

Commit

Permalink
Issue: renamed the INFORMATION level to MESSAGE (closes #674).
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny authored Jul 29, 2020
2 parents dc04f93 + 08d76b0 commit b63e727
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/api/libcellml/issue.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class LIBCELLML_EXPORT Issue
ERROR,
WARNING,
HINT,
INFORMATION
MESSAGE
};

/**
Expand Down
23 changes: 12 additions & 11 deletions src/api/libcellml/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,27 @@ class LIBCELLML_EXPORT Logger
IssuePtr hint(size_t index) const;

/**
* @brief Get the number of issues with level of INFORMATION.
* @brief Get the number of issues with level of MESSAGE.
*
* Return the number of pieces of information currently stored in the logger.
* Return the number of messages currently stored in the logger.
*
* @return The number of pieces of information.
* @return The number of messages.
*/
size_t informationCount() const;
size_t messageCount() const;

/**
* @brief Get issue of level INFORMATION at the specified @p index.
* @brief Get issue of level MESSAGE at the specified @p index.
*
* Returns a piece of information at the @p index. If the @p index
* is not valid a @c nullptr is returned, the valid range for the @p index
* is [0, \#informations).
* Returns a message at the @p index. If the @p index is not valid a
* @c nullptr is returned, the valid range for the @p index is
* [0, \#messages).
*
* @param index The index of the piece of information to return.
* @param index The index of the message to return.
*
* @return A reference to the piece of information at the given index on success, @c nullptr otherwise.
* @return A reference to the message at the given index on success,
* @c nullptr otherwise.
*/
IssuePtr information(size_t index) const;
IssuePtr message(size_t index) const;

protected:
Logger(); /**< Constructor */
Expand Down
8 changes: 4 additions & 4 deletions src/bindings/interface/logger.i
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
%feature("docstring") libcellml::Logger::hintCount
"Returns the number of issues of level HINT currently stored in the logger.";

%feature("docstring") libcellml::Logger::information
"Returns the issue of level INFORMATION at the specified ``index``.";
%feature("docstring") libcellml::Logger::message
"Returns the issue of level MESSAGE at the specified ``index``.";

%feature("docstring") libcellml::Logger::informationCount
"Returns the number of issues of level INFORMATION currently stored in the logger.";
%feature("docstring") libcellml::Logger::messageCount
"Returns the number of issues of level MESSAGE currently stored in the logger.";

#if defined(SWIGPYTHON)
// Treat negative size_t as invalid index (instead of unknown method)
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/interface/types.i
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Only meant to be included, shouldn't be passed to cmake as a module!
if (!SWIG_IsOK(ecode)) {
%argument_fail(ecode, "$type", $symname, $argnum);
} else {
if (val < %static_cast($type::ERROR, int) || %static_cast($type::INFORMATION, int) < val) {
if (val < %static_cast($type::ERROR, int) || %static_cast($type::MESSAGE, int) < val) {
%argument_fail(ecode, "$type is not a valid value for the enumeration.", $symname, $argnum);
}
$1 = %static_cast(val,$basetype);
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Object:
'ERROR',
'WARNING',
'HINT',
'INFORMATION',
'MESSAGE',
])
convert(Issue, 'ReferenceRule', [
'UNDEFINED',
Expand Down
18 changes: 9 additions & 9 deletions src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct Logger::LoggerImpl
std::vector<size_t> mErrors;
std::vector<size_t> mWarnings;
std::vector<size_t> mHints;
std::vector<size_t> mInformations;
std::vector<size_t> mMessages;
std::vector<IssuePtr> mIssues;
};

Expand Down Expand Up @@ -92,16 +92,16 @@ IssuePtr Logger::hint(size_t index) const
return issue;
}

size_t Logger::informationCount() const
size_t Logger::messageCount() const
{
return mPimpl->mInformations.size();
return mPimpl->mMessages.size();
}

IssuePtr Logger::information(size_t index) const
IssuePtr Logger::message(size_t index) const
{
IssuePtr issue = nullptr;
if (index < mPimpl->mInformations.size()) {
issue = mPimpl->mIssues.at(mPimpl->mInformations.at(index));
if (index < mPimpl->mMessages.size()) {
issue = mPimpl->mIssues.at(mPimpl->mMessages.at(index));
}
return issue;
}
Expand All @@ -112,7 +112,7 @@ void Logger::removeAllIssues()
mPimpl->mErrors.clear();
mPimpl->mWarnings.clear();
mPimpl->mHints.clear();
mPimpl->mInformations.clear();
mPimpl->mMessages.clear();
}

void Logger::addIssue(const IssuePtr &issue)
Expand All @@ -131,8 +131,8 @@ void Logger::addIssue(const IssuePtr &issue)
case libcellml::Issue::Level::HINT:
mPimpl->mHints.push_back(index);
break;
case libcellml::Issue::Level::INFORMATION:
mPimpl->mInformations.push_back(index);
case libcellml::Issue::Level::MESSAGE:
mPimpl->mMessages.push_back(index);
break;
}
}
Expand Down
44 changes: 22 additions & 22 deletions tests/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(Logger, addError)
EXPECT_EQ(size_t(1), logger->errorCount());
EXPECT_EQ(size_t(0), logger->warningCount());
EXPECT_EQ(size_t(0), logger->hintCount());
EXPECT_EQ(size_t(0), logger->informationCount());
EXPECT_EQ(size_t(0), logger->messageCount());
EXPECT_EQ(logger->error(0), issue);
EXPECT_EQ(logger->issue(0), issue);
}
Expand All @@ -45,7 +45,7 @@ TEST(Logger, addWarning)
EXPECT_EQ(size_t(0), logger->errorCount());
EXPECT_EQ(size_t(1), logger->warningCount());
EXPECT_EQ(size_t(0), logger->hintCount());
EXPECT_EQ(size_t(0), logger->informationCount());
EXPECT_EQ(size_t(0), logger->messageCount());
EXPECT_EQ(logger->warning(0), issue);
EXPECT_EQ(logger->issue(0), issue);
}
Expand All @@ -61,24 +61,24 @@ TEST(Logger, addHint)
EXPECT_EQ(size_t(0), logger->errorCount());
EXPECT_EQ(size_t(0), logger->warningCount());
EXPECT_EQ(size_t(1), logger->hintCount());
EXPECT_EQ(size_t(0), logger->informationCount());
EXPECT_EQ(size_t(0), logger->messageCount());
EXPECT_EQ(logger->hint(0), issue);
EXPECT_EQ(logger->issue(0), issue);
}

TEST(Logger, addInformation)
TEST(Logger, addMessage)
{
auto issue = libcellml::Issue::create();
issue->setLevel(libcellml::Issue::Level::INFORMATION);
issue->setLevel(libcellml::Issue::Level::MESSAGE);
auto logger = libcellml::Validator::create();

logger->addIssue(issue);
EXPECT_EQ(size_t(1), logger->issueCount());
EXPECT_EQ(size_t(0), logger->errorCount());
EXPECT_EQ(size_t(0), logger->warningCount());
EXPECT_EQ(size_t(0), logger->hintCount());
EXPECT_EQ(size_t(1), logger->informationCount());
EXPECT_EQ(logger->information(0), issue);
EXPECT_EQ(size_t(1), logger->messageCount());
EXPECT_EQ(logger->message(0), issue);
EXPECT_EQ(logger->issue(0), issue);
}

Expand All @@ -93,8 +93,8 @@ TEST(Logger, getIssueByLevelFunction)
auto hint1 = libcellml::Issue::create();
hint1->setLevel(libcellml::Issue::Level::HINT);

auto information1 = libcellml::Issue::create();
information1->setLevel(libcellml::Issue::Level::INFORMATION);
auto message1 = libcellml::Issue::create();
message1->setLevel(libcellml::Issue::Level::MESSAGE);

auto error2 = libcellml::Issue::create();
error2->setLevel(libcellml::Issue::Level::ERROR);
Expand All @@ -105,15 +105,15 @@ TEST(Logger, getIssueByLevelFunction)
auto hint2 = libcellml::Issue::create();
hint2->setLevel(libcellml::Issue::Level::HINT);

auto information2 = libcellml::Issue::create();
information2->setLevel(libcellml::Issue::Level::INFORMATION);
auto message2 = libcellml::Issue::create();
message2->setLevel(libcellml::Issue::Level::MESSAGE);

auto validator = libcellml::Validator::create();
validator->addIssue(error1);
validator->addIssue(warning1);
validator->addIssue(hint1);
validator->addIssue(information1);
validator->addIssue(information2);
validator->addIssue(message1);
validator->addIssue(message2);
validator->addIssue(hint2);
validator->addIssue(warning2);
validator->addIssue(error2);
Expand All @@ -124,8 +124,8 @@ TEST(Logger, getIssueByLevelFunction)
EXPECT_EQ(error1, validator->issue(0));
EXPECT_EQ(warning1, validator->issue(1));
EXPECT_EQ(hint1, validator->issue(2));
EXPECT_EQ(information1, validator->issue(3));
EXPECT_EQ(information2, validator->issue(4));
EXPECT_EQ(message1, validator->issue(3));
EXPECT_EQ(message2, validator->issue(4));
EXPECT_EQ(hint2, validator->issue(5));
EXPECT_EQ(warning2, validator->issue(6));
EXPECT_EQ(error2, validator->issue(7));
Expand All @@ -142,32 +142,32 @@ TEST(Logger, getIssueByLevelFunction)
EXPECT_EQ(hint1, validator->hint(0));
EXPECT_EQ(hint2, validator->hint(1));

// Expect to call information(0-1) and get the INFORMATION level issues only
EXPECT_EQ(information1, validator->information(0));
EXPECT_EQ(information2, validator->information(1));
// Expect to call message(0-1) and get the MESSAGE level issues only
EXPECT_EQ(message1, validator->message(0));
EXPECT_EQ(message2, validator->message(1));
}

TEST(Logger, outOfRangeIndex)
{
auto error1 = libcellml::Issue::create();
auto warning1 = libcellml::Issue::create();
auto hint1 = libcellml::Issue::create();
auto information1 = libcellml::Issue::create();
auto message1 = libcellml::Issue::create();

error1->setLevel(libcellml::Issue::Level::ERROR);
warning1->setLevel(libcellml::Issue::Level::WARNING);
hint1->setLevel(libcellml::Issue::Level::HINT);
information1->setLevel(libcellml::Issue::Level::INFORMATION);
message1->setLevel(libcellml::Issue::Level::MESSAGE);

auto validator = libcellml::Validator::create();
validator->addIssue(error1);
validator->addIssue(warning1);
validator->addIssue(hint1);
validator->addIssue(information1);
validator->addIssue(message1);

EXPECT_EQ(nullptr, validator->issue(10));
EXPECT_EQ(nullptr, validator->error(10));
EXPECT_EQ(nullptr, validator->warning(10));
EXPECT_EQ(nullptr, validator->hint(10));
EXPECT_EQ(nullptr, validator->information(10));
EXPECT_EQ(nullptr, validator->message(10));
}

0 comments on commit b63e727

Please sign in to comment.