Exemple #1
0
/**
 * Returns the backlog time-offset for making requests of an upstream LDM.
 *
 * @return  The backlog time-offset, in seconds, for making requests of an
 *          upstream LDM.
 */
unsigned
getTimeOffset(void)
{
    static unsigned timeOffset;
    static int      isSet = 0;

    if (!isSet) {
        int status = reg_getUint(REG_TIME_OFFSET, &timeOffset);

        if (status) {
            timeOffset = 3600;
            LOG_ADD1("Using default value: %u seconds", timeOffset);
            if (status == ENOENT) {
                log_log(LOG_INFO);
                isSet = 1;
            }
            else {
                log_log(LOG_ERR);
            }
        }
        else {
            isSet = 1;
        }
    }

    return timeOffset;
}
Exemple #2
0
static void
test_regInt(void)
{
    RegStatus   status;
    int         value;

    status = reg_putUint("/fooInt_key", 1);
    if (status) {
        log_error("test_regInt(): Couldn't add int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_putUint("/fooInt_key", 2);
    if (status) {
        log_error("test_regInt(): Couldn't replace int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getUint("/fooInt_key", &value);
    if (status) {
        log_error("test_regInt(): Couldn't get int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_EQUAL(value, 2);
    }

    status = reg_getUint("/barInt_key", &value);
    if (status && ENOENT != status) {
        log_error("test_regInt(): Couldn't put second int");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }
}
Exemple #3
0
static void
test_regDelete(void)
{
    RegStatus   status;
    char*       string;
    int         value;

    status = reg_putString("/string_key", "string value");
    if (status) {
        log_error("test_regDelete(): Couldn't put string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getString("/string_key", &string);
    if (status) {
        log_error("test_regDelete(): Couldn't get string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_STRING_EQUAL(string, "string value");
        free(string);
    }

    status = reg_deleteValue("/string_key");
    if (status) {
        log_error("test_regDelete(): Couldn't delete string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getString("/string_key", &string);
    if (status && ENOENT != status) {
        log_error("test_regDelete(): Couldn't verify string deletion");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_putUint("/int_key", -1);
    if (status) {
        log_error("test_regDelete(): Couldn't put int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getUint("/int_key", &value);
    if (status) {
        log_error("test_regDelete(): Couldn't get int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_EQUAL(value, -1);
    }

    status = reg_deleteValue("/int_key");
    if (status) {
        log_error("test_regDelete(): Couldn't delete int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getUint("/int_key", &value);
    if (status && ENOENT != status) {
        log_error("test_regDelete(): Couldn't verify int deletion");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_deleteValue("/nosuch_key");
    if (status && ENOENT != status) {
        log_error("test_regDelete(): Couldn't verify no-such-value deletion");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }
}