本文整理汇总了C++中OrMatchExpression::add方法的典型用法代码示例。如果您正苦于以下问题:C++ OrMatchExpression::add方法的具体用法?C++ OrMatchExpression::add怎么用?C++ OrMatchExpression::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrMatchExpression
的用法示例。
在下文中一共展示了OrMatchExpression::add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BSON
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, 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 ) );
}
示例3: BSON
/*
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" );
unique_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() );
ASSERT( sub1->init( "a", baseOperand1[ "$lt" ] ).isOK() );
unique_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() );
ASSERT( sub2->init( "a", baseOperand2[ "$gt" ] ).isOK() );
unique_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);
unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression());
ASSERT(eq->init("a", baseOperand["$ne"]).isOK());
unique_ptr<NotMatchExpression> ne(new NotMatchExpression());
ASSERT(ne->init(eq.release()).isOK());
OrMatchExpression orOp;
orOp.add(ne.release());
ASSERT(orOp.matchesBSON(BSON("a" << 4), NULL));
ASSERT(orOp.matchesBSON(BSON("a" << BSON_ARRAY(4 << 6)), NULL));
ASSERT(!orOp.matchesBSON(BSON("a" << 5), NULL));
ASSERT(!orOp.matchesBSON(BSON("a" << BSON_ARRAY(4 << 5)), NULL));
}