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.

94 lines
3.3 KiB

  1. //***************************************************************************
  2. //This script tests the manipulation of property values, in the case that the
  3. //property is an array type.
  4. //Note that because we have to wrap the all array values inside a VBArray it is
  5. //not possible to test "direct" access.
  6. //***************************************************************************
  7. var locator = WScript.CreateObject ("WbemScripting.SWbemLocator");
  8. var service = locator.ConnectServer (".", "root/default");
  9. var Class = service.Get();
  10. Class.Path_.Class = "ARRAYPROP00";
  11. var Property = Class.Properties_.Add ("p", 19, true);
  12. //****************************************
  13. //First pass of tests works on non-dot API
  14. //****************************************
  15. WScript.Echo ("");
  16. WScript.Echo ("PASS 1 - Use Non-Dot Notation");
  17. WScript.Echo ("");
  18. //Verify we can set the value of a complete property array value.
  19. Property.Value = new Array (1, 2, 44);
  20. var str = "After direct assignment the initial value of p is [1,2,44]: {";
  21. var value = new VBArray (Property.Value).toArray ();
  22. WScript.Echo ("The length of the array is [3]:", value.length);
  23. for (var x=0; x < value.length; x++) {
  24. if (x != 0) {
  25. str = str + ", ";
  26. }
  27. str = str + value[x];
  28. }
  29. str = str + "}";
  30. WScript.Echo (str);
  31. //Verify we can report the value of an element of the property value.
  32. var v = new VBArray (Property.Value).toArray ();
  33. WScript.Echo ("By indirection the p[2] had value [44]:",v[2]);
  34. //Verify we can set the value of a single property value element
  35. var p = new VBArray (Property.Value).toArray ();
  36. p[1] = 345;
  37. Property.Value = p;
  38. var value = new VBArray (Property.Value).toArray ();
  39. WScript.Echo ("After indirect assignment p[1] has value [345]:", value[1]);
  40. //****************************************
  41. //Second pass of tests works on dot API
  42. //****************************************
  43. WScript.Echo ("");
  44. WScript.Echo ("PASS 2 - Use Dot Notation");
  45. WScript.Echo ("");
  46. //Verify we can report the array of a property using the dot notation
  47. var value = new VBArray (Class.p).toArray ();
  48. var str = "By direct access via the dot notation the entire value of p is [1,345,44]: {";
  49. for (var x = 0; x < value.length; x++) {
  50. if (x != 0) {
  51. str = str + ", ";
  52. }
  53. str = str + value[x];
  54. }
  55. str = str + "}";
  56. WScript.Echo (str);
  57. //Verify we can report the value of a property array element using the "dot" notation
  58. WScript.Echo ("By direct access p1[1] has value [345]:", (new VBArray(Class.p).toArray())[1]);
  59. //Verify we can set the entire array value using dot notation
  60. Class.p = new Array (412, 3, 544)
  61. var value = new VBArray (Class.p).toArray ();
  62. var str = "By direct access via the dot notation the entire value of p has been set to [412,3,544]: {";
  63. for (var x = 0; x < value.length; x++) {
  64. if (x != 0) {
  65. str = str + ", ";
  66. }
  67. str = str + value[x];
  68. }
  69. str = str + "}";
  70. WScript.Echo (str);
  71. //Verify we can set the value of a property array element using the "dot" notation
  72. // NB - Note that using [] rather than () does NOT work as JScript appears to first
  73. // interpret this as a request to retrieve Property.Value; the assignment is therefore
  74. // only made on the local temporary copy of the value
  75. Class.p(2) = 8889;
  76. WScript.Echo ("By direct access p(2) has been set to [8889]:", (new VBArray(Class.p).toArray())[2]);
  77. Class.Put_ ();