Ejemplo n.º 1
0
/**
 * Basic test for reallocation
 */
void test_Brealloc(void)
{
    UBFH *p_ub = NULL;

    p_ub=Balloc(1, 30);
    assert_not_equal(p_ub, NULL);

    assert_equal(Badd(p_ub, T_STRING_FLD, BIG_TEST_STRING, 0), FAIL);
    assert_equal(Berror, BNOSPACE);

    /* Now reallocate, space should be bigger! */
    p_ub=Brealloc(p_ub, 1, strlen(BIG_TEST_STRING)+1+2/* align */);
    assert_not_equal(p_ub, NULL);
    assert_equal(Badd(p_ub, T_STRING_FLD, BIG_TEST_STRING, 0), SUCCEED);
    
    /* should not allow to reallocate to 0! */
    assert_equal(Brealloc(p_ub, 1, 0), NULL);
    assert_equal(Berror, BEINVAL);

    /* should be bigger than existing. */
    assert_equal(Brealloc(p_ub, 1, strlen(BIG_TEST_STRING)+1), NULL);
    assert_equal(Berror, BEINVAL);

    assert_equal(SUCCEED, Bfree(p_ub));

}
Ejemplo n.º 2
0
void TEST4_2ND (TPSVCINFO *p_svc)
{
    int ret=SUCCEED;

    static double d = 11.66;

    UBFH *p_ub = (UBFH *)p_svc->data;

    NDRX_LOG(log_debug, "TESTSVFN got call");

    /* Just print the buffer */
    Bprint(p_ub);
    if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 4096))) /* allocate some stuff for more data to put in  */
    {
        ret=FAIL;
        goto out;
    }

    d+=1;

    if (FAIL==Badd(p_ub, T_DOUBLE_2_FLD, (char *)&d, 0))
    {
        ret=FAIL;
        goto out;
    }

out:
    tpreturn(  ret==SUCCEED?TPSUCCESS:TPFAIL,
                0L,
                (char *)p_ub,
                0L,
                0L);
}
Ejemplo n.º 3
0
void TEST2_1ST (TPSVCINFO *p_svc)
{
    int ret=SUCCEED;

    static double d = 55.66;

    UBFH *p_ub = (UBFH *)p_svc->data;

    NDRX_LOG(log_debug, "TEST2_1ST got call");

    /* Just print the buffer */
    Bprint(p_ub);
    if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 8192))) /* allocate some stuff for more data to put in  */
    {
        ret=FAIL;
        goto out;
    }

    d+=1;

    if (FAIL==Badd(p_ub, T_DOUBLE_FLD, (char *)&d, 0))
    {
        ret=FAIL;
        goto out;
    }

out:
    tpforward(  "TEST2_2ND",
                (char *)p_ub,
                0L,
                0L);
}
Ejemplo n.º 4
0
/*
 * Do the test call to the server
 */
int main(int argc, char** argv) {

    UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
    long rsplen;
    int i;
    int ret=SUCCEED;

    
    CBadd(p_ub, T_DOUBLE_FLD, "5", 0, BFLD_STRING);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);

    /* Do it many times...! */
    for (i=0; i<9900; i++)
    {
        ret=tppost("EVX.TEST", (char*)p_ub, 0L, TPSIGRSTRT);
        NDRX_LOG(log_debug, "dispatched events: %d", ret);
        if (ret!=6)
        {
            NDRX_LOG(log_error, "Applied event count is not 6 (which is %d)", ret);
            ret=FAIL;
            goto out;
        }
        else
        {
            NDRX_LOG(log_debug, "6 dispatches - OK");
        }
        
        if (i % 1000 == 0)
        {
            /* let services to flush the stuff... */
            NDRX_LOG(log_debug, "Dispatched %d - sleeping", i);
            sleep(10);
        }
    }

    ret=tppost("TEST2EV", (char*)p_ub, 0L, TPSIGRSTRT);

    if (3!=ret)
    {
        NDRX_LOG(log_error, "TESTERROR: First post of TEST2EV did not return 3 (%d) ",
                                    ret);
        ret=FAIL;
        goto out;
    }
    sleep(10); /* << because server may not complete the unsubscribe! */
    ret=tppost("TEST2EV", (char*)p_ub, 0L, TPSIGRSTRT);
    if (0!=ret)
    {
        NDRX_LOG(log_error, "TESTERROR: Second post of TEST2EV did not return 0 (%d) ",
                                    ret);
        ret=FAIL;
        goto out;
    }

out:


    if (ret>=0)
        ret=SUCCEED;


    return ret;
}
Ejemplo n.º 5
0
/*
 * Do the test call to the server
 */
int main(int argc, char** argv) {

    UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
    long rsplen;
    int i;
    int ret=SUCCEED;
    double d;
    double dv = 55.66;
    int cd;
    long revent;
    int received = 0;
    char tmp[126];

    
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);


    if (FAIL==(cd=tpconnect("CONVSV", (char *)p_ub, 0L, TPRECVONLY)))
    {
            NDRX_LOG(log_error, "TESTSV connect failed!: %s",
                                    tpstrerror(tperrno));
            ret=FAIL;
            goto out;
    }

    /* Recieve the stuff back */
    NDRX_LOG(log_debug, "About to tprecv!");

    while (SUCCEED==tprecv(cd, (char **)&p_ub, 0L, 0L, &revent))
    {
        received++;
        NDRX_LOG(log_debug, "MSG RECEIVED OK!");
    }
    

    /* If we have event, we would like to become recievers if so */
    if (TPEEVENT==tperrno)
    {
        received++;
        sprintf(tmp, "CLT: %d", received);
        
        Badd(p_ub, T_STRING_FLD, tmp, 0L);
        if (TPEV_SENDONLY==revent)
        {
            int i=0;
            /* Start the sending stuff now! */
            for (i=0; i<100 && SUCCEED==ret; i++)
            {
                ret=tpsend(cd, (char *)p_ub, 0L, 0L, &revent);
            }
        }
    }

    /* Now give the control to the server, so that he could finish up */
    if (FAIL==tpsend(cd, NULL, 0L, TPRECVONLY, &revent))
    {
        NDRX_LOG(log_debug, "Failed to give server control!!");
        ret=FAIL;
        goto out;
    }

    NDRX_LOG(log_debug, "Get response from tprecv!");
    Bfprint(p_ub, stderr);

    /* Wait for return from server */
    ret=tprecv(cd, (char **)&p_ub, 0L, 0L, &revent);
    NDRX_LOG(log_error, "tprecv failed with revent=%ld", revent);

    if (FAIL==ret && TPEEVENT==tperrno && TPEV_SVCSUCC==revent)
    {
        NDRX_LOG(log_error, "Service finished with TPEV_SVCSUCC!");
        ret=SUCCEED;
    }
    
    if (SUCCEED!=tpterm())
    {
        NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
        ret=FAIL;
        goto out;
    }
    
out:
    return ret;
}
Ejemplo n.º 6
0
/**
 * Basic test for Badd & Bget
 */
void test_Badd_str(void)
{
    char pan1[32] = "THIS IS 1";
    char pan2[32] = "THIS IS 2";
    char pan3[32] = "THIS IS 3";
    char pan4[32] = "THIS IS 4";

    double amttxn1=10021.123;
    double amttxn2=20021.123;
    double amttxn3=321.123;
    double amttxn4=11.123;
    double amttxn5=33.123;
    double tmp_amttxn=0;

    char tmp_buf[32+8]; /* 8 for alignment */
    int org_used = Bused(M_p_ub1);

    assert_equal(
            Badd(M_p_ub1, T_STRING_FLD, pan1, 0),
            SUCCEED);

    assert_equal(
            Badd(M_p_ub1, T_STRING_FLD, pan2, 0),
            SUCCEED);

    assert_equal(
            Badd(M_p_ub1, T_STRING_FLD, pan3, 0),
            SUCCEED);

    assert_equal(
            Badd(M_p_ub1, T_STRING_FLD, pan4, 0),
            SUCCEED);

    /* Get the data from buffer */
    assert_equal(
            Bget(M_p_ub1, T_STRING_FLD, 0, tmp_buf, 0),
            SUCCEED);
    assert_string_equal(pan1, tmp_buf);

    assert_equal(
            Bget(M_p_ub1, T_STRING_FLD, 1, tmp_buf, 0),
            SUCCEED);
    assert_string_equal(pan2, tmp_buf);

    assert_equal(
            Bget(M_p_ub1, T_STRING_FLD, 2, tmp_buf, 0),
            SUCCEED);
    assert_string_equal(pan3, tmp_buf);

    assert_equal(
            Bget(M_p_ub1, T_STRING_FLD, 3, tmp_buf, 0),
            SUCCEED);
    assert_string_equal(pan4, tmp_buf);

    /* Now add something other, some double value? */
    assert_equal(
            Badd(M_p_ub1, T_DOUBLE_4_FLD, (char *)&amttxn1, 0),
            SUCCEED);
    assert_equal(
            Badd(M_p_ub1, T_DOUBLE_4_FLD, (char *)&amttxn2, 0),
            SUCCEED);
    assert_equal(
            Badd(M_p_ub1, T_DOUBLE_4_FLD, (char *)&amttxn3, 0),
            SUCCEED);
    assert_equal(
            Badd(M_p_ub1, T_DOUBLE_4_FLD, (char *)&amttxn4, 0),
            SUCCEED);
    /* Do not have space availabel in buffer */
    assert_equal(
            Badd(M_p_ub1, T_DOUBLE_4_FLD, (char *)&amttxn5, 0),
            FAIL);
    /* Compare the values from buffer */
    assert_equal(
        Bget(M_p_ub1, T_DOUBLE_4_FLD, 0, (char *)&tmp_amttxn, 0),
        SUCCEED);
    assert_double_equal(tmp_amttxn, 10021.123);

    assert_equal(
            Bget(M_p_ub1, T_DOUBLE_4_FLD, 1, (char *)&tmp_amttxn, 0),
            SUCCEED);
    assert_double_equal(tmp_amttxn, 20021.123);

    assert_equal(
            Bget(M_p_ub1, T_DOUBLE_4_FLD, 2, (char *)&tmp_amttxn, 0),
            SUCCEED);
    assert_double_equal(tmp_amttxn, 321.123);
    assert_equal(
            Bget(M_p_ub1, T_DOUBLE_4_FLD, 3, (char *)&tmp_amttxn, 0),
            SUCCEED);
    assert_double_equal(tmp_amttxn, 11.123);
    /* Do not have space in buffer! */
    assert_equal(
            Bget(M_p_ub1, T_DOUBLE_4_FLD, 4, (char *)&tmp_amttxn, 0),
            FAIL);

    /* Summ the stuff up (+4 - EOS symbols in buffer)*/
    assert_equal(org_used+strlen(pan1)+strlen(pan2)+strlen(pan3)+strlen(pan4)+4+
                sizeof(amttxn1)+sizeof(amttxn2)+sizeof(amttxn3)+sizeof(amttxn4)+
                8*sizeof(BFLDID)+8/*align*/, Bused(M_p_ub1));
}