Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.9 KiB

  1. #***************************************************************************
  2. #This script tests the manipulation of property values, in the case that the
  3. #property is an array type
  4. #***************************************************************************
  5. use OLE;
  6. use Win32;
  7. # Get a favorite class from CIMOM
  8. $locator = CreateObject OLE 'WbemScripting.SWbemLocator';
  9. $service = $locator->ConnectServer (".", "root/default");
  10. $class = $service->Get();
  11. $class->{Path_}->{Class} = "ARRAYPROP00";
  12. @a = (41, 77642, 3);
  13. $property = $class->{Properties_}->Add("p1", 19, true);
  14. $property->{Value} = \@a;
  15. print ("The initial value of p1 is [41, 77642, 3]: {");
  16. $rb = $class->{Properties_}->{p1}->{Value};
  17. foreach $elem (@$rb) {
  18. print (" $elem ");
  19. }
  20. print ("}\n");
  21. #****************************************
  22. #First pass of tests works on non-dot API
  23. #****************************************
  24. print ("\nPASS 1 - Use Non-Dot Notation\n");
  25. #Verify we can report the value of an element of the property value
  26. $rb = $class->{Properties_}->{p1}->{Value};
  27. print ("By indirection p1[0] has value [41]: @$rb[0]\n");
  28. #Verify we can report the value directly
  29. print ("By direct access p1[0] has value [41]: $class->{Properties_}->{p1}->{Value}[0]\n");
  30. #Verify we can set the value of a single property value element
  31. $rb = $class->{Properties_}->{p1}->{Value};
  32. @$rb[1] = 234;
  33. $class->{Properties_}->{p1} = $rb;
  34. print ("By direct assignment p1[1] has value [234]: $class->{Properties_}->{p1}->{Value}[1]\n");
  35. #Verify we can set the value of a single property value element
  36. #This cannot be done using Perl as it is not possible to coerce the value on the LHS to
  37. #a reference to an array. VBScript and JScript work OK because they interpret
  38. # A.p1(0) = 1 as a call to set A.p1 with 2 parameters (0 and 1) - API can interpret this
  39. # internally as an attempt to set the first element of the array "in-place".
  40. #@($class->{Properties_}->{p1}->{Value}))[1] = 345;
  41. #($class->{Properties_}->{p1}->{Value})(1) = 345;
  42. #print ("By direct assignment the second element of p1 has value: $class->{Properties_}->{p1}->{Value}[1]\n");
  43. #Verify we can set the value of an entire property value
  44. @a = (345, 934, 1871);
  45. $class->{Properties_}->{p1} = \@a;
  46. print ("After direct array assignment p1[0] has value [345]: $class->{Properties_}->{p1}->{Value}[0]\n");
  47. $rb = $class->{Properties_}->{p1}->{Value};
  48. print ("After direct array assignment p1 is [345, 934, 1871]: { @$rb }\n");
  49. #$service->Put ($class);
  50. #****************************************
  51. #Second pass of tests works on dot API
  52. #****************************************
  53. print ("\nPASS 2 - Use Dot Notation\n");
  54. #Verify we can report the array of a property using the dot notation
  55. $rb = $class->{p1};
  56. print ("By indirect access the entire value of p1 is [345, 934, 1871]: @$rb\n");
  57. #Direct access to the entire array value appears not to work
  58. #print ("By direct access the entire value of p1 is: @($class->{p1})\n");
  59. #Verify we can report the value of a property array element using the "dot" notation
  60. print ("By direct access p1[0] has value [345]: $class->{p1}[0]\n");
  61. #Verify we can report the value of a property array element using the "dot" notation
  62. $rb = $class->{p1};
  63. print ("By indirect access p1[0] has value [345]: @$rb[0]\n");
  64. #Verify we can set the value of a property array element using the "dot" notation
  65. # Note cannot do this direct to a single element for similar reasons to the above
  66. #@($class->{p1})[2] = 8889;
  67. #print ("By direct access the second element of p1 has been set to: $class->{p1}[2]\n");
  68. #Verify we can set the value of an entire property value
  69. @a = (412, 3, 544);
  70. $class->{p1} = \@a;
  71. print ("After direct array assignment p1[0] has value [412]: $class->{p1}[0]\n");
  72. $rb = $class->{p1};
  73. print ("After direct array assignment the entire value of p1 is [412, 3, 544]: { @$rb }\n");