예제 #1
0
/*
 * Removes the values referenced by an absolute registry pathname.
 *
 * Arguments:
 *      path            Pointer to a an absolute registry pathname.  Shall not
 *                      be NULL.  If the pathname refers to a node, then the
 *                      node and all its subnodes are recursively removed.
 *      quiet           Whether or not to be quiet about a pathname not
 *                      existing.
 * Returns:
 *      0               Success.
 *      NO_SUCH_ENTRY   No such entry in the registry.  "log_flush()" called iff
 *                      "quiet == 0".
 *      SYSTEM_ERROR    System error.  "log_flush()" called.
 */
static Status deletePath(
    const char* const   path,
    const int           quiet)
{
    log_debug("%s deleting path \"%s\"", quiet ? "Quietly" : "Non-quietly", path);

    switch (reg_deleteValue(path)) {
        case 0:
            return 0;

        case ENOENT: {
            RegNode*        node;

            switch (reg_getNode(path, &node, 0)) {
                case 0:
                    reg_deleteNode(node);

                    if (reg_flushNode(node)) {
                        log_flush_error();
                        return SYSTEM_ERROR;
                    }

                    return 0;
                case ENOENT:
                    if (!quiet) {
                        log_error("No such value or node: \"%s\"", path);
                    }
                    return NO_SUCH_ENTRY;
                default:
                    log_flush_error();
                    return SYSTEM_ERROR;
            }
        }
        /* FALLTHROUGH */
        /* no break */

        default:
            log_flush_error();
            return SYSTEM_ERROR;
    }
}
예제 #2
0
static void
test_regNode(void)
{
    RegStatus   status;
    RegNode*    testnode;
    RegNode*    subnode;
    char*       string;
    const char* constString;
    unsigned    uint;
    int         boolean;
    timestampt  time;
    signaturet  defSig1 = {0};
    signaturet  defSig2 = {1};
    signaturet  sig;

    status = reg_getNode("/test_node/subnode", &subnode, 1);
    if (status) {
        log_error("test_regNode(): Couldn't get subnode");
    }
    else {
        CU_ASSERT_EQUAL_FATAL(status, 0);
        CU_ASSERT_PTR_NOT_NULL(subnode);
    }

    constString = reg_getNodeName(subnode);
    CU_ASSERT_STRING_EQUAL(constString, "subnode");

    constString = reg_getNodeAbsPath(subnode);
    CU_ASSERT_STRING_EQUAL(constString, "/test_node/subnode");

    status = reg_getNodeString(subnode, "string_key", &string);
    if (status && ENOENT != status) {
        log_error("test_regNode(): Couldn't verify non-existant subnode string");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_putNodeString(subnode, "string_key", "string value");
    if (0 != status) {
        log_error("test_regNode(): Couldn't add subnode string");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

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

    status = reg_getNodeBool(subnode, "bool_key", &boolean);
    if (status && ENOENT != status) {
        log_error("test_regNode(): Couldn't verify non-existant subnode boolean");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_putNodeBool(subnode, "bool_key", 1);
    if (0 != status) {
        log_error("test_regNode(): Couldn't put subnode boolean");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getNodeBool(subnode, "bool_key", &boolean);
    if (status) {
        log_error("test_regNode(): Couldn't get subnode boolean");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_EQUAL(boolean, 1);
    }

    status = reg_getNodeUint(subnode, "uint_key", &uint);
    if (status && ENOENT != status) {
        log_error("test_regNode(): Couldn't verify non-existant subnode int");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_putNodeUint(subnode, "uint_key", 5);
    if (0 != status) {
        log_error("test_regNode(): Couldn't put subnode int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getNodeUint(subnode, "uint_key", &uint);
    if (status) {
        log_error("test_regNode(): Couldn't get subnode int");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_EQUAL(uint, 5);
    }

    status = reg_getNodeTime(subnode, "time_key", &time);
    if (status && ENOENT != status) {
        log_error("test_regNode(): Couldn't verify non-existant subnode time");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_putNodeTime(subnode, "time_key", &TS_ZERO);
    if (0 != status) {
        log_error("test_regNode(): Couldn't put subnode time");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getNodeTime(subnode, "time_key", &time);
    if (status) {
        log_error("test_regNode(): Couldn't get subnode time");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_EQUAL(d_diff_timestamp(&time, &TS_ZERO), 0.0);
    }

    status = reg_getNodeSignature(subnode, "sig_key", &sig);
    if (status && ENOENT != status) {
        log_error("test_regNode(): Couldn't verify non-existant subnode sig");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_putNodeSignature(subnode, "sig_key", defSig2);
    if (0 != status) {
        log_error("test_regNode(): Couldn't put subnode sig");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getNodeSignature(subnode, "sig_key", &sig);
    if (status) {
        log_error("test_regNode(): Couldn't get subnode sig");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
        CU_ASSERT_EQUAL(memcmp(sig, defSig2, sizeof(signaturet)), 0);
    }

    status = reg_deleteNodeValue(subnode, "non-existant_key");
    if (status && ENOENT != status) {
        log_error("test_regNode(): Couldn't verify non-existant subnode value deletion");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_deleteNodeValue(subnode, "string_key");
    if (status) {
        log_error("test_regNode(): Couldn't delete subnode value");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    status = reg_getNodeString(subnode, "string_key", &string);
    if (status && ENOENT != status) {
        log_error("test_regNode(): Couldn't verify non-existant subnode string");
    }
    else {
        CU_ASSERT_EQUAL(status, ENOENT);
    }

    status = reg_getNode("/test_node", &testnode, 1);
    if (status) {
        log_error("test_regNode(): Couldn't get subnode");
    }
    else {
        CU_ASSERT_EQUAL_FATAL(status, 0);
        CU_ASSERT_PTR_NOT_NULL(testnode);
    }

    status = reg_flushNode(testnode);
    if (status) {
        log_error("test_regNode(): Couldn't flush node");
    }
    else {
        CU_ASSERT_EQUAL(status, 0);
    }

    rn_free(testnode);

    {
        status = reg_getNode("/test_node2", &testnode, 1);
        if (status) {
            log_error("test_regNode(): Couldn't get temporary node");
        }
        else {
            CU_ASSERT_EQUAL_FATAL(status, 0);
            CU_ASSERT_PTR_NOT_NULL(testnode);
        }

        status = reg_putNodeString(testnode, "string_key", "string value");
        if (0 != status) {
            log_error("test_regNode(): Couldn't add temporary node string");
        }
        else {
            CU_ASSERT_EQUAL(status, 0);
        }

        status = reg_flushNode(testnode);
        if (status) {
            log_error("test_regNode(): Couldn't flush temporary node");
        }
        else {
            CU_ASSERT_EQUAL(status, 0);
        }

        reg_deleteNode(testnode);

        status = reg_flushNode(testnode);
        if (status) {
            log_error("test_regNode(): Couldn't delete temporary node");
        }
        else {
            CU_ASSERT_EQUAL(status, 0);
        }

        rn_free(testnode);

        status = reg_getNode("/test_node2", &testnode, 0);
        if (status && ENOENT != status) {
            log_error("test_regNode(): Couldn't verify temporary node deletion");
        }
        else {
            CU_ASSERT_EQUAL(status, ENOENT);
        }
    }
}