Exemple #1
0
static rc
testStringInfo(void)
{
    StringInfo str = makeStringInfo();

    appendStringInfoChar(str,'a');
    ASSERT_EQUALS_STRING("a", str->data, "data is a");

    appendStringInfoString(str, "hello");
    ASSERT_EQUALS_STRING("ahello", str->data, "data is ahello");
    ASSERT_EQUALS_INT(6, str->len, "length is 6");

    for(int i = 0; i < 256; i++)
        appendStringInfoChar(str, 'b');
    ASSERT_EQUALS_INT(6 + 256, str->len, "length is 6 + 256");
    for(int i = 255; i < 256 + 6; i++)
        ASSERT_EQUALS_INT('b', str->data[i], "chars are all b");

    resetStringInfo(str);
    ASSERT_EQUALS_INT(0, str->len, "after reset length is 0");

    appendStringInfo(str, "%s", "test");
    ASSERT_EQUALS_STRING("test", str->data, "data is test");

    return PASS;
}
Exemple #2
0
// ************************************************************
void
testValueSerialize (void)
{
    testName = "test value serialization and deserialization";
    
    ASSERT_EQUALS_STRING(serializeValue(stringToValue("i10")), "10", "create Value 10");
    ASSERT_EQUALS_STRING(serializeValue(stringToValue("f5.3")), "5.300000", "create Value 5.3");
    ASSERT_EQUALS_STRING(serializeValue(stringToValue("sHello World")), "Hello World", "create Value Hello World");
    ASSERT_EQUALS_STRING(serializeValue(stringToValue("bt")), "true", "create Value true");
    ASSERT_EQUALS_STRING(serializeValue(stringToValue("btrue")), "true", "create Value true");
    
    TEST_DONE();
}
void 
checkDummyPages(BM_BufferPool *bm, int num)
{
  int i;
  BM_PageHandle *h = MAKE_PAGE_HANDLE();
  char *expected = malloc(sizeof(char) * 512);

  CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL));

  for (i = 0; i < num; i++)
    {
      CHECK(pinPage(bm, h, i));

      sprintf(expected, "%s-%i", "Page", h->pageNum);

      ASSERT_EQUALS_STRING(expected, h->data, "reading back dummy page content");
	 
      CHECK(unpinPage(bm,h));
    }

  CHECK(shutdownBufferPool(bm));

  free(expected);
  free(h);
}
Exemple #4
0
static rc
testExpressionToSQL()
{
//    Constant *c1, *c2;
    Operator *o;

    o = createOpExpr("+", LIST_MAKE(createConstInt(1), createConstInt(2)));

    ASSERT_EQUALS_STRING("(1 + 2)", exprToSQL((Node *) o), "translate expression into SQL code (1 + 2)");

    o = createOpExpr("*", LIST_MAKE(o, createConstFloat(2.0)));
    ASSERT_EQUALS_STRING("((1 + 2) * 2.000000)", exprToSQL((Node *) o), "translate expression into SQL code (1 + 2) * 2.0");

    o = createOpExpr("+", LIST_MAKE(createAttributeReference("a"), createConstInt(2)));
    ASSERT_EQUALS_STRING("(a + 2)", exprToSQL((Node *) o), "translate expression into SQL code (a + 2)");

    return PASS;
}
Exemple #5
0
void
testPrintTree(void)
{
  RID insert[] = { 
    {1,1},
    {2,3},
    {1,2},
    {3,5},
    {4,4},
    {3,2}, 
  };
  int numInserts = 6;
  Value **keys;
  char *stringKeys[] = {
    "i1",
    "i11",
    "i13",
    "i17",
    "i23",
    "i52"
  };
  testName = "test b-tree print";
  int i, testint;
  BTreeHandle *tree = NULL;
  
  keys = createValues(stringKeys, numInserts);

  // init
  TEST_CHECK(initIndexManager(NULL));
  TEST_CHECK(createBtree("testidx", DT_INT, 2));
  TEST_CHECK(openBtree(&tree, "testidx"));
       printf("0"); // remove it later

  // insert keys
  for(i = 0; i < numInserts; i++)
    TEST_CHECK(insertKey(tree, keys[i], insert[i]));

  
  char * expected = "(0)[1,13,2,23,3]\n(1)[1.1,1,2.3,11,2]\n(2)[1.2,13,3.5,17,3]\n(3)[4.4,23,3.2,52]\n";

  //test printTree function
  ASSERT_EQUALS_STRING(expected,printTree(tree),"checking b-tree shape");			\

  // cleanup
  TEST_CHECK(closeBtree(tree));
  TEST_CHECK(deleteBtree("testidx"));
  TEST_CHECK(shutdownIndexManager());
  freeValues(keys, numInserts);

  TEST_DONE();
}
Exemple #6
0
static rc
testFunctionCall(void)
{
    FunctionCall *a;
    Constant *c;

    a = createFunctionCall ("f", LIST_MAKE(createConstInt(1), createConstInt(2)));
    c = (Constant *) getNthOfListP(a->args, 0);

    ASSERT_EQUALS_INT(1, INT_VALUE(c), "first arg is 1 const");
    ASSERT_EQUALS_STRING("f", a->functionname, "function name is f");

    return PASS;
}
Exemple #7
0
static rc
testOperator (void)
{
    Operator *a;
    Constant *c;

    a = createOpExpr("f", LIST_MAKE(createConstInt(1), createConstInt(2)));
    c = (Constant *) getNthOfListP(a->args, 0);

    ASSERT_EQUALS_INT(1, INT_VALUE(c), "first arg is 1 const");
    ASSERT_EQUALS_STRING("f", a->name, "op name is f");

    return PASS;
}
Exemple #8
0
void 
readAndCheckDummyPage(BM_BufferPool *bm, int pageNum)
{
  BM_PageHandle *h = MAKE_PAGE_HANDLE();
  char *expected = malloc(sizeof(char) * 512);

  CHECK(pinPage(bm, h, pageNum));

  sprintf(expected, "%s-%i", "Page", h->pageNum);
  ASSERT_EQUALS_STRING(expected, h->data, "check read page dummy page content");
  CHECK(unpinPage(bm,h));

  free(expected);
  free(h);
}
Exemple #9
0
static rc
testQueryBlockToString(void)
{
    char *toString;
    QueryBlock *q = createQueryBlock();

    q->distinct = NULL;
    q->fromClause = NIL;
    q->havingClause = NULL;
    q->selectClause = NIL;
    q->whereClause = NULL;

    toString = nodeToString(q);
    ASSERT_EQUALS_STRING("{QUERYBLOCK:distinct|<>:selectClause|<>:fromClause|<>"
                         ":whereClause|<>:groupByClause|<>:havingClause|<>:orderByClause|<>"
                         ":limitClause|<>}", toString, "");

    return PASS;
}
Exemple #10
0
static rc
testConstant (void)
{
    Constant *c;
    char *str;

    c = createConstInt(1);
    ASSERT_EQUALS_INT(1, INT_VALUE(c), "constant int 1");

    c = createConstFloat(2.0);
    ASSERT_EQUALS_FLOAT(2.0, FLOAT_VALUE(c), "constant float 2.0");

    c = createConstBool(TRUE);
    ASSERT_EQUALS_INT(TRUE, BOOL_VALUE(c), "constant boolean TRUE");

    str = strdup("test");
    c = createConstString(str);
    ASSERT_EQUALS_STRING("test", STRING_VALUE(c), "constant string \"test\"");

    return PASS;
}
Exemple #11
0
rc
testPICSGraph(void)
{
    //RUN_TEST(testTableAccessRewrite(),"test table access rewrite for graphs");
    initMetadataLookupPlugins();
    chooseMetadataLookupPlugin(METADATA_LOOKUP_PLUGIN_ORACLE);
    initMetadataLookupPlugin();
    List *res, *first;
    List *second;

    //Test projection
    //Check if the right result is returned
    char *s = "WITH x AS (SELECT a,b FROM test_graph_pi) SELECT a.a FROM x a, (SELECT a AS c, b AS d FROM x) b  WHERE a.a = b.d AND a.a = 2";
    char *sParse = "WITH x AS (SELECT a,b FROM test_graph_pi) SELECT m.a FROM x m, (SELECT a AS c, b AS d FROM x) n  WHERE m.a = n.d AND m.a = 2;";
    res = executeQuery(s);
    DEBUG_LOG("%s", nodeToString(res));
    DEBUG_LOG("%s", beatify(nodeToString(res)));
    first = (List *)getHeadOfListP(res);
    second = (List *)getNthOfListP(res, 1);
    ASSERT_EQUALS_STRING(getHeadOfListP(first), "2", "First value is correct.");
    ASSERT_EQUALS_STRING(getHeadOfListP(second), "2", "Second value is correct.");

    //Then check the node has been rewritten only once
    Node *result;
    Node *qoModel;
    QueryOperator *rewriteQoModel, *op;

    result = parseFromString(sParse);
    qoModel = translateParse(result);
    op = (QueryOperator *) getHeadOfListP((List *) qoModel);
    rewriteQoModel = rewritePI_CS((ProvenanceComputation *) op);
    DEBUG_LOG("rewrite is %s", operatorToOverviewString((Node *) rewriteQoModel));
    ASSERT_EQUALS_P((Node*)OP_LCHILD(OP_LCHILD(rewriteQoModel)), (Node*)OP_LCHILD(OP_LCHILD(OP_RCHILD(OP_LCHILD(rewriteQoModel)))),"The address of the children is same.");


    //Test aggregation
    s = "WITH x AS (SELECT sum(a) as a, b FROM test_graph_pi group by b) SELECT a.a FROM x a, (SELECT a AS c, b AS d FROM x) b  WHERE a.a = b.c";
    res = executeQuery(s);
    first = (List *)getHeadOfListP(res);

    ASSERT_EQUALS_STRING(getHeadOfListP(first), "3", "First value is correct.");

    /*
    result = parseFromString(getStringOption(s));
    qoModel = translateParse(result);
    op = (QueryOperator *) getHeadOfListP((List *) qoModel);
    rewriteQoModel = rewritePI_CS((ProvenanceComputation *) op);
    ASSERT_EQUALS_P((Node*)OP_LCHILD(OP_LCHILD(rewriteQoModel)), (Node*)OP_RCHILD(OP_LCHILD(rewriteQoModel)),"The address of the children is same.");
	*/

    //Test join
    s = "WITH x AS (SELECT test_graph_pi.a, test_graph_pi2.c FROM test_graph_pi join test_graph_pi2 on test_graph_pi.B = test_graph_pi2.C) SELECT a.a FROM x a, (SELECT a AS c, c AS d FROM x) b WHERE a.a = b.c";
    res = executeQuery(s);
    first = (List *)getHeadOfListP(res);
    second = (List *)getNthOfListP(res, 1);
    ASSERT_EQUALS_STRING(getHeadOfListP(first), "1", "First value is correct.");
    ASSERT_EQUALS_STRING(getHeadOfListP(second), "2", "Second value is correct.");

    /*
    result = parseFromString(getStringOption(s));
    qoModel = translateParse(result);
    op = (QueryOperator *) getHeadOfListP((List *) qoModel);
    rewriteQoModel = rewritePI_CS((ProvenanceComputation *) op);
    ASSERT_EQUALS_P((Node*)OP_LCHILD(OP_LCHILD(rewriteQoModel)), (Node*)OP_RCHILD(OP_LCHILD(rewriteQoModel)),"The address of the children is same.");
	*/
	//Test set
    s = "WITH x AS (SELECT a FROM test_graph_pi UNION ALL SELECT a as c FROM test_graph_pi t) SELECT a.a FROM  x a, (SELECT a AS c FROM x) WHERE c = 1 AND a = 1";
    res = executeQuery(s);
    first = (List *)getHeadOfListP(res);
    second = (List *)getNthOfListP(res, 1);
    ASSERT_EQUALS_STRING(getHeadOfListP(first), "1", "First value is correct.");
    ASSERT_EQUALS_STRING(getHeadOfListP(second), "1", "Second value is correct.");
	/*
    result = parseFromString(getStringOption(s));
    qoModel = translateParse(result);
    op = (QueryOperator *) getHeadOfListP((List *) qoModel);
    rewriteQoModel = rewritePI_CS((ProvenanceComputation *) op);
    ASSERT_EQUALS_P((Node*)OP_LCHILD(OP_LCHILD(rewriteQoModel)), (Node*)OP_RCHILD(OP_LCHILD(rewriteQoModel)),"The address of the children is same.");
	*/
	//Test order
	s = "WITH x AS (SELECT * FROM test_graph_pi ORDER BY a) SELECT a.a FROM x a, (SELECT a AS c FROM x) WHERE c = 2 AND a = 2";
	res = executeQuery(s);
	first = (List *)getHeadOfListP(res);
    ASSERT_EQUALS_STRING(getHeadOfListP(first), "2", "First value is correct.");

    /*
    result = parseFromString(getStringOption(s));
    qoModel = translateParse(result);
    op = (QueryOperator *) getHeadOfListP((List *) qoModel);
    rewriteQoModel = rewritePI_CS((ProvenanceComputation *) op);
    ASSERT_EQUALS_P((Node*)OP_LCHILD(OP_LCHILD(rewriteQoModel)), (Node*)OP_RCHILD(OP_LCHILD(rewriteQoModel)),"The address of the children is same.");
	*/

	//Test duplicate removal
	s = "WITH x AS (SELECT a FROM test_graph_pi UNION SELECT a as c FROM test_graph_pi t) SELECT a.a FROM  x a, (SELECT a AS c FROM x) WHERE c = 1 AND a = 1";
	res = executeQuery(s);
	first = (List *)getHeadOfListP(res);
    ASSERT_EQUALS_STRING(getHeadOfListP(first), "1", "First value is correct.");

    /*
    result = parseFromString(getStringOption(s));
    qoModel = translateParse(result);
    op = (QueryOperator *) getHeadOfListP((List *) qoModel);
    rewriteQoModel = rewritePI_CS((ProvenanceComputation *) op);
    ASSERT_EQUALS_P((Node*)OP_LCHILD(OP_LCHILD(rewriteQoModel)), (Node*)OP_RCHILD(OP_LCHILD(rewriteQoModel)),"The address of the children is same.");

	*/

    return PASS;
}