/usr/src/suites/os/smf/tests/libscf-low/templates/scf_tmpl_value_name_constraint/scf_tmpl_value_name_constraint_009.c
C | 178 lines | 112 code | 22 blank | 44 comment | 24 complexity | 8b05ed900519a506714c50c97e04b078 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
- /*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
- /*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
- #pragma ident "%Z%%M% %I% %E% SMI"
- #ifdef __stc_assertion__
- /*
- * ASSERTION: scf_tmpl_value_name_constraint_009
- *
- * DESCRIPTION:
- * scf_tmpl_value_name_constraint gets the correct error
- * from a property pattern that has no constraints
- *
- * STRATEGY:
- * 1. Get the property group
- * 2. Get the preoprty pattern
- * 3. Get the constraint values
- * 4. Verify the set of constraints against the
- * expected set
- *
- * INTERFACES: scf_tmpl_value_name_constraint
- *
- */
- #endif /* __stc_assertion__ */
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
- #include <errno.h>
- #include <libscf.h>
- #include <libscftest-tmpl.h>
- int
- main()
- {
- scf_error_t exp_scf_err;
- scf_values_t names;
- scf_prop_tmpl_t *p;
- scf_pg_tmpl_t *t = NULL;
- scf_handle_t *h = NULL;
- char *instance_fmri = NULL;
- char *property_group = "foobar";
- char *property = "foobar_prop";
- int result = PASS;
- char **c;
- int i;
- instance_fmri = SCFTEST_TEMPLATES_INST;
- (void) fprintf(stdout, "\n--ASRT: "
- "scf_tmpl_value_name_constraint gets the correct error\n"
- "from a property pattern that has no constraints\n"
- "\tINTERFACES: scf_tmpl_value_name_constraint()\n");
- /* Create a connection handle; do not bind it to the repository */
- if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
- result = UNRESOLVED;
- (void) fprintf(stdout, "--DIAG: "
- "scf_handle_create() failed\n\t"
- "EXPECTED: handle != NULL, no error\n\t"
- "RETURNED: handle == NULL, %s\n",
- scf_strerror(scf_error()));
- goto out;
- } /* scf_handle_create() */
- /* Bind the handle to the repository */
- if (scf_handle_bind(h) != 0) {
- result = UNRESOLVED;
- (void) fprintf(stdout, "--DIAG: "
- "Error connecting handle to repository: "
- "scf_handle_bind() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- goto out;
- }
- if ((t = scf_tmpl_pg_create(h)) == NULL) {
- result = UNRESOLVED;
- (void) fprintf(stdout, "--DIAG: "
- "Error creating property group template: "
- "scf_tmpl_pg_create() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- goto out;
- }
- /* VERIFY ASSERTION */
- exp_scf_err = SCF_ERROR_NONE;
- if (scftest_tmpl_get_by_pg_name(instance_fmri, NULL, property_group,
- NULL, t, 0, &exp_scf_err) == -1 || exp_scf_err != PASS) {
- result = UNRESOLVED;
- (void) fprintf(stdout, "--DIAG: scf_tmpl_get_by_pg_name() "
- "failed to get the property group."
- "RETURNED: %s\n", scf_strerror(scf_error()));
- goto out;
- }
- if ((p = scf_tmpl_prop_create(h)) == NULL) {
- result = UNRESOLVED;
- (void) fprintf(stdout, "--DIAG: "
- "Error creating property pattern : "
- "scf_tmpl_prop_create() failed\n\t"
- "EXPECTED: no error\n\t"
- "RETURNED: %s\n",
- scf_strerror(scf_error()));
- goto out;
- }
- exp_scf_err = SCF_ERROR_NONE;
- if (scftest_tmpl_get_by_prop(t, property, p, 0,
- &exp_scf_err) == -1 || exp_scf_err != PASS) {
- result = UNRESOLVED;
- (void) fprintf(stdout, "--DIAG: scf_tmpl_get_by_prop() failed "
- "to get the property group\n"
- "RETURNED: %s\n", scf_strerror(scf_error()));
- goto out;
- } else {
- (void) fprintf(stdout, "--INFO: scf_tmpl_get_by_prop() "
- "successfully got a property group template for %s\n",
- instance_fmri);
- }
- exp_scf_err = SCF_ERROR_NOT_FOUND;
- if (scftest_tmpl_value_name_constraints(p, &names,
- &exp_scf_err) == -1) {
- if (names.values.v_astring) {
- (void) fprintf(stdout, "--DIAG: "
- "Got the following names from "
- "scf_tmpl_value_name_constraint()\n");
- i = 0;
- c = names.values.v_astring;
- while (c[i] != NULL) {
- (void) fprintf(stdout, "\t%s\n", c[i]);
- i++;
- }
- }
- }
- out:
- if (t)
- scf_tmpl_pg_destroy(t);
- if (h)
- scf_handle_destroy(h);
- (void) fprintf(stdout, "--RSLT: %s\n\n", result_tbl[result]);
- return (result);
- }