void isStandardType() const { std::vector<std::string> standard_types; standard_types.push_back("bool"); standard_types.push_back("char"); standard_types.push_back("short"); standard_types.push_back("int"); standard_types.push_back("long"); standard_types.push_back("float"); standard_types.push_back("double"); standard_types.push_back("size_t"); std::vector<std::string>::const_iterator test_op, test_ops_end = standard_types.end(); for (test_op = standard_types.begin(); test_op != test_ops_end; ++test_op) { Token tok(nullptr); tok.str(*test_op); ASSERT_EQUALS_MSG(true, tok.isStandardType(), "Failing standard type: " + *test_op); } // Negative test Token tok(nullptr); tok.str("string"); ASSERT_EQUALS(false, tok.isStandardType()); // Change back to standard type tok.str("int"); ASSERT_EQUALS(true, tok.isStandardType()); }
void isConstOp() const { std::vector<std::string> test_ops; append_vector(test_ops, arithmeticalOps); append_vector(test_ops, bitOps); append_vector(test_ops, comparisonOps); append_vector(test_ops, logicalOps); std::vector<std::string>::const_iterator test_op, test_ops_end = test_ops.end(); for (test_op = test_ops.begin(); test_op != test_ops_end; ++test_op) { Token tok(nullptr); tok.str(*test_op); ASSERT_EQUALS(true, tok.isConstOp()); } // Negative test against other operators std::vector<std::string> other_ops; append_vector(other_ops, extendedOps); append_vector(other_ops, assignmentOps); std::vector<std::string>::const_iterator other_op, other_ops_end = other_ops.end(); for (other_op = other_ops.begin(); other_op != other_ops_end; ++other_op) { Token tok(nullptr); tok.str(*other_op); ASSERT_EQUALS_MSG(false, tok.isConstOp(), "Failing normal operator: " + *other_op); } }
void runSamples() const { REDIRECT; std::map<std::string, std::size_t> files; const std::vector<std::string> masks; const PathMatch matcher(masks); #ifdef _WIN32 FileLister::recursiveAddFiles(files, "..\\samples", matcher); #else FileLister::recursiveAddFiles(files, "samples", matcher); #endif for (std::map<std::string, std::size_t>::const_iterator i = files.begin(); i != files.end(); ++i) { CLEAR_REDIRECT_ERROUT; char* path = new char[i->first.size() + 1]; strcpy(path, i->first.c_str()); const char* argv[] = { #ifdef _WIN32 ".\\..\\testrunner", #else "./testrunner", #endif "--severities=style,warning,performance,portability", "--inconclusive", "-rp", "-f", "-q", path }; std::string filename = i->first.substr(i->first.find_last_of("/\\")+1); if (filename == "good.cpp" || filename == "good.c") { CppCheckExecutor exec; exec.check(7, argv); ASSERT_EQUALS_MSG("", GET_REDIRECT_ERROUT, i->first); } else if (filename == "bad.cpp" || filename == "bad.c") { CppCheckExecutor exec; exec.check(7, argv); std::string expected_filename = Path::getPathFromFilename(i->first) + "out.txt"; std::ifstream ifs(expected_filename.c_str()); std::string expected((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()); std::string actual = GET_REDIRECT_ERROUT; // We need some uniformization to make this work on Unix and Windows std::replace(actual.begin(), actual.end(), '/', '\\'); // Uniformize slashes. while (actual.find("..\\") != std::string::npos) actual.erase(actual.find("..\\"), 3); // Remove '..\' ASSERT_EQUALS_MSG(expected, actual, i->first); } delete[] path; } }
void matchConstOp() { std::vector<std::string> test_ops; append_vector(test_ops, arithmeticalOps); append_vector(test_ops, bitOps); append_vector(test_ops, comparisonOps); append_vector(test_ops, logicalOps); std::vector<std::string>::const_iterator test_op, test_ops_end = test_ops.end(); for (test_op = test_ops.begin(); test_op != test_ops_end; ++test_op) { ASSERT_EQUALS(true, Match(*test_op, "%cop%")); } // Negative test against other operators std::vector<std::string> other_ops; append_vector(other_ops, extendedOps); append_vector(other_ops, assignmentOps); std::vector<std::string>::const_iterator other_op, other_ops_end = other_ops.end(); for (other_op = other_ops.begin(); other_op != other_ops_end; ++other_op) { ASSERT_EQUALS_MSG(false, Match(*other_op, "%cop%"), "Failing other operator: " + *other_op); } }