Example #1
0
void test_tcp_connect_ok1(CuTest* tc)
{
    evrythng_handle_t h;
    common_tcp_init_handle(&h);
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngDisconnect(h));
    EvrythngDestroyHandle(h);
}
Example #2
0
void test_subunsub_prod(CuTest* tc)
{
    PRINT_START_MEM_STATS 
    evrythng_handle_t h1;
    common_tcp_init_handle(&h1);
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngConnect(h1));

    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubProductProperty(h1, PRODUCT_1, PROPERTY_1, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubProductProperty(h1, PRODUCT_1, PROPERTY_2, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubProductProperty(h1, PRODUCT_1, PROPERTY_1));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubProductProperty(h1, PRODUCT_1, PROPERTY_2));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubProductProperties(h1, PRODUCT_1, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubProductProperties(h1, PRODUCT_1));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubProductAction(h1, PRODUCT_1, ACTION_1, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubProductAction(h1, PRODUCT_1, ACTION_2, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubProductAction(h1, PRODUCT_1, ACTION_2));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubProductActions(h1, PRODUCT_1, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubProductActions(h1, PRODUCT_1));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubAction(h1, ACTION_1, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubAction(h1, ACTION_2, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubAction(h1, ACTION_2));

    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngDisconnect(h1));
    EvrythngDestroyHandle(h1);
    PRINT_END_MEM_STATS
}
Example #3
0
void test_set_callback_fail(CuTest* tc)
{
    evrythng_handle_t h;
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngInitHandle(&h));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSetLogCallback(h, 0));
    EvrythngDestroyHandle(h);
}
Example #4
0
void test_set_qos_fail(CuTest* tc)
{
    evrythng_handle_t h;
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngInitHandle(&h));
    CuAssertIntEquals(tc, EVRYTHNG_BAD_ARGS, EvrythngSetQos(h, 8));
    EvrythngDestroyHandle(h);
}
Example #5
0
void test_set_url_ok(CuTest* tc)
{
    evrythng_handle_t h;
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngInitHandle(&h));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSetUrl(h, "tcp://localhost:666"));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSetUrl(h, "ssl://localhost:666"));
    EvrythngDestroyHandle(h);
}
Example #6
0
void test_set_client_id_ok(CuTest* tc)
{
    evrythng_handle_t h;
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngInitHandle(&h));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSetClientId(h, "123456789"));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSetClientId(h, "123456789123456789"));
    EvrythngDestroyHandle(h);
}
Example #7
0
void test_set_url_fail(CuTest* tc)
{
    evrythng_handle_t h;
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngInitHandle(&h));
    CuAssertIntEquals(tc, EVRYTHNG_BAD_ARGS, EvrythngSetUrl(h, 0));
    CuAssertIntEquals(tc, EVRYTHNG_BAD_URL, EvrythngSetUrl(h, "ttt://localhost:666"));
    EvrythngDestroyHandle(h);
}
Example #8
0
void test_tcp_connect_ok2(CuTest* tc)
{
    PRINT_START_MEM_STATS 
    evrythng_handle_t h1;
    common_tcp_init_handle(&h1);
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngConnect(h1));
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngDisconnect(h1));
    EvrythngDestroyHandle(h1);
    PRINT_END_MEM_STATS
}
Example #9
0
void test_sub_diffpubstate(CuTest* tc)
{
    PRINT_START_MEM_STATS
    evrythng_handle_t h1;
    common_tcp_init_handle(&h1);
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngConnect(h1));
    
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngProperty(h1, THNG_1, PROPERTY_1, 0, test_sub_callback));
    CuAssertIntEquals(tc, EVRYTHNG_ALREADY_SUBSCRIBED, EvrythngSubThngProperty(h1, THNG_1, PROPERTY_1, 1, test_sub_callback));

    EvrythngDisconnect(h1);
    EvrythngDestroyHandle(h1);
    PRINT_END_MEM_STATS
}
Example #10
0
void test_unsub_nonexistent(CuTest* tc)
{
    PRINT_START_MEM_STATS
    evrythng_handle_t h1;
    common_tcp_init_handle(&h1);
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngConnect(h1));
    
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngConnect(h1));
    CuAssertIntEquals(tc, EVRYTHNG_NOT_SUBSCRIBED, EvrythngUnsubThngProperty(h1, THNG_1, PROPERTY_1));
    CuAssertIntEquals(tc, EVRYTHNG_NOT_SUBSCRIBED, EvrythngUnsubThngProperty(h1, THNG_1, PROPERTY_2));

    EvrythngDisconnect(h1);
    EvrythngDestroyHandle(h1);
    PRINT_END_MEM_STATS
}
Example #11
0
static void evrythng_task(void* pvParameters)
{
    cmd_opts* opts = (cmd_opts*)pvParameters;

    EvrythngInitHandle(&opts->evt_handle);
    EvrythngSetLogCallback(opts->evt_handle, log_callback);
    EvrythngSetConnectionCallbacks(opts->evt_handle, conlost_callback, conrestored_callback);
    EvrythngSetUrl(opts->evt_handle, opts->url);
    EvrythngSetKey(opts->evt_handle, opts->key);
    EvrythngSetThreadPriority(opts->evt_handle, 5);

    log("Connecting to %s", opts->url);
    while(EvrythngConnect(opts->evt_handle) != EVRYTHNG_SUCCESS) 
    {
        log("Retrying");
        platform_sleep(2000);
    }
    log("Evrythng client Connected");
    
    if (opts->sub) 
    {
        log("Subscribing to property %s", opts->prop);
        EvrythngSubThngProperty(opts->evt_handle, opts->thng, opts->prop, 1, print_property_callback);
        while (!stop) 
        {
            platform_sleep(2000);
        }
    } 
    else 
    {
        while (!stop) 
        {
            int value = rand() % 100;
            char msg[128];
            sprintf(msg, "[{\"value\": %d}]", value);
            log("Publishing value %d to property %s", value, opts->prop);
            EvrythngPubThngProperty(opts->evt_handle, opts->thng, opts->prop, msg);
            platform_sleep(1000);
        }
    }

    EvrythngDisconnect(opts->evt_handle);
    EvrythngDestroyHandle(opts->evt_handle);

    vTaskEndScheduler();
}
Example #12
0
void test_init_handle_ok(CuTest* tc)
{
    evrythng_handle_t h;
    CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngInitHandle(&h));
    EvrythngDestroyHandle(h);
}