#include "TestLib.h"
#define NUM_ATTRS 7
int dpiTest__verifyAttributeInfo(dpiTestCase *testCase,
dpiObjectAttrInfo *attrInfo, const char *expectedName,
dpiOracleTypeNum expectedOracleTypeNum,
dpiNativeTypeNum expectedDefaultNativeTypeNum,
const char *expectedObjectTypeName)
{
dpiObjectTypeInfo typeInfo;
if (dpiTestCase_expectStringEqual(testCase, attrInfo->name,
attrInfo->nameLength, expectedName, strlen(expectedName)) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectUintEqual(testCase, attrInfo->typeInfo.oracleTypeNum,
expectedOracleTypeNum) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectUintEqual(testCase,
attrInfo->typeInfo.defaultNativeTypeNum,
expectedDefaultNativeTypeNum) < 0)
return DPI_FAILURE;
if (expectedObjectTypeName && !attrInfo->typeInfo.objectType)
return dpiTestCase_setFailed(testCase,
"Expected object type but got NULL");
if (!expectedObjectTypeName && attrInfo->typeInfo.objectType)
return dpiTestCase_setFailed(testCase,
"Expected no object type but got one");
if (expectedObjectTypeName && attrInfo->typeInfo.objectType) {
if (dpiObjectType_getInfo(attrInfo->typeInfo.objectType,
&typeInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase, typeInfo.name,
typeInfo.nameLength, expectedObjectTypeName,
strlen(expectedObjectTypeName)) < 0)
return DPI_FAILURE;
}
return DPI_SUCCESS;
}
int dpiTest__verifyObjectTypeInfo(dpiTestCase *testCase,
dpiObjectTypeInfo *typeInfo, const char *expectedSchemaName,
uint32_t expectedSchemaNameLength, const char * expectedName,
int expectedIsCollection, dpiOracleTypeNum expectedOracleTypeNum,
dpiNativeTypeNum expectedDefaultNativeTypeNum,
dpiObjectType *expectedObjectType, uint16_t expectedNumAttrs)
{
if (dpiTestCase_expectStringEqual(testCase, typeInfo->schema,
typeInfo->schemaLength, expectedSchemaName,
expectedSchemaNameLength) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectStringEqual(testCase, typeInfo->name,
typeInfo->nameLength, expectedName, strlen(expectedName)) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectUintEqual(testCase, typeInfo->isCollection,
expectedIsCollection) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectUintEqual(testCase, typeInfo->numAttributes,
expectedNumAttrs) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectUintEqual(testCase,
typeInfo->elementTypeInfo.oracleTypeNum,
expectedOracleTypeNum) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectUintEqual(testCase,
typeInfo->elementTypeInfo.defaultNativeTypeNum,
expectedDefaultNativeTypeNum) < 0)
return DPI_FAILURE;
return DPI_SUCCESS;
}
int dpiTest_1300_verifyGetObjTypeWithInvalidObj(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *expectedErrors[] = { "ORA-04043:", "OCI-22303:", NULL };
const char *objStr = "INVALID_OBJECT_TYPE";
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType);
return dpiTestCase_expectAnyError(testCase, expectedErrors);
}
int dpiTest_1301_verifyGetObjTypeWithValidObj(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *objStr = "UDT_OBJECTDATATYPES";
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_1302_releaseObjTypeTwice(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *objStr = "UDT_OBJECTDATATYPES";
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiObjectType_release(objType);
return dpiTestCase_expectError(testCase, "DPI-1002:");
}
int dpiTest_1303_verifyPubFuncsOfObjTypeWithNull(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *expectedError = "DPI-1002:";
dpiObjectAttr *attributes[NUM_ATTRS];
dpiObjectTypeInfo info;
dpiObject *obj;
dpiObjectType_addRef(NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiObjectType_createObject(NULL, &obj);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiObjectType_getAttributes(NULL, 0, attributes);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiObjectType_getInfo(NULL, &info);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiObjectType_release(NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
return DPI_SUCCESS;
}
int dpiTest_1304_verifyGetAttrsFunWithInvalidNumAttrs(dpiTestCase *testCase,
dpiTestParams *params)
{
dpiObjectAttr *attributes[NUM_ATTRS];
const char *objStr = "UDT_OBJECT";
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiObjectType_getAttributes(objType, 5, attributes);
if (dpiTestCase_expectError(testCase, "DPI-1018:") < 0)
return DPI_FAILURE;
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_1305_verifyMetaDataOfAttributes(dpiTestCase *testCase,
dpiTestParams *params)
{
dpiObjectAttr *attributes[NUM_ATTRS];
const char *objStr = "UDT_OBJECT";
dpiObjectAttrInfo attrInfo;
dpiObjectTypeInfo typeInfo;
dpiObjectType *objType;
dpiConn *conn;
uint32_t i;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_getInfo(objType, &typeInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_getAttributes(objType, typeInfo.numAttributes,
attributes) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectAttr_getInfo(attributes[0], &attrInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyAttributeInfo(testCase, &attrInfo, "NUMBERVALUE",
DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_DOUBLE, NULL) < 0)
return DPI_FAILURE;
if (dpiObjectAttr_getInfo(attributes[1], &attrInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyAttributeInfo(testCase, &attrInfo, "STRINGVALUE",
DPI_ORACLE_TYPE_VARCHAR, DPI_NATIVE_TYPE_BYTES, NULL) < 0)
return DPI_FAILURE;
if (dpiObjectAttr_getInfo(attributes[2], &attrInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyAttributeInfo(testCase, &attrInfo, "FIXEDCHARVALUE",
DPI_ORACLE_TYPE_CHAR, DPI_NATIVE_TYPE_BYTES, NULL) < 0)
return DPI_FAILURE;
if (dpiObjectAttr_getInfo(attributes[3], &attrInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyAttributeInfo(testCase, &attrInfo, "DATEVALUE",
DPI_ORACLE_TYPE_DATE, DPI_NATIVE_TYPE_TIMESTAMP, NULL) < 0)
return DPI_FAILURE;
if (dpiObjectAttr_getInfo(attributes[4], &attrInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyAttributeInfo(testCase, &attrInfo, "TIMESTAMPVALUE",
DPI_ORACLE_TYPE_TIMESTAMP, DPI_NATIVE_TYPE_TIMESTAMP, NULL) < 0)
return DPI_FAILURE;
if (dpiObjectAttr_getInfo(attributes[5], &attrInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyAttributeInfo(testCase, &attrInfo, "SUBOBJECTVALUE",
DPI_ORACLE_TYPE_OBJECT, DPI_NATIVE_TYPE_OBJECT,
"UDT_SUBOBJECT") < 0)
return DPI_FAILURE;
if (dpiObjectAttr_getInfo(attributes[6], &attrInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyAttributeInfo(testCase, &attrInfo, "SUBOBJECTARRAY",
DPI_ORACLE_TYPE_OBJECT, DPI_NATIVE_TYPE_OBJECT,
"UDT_OBJECTARRAY") < 0)
return DPI_FAILURE;
for (i = 0; i < NUM_ATTRS; i++) {
if (dpiObjectAttr_release(attributes[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_1306_verifyTypeInfoOfObjCollection(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *objStr = "UDT_OBJECTARRAY";
dpiObjectTypeInfo typeInfo;
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_getInfo(objType, &typeInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyObjectTypeInfo(testCase, &typeInfo,
params->mainUserName, params->mainUserNameLength, objStr, 1,
DPI_ORACLE_TYPE_OBJECT, DPI_NATIVE_TYPE_OBJECT, NULL, 0) < 0)
return DPI_FAILURE;
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_1307_verifyTypeInfoOfScalarCollection(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *objStr = "UDT_ARRAY";
dpiObjectTypeInfo typeInfo;
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_getInfo(objType, &typeInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyObjectTypeInfo(testCase, &typeInfo,
params->mainUserName, params->mainUserNameLength, objStr, 1,
DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_DOUBLE, NULL, 0) < 0)
return DPI_FAILURE;
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_1308_verifyTypeInfoOfNonCollection(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *objStr = "UDT_OBJECT";
dpiObjectTypeInfo typeInfo;
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_getInfo(objType, &typeInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyObjectTypeInfo(testCase, &typeInfo,
params->mainUserName, params->mainUserNameLength, objStr, 0, 0, 0,
NULL, NUM_ATTRS) < 0)
return DPI_FAILURE;
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_1309_verifyTypeInfoOfIndexedTable(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *objStr = "PKG_TESTNUMBERARRAYS.UDT_NUMBERLIST";
dpiObjectTypeInfo typeInfo;
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_setSkippedIfVersionTooOld(testCase, 0, 12, 1) < 0)
return DPI_FAILURE;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_getInfo(objType, &typeInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyObjectTypeInfo(testCase, &typeInfo,
params->mainUserName, params->mainUserNameLength, "UDT_NUMBERLIST",
1, DPI_ORACLE_TYPE_NUMBER, DPI_NATIVE_TYPE_DOUBLE, NULL, 0) < 0)
return DPI_FAILURE;
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_1310_verifyTypeInfoOfRecordType(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *objStr = "PKG_TESTRECORDS.UDT_RECORD";
dpiObjectTypeInfo typeInfo;
dpiObjectType *objType;
dpiConn *conn;
if (dpiTestCase_setSkippedIfVersionTooOld(testCase, 0, 12, 1) < 0)
return DPI_FAILURE;
if (dpiTestCase_getConnection(testCase, &conn) < 0)
return DPI_FAILURE;
if (dpiConn_getObjectType(conn, objStr, strlen(objStr), &objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiObjectType_getInfo(objType, &typeInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyObjectTypeInfo(testCase, &typeInfo,
params->mainUserName, params->mainUserNameLength, "UDT_RECORD", 0,
0, 0, NULL, 5) < 0)
return DPI_FAILURE;
if (dpiObjectType_release(objType) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int main(int argc, char **argv)
{
dpiTestSuite_initialize(1300);
dpiTestSuite_addCase(dpiTest_1300_verifyGetObjTypeWithInvalidObj,
"dpiConn_getObjectType() with invalid name");
dpiTestSuite_addCase(dpiTest_1301_verifyGetObjTypeWithValidObj,
"dpiConn_getObjectType() with valid name");
dpiTestSuite_addCase(dpiTest_1302_releaseObjTypeTwice,
"dpiObjectType_release() called twice");
dpiTestSuite_addCase(dpiTest_1303_verifyPubFuncsOfObjTypeWithNull,
"call object type functions with NULL object type");
dpiTestSuite_addCase(dpiTest_1304_verifyGetAttrsFunWithInvalidNumAttrs,
"dpiObjectType_getAttributes() with too small numAttributes");
dpiTestSuite_addCase(dpiTest_1305_verifyMetaDataOfAttributes,
"dpiObjectAttr_getInfo() and verify metadata");
dpiTestSuite_addCase(dpiTest_1306_verifyTypeInfoOfObjCollection,
"dpiObjectType_getInfo() of collection containing an object");
dpiTestSuite_addCase(dpiTest_1307_verifyTypeInfoOfScalarCollection,
"dpiObjectType_getInfo() of collection containing scalar values");
dpiTestSuite_addCase(dpiTest_1308_verifyTypeInfoOfNonCollection,
"dpiObjectType_getInfo() of object type with attributes");
dpiTestSuite_addCase(dpiTest_1309_verifyTypeInfoOfIndexedTable,
"dpiObjectType_getInfo() of indexed-by binary integer table");
dpiTestSuite_addCase(dpiTest_1310_verifyTypeInfoOfRecordType,
"dpiObjectType_getInfo() of PL/SQL record type");
return dpiTestSuite_run();
}