1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 7 namespace Microsoft.Test.ModuleCore 8 { 9 //////////////////////////////////////////////////////////////// 10 // SecurityFlags 11 // 12 //////////////////////////////////////////////////////////////// 13 public enum SecurityFlags 14 { 15 None = 0, 16 FullTrust = 1, 17 ThreatModel = 2, 18 } 19 20 //////////////////////////////////////////////////////////////// 21 // TestAttribute (attribute) 22 // 23 //////////////////////////////////////////////////////////////// 24 public abstract class TestAttribute : Attribute 25 { 26 //Data 27 protected string pname; 28 protected string pdesc; 29 protected object[] pparams; 30 protected int pid; 31 protected string pguid; 32 protected bool pinheritance = true; 33 protected TestAttribute pparent = null; 34 protected string pfilter; 35 protected string pversion; 36 37 //Allows Inheritance (ie: object to determine if ever been set) 38 protected int? ppriority; //Allows Inheritance 39 protected string ppurpose; //Allows Inheritance 40 protected bool? pimplemented; //Allows Inheritance 41 protected string[] powners; //Allows Inheritance 42 protected string[] pareas; //Allows Inheritance 43 protected bool? pskipped; //Allows Inheritance 44 protected bool? perror; //Allows Inheritance 45 protected bool? pmanual; //Allows Inheritance 46 protected SecurityFlags? psecurity; //Allows Inheritance 47 protected string pfiltercriteria;//Allows Inheritance 48 protected string[] planguages; //Allows Inheritance 49 protected string pxml; //Allows Inheritance 50 protected int? ptimeout; //Allows Inheritance 51 protected int? pthreads; //Allows Inheritance 52 protected int? prepeat; //Allows Inheritance 53 protected bool? pstress; //Allows Inheritance 54 55 //Constructors TestAttribute()56 public TestAttribute() 57 { 58 } 59 TestAttribute(string desc)60 public TestAttribute(string desc) 61 { 62 Desc = desc; 63 } 64 TestAttribute(string desc, params Object[] parameters)65 public TestAttribute(string desc, params Object[] parameters) 66 { 67 Desc = desc; 68 Params = parameters; 69 } 70 71 //Accessors 72 public virtual string Name 73 { 74 get { return pname; } 75 set { pname = value; } 76 } 77 78 public virtual string Desc 79 { 80 get { return pdesc; } 81 set { pdesc = value; } 82 } 83 84 public virtual int Id 85 { 86 get { return pid; } 87 set { pid = value; } 88 } 89 90 public virtual string Guid 91 { 92 get { return pguid; } 93 set { pguid = value; } 94 } 95 96 public virtual int Priority 97 { 98 get 99 { 100 if (ppriority == null) 101 { 102 //Inheritance 103 if (Inheritance && pparent != null) 104 return pparent.Priority; 105 106 //Default 107 return 2; 108 } 109 return (int)ppriority; 110 } 111 set { ppriority = value; } 112 } 113 114 public virtual string Owner 115 { 116 get 117 { 118 if (powners != null) 119 return powners[0]; 120 return null; 121 } 122 set 123 { 124 if (powners == null) 125 powners = new string[1]; 126 powners[0] = value; 127 } 128 } 129 130 public virtual string[] Owners 131 { 132 get { return powners; } 133 set { powners = value; } 134 } 135 136 public virtual string Area 137 { 138 get 139 { 140 if (pareas != null) 141 return pareas[0]; 142 return null; 143 } 144 set 145 { 146 if (pareas == null) 147 pareas = new string[1]; 148 pareas[0] = value; 149 } 150 } 151 152 public virtual string[] Areas 153 { 154 get { return pareas; } 155 set { pareas = value; } 156 } 157 158 public virtual string Version 159 { 160 get { return pversion; } 161 set { pversion = value; } 162 } 163 164 public virtual object Param 165 { 166 get 167 { 168 if (pparams != null) 169 return pparams[0]; 170 return null; 171 } 172 set 173 { 174 if (pparams == null) 175 pparams = new object[1]; 176 pparams[0] = value; 177 } 178 } 179 180 public virtual object[] Params 181 { 182 get { return pparams; } 183 set { pparams = value; } 184 } 185 186 public virtual bool Inheritance 187 { 188 get { return pinheritance; } 189 set { pinheritance = value; } 190 } 191 192 public virtual TestAttribute Parent 193 { 194 get { return pparent; } 195 set { pparent = value; } 196 } 197 198 public virtual string Filter 199 { 200 get { return pfilter; } 201 set { pfilter = value; } 202 } 203 204 public virtual string Purpose 205 { 206 get 207 { 208 if (ppurpose == null) 209 { 210 //Inheritance 211 if (Inheritance && pparent != null) 212 return pparent.Purpose; 213 214 //Default 215 return null; 216 } 217 return (string)ppurpose; 218 } 219 set { ppurpose = value; } 220 } 221 222 public virtual bool Implemented 223 { 224 get 225 { 226 if (pimplemented == null) 227 { 228 //Inheritance 229 if (Inheritance && pparent != null) 230 return pparent.Implemented; 231 232 //Default 233 return true; 234 } 235 return (bool)pimplemented; 236 } 237 set { pimplemented = value; } 238 } 239 240 public virtual bool Skipped 241 { 242 get 243 { 244 if (pskipped == null) 245 { 246 //Inheritance 247 if (Inheritance && pparent != null) 248 return pparent.Skipped; 249 250 //Default 251 return false; 252 } 253 return (bool)pskipped; 254 } 255 set { pskipped = value; } 256 } 257 258 public virtual bool Error 259 { 260 get 261 { 262 if (perror == null) 263 { 264 //Inheritance 265 if (Inheritance && pparent != null) 266 return pparent.Error; 267 268 //Default 269 return false; 270 } 271 return (bool)perror; 272 } 273 set { perror = value; } 274 } 275 276 public virtual bool Manual 277 { 278 get 279 { 280 if (pmanual == null) 281 { 282 //Inheritance 283 if (Inheritance && pparent != null) 284 return pparent.Manual; 285 286 //Default 287 return false; 288 } 289 return (bool)pmanual; 290 } 291 set { pmanual = value; } 292 } 293 294 public virtual SecurityFlags Security 295 { 296 get 297 { 298 if (psecurity == null) 299 { 300 //Inheritance 301 if (Inheritance && pparent != null) 302 return pparent.Security; 303 304 //Default 305 return SecurityFlags.None; 306 } 307 return (SecurityFlags)psecurity; 308 } 309 set { psecurity = value; } 310 } 311 312 public virtual string FilterCriteria 313 { 314 get 315 { 316 if (pfiltercriteria == null) 317 { 318 //Inheritance 319 if (Inheritance && pparent != null) 320 return pparent.FilterCriteria; 321 322 //Default 323 return null; 324 } 325 return (string)pfiltercriteria; 326 } 327 set { pfiltercriteria = value; } 328 } 329 330 public virtual string Language 331 { 332 get 333 { 334 if (Languages != null) 335 return Languages[0]; 336 return null; 337 } 338 set 339 { 340 if (Languages == null) 341 Languages = new string[1]; 342 Languages[0] = value; 343 } 344 } 345 346 public virtual string[] Languages 347 { 348 get 349 { 350 if (planguages == null) 351 { 352 //Inheritance 353 if (Inheritance && pparent != null) 354 return pparent.Languages; 355 356 //Default 357 return null; 358 } 359 return (string[])planguages; 360 } 361 set { planguages = value; } 362 } 363 364 public virtual string Xml 365 { 366 get 367 { 368 if (pxml == null) 369 { 370 //Inheritance 371 if (Inheritance && pparent != null) 372 return pparent.Xml; 373 374 //Default 375 return null; 376 } 377 return (string)pxml; 378 } 379 set { pxml = value; } 380 } 381 382 public virtual bool Stress 383 { 384 get 385 { 386 if (pstress == null) 387 { 388 //Inheritance 389 if (Inheritance && pparent != null) 390 return pparent.Stress; 391 392 //Default 393 return false; 394 } 395 return (bool)pstress; 396 } 397 set { pstress = value; } 398 } 399 400 public virtual int Timeout 401 { 402 get 403 { 404 if (ptimeout == null) 405 { 406 //Inheritance 407 if (Inheritance && pparent != null) 408 return pparent.Timeout; 409 410 //Default (infinite) 411 return 0; 412 } 413 return (int)ptimeout; 414 } 415 set { ptimeout = value; } 416 } 417 418 public virtual int Threads 419 { 420 get 421 { 422 if (pthreads == null) 423 { 424 //Inheritance 425 if (Inheritance && pparent != null) 426 return pparent.Threads; 427 428 //Default (one thread) 429 return 1; 430 } 431 return (int)pthreads; 432 } 433 set { pthreads = value; } 434 } 435 436 public virtual int Repeat 437 { 438 get 439 { 440 if (prepeat == null) 441 { 442 //Inheritance 443 if (Inheritance && pparent != null) 444 return pparent.Repeat; 445 446 //Default (no repeat) 447 return 0; 448 } 449 return (int)prepeat; 450 } 451 set { prepeat = value; } 452 } 453 } 454 455 456 //////////////////////////////////////////////////////////////// 457 // TestModule (attribute) 458 // 459 //////////////////////////////////////////////////////////////// 460 public class TestModuleAttribute : TestAttribute 461 { 462 //Data 463 protected string pcreated; 464 protected string pmodified; 465 466 //Constructors TestModuleAttribute()467 public TestModuleAttribute() 468 : base() 469 { 470 } 471 TestModuleAttribute(string desc)472 public TestModuleAttribute(string desc) 473 : base(desc) 474 { 475 } 476 TestModuleAttribute(string desc, params Object[] parameters)477 public TestModuleAttribute(string desc, params Object[] parameters) 478 : base(desc, parameters) 479 { 480 } 481 482 [TestProperty(Visible = true)] 483 public virtual string Created 484 { 485 get { return pcreated; } 486 set { pcreated = value; } 487 } 488 489 [TestProperty(Visible = true)] 490 public virtual string Modified 491 { 492 get { return pmodified; } 493 set { pmodified = value; } 494 } 495 } 496 497 //////////////////////////////////////////////////////////////// 498 // TestCase (attribute) 499 // 500 //////////////////////////////////////////////////////////////// 501 public class TestCaseAttribute : TestAttribute 502 { 503 //Constructors TestCaseAttribute()504 public TestCaseAttribute() 505 : base() 506 { 507 } 508 TestCaseAttribute(string desc)509 public TestCaseAttribute(string desc) 510 : base(desc) 511 { 512 } 513 TestCaseAttribute(string desc, params Object[] parameters)514 public TestCaseAttribute(string desc, params Object[] parameters) 515 : base(desc, parameters) 516 { 517 } 518 } 519 520 521 //////////////////////////////////////////////////////////////// 522 // Variation (attribute) 523 // 524 //////////////////////////////////////////////////////////////// 525 public class VariationAttribute : TestAttribute 526 { 527 //Data 528 529 //Constructors VariationAttribute()530 public VariationAttribute() 531 : base() 532 { 533 } 534 VariationAttribute(string desc)535 public VariationAttribute(string desc) 536 : base(desc) 537 { 538 } 539 VariationAttribute(string desc, params Object[] parameters)540 public VariationAttribute(string desc, params Object[] parameters) 541 : base(desc, parameters) 542 { 543 } 544 } 545 546 //////////////////////////////////////////////////////////////// 547 // TestPropertyAttribute (attribute) 548 // 549 //////////////////////////////////////////////////////////////// 550 public class TestPropertyAttribute : Attribute 551 { 552 //Data 553 protected string pname; 554 protected string pdesc; 555 protected Guid pguid; 556 protected int pid; 557 protected object pdefaultvalue; 558 protected TestPropertyFlags pflags = TestPropertyFlags.Read; 559 560 //Constructors TestPropertyAttribute()561 public TestPropertyAttribute() 562 { 563 } 564 565 public virtual string Name 566 { 567 get { return pname; } 568 set { pname = value; } 569 } 570 571 public virtual string Desc 572 { 573 get { return pdesc; } 574 set { pdesc = value; } 575 } 576 577 public virtual Guid Guid 578 { 579 get { return pguid; } 580 set { pguid = value; } 581 } 582 583 public virtual int Id 584 { 585 get { return pid; } 586 set { pid = value; } 587 } 588 589 public virtual object DefaultValue 590 { 591 get { return pdefaultvalue; } 592 set { pdefaultvalue = value; } 593 } 594 595 public virtual bool Settable 596 { 597 get { return this.IsFlag(TestPropertyFlags.Write); } 598 set { this.SetFlag(TestPropertyFlags.Write, value); } 599 } 600 601 public virtual bool Required 602 { 603 get { return this.IsFlag(TestPropertyFlags.Required); } 604 set { this.SetFlag(TestPropertyFlags.Required, value); } 605 } 606 607 public virtual bool Inherit 608 { 609 get { return this.IsFlag(TestPropertyFlags.Inheritance); } 610 set { this.SetFlag(TestPropertyFlags.Inheritance, value); } 611 } 612 613 public virtual bool Visible 614 { 615 get { return this.IsFlag(TestPropertyFlags.Visible); } 616 set { this.SetFlag(TestPropertyFlags.Visible, value); } 617 } 618 619 public virtual bool MultipleValues 620 { 621 get { return this.IsFlag(TestPropertyFlags.MultipleValues); } 622 set { this.SetFlag(TestPropertyFlags.MultipleValues, value); } 623 } 624 public virtual TestPropertyFlags Flags 625 { 626 get { return pflags; } 627 set { pflags = value; } 628 } 629 630 //Helpers IsFlag(TestPropertyFlags flags)631 protected bool IsFlag(TestPropertyFlags flags) 632 { 633 return (pflags & flags) == flags; 634 } 635 SetFlag(TestPropertyFlags flags, bool value)636 protected void SetFlag(TestPropertyFlags flags, bool value) 637 { 638 if (value) 639 pflags |= flags; 640 else 641 pflags &= ~flags; 642 } 643 } 644 645 //////////////////////////////////////////////////////////////// 646 // TestInclude (attribute) 647 // 648 //////////////////////////////////////////////////////////////// 649 public class TestIncludeAttribute : Attribute 650 { 651 //Data 652 protected string pname; 653 protected string pfile; 654 protected string pfiles; 655 protected string pfilter; 656 657 //Constructors TestIncludeAttribute()658 public TestIncludeAttribute() 659 { 660 } 661 662 public virtual string Name 663 { 664 //Prefix for testcase names 665 get { return pname; } 666 set { pname = value; } 667 } 668 669 public virtual string File 670 { 671 get { return pfile; } 672 set { pfile = value; } 673 } 674 675 public virtual string Files 676 { 677 //Search Pattern (ie: *.*) 678 get { return pfiles; } 679 set { pfiles = value; } 680 } 681 682 public virtual string Filter 683 { 684 get { return pfilter; } 685 set { pfilter = value; } 686 } 687 } 688 } 689