/packages/fcl-sdo/tests/test_suite/test_property.pas
Pascal | 1035 lines | 868 code | 84 blank | 83 comment | 6 complexity | be11e375bdc69502854b600a999b6e75 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
1{$INCLUDE sdo_global.inc} 2unit test_property; 3 4interface 5uses SysUtils 6{$IFDEF FPC} 7 ,fpcunit, testutils, testregistry 8{$ENDIF} 9{$IFNDEF FPC} 10 ,TestFrameWork 11{$ENDIF} 12 ,test_suite_utils, sdo, sdo_type, sdo_types, sdo_property ; 13 14type 15 16 TSDOPropertyAsbtract_Test = class(TWstBaseTest) 17 protected 18 class function create_obj( 19 const AName : string; 20 const AType : ISDOType; 21 const AMany : Boolean; 22 const AContained : Boolean; 23 const AContainingType : ISDOType; 24 const AReadOnly : Boolean; 25 const AIsAttribute : Boolean 26 ) : ISDOProperty;virtual;abstract; 27 public 28 procedure CheckEquals(expected, actual: TSDODate; msg: string = ''; const AStrict : Boolean = True); overload; 29 published 30 procedure test_create(); 31 32 procedure setDefault_boolean(); 33 procedure setDefault_byte(); 34 procedure setDefault_integer(); 35 procedure setDefault_string(); 36 procedure setDefault_object(); 37 procedure setDefault_date(); 38 39{$IFDEF HAS_SDO_BYTES} 40 procedure setDefault_bytes(); 41{$ENDIF HAS_SDO_BYTES} 42{$IFDEF HAS_SDO_CHAR} 43 procedure setDefault_char(); 44{$ENDIF HAS_SDO_CHAR} 45{$IFDEF HAS_SDO_CURRENCY} 46 procedure setDefault_currency(); 47{$ENDIF HAS_SDO_CURRENCY} 48{$IFDEF HAS_SDO_DOUBLE} 49 procedure setDefault_double(); 50{$ENDIF HAS_SDO_DOUBLE} 51{$IFDEF HAS_SDO_FLOAT} 52 procedure setDefault_float(); 53{$ENDIF HAS_SDO_FLOAT} 54{$IFDEF HAS_SDO_LONG} 55 procedure setDefault_long(); 56{$ENDIF HAS_SDO_LONG} 57{$IFDEF HAS_SDO_SHORT} 58 procedure setDefault_short(); 59{$ENDIF HAS_SDO_SHORT} 60 end; 61 62 TSDOProperty_Test = class(TSDOPropertyAsbtract_Test) 63 protected 64 class function create_obj( 65 const AName : string; 66 const AType : ISDOType; 67 const AMany : Boolean; 68 const AContained : Boolean; 69 const AContainingType : ISDOType; 70 const AReadOnly : Boolean; 71 const AIsAttribute : Boolean 72 ) : ISDOProperty;override; 73 end; 74 75implementation 76 77uses sdo_datafactory, Math, DateUtils, sdo_date_utils; 78 79const 80 s_uri = 'test-uri'; 81 s_type_object_A = 'Object_A'; s_type_object_B = 'Object_B'; 82 83{ TSDOPropertyAsbtract_Test } 84 85procedure TSDOPropertyAsbtract_Test.CheckEquals(expected, actual: TSDODate; 86 msg: string; const AStrict: Boolean 87); 88var 89 e, a : TDateTime; 90 e_y, e_m, e_d, e_h, e_mn, e_ss, e_ms : Word; 91 a_y, a_m, a_d, a_h, a_mn, a_ss, a_ms : Word; 92begin 93 if AStrict then begin 94 Check(CompareMem(@expected, @actual, SizeOf(TSDODate)), msg); 95 end else begin 96 e := NormalizeToUTC(expected); 97 a := NormalizeToUTC(actual); 98 DecodeDateTime(e, e_y, e_m, e_d, e_h, e_mn, e_ss, e_ms); 99 DecodeDateTime(a, a_y, a_m, a_d, a_h, a_mn, a_ss, a_ms); 100 CheckEquals(e_y,a_y,msg); 101 CheckEquals(e_m,a_m,msg); 102 CheckEquals(e_d,a_d,msg); 103 CheckEquals(e_h,a_h,msg); 104 CheckEquals(e_mn,a_mn,msg); 105 CheckEquals(e_ss,a_ss,msg); 106 CheckEquals(e_ms,a_ms,msg); 107 end; 108end; 109 110procedure TSDOPropertyAsbtract_Test.setDefault_boolean(); 111var 112 locFac : ISDODataFactory; 113 locObj : ISDOProperty; 114 tmpVal : TSDOBoolean; 115 ok : Boolean; 116begin 117 Randomize(); 118 locFac := TSDODataFactory.Create() as ISDODataFactory; 119 locFac.AddType(s_uri,s_type_object_A,[]); 120 locFac.AddType(s_uri,s_type_object_B,[]); 121 122 locObj := create_obj( 123 (*Name*) 'p_bool', 124 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[BooleanType]), 125 (* Many *) False, 126 (*Contained*) False, 127 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 128 (*ReadOnly*) False, 129 (*Attribute*) True 130 ); 131 CheckEquals(False, locObj.isDefaulted()); 132 CheckEquals(False, locObj.getBooleanDefault()); 133 CheckEquals(0, locObj.getIntegerDefault()); 134 CheckEquals('', locObj.getStringDefault()); 135 136 tmpVal := False; 137 locObj.setDefault(tmpVal); 138 CheckEquals(True, locObj.isDefaulted()); 139 CheckEquals(tmpVal, locObj.getBooleanDefault()); 140 tmpVal := True; 141 locObj.setDefault(tmpVal); 142 CheckEquals(True, locObj.isDefaulted()); 143 CheckEquals(tmpVal, locObj.getBooleanDefault()); 144 145 locFac.createNew(s_uri,s_type_object_A); 146 ok := False; 147 try 148 locObj.setDefault(False); 149 except 150 on e : ESDOUnsupportedOperationException do 151 ok := True; 152 end; 153 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 154end; 155 156procedure TSDOPropertyAsbtract_Test.setDefault_byte(); 157const 158 PROP_TYPE = ByteType; 159var 160 locFac : ISDODataFactory; 161 locObj : ISDOProperty; 162 tmpVal : TSDOByte; 163 ok : Boolean; 164begin 165 Randomize(); 166 locFac := TSDODataFactory.Create() as ISDODataFactory; 167 locFac.AddType(s_uri,s_type_object_A,[]); 168 locFac.AddType(s_uri,s_type_object_B,[]); 169 170 locObj := create_obj( 171 (*Name*) 'p_sample', 172 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[PROP_TYPE]), 173 (* Many *) False, 174 (*Contained*) False, 175 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 176 (*ReadOnly*) False, 177 (*Attribute*) True 178 ); 179 CheckEquals(False, locObj.isDefaulted()); 180 CheckEquals(False, locObj.getBooleanDefault()); 181 CheckEquals(0, locObj.getByteDefault()); 182 CheckEquals(0, locObj.getIntegerDefault()); 183 CheckEquals('', locObj.getStringDefault()); 184 185 tmpVal := RandomRange(Low(TSDOByte),High(TSDOByte)); 186 locObj.setDefault(tmpVal); 187 CheckEquals(True, locObj.isDefaulted()); 188 CheckEquals(tmpVal, locObj.getByteDefault()); 189 tmpVal := RandomRange(Low(TSDOByte),High(TSDOByte)); 190 locObj.setDefault(tmpVal); 191 CheckEquals(True, locObj.isDefaulted()); 192 CheckEquals(tmpVal, locObj.getByteDefault()); 193 194 locFac.createNew(s_uri,s_type_object_A); 195 ok := False; 196 try 197 locObj.setDefault(TSDOByte(123)); 198 except 199 on e : ESDOUnsupportedOperationException do 200 ok := True; 201 end; 202 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 203end; 204 205procedure TSDOPropertyAsbtract_Test.setDefault_date(); 206var 207 locFac : ISDODataFactory; 208 locObj : ISDOProperty; 209 tmpVal : TSDODate; 210 ok : Boolean; 211begin 212 Randomize(); 213 locFac := TSDODataFactory.Create() as ISDODataFactory; 214 locFac.AddType(s_uri,s_type_object_A,[]); 215 locFac.AddType(s_uri,s_type_object_B,[]); 216 217 locObj := create_obj( 218 (*Name*) 'p_dt', 219 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[DateTimeType]), 220 (* Many *) False, 221 (*Contained*) False, 222 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 223 (*ReadOnly*) False, 224 (*Attribute*) True 225 ); 226 CheckEquals(False, locObj.isDefaulted()); 227 CheckEquals(False, locObj.getBooleanDefault()); 228 CheckEquals(0, locObj.getByteDefault()); 229 CheckEquals(0, locObj.getIntegerDefault()); 230 CheckEquals('', locObj.getStringDefault()); 231 CheckEquals(ZERO_DATE,locObj.getDateDefault()); 232 233 tmpVal := xsd_StrToDate('1976-10-12T23:34:56.7',xdkDateTime); 234 locObj.setDefault(tmpVal); 235 CheckEquals(True, locObj.isDefaulted()); 236 CheckEquals(tmpVal, locObj.getDateDefault()); 237 tmpVal := xsd_StrToDate('1987-11-12',xdkDateTime); 238 locObj.setDefault(tmpVal); 239 CheckEquals(True, locObj.isDefaulted()); 240 CheckEquals(tmpVal, locObj.getDateDefault()); 241 242 locFac.createNew(s_uri,s_type_object_A); 243 ok := False; 244 try 245 locObj.setDefault(xsd_StrToDate('1987-11-12',xdkDateTime)); 246 except 247 on e : ESDOUnsupportedOperationException do 248 ok := True; 249 end; 250 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 251end; 252 253procedure TSDOPropertyAsbtract_Test.setDefault_integer(); 254var 255 locFac : ISDODataFactory; 256 locObj : ISDOProperty; 257 tmpVal : TSDOInteger; 258 ok : Boolean; 259begin 260 Randomize(); 261 locFac := TSDODataFactory.Create() as ISDODataFactory; 262 locFac.AddType(s_uri,s_type_object_A,[]); 263 locFac.AddType(s_uri,s_type_object_B,[]); 264 265 locObj := create_obj( 266 (*Name*) 'p_int', 267 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[IntegerType]), 268 (* Many *) False, 269 (*Contained*) False, 270 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 271 (*ReadOnly*) False, 272 (*Attribute*) True 273 ); 274 CheckEquals(False, locObj.isDefaulted()); 275 CheckEquals(False, locObj.getBooleanDefault()); 276 CheckEquals(0, locObj.getIntegerDefault()); 277 CheckEquals('', locObj.getStringDefault()); 278 279 tmpVal := RandomRange(-12345,12345); 280 locObj.setDefault(tmpVal); 281 CheckEquals(True, locObj.isDefaulted()); 282 CheckEquals(tmpVal, locObj.getIntegerDefault()); 283 tmpVal := RandomRange(-12345,12345); 284 locObj.setDefault(tmpVal); 285 CheckEquals(True, locObj.isDefaulted()); 286 CheckEquals(tmpVal, locObj.getIntegerDefault()); 287 288 locFac.createNew(s_uri,s_type_object_A); 289 ok := False; 290 try 291 locObj.setDefault(123); 292 except 293 on e : ESDOUnsupportedOperationException do 294 ok := True; 295 end; 296 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 297end; 298 299{$IFDEF HAS_SDO_BYTES} 300procedure TSDOPropertyAsbtract_Test.setDefault_bytes(); 301const 302 PROP_TYPE = BytesType; 303var 304 locFac : ISDODataFactory; 305 locObj : ISDOProperty; 306 tmpVal : TSDOBytes; 307 ok : Boolean; 308begin 309 Randomize(); 310 locFac := TSDODataFactory.Create() as ISDODataFactory; 311 locFac.AddType(s_uri,s_type_object_A,[]); 312 locFac.AddType(s_uri,s_type_object_B,[]); 313 314 locObj := create_obj( 315 (*Name*) 'p_sample', 316 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[PROP_TYPE]), 317 (* Many *) False, 318 (*Contained*) False, 319 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 320 (*ReadOnly*) False, 321 (*Attribute*) True 322 ); 323 CheckEquals(False, locObj.isDefaulted()); 324 CheckEquals(False, locObj.getBooleanDefault()); 325 CheckEquals(TSDOBytes(nil), locObj.getBytesDefault()); 326 CheckEquals('', locObj.getStringDefault()); 327 328 tmpVal := RandomBytes(100); 329 locObj.setDefault(tmpVal); 330 CheckEquals(True, locObj.isDefaulted()); 331 CheckEquals(tmpVal, locObj.getBytesDefault()); 332 CheckEquals(BytesToString(tmpVal), locObj.getStringDefault()); 333 tmpVal := RandomBytes(100); 334 locObj.setDefault(tmpVal); 335 CheckEquals(True, locObj.isDefaulted()); 336 CheckEquals(tmpVal, locObj.getBytesDefault()); 337 CheckEquals(BytesToString(tmpVal), locObj.getStringDefault()); 338 339 locFac.createNew(s_uri,s_type_object_A); 340 ok := False; 341 try 342 locObj.setDefault(RandomBytes(100)); 343 except 344 on e : ESDOUnsupportedOperationException do 345 ok := True; 346 end; 347 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 348end; 349{$ENDIF HAS_SDO_BYTES} 350 351{$IFDEF HAS_SDO_CHAR} 352procedure TSDOPropertyAsbtract_Test.setDefault_char(); 353const 354 PROP_TYPE = CharacterType; 355var 356 locFac : ISDODataFactory; 357 locObj : ISDOProperty; 358 tmpVal : TSDOChar; 359 ok : Boolean; 360begin 361 Randomize(); 362 locFac := TSDODataFactory.Create() as ISDODataFactory; 363 locFac.AddType(s_uri,s_type_object_A,[]); 364 locFac.AddType(s_uri,s_type_object_B,[]); 365 366 locObj := create_obj( 367 (*Name*) 'p_sample', 368 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[PROP_TYPE]), 369 (* Many *) False, 370 (*Contained*) False, 371 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 372 (*ReadOnly*) False, 373 (*Attribute*) True 374 ); 375 CheckEquals(False, locObj.isDefaulted()); 376 CheckEquals(False, locObj.getBooleanDefault()); 377 CheckEquals(0, locObj.getByteDefault()); 378{$IFDEF HAS_SDO_CHAR} 379 CheckEquals(#0, locObj.getCharacterDefault()); 380{$ENDIF HAS_SDO_CHAR} 381 CheckEquals(0, locObj.getIntegerDefault()); 382{$IFDEF HAS_SDO_LONG} 383 CheckEquals(0, locObj.getLongDefault()); 384{$ENDIF HAS_SDO_LONG} 385{$IFDEF HAS_SDO_SHORT} 386 CheckEquals(0, locObj.getShortDefault()); 387{$ENDIF HAS_SDO_SHORT} 388 CheckEquals('', locObj.getStringDefault()); 389 390 tmpVal := TSDOChar(RandomRange(Ord(Low(TSDOChar)),Ord(High(TSDOChar)))); 391 locObj.setDefault(tmpVal); 392 CheckEquals(True, locObj.isDefaulted()); 393 CheckEquals(tmpVal, locObj.getCharacterDefault()); 394 tmpVal := TSDOChar(RandomRange(Ord(Low(TSDOChar)),Ord(High(TSDOChar)))); 395 locObj.setDefault(tmpVal); 396 CheckEquals(True, locObj.isDefaulted()); 397 CheckEquals(tmpVal, locObj.getCharacterDefault()); 398 399 locFac.createNew(s_uri,s_type_object_A); 400 ok := False; 401 try 402 locObj.setDefault(TSDOChar('s')); 403 except 404 on e : ESDOUnsupportedOperationException do 405 ok := True; 406 end; 407 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 408end; 409{$ENDIF HAS_SDO_CHAR} 410 411{$IFDEF HAS_SDO_CURRENCY} 412procedure TSDOPropertyAsbtract_Test.setDefault_currency(); 413const 414 PROP_TYPE = CurrencyType; 415 VAL_1 : TSDOCurrency = 1238653223453; 416var 417 locFac : ISDODataFactory; 418 locObj : ISDOProperty; 419 tmpVal : TSDOCurrency; 420 ok : Boolean; 421begin 422 Randomize(); 423 locFac := TSDODataFactory.Create() as ISDODataFactory; 424 locFac.AddType(s_uri,s_type_object_A,[]); 425 locFac.AddType(s_uri,s_type_object_B,[]); 426 427 locObj := create_obj( 428 (*Name*) 'p_sample', 429 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[PROP_TYPE]), 430 (* Many *) False, 431 (*Contained*) False, 432 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 433 (*ReadOnly*) False, 434 (*Attribute*) True 435 ); 436 CheckEquals(False, locObj.isDefaulted()); 437 CheckEquals(False, locObj.getBooleanDefault()); 438 CheckEquals(0, locObj.getByteDefault()); 439{$IFDEF HAS_SDO_CHAR} 440 CheckEquals(#0, locObj.getCharacterDefault()); 441{$ENDIF HAS_SDO_CHAR} 442 443{$IFDEF HAS_SDO_DOUBLE} 444 CheckEquals(0, locObj.getDoubleDefault()); 445{$ENDIF HAS_SDO_DOUBLE} 446{$IFDEF HAS_SDO_FLOAT} 447 CheckEquals(0, locObj.getFloatDefault()); 448{$ENDIF HAS_SDO_FLOAT} 449{$IFDEF HAS_SDO_LONG} 450 CheckEquals(0, locObj.getLongDefault()); 451{$ENDIF HAS_SDO_LONG} 452{$IFDEF HAS_SDO_SHORT} 453 CheckEquals(0, locObj.getShortDefault()); 454{$ENDIF HAS_SDO_SHORT} 455 CheckEquals(0, locObj.getIntegerDefault()); 456 CheckEquals('', locObj.getStringDefault()); 457 458 CheckEquals(0, locObj.getCurrencyDefault()); 459 460 tmpVal := test_suite_utils.RandomRange(Low(Word),High(Word)); 461 locObj.setDefaultCurrency(tmpVal); 462 CheckEquals(True, locObj.isDefaulted()); 463 CheckEquals(tmpVal, locObj.getCurrencyDefault()); 464 tmpVal := test_suite_utils.RandomRange(Low(Word),High(Word)); 465 locObj.setDefaultCurrency(tmpVal); 466 CheckEquals(True, locObj.isDefaulted()); 467 CheckEquals(tmpVal, locObj.getCurrencyDefault()); 468 469 locFac.createNew(s_uri,s_type_object_A); 470 ok := False; 471 try 472 locObj.setDefaultCurrency(VAL_1); 473 except 474 on e : ESDOUnsupportedOperationException do 475 ok := True; 476 end; 477 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 478end; 479{$ENDIF HAS_SDO_CURRENCY} 480 481{$IFDEF HAS_SDO_DOUBLE} 482procedure TSDOPropertyAsbtract_Test.setDefault_double(); 483const 484 PROP_TYPE = DoubleType; 485 VAL_1 : TSDODouble = 1238653223453; 486var 487 locFac : ISDODataFactory; 488 locObj : ISDOProperty; 489 tmpVal : TSDODouble; 490 ok : Boolean; 491begin 492 Randomize(); 493 locFac := TSDODataFactory.Create() as ISDODataFactory; 494 locFac.AddType(s_uri,s_type_object_A,[]); 495 locFac.AddType(s_uri,s_type_object_B,[]); 496 497 locObj := create_obj( 498 (*Name*) 'p_sample', 499 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[PROP_TYPE]), 500 (* Many *) False, 501 (*Contained*) False, 502 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 503 (*ReadOnly*) False, 504 (*Attribute*) True 505 ); 506 CheckEquals(False, locObj.isDefaulted()); 507 CheckEquals(False, locObj.getBooleanDefault()); 508 CheckEquals(0, locObj.getByteDefault()); 509{$IFDEF HAS_SDO_CHAR} 510 CheckEquals(#0, locObj.getCharacterDefault()); 511{$ENDIF HAS_SDO_CHAR} 512{$IFDEF HAS_SDO_CURRENCY} 513 CheckEquals(0, locObj.getCurrencyDefault()); 514{$ENDIF HAS_SDO_CURRENCY} 515{$IFDEF HAS_SDO_FLOAT} 516 CheckEquals(0, locObj.getFloatDefault()); 517{$ENDIF HAS_SDO_FLOAT} 518{$IFDEF HAS_SDO_LONG} 519 CheckEquals(0, locObj.getLongDefault()); 520{$ENDIF HAS_SDO_LONG} 521{$IFDEF HAS_SDO_SHORT} 522 CheckEquals(0, locObj.getShortDefault()); 523{$ENDIF HAS_SDO_SHORT} 524 CheckEquals(0, locObj.getIntegerDefault()); 525 CheckEquals('', locObj.getStringDefault()); 526 527 CheckEquals(0, locObj.getDoubleDefault()); 528 529 tmpVal := test_suite_utils.RandomRange(Low(Word),High(Word)); 530 locObj.setDefault(tmpVal); 531 CheckEquals(True, locObj.isDefaulted()); 532 CheckEquals(tmpVal, locObj.getDoubleDefault()); 533 tmpVal := test_suite_utils.RandomRange(Low(Word),High(Word)); 534 locObj.setDefault(tmpVal); 535 CheckEquals(True, locObj.isDefaulted()); 536 CheckEquals(tmpVal, locObj.getDoubleDefault()); 537 538 locFac.createNew(s_uri,s_type_object_A); 539 ok := False; 540 try 541 locObj.setDefault(VAL_1); 542 except 543 on e : ESDOUnsupportedOperationException do 544 ok := True; 545 end; 546 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 547end; 548{$ENDIF HAS_SDO_DOUBLE} 549 550{$IFDEF HAS_SDO_FLOAT} 551procedure TSDOPropertyAsbtract_Test.setDefault_float(); 552const 553 PROP_TYPE = FloatType; 554 VAL_1 : TSDOFloat = 1238653223453; 555var 556 locFac : ISDODataFactory; 557 locObj : ISDOProperty; 558 tmpVal : TSDOFloat; 559 ok : Boolean; 560begin 561 Randomize(); 562 locFac := TSDODataFactory.Create() as ISDODataFactory; 563 locFac.AddType(s_uri,s_type_object_A,[]); 564 locFac.AddType(s_uri,s_type_object_B,[]); 565 566 locObj := create_obj( 567 (*Name*) 'p_sample', 568 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[PROP_TYPE]), 569 (* Many *) False, 570 (*Contained*) False, 571 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 572 (*ReadOnly*) False, 573 (*Attribute*) True 574 ); 575 CheckEquals(False, locObj.isDefaulted()); 576 CheckEquals(False, locObj.getBooleanDefault()); 577 CheckEquals(0, locObj.getByteDefault()); 578{$IFDEF HAS_SDO_CHAR} 579 CheckEquals(#0, locObj.getCharacterDefault()); 580{$ENDIF HAS_SDO_CHAR} 581{$IFDEF HAS_SDO_CURRENCY} 582 CheckEquals(0, locObj.getCurrencyDefault()); 583{$ENDIF HAS_SDO_CURRENCY} 584{$IFDEF HAS_SDO_DOUBLE} 585 CheckEquals(0, locObj.getDoubleDefault()); 586{$ENDIF HAS_SDO_DOUBLE} 587{$IFDEF HAS_SDO_LONG} 588 CheckEquals(0, locObj.getLongDefault()); 589{$ENDIF HAS_SDO_LONG} 590{$IFDEF HAS_SDO_SHORT} 591 CheckEquals(0, locObj.getShortDefault()); 592{$ENDIF HAS_SDO_SHORT} 593 CheckEquals(0, locObj.getIntegerDefault()); 594 CheckEquals('', locObj.getStringDefault()); 595 596 CheckEquals(0, locObj.getFloatDefault()); 597 598 tmpVal := test_suite_utils.RandomRange(Low(Word),High(Word)); 599 locObj.setDefault(tmpVal); 600 CheckEquals(True, locObj.isDefaulted()); 601 CheckEquals(tmpVal, locObj.getFloatDefault()); 602 tmpVal := test_suite_utils.RandomRange(Low(Word),High(Word)); 603 locObj.setDefault(tmpVal); 604 CheckEquals(True, locObj.isDefaulted()); 605 CheckEquals(tmpVal, locObj.getFloatDefault()); 606 607 locFac.createNew(s_uri,s_type_object_A); 608 ok := False; 609 try 610 locObj.setDefault(VAL_1); 611 except 612 on e : ESDOUnsupportedOperationException do 613 ok := True; 614 end; 615 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 616end; 617{$ENDIF HAS_SDO_FLOAT} 618 619{$IFDEF HAS_SDO_LONG} 620procedure TSDOPropertyAsbtract_Test.setDefault_long(); 621const 622 PROP_TYPE = LongType; 623var 624 locFac : ISDODataFactory; 625 locObj : ISDOProperty; 626 tmpVal : TSDOLong; 627 ok : Boolean; 628begin 629 Randomize(); 630 locFac := TSDODataFactory.Create() as ISDODataFactory; 631 locFac.AddType(s_uri,s_type_object_A,[]); 632 locFac.AddType(s_uri,s_type_object_B,[]); 633 634 locObj := create_obj( 635 (*Name*) 'p_sample', 636 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[PROP_TYPE]), 637 (* Many *) False, 638 (*Contained*) False, 639 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 640 (*ReadOnly*) False, 641 (*Attribute*) True 642 ); 643 CheckEquals(False, locObj.isDefaulted()); 644 CheckEquals(False, locObj.getBooleanDefault()); 645 CheckEquals(0, locObj.getByteDefault()); 646{$IFDEF HAS_SDO_CHAR} 647 CheckEquals(#0, locObj.getCharacterDefault()); 648{$ENDIF HAS_SDO_CHAR} 649 CheckEquals(0, locObj.getIntegerDefault()); 650{$IFDEF HAS_SDO_LONG} 651 CheckEquals(0, locObj.getLongDefault()); 652{$ENDIF HAS_SDO_LONG} 653{$IFDEF HAS_SDO_SHORT} 654 CheckEquals(0, locObj.getShortDefault()); 655{$ENDIF HAS_SDO_SHORT} 656 CheckEquals('', locObj.getStringDefault()); 657 658 tmpVal := test_suite_utils.RandomRange(Low(TSDOLong),High(TSDOLong)); 659 locObj.setDefault(tmpVal); 660 CheckEquals(True, locObj.isDefaulted()); 661 CheckEquals(tmpVal, locObj.getLongDefault()); 662 tmpVal := test_suite_utils.RandomRange(Low(TSDOLong),High(TSDOLong)); 663 locObj.setDefault(tmpVal); 664 CheckEquals(True, locObj.isDefaulted()); 665 CheckEquals(tmpVal, locObj.getLongDefault()); 666 667 locFac.createNew(s_uri,s_type_object_A); 668 ok := False; 669 try 670 locObj.setDefault(TSDOLong(123865322345363636)); 671 except 672 on e : ESDOUnsupportedOperationException do 673 ok := True; 674 end; 675 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 676end; 677{$ENDIF HAS_SDO_LONG} 678 679{$IFDEF HAS_SDO_SHORT} 680procedure TSDOPropertyAsbtract_Test.setDefault_short(); 681const 682 PROP_TYPE = ShortType; 683var 684 locFac : ISDODataFactory; 685 locObj : ISDOProperty; 686 tmpVal : TSDOShort; 687 ok : Boolean; 688begin 689 Randomize(); 690 locFac := TSDODataFactory.Create() as ISDODataFactory; 691 locFac.AddType(s_uri,s_type_object_A,[]); 692 locFac.AddType(s_uri,s_type_object_B,[]); 693 694 locObj := create_obj( 695 (*Name*) 'p_sample', 696 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[PROP_TYPE]), 697 (* Many *) False, 698 (*Contained*) False, 699 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 700 (*ReadOnly*) False, 701 (*Attribute*) True 702 ); 703 CheckEquals(False, locObj.isDefaulted()); 704 CheckEquals(False, locObj.getBooleanDefault()); 705 CheckEquals(0, locObj.getByteDefault()); 706{$IFDEF HAS_SDO_CHAR} 707 CheckEquals(#0, locObj.getCharacterDefault()); 708{$ENDIF HAS_SDO_CHAR} 709 CheckEquals(0, locObj.getIntegerDefault()); 710{$IFDEF HAS_SDO_LONG} 711 CheckEquals(0, locObj.getLongDefault()); 712{$ENDIF HAS_SDO_LONG} 713{$IFDEF HAS_SDO_SHORT} 714 CheckEquals(0, locObj.getShortDefault()); 715{$ENDIF HAS_SDO_SHORT} 716 CheckEquals('', locObj.getStringDefault()); 717 718 tmpVal := RandomRange(Low(TSDOShort),High(TSDOShort)); 719 locObj.setDefault(tmpVal); 720 CheckEquals(True, locObj.isDefaulted()); 721 CheckEquals(tmpVal, locObj.getShortDefault()); 722 tmpVal := RandomRange(Low(TSDOShort),High(TSDOShort)); 723 locObj.setDefault(tmpVal); 724 CheckEquals(True, locObj.isDefaulted()); 725 CheckEquals(tmpVal, locObj.getShortDefault()); 726 727 locFac.createNew(s_uri,s_type_object_A); 728 ok := False; 729 try 730 locObj.setDefault(TSDOShort(12386)); 731 except 732 on e : ESDOUnsupportedOperationException do 733 ok := True; 734 end; 735 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 736end; 737{$ENDIF HAS_SDO_SHORT} 738 739procedure TSDOPropertyAsbtract_Test.setDefault_object; 740var 741 locFac : ISDODataFactory; 742 locObj : ISDOProperty; 743 ok : boolean; 744begin 745 locFac := TSDODataFactory.Create() as ISDODataFactory; 746 locFac.AddType(s_uri,s_type_object_A,[]); 747 locFac.AddType(s_uri,s_type_object_B,[]); 748 749 locObj := create_obj( 750 (*Name*) 'p_string', 751 (*Type*) locFac.getType(s_uri,s_type_object_B), 752 (* Many *) False, 753 (*Contained*) False, 754 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 755 (*ReadOnly*) False, 756 (*Attribute*) False 757 ); 758 CheckEquals(False, locObj.isDefaulted()); 759 ok := False; 760 try 761 locObj.setDefault('asa'); 762 except 763 on e : ESDOUnsupportedOperationException do 764 ok := True; 765 end; 766 Check(ok, 'setDefault(string)'); 767 768 ok := False; 769 try 770 locObj.setDefault(True); 771 except 772 on e : ESDOUnsupportedOperationException do 773 ok := True; 774 end; 775 Check(ok, 'setDefault(Boolean)'); 776 777 ok := False; 778 try 779 locObj.setDefault(1210); 780 except 781 on e : ESDOUnsupportedOperationException do 782 ok := True; 783 end; 784 Check(ok, 'setDefault(Integer)'); 785end; 786 787procedure TSDOPropertyAsbtract_Test.setDefault_string(); 788var 789 locFac : ISDODataFactory; 790 locObj : ISDOProperty; 791 tmpVal : TSDOString; 792 ok : Boolean; 793begin 794 Randomize(); 795 locFac := TSDODataFactory.Create() as ISDODataFactory; 796 locFac.AddType(s_uri,s_type_object_A,[]); 797 locFac.AddType(s_uri,s_type_object_B,[]); 798 799 locObj := create_obj( 800 (*Name*) 'p_string', 801 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType]), 802 (* Many *) False, 803 (*Contained*) False, 804 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 805 (*ReadOnly*) False, 806 (*Attribute*) True 807 ); 808 CheckEquals(False, locObj.isDefaulted()); 809 CheckEquals(False, locObj.getBooleanDefault()); 810 CheckEquals(0, locObj.getIntegerDefault()); 811 CheckEquals('', locObj.getStringDefault()); 812 813 tmpVal := RandomString(RandomRange(1,1000)); 814 locObj.setDefault(tmpVal); 815 CheckEquals(True, locObj.isDefaulted()); 816 CheckEquals(tmpVal, locObj.getStringDefault()); 817 tmpVal := RandomString(RandomRange(1,1000)); 818 locObj.setDefault(tmpVal); 819 CheckEquals(True, locObj.isDefaulted()); 820 CheckEquals(tmpVal, locObj.getStringDefault()); 821 822 locFac.createNew(s_uri,s_type_object_A); 823 ok := False; 824 try 825 locObj.setDefault('azerty'); 826 except 827 on e : ESDOUnsupportedOperationException do 828 ok := True; 829 end; 830 Check(ok, 'Once an instance has been created, the metadata becomes read-only.'); 831end; 832 833procedure TSDOPropertyAsbtract_Test.test_create(); 834 procedure check_invalid_args( 835 const AName : string; 836 const AType : ISDOType; 837 const AMany : Boolean; 838 const AContained : Boolean; 839 const AContainingType : ISDOType; 840 const AReadOnly : Boolean; 841 const AIsAttribute : Boolean; 842 843 const AMsg : string 844 ); 845 var 846 ok : Boolean; 847 begin 848 ok := False; 849 try 850 create_obj(AName,AType,AMany,AContained,AContainingType,AReadOnly,AIsAttribute); 851 except 852 on e : ESDOIllegalArgumentException do 853 ok := True; 854 end; 855 Check(ok, AMsg); 856 end; 857 858var 859 locFac : ISDODataFactory; 860 locObj : ISDOProperty; 861begin 862 locFac := TSDODataFactory.Create() as ISDODataFactory; 863 locFac.AddType(s_uri,s_type_object_A,[]); 864 locFac.AddType(s_uri,s_type_object_B,[]); 865 check_invalid_args( 866 (*Name*) '', 867 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType]), 868 (* Many *) False, 869 (*Contained*) False, 870 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 871 (*ReadOnly*) False, 872 (*Attribute*) True, 873 'Invalid Name.' 874 ); 875 876 check_invalid_args( 877 (*Name*) '1az', 878 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType]), 879 (* Many *) False, 880 (*Contained*) False, 881 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 882 (*ReadOnly*) False, 883 (*Attribute*) True, 884 'Invalid Name.' 885 ); 886 887 check_invalid_args( 888 (*Name*) 'ab[1]', 889 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType]), 890 (* Many *) False, 891 (*Contained*) False, 892 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 893 (*ReadOnly*) False, 894 (*Attribute*) True, 895 'Invalid Name.' 896 ); 897 898 check_invalid_args( 899 (*Name*) 'azerty', 900 (*Type*) nil, 901 (* Many *) False, 902 (*Contained*) False, 903 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 904 (*ReadOnly*) False, 905 (*Attribute*) True, 906 'Invalid type.' 907 ); 908 909 check_invalid_args( 910 (*Name*) 'azerty', 911 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType]), 912 (* Many *) False, 913 (*Contained*) True, 914 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 915 (*ReadOnly*) False, 916 (*Attribute*) True, 917 'Invalid Contained.' 918 ); 919 920 check_invalid_args( 921 (*Name*) 'azerty', 922 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType]), 923 (* Many *) False, 924 (*Contained*) True, 925 (*ContainingType*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[IntegerType]), 926 (*ReadOnly*) False, 927 (*Attribute*) True, 928 'Invalid containingType : The containing type must be a DataObject.' 929 ); 930 931 locObj := create_obj( 932 (*Name*) 'p_string', 933 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType]), 934 (* Many *) False, 935 (*Contained*) False, 936 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 937 (*ReadOnly*) False, 938 (*Attribute*) True 939 ); 940 CheckEquals('p_string', locObj.getName(), 'Name'); 941 Check(locObj.getType().equals(locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType])), 'Type'); 942 CheckEquals(False, locObj.isMany(), 'isMany'); 943 CheckEquals(False, locObj.isReadOnly(), 'isReadOnly'); 944 CheckEquals(False, locObj.isContainment(), 'isContainment'); 945 CheckEquals(Ord(locObj.getType().getTypeEnum), Ord(locObj.getTypeEnum()), 'getTypeEnum'); 946 CheckEquals(False, locObj.isReference(), 'isReference'); 947 CheckEquals(True, locObj.isAttribute(), 'isAttribute'); 948 CheckEquals(False, locObj.isDefaulted(), 'isDefaulted'); 949 950 locObj := create_obj( 951 (*Name*) 'p_string', 952 (*Type*) locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType]), 953 (* Many *) False, 954 (*Contained*) False, 955 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 956 (*ReadOnly*) False, 957 (*Attribute*) False 958 ); 959 CheckEquals('p_string', locObj.getName(), 'Name'); 960 Check(locObj.getType().equals(locFac.getType(sdo_namespace,SDOTypeDefaultTypeNames[StringType])), 'Type'); 961 CheckEquals(False, locObj.isMany(), 'isMany'); 962 CheckEquals(False, locObj.isReadOnly(), 'isReadOnly'); 963 CheckEquals(False, locObj.isContainment(), 'isContainment'); 964 CheckEquals(Ord(locObj.getType().getTypeEnum), Ord(locObj.getTypeEnum()), 'getTypeEnum'); 965 CheckEquals(False, locObj.isReference(), 'isReference'); 966 CheckEquals(False, locObj.isAttribute(), 'isAttribute'); 967 CheckEquals(False, locObj.isDefaulted(), 'isDefaulted'); 968 969 locObj := create_obj( 970 (*Name*) 'p_ab', 971 (*Type*) locFac.getType(s_uri,s_type_object_B), 972 (* Many *) False, 973 (*Contained*) False, 974 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 975 (*ReadOnly*) False, 976 (*Attribute*) False 977 ); 978 CheckEquals('p_ab', locObj.getName(), 'Name'); 979 Check(locObj.getType().equals(locFac.getType(s_uri,s_type_object_B)), 'Type'); 980 CheckEquals(False, locObj.isMany(), 'isMany'); 981 CheckEquals(False, locObj.isReadOnly(), 'isReadOnly'); 982 CheckEquals(False, locObj.isContainment(), 'isContainment'); 983 CheckEquals(Ord(locObj.getType().getTypeEnum), Ord(locObj.getTypeEnum()), 'getTypeEnum'); 984 CheckEquals(True, locObj.isReference(), 'isReference'); 985 CheckEquals(False, locObj.isDefaulted(), 'isDefaulted'); 986 987 locObj := create_obj( 988 (*Name*) 'p_ab2', 989 (*Type*) locFac.getType(s_uri,s_type_object_B), 990 (* Many *) False, 991 (*Contained*) True, 992 (*ContainingType*) locFac.getType(s_uri,s_type_object_A), 993 (*ReadOnly*) False, 994 (*Attribute*) False 995 ); 996 CheckEquals('p_ab2', locObj.getName(), 'Name'); 997 Check(locObj.getType().equals(locFac.getType(s_uri,s_type_object_B)), 'Type'); 998 CheckEquals(False, locObj.isMany(), 'isMany'); 999 CheckEquals(False, locObj.isReadOnly(), 'isReadOnly'); 1000 CheckEquals(True, locObj.isContainment(), 'isContainment'); 1001 CheckEquals(Ord(locObj.getType().getTypeEnum), Ord(locObj.getTypeEnum()), 'getTypeEnum'); 1002 CheckEquals(False, locObj.isReference(), 'isReference'); 1003 CheckEquals(False, locObj.isDefaulted(), 'isDefaulted'); 1004end; 1005 1006{ TSDOProperty_Test } 1007 1008class function TSDOProperty_Test.create_obj( 1009 const AName: string; 1010 const AType: ISDOType; 1011 const AMany, AContained: Boolean; 1012 const AContainingType: ISDOType; 1013 const AReadOnly: Boolean; 1014 const AIsAttribute : Boolean 1015): ISDOProperty; 1016var 1017 f : TPropertyFlags; 1018begin 1019 f := []; 1020 if AMany then 1021 Include(f, pfIsMany); 1022 if AContained then 1023 Include(f, pfIsContainment); 1024 if AReadOnly then 1025 Include(f, pfIsReadOnly); 1026 if AIsAttribute then 1027 Include(f, pfIsAttribute); 1028 1029 Result := TSDOProperty.Create(AName,AType,f,AContainingType) as ISDOProperty; 1030end; 1031 1032initialization 1033 RegisterTest('Metadata',TSDOProperty_Test.Suite); 1034 1035end.