コード例 #1
0
ファイル: test_CSSOM.c プロジェクト: VasilyStepanov/libcssom
static void test_CSSOM_errors(void) {
  const char * css =
"p { color:green }\n"
"p { color:green; color } /* malformed declaration missing ':', value */\n"
"p { color:red; color; color:green } /* same with expected recovery */\n"
"p { color:green; color: } /* malformed declaration missing value */\n"
"p { color:red; color:; color:green } /* same with expected recovery */\n"
"p { color:green; color{;color:maroon} } /* unexpected tokens { } */\n"
"p { color:red; color{;color:maroon}; color:green } /* same with recovery */\n";

  CSSOM *cssom;
  CSSOM_CSSStyleSheet *styleSheet;
  const CSSOM_CSSRuleList *cssRules;
  CSSOM_CSSRule *cssRule;
  const CSSOM_CSSStyleDeclaration *style;
  size_t errors = 0;

  cssom = CSSOM_create();
  CSSOM_setUserData(cssom, &errors);
  CSSOM_setErrorHandler(cssom, errorHandler);

  styleSheet = CSSOM_parse(cssom, css, strlen(css));

  assert(errors == 6);

  cssRules = CSSOM_CSSStyleSheet_cssRules(styleSheet);
  assert(CSSOM_CSSRuleList_length(cssRules) == 7);

  cssRule = CSSOM_CSSRuleList_at(cssRules, 6);
  assert(cssRule != NULL);

  assert(CSSOM_CSSRule_type(cssRule) == CSSOM_CSSRule_STYLE_RULE);

  ASSERT_EQUAL_STRINGS("p",
    CSSOM_CSSStyleRule_selectorText((CSSOM_CSSStyleRule*)cssRule));

  style = CSSOM_CSSStyleRule_style((CSSOM_CSSStyleRule*)cssRule);

  assert(CSSOM_CSSStyleDeclaration_length(style) == 1);

  ASSERT_EQUAL_STRINGS("green",
    CSSOM_CSSStyleDeclaration_getPropertyValue(style, "color"));
  ASSERT_EQUAL_STRINGS("",
    CSSOM_CSSStyleDeclaration_getPropertyPriority(style, "color"));
  ASSERT_EQUAL_STRINGS("color : green;",
    CSSOM_CSSStyleDeclaration_cssText(style));

  CSSOM_CSSStyleSheet_release(styleSheet);
  CSSOM_release(cssom);
}
コード例 #2
0
ファイル: write_concern.c プロジェクト: cmjonze/rpm5_tarballs
static void test_write_concern_input( mongo *conn ) {
    mongo_write_concern wc[1], wcbad[1];
    bson b[1];

    mongo_cmd_drop_collection( conn, TEST_DB, TEST_COL, NULL );

    bson_init( b );
    bson_append_new_oid( b, "_id" );
    bson_finish( b );

    mongo_write_concern_init( wc );    
    mongo_write_concern_set_w( wc, 1 );

    /* Failure to finish write concern object. */
    ASSERT( mongo_insert( conn, TEST_NS, b, wc ) != MONGO_OK );
    ASSERT( conn->err == MONGO_WRITE_CONCERN_INVALID );
    ASSERT_EQUAL_STRINGS( conn->errstr,
        "Must call mongo_write_concern_finish() before using *write_concern." );

    mongo_write_concern_finish( wc );

    /* Use a bad write concern. */
    mongo_clear_errors( conn );
    mongo_write_concern_init( wcbad );    
    mongo_write_concern_set_w( wcbad, 2 );
    mongo_write_concern_finish( wcbad );
    mongo_set_write_concern( conn, wcbad );
    ASSERT( mongo_insert( conn, TEST_NS, b, NULL ) != MONGO_OK );
    ASSERT( conn->err == MONGO_WRITE_ERROR );
    ASSERT_EQUAL_STRINGS( conn->lasterrstr, "norepl" );

    /* Ensure that supplied write concern overrides default. */
    mongo_clear_errors( conn );
    ASSERT( mongo_insert( conn, TEST_NS, b, wc ) != MONGO_OK );
    ASSERT( conn->err == MONGO_WRITE_ERROR );
    ASSERT_EQUAL_STRINGS( conn->errstr, "See conn->lasterrstr for details." );
    ASSERT_EQUAL_STRINGS( conn->lasterrstr, "E11000 duplicate key error index" );
    ASSERT( conn->lasterrcode == 11000 );

    conn->write_concern = NULL;
    mongo_write_concern_destroy( wc );
    mongo_write_concern_destroy( wcbad );
    bson_destroy( b );
}
コード例 #3
0
ファイル: test_CSSOM.c プロジェクト: VasilyStepanov/libcssom
static void test_CSSOM_basics(void) {
  const char *css =
"p {\n"
"  color : green\n"
"}\n";

  CSSOM *cssom;
  CSSOM_CSSStyleSheet *styleSheet;
  const CSSOM_CSSRuleList *cssRules;
  CSSOM_CSSRule *cssRule;
  const CSSOM_CSSStyleDeclaration *style;
  
  cssom = CSSOM_create();
  styleSheet = CSSOM_parse(cssom, css, strlen(css));

  cssRules = CSSOM_CSSStyleSheet_cssRules(styleSheet);
  assert(CSSOM_CSSRuleList_length(cssRules) == 1);

  cssRule = CSSOM_CSSRuleList_at(cssRules, 0);
  assert(cssRule != NULL);

  assert(CSSOM_CSSRule_type(cssRule) == CSSOM_CSSRule_STYLE_RULE);

  ASSERT_EQUAL_STRINGS("p",
    CSSOM_CSSStyleRule_selectorText((CSSOM_CSSStyleRule*)cssRule));

  style = CSSOM_CSSStyleRule_style((CSSOM_CSSStyleRule*)cssRule);

  assert(CSSOM_CSSStyleDeclaration_length(style) == 1);

  ASSERT_EQUAL_STRINGS("green",
    CSSOM_CSSStyleDeclaration_getPropertyValue(style, "color"));
  ASSERT_EQUAL_STRINGS("",
    CSSOM_CSSStyleDeclaration_getPropertyPriority(style, "color"));
  ASSERT_EQUAL_STRINGS("color : green;",
    CSSOM_CSSStyleDeclaration_cssText(style));

  CSSOM_CSSStyleSheet_release(styleSheet);
  CSSOM_release(cssom);
}
コード例 #4
0
static void test_condition_factory(void) {
  SAC_MPool mpool;
  SAC_Condition *condition;
  SAC_Condition *firstCondition;
  SAC_Condition *secondCondition;
  SAC_Selector *selector;
  SAC_LexicalUnit *ident;

  mpool = SAC_mpool_open(256);

  condition = SAC_condition_class(mpool, "foo");
  assert(condition->conditionType == SAC_CLASS_CONDITION);
  assert(condition->desc.attribute.prefix == NULL);
  assert(condition->desc.attribute.name == NULL);
  assert(condition->desc.attribute.specified == SAC_TRUE);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.value);

  condition = SAC_condition_id(mpool, "foo");
  assert(condition->conditionType == SAC_ID_CONDITION);
  assert(condition->desc.attribute.prefix == NULL);
  assert(condition->desc.attribute.name == NULL);
  assert(condition->desc.attribute.specified == SAC_TRUE);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.value);

  condition = SAC_condition_prefix_attribute(mpool, "ns", "foo", "bar");
  assert(condition->conditionType == SAC_PREFIX_ATTRIBUTE_CONDITION);
  ASSERT_EQUAL_STRINGS("ns", condition->desc.attribute.prefix);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.name);
  assert(condition->desc.attribute.specified == SAC_FALSE);
  ASSERT_EQUAL_STRINGS("bar", condition->desc.attribute.value);

  condition = SAC_condition_suffix_attribute(mpool, "ns", "foo", "bar");
  assert(condition->conditionType == SAC_SUFFIX_ATTRIBUTE_CONDITION);
  ASSERT_EQUAL_STRINGS("ns", condition->desc.attribute.prefix);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.name);
  assert(condition->desc.attribute.specified == SAC_FALSE);
  ASSERT_EQUAL_STRINGS("bar", condition->desc.attribute.value);

  condition = SAC_condition_substring_attribute(mpool, "ns", "foo", "bar");
  assert(condition->conditionType == SAC_SUBSTRING_ATTRIBUTE_CONDITION);
  ASSERT_EQUAL_STRINGS("ns", condition->desc.attribute.prefix);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.name);
  assert(condition->desc.attribute.specified == SAC_FALSE);
  ASSERT_EQUAL_STRINGS("bar", condition->desc.attribute.value);

  condition = SAC_condition_attribute(mpool, "ns", "foo", "bar");
  assert(condition->conditionType == SAC_ATTRIBUTE_CONDITION);
  ASSERT_EQUAL_STRINGS("ns", condition->desc.attribute.prefix);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.name);
  assert(condition->desc.attribute.specified == SAC_TRUE);
  ASSERT_EQUAL_STRINGS("bar", condition->desc.attribute.value);

  condition = SAC_condition_attribute(mpool, "ns", "foo", NULL);
  assert(condition->conditionType == SAC_ATTRIBUTE_CONDITION);
  ASSERT_EQUAL_STRINGS("ns", condition->desc.attribute.prefix);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.name);
  assert(condition->desc.attribute.specified == SAC_FALSE);
  assert(condition->desc.attribute.value == NULL);

  condition = SAC_condition_one_of_attribute(mpool, "ns", "foo", "bar");
  assert(condition->conditionType == SAC_ONE_OF_ATTRIBUTE_CONDITION);
  ASSERT_EQUAL_STRINGS("ns", condition->desc.attribute.prefix);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.name);
  assert(condition->desc.attribute.specified == SAC_FALSE);
  ASSERT_EQUAL_STRINGS("bar", condition->desc.attribute.value);

  condition = SAC_condition_begin_hyphen_attribute(mpool, "ns", "foo", "bar");
  assert(condition->conditionType == SAC_BEGIN_HYPHEN_ATTRIBUTE_CONDITION);
  ASSERT_EQUAL_STRINGS("ns", condition->desc.attribute.prefix);
  ASSERT_EQUAL_STRINGS("foo", condition->desc.attribute.name);
  assert(condition->desc.attribute.specified == SAC_FALSE);
  ASSERT_EQUAL_STRINGS("bar", condition->desc.attribute.value);

  ident = SAC_lexical_unit_ident(mpool, "foo");
  condition = SAC_condition_pseudo_class(mpool, ident);
  assert(condition->conditionType == SAC_PSEUDO_CLASS_CONDITION);
  assert(condition->desc.pseudo == ident);

  ident = SAC_lexical_unit_ident(mpool, "foo");
  condition = SAC_condition_pseudo_element(mpool, ident);
  assert(condition->conditionType == SAC_PSEUDO_ELEMENT_CONDITION);
  assert(condition->desc.pseudo == ident);

  firstCondition = SAC_condition_class(mpool, "foo");
  secondCondition = SAC_condition_class(mpool, "bar");
  condition = SAC_condition_and(mpool, firstCondition, secondCondition);
  assert(condition->conditionType == SAC_AND_CONDITION);
  assert(condition->desc.combinator.firstCondition == firstCondition);
  assert(condition->desc.combinator.secondCondition == secondCondition);

  selector = SAC_selector_any_node(mpool);
  condition = SAC_condition_negation(mpool, selector);
  assert(condition->conditionType == SAC_NEGATIVE_CONDITION);
  assert(condition->desc.selector == selector);
  
  SAC_mpool_close(mpool);
}
コード例 #5
0
ファイル: write_concern.c プロジェクト: cmjonze/rpm5_tarballs
static void test_insert( mongo *conn ) {
    mongo_write_concern wc0[1], wc1[1];
    bson b[1], b2[1], b3[1], b4[1];
    bson *objs[2];

    mongo_cmd_drop_collection( conn, TEST_DB, TEST_COL, NULL );

    mongo_write_concern_init( wc0 );    
    mongo_write_concern_set_w( wc0, 0 );
    mongo_write_concern_finish( wc0 );
    mongo_write_concern_init( wc1 );    
    mongo_write_concern_set_w( wc1, 1 );
    mongo_write_concern_finish( wc1 );

    bson_init( b4 );
    bson_append_string( b4, "foo", "bar" );
    bson_finish( b4 );

    ASSERT( mongo_insert( conn, TEST_NS, b4, wc1 ) == MONGO_OK );

    ASSERT( mongo_remove( conn, TEST_NS, bson_shared_empty( ), wc1 ) == MONGO_OK );

    bson_init( b );
    bson_append_new_oid( b, "_id" );
    bson_finish( b );

    ASSERT( mongo_insert( conn, TEST_NS, b, NULL ) == MONGO_OK );

    /* This fails but returns OK with write concern w = 0 */
    ASSERT( mongo_insert( conn, TEST_NS, b, wc0 ) == MONGO_OK ); /* no getLastError request */

    ASSERT( mongo_insert( conn, TEST_NS, b, wc1 ) == MONGO_ERROR );
    ASSERT( conn->err == MONGO_WRITE_ERROR );
    ASSERT_EQUAL_STRINGS( conn->errstr, "See conn->lasterrstr for details." );
    ASSERT_EQUAL_STRINGS( conn->lasterrstr, "E11000 duplicate key error index" );
    ASSERT( conn->lasterrcode == 11000 );
    mongo_clear_errors( conn );

    /* Still fails but returns OK with write concern w = 0 */
    ASSERT( mongo_insert( conn, TEST_NS, b, wc0 ) == MONGO_OK );

    /* But not when we set a default write concern on the conn. */
    mongo_set_write_concern( conn, wc1 );
    ASSERT( mongo_insert( conn, TEST_NS, b, NULL ) != MONGO_OK );
    ASSERT( conn->err == MONGO_WRITE_ERROR );
    ASSERT_EQUAL_STRINGS( conn->errstr, "See conn->lasterrstr for details." );
    ASSERT_EQUAL_STRINGS( conn->lasterrstr, "E11000 duplicate key error index" );
    ASSERT( conn->lasterrcode == 11000 );

    /* Now test batch insert. */
    bson_init( b2 );
    bson_append_new_oid( b2, "_id" );
    bson_finish( b2 );

    bson_init( b3 );
    bson_append_new_oid( b3, "_id" );
    bson_finish( b3 );

    objs[0] = b2;
    objs[1] = b3;

    /* Insert two new documents by insert_batch. */
    conn->write_concern = NULL;
    ASSERT( mongo_count( conn, TEST_DB, TEST_COL, bson_shared_empty( ) ) == 1 );
    ASSERT( mongo_insert_batch( conn, TEST_NS, (const bson **)objs, 2, NULL, 0 ) == MONGO_OK );
    ASSERT( mongo_count( conn, TEST_DB, TEST_COL, bson_shared_empty( ) ) == 3 );

    /* This should definitely fail if we try again with write concern. */
    mongo_clear_errors( conn );
    ASSERT( mongo_insert_batch( conn, TEST_NS, (const bson **)objs, 2, wc1, 0 ) == MONGO_ERROR );
    ASSERT( conn->err == MONGO_WRITE_ERROR );
    ASSERT_EQUAL_STRINGS( conn->errstr, "See conn->lasterrstr for details." );
    ASSERT_EQUAL_STRINGS( conn->lasterrstr, "E11000 duplicate key error index" );
    ASSERT( conn->lasterrcode == 11000 );

    /* But it will succeed without the write concern set. */
    ASSERT( mongo_insert_batch( conn, TEST_NS, (const bson **)objs, 2, NULL, 0 ) == MONGO_OK );

    bson_destroy( b );
    bson_destroy( b2 );
    bson_destroy( b3 );
    bson_destroy( b4 );
    mongo_write_concern_destroy( wc0 );
    mongo_write_concern_destroy( wc1 );
}
コード例 #6
0
ファイル: write_concern.c プロジェクト: cmjonze/rpm5_tarballs
/* We can test write concern for update
 * and remove by doing operations on a capped collection. */
static void test_update_and_remove( mongo *conn ) {
    mongo_write_concern wc[1];
    bson *objs[5];
    bson query[1], update[1];
    int i;

    create_capped_collection( conn );

    for( i=0; i<5; i++ ) {
        objs[i] = bson_alloc();
        bson_init( objs[i] );
        bson_append_int( objs[i], "n", i );
        bson_finish( objs[i] );
    }

    ASSERT( mongo_insert_batch( conn, "test.wc", (const bson **)objs, 5,
        NULL, 0 ) == MONGO_OK );

    ASSERT( mongo_count( conn, "test", "wc", bson_shared_empty( ) ) == 5 );

    bson_init( query );
    bson_append_int( query, "n", 2 );
    bson_finish( query );

    ASSERT( mongo_find_one( conn, "test.wc", query, bson_shared_empty( ), NULL ) == MONGO_OK );

    bson_init( update );
        bson_append_start_object( update, "$set" );
            bson_append_string( update, "n", "a big long string" );
        bson_append_finish_object( update );
    bson_finish( update );

    /* Update will appear to succeed with no write concern specified, but doesn't. */
    ASSERT( mongo_find_one( conn, "test.wc", query, bson_shared_empty( ), NULL ) == MONGO_OK );
    ASSERT( mongo_update( conn, "test.wc", query, update, 0, NULL ) == MONGO_OK );
    ASSERT( mongo_find_one( conn, "test.wc", query, bson_shared_empty( ), NULL ) == MONGO_OK );

    /* Remove will appear to succeed with no write concern specified, but doesn't. */
    ASSERT( mongo_remove( conn, "test.wc", query, NULL ) == MONGO_OK );
    ASSERT( mongo_find_one( conn, "test.wc", query, bson_shared_empty( ), NULL ) == MONGO_OK );

    mongo_write_concern_init( wc );    
    mongo_write_concern_set_w( wc, 1 );
    mongo_write_concern_finish( wc );

    mongo_clear_errors( conn );
    ASSERT( mongo_update( conn, "test.wc", query, update, 0, wc ) == MONGO_ERROR );
    ASSERT( conn->err == MONGO_WRITE_ERROR );
    ASSERT_EQUAL_STRINGS( conn->lasterrstr, "failing update: objects in a capped ns cannot grow" );

    mongo_clear_errors( conn );
    ASSERT( mongo_remove( conn, "test.wc", query, wc ) == MONGO_ERROR );
    ASSERT( conn->err == MONGO_WRITE_ERROR );
    ASSERT_EQUAL_STRINGS( conn->lasterrstr, "can't remove from a capped collection" );

    mongo_write_concern_destroy( wc );
    bson_destroy( query );
    bson_destroy( update );
    for( i=0; i<5; i++ ) {
        bson_destroy( objs[i] );
        bson_dealloc( objs[i] );
    }
}