-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy_api_test.go
1043 lines (977 loc) · 44.1 KB
/
easy_api_test.go
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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2018-2022 YottaDB LLC and/or its subsidiaries. //
// All rights reserved. //
// //
// This source code contains the intellectual property //
// of its copyright holder(s), and is made available //
// under a license. If you do not know the terms of //
// the license, please stop and do not read further. //
// //
//////////////////////////////////////////////////////////////////
package yottadb_test
import (
"lang.yottadb.com/go/yottadb"
. "lang.yottadb.com/go/yottadb/internal/test_helpers"
"strconv"
"testing"
)
func TestDataE(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var dval uint32
var errstr yottadb.BufferT
errstr.Alloc(128)
// Create a few nodes so we can check DataE() on them
err = yottadb.SetValE(tptoken, &errstr, "val1", "^tdaNoSubs", []string{})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val2", "^tdaSubs", []string{"sub1", "sub2"})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val3", "^tdaSubs", []string{"sub1", "sub2", "sub3"})
Assertnoerr(err, t)
// Check against a non-existent node - should return 0
dval, err = yottadb.DataE(tptoken, &errstr, "^noExistGbl", []string{})
Assertnoerr(err, t)
if 0 != int(dval) {
t.Error("FAIL - The DataE() value for ^noExistGbl expected to be 0 but was", dval)
}
// Check node with value but no subscripts - should be 1
dval, err = yottadb.DataE(tptoken, &errstr, "^tdaNoSubs", []string{})
Assertnoerr(err, t)
if yottadb.YDB_DATA_VALUE_NODESC != int(dval) {
t.Error("The DataE() value for ^tdaNoSubs expected to be 1 but was", dval)
}
// Check against a subscripted node with no value but has descendants
dval, err = yottadb.DataE(tptoken, &errstr, "^tdaSubs", []string{"sub1"})
Assertnoerr(err, t)
if yottadb.YDB_DATA_NOVALUE_DESC != int(dval) {
t.Error("The DataE() value for ^tdaSubs(\"sub1\") expected to be 10 but was", dval)
}
// Check against a subscripted node with a value and descendants
dval, err = yottadb.DataE(tptoken, &errstr, "^tdaSubs", []string{"sub1", "sub2"})
Assertnoerr(err, t)
if yottadb.YDB_DATA_VALUE_DESC != int(dval) {
t.Error("The DataE() value for ^tdaSubs(\"sub1\",\"sub2\") expected to be 11 but was", dval)
}
// Check if return value set correctly on an error by giving it an invalid var name
dval, err = yottadb.DataE(tptoken, &errstr, "12345", []string{})
if yottadb.YDB_DATA_ERROR != int(dval) {
t.Error("The DataE() return value for an invalid varname expected to be YDB_DATA_NOERROR but was", dval)
}
}
func TestDataEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
_, err = yottadb.DataE(tptoken, &errstr, "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The DataE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
_, err = yottadb.DataE(tptoken, &errstr, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The DataE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
_, err = yottadb.DataE(tptoken, &errstr, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The DataE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
_, err = yottadb.DataE(yottadb.NOTTP, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The DataE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
_, err = yottadb.DataE(yottadb.NOTTP, &errstr, "a", []string{"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"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The DataE() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestDeleteE(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var dval uint32
var errstr yottadb.BufferT
errstr.Alloc(128)
// Create a few nodes so we can check DataE() on them
err = yottadb.SetValE(tptoken, &errstr, "val1", "^tdaNoSubs", []string{})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val2", "^tdaSubs", []string{"sub1", "sub2"})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val3", "^tdaSubs", []string{"sub1", "sub2", "sub3"})
Assertnoerr(err, t)
err = yottadb.DeleteE(tptoken, &errstr, yottadb.YDB_DEL_TREE, "^tdaSubs", []string{})
Assertnoerr(err, t)
dval, err = yottadb.DataE(tptoken, &errstr, "^tdaSubs", []string{})
Assertnoerr(err, t)
if 0 != dval {
t.Error("The ^tdaSubs node still exists after DeleteE() - DataE() returned:", dval)
}
err = yottadb.DeleteE(tptoken, &errstr, yottadb.YDB_DEL_NODE, "^tdaNoSubs", []string{})
Assertnoerr(err, t)
dval, err = yottadb.DataE(tptoken, &errstr, "^tdaNoSubs", []string{})
Assertnoerr(err, t)
if 0 != dval {
t.Error("The ^tdaNoSubs node still exists after DeleteE() - DataE() returned:", dval)
}
}
func TestDeleteEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
err = yottadb.DeleteE(tptoken, &errstr, yottadb.YDB_DEL_TREE, "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The DeleteE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED - from special variable
err = yottadb.DeleteE(tptoken, &errstr, yottadb.YDB_DEL_TREE, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The DeleteE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
err = yottadb.DeleteE(tptoken, &errstr, yottadb.YDB_DEL_TREE, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The DeleteE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
err = yottadb.DeleteE(yottadb.NOTTP, &errstr, yottadb.YDB_DEL_TREE, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The DeleteE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
err = yottadb.DeleteE(yottadb.NOTTP, &errstr, yottadb.YDB_DEL_TREE, "a", []string{"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"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The DeleteE() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_UNIMPLOP - from bad deltype parm (not YDB_DEL_NODE/TREE)
err = yottadb.DeleteE(tptoken, &errstr, 999, "^deletethis", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_UNIMPLOP != errcode {
t.Error("The DeleteE() errorcode for deltype 999 expected to be", yottadb.YDB_ERR_UNIMPLOP, "but was", errcode)
}
}
func TestDeleteExclE(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errcode int
var errstr yottadb.BufferT
errstr.Alloc(128)
// We need to create 4 local variables to test this so do that first (thus also testing KeyT.SetValE()
err = yottadb.SetValE(tptoken, &errstr, "I have a value", "var1", []string{"sub1", "sub2"})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "I wish I was a value", "var2", []string{})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "I was a value", "var3", []string{"sub1"})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "I AM A VALUE", "var4", []string{})
Assertnoerr(err, t)
_, err = yottadb.ValE(tptoken, &errstr, "var1", []string{"sub1", "sub2"})
// Now delete var1 and var3 by exclusively keeping var2 and var4
err = yottadb.DeleteExclE(tptoken, &errstr, []string{"var2", "var4"})
Assertnoerr(err, t)
// OK, delete done, see which vars exist
_, err = yottadb.ValE(tptoken, &errstr, "var1", []string{"sub1", "sub2"}) // Expect this var to be gone
if nil == err {
t.Error("var1 found when it should have been deleted (no error occurred when fetched")
}
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_LVUNDEF != errcode { // YDB_ERR_LVUNDEF
t.Error("The ValE() errorcode for var1(\"sub1\",\"sub2\") expected to be", yottadb.YDB_ERR_LVUNDEF, "but was", errcode)
}
_, err = yottadb.ValE(tptoken, &errstr, "var2", []string{})
if nil != err {
t.Error("var2 not found when it should still exist (if ever existed)")
}
_, err = yottadb.ValE(tptoken, &errstr, "var3", []string{"sub1"})
if nil == err {
t.Error("var3 found when it should have been deleted (no error occurred when fetched")
}
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_LVUNDEF != errcode { // YDB_ERR_LVUNDEF
t.Error("The ValE() errorcode for var3(\"sub1\") expected to be", yottadb.YDB_ERR_LVUNDEF, "but was", errcode)
}
_, err = yottadb.ValE(tptoken, &errstr, "var4", []string{})
if nil != err {
t.Error("var4 not found when it should still exist (if ever existed)")
}
// Pass an empty array check that it deletes var2 and var4
err = yottadb.DeleteExclE(tptoken, &errstr, []string{})
Assertnoerr(err, t)
_, err = yottadb.ValE(tptoken, &errstr, "var2", []string{}) // Expect this var to be gone
if nil == err {
t.Error("var2 found when it should have been deleted (no error occurred when fetched")
}
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_LVUNDEF != errcode { // YDB_ERR_LVUNDEF
t.Error("The ValE() errorcode for var2 expected to be", yottadb.YDB_ERR_LVUNDEF, "but was", errcode)
}
_, err = yottadb.ValE(tptoken, &errstr, "var4", []string{}) // Expect this var to be gone
if nil == err {
t.Error("var4 found when it should have been deleted (no error occurred when fetched")
}
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_LVUNDEF != errcode { // YDB_ERR_LVUNDEF
t.Error("The ValE() errorcode for var4 expected to be", yottadb.YDB_ERR_LVUNDEF, "but was", errcode)
}
}
func TestDeleteExclEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME - from passing a bad M name
err = yottadb.DeleteExclE(tptoken, &errstr, []string{"1"})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The DeleteExclE() errorcode for 1 expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED - from special variable
err = yottadb.DeleteExclE(tptoken, &errstr, []string{"$ZCHSET"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The DeleteExclE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_GVNUNSUPPORTED - from passing a global
err = yottadb.DeleteExclE(tptoken, &errstr, []string{"^a"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_GVNUNSUPPORTED != errcode {
t.Error("The DeleteExclE() errorcode for ^a expected to be", yottadb.YDB_ERR_GVNUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
err = yottadb.DeleteExclE(yottadb.NOTTP, &errstr, []string{"a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The DeleteExclE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_NAMECOUNT2HI
err = yottadb.DeleteExclE(yottadb.NOTTP, &errstr, []string{"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21", "a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30", "a31", "a32", "a33", "a34", "a35", "a36"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_NAMECOUNT2HI != errcode {
t.Error("The DeleteExclE() errorcode for node with 36 subscripts expected to be", yottadb.YDB_ERR_NAMECOUNT2HI, "but was", errcode)
}
}
func TestValE(t *testing.T) {
// Already tested in tests for TpST() and DeleteExclE()
}
func TestValEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
_, err = yottadb.ValE(tptoken, &errstr, "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The ValE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_GVUNDEF
_, err = yottadb.ValE(tptoken, &errstr, "^doesnotexist", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_GVUNDEF != errcode {
t.Error("The ValE() errorcode for ^doesnotexist expected to be", yottadb.YDB_ERR_GVUNDEF, "but was", errcode)
}
// YDB_ERR_LVUNDEF
_, err = yottadb.ValE(tptoken, &errstr, "doesnotexist", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_LVUNDEF != errcode {
t.Error("The ValE() errorcode for doesnotexist expected to be", yottadb.YDB_ERR_LVUNDEF, "but was", errcode)
}
// YDB_ERR_INVSVN
_, err = yottadb.ValE(tptoken, &errstr, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The ValE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
_, err = yottadb.ValE(yottadb.NOTTP, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The ValE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
_, err = yottadb.ValE(yottadb.NOTTP, &errstr, "a", []string{"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"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The ValE() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestIncrE(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var newvalA, newvalB string
var err error
var newvalBi int
var errstr yottadb.BufferT
errstr.Alloc(128)
// Create a simple subscripted node, then increment it, then fetch it and compare to returned value
// increment by a value (2)
err = yottadb.SetValE(tptoken, &errstr, "42", "^ivar", []string{"isub1"})
Assertnoerr(err, t)
newvalB, err = yottadb.IncrE(tptoken, &errstr, "2", "^ivar", []string{"isub1"})
Assertnoerr(err, t)
newvalBi, err = strconv.Atoi(newvalB)
Assertnoerr(err, t)
if 44 != newvalBi {
t.Error("The expected increment value is 44 but it is", newvalB)
}
// Fetch the value and verify same as what we got back from IncrST()
newvalA, err = yottadb.ValE(tptoken, &errstr, "^ivar", []string{"isub1"})
Assertnoerr(err, t)
if newvalA != newvalB {
t.Error("Returned and post-increment fetch values not same - db :", newvalA,
" returned: ", newvalB)
}
// increment by nil which should increase global by 1
newvalB, err = yottadb.IncrE(tptoken, &errstr, "", "^ivar", []string{"isub1"})
Assertnoerr(err, t)
newvalBi, err = strconv.Atoi(newvalB)
Assertnoerr(err, t)
if 45 != newvalBi {
t.Error("The expected increment value is 45 but it is", newvalB)
}
// Fetch the value and verify same as what we got back from IncrST()
newvalA, err = yottadb.ValE(tptoken, &errstr, "^ivar", []string{"isub1"})
Assertnoerr(err, t)
if newvalA != newvalB {
t.Error("Returned and post-increment fetch values not same - db :", newvalA,
" returned: ", newvalB)
}
// Increment a nonexistant node, check that it is set to the increment
newvalB, err = yottadb.IncrE(tptoken, &errstr, "9001", "^ivar", []string{"isub2"})
Assertnoerr(err, t)
newvalBi, err = strconv.Atoi(newvalB)
Assertnoerr(err, t)
if 9001 != newvalBi {
t.Error("The expected increment value is 9001 but it is", newvalB)
}
// Fetch the value and verify same as what we got back from IncrST()
newvalA, err = yottadb.ValE(tptoken, &errstr, "^ivar", []string{"isub2"})
Assertnoerr(err, t)
if newvalA != newvalB {
t.Error("Returned and post-increment fetch values not same - db :", newvalA,
" returned: ", newvalB)
}
// Increment a non-cannonical number, check that it is foreced to a number
err = yottadb.SetValE(tptoken, &errstr, "This is not a number", "^ivar", []string{"isub3"})
Assertnoerr(err, t)
newvalB, err = yottadb.IncrE(tptoken, &errstr, "1337", "^ivar", []string{"isub3"})
Assertnoerr(err, t)
newvalBi, err = strconv.Atoi(newvalB)
Assertnoerr(err, t)
if 1337 != newvalBi {
t.Error("The expected increment value is 1337 but it is", newvalB)
}
// Fetch the value and verify same as what we got back from IncrST()
newvalA, err = yottadb.ValE(tptoken, &errstr, "^ivar", []string{"isub3"})
Assertnoerr(err, t)
if newvalA != newvalB {
t.Error("Returned and post-increment fetch values not same - db :", newvalA,
" returned: ", newvalB)
}
}
func TestIncrEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
_, err = yottadb.IncrE(tptoken, &errstr, "", "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The IncrE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
_, err = yottadb.IncrE(tptoken, &errstr, "", "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The IncrE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
_, err = yottadb.IncrE(tptoken, &errstr, "", "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The IncrE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
_, err = yottadb.IncrE(yottadb.NOTTP, &errstr, "", "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The IncrE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
_, err = yottadb.IncrE(yottadb.NOTTP, &errstr, "", "a", []string{"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"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The IncrE() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_NUMOFLOW
_, err = yottadb.IncrE(tptoken, &errstr, "1E12345", "^ivar", []string{"newsub"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_NUMOFLOW != errcode {
t.Error("The IncrE() errorcode for incrementing by 1E12345 expected to be", yottadb.YDB_ERR_NUMOFLOW, "but was", errcode)
}
}
func TestLockE(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var timeout uint64
var errors int
var errstr yottadb.BufferT
errstr.Alloc(128)
// Take out 3 locks (2 global, 1 local) with one call and verify they are held. Note more than two subscripts breaks verifyLockExists()
err = yottadb.LockE(tptoken, &errstr, timeout, "^lock1", []string{"sub11", "sub12"}, "lock2", []string{}, "^lock3", []string{"sub21"})
Assertnoerr(err, t)
VerifyLockExists([]byte("^lock1(\"sub11\",\"sub12\")"), &errors, true, t)
VerifyLockExists([]byte("lock2"), &errors, true, t)
VerifyLockExists([]byte("^lock3(\"sub21\")"), &errors, true, t)
}
func TestLockEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
err = yottadb.LockE(tptoken, &errstr, 0, "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The LockE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
err = yottadb.LockE(tptoken, &errstr, 0, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The LockE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
err = yottadb.LockE(tptoken, &errstr, 0, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The LockE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
err = yottadb.LockE(yottadb.NOTTP, &errstr, 0, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The LockE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
err = yottadb.LockE(yottadb.NOTTP, &errstr, 0, "a", []string{"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", "a33", "a34", "a35"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The LockE() errorcode for node with 35 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_TIME2LONG
err = yottadb.LockE(tptoken, &errstr, yottadb.YDB_MAX_TIME_NSEC+1, "a", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_TIME2LONG != errcode {
t.Error("The LockE() errorcode for timeout of YDB_MAX_TIME_NSEC+1 expected to be", yottadb.YDB_ERR_TIME2LONG, "but was", errcode)
}
// YDB_ERR_NAMECOUNT2HI
err = yottadb.LockE(tptoken, &errstr, 0, "a1", []string{}, "a2", []string{}, "a3", []string{}, "a4", []string{}, "a5", []string{}, "a6", []string{}, "a7", []string{}, "a8", []string{}, "a9", []string{}, "a10", []string{}, "a11", []string{}, "a12", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_NAMECOUNT2HI != errcode {
t.Error("The LockE() errorcode for 12 lock pairs expected to be", yottadb.YDB_ERR_NAMECOUNT2HI, "but was", errcode)
}
// YDB_ERR_INVLKNMPAIRLIST
err = yottadb.LockE(tptoken, &errstr, 0, "a")
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVLKNMPAIRLIST != errcode {
t.Error("The LockE() errorcode for an incorrect pair expected to be", yottadb.YDB_ERR_INVLKNMPAIRLIST, "but was", errcode)
}
}
func TestLockIncrE(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var timeout uint64
var errors int
var errstr yottadb.BufferT
errstr.Alloc(128)
// Increment a given lock 3 times then start decrementing it and after each check, the lock
// should still be there until we've decremented the 3rd time after which the lock should
// NOT be there.
//
// First, create the key for the lock we are incrementally locking/unlocking
err = yottadb.LockIncrE(tptoken, &errstr, timeout, "^lvar", []string{"Don't", "Panic!"}) // Lock it 3 times
Assertnoerr(err, t)
err = yottadb.LockIncrE(tptoken, &errstr, timeout, "^lvar", []string{"Don't", "Panic!"})
Assertnoerr(err, t)
err = yottadb.LockIncrE(tptoken, &errstr, timeout, "^lvar", []string{"Don't", "Panic!"})
Assertnoerr(err, t)
VerifyLockExists([]byte("^lvar(\"Don't\",\"Panic!\")"), &errors, true, t)
// Start decrementing the lock checking each time it still exists
err = yottadb.LockDecrE(tptoken, &errstr, "^lvar", []string{"Don't", "Panic!"})
Assertnoerr(err, t)
VerifyLockExists([]byte("^lvar(\"Don't\",\"Panic!\")"), &errors, true, t)
err = yottadb.LockDecrE(tptoken, &errstr, "^lvar", []string{"Don't", "Panic!"})
Assertnoerr(err, t)
VerifyLockExists([]byte("^lvar(\"Don't\",\"Panic!\")"), &errors, true, t)
err = yottadb.LockDecrE(tptoken, &errstr, "^lvar", []string{"Don't", "Panic!"})
Assertnoerr(err, t)
if VerifyLockExists([]byte("^lvar(\"Don't\",\"Panic!\")"), &errors, false, t) {
t.Error("Lock should be gone but is not")
}
err = yottadb.LockST(tptoken, &errstr, 0) // Release all locks
Assertnoerr(err, t)
}
func TestLockIncrEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
err = yottadb.LockIncrE(tptoken, &errstr, 0, "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The LockIncrE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
err = yottadb.LockIncrE(tptoken, &errstr, 0, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The LockIncrE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
err = yottadb.LockIncrE(tptoken, &errstr, 0, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The LockIncrE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
err = yottadb.LockIncrE(yottadb.NOTTP, &errstr, 0, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The LockIncrE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
err = yottadb.LockIncrE(yottadb.NOTTP, &errstr, 0, "a", []string{"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", "a33", "a34", "a35"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The LockIncrE() errorcode for node with 35 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_TIME2LONG
err = yottadb.LockIncrE(tptoken, &errstr, yottadb.YDB_MAX_TIME_NSEC+1, "a", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_TIME2LONG != errcode {
t.Error("The LockIncrE() errorcode for timeout of YDB_MAX_TIME_NSEC+1 expected to be", yottadb.YDB_ERR_TIME2LONG, "but was", errcode)
}
// YDB_ERR_INVVARNAME
err = yottadb.LockDecrE(tptoken, &errstr, "^", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The LockDecrE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
err = yottadb.LockDecrE(tptoken, &errstr, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The LockDecrE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
err = yottadb.LockDecrE(tptoken, &errstr, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The LockDecrE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
err = yottadb.LockDecrE(yottadb.NOTTP, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The LockDecrE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
err = yottadb.LockDecrE(yottadb.NOTTP, &errstr, "a", []string{"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", "a33", "a34", "a35"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The LockDecrE() errorcode for node with 35 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestMessageE(t *testing.T) {
// Already tested in tests for NodeNextST()/NodePrevST()
}
func TestNodeNextE(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errors, i int
var subscrary []string
var subs [3][]string
var sublst yottadb.BufferTArray
var errstr yottadb.BufferT
errstr.Alloc(128)
sublst.Alloc(AryDim, SubSiz)
// Need to start with a clean slate (empty database) so do that first
Dbdeleteall(tptoken, &errstr, &errors, t)
subs[0] = []string{"sub0a", "sub0b", "sub0c", "sub0d"}
subs[1] = []string{"sub1a", "sub1b"}
subs[2] = []string{"sub2a", "sub2b", "sub2c-but a long sub2c comparatively"}
err = yottadb.SetValE(tptoken, &errstr, "val0", "^node", subs[0])
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val1", "^node", subs[1])
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val2", "^node", subs[2])
Assertnoerr(err, t)
subscrary = []string{""}
// Loop to test NodeNextST()
if DebugFlag {
t.Log(" Starting NodeNextE() loop")
}
for i = 0; ; i++ {
err = sublst.SetElemUsed(tptoken, &errstr, AryDim) // Reset each round to (re)set how many array elems are available
Assertnoerr(err, t)
retsubs, err := yottadb.NodeNextE(tptoken, &errstr, "^node", subscrary)
if nil != err {
errorcode := yottadb.ErrorCode(err)
if CheckErrorExpectYDB_ERR_NODEEND(errorcode) {
// We've reached the end of the list - all done!
break
}
if DebugFlag {
t.Error("NodeNextST() failed:", err)
}
Assertnoerr(err, t)
}
// Check if subscript list is as expected
if DebugFlag {
t.Logf(" Retsubs: %v [len=%d]\n", retsubs, len(retsubs))
}
if !Cmpstrary(&retsubs, &subs[i]) {
t.Error("Expected subscript array and return array not the same for index", i)
t.Log(" Expected:", subs[i])
t.Log(" Returned:", retsubs)
}
// Move sublst into dbkey.Subary using the retsubs subscript array as the source
subscrary = retsubs
}
if 3 != i {
t.Errorf("Unexpected NodeNextST() loop count - expected 3 but got %d\n", i)
}
// Next run the loop in reverse to refetch things using NodePrev()
subscrary = []string{"~~~~~~~~~~"}
if DebugFlag {
t.Log(" Starting NodePrevE() loop")
}
for i = 2; ; i-- {
err = sublst.SetElemUsed(tptoken, &errstr, AryDim) // Reset each round to (re)set how many array elems are available
Assertnoerr(err, t)
retsubs, err := yottadb.NodePrevE(tptoken, &errstr, "^node", subscrary)
if nil != err {
errorcode := yottadb.ErrorCode(err)
if CheckErrorExpectYDB_ERR_NODEEND(errorcode) {
// We've reached the end of the list - all done!
break
}
if DebugFlag {
t.Error("NodePrevST() failed:", err)
}
Assertnoerr(err, t)
}
// Check if subscript list is as expected
if DebugFlag {
t.Logf(" Retsubs: %v [len=%d]\n", retsubs, len(retsubs))
}
if !Cmpstrary(&retsubs, &subs[i]) {
t.Error(" Expected subscript array and return array not the same for index", i)
t.Log(" Expected:", subs[i])
t.Log(" Returned:", retsubs)
}
// Move sublst into dbkey.Subary using the retsubs subscript array as the source
subscrary = retsubs
}
if -1 != i {
t.Errorf("Unexpected NodePrevST() loop count - expected -1 but got %d\n", i)
}
}
func TestNodeNextEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
_, err = yottadb.NodeNextE(tptoken, &errstr, "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The NodeNextE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
_, err = yottadb.NodeNextE(tptoken, &errstr, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The NodeNextE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
_, err = yottadb.NodeNextE(tptoken, &errstr, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The NodeNextE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
_, err = yottadb.NodeNextE(yottadb.NOTTP, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The NodeNextE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
_, err = yottadb.NodeNextE(yottadb.NOTTP, &errstr, "a", []string{"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"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The NodeNextE() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_INVVARNAME
_, err = yottadb.NodePrevE(tptoken, &errstr, "^", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The NodePrevE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
_, err = yottadb.NodePrevE(tptoken, &errstr, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The NodePrevE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
_, err = yottadb.NodePrevE(tptoken, &errstr, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The NodePrevE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
_, err = yottadb.NodePrevE(yottadb.NOTTP, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The NodePrevE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
_, err = yottadb.NodePrevE(yottadb.NOTTP, &errstr, "a", []string{"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"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The NodePrevE() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestSetValE(t *testing.T) {
// Already tested in *MANY* tests above
}
func TestSetValEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
err = yottadb.SetValE(tptoken, &errstr, "A Value", "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The SetValE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_SVNOSET
err = yottadb.SetValE(tptoken, &errstr, "A Value", "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_SVNOSET != errcode {
t.Error("The SetValE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_SVNOSET, "but was", errcode)
}
// YDB_ERR_INVSVN
err = yottadb.SetValE(tptoken, &errstr, "A Value", "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The SetValE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
err = yottadb.SetValE(yottadb.NOTTP, &errstr, "A Value", "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The SetValE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
err = yottadb.SetValE(yottadb.NOTTP, &errstr, "A Value", "a", []string{"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"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The SetValE() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
}
func TestSubNextE(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errors, i int
var subscrary []string
var sublst yottadb.BufferTArray
var errstr yottadb.BufferT
errstr.Alloc(128)
sublst.Alloc(AryDim, SubSiz)
// Start with a clean slate
Dbdeleteall(tptoken, &errstr, &errors, t)
// Create a simple 4 element array
err = yottadb.SetValE(tptoken, &errstr, "val0", "^dbvar", []string{"sub0"})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val1", "^dbvar", []string{"sub1"})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val2", "^dbvar", []string{"sub2"})
Assertnoerr(err, t)
err = yottadb.SetValE(tptoken, &errstr, "val3", "^dbvar", []string{"sub3"})
Assertnoerr(err, t)
// Initialize key with null subscript so find first one
subscrary = []string{""}
// Start forward SubNextE() loop
if DebugFlag {
t.Log(" Starting SubNextE() loop")
}
for i = 0; ; i++ {
retsub, err := yottadb.SubNextE(tptoken, &errstr, "^dbvar", subscrary)
if nil != err {
errorcode := yottadb.ErrorCode(err)
if CheckErrorExpectYDB_ERR_NODEEND(errorcode) {
// We've reached the end of the list - all done!
break
}
if DebugFlag {
t.Error("SubNextE() failed:", err)
}
Assertnoerr(err, t) // Unknown error - cause panic
}
// Validate subname
expectsub := "sub" + strconv.Itoa(i)
if retsub != expectsub {
t.Errorf("Subscript not what was expected. Expected: %s but got %s\n", expectsub, retsub)
}
// The returned subscript becomes the next subscript to use
subscrary[0] = retsub
}
// Verify loop termination conditions
if 4 != i {
t.Error("Unexpected SubNextE() loop count - expected 4 but got", i)
}
// Now run the loop the other direction using SubPrevE()
subscrary = []string{"~~~~~~~~~~"}
if DebugFlag {
t.Log(" Starting SubPrevE() loop")
}
for i = 3; ; i-- {
retsub, err := yottadb.SubPrevE(tptoken, &errstr, "^dbvar", subscrary)
if nil != err {
errorcode := yottadb.ErrorCode(err)
if CheckErrorExpectYDB_ERR_NODEEND(errorcode) {
// We've reached the end of the list - all done!
break
}
if DebugFlag {
t.Error("SubPrev() failed:", err)
}
Assertnoerr(err, t) // Unknown error - cause panic
}
// Validate subname
expectsub := "sub" + strconv.Itoa(i)
if retsub != expectsub {
t.Errorf("Subscript not what was expected. Expected: %s but got %s\n", expectsub, retsub)
}
// The returned subscript becomes the next subscript to use
subscrary[0] = retsub
}
// Verify loop termination conditions
if -1 != i {
t.Error("Unexpected SubPrevE() loop count - expected -1 but got", i)
}
}
func TestSubNextEErrors(t *testing.T) {
var tptoken uint64 = yottadb.NOTTP
var err error
var errstr yottadb.BufferT
errstr.Alloc(128)
// YDB_ERR_INVVARNAME
_, err = yottadb.SubNextE(tptoken, &errstr, "^", []string{})
errcode := yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The SubNextE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
_, err = yottadb.SubNextE(tptoken, &errstr, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The SubNextE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
_, err = yottadb.SubNextE(tptoken, &errstr, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The SubNextE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
_, err = yottadb.SubNextE(yottadb.NOTTP, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_VARNAME2LONG != errcode {
t.Error("The SubNextE() errorcode for a too long VarName expected to be", yottadb.YDB_ERR_VARNAME2LONG, "but was", errcode)
}
// YDB_ERR_MAXNRSUBSCRIPTS
_, err = yottadb.SubNextE(yottadb.NOTTP, &errstr, "a", []string{"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"})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_MAXNRSUBSCRIPTS != errcode {
t.Error("The SubNextE() errorcode for node with 32 subscripts expected to be", yottadb.YDB_ERR_MAXNRSUBSCRIPTS, "but was", errcode)
}
// YDB_ERR_INVVARNAME
_, err = yottadb.SubPrevE(tptoken, &errstr, "^", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVVARNAME != errcode {
t.Error("The SubPrevE() errorcode for ^ expected to be", yottadb.YDB_ERR_INVVARNAME, "but was", errcode)
}
// YDB_ERR_ISVUNSUPPORTED
_, err = yottadb.SubPrevE(tptoken, &errstr, "$ZCHSET", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_ISVUNSUPPORTED != errcode {
t.Error("The SubPrevE() errorcode for $ZCHSET expected to be", yottadb.YDB_ERR_ISVUNSUPPORTED, "but was", errcode)
}
// YDB_ERR_INVSVN
_, err = yottadb.SubPrevE(tptoken, &errstr, "$NOTATHING", []string{})
errcode = yottadb.ErrorCode(err)
if yottadb.YDB_ERR_INVSVN != errcode {
t.Error("The SubPrevE() errorcode for $NOTATHING expected to be", yottadb.YDB_ERR_INVSVN, "but was", errcode)
}
// YDB_ERR_VARNAME2LONG
_, err = yottadb.SubPrevE(yottadb.NOTTP, &errstr, "a1a2a3a4a5a6a7a8a9a0b1b2b3b4b5b6b7b8b9b0", []string{})