File: test_4000_queue.c

package info (click to toggle)
odpic 5.6.4-1
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 4,320 kB
  • sloc: ansic: 42,451; sql: 2,153; makefile: 218; python: 123; sh: 15
file content (712 lines) | stat: -rw-r--r-- 28,280 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
//-----------------------------------------------------------------------------
// Copyright (c) 2019, 2025, Oracle and/or its affiliates.
//
// This software is dual-licensed to you under the Universal Permissive License
// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
// either license.
//
// If you elect to accept the software under the Apache License, Version 2.0,
// the following applies:
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// test_4000_queue.c
//   Test suite for testing all the features of AQ queues.
//-----------------------------------------------------------------------------

#include "TestLib.h"

#define RAW_QUEUE_NAME                  "RAW_QUEUE"
#define NUM_MESSAGES                    12
#define NUM_BATCH_ENQ                   5
#define NUM_BATCH_DEQ                   8

#define OBJ_QUEUE_NAME                  "BOOK_QUEUE"
#define QUEUE_OBJECT_TYPE               "UDT_BOOK"
#define NUM_ATTRS                       3

struct bookType {
    char *title;
    char *authors;
    double price;
};


//-----------------------------------------------------------------------------
// dpiTest__clearQueue()
//   Dequeue all messages from the queue to ensure that we are starting with
// an empty queue.
//-----------------------------------------------------------------------------
int dpiTest__clearQueue(dpiTestCase *testCase, dpiConn *conn,
        const char *name, dpiObjectType *objType)
{
    dpiDeqOptions *deqOptions;
    dpiMsgProps *props;
    dpiQueue *queue;

    // create queue
    if (dpiConn_newQueue(conn, name, strlen(name), objType, &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // get dequeue options from queue and specify that waiting should not be
    // done for messages
    if (dpiQueue_getDeqOptions(queue, &deqOptions) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setWait(deqOptions, DPI_DEQ_WAIT_NO_WAIT) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // perform dequeue until all messages have been dequeued
    while (1) {
        if (dpiQueue_deqOne(queue, &props) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (!props)
            break;
        if (dpiMsgProps_release(props) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_4000()
//   Call each of the dpiQueue public functions with the queue parameter set to
// NULL (error DPI-1002).
//-----------------------------------------------------------------------------
int dpiTest_4000(dpiTestCase *testCase, dpiTestParams *params)
{
    const char *expectedError = "DPI-1002:";

    dpiQueue_addRef(NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiQueue_deqMany(NULL, NULL, NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiQueue_deqOne(NULL, NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiQueue_enqMany(NULL, 0, NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiQueue_enqOne(NULL, NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiQueue_getDeqOptions(NULL, NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiQueue_getEnqOptions(NULL, NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;
    dpiQueue_release(NULL);
    if (dpiTestCase_expectError(testCase, expectedError) < 0)
        return DPI_FAILURE;

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_4001()
//   Create a queue, then call dpiQueue_release() twice (error DPI-1002).
//-----------------------------------------------------------------------------
int dpiTest_4001(dpiTestCase *testCase, dpiTestParams *params)
{
    dpiQueue *queue;
    dpiConn *conn;

    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_newQueue(conn, RAW_QUEUE_NAME, strlen(RAW_QUEUE_NAME), NULL,
            &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    dpiQueue_release(queue);
    return dpiTestCase_expectError(testCase, "DPI-1002:");
}


//-----------------------------------------------------------------------------
// dpiTest_4002()
//   Create a queue and then call dpiQueue_enqMany() without setting any
// payload (error DPI-1070), with the message properties parameter set to NULL
// (error DPI-1046) and with the number of properties set to zero (no error).
//-----------------------------------------------------------------------------
int dpiTest_4002(dpiTestCase *testCase, dpiTestParams *params)
{
    dpiMsgProps *enqProps[NUM_BATCH_ENQ];
    dpiQueue *queue;
    dpiConn *conn;
    uint32_t i;

    // create queue
    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_newQueue(conn, RAW_QUEUE_NAME, strlen(RAW_QUEUE_NAME), NULL,
            &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // create some message properties to enqueue but don't set any payloads
    for (i = 0; i < NUM_BATCH_ENQ; i++) {
        if (dpiConn_newMsgProps(conn, &enqProps[i]) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }

    // perform various tests
    dpiQueue_enqMany(queue, NUM_BATCH_ENQ, enqProps);
    if (dpiTestCase_expectError(testCase, "DPI-1070:") < 0)
        return DPI_FAILURE;
    dpiQueue_enqMany(queue, NUM_BATCH_ENQ, NULL);
    if (dpiTestCase_expectError(testCase, "DPI-1046:") < 0)
        return DPI_FAILURE;
    if (dpiQueue_enqMany(queue, 0, enqProps) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // cleanup
    for (i = 0; i < NUM_BATCH_ENQ; i++) {
        if (dpiMsgProps_release(enqProps[i]) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_4003()
//   Create a queue and then call dpiQueue_deqMany() on an empty queue
// (no error), number of properties set to 0 (error ORA-25327) and with the
// different parameters set to NULL (error DPI-1046).
//-----------------------------------------------------------------------------
int dpiTest_4003(dpiTestCase *testCase, dpiTestParams *params)
{
    dpiMsgProps *deqProps[NUM_BATCH_DEQ];
    dpiDeqOptions *deqOptions;
    uint32_t numMessages;
    dpiQueue *queue;
    dpiConn *conn;

    // create queue; ensure it is cleared so that errors don't cascade
    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiTest__clearQueue(testCase, conn, RAW_QUEUE_NAME, NULL) < 0)
        return DPI_FAILURE;
    if (dpiConn_newQueue(conn, RAW_QUEUE_NAME, strlen(RAW_QUEUE_NAME), NULL,
            &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // get dequeue options from queue and set some options
    if (dpiQueue_getDeqOptions(queue, &deqOptions) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setNavigation(deqOptions, DPI_DEQ_NAV_FIRST_MSG) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setWait(deqOptions, DPI_DEQ_WAIT_NO_WAIT) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // perform various tests
    numMessages = NUM_BATCH_DEQ;
    if (dpiQueue_deqMany(queue, &numMessages, deqProps) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTestCase_expectUintEqual(testCase, numMessages, 0) < 0)
        return DPI_FAILURE;
    dpiQueue_deqMany(queue, &numMessages, deqProps);
    if (dpiTestCase_expectError(testCase, "ORA-25327:") < 0)
        return DPI_FAILURE;
    dpiQueue_deqMany(queue, NULL, deqProps);
    if (dpiTestCase_expectError(testCase, "DPI-1046:") < 0)
        return DPI_FAILURE;
    dpiQueue_deqMany(queue, &numMessages, NULL);
    if (dpiTestCase_expectError(testCase, "DPI-1046:") < 0)
        return DPI_FAILURE;

    // cleanup
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_4004()
//   Create a queue and then call dpiQueue_enqOne() without setting a payload
// (error DPI-1070) and with the different parameters set to NULL (error
// DPI-1002).
//-----------------------------------------------------------------------------
int dpiTest_4004(dpiTestCase *testCase, dpiTestParams *params)
{
    dpiMsgProps *msgProps;
    dpiQueue *queue;
    dpiConn *conn;

    // create queue
    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_newQueue(conn, RAW_QUEUE_NAME, strlen(RAW_QUEUE_NAME), NULL,
            &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiConn_newMsgProps(conn, &msgProps) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // perform various tests
    dpiQueue_enqOne(queue, msgProps);
    if (dpiTestCase_expectError(testCase, "DPI-1070:") < 0)
        return DPI_FAILURE;
    dpiQueue_enqOne(queue, NULL);
    if (dpiTestCase_expectError(testCase, "DPI-1002:") < 0)
        return DPI_FAILURE;

    // cleanup
    if (dpiMsgProps_release(msgProps) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_4005()
//   Create a queue and then call dpiQueue_deqOne() on an empty queue (no
// error) and with the different parameters set to null (error DPI-1046).
//-----------------------------------------------------------------------------
int dpiTest_4005(dpiTestCase *testCase, dpiTestParams *params)
{
    dpiDeqOptions *deqOptions;
    dpiMsgProps *props;
    dpiQueue *queue;
    dpiConn *conn;

    // create queue; ensure it is cleared so that errors don't cascade
    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiTest__clearQueue(testCase, conn, RAW_QUEUE_NAME, NULL) < 0)
        return DPI_FAILURE;
    if (dpiConn_newQueue(conn, RAW_QUEUE_NAME, strlen(RAW_QUEUE_NAME), NULL,
            &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // get dequeue options from queue and set some options
    if (dpiQueue_getDeqOptions(queue, &deqOptions) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setNavigation(deqOptions, DPI_DEQ_NAV_FIRST_MSG) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setWait(deqOptions, DPI_DEQ_WAIT_NO_WAIT) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // perform various tests
    if (dpiQueue_deqOne(queue, &props) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (props)
        return dpiTestCase_setFailed(testCase,
                "dequeue on empty queue should have NULL result");
    dpiQueue_deqOne(queue, NULL);
    if (dpiTestCase_expectError(testCase, "DPI-1046:") < 0)
        return DPI_FAILURE;

    // cleanup
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_4006()
//   Create a queue and then enqueue some messages in batches. Verify that the
// messages can then be dequeued and match what was enqueued (no error).
//-----------------------------------------------------------------------------
int dpiTest_4006(dpiTestCase *testCase, dpiTestParams *params)
{
    dpiMsgProps *enqProps[NUM_BATCH_ENQ], *deqProps[NUM_BATCH_DEQ];
    uint32_t i, pos, numMessages, payloadLength;
    const char *payloads[NUM_MESSAGES] = {
        "The first message",
        "The second message",
        "The third message",
        "The fourth message",
        "The fifth message",
        "The sixth message",
        "The seventh message",
        "The eighth message",
        "The ninth message",
        "The tenth message",
        "The eleventh message",
        "The twelfth and final message"
    };
    dpiDeqOptions *deqOptions;
    const char *payload;
    dpiQueue *queue;
    dpiConn *conn;

    // create queue; ensure it is cleared so that errors don't cascade
    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiTest__clearQueue(testCase, conn, RAW_QUEUE_NAME, NULL) < 0)
        return DPI_FAILURE;
    if (dpiConn_newQueue(conn, RAW_QUEUE_NAME, strlen(RAW_QUEUE_NAME), NULL,
            &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // create some messages to be used for enqueuing
    for (i = 0; i < NUM_BATCH_ENQ; i++) {
        if (dpiConn_newMsgProps(conn, &enqProps[i]) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }

    // enqueue messages in batches
    for (i = 0, pos = 0; i < NUM_MESSAGES; i++) {
        if (dpiMsgProps_setPayloadBytes(enqProps[pos], payloads[i],
                strlen(payloads[i])) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (++pos == NUM_BATCH_ENQ || i == NUM_MESSAGES - 1) {
            if (dpiQueue_enqMany(queue, pos, enqProps) < 0)
                return dpiTestCase_setFailedFromError(testCase);
            pos = 0;
        }
    }
    for (i = 0; i < NUM_BATCH_ENQ; i++) {
        if (dpiMsgProps_release(enqProps[i]) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }

    // get dequeue options from queue and set some options
    if (dpiQueue_getDeqOptions(queue, &deqOptions) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setNavigation(deqOptions, DPI_DEQ_NAV_FIRST_MSG) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setWait(deqOptions, DPI_DEQ_WAIT_NO_WAIT) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // dequeue messages and verify they match what was enqueued
    pos = 0;
    while (1) {
        numMessages = NUM_BATCH_DEQ;
        if (dpiQueue_deqMany(queue, &numMessages, deqProps) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (numMessages == 0)
            break;
        for (i = 0; i < numMessages; i++, pos++) {
            if (dpiMsgProps_getPayload(deqProps[i], NULL, &payload,
                    &payloadLength) < 0)
                return dpiTestCase_setFailedFromError(testCase);
            if (dpiTestCase_expectStringEqual(testCase, payload, payloadLength,
                    payloads[pos], strlen(payloads[pos])) < 0)
                return DPI_FAILURE;
            if (dpiMsgProps_release(deqProps[i]) < 0)
                return dpiTestCase_setFailedFromError(testCase);
        }
    }
    if (dpiTestCase_expectUintEqual(testCase, pos, NUM_MESSAGES) < 0)
        return DPI_FAILURE;

    // cleanup
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_4007()
//   Create a queue and then enqueue some objects in batches. Verify that the
// objects can then be dequeued and match what was enqueued (no error).
//-----------------------------------------------------------------------------
int dpiTest_4007(dpiTestCase *testCase, dpiTestParams *params)
{
    dpiMsgProps *enqProps[NUM_BATCH_ENQ], *deqProps[NUM_BATCH_DEQ];
    struct bookType books[NUM_MESSAGES] = {
        { "Oracle Call Interface Programmers Guide", "Oracle", 0 },
        { "Oracle Call Interface Programmers Guide 1", "Oracle 1", 1.23 },
        { "Oracle Call Interface Programmers Guide 2", "Oracle 2", 2.34 },
        { "Oracle Call Interface Programmers Guide 3", "Oracle 3", 3.34 },
        { "Oracle Call Interface Programmers Guide 4", "Oracle 4", 4.34 },
        { "Oracle Call Interface Programmers Guide 5", "Oracle 5", 5.34 },
        { "Oracle Call Interface Programmers Guide 6", "Oracle 6", 6.66 },
        { "Oracle Call Interface Programmers Guide 7", "Oracle 7", 7.34 },
        { "Oracle Call Interface Programmers Guide 8", "Oracle 8", 8.99 },
        { "Oracle Call Interface Programmers Guide 9", "Oracle 9", 9.99 },
        { "Oracle Call Interface Programmers Guide 10", "Oracle 10", 10.11 },
        { "Selecting Employees", "Scott Tiger", 7.99 }
    };
    dpiObjectAttr *attrs[NUM_ATTRS];
    uint32_t i, pos, numMessages;
    dpiDeqOptions *deqOptions;
    dpiObjectType *objType;
    dpiObject *bookObj;
    dpiData attrValue;
    dpiQueue *queue;
    dpiConn *conn;

    // create queue; ensure it is cleared so that errors don't cascade
    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiConn_getObjectType(conn, QUEUE_OBJECT_TYPE,
            strlen(QUEUE_OBJECT_TYPE), &objType) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiObjectType_getAttributes(objType, NUM_ATTRS, attrs) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTest__clearQueue(testCase, conn, OBJ_QUEUE_NAME, objType) < 0)
        return DPI_FAILURE;
    if (dpiConn_newQueue(conn, OBJ_QUEUE_NAME, strlen(OBJ_QUEUE_NAME), objType,
            &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // create some messages to be used for enqueuing
    for (i = 0; i < NUM_BATCH_ENQ; i++) {
        if (dpiConn_newMsgProps(conn, &enqProps[i]) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }

    // enqueue messages in batches
    for (i = 0, pos = 0; i < NUM_MESSAGES; i++) {

        // create new object
        if (dpiObjectType_createObject(objType, &bookObj) < 0)
            return dpiTestCase_setFailedFromError(testCase);

        // set title
        dpiData_setBytes(&attrValue, books[i].title, strlen(books[i].title));
        if (dpiObject_setAttributeValue(bookObj, attrs[0],
                DPI_NATIVE_TYPE_BYTES, &attrValue) < 0)
            return dpiTestCase_setFailedFromError(testCase);

        // set authors
        dpiData_setBytes(&attrValue, books[i].authors,
                strlen(books[i].authors));
        if (dpiObject_setAttributeValue(bookObj, attrs[1],
                DPI_NATIVE_TYPE_BYTES, &attrValue) < 0)
            return dpiTestCase_setFailedFromError(testCase);

        // set price
        dpiData_setDouble(&attrValue, books[i].price);
        if (dpiObject_setAttributeValue(bookObj, attrs[2],
                DPI_NATIVE_TYPE_DOUBLE, &attrValue) < 0)
            return dpiTestCase_setFailedFromError(testCase);

        // set payload
        if (dpiMsgProps_setPayloadObject(enqProps[pos], bookObj) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (dpiObject_release(bookObj) < 0)
            return dpiTestCase_setFailedFromError(testCase);

        // perform enqueue once the batch has been filled or there are no more
        // messages
        if (++pos == NUM_BATCH_ENQ || i == NUM_MESSAGES - 1) {
            if (dpiQueue_enqMany(queue, pos, enqProps) < 0)
                return dpiTestCase_setFailedFromError(testCase);
            pos = 0;
        }

    }

    // cleanup enqueue
    for (i = 0; i < NUM_BATCH_ENQ; i++) {
        if (dpiMsgProps_release(enqProps[i]) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }
    if (dpiObjectType_release(objType) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // get dequeue options from queue and set some options
    if (dpiQueue_getDeqOptions(queue, &deqOptions) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setNavigation(deqOptions, DPI_DEQ_NAV_FIRST_MSG) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setWait(deqOptions, DPI_DEQ_WAIT_NO_WAIT) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // dequeue messages and verify they match what was enqueued
    pos = 0;
    while (1) {
        numMessages = NUM_BATCH_DEQ;
        if (dpiQueue_deqMany(queue, &numMessages, deqProps) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (numMessages == 0)
            break;
        for (i = 0; i < numMessages; i++, pos++) {

            // get payload
            if (dpiMsgProps_getPayload(deqProps[i], &bookObj, NULL, NULL) < 0)
                return dpiTestCase_setFailedFromError(testCase);

            // verify title matches
            if (dpiObject_getAttributeValue(bookObj, attrs[0],
                    DPI_NATIVE_TYPE_BYTES, &attrValue) < 0)
                return dpiTestCase_setFailedFromError(testCase);
            if (dpiTestCase_expectStringEqual(testCase,
                    attrValue.value.asBytes.ptr,
                    attrValue.value.asBytes.length, books[pos].title,
                    strlen(books[pos].title)) < 0)
                return DPI_FAILURE;

            // verify authors match
            if (dpiObject_getAttributeValue(bookObj, attrs[1],
                    DPI_NATIVE_TYPE_BYTES, &attrValue) < 0)
                return dpiTestCase_setFailedFromError(testCase);
            if (dpiTestCase_expectStringEqual(testCase,
                attrValue.value.asBytes.ptr, attrValue.value.asBytes.length,
                books[pos].authors, strlen(books[pos].authors)) < 0)
                return DPI_FAILURE;

            // verify price matches
            if (dpiObject_getAttributeValue(bookObj, attrs[2],
                    DPI_NATIVE_TYPE_DOUBLE, &attrValue) < 0)
                return dpiTestCase_setFailedFromError(testCase);
            if (dpiTestCase_expectDoubleEqual(testCase,
                    attrValue.value.asDouble, books[pos].price) < 0)
                return DPI_FAILURE;

            // cleanup
            if (dpiMsgProps_release(deqProps[i]) < 0)
                return dpiTestCase_setFailedFromError(testCase);
        }
    }
    if (dpiTestCase_expectUintEqual(testCase, pos, NUM_MESSAGES) < 0)
        return DPI_FAILURE;

    // cleanup
    for (i = 0; i < NUM_ATTRS; i++) {
        if (dpiObjectAttr_release(attrs[i]) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}


//-----------------------------------------------------------------------------
// dpiTest_4008()
//   Create a queue and then enqueue some messages. Verify that the
// message can then be dequeued using msgId(no error).
//-----------------------------------------------------------------------------
int dpiTest_4008(dpiTestCase *testCase, dpiTestParams *params)
{
    const char *payloads[NUM_MESSAGES] = {
        "The first message",
        "The second message",
        "The third message",
        "The fourth message",
        "The fifth message",
        "The sixth message",
        "The seventh message",
        "The eighth message",
        "The ninth message",
        "The tenth message",
        "The eleventh message",
        "The twelfth and final message"
    };
    dpiDeqOptions *deqOptions;
    uint32_t payloadLength;
    dpiMsgProps *msgProps;
    const char *payload;
    const char *msg;
    uint32_t msgLen;
    dpiQueue *queue;
    dpiConn *conn;
    uint32_t i;

    // connect to database
    if (dpiTestCase_getConnection(testCase, &conn) < 0)
        return DPI_FAILURE;
    if (dpiTest__clearQueue(testCase, conn, RAW_QUEUE_NAME, NULL) < 0)
        return DPI_FAILURE;
    if (dpiConn_newQueue(conn, RAW_QUEUE_NAME, strlen(RAW_QUEUE_NAME), NULL,
            &queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiConn_newMsgProps(conn, &msgProps) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    // enqueue messages
    for (i = 0; i < NUM_MESSAGES; i++) {
        if (dpiMsgProps_setPayloadBytes(msgProps, payloads[i],
                strlen(payloads[i])) < 0)
            return dpiTestCase_setFailedFromError(testCase);
        if (dpiQueue_enqOne(queue, msgProps) < 0)
            return dpiTestCase_setFailedFromError(testCase);
    }

    if (dpiMsgProps_getMsgId(msgProps, &msg, &msgLen) < 0)
            return dpiTestCase_setFailedFromError(testCase);

    // get dequeue options from queue and set some options
    if (dpiQueue_getDeqOptions(queue, &deqOptions) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setNavigation(deqOptions, DPI_DEQ_NAV_FIRST_MSG) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setWait(deqOptions, DPI_DEQ_WAIT_NO_WAIT) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiDeqOptions_setMsgId(deqOptions, msg, msgLen) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiMsgProps_release(msgProps) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiQueue_deqOne(queue, &msgProps) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiMsgProps_getPayload(msgProps, NULL, &payload,
            &payloadLength) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiTestCase_expectStringEqual(testCase, payload, payloadLength,
            payloads[NUM_MESSAGES - 1],
            strlen(payloads[NUM_MESSAGES - 1])) < 0)
        return DPI_FAILURE;

    // cleanup
    if (dpiQueue_release(queue) < 0)
        return dpiTestCase_setFailedFromError(testCase);
    if (dpiMsgProps_release(msgProps) < 0)
        return dpiTestCase_setFailedFromError(testCase);

    return DPI_SUCCESS;
}

//-----------------------------------------------------------------------------
// main()
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
    dpiTestSuite_initialize(4000);
    dpiTestSuite_addCase(dpiTest_4000,
            "call public functions with queue set to NULL");
    dpiTestSuite_addCase(dpiTest_4001,
            "call dpiQueue_release() twice");
    dpiTestSuite_addCase(dpiTest_4002,
            "call dpiQueue_enqMany() with various parameters");
    dpiTestSuite_addCase(dpiTest_4003,
            "call dpiQueue_deqMany() with various parameters");
    dpiTestSuite_addCase(dpiTest_4004,
            "call dpiQueue_enqOne() with various parameters");
    dpiTestSuite_addCase(dpiTest_4005,
            "call dpiQueue_deqOne() with various parameters");
    dpiTestSuite_addCase(dpiTest_4006,
            "bulk dequeue of raw data matches what was enqueued");
    dpiTestSuite_addCase(dpiTest_4007,
            "bulk dequeue of objects matches what was enqueued");
    dpiTestSuite_addCase(dpiTest_4008,
            "verify dequeue by message id");

    return dpiTestSuite_run();
}