Пример #1
0
    /*
    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 ) );
    }
Пример #2
0
    TEST( OrOp, 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() );

        OrMatchExpression orOp;
        orOp.add( sub1.release() );
        orOp.add( sub2.release() );

        MatchDetails details;
        details.requestElemMatchKey();
        ASSERT( !orOp.matches( BSONObj(), &details ) );
        ASSERT( !details.hasElemMatchKey() );
        ASSERT( !orOp.matches( BSON( "a" << BSON_ARRAY( 10 ) << "b" << BSON_ARRAY( 10 ) ),
                               &details ) );
        ASSERT( !details.hasElemMatchKey() );
        ASSERT( orOp.matches( 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
0
    TEST( OrOp, 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() );

        OrMatchExpression orOp;
        orOp.add( sub1.release() );
        orOp.add( sub2.release() );
        orOp.add( sub3.release() );

        ASSERT( orOp.matches( BSON( "a" << -1 ), NULL ) );
        ASSERT( orOp.matches( BSON( "a" << 11 ), NULL ) );
        ASSERT( !orOp.matches( BSON( "a" << 5 ), NULL ) );
        ASSERT( orOp.matches( BSON( "b" << 100 ), NULL ) );
        ASSERT( !orOp.matches( BSON( "b" << 101 ), NULL ) );
        ASSERT( !orOp.matches( BSONObj(), NULL ) );
        ASSERT( orOp.matches( BSON( "a" << 11 << "b" << 100 ), NULL ) );
    }
Пример #4
0
 TEST( OrOp, NoClauses ) {
     OrMatchExpression orOp;
     ASSERT( !orOp.matches( BSONObj(), NULL ) );
 }