The following issues were found
src/mongo/db/matcher/expression_serialization_test.cpp
1 issues
Line: 57
return bob.obj();
}
TEST(SerializeBasic, AndExpressionWithOneChildSerializesCorrectly) {
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{$and: [{x: 0}]}"),
expCtx,
ExtensionsCallbackNoop(),
MatchExpressionParser::kAllowAllSpecialFeatures);
Reported by Cppcheck.
src/mongo/db/matcher/expression_tree_test.cpp
1 issues
Line: 51
ASSERT(!notOp.matchesBSON(BSON("a" << 4), nullptr));
}
TEST(NotMatchExpression, MatchesArray) {
auto baseOperand = BSON("$lt" << 5);
auto lt = std::make_unique<LTMatchExpression>("a", baseOperand["$lt"]);
auto notOp = NotMatchExpression{lt.release()};
ASSERT(notOp.matchesBSON(BSON("a" << BSON_ARRAY(6)), nullptr));
ASSERT(!notOp.matchesBSON(BSON("a" << BSON_ARRAY(4)), nullptr));
Reported by Cppcheck.
src/mongo/db/matcher/expression_type_test.cpp
1 issues
Line: 46
ASSERT(!type.matchesSingleElement(notMatch["a"]));
}
TEST(ExpressionTypeTest, MatchesElementNullType) {
BSONObj match = BSON("a" << BSONNULL);
BSONObj notMatch = BSON("a"
<< "abc");
TypeMatchExpression type("", jstNULL);
ASSERT(type.matchesSingleElement(match["a"]));
Reported by Cppcheck.
src/mongo/db/matcher/expression_with_placeholder_test.cpp
1 issues
Line: 46
using unittest::assertGet;
TEST(ExpressionWithPlaceholderTest, ParseBasic) {
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
auto rawFilter = fromjson("{i: 0}");
auto parsedFilter = assertGet(MatchExpressionParser::parse(rawFilter, expCtx));
auto filter = assertGet(ExpressionWithPlaceholder::make(std::move(parsedFilter)));
ASSERT(filter->getPlaceholder());
Reported by Cppcheck.
src/mongo/db/matcher/matcher_type_set_test.cpp
1 issues
Line: 49
ASSERT_EQ(result.getValue().bsonTypes.size(), 0u);
}
TEST(MatcherTypeSetTest, ParseFromStringAliasesCanParseLongAlias) {
auto result = MatcherTypeSet::fromStringAliases({"long"}, findBSONTypeAlias);
ASSERT_OK(result.getStatus());
ASSERT_FALSE(result.getValue().allNumbers);
ASSERT_EQ(result.getValue().bsonTypes.size(), 1u);
ASSERT_TRUE(result.getValue().hasType(BSONType::NumberLong));
Reported by Cppcheck.
src/mongo/db/matcher/path_accepting_keyword_test.cpp
1 issues
Line: 128
MatchExpressionParser::parsePathAcceptingKeyword(BSON("$eq" << 1).firstElement()));
}
TEST(PathAcceptingKeyword, UnknownExpressionReturnsDefault) {
// Non-existent expression starting with '$'.
ASSERT_TRUE(PathAcceptingKeyword::GEO_INTERSECTS ==
MatchExpressionParser::parsePathAcceptingKeyword(
BSON("$foo" << 1).firstElement(), PathAcceptingKeyword::GEO_INTERSECTS));
// Existing expression but missing leading '$'.
Reported by Cppcheck.
src/mongo/db/matcher/path_test.cpp
1 issues
Line: 40
using std::string;
TEST(Path, Root1) {
ElementPath p{"a"};
BSONObj doc = BSON("x" << 4 << "a" << 5);
BSONElementIterator cursor(&p, doc);
Reported by Cppcheck.
src/mongo/db/matcher/rewrite_expr_test.cpp
1 issues
Line: 70
//
// Expressions that can be fully translated to MatchExpression.
//
TEST(RewriteExpr, EqWithOneFieldPathRewritesToMatch) {
BSONObj expr = fromjson("{$expr: {$eq: ['$x', 3]}}");
const BSONObj expectedMatch = fromjson("{x: {$_internalExprEq: 3}}");
testExprRewrite(expr, expectedMatch);
expr = fromjson("{$expr: {$eq: [3, '$x']}}");
Reported by Cppcheck.
src/mongo/db/matcher/schema/array_keywords_test.cpp
1 issues
Line: 48
ErrorCodes::FailedToParse);
}
TEST(JSONSchemaArrayKeywordTest, FailsToParseIfMinItemsIsNotANonNegativeInteger) {
auto schema = BSON("minItems" << -1);
ASSERT_EQ(JSONSchemaParser::parse(new ExpressionContextForTest(), schema).getStatus(),
ErrorCodes::FailedToParse);
schema = BSON("minItems" << 3.14);
Reported by Cppcheck.
src/mongo/db/matcher/schema/encrypt_keyword_test.cpp
1 issues
Line: 58
})"));
}
TEST(JSONSchemaParserEncryptTest, EncryptWithSingleBsonTypeTranslatesCorrectly) {
BSONObj schema = fromjson("{properties: {foo: {encrypt: {bsonType: \"string\"}}}}");
auto result = JSONSchemaParser::parse(new ExpressionContextForTest(), schema);
ASSERT_OK(result.getStatus());
auto optimizedResult = MatchExpression::optimize(std::move(result.getValue()));
ASSERT_SERIALIZES_TO(optimizedResult, fromjson(R"(
Reported by Cppcheck.