TEST( NorOp, MatchesSingleClause ) { BSONObj baseOperand = BSON( "$ne" << 5 ); auto_ptr<ComparisonMatchExpression> ne( new ComparisonMatchExpression() ); ASSERT( ne->init( "a", ComparisonMatchExpression::NE, baseOperand[ "$ne" ] ).isOK() ); NorMatchExpression norOp; norOp.add( ne.release() ); ASSERT( !norOp.matches( BSON( "a" << 4 ), NULL ) ); ASSERT( !norOp.matches( BSON( "a" << BSON_ARRAY( 4 << 6 ) ), NULL ) ); ASSERT( norOp.matches( BSON( "a" << 5 ), NULL ) ); ASSERT( norOp.matches( BSON( "a" << BSON_ARRAY( 4 << 5 ) ), NULL ) ); }
TEST( NorOp, MatchesThreeClauses ) { BSONObj baseOperand1 = BSON( "$gt" << 10 ); BSONObj baseOperand2 = BSON( "$lt" << 0 ); BSONObj baseOperand3 = BSON( "b" << 100 ); auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); ASSERT( sub1->init( "a", ComparisonMatchExpression::GT, baseOperand1[ "$gt" ] ).isOK() ); auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); ASSERT( sub2->init( "a", ComparisonMatchExpression::LT, baseOperand2[ "$lt" ] ).isOK() ); auto_ptr<ComparisonMatchExpression> sub3( new ComparisonMatchExpression() ); ASSERT( sub3->init( "b", ComparisonMatchExpression::EQ, baseOperand3[ "b" ] ).isOK() ); NorMatchExpression norOp; norOp.add( sub1.release() ); norOp.add( sub2.release() ); norOp.add( sub3.release() ); ASSERT( !norOp.matches( BSON( "a" << -1 ), NULL ) ); ASSERT( !norOp.matches( BSON( "a" << 11 ), NULL ) ); ASSERT( norOp.matches( BSON( "a" << 5 ), NULL ) ); ASSERT( !norOp.matches( BSON( "b" << 100 ), NULL ) ); ASSERT( norOp.matches( BSON( "b" << 101 ), NULL ) ); ASSERT( norOp.matches( BSONObj(), NULL ) ); ASSERT( !norOp.matches( BSON( "a" << 11 << "b" << 100 ), NULL ) ); }
TEST( NorOp, ElemMatchKey ) { BSONObj baseOperand1 = BSON( "a" << 1 ); BSONObj baseOperand2 = BSON( "b" << 2 ); auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() ); ASSERT( sub1->init( "a", ComparisonMatchExpression::EQ, baseOperand1[ "a" ] ).isOK() ); auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() ); ASSERT( sub2->init( "b", ComparisonMatchExpression::EQ, baseOperand2[ "b" ] ).isOK() ); NorMatchExpression norOp; norOp.add( sub1.release() ); norOp.add( sub2.release() ); MatchDetails details; details.requestElemMatchKey(); ASSERT( !norOp.matches( BSON( "a" << 1 ), &details ) ); ASSERT( !details.hasElemMatchKey() ); ASSERT( !norOp.matches( BSON( "a" << BSON_ARRAY( 1 ) << "b" << BSON_ARRAY( 10 ) ), &details ) ); ASSERT( !details.hasElemMatchKey() ); ASSERT( norOp.matches( BSON( "a" << BSON_ARRAY( 3 ) << "b" << BSON_ARRAY( 4 ) ), &details ) ); // The elem match key feature is not implemented for $nor. ASSERT( !details.hasElemMatchKey() ); }
TEST( NorOp, NoClauses ) { NorMatchExpression norOp; ASSERT( norOp.matches( BSONObj(), NULL ) ); }