本文整理汇总了C++中OrMatchExpression类的典型用法代码示例。如果您正苦于以下问题:C++ OrMatchExpression类的具体用法?C++ OrMatchExpression怎么用?C++ OrMatchExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OrMatchExpression类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(OrOp, MatchesThreeClauses) {
BSONObj baseOperand1 = BSON("$gt" << 10);
BSONObj baseOperand2 = BSON("$lt" << 0);
BSONObj baseOperand3 = BSON("b" << 100);
const CollatorInterface* collator = nullptr;
unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression(collator));
ASSERT(sub1->init("a", baseOperand1["$gt"]).isOK());
unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression(collator));
ASSERT(sub2->init("a", baseOperand2["$lt"]).isOK());
unique_ptr<ComparisonMatchExpression> sub3(new EqualityMatchExpression(collator));
ASSERT(sub3->init("b", baseOperand3["b"]).isOK());
OrMatchExpression orOp;
orOp.add(sub1.release());
orOp.add(sub2.release());
orOp.add(sub3.release());
ASSERT(orOp.matchesBSON(BSON("a" << -1), NULL));
ASSERT(orOp.matchesBSON(BSON("a" << 11), NULL));
ASSERT(!orOp.matchesBSON(BSON("a" << 5), NULL));
ASSERT(orOp.matchesBSON(BSON("b" << 100), NULL));
ASSERT(!orOp.matchesBSON(BSON("b" << 101), NULL));
ASSERT(!orOp.matchesBSON(BSONObj(), NULL));
ASSERT(orOp.matchesBSON(BSON("a" << 11 << "b" << 100), NULL));
}
示例2: TEST
TEST(OrOp, ElemMatchKey) {
BSONObj baseOperand1 = BSON("a" << 1);
BSONObj baseOperand2 = BSON("b" << 2);
unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression());
ASSERT(sub1->init("a", baseOperand1["a"]).isOK());
unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression());
ASSERT(sub2->init("b", baseOperand2["b"]).isOK());
OrMatchExpression orOp;
orOp.add(sub1.release());
orOp.add(sub2.release());
MatchDetails details;
details.requestElemMatchKey();
ASSERT(!orOp.matchesBSON(BSONObj(), &details));
ASSERT(!details.hasElemMatchKey());
ASSERT(!orOp.matchesBSON(BSON("a" << BSON_ARRAY(10) << "b" << BSON_ARRAY(10)), &details));
ASSERT(!details.hasElemMatchKey());
ASSERT(orOp.matchesBSON(BSON("a" << BSON_ARRAY(1) << "b" << BSON_ARRAY(1 << 2)), &details));
// The elem match key feature is not implemented for $or.
ASSERT(!details.hasElemMatchKey());
}
示例3: TEST
/*
TEST( OrOp, MatchesElementThreeClauses ) {
BSONObj baseOperand1 = BSON( "$lt" << 0 );
BSONObj baseOperand2 = BSON( "$gt" << 10 );
BSONObj baseOperand3 = BSON( "a" << 5 );
BSONObj match1 = BSON( "a" << -1 );
BSONObj match2 = BSON( "a" << 11 );
BSONObj match3 = BSON( "a" << 5 );
BSONObj notMatch = BSON( "a" << "6" );
auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() );
ASSERT( sub1->init( "a", baseOperand1[ "$lt" ] ).isOK() );
auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() );
ASSERT( sub2->init( "a", baseOperand2[ "$gt" ] ).isOK() );
auto_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() );
ASSERT( sub3->init( "a", baseOperand3[ "a" ] ).isOK() );
OwnedPointerVector<MatchMatchExpression> subMatchExpressions;
subMatchExpressions.mutableVector().push_back( sub1.release() );
subMatchExpressions.mutableVector().push_back( sub2.release() );
subMatchExpressions.mutableVector().push_back( sub3.release() );
OrOp orOp;
ASSERT( orOp.init( &subMatchExpressions ).isOK() );
ASSERT( orOp.matchesSingleElement( match1[ "a" ] ) );
ASSERT( orOp.matchesSingleElement( match2[ "a" ] ) );
ASSERT( orOp.matchesSingleElement( match3[ "a" ] ) );
ASSERT( !orOp.matchesSingleElement( notMatch[ "a" ] ) );
}
*/
TEST( OrOp, MatchesSingleClause ) {
BSONObj baseOperand = BSON( "$ne" << 5 );
auto_ptr<ComparisonMatchExpression> ne( new ComparisonMatchExpression() );
ASSERT( ne->init( "a", ComparisonMatchExpression::NE, baseOperand[ "$ne" ] ).isOK() );
OrMatchExpression orOp;
orOp.add( ne.release() );
ASSERT( orOp.matches( BSON( "a" << 4 ), NULL ) );
ASSERT( orOp.matches( BSON( "a" << BSON_ARRAY( 4 << 6 ) ), NULL ) );
ASSERT( !orOp.matches( BSON( "a" << 5 ), NULL ) );
ASSERT( !orOp.matches( BSON( "a" << BSON_ARRAY( 4 << 5 ) ), NULL ) );
}