#include "TestLib.h"
int dpiTest_600_busyCount(dpiTestCase *testCase, dpiTestParams *params)
{
uint32_t count, i;
dpiConn *conn[3];
dpiPool *pool;
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
if (dpiPool_getBusyCount(pool, &count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count, 0) < 0)
return DPI_FAILURE;
for (i = 0; i < 3; i++) {
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL,
&conn[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getBusyCount(pool, &count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count, i + 1) < 0)
return DPI_FAILURE;
}
for (i = 0; i < 3; i++) {
if (dpiConn_release(conn[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getBusyCount(pool, &count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count, 2 - i) < 0)
return DPI_FAILURE;
}
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_601_openCount(dpiTestCase *testCase, dpiTestParams *params)
{
uint32_t count;
dpiPool *pool;
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
if (dpiPool_getOpenCount(pool, &count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count,
DPI_TEST_POOL_MIN_SESSIONS) < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_602_encodingInfo(dpiTestCase *testCase, dpiTestParams *params)
{
const char *charSet = "ISO-8859-13";
dpiCommonCreateParams commonParams;
dpiEncodingInfo info;
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiContext_initCommonCreateParams(context, &commonParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
commonParams.encoding = charSet;
commonParams.nencoding = charSet;
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, &commonParams, NULL, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getEncodingInfo(pool, &info) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase, info.encoding,
strlen(info.encoding), charSet, strlen(charSet)) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectStringEqual(testCase, info.nencoding,
strlen(info.nencoding), charSet, strlen(charSet)) < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_603_checkGetMode(dpiTestCase *testCase, dpiTestParams *params)
{
dpiPoolCreateParams createParams;
dpiPoolGetMode value;
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_setGetMode(pool, DPI_MODE_POOL_GET_WAIT) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getGetMode(pool, &value) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, value,
DPI_MODE_POOL_GET_WAIT) < 0)
return DPI_FAILURE;
if (dpiPool_setGetMode(pool, DPI_MODE_POOL_GET_NOWAIT) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getGetMode(pool, &value) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, value,
DPI_MODE_POOL_GET_NOWAIT) < 0)
return DPI_FAILURE;
if (dpiPool_setGetMode(pool, DPI_MODE_POOL_GET_FORCEGET) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getGetMode(pool, &value) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, value,
DPI_MODE_POOL_GET_FORCEGET) < 0)
return DPI_FAILURE;
dpiPool_release(pool);
return DPI_SUCCESS;
}
int dpiTest_604_checkMaxLifetimeSession(dpiTestCase *testCase,
dpiTestParams *params)
{
uint32_t value, valueToSet = 10;
dpiPool *pool;
if (dpiTestCase_setSkippedIfVersionTooOld(testCase, 0, 12, 1) < 0)
return DPI_FAILURE;
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
if (dpiPool_setMaxLifetimeSession(pool, valueToSet) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getMaxLifetimeSession(pool, &value) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, value, valueToSet) < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_605_checkTimeout(dpiTestCase *testCase, dpiTestParams *params)
{
uint32_t value, valueToSet = 12;
dpiPool *pool;
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
if (dpiPool_setTimeout(pool, valueToSet) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getTimeout(pool, &value) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, value, valueToSet) < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_606_encodingInfo(dpiTestCase *testCase, dpiTestParams *params)
{
const char *charSet = "ISO-8859-13";
dpiCommonCreateParams commonParams;
dpiEncodingInfo info, defaultInfo;
dpiConn *defaultConn;
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiContext_initCommonCreateParams(context, &commonParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiConn_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, &commonParams, NULL,
&defaultConn) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiConn_getEncodingInfo(defaultConn, &defaultInfo) < 0)
return dpiTestCase_setFailedFromError(testCase);
commonParams.encoding = charSet;
commonParams.nencoding = NULL;
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, &commonParams, NULL, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getEncodingInfo(pool, &info) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase, info.encoding,
strlen(info.encoding), charSet, strlen(charSet)) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectStringEqual(testCase, info.nencoding,
strlen(info.nencoding), defaultInfo.nencoding,
strlen(defaultInfo.nencoding)) < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
commonParams.encoding = NULL;
commonParams.nencoding = charSet;
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, &commonParams, NULL, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getEncodingInfo(pool, &info) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase, info.encoding,
strlen(info.encoding), defaultInfo.encoding,
strlen(defaultInfo.encoding)) < 0)
return DPI_FAILURE;
if (dpiTestCase_expectStringEqual(testCase, info.nencoding,
strlen(info.nencoding), charSet, strlen(charSet)) < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiConn_release(defaultConn) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int main(int argc, char **argv)
{
dpiTestSuite_initialize(600);
dpiTestSuite_addCase(dpiTest_600_busyCount,
"dpiPool_getBusyCount() with various scenarios");
dpiTestSuite_addCase(dpiTest_601_openCount,
"dpiPool_getOpenCount() with various scenarios");
dpiTestSuite_addCase(dpiTest_602_encodingInfo,
"dpiPool_getEncodingInfo() to verify that the values match");
dpiTestSuite_addCase(dpiTest_603_checkGetMode,
"check get / set mode for getting connections from pool");
dpiTestSuite_addCase(dpiTest_604_checkMaxLifetimeSession,
"check get / set maximum lifetime session of pool");
dpiTestSuite_addCase(dpiTest_605_checkTimeout,
"check get / set pool timeout");
dpiTestSuite_addCase(dpiTest_606_encodingInfo,
"specifying a value for nencoding and null for encoding");
return dpiTestSuite_run();
}