#include "TestLib.h"
int dpiTest__verifyContent(dpiTestCase *testCase, dpiSodaColl *coll,
dpiSodaOperOptions *options, const char *expectedContent)
{
const char *content, *encoding;
uint32_t contentLength;
dpiSodaDoc *doc;
if (dpiSodaColl_findOne(coll, options, DPI_SODA_FLAGS_DEFAULT, &doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_getContent(doc, &content, &contentLength, &encoding) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase, content, contentLength,
expectedContent, strlen(expectedContent)) < 0)
return DPI_FAILURE;
if (dpiSodaDoc_release(doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest__countDocuments(dpiTestCase *testCase, dpiSodaColl *coll,
dpiSodaOperOptions *options, uint64_t expectedCount)
{
dpiSodaDocCursor *cursor;
dpiSodaDoc *doc;
uint64_t pos;
if (dpiSodaColl_find(coll, options, DPI_SODA_FLAGS_DEFAULT, &cursor) < 0)
return dpiTestCase_setFailedFromError(testCase);
for (pos = 0; pos < expectedCount; pos++) {
if (dpiSodaDocCursor_getNext(cursor, DPI_SODA_FLAGS_DEFAULT, &doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (!doc)
return dpiTestCase_setFailed(testCase,
"too few documents found in the database");
if (dpiSodaDoc_release(doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiSodaDocCursor_getNext(cursor, DPI_SODA_FLAGS_DEFAULT, &doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (doc)
return dpiTestCase_setFailed(testCase,
"too many documents found in the database");
if (dpiSodaDocCursor_release(cursor) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest__insertDoc(dpiTestCase *testCase, dpiSodaDb *db,
const char *content, dpiSodaColl *coll, dpiSodaDoc **insertedDoc)
{
dpiSodaDoc *doc;
if (dpiSodaDb_createDocument(db, NULL, 0, content, strlen(content), NULL,
0, DPI_SODA_FLAGS_DEFAULT, &doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_insertOne(coll, doc, DPI_SODA_FLAGS_ATOMIC_COMMIT,
insertedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_release(doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest__insertManyDocs(dpiTestCase *testCase, dpiSodaDb *db,
dpiSodaColl *coll, uint32_t numDocs, const char **content,
dpiSodaDoc **insertedDocs)
{
uint64_t origDocCount, docCount;
dpiSodaOperOptions options;
dpiContext *context;
dpiSodaDoc **docs;
uint32_t i;
if (dpiSodaColl_getDocCount(coll, NULL, DPI_SODA_FLAGS_DEFAULT,
&origDocCount) < 0)
return dpiTestCase_setFailedFromError(testCase);
docs = malloc(numDocs * sizeof(dpiSodaDoc*));
if (!docs)
return dpiTestCase_setFailed(testCase, "Out of memory!");
for (i = 0; i < numDocs; i++) {
if (dpiSodaDb_createDocument(db, NULL, 0, content[i],
strlen(content[i]), NULL, 0, DPI_SODA_FLAGS_DEFAULT,
&docs[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiSodaColl_insertMany(coll, numDocs, docs,
DPI_SODA_FLAGS_ATOMIC_COMMIT, insertedDocs) < 0)
return dpiTestCase_setFailedFromError(testCase);
for (i = 0; i < numDocs; i++)
dpiSodaDoc_release(docs[i]);
free(docs);
if (dpiSodaColl_getDocCount(coll, NULL, DPI_SODA_FLAGS_DEFAULT,
&docCount) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, docCount,
origDocCount + numDocs) < 0)
return DPI_FAILURE;
if (insertedDocs) {
dpiTestSuite_getContext(&context);
if (dpiContext_initSodaOperOptions(context, &options) < 0)
return dpiTestCase_setFailedFromError(testCase);
for (i = 0; i < numDocs; i++) {
if (dpiSodaDoc_getKey(insertedDocs[i], &options.key,
&options.keyLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyContent(testCase, coll, &options,
content[i]) < 0)
return DPI_FAILURE;
}
}
return DPI_SUCCESS;
}
int dpiTest_2600_nullHandle(dpiTestCase *testCase, dpiTestParams *params)
{
const char *expectedError = "DPI-1002:";
dpiSodaColl_addRef(NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_createIndex(NULL, NULL, 0, DPI_SODA_FLAGS_DEFAULT);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_drop(NULL, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_dropIndex(NULL, NULL, 0, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_find(NULL, NULL, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_findOne(NULL, NULL, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_getDataGuide(NULL, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_getDocCount(NULL, NULL, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_getMetadata(NULL, NULL, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_getName(NULL, NULL, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_insertOne(NULL, NULL, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_insertMany(NULL, 0, NULL, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_release(NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_remove(NULL, NULL, DPI_SODA_FLAGS_DEFAULT, NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiSodaColl_replaceOne(NULL, NULL, NULL, DPI_SODA_FLAGS_DEFAULT, NULL,
NULL);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
return DPI_SUCCESS;
}
int dpiTest_2601_addRef(dpiTestCase *testCase, dpiTestParams *params)
{
const char *collName = "ODPIC_COLL_2601";
dpiSodaColl *coll;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_addRef(coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_release(coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
dpiSodaColl_release(coll);
if (dpiTestCase_expectError(testCase, "DPI-1002:") < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2602_replaceDoc(dpiTestCase *testCase, dpiTestParams *params)
{
const char *replaceContent = "{\"test\":\"2602 replaced\"}";
const char *content = "{\"test\":\"2602 original\"}";
const char *collName = "ODPIC_COLL_2602";
dpiSodaDoc *doc, *insertedDoc, *replacedDoc;
dpiSodaOperOptions options;
dpiContext *context;
dpiSodaColl *coll;
dpiSodaDb *db;
int replaced;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__insertDoc(testCase, db, content, coll, &insertedDoc) < 0)
return DPI_FAILURE;
dpiTestSuite_getContext(&context);
if (dpiContext_initSodaOperOptions(context, &options) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_getKey(insertedDoc, &options.key, &options.keyLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyContent(testCase, coll, &options, content) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createDocument(db, NULL, 0, replaceContent,
strlen(replaceContent), NULL, 0, DPI_SODA_FLAGS_DEFAULT, &doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_replaceOne(coll, &options, doc,
DPI_SODA_FLAGS_ATOMIC_COMMIT, &replaced, &replacedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_release(doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, replaced, 1) < 0)
return DPI_FAILURE;
if (dpiTest__verifyContent(testCase, coll, &options, replaceContent) < 0)
return DPI_FAILURE;
if (dpiSodaDoc_release(insertedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_release(replacedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2603_removeDoc(dpiTestCase *testCase, dpiTestParams *params)
{
const char *content = "{\"test\":\"2603 content\"}";
const char *collName = "ODPIC_COLL_2603";
dpiSodaOperOptions options;
dpiSodaDoc *insertedDoc;
dpiContext *context;
dpiSodaColl *coll;
uint64_t numDocs;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__insertDoc(testCase, db, content, coll, &insertedDoc) < 0)
return DPI_FAILURE;
dpiTestSuite_getContext(&context);
if (dpiContext_initSodaOperOptions(context, &options) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_getKey(insertedDoc, &options.key, &options.keyLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_remove(coll, &options, DPI_SODA_FLAGS_ATOMIC_COMMIT,
&numDocs) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, numDocs, 1) < 0)
return DPI_FAILURE;
if (dpiSodaColl_remove(coll, &options, DPI_SODA_FLAGS_ATOMIC_COMMIT,
&numDocs) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, numDocs, 0) < 0)
return DPI_FAILURE;
if (dpiSodaDoc_release(insertedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2604_dropColl(dpiTestCase *testCase, dpiTestParams *params)
{
const char *name = "ODPIC_COLL_2604";
dpiSodaColl *coll;
int isDropped;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, name, strlen(name), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_drop(coll, DPI_SODA_FLAGS_DEFAULT, &isDropped) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, isDropped, 1) < 0)
return DPI_FAILURE;
if (dpiSodaColl_drop(coll, DPI_SODA_FLAGS_DEFAULT, &isDropped) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, isDropped, 0) < 0)
return DPI_FAILURE;
if (dpiSodaColl_release(coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2605_createAndDropIndex(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *indexSpec = "{'name': 'ODPIC_COLL_2605_IX_1'}";
const char *indexName = "ODPIC_COLL_2605_IX_1";
const char *collName = "ODPIC_COLL_2605";
dpiSodaColl *coll;
dpiSodaDb *db;
int isDropped;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiTestCase_dropAllSodaColls(testCase, db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_createIndex(coll, indexSpec, strlen(indexSpec),
DPI_SODA_FLAGS_DEFAULT) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_dropIndex(coll, indexName, strlen(indexName),
DPI_SODA_FLAGS_DEFAULT, &isDropped) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, isDropped, 1) < 0)
return DPI_FAILURE;
if (dpiSodaColl_dropIndex(coll, indexName, strlen(indexName),
DPI_SODA_FLAGS_DEFAULT, &isDropped) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, isDropped, 0) < 0)
return DPI_FAILURE;
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2606_getDocCount(dpiTestCase *testCase, dpiTestParams *params)
{
const char *content = "{\"test\" : \"2606 content\"}";
const char *collName = "ODPIC_COLL_2606";
dpiSodaOperOptions options;
dpiSodaDoc *insertedDoc;
dpiContext *context;
dpiSodaColl *coll;
uint64_t numDocs;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiTestCase_dropAllSodaColls(testCase, db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_getDocCount(coll, NULL, DPI_SODA_FLAGS_DEFAULT,
&numDocs) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, numDocs, 0) < 0)
return DPI_FAILURE;
if (dpiTest__insertDoc(testCase, db, content, coll, &insertedDoc) < 0)
return DPI_FAILURE;
if (dpiTest__insertDoc(testCase, db, content, coll, NULL) < 0)
return DPI_FAILURE;
if (dpiSodaColl_getDocCount(coll, NULL, DPI_SODA_FLAGS_DEFAULT,
&numDocs) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, numDocs, 2) < 0)
return DPI_FAILURE;
dpiTestSuite_getContext(&context);
if (dpiContext_initSodaOperOptions(context, &options) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_getKey(insertedDoc, &options.key, &options.keyLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_getDocCount(coll, &options, DPI_SODA_FLAGS_DEFAULT,
&numDocs) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, numDocs, 1) < 0)
return DPI_FAILURE;
if (dpiSodaDoc_release(insertedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2607_getCollName(dpiTestCase *testCase, dpiTestParams *params)
{
const char *collName = "ODPIC_COLL_2607";
uint32_t valueLength;
const char *value;
dpiSodaColl *coll;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_getName(coll, &value, &valueLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase, value, valueLength,
collName, strlen(collName)) < 0)
return DPI_FAILURE;
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2608_getMetadata(dpiTestCase *testCase, dpiTestParams *params)
{
const char *collName1 = "ODPIC_COLL_2608_A";
const char *collName2 = "ODPIC_COLL_2608_B";
dpiSodaColl *coll1, *coll2;
uint32_t metadataLength;
const char *metadata;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiTestCase_dropAllSodaColls(testCase, db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName1, strlen(collName1), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll1) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_getMetadata(coll1, &metadata, &metadataLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDb_createCollection(db, collName1, strlen(collName1), metadata,
metadataLength, DPI_SODA_FLAGS_DEFAULT, &coll2) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_release(coll2) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDb_createCollection(db, collName2, strlen(collName2), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll2) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiSodaDb_createCollection(db, collName2, strlen(collName2), metadata,
metadataLength, DPI_SODA_FLAGS_DEFAULT, &coll2);
if (dpiTestCase_expectError(testCase, "ORA-40669:") < 0)
return DPI_FAILURE;
if (dpiTestCase_cleanupSodaColl(testCase, coll1) < 0)
return DPI_FAILURE;
if (dpiTestCase_cleanupSodaColl(testCase, coll2) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2609_verifyFind(dpiTestCase *testCase, dpiTestParams *params)
{
const char *content = "{\"test\":\"2609\"}";
const char *collName = "ODPIC_COLL_2609";
dpiSodaDoc **temp, *insertedDoc;
dpiSodaOperOptions options;
uint32_t i, numDocs = 5;
dpiContext *context;
dpiSodaColl *coll;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiTestCase_dropAllSodaColls(testCase, db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__countDocuments(testCase, coll, NULL, 0) < 0)
return DPI_FAILURE;
for (i = 0; i < numDocs; i++) {
temp = (i == 0) ? &insertedDoc : NULL;
if (dpiTest__insertDoc(testCase, db, content, coll, temp) < 0)
return DPI_FAILURE;
}
if (dpiTest__countDocuments(testCase, coll, NULL, numDocs) < 0)
return DPI_FAILURE;
dpiTestSuite_getContext(&context);
if (dpiContext_initSodaOperOptions(context, &options) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_getKey(insertedDoc, &options.key, &options.keyLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__countDocuments(testCase, coll, &options, 1) < 0)
return DPI_FAILURE;
if (dpiSodaDoc_release(insertedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2610_testInvalidJson(dpiTestCase *testCase, dpiTestParams *params)
{
const char *content = "{\"test : 2610 content\"}";
const char *collName = "ODPIC_COLL_2610";
dpiSodaColl *coll;
dpiSodaDoc *doc;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDb_createDocument(db, NULL, 0, content, strlen(content), NULL,
0, DPI_SODA_FLAGS_DEFAULT, &doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiSodaColl_insertOne(coll, doc, DPI_SODA_FLAGS_ATOMIC_COMMIT, NULL);
if (dpiTestCase_expectError(testCase, "ORA-02290:") < 0)
return DPI_FAILURE;
if (dpiSodaDoc_release(doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2611_verifyKeys(dpiTestCase *testCase, dpiTestParams *params)
{
uint32_t i, keyLengths[3], numDocs = 5, numKeys = 3;
const char *content = "{\"test\":\"2611\"}";
const char *collName = "ODPIC_COLL_2611";
dpiSodaDoc *doc, *retainedDocs[3];
dpiSodaOperOptions options;
const char *keys[3];
dpiContext *context;
dpiSodaColl *coll;
uint64_t count;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_remove(coll, NULL, DPI_SODA_FLAGS_ATOMIC_COMMIT,
&count) < 0)
return dpiTestCase_setFailedFromError(testCase);
for (i = 0; i < numDocs; i++) {
if (dpiTest__insertDoc(testCase, db, content, coll, &doc) < 0)
return DPI_FAILURE;
if (i % 2 == 0) {
retainedDocs[i >> 1] = doc;
if (dpiSodaDoc_getKey(doc, &keys[i >> 1], &keyLengths[i >> 1]) < 0)
return dpiTestCase_setFailedFromError(testCase);
} else if (dpiSodaDoc_release(doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiTest__countDocuments(testCase, coll, NULL, numDocs) < 0)
return DPI_FAILURE;
dpiTestSuite_getContext(&context);
if (dpiContext_initSodaOperOptions(context, &options) < 0)
return dpiTestCase_setFailedFromError(testCase);
options.numKeys = numKeys;
options.keys = keys;
options.keyLengths = keyLengths;
if (dpiTest__countDocuments(testCase, coll, &options, numKeys) < 0)
return DPI_FAILURE;
if (dpiSodaColl_getDocCount(coll, &options, DPI_SODA_FLAGS_DEFAULT,
&count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count, numKeys) < 0)
return DPI_FAILURE;
if (dpiSodaColl_remove(coll, &options, DPI_SODA_FLAGS_ATOMIC_COMMIT,
&count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count, numKeys) < 0)
return DPI_FAILURE;
for (i = 0; i < numKeys; i++) {
if (dpiSodaDoc_release(retainedDocs[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2612_verifySkipAndLimit(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *content = "{\"test\":\"2611\"}";
const char *collName = "ODPIC_COLL_2611";
dpiSodaOperOptions options;
uint32_t i, numDocs = 50;
dpiContext *context;
dpiSodaColl *coll;
uint64_t count;
dpiSodaDb *db;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_remove(coll, NULL, DPI_SODA_FLAGS_ATOMIC_COMMIT,
&count) < 0)
return dpiTestCase_setFailedFromError(testCase);
for (i = 0; i < numDocs; i++) {
if (dpiTest__insertDoc(testCase, db, content, coll, NULL) < 0)
return DPI_FAILURE;
}
if (dpiSodaColl_getDocCount(coll, NULL, DPI_SODA_FLAGS_DEFAULT,
&count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count, numDocs) < 0)
return DPI_FAILURE;
dpiTestSuite_getContext(&context);
if (dpiContext_initSodaOperOptions(context, &options) < 0)
return dpiTestCase_setFailedFromError(testCase);
options.skip = 15;
if (dpiTest__countDocuments(testCase, coll, &options,
numDocs - options.skip) < 0)
return DPI_FAILURE;
options.skip = numDocs;
if (dpiTest__countDocuments(testCase, coll, &options, 0) < 0)
return DPI_FAILURE;
options.skip = 0;
options.limit = 20;
if (dpiTest__countDocuments(testCase, coll, &options, options.limit) < 0)
return DPI_FAILURE;
options.skip = 10;
options.limit = 5;
if (dpiTest__countDocuments(testCase, coll, &options, options.limit) < 0)
return DPI_FAILURE;
options.skip = 40;
options.limit = 20;
if (dpiTest__countDocuments(testCase, coll, &options,
numDocs - options.skip) < 0)
return DPI_FAILURE;
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2613_verifyDocsWithLargeBytes(dpiTestCase *testCase,
dpiTestParams *params)
{
uint64_t numBytes[5] = {100000, 200000, 400000, 800000, 1048576};
uint64_t numRemoved, numDocs = 5, i, j, lower = 49, upper = 90;
const char *initStr = "{\"test\":\"", *termStr = "\"}";
const char *collName = "ODPIC_COLL_2613";
dpiSodaDoc *doc, *insertedDoc, *replacedDoc;
uint64_t initStrLength = strlen(initStr);
uint64_t termStrLength = strlen(termStr);
char *content, *replaceContent;
dpiSodaOperOptions options;
dpiContext *context;
dpiSodaColl *coll;
dpiSodaDb *db;
int replaced;
content = malloc(numBytes[numDocs - 1] + 1);
replaceContent = malloc(numBytes[numDocs - 1] + 1);
if (!content || !replaceContent)
return dpiTestCase_setFailed(testCase, "Out of memory!");
strcpy(content, initStr);
strcpy(replaceContent, initStr);
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiTestSuite_getContext(&context);
for (i = 0; i < numDocs; i++) {
for (j = initStrLength; j < numBytes[i] - termStrLength; j++) {
content[j] = (rand() % (upper - lower + 1)) + lower;
replaceContent[j] = (rand() % (upper - lower + 1)) + lower;
}
strcpy(&content[numBytes[i] - termStrLength], termStr);
strcpy(&replaceContent[numBytes[i] - termStrLength], termStr);
if (dpiTest__insertDoc(testCase, db, content, coll, &insertedDoc) < 0)
return DPI_FAILURE;
if (dpiContext_initSodaOperOptions(context, &options) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_getKey(insertedDoc, &options.key,
&options.keyLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__verifyContent(testCase, coll, &options, content) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createDocument(db, NULL, 0, replaceContent,
strlen(replaceContent), NULL, 0, DPI_SODA_FLAGS_DEFAULT,
&doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_replaceOne(coll, &options, doc,
DPI_SODA_FLAGS_ATOMIC_COMMIT, &replaced, &replacedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_release(doc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, replaced, 1) < 0)
return DPI_FAILURE;
if (dpiTest__verifyContent(testCase, coll, &options,
replaceContent) < 0)
return DPI_FAILURE;
if (dpiSodaColl_remove(coll, &options, DPI_SODA_FLAGS_ATOMIC_COMMIT,
&numRemoved) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, numRemoved, 1) < 0)
return DPI_FAILURE;
if (dpiSodaDoc_release(insertedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaDoc_release(replacedDoc) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
free(content);
free(replaceContent);
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2614_verifyInsertManyWorksAsExpected(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *contents[4] = {
"{\"test1\" : \"2614 content1\"}",
"{\"test2\" : \"2614 content2\"}",
"{\"test3\" : \"2614 content3\"}",
"{\"test4\" : \"2614 content4\"}"
};
const char *collName = "ODPIC_COLL_2614";
dpiSodaDoc **insertedDocs;
uint32_t numDocs = 4;
uint64_t docCount;
dpiSodaColl *coll;
dpiSodaDb *db;
if (dpiTestCase_setSkippedIfVersionTooOld(testCase, 0, 18, 5) < 0)
return DPI_FAILURE;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiSodaColl_remove(coll, NULL, DPI_SODA_FLAGS_ATOMIC_COMMIT,
&docCount) < 0)
return dpiTestCase_setFailedFromError(testCase);
insertedDocs = malloc(numDocs * sizeof(dpiSodaDoc*));
if (!insertedDocs)
return dpiTestCase_setFailed(testCase, "Out of memory!");
if (dpiTest__insertManyDocs(testCase, db, coll, numDocs, contents,
insertedDocs) < 0)
return DPI_FAILURE;
free(insertedDocs);
if (dpiTest__insertManyDocs(testCase, db, coll, numDocs, contents,
NULL) < 0)
return DPI_FAILURE;
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int dpiTest_2615_testInsertManyWithInvalidJson(dpiTestCase *testCase,
dpiTestParams *params)
{
const char *contents[5] = {
"{\"test1\" : \"2615 content1\"}",
"{\"test2\" : \"2615 content2\"}",
"{\"test3\" : \"2615 content3\"}",
"{\"test4 : 2615 content4\"}",
"{\"test5\" : \"2615 content5\"}",
};
const char *collName = "ODPIC_COLL_2615";
uint32_t i, numDocs = 5;
dpiErrorInfo errorInfo;
dpiSodaColl *coll;
dpiSodaDoc **docs;
dpiSodaDb *db;
if (dpiTestCase_setSkippedIfVersionTooOld(testCase, 0, 18, 5) < 0)
return DPI_FAILURE;
if (dpiTestCase_getSodaDb(testCase, &db) < 0)
return DPI_FAILURE;
if (dpiSodaDb_createCollection(db, collName, strlen(collName), NULL, 0,
DPI_SODA_FLAGS_DEFAULT, &coll) < 0)
return dpiTestCase_setFailedFromError(testCase);
docs = malloc(numDocs * sizeof(dpiSodaDoc*));
if (!docs)
return dpiTestCase_setFailed(testCase, "Out of memory!");
for (i = 0; i < numDocs; i++) {
if (dpiSodaDb_createDocument(db, NULL, 0, contents[i],
strlen(contents[i]), NULL, 0, DPI_SODA_FLAGS_DEFAULT,
&docs[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
dpiSodaColl_insertMany(coll, numDocs, docs, DPI_SODA_FLAGS_ATOMIC_COMMIT,
NULL);
if (dpiTestCase_expectError(testCase, "ORA-02290:") < 0)
return DPI_FAILURE;
dpiTestSuite_getErrorInfo(&errorInfo);
if (dpiTestCase_expectIntEqual(testCase, errorInfo.offset, 3) < 0)
return DPI_FAILURE;
for (i = 0; i < numDocs; i++) {
if (dpiSodaDoc_release(docs[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
free(docs);
if (dpiTestCase_cleanupSodaColl(testCase, coll) < 0)
return DPI_FAILURE;
if (dpiSodaDb_release(db) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
int main(int argc, char **argv)
{
dpiTestSuite_initialize(2600);
dpiTestSuite_addCase(dpiTest_2600_nullHandle,
"call SODA collection functions with NULL handle");
dpiTestSuite_addCase(dpiTest_2601_addRef,
"dpiSodaColl_addRef() with valid parameters");
dpiTestSuite_addCase(dpiTest_2602_replaceDoc,
"dpiSodaColl_replaceOne() with valid parameters");
dpiTestSuite_addCase(dpiTest_2603_removeDoc,
"dpiSodaColl_remove() with valid parameters");
dpiTestSuite_addCase(dpiTest_2604_dropColl,
"dpiSodaColl_drop() with valid parameters");
dpiTestSuite_addCase(dpiTest_2605_createAndDropIndex,
"dpiSodaColl_dropIndex() with valid parameters");
dpiTestSuite_addCase(dpiTest_2606_getDocCount,
"dpiSodaColl_getDocCount() with valid parameters");
dpiTestSuite_addCase(dpiTest_2607_getCollName,
"dpiSodaColl_getName() with valid parameters");
dpiTestSuite_addCase(dpiTest_2608_getMetadata,
"dpiSodaColl_getMetadata() with valid parameters");
dpiTestSuite_addCase(dpiTest_2609_verifyFind,
"dpiSodaColl_find() with valid parameters");
dpiTestSuite_addCase(dpiTest_2610_testInvalidJson,
"dpiSodaColl_insertOne() with invalid JSON");
dpiTestSuite_addCase(dpiTest_2611_verifyKeys,
"verify find, getDocCount, remove with multiple keys");
dpiTestSuite_addCase(dpiTest_2612_verifySkipAndLimit,
"dpiSodaColl_find() with skip and limit");
dpiTestSuite_addCase(dpiTest_2613_verifyDocsWithLargeBytes,
"verify documents with large data");
dpiTestSuite_addCase(dpiTest_2614_verifyInsertManyWorksAsExpected,
"dpiSodaColl_insertMany() with valid parameters");
dpiTestSuite_addCase(dpiTest_2615_testInsertManyWithInvalidJson,
"dpiSodaColl_insertMany() with invalid JSON");
return dpiTestSuite_run();
}