Enabled PointerBindsToType in clang-format options.

This commit is contained in:
Aaron Jacobs
2014-09-15 10:15:29 +10:00
parent 30b07c0275
commit 11086dd6a7
14 changed files with 539 additions and 539 deletions

View File

@@ -81,14 +81,14 @@ TestResult::TestResult()
predicateStackTail_ = &rootPredicateNode_;
}
void TestResult::setTestName(const std::string &name) { name_ = name; }
void TestResult::setTestName(const std::string& name) { name_ = name; }
TestResult &
TestResult::addFailure(const char *file, unsigned int line, const char *expr) {
TestResult&
TestResult::addFailure(const char* file, unsigned int line, const char* expr) {
/// Walks the PredicateContext stack adding them to failures_ if not already
/// added.
unsigned int nestingLevel = 0;
PredicateContext *lastNode = rootPredicateNode_.next_;
PredicateContext* lastNode = rootPredicateNode_.next_;
for (; lastNode != 0; lastNode = lastNode->next_) {
if (lastNode->id_ > lastUsedPredicateId_) // new PredicateContext
{
@@ -108,9 +108,9 @@ TestResult::addFailure(const char *file, unsigned int line, const char *expr) {
return *this;
}
void TestResult::addFailureInfo(const char *file,
void TestResult::addFailureInfo(const char* file,
unsigned int line,
const char *expr,
const char* expr,
unsigned int nestingLevel) {
Failure failure;
failure.file_ = file;
@@ -122,13 +122,13 @@ void TestResult::addFailureInfo(const char *file,
failures_.push_back(failure);
}
TestResult &TestResult::popPredicateContext() {
PredicateContext *lastNode = &rootPredicateNode_;
TestResult& TestResult::popPredicateContext() {
PredicateContext* lastNode = &rootPredicateNode_;
while (lastNode->next_ != 0 && lastNode->next_->next_ != 0) {
lastNode = lastNode->next_;
}
// Set message target to popped failure
PredicateContext *tail = lastNode->next_;
PredicateContext* tail = lastNode->next_;
if (tail != 0 && tail->failure_ != 0) {
messageTarget_ = tail->failure_;
}
@@ -142,7 +142,7 @@ bool TestResult::failed() const { return !failures_.empty(); }
unsigned int TestResult::getAssertionNestingLevel() const {
unsigned int level = 0;
const PredicateContext *lastNode = &rootPredicateNode_;
const PredicateContext* lastNode = &rootPredicateNode_;
while (lastNode->next_ != 0) {
lastNode = lastNode->next_;
++level;
@@ -162,7 +162,7 @@ void TestResult::printFailure(bool printTestName) const {
// Print in reverse to display the callstack in the right order
Failures::const_iterator itEnd = failures_.end();
for (Failures::const_iterator it = failures_.begin(); it != itEnd; ++it) {
const Failure &failure = *it;
const Failure& failure = *it;
std::string indent(failure.nestingLevel_ * 2, ' ');
if (failure.file_) {
printf("%s%s(%d): ", indent.c_str(), failure.file_, failure.line_);
@@ -179,8 +179,8 @@ void TestResult::printFailure(bool printTestName) const {
}
}
std::string TestResult::indentText(const std::string &text,
const std::string &indent) {
std::string TestResult::indentText(const std::string& text,
const std::string& indent) {
std::string reindented;
std::string::size_type lastIndex = 0;
while (lastIndex < text.size()) {
@@ -195,22 +195,22 @@ std::string TestResult::indentText(const std::string &text,
return reindented;
}
TestResult &TestResult::addToLastFailure(const std::string &message) {
TestResult& TestResult::addToLastFailure(const std::string& message) {
if (messageTarget_ != 0) {
messageTarget_->message_ += message;
}
return *this;
}
TestResult &TestResult::operator<<(Json::Int64 value) {
TestResult& TestResult::operator<<(Json::Int64 value) {
return addToLastFailure(Json::valueToString(value));
}
TestResult &TestResult::operator<<(Json::UInt64 value) {
TestResult& TestResult::operator<<(Json::UInt64 value) {
return addToLastFailure(Json::valueToString(value));
}
TestResult &TestResult::operator<<(bool value) {
TestResult& TestResult::operator<<(bool value) {
return addToLastFailure(value ? "true" : "false");
}
@@ -221,7 +221,7 @@ TestCase::TestCase() : result_(0) {}
TestCase::~TestCase() {}
void TestCase::run(TestResult &result) {
void TestCase::run(TestResult& result) {
result_ = &result;
runTestCase();
}
@@ -231,7 +231,7 @@ void TestCase::run(TestResult &result) {
Runner::Runner() {}
Runner &Runner::add(TestCaseFactory factory) {
Runner& Runner::add(TestCaseFactory factory) {
tests_.push_back(factory);
return *this;
}
@@ -241,14 +241,14 @@ unsigned int Runner::testCount() const {
}
std::string Runner::testNameAt(unsigned int index) const {
TestCase *test = tests_[index]();
TestCase* test = tests_[index]();
std::string name = test->testName();
delete test;
return name;
}
void Runner::runTestAt(unsigned int index, TestResult &result) const {
TestCase *test = tests_[index]();
void Runner::runTestAt(unsigned int index, TestResult& result) const {
TestCase* test = tests_[index]();
result.setTestName(test->testName());
printf("Testing %s: ", test->testName());
fflush(stdout);
@@ -258,13 +258,13 @@ void Runner::runTestAt(unsigned int index, TestResult &result) const {
test->run(result);
#if JSON_USE_EXCEPTION
}
catch (const std::exception &e) {
catch (const std::exception& e) {
result.addFailure(__FILE__, __LINE__, "Unexpected exception caught:")
<< e.what();
}
#endif // if JSON_USE_EXCEPTION
delete test;
const char *status = result.failed() ? "FAILED" : "OK";
const char* status = result.failed() ? "FAILED" : "OK";
printf("%s\n", status);
fflush(stdout);
}
@@ -287,7 +287,7 @@ bool Runner::runAllTest(bool printSummary) const {
return true;
} else {
for (unsigned int index = 0; index < failures.size(); ++index) {
TestResult &result = failures[index];
TestResult& result = failures[index];
result.printFailure(count > 1);
}
@@ -303,8 +303,8 @@ bool Runner::runAllTest(bool printSummary) const {
}
}
bool Runner::testIndex(const std::string &testName,
unsigned int &indexOut) const {
bool Runner::testIndex(const std::string& testName,
unsigned int& indexOut) const {
unsigned int count = testCount();
for (unsigned int index = 0; index < count; ++index) {
if (testNameAt(index) == testName) {
@@ -322,7 +322,7 @@ void Runner::listTests() const {
}
}
int Runner::runCommandLine(int argc, const char *argv[]) const {
int Runner::runCommandLine(int argc, const char* argv[]) const {
typedef std::deque<std::string> TestNames;
Runner subrunner;
for (int index = 1; index < argc; ++index) {
@@ -363,7 +363,7 @@ int Runner::runCommandLine(int argc, const char *argv[]) const {
#if defined(_MSC_VER) && defined(_DEBUG)
// Hook MSVCRT assertions to prevent dialog from appearing
static int
msvcrtSilentReportHook(int reportType, char *message, int * /*returnValue*/) {
msvcrtSilentReportHook(int reportType, char* message, int* /*returnValue*/) {
// The default CRT handling of error and assertion is to display
// an error dialog to the user.
// Instead, when an error or an assertion occurs, we force the
@@ -409,7 +409,7 @@ void Runner::preventDialogOnCrash() {
#endif // if defined(_WIN32)
}
void Runner::printUsage(const char *appName) {
void Runner::printUsage(const char* appName) {
printf("Usage: %s [options]\n"
"\n"
"If --test is not specified, then all the test cases be run.\n"
@@ -426,12 +426,12 @@ void Runner::printUsage(const char *appName) {
// Assertion functions
// //////////////////////////////////////////////////////////////////
TestResult &checkStringEqual(TestResult &result,
const std::string &expected,
const std::string &actual,
const char *file,
TestResult& checkStringEqual(TestResult& result,
const std::string& expected,
const std::string& actual,
const char* file,
unsigned int line,
const char *expr) {
const char* expr) {
if (expected != actual) {
result.addFailure(file, line, expr);
result << "Expected: '" << expected << "'\n";

View File

@@ -30,7 +30,7 @@ namespace JsonTest {
class Failure {
public:
const char *file_;
const char* file_;
unsigned int line_;
std::string expr_;
std::string message_;
@@ -43,13 +43,13 @@ public:
struct PredicateContext {
typedef unsigned int Id;
Id id_;
const char *file_;
const char* file_;
unsigned int line_;
const char *expr_;
PredicateContext *next_;
const char* expr_;
PredicateContext* next_;
/// Related Failure, set when the PredicateContext is converted
/// into a Failure.
Failure *failure_;
Failure* failure_;
};
class TestResult {
@@ -63,25 +63,25 @@ public:
PredicateContext::Id predicateId_;
/// \internal Implementation detail for predicate macros
PredicateContext *predicateStackTail_;
PredicateContext* predicateStackTail_;
void setTestName(const std::string &name);
void setTestName(const std::string& name);
/// Adds an assertion failure.
TestResult &
addFailure(const char *file, unsigned int line, const char *expr = 0);
TestResult&
addFailure(const char* file, unsigned int line, const char* expr = 0);
/// Removes the last PredicateContext added to the predicate stack
/// chained list.
/// Next messages will be targed at the PredicateContext that was removed.
TestResult &popPredicateContext();
TestResult& popPredicateContext();
bool failed() const;
void printFailure(bool printTestName) const;
// Generic operator that will work with anything ostream can deal with.
template <typename T> TestResult &operator<<(const T &value) {
template <typename T> TestResult& operator<<(const T& value) {
std::ostringstream oss;
oss.precision(16);
oss.setf(std::ios_base::floatfield);
@@ -90,21 +90,21 @@ public:
}
// Specialized versions.
TestResult &operator<<(bool value);
TestResult& operator<<(bool value);
// std:ostream does not support 64bits integers on all STL implementation
TestResult &operator<<(Json::Int64 value);
TestResult &operator<<(Json::UInt64 value);
TestResult& operator<<(Json::Int64 value);
TestResult& operator<<(Json::UInt64 value);
private:
TestResult &addToLastFailure(const std::string &message);
TestResult& addToLastFailure(const std::string& message);
unsigned int getAssertionNestingLevel() const;
/// Adds a failure or a predicate context
void addFailureInfo(const char *file,
void addFailureInfo(const char* file,
unsigned int line,
const char *expr,
const char* expr,
unsigned int nestingLevel);
static std::string indentText(const std::string &text,
const std::string &indent);
static std::string indentText(const std::string& text,
const std::string& indent);
typedef std::deque<Failure> Failures;
Failures failures_;
@@ -112,7 +112,7 @@ private:
PredicateContext rootPredicateNode_;
PredicateContext::Id lastUsedPredicateId_;
/// Failure which is the target of the messages added using operator <<
Failure *messageTarget_;
Failure* messageTarget_;
};
class TestCase {
@@ -121,32 +121,32 @@ public:
virtual ~TestCase();
void run(TestResult &result);
void run(TestResult& result);
virtual const char *testName() const = 0;
virtual const char* testName() const = 0;
protected:
TestResult *result_;
TestResult* result_;
private:
virtual void runTestCase() = 0;
};
/// Function pointer type for TestCase factory
typedef TestCase *(*TestCaseFactory)();
typedef TestCase* (*TestCaseFactory)();
class Runner {
public:
Runner();
/// Adds a test to the suite
Runner &add(TestCaseFactory factory);
Runner& add(TestCaseFactory factory);
/// Runs test as specified on the command-line
/// If no command-line arguments are provided, run all tests.
/// If --list-tests is provided, then print the list of all test cases
/// If --test <testname> is provided, then run test testname.
int runCommandLine(int argc, const char *argv[]) const;
int runCommandLine(int argc, const char* argv[]) const;
/// Runs all the test cases
bool runAllTest(bool printSummary) const;
@@ -158,17 +158,17 @@ public:
std::string testNameAt(unsigned int index) const;
/// Runs the test case at the specified index using the specified TestResult
void runTestAt(unsigned int index, TestResult &result) const;
void runTestAt(unsigned int index, TestResult& result) const;
static void printUsage(const char *appName);
static void printUsage(const char* appName);
private: // prevents copy construction and assignment
Runner(const Runner &other);
Runner &operator=(const Runner &other);
Runner(const Runner& other);
Runner& operator=(const Runner& other);
private:
void listTests() const;
bool testIndex(const std::string &testName, unsigned int &index) const;
bool testIndex(const std::string& testName, unsigned int& index) const;
static void preventDialogOnCrash();
private:
@@ -177,12 +177,12 @@ private:
};
template <typename T, typename U>
TestResult &checkEqual(TestResult &result,
const T &expected,
const U &actual,
const char *file,
TestResult& checkEqual(TestResult& result,
const T& expected,
const U& actual,
const char* file,
unsigned int line,
const char *expr) {
const char* expr) {
if (static_cast<U>(expected) != actual) {
result.addFailure(file, line, expr);
result << "Expected: " << static_cast<U>(expected) << "\n";
@@ -191,12 +191,12 @@ TestResult &checkEqual(TestResult &result,
return result;
}
TestResult &checkStringEqual(TestResult &result,
const std::string &expected,
const std::string &actual,
const char *file,
TestResult& checkStringEqual(TestResult& result,
const std::string& expected,
const std::string& actual,
const char* file,
unsigned int line,
const char *expr);
const char* expr);
} // namespace JsonTest
@@ -260,12 +260,12 @@ TestResult &checkStringEqual(TestResult &result,
#define JSONTEST_FIXTURE(FixtureType, name) \
class Test##FixtureType##name : public FixtureType { \
public: \
static JsonTest::TestCase *factory() { \
static JsonTest::TestCase* factory() { \
return new Test##FixtureType##name(); \
} \
\
public: /* overidden from TestCase */ \
virtual const char *testName() const { return #FixtureType "/" #name; } \
virtual const char* testName() const { return #FixtureType "/" #name; } \
virtual void runTestCase(); \
}; \
\

View File

@@ -85,23 +85,23 @@ struct ValueTest : JsonTest::TestCase {
bool isNumeric_;
};
void checkConstMemberCount(const Json::Value &value,
void checkConstMemberCount(const Json::Value& value,
unsigned int expectedCount);
void checkMemberCount(Json::Value &value, unsigned int expectedCount);
void checkMemberCount(Json::Value& value, unsigned int expectedCount);
void checkIs(const Json::Value &value, const IsCheck &check);
void checkIs(const Json::Value& value, const IsCheck& check);
void checkIsLess(const Json::Value &x, const Json::Value &y);
void checkIsLess(const Json::Value& x, const Json::Value& y);
void checkIsEqual(const Json::Value &x, const Json::Value &y);
void checkIsEqual(const Json::Value& x, const Json::Value& y);
/// Normalize the representation of floating-point number by stripped leading
/// 0 in exponent.
static std::string normalizeFloatingPointStr(const std::string &s);
static std::string normalizeFloatingPointStr(const std::string& s);
};
std::string ValueTest::normalizeFloatingPointStr(const std::string &s) {
std::string ValueTest::normalizeFloatingPointStr(const std::string& s) {
std::string::size_type index = s.find_last_of("eE");
if (index != std::string::npos) {
std::string::size_type hasSign =
@@ -187,7 +187,7 @@ JSONTEST_FIXTURE(ValueTest, objects) {
JSONTEST_ASSERT(!emptyObject_.isConvertibleTo(Json::stringValue));
// Access through const reference
const Json::Value &constObject = object1_;
const Json::Value& constObject = object1_;
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constObject["id"]);
JSONTEST_ASSERT_EQUAL(Json::Value(), constObject["unknown id"]);
@@ -229,7 +229,7 @@ JSONTEST_FIXTURE(ValueTest, arrays) {
JSONTEST_ASSERT(!emptyArray_.isConvertibleTo(Json::stringValue));
// Access through const reference
const Json::Value &constArray = array1_;
const Json::Value& constArray = array1_;
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constArray[index0]);
JSONTEST_ASSERT_EQUAL(Json::Value(1234), constArray[0]);
@@ -1239,7 +1239,7 @@ JSONTEST_FIXTURE(ValueTest, nonIntegers) {
normalizeFloatingPointStr(val.asString()));
}
void ValueTest::checkConstMemberCount(const Json::Value &value,
void ValueTest::checkConstMemberCount(const Json::Value& value,
unsigned int expectedCount) {
unsigned int count = 0;
Json::Value::const_iterator itEnd = value.end();
@@ -1249,7 +1249,7 @@ void ValueTest::checkConstMemberCount(const Json::Value &value,
JSONTEST_ASSERT_EQUAL(expectedCount, count) << "Json::Value::const_iterator";
}
void ValueTest::checkMemberCount(Json::Value &value,
void ValueTest::checkMemberCount(Json::Value& value,
unsigned int expectedCount) {
JSONTEST_ASSERT_EQUAL(expectedCount, value.size());
@@ -1269,7 +1269,7 @@ ValueTest::IsCheck::IsCheck()
isUInt64_(false), isIntegral_(false), isDouble_(false),
isNumeric_(false) {}
void ValueTest::checkIs(const Json::Value &value, const IsCheck &check) {
void ValueTest::checkIs(const Json::Value& value, const IsCheck& check) {
JSONTEST_ASSERT_EQUAL(check.isObject_, value.isObject());
JSONTEST_ASSERT_EQUAL(check.isArray_, value.isArray());
JSONTEST_ASSERT_EQUAL(check.isBool_, value.isBool());
@@ -1384,7 +1384,7 @@ JSONTEST_FIXTURE(ValueTest, compareType) {
Json::Value(Json::objectValue)));
}
void ValueTest::checkIsLess(const Json::Value &x, const Json::Value &y) {
void ValueTest::checkIsLess(const Json::Value& x, const Json::Value& y) {
JSONTEST_ASSERT(x < y);
JSONTEST_ASSERT(y > x);
JSONTEST_ASSERT(x <= y);
@@ -1399,7 +1399,7 @@ void ValueTest::checkIsLess(const Json::Value &x, const Json::Value &y) {
JSONTEST_ASSERT(y.compare(x) >= 0);
}
void ValueTest::checkIsEqual(const Json::Value &x, const Json::Value &y) {
void ValueTest::checkIsEqual(const Json::Value& x, const Json::Value& y) {
JSONTEST_ASSERT(x == y);
JSONTEST_ASSERT(y == x);
JSONTEST_ASSERT(x <= y);
@@ -1601,7 +1601,7 @@ JSONTEST_FIXTURE(ReaderTest, parseWithDetailError) {
JSONTEST_ASSERT(errors.at(0).message == "Bad escape sequence in string");
}
int main(int argc, const char *argv[]) {
int main(int argc, const char* argv[]) {
JsonTest::Runner runner;
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, checkNormalizeFloatingPointStr);
JSONTEST_REGISTER_FIXTURE(runner, ValueTest, memberCount);