tests/immsv/common/immtest.c | 60 +- tests/immsv/implementer/Makefile.am | 1 + tests/immsv/implementer/applier.c | 24 +- tests/immsv/implementer/test_cleanup.c | 38 +- tests/immsv/implementer/test_saImmOiLongDn.c | 621 +++++++++++++++++ tests/immsv/implementer/test_saImmOiRtObjectCreate_2.c | 10 +- tests/immsv/management/Makefile.am | 1 + tests/immsv/management/test_cleanup.c | 38 +- tests/immsv/management/test_saImmOmLongDn.c | 368 ++++++++++ 9 files changed, 1113 insertions(+), 48 deletions(-)
New test cases have been added to immomtest and immoitest. If SA_ENABLE_EXTENDED_NAMES is not set, immomtest and immoitest can use --longDn parameter to set SA_ENABLE_EXTENDED_NAMES for testing. Option -h and --help have been added to show the usage of immomtest and immoitest diff --git a/tests/immsv/common/immtest.c b/tests/immsv/common/immtest.c --- a/tests/immsv/common/immtest.c +++ b/tests/immsv/common/immtest.c @@ -16,6 +16,7 @@ */ #include <stdlib.h> +#include <libgen.h> #include <sys/time.h> #include <unistd.h> #include <pthread.h> @@ -43,21 +44,59 @@ const SaNameT rootObj = { void (*test_setup)(void) = NULL; void (*test_cleanup)(void) = NULL; +void usage(const char *progname) { + printf("Usage: %s [-h] [--help] [--longDn] [suite [testcase]]\n\n", progname); + printf("OPTIONS:\n"); + printf("\t-h, --help this help\n"); + printf("\t--longDn enable extended names support\n"); + printf("\tsuite suite for testing. 0 for listing all tests\n"); + printf("\ttestcase test case for testing in specific suite\n"); +} + int main(int argc, char **argv) { int suite = ALL_SUITES, tcase = ALL_TESTS; int rc = 0; + int i; + int index = 0; + int longDn = 0; + int failed = 0; + char *endptr; srandom(getpid()); - if (argc > 1) - { - suite = atoi(argv[1]); + for(i=1; i<argc; i++) { + if(!strcmp(argv[i], "--longDn")) { + longDn = 1; + } else if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + usage(basename(argv[0])); + return 0; + } else if(index == 0) { + suite = strtol(argv[i], &endptr, 10); + if(endptr && *endptr) { + failed = 1; + } else { + index++; + } + } else if(index == 1) { + tcase = strtol(argv[i], &endptr, 10); + if(endptr && *endptr) { + failed = 1; + } else { + index++; + } + } else { + failed = 1; + } + + if(failed) { + fprintf(stderr, "Try '%s --help' for more information\n", argv[0]); + return EXIT_FAILURE; + } } - if (argc > 2) - { - tcase = atoi(argv[2]); + if(longDn) { + setenv("SA_ENABLE_EXTENDED_NAMES", "1", 1); } if(test_setup) @@ -111,7 +150,10 @@ SaAisErrorT config_class_create(SaImmHan SaImmAttrDefinitionT_2 attr7 = { "attr7", SA_IMM_ATTR_SAANYT, SA_IMM_ATTR_CONFIG | SA_IMM_ATTR_WRITABLE | SA_IMM_ATTR_MULTI_VALUE | SA_IMM_ATTR_NO_DUPLICATES, NULL}; - const SaImmAttrDefinitionT_2* attributes[] = {&rdn, &attr1, &attr2, &attr3, &attr4, &attr5, &attr6, &attr7, NULL}; + SaImmAttrDefinitionT_2 attr8 = { + "attr8", SA_IMM_ATTR_SANAMET, SA_IMM_ATTR_CONFIG | SA_IMM_ATTR_WRITABLE, NULL}; + + const SaImmAttrDefinitionT_2* attributes[] = {&rdn, &attr1, &attr2, &attr3, &attr4, &attr5, &attr6, &attr7, &attr8, NULL}; err = saImmOmClassCreate_2(immHandle, configClassName, SA_IMM_CLASS_CONFIG, attributes); @@ -142,8 +184,10 @@ SaAisErrorT runtime_class_create(SaImmHa SaImmAttrDefinitionT_2 attr1 = { "attr1", SA_IMM_ATTR_SAUINT32T, SA_IMM_ATTR_RUNTIME, NULL}; + SaImmAttrDefinitionT_2 attr2 = { + "attr2", SA_IMM_ATTR_SANAMET, SA_IMM_ATTR_RUNTIME, NULL}; - const SaImmAttrDefinitionT_2* attributes[] = {&rdn, &attr1, NULL}; + const SaImmAttrDefinitionT_2* attributes[] = {&rdn, &attr1, &attr2, NULL}; return saImmOmClassCreate_2(immHandle, runtimeClassName, SA_IMM_CLASS_RUNTIME, attributes); diff --git a/tests/immsv/implementer/Makefile.am b/tests/immsv/implementer/Makefile.am --- a/tests/immsv/implementer/Makefile.am +++ b/tests/immsv/implementer/Makefile.am @@ -44,6 +44,7 @@ immoitest_SOURCES = \ test_SaImmOiCcb.c \ test_SaImmOiAdminOperation.c \ test_saImmOiAugmentCcbInitialize.c \ + test_saImmOiLongDn.c \ test_cleanup.c immoitest_LDADD = \ diff --git a/tests/immsv/implementer/applier.c b/tests/immsv/implementer/applier.c --- a/tests/immsv/implementer/applier.c +++ b/tests/immsv/implementer/applier.c @@ -41,6 +41,9 @@ #include <immutil.h> #include "saf_error.h" #include <poll.h> + +#include "osaf_extended_name.h" + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -74,7 +77,7 @@ static SaAisErrorT saImmOiCcbObjectModif const SaNameT *objectName, const SaImmAttrModificationT_2 **attrMods) { SaAisErrorT rc = SA_AIS_OK; - printf("Modify callback on %s - object:%s ccbId:%llu\n", implName, objectName->value, ccbId); + printf("Modify callback on %s - object:%s ccbId:%llu\n", implName, osaf_extended_name_borrow(objectName), ccbId); struct CcbUtilCcbData *ccbUtilCcbData; if ((ccbUtilCcbData = ccbutil_findCcbData(ccbId)) == NULL) { @@ -100,7 +103,7 @@ static SaAisErrorT saImmOiCcbObjectCreat SaAisErrorT rc = SA_AIS_OK; struct CcbUtilCcbData *ccbUtilCcbData; - printf("Create callback on %s - parent:%s ccbId:%llu\n", implName, parentName->value, ccbId); + printf("Create callback on %s - parent:%s ccbId:%llu\n", implName, osaf_extended_name_borrow(parentName), ccbId); if ((ccbUtilCcbData = ccbutil_findCcbData(ccbId)) == NULL) { if ((ccbUtilCcbData = ccbutil_getCcbData(ccbId)) == NULL) { @@ -120,7 +123,7 @@ static SaAisErrorT saImmOiCcbObjectDelet { SaAisErrorT rc = SA_AIS_OK; struct CcbUtilCcbData *ccbUtilCcbData; - printf("Delete callback on %s - object:%s ccbId:%llu\n", implName, objectName->value, ccbId); + printf("Delete callback on %s - object:%s ccbId:%llu\n", implName, osaf_extended_name_borrow(objectName), ccbId); if ((ccbUtilCcbData = ccbutil_findCcbData(ccbId)) == NULL) { if ((ccbUtilCcbData = ccbutil_getCcbData(ccbId)) == NULL) { @@ -187,7 +190,7 @@ static void saImmOiAdminOperationCallbac const SaImmAdminOperationParamsT_2 **params) { printf("AdminOperationCallback received by impl %s on object %s operation:%llu invocation:%llu\n", - implName, (char *) objectName->value, operationId, invocation); + implName, (char *) osaf_extended_name_borrow(objectName), operationId, invocation); SaAisErrorT err = saImmOiAdminOperationResult(immOiHandle, invocation, SA_AIS_OK); if(err != SA_AIS_OK) { fprintf(stderr, "Reply on admin operation failed, err:%u\n", err); @@ -273,12 +276,13 @@ int main(int argc, char *argv[]) /* Remaining arguments should be class names for which implementer is set. */ while (optind < argc) { - strncpy((char *)objectName.value, argv[optind], SA_MAX_NAME_LENGTH); - objectName.length = strlen((char *)objectName.value); + osaf_extended_name_alloc(argv[optind], &objectName); +// strncpy((char *)objectName.value, argv[optind], SA_MAX_NAME_LENGTH); +// objectName.length = strlen((char *)objectName.value); - printf("Class: %s\n", objectName.value); + printf("Class: %s\n", osaf_extended_name_borrow(&objectName)); - if(!strcmp((const char *) objectName.value, "OpensafImmRtTest")) { + if(!strcmp((const char *) osaf_extended_name_borrow(&objectName), "OpensafImmRtTest")) { /* Special test case for RTO's. Class OpensafImmRtTest foundd at samples/immsv/immsv_test_classes_rtobj.xml */ @@ -287,7 +291,7 @@ int main(int argc, char *argv[]) SaImmAttrValuesT_2 v1 = { "testRdn", SA_IMM_ATTR_SASTRINGT, 1, (void**)strValues }; const SaImmAttrValuesT_2* attrValues[] = {&v1, NULL}; - error = saImmOiRtObjectCreate_2(immOiHandle, (SaImmClassNameT) objectName.value, NULL, attrValues); + error = saImmOiRtObjectCreate_2(immOiHandle, (SaImmClassNameT) osaf_extended_name_borrow(&objectName), NULL, attrValues); if (error != SA_AIS_OK && error != SA_AIS_ERR_EXIST) { fprintf(stderr, "error - saImmOiClassImplementerSet FAILED: %s\n", saf_error(error)); exit(EXIT_FAILURE); @@ -298,7 +302,7 @@ int main(int argc, char *argv[]) printf("Runtime object: %s exists\n", str1); } } else { - error = saImmOiClassImplementerSet(immOiHandle, (SaImmClassNameT) objectName.value); + error = saImmOiClassImplementerSet(immOiHandle, (SaImmClassNameT) osaf_extended_name_borrow(&objectName)); if (error != SA_AIS_OK) { fprintf(stderr, "error - saImmOiClassImplementerSet FAILED: %s\n", saf_error(error)); exit(EXIT_FAILURE); diff --git a/tests/immsv/implementer/test_cleanup.c b/tests/immsv/implementer/test_cleanup.c --- a/tests/immsv/implementer/test_cleanup.c +++ b/tests/immsv/implementer/test_cleanup.c @@ -16,6 +16,7 @@ */ #include "immtest.h" +#include "osaf_extended_name.h" static char *objects[] = { @@ -31,6 +32,7 @@ static char *objects[] = { "123456789012345678901234567890123456789012345678901234567890123,123456789012345678901234567890123456789012345678901234567890123,123456789012345678901234567890123456789012345678901234567890123,rdn=root", "Test,rdn=root", "rdn=root", + "longdn=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", NULL }; @@ -41,6 +43,7 @@ static char *classes[] = { NULL }; +extern void addOiLongDnTestCases(); static void cleanup() { SaVersionT version = { 'A', 2, 11 }; @@ -64,26 +67,25 @@ static void cleanup() { assert(rc == SA_AIS_OK); /* Delete objects */ - int len; SaNameT objectName = {0}; SaNameT *objectNames[2] = { &objectName, NULL }; obj = objects; while(*obj) { - len = strlen(*obj); - objectName.length = (len > SA_MAX_NAME_LENGTH) ? SA_MAX_NAME_LENGTH : len; - strncpy((char *)objectName.value, *obj, objectName.length); + if(osaf_is_extended_names_enabled() || strlen(*obj) < SA_MAX_NAME_LENGTH) { + osaf_extended_name_lend(*obj, &objectName); - rc = saImmOmAdminOwnerSet(ownerHandle, (const SaNameT **)objectNames, SA_IMM_ONE); - if(rc == SA_AIS_ERR_NOT_EXIST) { - obj++; - continue; + rc = saImmOmAdminOwnerSet(ownerHandle, (const SaNameT **)objectNames, SA_IMM_ONE); + if(rc == SA_AIS_ERR_NOT_EXIST) { + obj++; + continue; + } + assert(rc == SA_AIS_OK); + + rc = saImmOmCcbObjectDelete(ccbHandle, &objectName); + if(rc != SA_AIS_OK && rc != SA_AIS_ERR_NOT_EXIST) + fprintf(stderr, "Failed to delete object '%s' with error code: %d\n", *obj, rc); + assert(rc == SA_AIS_OK || rc == SA_AIS_ERR_NOT_EXIST); } - assert(rc == SA_AIS_OK); - - rc = saImmOmCcbObjectDelete(ccbHandle, &objectName); - if(rc != SA_AIS_OK && rc != SA_AIS_ERR_NOT_EXIST) - fprintf(stderr, "Failed to delete object '%s' with error code: %d\n", *obj, rc); - assert(rc == SA_AIS_OK || rc == SA_AIS_ERR_NOT_EXIST); obj++; } @@ -132,6 +134,14 @@ static void startup() { safassert(object_create(immOmHandle, ownerHandle, configClassName, &rootObj, NULL, NULL), SA_AIS_OK); safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); + + /* Add long DN test cases */ + char *env; + if((env = getenv("SA_ENABLE_EXTENDED_NAMES"))) { + if(!strcmp(env, "1")) { + addOiLongDnTestCases(); + } + } } __attribute__ ((constructor)) static void cleanup_constructor(void) diff --git a/tests/immsv/implementer/test_saImmOiLongDn.c b/tests/immsv/implementer/test_saImmOiLongDn.c new file mode 100644 --- /dev/null +++ b/tests/immsv/implementer/test_saImmOiLongDn.c @@ -0,0 +1,621 @@ +/* -*- OpenSAF -*- + * + * (C) Copyright 2014 The OpenSAF Foundation + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed + * under the GNU Lesser General Public License Version 2.1, February 1999. + * The complete license can be accessed from the following location: + * http://opensource.org/licenses/lgpl-license.php + * See the Copying file included with the OpenSAF distribution for full + * licensing terms. + * + * Author(s): Ericsson AB + * + */ + + +#include <unistd.h> +#include <pthread.h> +#include <poll.h> + +#include "immtest.h" +#include "osaf_extended_name.h" + + +static char *longDn = "longdn=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"; +static char *longDn2 = "longdn=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"; + + +static void setupOiLongDn(void) { + SaImmHandleT immHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmCcbHandleT ccbHandle; + SaNameT dn; + const SaImmAdminOwnerNameT ownerName = (const SaImmAdminOwnerNameT)__FUNCTION__; + + SaImmAttrValueT attrValues[1] = { &dn }; + SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, + { "attr8", SA_IMM_ATTR_SANAMET, 1, attrValues }}; + const SaImmAttrModificationT_2 *attrMods[2] = { &attrMod, NULL }; + + osaf_extended_name_lend(longDn, &dn); + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + config_class_create(immHandle); + safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + safassert(object_create(immHandle, ownerHandle, configClassName, &dn, NULL, NULL), SA_AIS_OK); + + // Change SaNameT attribute for testing + safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); + safassert(saImmOmCcbObjectModify_2(ccbHandle, &dn, attrMods), SA_AIS_OK); + safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK); + safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); +} + +static void cleanOiLongDn(void) { + SaImmHandleT immHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaNameT dn; + const SaNameT *objects[2] = { &dn, NULL }; + const SaImmAdminOwnerNameT ownerName = (const SaImmAdminOwnerNameT)__FUNCTION__; + + osaf_extended_name_lend(longDn, &dn); + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + saImmOmAdminOwnerSet(ownerHandle, objects, SA_IMM_ONE); + + object_delete(ownerHandle, &dn, 0); + config_class_delete(immHandle); + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); +} + + +static void saImmOiAdminOperationCallback(SaImmOiHandleT immOiHandle, + SaInvocationT invocation, + const SaNameT *objectName, + SaImmAdminOperationIdT operationId, + const SaImmAdminOperationParamsT_2 **params) { + + if(params && params[0] && !strcmp(params[0]->paramName, "attr8")) { + SaNameT *val = (SaNameT *)params[0]->paramBuffer; + if(!strcmp(osaf_extended_name_borrow(val), longDn2)) { + // Return input parameters + saImmOiAdminOperationResult_o2(immOiHandle, invocation, SA_AIS_OK, params); + return; + } + } + + saImmOiAdminOperationResult_o2(immOiHandle, invocation, SA_AIS_ERR_BAD_OPERATION, NULL); +} + +static void saImmOiCcbAbortCallback(SaImmOiHandleT immOiHandle, SaImmOiCcbIdT ccbId) { +} + +static void saImmOiCcbApplyCallback(SaImmOiHandleT immOiHandle, SaImmOiCcbIdT ccbId) { +} + +static SaAisErrorT saImmOiCcbCompletedCallback(SaImmOiHandleT immOiHandle, SaImmOiCcbIdT ccbId) { + return SA_AIS_OK; +} + +static SaAisErrorT saImmOiCcbObjectCreateCallback(SaImmOiHandleT immOiHandle, + SaImmOiCcbIdT ccbId, + const SaImmClassNameT className, + const SaNameT *parentName, const SaImmAttrValuesT_2 **attr) { + return SA_AIS_OK; +} + +static SaAisErrorT saImmOiCcbObjectDeleteCallback(SaImmOiHandleT immOiHandle, SaImmOiCcbIdT ccbId, const SaNameT *objectName) { + return SA_AIS_OK; +} + +static SaAisErrorT saImmOiCcbObjectModifyCallback(SaImmOiHandleT immOiHandle, SaImmOiCcbIdT ccbId, const SaNameT *objectName, const SaImmAttrModificationT_2 **attrMods) { + return SA_AIS_OK; +} + +static SaAisErrorT saImmOiRtAttrUpdateCallback(SaImmOiHandleT immOiHandle, const SaNameT *objectName, const SaImmAttrNameT *attributeNames) { + SaNameT val; + SaImmAttrValueT attrValues[1] = { &val }; + SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, + { "attr2", SA_IMM_ATTR_SANAMET, 1, attrValues }}; + const SaImmAttrModificationT_2 *attrMods[2] = { &attrMod, NULL }; + + if(osaf_extended_name_length(objectName) == strlen(longDn) + && !strncmp(osaf_extended_name_borrow(objectName), longDn, strlen(longDn2))) { + osaf_extended_name_lend(longDn2, &val); + saImmOiRtObjectUpdate_2(immOiHandle, objectName, attrMods); + return SA_AIS_OK; + } + + return SA_AIS_ERR_FAILED_OPERATION; +} + +static SaImmOiCallbacksT_2 localImmOiCallbacks = { + saImmOiAdminOperationCallback, + saImmOiCcbAbortCallback, + saImmOiCcbApplyCallback, + saImmOiCcbCompletedCallback, + saImmOiCcbObjectCreateCallback, + saImmOiCcbObjectDeleteCallback, + saImmOiCcbObjectModifyCallback, + saImmOiRtAttrUpdateCallback, +}; + +enum { + S_DISP_START = 0, + S_DISP_READY, + S_DISP_FINISH +}; + +// -1 for infinite loop, exit with setting s_dispatch_exit = 0 +static int s_dispatch_repeat = 0; +static int s_dispatch_exit = 0; +static int s_dispatch_status = 0; +static SaImmOiHandleT s_dispatch_oi_handle = 0; + +static void *dispatchThread(void *param) { + SaImmOiHandleT oiHandle = s_dispatch_oi_handle; + SaSelectionObjectT selObj; + int repeat = s_dispatch_repeat ? s_dispatch_repeat : -1; + int waittime = (repeat == -1) ? 10 : -1; + int rc; + struct pollfd fd; + + safassert(saImmOiSelectionObjectGet(oiHandle, &selObj), SA_AIS_OK); + + s_dispatch_status = S_DISP_READY; + + while(repeat) { + fd.fd = selObj; + fd.events = POLLIN; + rc = poll(&fd, 1, waittime); + if(!rc) { + if(s_dispatch_exit) + repeat = 0; + continue; + } + assert(rc != -1); + + saImmOiDispatch(oiHandle, SA_DISPATCH_ONE); + + if(repeat > 0) { + repeat--; + } else if(s_dispatch_exit) { + // Exit from loop + repeat = 0; + } + } + + s_dispatch_status = S_DISP_FINISH; + + return NULL; +} + +static void saImmOiLongDn_01(void) { + SaAisErrorT rc; + SaImmOiHandleT immOiHandle; + SaImmHandleT immOmHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmCcbHandleT ccbHandle; + SaImmAdminOwnerNameT ownerName = (SaImmAdminOwnerNameT)__FUNCTION__; + const SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT)__FILE__; + pthread_t threadid; + + SaNameT dn; + SaImmAttrValueT rdnVal[1] = { (SaImmAttrValueT)&dn }; + SaImmAttrValuesT_2 attrValue = { "rdn", SA_IMM_ATTR_SANAMET, 1, rdnVal }; + const SaImmAttrValuesT_2 *attrValues[2] = { &attrValue, NULL }; + + osaf_extended_name_lend(longDn, &dn); + + safassert(saImmOiInitialize_2(&immOiHandle, &localImmOiCallbacks, &immVersion), SA_AIS_OK); + safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); + + s_dispatch_repeat = 0; + s_dispatch_oi_handle = immOiHandle; + s_dispatch_exit = 0; + s_dispatch_status = 0; + assert(pthread_create(&threadid, NULL, dispatchThread, NULL) == 0); + + while(s_dispatch_status != S_DISP_READY) { + usleep(100); + } + + safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK); + config_class_create(immOmHandle); + + safassert(saImmOiClassImplementerSet(immOiHandle, configClassName), SA_AIS_OK); + + safassert(saImmOmAdminOwnerInitialize(immOmHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); + + rc = saImmOmCcbObjectCreate_2(ccbHandle, configClassName, NULL, attrValues); + + safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + + safassert(saImmOiClassImplementerRelease(immOiHandle, configClassName), SA_AIS_OK); + + // Wait for thread to exit + s_dispatch_exit = 1; + while(s_dispatch_status != S_DISP_FINISH) { + usleep(100); + } + + safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); + + config_class_delete(immOmHandle); + safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); +} + +static void saImmOiLongDn_02(void) { + SaAisErrorT rc; + SaImmOiHandleT immOiHandle; + SaImmHandleT immOmHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmCcbHandleT ccbHandle; + SaImmAdminOwnerNameT ownerName = (SaImmAdminOwnerNameT)__FUNCTION__; + const SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT)__FILE__; + pthread_t threadid; + SaNameT dn; + SaNameT val; + const SaNameT *objects[2] = { &dn, NULL }; + + SaImmAttrValueT attrValues[1] = { &val }; + SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, + { "attr8", SA_IMM_ATTR_SANAMET, 1, attrValues }}; + const SaImmAttrModificationT_2 *attrMods[2] = { &attrMod, NULL }; + + osaf_extended_name_lend(longDn, &dn); + osaf_extended_name_lend(longDn2, &val); + + setupOiLongDn(); + + safassert(saImmOiInitialize_2(&immOiHandle, &localImmOiCallbacks, &immVersion), SA_AIS_OK); + safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); + safassert(saImmOiClassImplementerSet(immOiHandle, configClassName), SA_AIS_OK); + + s_dispatch_repeat = 0; + s_dispatch_oi_handle = immOiHandle; + s_dispatch_exit = 0; + s_dispatch_status = 0; + pthread_create(&threadid, NULL, dispatchThread, NULL); + + while(s_dispatch_status != S_DISP_READY) { + usleep(100); + } + + safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK); + safassert(saImmOmAdminOwnerInitialize(immOmHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + safassert(saImmOmAdminOwnerSet(ownerHandle, objects, SA_IMM_ONE), SA_AIS_OK); + safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); + + rc = saImmOmCcbObjectModify_2(ccbHandle, &dn, attrMods); + + safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK); + safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); + + safassert(saImmOiClassImplementerRelease(immOiHandle, configClassName), SA_AIS_OK); + + // Wait for thread to exit + s_dispatch_exit = 1; + while(s_dispatch_status != S_DISP_FINISH) { + usleep(100); + } + + safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); + + cleanOiLongDn(); +} + +static void saImmOiLongDn_03(void) { + SaAisErrorT rc; + SaImmOiHandleT immOiHandle; + SaImmHandleT immOmHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmCcbHandleT ccbHandle; + SaImmAdminOwnerNameT ownerName = (SaImmAdminOwnerNameT)__FUNCTION__; + const SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT)__FILE__; + pthread_t threadid; + SaNameT dn; + const SaNameT *objects[2] = { &dn, NULL }; + + osaf_extended_name_lend(longDn, &dn); + + setupOiLongDn(); + + safassert(saImmOiInitialize_2(&immOiHandle, &localImmOiCallbacks, &immVersion), SA_AIS_OK); + safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); + safassert(saImmOiClassImplementerSet(immOiHandle, configClassName), SA_AIS_OK); + + s_dispatch_repeat = 0; + s_dispatch_oi_handle = immOiHandle; + s_dispatch_exit = 0; + s_dispatch_status = 0; + pthread_create(&threadid, NULL, dispatchThread, NULL); + + while(s_dispatch_status != S_DISP_READY) { + usleep(100); + } + + safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK); + safassert(saImmOmAdminOwnerInitialize(immOmHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + safassert(saImmOmAdminOwnerSet(ownerHandle, objects, SA_IMM_ONE), SA_AIS_OK); + safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); + + rc = saImmOmCcbObjectDelete(ccbHandle, &dn); + + safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK); + safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); + + safassert(saImmOiClassImplementerRelease(immOiHandle, configClassName), SA_AIS_OK); + + // Wait for thread to exit + s_dispatch_exit = 1; + while(s_dispatch_status != S_DISP_FINISH) { + usleep(100); + } + + safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); + + cleanOiLongDn(); +} + +static void saImmOiLongDn_04(void) { + SaAisErrorT rc, rc1; + SaImmOiHandleT immOiHandle; + SaImmHandleT immOmHandle; + const SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT)__FILE__; + pthread_t threadid; + + SaNameT dn; + SaImmAttrValueT rdnVal[1] = { (SaImmAttrValueT)&dn }; + SaImmAttrValuesT_2 attrValue = { "rdn", SA_IMM_ATTR_SANAMET, 1, rdnVal }; + const SaImmAttrValuesT_2 *attrValues[2] = { &attrValue, NULL }; + + osaf_extended_name_lend(longDn, &dn); + + safassert(saImmOiInitialize_2(&immOiHandle, &localImmOiCallbacks, &immVersion), SA_AIS_OK); + safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); + + s_dispatch_repeat = 0; + s_dispatch_oi_handle = immOiHandle; + s_dispatch_exit = 0; + s_dispatch_status = 0; + pthread_create(&threadid, NULL, dispatchThread, NULL); + + while(s_dispatch_status != S_DISP_READY) { + usleep(100); + } + + safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK); + runtime_class_create(immOmHandle); + + rc = saImmOiRtObjectCreate_2(immOiHandle, runtimeClassName, NULL, attrValues); + rc1 = saImmOiRtObjectDelete(immOiHandle, &dn); + + if(rc == SA_AIS_OK) { + rc = rc1; + } + + runtime_class_delete(immOmHandle); + safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); + + // Wait for thread to exit + s_dispatch_exit = 1; + while(s_dispatch_status != S_DISP_FINISH) { + usleep(100); + } + + safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); +} + +static void saImmOiLongDn_05(void) { + SaAisErrorT rc; + SaImmOiHandleT immOiHandle; + SaImmHandleT immOmHandle; + SaImmAccessorHandleT accessorHandle; + const SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT)__FILE__; + pthread_t threadid; + SaImmAttrValuesT_2 **attributes = NULL; + + SaNameT dn; + SaImmAttrValueT rdnVal[1] = { (SaImmAttrValueT)&dn }; + SaImmAttrValuesT_2 attrValue = { "rdn", SA_IMM_ATTR_SANAMET, 1, rdnVal }; + const SaImmAttrValuesT_2 *attrValues[2] = { &attrValue, NULL }; + + osaf_extended_name_lend(longDn, &dn); + + safassert(saImmOiInitialize_2(&immOiHandle, &localImmOiCallbacks, &immVersion), SA_AIS_OK); + safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); + + s_dispatch_repeat = 0; + s_dispatch_oi_handle = immOiHandle; + s_dispatch_exit = 0; + s_dispatch_status = 0; + pthread_create(&threadid, NULL, dispatchThread, NULL); + + while(s_dispatch_status != S_DISP_READY) { + usleep(100); + } + + safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK); + runtime_class_create(immOmHandle); + safassert(saImmOiRtObjectCreate_2(immOiHandle, runtimeClassName, NULL, attrValues), SA_AIS_OK); + + safassert(saImmOmAccessorInitialize(immOmHandle, &accessorHandle), SA_AIS_OK); + rc = saImmOmAccessorGet_2(accessorHandle, &dn, NULL, &attributes); + if(rc == SA_AIS_OK) { + // Accesor get must return a value. attributes cannot be NULL + assert(attributes); + + SaNameT *val; + int i; + for(i=0; attributes[i]; i++) { + if(!strcmp(attributes[i]->attrName, "attr2")) { + // Must return 1 value + assert(attributes[i]->attrValuesNumber == 1); + assert(attributes[i]->attrValues); + + val = (SaNameT *)attributes[i]->attrValues[0]; + // Check attribute value + assert(osaf_extended_name_length(val) == strlen(longDn2)); + assert(strncmp(osaf_extended_name_borrow(val), longDn2, strlen(longDn2)) == 0); + break; + } + } + + // Updated value was not found in the result list + assert(attributes[i]); + } + + safassert(saImmOiRtObjectDelete(immOiHandle, &dn), SA_AIS_OK); + runtime_class_delete(immOmHandle); + safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); + + // Wait for thread to exit + s_dispatch_exit = 1; + while(s_dispatch_status != S_DISP_FINISH) { + usleep(100); + } + + safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); +} + +static void saImmOiLongDn_06(void) { + SaAisErrorT rc; + SaAisErrorT result; + SaImmOiHandleT immOiHandle; + SaImmHandleT immOmHandle; + SaImmAdminOwnerHandleT ownerHandle; + const SaImmAdminOwnerNameT ownerName = (SaImmAdminOwnerNameT)__FUNCTION__; + const SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT)__FILE__; + pthread_t threadid; + SaNameT dn; + SaNameT val; + const SaNameT *objects[2] = { &dn, NULL }; + SaImmAdminOperationParamsT_2 param = { + "attr8", + SA_IMM_ATTR_SANAMET, + &val + }; + const SaImmAdminOperationParamsT_2 *params[2] = { ¶m, NULL }; + SaImmAdminOperationParamsT_2 **returnParams; + + osaf_extended_name_lend(longDn, &dn); + osaf_extended_name_lend(longDn2, &val); + + setupOiLongDn(); + + safassert(saImmOiInitialize_2(&immOiHandle, &localImmOiCallbacks, &immVersion), SA_AIS_OK); + safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); + safassert(saImmOiClassImplementerSet(immOiHandle, configClassName), SA_AIS_OK); + + s_dispatch_repeat = 0; + s_dispatch_oi_handle = immOiHandle; + s_dispatch_exit = 0; + s_dispatch_status = 0; + pthread_create(&threadid, NULL, dispatchThread, NULL); + + while(s_dispatch_status != S_DISP_READY) { + usleep(100); + } + + safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK); + safassert(saImmOmAdminOwnerInitialize(immOmHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + safassert(saImmOmAdminOwnerSet(ownerHandle, objects, SA_IMM_ONE), SA_AIS_OK); + + rc = saImmOmAdminOperationInvoke_o2(ownerHandle, &dn, 1, 1, params, &result, 10, &returnParams); + + if(rc == SA_AIS_OK) { + assert(returnParams); + assert(returnParams[0]); + assert(!strcmp(returnParams[0]->paramName, "attr8")); + SaNameT *val = (SaNameT *)returnParams[0]->paramBuffer; + assert(!strcmp(osaf_extended_name_borrow(val), longDn2)); + saImmOmAdminOperationMemoryFree(ownerHandle, returnParams); + } + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); + + safassert(saImmOiClassImplementerRelease(immOiHandle, configClassName), SA_AIS_OK); + + // Wait for thread to exit + s_dispatch_exit = 1; + while(s_dispatch_status != S_DISP_FINISH) { + usleep(100); + } + + safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); + + cleanOiLongDn(); +} + +static void saImmOiLongDn_07(void) { + SaAisErrorT rc; + SaImmOiHandleT immOiHandle; + const SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT)__FILE__; + SaNameT dn; + + osaf_extended_name_lend(longDn, &dn); + + setupOiLongDn(); + + safassert(saImmOiInitialize_2(&immOiHandle, &localImmOiCallbacks, &immVersion), SA_AIS_OK); + safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); + + rc = saImmOiObjectImplementerSet(immOiHandle, &dn, SA_IMM_ONE); + if(rc == SA_AIS_OK) { + rc = saImmOiObjectImplementerRelease(immOiHandle, &dn, SA_IMM_ONE); + } + + safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); + + cleanOiLongDn(); +} + +void addOiLongDnTestCases() { + test_case_add(7, saImmOiLongDn_01, "SA_AIS_OK - Object create callback"); + test_case_add(7, saImmOiLongDn_02, "SA_AIS_OK - Object modify callback"); + test_case_add(7, saImmOiLongDn_03, "SA_AIS_OK - Object delete callback"); + test_case_add(7, saImmOiLongDn_04, "SA_AIS_OK - Rt Object create and delete"); + test_case_add(7, saImmOiLongDn_05, "SA_AIS_OK - Rt Object update"); + test_case_add(7, saImmOiLongDn_06, "SA_AIS_OK - Admin operation callback"); + test_case_add(7, saImmOiLongDn_07, "SA_AIS_OK - saImmOiObjectImplementerSet"); +} + +__attribute__ ((constructor)) static void saImmOiLongDn_constructor(void) +{ + test_suite_add(7, "Long DN"); +} diff --git a/tests/immsv/implementer/test_saImmOiRtObjectCreate_2.c b/tests/immsv/implementer/test_saImmOiRtObjectCreate_2.c --- a/tests/immsv/implementer/test_saImmOiRtObjectCreate_2.c +++ b/tests/immsv/implementer/test_saImmOiRtObjectCreate_2.c @@ -16,6 +16,7 @@ */ #include "immtest.h" +#include "osaf_extended_name.h" static const SaNameT rdnObj1 = {sizeof("Obj1"), "Obj1"}; static const SaNameT rdnObj2 = {sizeof("Obj2"), "Obj2"}; @@ -175,7 +176,11 @@ void saImmOiRtObjectCreate_2_07(void) /*Create of fourth rt object should fail. */ rc = saImmOiRtObjectCreate_2(immOiHandle, className, &tmpName, attrValues27);/*299!! (63 + 236)*/ - test_validate(rc, SA_AIS_ERR_NAME_TOO_LONG); + if(!osaf_is_extended_names_enabled()) { + test_validate(rc, SA_AIS_ERR_NAME_TOO_LONG); + } else { + test_validate(rc, SA_AIS_OK); + } /*Tear down*/ @@ -212,7 +217,8 @@ extern void SaImmOiRtAttrUpdateCallbackT test_case_add(3, saImmOiRtObjectCreate_2_04, "saImmOiRtObjectCreate_2 - SA_AIS_ERR_BAD_HANDLE - immOiHandle not associated with implementer name"); test_case_add(3, saImmOiRtObjectCreate_2_05, "saImmOiRtObjectCreate_2 - SA_AIS_ERR_NOT_EXIST - className non existing"); test_case_add(3, saImmOiRtObjectCreate_2_06, "saImmOiRtObjectCreate_2 - SA_AIS_ERR_EXIST - object already created"); - test_case_add(3, saImmOiRtObjectCreate_2_07, "saImmOiRtObjectCreate_2 - SA_AIS_ERR_NAME_TOO_LONG - size of dn for new object too big"); + + test_case_add(3, saImmOiRtObjectCreate_2_07, "saImmOiRtObjectCreate_2 - SA_AIS_ERR_NAME_TOO_LONG - size of dn for new object too big. Not valid test with extended names"); test_case_add(3, saImmOiRtObjectDelete_01, "saImmOiRtObjectDelete - SA_AIS_OK"); test_case_add(3, saImmOiRtObjectDelete_03, "saImmOiRtObjectDelete - SA_AIS_ERR_BAD_HANDLE - invalid handle"); diff --git a/tests/immsv/management/Makefile.am b/tests/immsv/management/Makefile.am --- a/tests/immsv/management/Makefile.am +++ b/tests/immsv/management/Makefile.am @@ -53,6 +53,7 @@ immomtest_SOURCES = \ test_saImmOmCcbFinalize.c \ test_saImmOmAdminOperationContinue.c \ test_saImmOmThreadInterference.c \ + test_saImmOmLongDn.c \ test_cleanup.c immomtest_LDADD = \ diff --git a/tests/immsv/management/test_cleanup.c b/tests/immsv/management/test_cleanup.c --- a/tests/immsv/management/test_cleanup.c +++ b/tests/immsv/management/test_cleanup.c @@ -16,6 +16,7 @@ */ #include "immtest.h" +#include "osaf_extended_name.h" static char *objects[] = { @@ -28,6 +29,7 @@ static char *objects[] = { "id=2", "id=3", "rdn=root", + "longdn=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", NULL }; @@ -51,6 +53,7 @@ static char *classes[] = { NULL }; +extern void addOmLongDnTestCases(); static void cleanup() { SaVersionT version = { 'A', 2, 11 }; @@ -74,26 +77,25 @@ static void cleanup() { assert(rc == SA_AIS_OK); /* Delete objects */ - int len; SaNameT objectName = {0}; SaNameT *objectNames[2] = { &objectName, NULL }; obj = objects; while(*obj) { - len = strlen(*obj); - objectName.length = (len > SA_MAX_NAME_LENGTH) ? SA_MAX_NAME_LENGTH : len; - strncpy((char *)objectName.value, *obj, objectName.length); + if(osaf_is_extended_names_enabled() || strlen(*obj) < SA_MAX_NAME_LENGTH) { + osaf_extended_name_lend(*obj, &objectName); - rc = saImmOmAdminOwnerSet(ownerHandle, (const SaNameT **)objectNames, SA_IMM_SUBTREE); - if(rc == SA_AIS_ERR_NOT_EXIST) { - obj++; - continue; + rc = saImmOmAdminOwnerSet(ownerHandle, (const SaNameT **)objectNames, SA_IMM_SUBTREE); + if(rc == SA_AIS_ERR_NOT_EXIST) { + obj++; + continue; + } + assert(rc == SA_AIS_OK); + + rc = saImmOmCcbObjectDelete(ccbHandle, &objectName); + if(rc != SA_AIS_OK && rc != SA_AIS_ERR_NOT_EXIST) + fprintf(stderr, "Failed to delete object '%s' with error code: %d\n", *obj, rc); + assert(rc == SA_AIS_OK || rc == SA_AIS_ERR_NOT_EXIST); } - assert(rc == SA_AIS_OK); - - rc = saImmOmCcbObjectDelete(ccbHandle, &objectName); - if(rc != SA_AIS_OK && rc != SA_AIS_ERR_NOT_EXIST) - fprintf(stderr, "Failed to delete object '%s' with error code: %d\n", *obj, rc); - assert(rc == SA_AIS_OK || rc == SA_AIS_ERR_NOT_EXIST); obj++; } @@ -142,6 +144,14 @@ static void startup() { safassert(object_create(immOmHandle, ownerHandle, configClassName, &rootObj, NULL, NULL), SA_AIS_OK); safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); + + /* Add long DN test cases */ + char *env; + if((env = getenv("SA_ENABLE_EXTENDED_NAMES"))) { + if(!strcmp(env, "1")) { + addOmLongDnTestCases(); + } + } } __attribute__ ((constructor)) static void cleanup_constructor(void) diff --git a/tests/immsv/management/test_saImmOmLongDn.c b/tests/immsv/management/test_saImmOmLongDn.c new file mode 100644 --- /dev/null +++ b/tests/immsv/management/test_saImmOmLongDn.c @@ -0,0 +1,368 @@ +/* -*- OpenSAF -*- + * + * (C) Copyright 2014 The OpenSAF Foundation + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed + * under the GNU Lesser General Public License Version 2.1, February 1999. + * The complete license can be accessed from the following location: + * http://opensource.org/licenses/lgpl-license.php + * See the Copying file included with the OpenSAF distribution for full + * licensing terms. + * + * Author(s): Ericsson AB + * + */ + +#include "immtest.h" +#include "osaf_extended_name.h" + + +static char *longDn = "longdn=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"; + + +static void setupLongDn(void) { + SaImmHandleT immHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmCcbHandleT ccbHandle; + SaNameT dn; + const SaImmAdminOwnerNameT ownerName = (const SaImmAdminOwnerNameT)__FUNCTION__; + + SaImmAttrValueT attrValues[1] = { &dn }; + SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, + { "attr8", SA_IMM_ATTR_SANAMET, 1, attrValues }}; + const SaImmAttrModificationT_2 *attrMods[2] = { &attrMod, NULL }; + + osaf_extended_name_lend(longDn, &dn); + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + config_class_create(immHandle); + safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + safassert(object_create(immHandle, ownerHandle, configClassName, &dn, NULL, NULL), SA_AIS_OK); + + // Change SaNameT attribute for testing + safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); + safassert(saImmOmCcbObjectModify_2(ccbHandle, &dn, attrMods), SA_AIS_OK); + safassert(saImmOmCcbApply(ccbHandle), SA_AIS_OK); + safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); +} + +static void cleanLongDn(void) { + SaImmHandleT immHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaNameT dn; + const SaNameT *objects[2] = { &dn, NULL }; + const SaImmAdminOwnerNameT ownerName = (const SaImmAdminOwnerNameT)__FUNCTION__; + + osaf_extended_name_lend(longDn, &dn); + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + safassert(saImmOmAdminOwnerSet(ownerHandle, objects, SA_IMM_ONE), SA_AIS_OK); + + safassert(object_delete(ownerHandle, &dn, 0), SA_AIS_OK); + config_class_delete(immHandle); + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); +} + +static void saImmOmLongDn_01(void) { + SaImmHandleT immHandle; + SaAisErrorT error; + SaNameT defaultValue; + SaImmAttrDefinitionT_2 rdn = { + "rdn", SA_IMM_ATTR_SANAMET, SA_IMM_ATTR_CONFIG | SA_IMM_ATTR_RDN, NULL + }; + SaImmAttrDefinitionT_2 attr = { + "attr", SA_IMM_ATTR_SANAMET, SA_IMM_ATTR_CONFIG | SA_IMM_ATTR_WRITABLE, &defaultValue + }; + const SaImmAttrDefinitionT_2* attributes[] = {&rdn, &attr, NULL}; + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + osaf_extended_name_lend(longDn, &defaultValue); + error = saImmOmClassCreate_2(immHandle, "LongDnClass", SA_IMM_CLASS_CONFIG, attributes); + safassert(saImmOmClassDelete(immHandle, "LongDnClass"), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); + + test_validate(error, SA_AIS_OK); +} + +static void saImmOmLongDn_02(void) { + SaImmHandleT immHandle; + SaAisErrorT error; + SaNameT defaultValue; + SaImmClassCategoryT classCategory; + SaImmAttrDefinitionT_2 rdn = { + "rdn", SA_IMM_ATTR_SANAMET, SA_IMM_ATTR_CONFIG | SA_IMM_ATTR_RDN, NULL + }; + SaImmAttrDefinitionT_2 attr = { + "attr", SA_IMM_ATTR_SANAMET, SA_IMM_ATTR_CONFIG | SA_IMM_ATTR_WRITABLE, &defaultValue + }; + const SaImmAttrDefinitionT_2* attributes[] = {&rdn, &attr, NULL}; + SaImmAttrDefinitionT_2 **attrDef; + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + osaf_extended_name_lend(longDn, &defaultValue); + safassert(saImmOmClassCreate_2(immHandle, "LongDnClass", SA_IMM_CLASS_CONFIG, attributes), SA_AIS_OK); + + error = saImmOmClassDescriptionGet_2(immHandle, "LongDnClass", &classCategory, &attrDef); + if(error == SA_AIS_OK) { + int i = 0; + while(attrDef[i]) { + if(!strcmp("attr", attrDef[i]->attrName)) { + SaNameT *testDn = (SaNameT *)attrDef[i]->attrDefaultValue; + assert(testDn != NULL); + assert(strcmp(longDn, osaf_extended_name_borrow(testDn)) == 0); + break; + } + i++; + } + assert(attrDef[i] != NULL); + + safassert(saImmOmClassDescriptionMemoryFree_2(immHandle, attrDef), SA_AIS_OK); + } + + safassert(saImmOmClassDelete(immHandle, "LongDnClass"), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); + + test_validate(error, SA_AIS_OK); +} + +static void saImmOmLongDn_03(void) { + SaImmHandleT immHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmCcbHandleT ccbHandle; + SaAisErrorT rc; + SaNameT dn; + const SaImmAdminOwnerNameT ownerName = (const SaImmAdminOwnerNameT)__FUNCTION__; + + SaImmAttrValueT rdnVal[1] = { (SaImmAttrValueT)&dn }; + SaImmAttrValuesT_2 attrValue = { "rdn", SA_IMM_ATTR_SANAMET, 1, rdnVal }; + const SaImmAttrValuesT_2 *attrValues[2] = { &attrValue, NULL }; + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + config_class_create(immHandle); + osaf_extended_name_lend(longDn, &dn); + + safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); + + rc = saImmOmCcbObjectCreate_2(ccbHandle, configClassName, NULL, attrValues); + saImmOmCcbApply(ccbHandle); + + safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); + + safassert(object_delete(ownerHandle, &dn, 1), SA_AIS_OK); + config_class_delete(immHandle); + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); +} + +static void saImmOmLongDn_04(void) { + SaImmHandleT immHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmCcbHandleT ccbHandle; + SaAisErrorT rc; + SaNameT dn; + const SaImmAdminOwnerNameT ownerName = (const SaImmAdminOwnerNameT)__FUNCTION__; + + SaImmAttrValueT attrValues[1] = { &dn }; + SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, + { "attr8", SA_IMM_ATTR_SANAMET, 1, attrValues }}; + const SaImmAttrModificationT_2 *attrMods[2] = { &attrMod, NULL }; + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + config_class_create(immHandle); + + safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + + osaf_extended_name_lend(longDn, &dn); + safassert(object_create(immHandle, ownerHandle, configClassName, &dn, NULL, NULL), SA_AIS_OK); + + safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); + + rc = saImmOmCcbObjectModify_2(ccbHandle, &dn, attrMods); + saImmOmCcbApply(ccbHandle); + + safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); + + safassert(object_delete(ownerHandle, &dn, 1), SA_AIS_OK); + config_class_delete(immHandle); + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); +} + +static void saImmOmLongDn_05(void) { + SaImmHandleT immHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmCcbHandleT ccbHandle; + SaAisErrorT rc; + SaNameT dn; + const SaImmAdminOwnerNameT ownerName = (const SaImmAdminOwnerNameT)__FUNCTION__; + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + config_class_create(immHandle); + + safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + + osaf_extended_name_lend(longDn, &dn); + safassert(object_create(immHandle, ownerHandle, configClassName, &dn, NULL, NULL), SA_AIS_OK); + + safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); + + rc = saImmOmCcbObjectDelete(ccbHandle, &dn); + saImmOmCcbApply(ccbHandle); + + safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); + + config_class_delete(immHandle); + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); +} + +static void saImmOmLongDn_06(void) { + SaImmHandleT immHandle; + SaImmSearchHandleT searchHandle; + SaAisErrorT rc; + SaNameT dn; + SaImmSearchParametersT_2 searchParam; + SaNameT objectName; + SaImmAttrValuesT_2 **attributes; + int i; + + osaf_extended_name_lend(longDn, &dn); + searchParam.searchOneAttr.attrName = "attr8"; + searchParam.searchOneAttr.attrValueType = SA_IMM_ATTR_SANAMET; + searchParam.searchOneAttr.attrValue = &dn; + + setupLongDn(); + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + + safassert(saImmOmSearchInitialize_2(immHandle, NULL, SA_IMM_SUBTREE, + SA_IMM_SEARCH_ONE_ATTR | SA_IMM_SEARCH_GET_ALL_ATTR, &searchParam, + NULL, &searchHandle), SA_AIS_OK); + rc = saImmOmSearchNext_2(searchHandle, &objectName, &attributes); + if(rc == SA_AIS_OK) { + assert(strcmp(osaf_extended_name_borrow(&objectName), longDn) == 0); + for(i=0; attributes[i]; i++) { + if(!strcmp(attributes[i]->attrName, "attr8")) { + // Must have at least one value + assert(attributes[i]->attrValuesNumber > 0); + // Check attribute value + assert(strcmp(osaf_extended_name_borrow((SaNameT *)(attributes[i]->attrValues[0])), longDn) == 0); + break; + } + } + // SaNameT attribute is missing + assert(attributes != NULL); + } + safassert(saImmOmSearchFinalize(searchHandle), SA_AIS_OK); + + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); + + cleanLongDn(); +} + +static void saImmOmLongDn_07(void) { + SaImmHandleT immHandle; + SaImmAccessorHandleT accessorHandle; + SaAisErrorT rc; + SaNameT dn; + SaImmAttrValuesT_2 **attributes; + int i; + int score = 0; + + osaf_extended_name_lend(longDn, &dn); + + setupLongDn(); + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + + safassert(saImmOmAccessorInitialize(immHandle, &accessorHandle), SA_AIS_OK); + rc = saImmOmAccessorGet_2(accessorHandle, &dn, NULL, &attributes); + if(rc == SA_AIS_OK) { + for(i=0; attributes[i]; i++) { + if(!strcmp(attributes[i]->attrName, "rdn") || !strcmp(attributes[i]->attrName, "attr8")) { + assert(attributes[i]->attrValuesNumber > 0); + assert(strcmp(osaf_extended_name_borrow((SaNameT *)(attributes[i]->attrValues[0])), longDn) == 0); + score++; + } + } + + // Both SaNameT values are correct + assert(score == 2); + } + safassert(saImmOmAccessorFinalize(accessorHandle), SA_AIS_OK); + + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); + + cleanLongDn(); +} + +static void saImmOmLongDn_08(void) { + SaImmHandleT immHandle; + SaImmAdminOwnerHandleT ownerHandle; + SaImmAdminOwnerNameT ownerName = (SaImmAdminOwnerNameT)__FUNCTION__; + SaAisErrorT rc; + SaNameT dn; + const SaNameT *objects[2] = { &dn, NULL }; + + osaf_extended_name_lend(longDn, &dn); + + setupLongDn(); + + safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); + safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); + + rc = saImmOmAdminOwnerSet(ownerHandle, objects, SA_IMM_ONE); + + safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); + safassert(saImmOmFinalize(immHandle), SA_AIS_OK); + + test_validate(rc, SA_AIS_OK); + + cleanLongDn(); +} + + + +void addOmLongDnTestCases() { + test_case_add(8, saImmOmLongDn_01, "SA_AIS_OK - saImmOmClassCreate_2 with long DN as default value"); + test_case_add(8, saImmOmLongDn_02, "SA_AIS_OK - saImmOmClassDescriptionGet_2 with long DN as default value"); + test_case_add(8, saImmOmLongDn_03, "SA_AIS_OK - saImmOmCcbObjectCreate_2 - long RDN"); + test_case_add(8, saImmOmLongDn_04, "SA_AIS_OK - saImmOmCcbObjectModify_2 - long DN"); + test_case_add(8, saImmOmLongDn_05, "SA_AIS_OK - saImmOmCcbObjectDelete - long DN"); + test_case_add(8, saImmOmLongDn_06, "SA_AIS_OK - saImmOmSearchInitialize_2 and saImmOmSearchNext_2"); + test_case_add(8, saImmOmLongDn_07, "SA_AIS_OK - saImmOmAccessorGet_2"); + test_case_add(8, saImmOmLongDn_08, "SA_AIS_OK - saImmOmAdminOwnerSet"); +} + +__attribute__ ((constructor)) static void saImmOmLongDn_constructor(void) +{ + test_suite_add(8, "Long DN"); +} + + + + ------------------------------------------------------------------------------ Want fast and easy access to all the code in your enterprise? Index and search up to 200,000 lines of code with a free copy of Black Duck Code Sight - the same software that powers the world's largest code search on Ohloh, the Black Duck Open Hub! Try it now. http://p.sf.net/sfu/bds _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel