Пример #1
0
static void
test_regSubkeys(void)
{
    RegStatus   status;
    char*       value;

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

    status = reg_putString("/subkey/string_key", "string value 2");
    if (status) {
        log_error("test_subkeys(): Couldn't replace string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

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

    status = reg_putString("/subkey/string_key2", "string_value2");
    if (status) {
        log_error("test_subkeys(): Couldn't put second string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getString("/subkey/nonexistant_key", &value);
    if (status && ENOENT != status) {
        log_error("test_regString(): Couldn't verify non-existant value");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }
}
Пример #2
0
/*
 * Prints to the standard output stream all values in the registry whose path
 * name starts with a given prefix.
 *
 * Arguments:
 *      path            Pointer to a registry pathname to be printed.  Shall
 *                      not be NULL.
 *      quiet           Whether or not to be quiet about a pathname not
 *                      existing.
 * Returns:
 *      0               Success
 *      NO_SUCH_ENTRY   No such value or node.  "log_flush()" called iff "quiet
 *                      == 0".
 *      SYSTEM_ERROR    Failure.  "log_flush()" called.
 */
static Status printPath(
    const char*         path,
    const int           quiet)
{
    Status      status = 0;             /* success */
    RegStatus   regStatus;
    char*       value;

    log_debug("%s printing path \"%s\"", quiet ? "Quietly" : "Non-quietly", path);

    /*
     * The path name is first assumed to reference an existing value;
     * otherwise, the value wouldn't be printed.
     */ 
    if (0 == (regStatus = reg_getString(path, &value))) {
        if (NULL != value) {
            (void)printf("%s\n", value);
            free(value);
        }                               /* "value" allocated */
    }                                   /* got value-string */
    else {
        if (ENOENT != regStatus) {
            log_flush_error();
            status = SYSTEM_ERROR;
        }
        else {
            /*
             * The path must reference a node.
             */
            RegNode*    node;

            log_clear();

            if (0 != (regStatus = reg_getNode(path, &node, 0))) {
                if (ENOENT == regStatus) {
                    if (!quiet) {
                        log_error("No such value or node: \"%s\"", path);
                    }
                    status = NO_SUCH_ENTRY;
                }
                else {
                    log_flush_error();
                    status = SYSTEM_ERROR;
                }
            }                           /* didn't get node */
            else {
                _pathPrefix = path;

                if (0 != reg_visitNodes(node, printNodeValues)) {
                    log_flush_error();
                    status = SYSTEM_ERROR;
                }                       /* error visiting nodes */
            }                           /* got node */
        }                               /* no such value */
    }                                   /* didn't get value-string */

    return status;
}
Пример #3
0
static void
test_regMissing(void)
{
    RegStatus   status;
    char*       value;

    /* The registry shouldn't exist. */
    status = reg_getString("/foo_key", &value);
    CU_ASSERT_EQUAL(status, EIO);
    log_clear();
}
Пример #4
0
static void
test_regString(void)
{
    RegStatus   status;
    char*       value;

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

    status = reg_putString("/foo_key", "foo value");
    if (status) {
        log_error("test_regString(): Couldn't replace string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

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

    status = reg_getString("/bar_key", &value);
    if (status && ENOENT != status) {
        log_error("test_regString(): Couldn't add second string");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }
}
Пример #5
0
/*
 * Returns the path name of a file.
 *
 * Arguments:
 *      name            The name of the registry parameter that contains the
 *                      desired pathname.
 *      buf             Buffer of length PATH_MAX into which to put the path.
 *      desc            Pointer to a description of the file.
 * Returns:
 *      NULL            Error.  "log_log()" called.
 *      else            Pointer to the pathname of the file.  Might be absolute
 *                      or relative to the current working directory.
 */
static const char* getPath(
    const char* const   name,
    char                buf[PATH_MAX],
    const char* const   desc)
{
    if (0 == buf[0]) {
        char*           var;

        if (reg_getString(name, &var)) {
            LOG_ADD1("Couldn't get pathname of %s", desc);
            return NULL;
        }
        else {
            setPath(var, buf);
            free(var);
        }
    }

    return buf;
}
Пример #6
0
/**
 * Returns the pathname of the LDM log file.
 *
 * @return The pathname of the LDM log file
 */
static const char* get_ldm_logfile_pathname(void)
{
    static char pathname[_XOPEN_PATH_MAX];
    if (pathname[0] == 0) {
        int   reg_getString(const char* key, char** value);
        char* value;
        if (reg_getString("/log/file", &value)) {
            // No entry in registry
            (void)snprintf(pathname, sizeof(pathname), "%s/ldmd.log",
                    LDM_LOG_DIR);
            pathname[sizeof(pathname)-1] = 0;
            logl_internal(LOG_LEVEL_WARNING,
                    "Couldn't get pathname of LDM log file from registry. "
                    "Using default: \"%s\".", pathname);
        }
        else {
            (void)strncpy(pathname, value, sizeof(pathname));
            pathname[sizeof(pathname)-1] = 0;
            free(value);
        }
    }
    return pathname;
}
Пример #7
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);
    }
}