#include "TestLib.h"
int dpiTest_1000_validMajorMinor(dpiTestCase *testCase, dpiTestParams *params)
{
dpiErrorInfo errorInfo;
dpiContext *context;
if (dpiContext_createWithParams(DPI_MAJOR_VERSION, DPI_MINOR_VERSION, NULL,
&context, &errorInfo) < 0)
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
if (dpiContext_destroy(context) < 0) {
dpiContext_getError(context, &errorInfo);
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
}
return DPI_SUCCESS;
}
int dpiTest_1001_diffMajor(dpiTestCase *testCase, dpiTestParams *params)
{
dpiErrorInfo errorInfo;
dpiContext *context;
dpiContext_createWithParams(DPI_MAJOR_VERSION + 1, DPI_MINOR_VERSION, NULL,
&context, &errorInfo);
return dpiTestCase_expectError(testCase, "DPI-1020:");
}
int dpiTest_1002_diffMinor(dpiTestCase *testCase, dpiTestParams *params)
{
dpiErrorInfo errorInfo;
dpiContext *context;
dpiContext_createWithParams(DPI_MAJOR_VERSION, DPI_MINOR_VERSION + 1, NULL,
&context, &errorInfo);
return dpiTestCase_expectError(testCase, "DPI-1020:");
}
int dpiTest_1003_createWithNull(dpiTestCase *testCase, dpiTestParams *params)
{
dpiErrorInfo errorInfo;
dpiContext_createWithParams(DPI_MAJOR_VERSION, DPI_MINOR_VERSION, NULL,
NULL, &errorInfo);
return dpiTestCase_expectError(testCase, "DPI-1046:");
}
int dpiTest_1004_destroyWithNull(dpiTestCase *testCase, dpiTestParams *params)
{
dpiContext_destroy(NULL);
return dpiTestCase_expectError(testCase, "DPI-1002:");
}
int dpiTest_1005_destroyTwice(dpiTestCase *testCase, dpiTestParams *params)
{
dpiErrorInfo errorInfo;
dpiContext *context;
if (dpiContext_createWithParams(DPI_MAJOR_VERSION, DPI_MINOR_VERSION, NULL,
&context, &errorInfo) < 0)
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
if (dpiContext_destroy(context) < 0)
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
dpiContext_destroy(context);
return dpiTestCase_expectError(testCase, "DPI-1002:");
}
int dpiTest_1006_validCtxParams(dpiTestCase *testCase, dpiTestParams *params)
{
dpiContextCreateParams ctxParams = {0};
dpiErrorInfo errorInfo;
dpiContext *context;
ctxParams.defaultEncoding = "ASCII";
ctxParams.defaultDriverName = "dummy : 0.0.1";
if (dpiContext_createWithParams(DPI_MAJOR_VERSION, DPI_MINOR_VERSION,
&ctxParams, &context, &errorInfo) < 0)
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
if (dpiContext_destroy(context) < 0) {
dpiContext_getError(context, &errorInfo);
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
}
return DPI_SUCCESS;
}
int dpiTest_1007_multipleContexts(dpiTestCase *testCase, dpiTestParams *params)
{
dpiVersionInfo versionInfo1, versionInfo2;
dpiContext *context1, *context2;
dpiErrorInfo errorInfo;
if (dpiContext_createWithParams(DPI_MAJOR_VERSION, DPI_MINOR_VERSION,
NULL, &context1, &errorInfo) < 0)
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
if (dpiContext_getClientVersion(context1, &versionInfo1) < 0) {
dpiContext_getError(context1, &errorInfo);
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
}
if (dpiContext_createWithParams(DPI_MAJOR_VERSION, DPI_MINOR_VERSION,
NULL, &context2, &errorInfo) < 0)
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
if (dpiContext_getClientVersion(context2, &versionInfo2) < 0) {
dpiContext_getError(context2, &errorInfo);
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
}
if (dpiTestCase_expectUintEqual(testCase, versionInfo1.versionNum,
versionInfo2.versionNum) < 0)
return DPI_FAILURE;
if (dpiContext_destroy(context1) < 0) {
dpiContext_getError(context1, &errorInfo);
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
}
if (dpiContext_destroy(context2) < 0) {
dpiContext_getError(context2, &errorInfo);
return dpiTestCase_setFailedFromErrorInfo(testCase, &errorInfo);
}
return DPI_SUCCESS;
}
int main(int argc, char **argv)
{
dpiTestSuite_initialize(1000);
dpiTestSuite_addCase(dpiTest_1000_validMajorMinor,
"dpiContext_createWithParams() with valid major/minor versions");
dpiTestSuite_addCase(dpiTest_1001_diffMajor,
"dpiContext_createWithParams() with invalid major version");
dpiTestSuite_addCase(dpiTest_1002_diffMinor,
"dpiContext_createWithParams() with invalid minor version");
dpiTestSuite_addCase(dpiTest_1003_createWithNull,
"dpiContext_createWithParams() with NULL pointer");
dpiTestSuite_addCase(dpiTest_1004_destroyWithNull,
"dpiContext_destroy() with NULL pointer");
dpiTestSuite_addCase(dpiTest_1005_destroyTwice,
"dpiContext_destroy() called twice on same pointer");
dpiTestSuite_addCase(dpiTest_1006_validCtxParams,
"dpiContext_createWithParams() with creation parameters");
dpiTestSuite_addCase(dpiTest_1007_multipleContexts,
"dpiContext_createWithParams() twice");
return dpiTestSuite_run();
}