virtualbox 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. data/.yardopts +0 -1
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/virtualbox/abstract_model/attributable.rb +1 -0
  5. data/lib/virtualbox/abstract_model/validatable.rb +133 -10
  6. data/lib/virtualbox/abstract_model.rb +3 -3
  7. data/lib/virtualbox/appliance.rb +5 -2
  8. data/lib/virtualbox/audio_adapter.rb +11 -3
  9. data/lib/virtualbox/bios.rb +10 -4
  10. data/lib/virtualbox/com/abstract_enum.rb +6 -5
  11. data/lib/virtualbox/com/abstract_implementer.rb +4 -2
  12. data/lib/virtualbox/com/abstract_interface.rb +6 -4
  13. data/lib/virtualbox/com/base_interface.rb +38 -0
  14. data/lib/virtualbox/com/ffi/interface.rb +14 -5
  15. data/lib/virtualbox/com/ffi/interfaces.rb +36 -32
  16. data/lib/virtualbox/com/ffi/util.rb +22 -4
  17. data/lib/virtualbox/com/ffi_interface.rb +39 -8
  18. data/lib/virtualbox/com/implementer/base.rb +2 -2
  19. data/lib/virtualbox/com/implementer/ffi.rb +55 -44
  20. data/lib/virtualbox/com/implementer/mscom.rb +2 -4
  21. data/lib/virtualbox/com/interface/3.1.x/appliance.rb +22 -0
  22. data/lib/virtualbox/com/interface/3.1.x/audio_adapter.rb +15 -0
  23. data/lib/virtualbox/com/interface/3.1.x/audio_controller_type.rb +11 -0
  24. data/lib/virtualbox/com/interface/3.1.x/audio_driver_type.rb +11 -0
  25. data/lib/virtualbox/com/interface/3.1.x/bios_boot_menu_mode.rb +11 -0
  26. data/lib/virtualbox/com/interface/3.1.x/bios_settings.rb +21 -0
  27. data/lib/virtualbox/com/interface/3.1.x/clipboard_mode.rb +11 -0
  28. data/lib/virtualbox/com/interface/3.1.x/console.rb +50 -0
  29. data/lib/virtualbox/com/interface/3.1.x/cpu_property_type.rb +11 -0
  30. data/lib/virtualbox/com/interface/3.1.x/device_type.rb +11 -0
  31. data/lib/virtualbox/com/interface/3.1.x/dhcp_server.rb +22 -0
  32. data/lib/virtualbox/com/interface/3.1.x/firmware_type.rb +11 -0
  33. data/lib/virtualbox/com/interface/3.1.x/guest_os_type.rb +23 -0
  34. data/lib/virtualbox/com/interface/3.1.x/host.rb +42 -0
  35. data/lib/virtualbox/com/interface/3.1.x/host_network_interface.rb +30 -0
  36. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_medium_type.rb +11 -0
  37. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_status.rb +11 -0
  38. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_type.rb +11 -0
  39. data/lib/virtualbox/com/interface/3.1.x/host_usb_device.rb +13 -0
  40. data/lib/virtualbox/com/interface/3.1.x/host_usb_device_filter.rb +13 -0
  41. data/lib/virtualbox/com/interface/3.1.x/hw_virt_ex_property_type.rb +11 -0
  42. data/lib/virtualbox/com/interface/3.1.x/machine.rb +105 -0
  43. data/lib/virtualbox/com/interface/3.1.x/machine_state.rb +14 -0
  44. data/lib/virtualbox/com/interface/3.1.x/medium.rb +50 -0
  45. data/lib/virtualbox/com/interface/3.1.x/medium_attachment.rb +18 -0
  46. data/lib/virtualbox/com/interface/3.1.x/medium_format.rb +18 -0
  47. data/lib/virtualbox/com/interface/3.1.x/medium_state.rb +11 -0
  48. data/lib/virtualbox/com/interface/3.1.x/medium_type.rb +11 -0
  49. data/lib/virtualbox/com/interface/3.1.x/medium_variant.rb +11 -0
  50. data/lib/virtualbox/com/interface/3.1.x/network_adapter.rb +30 -0
  51. data/lib/virtualbox/com/interface/3.1.x/network_adapter_type.rb +11 -0
  52. data/lib/virtualbox/com/interface/3.1.x/network_attachment_type.rb +11 -0
  53. data/lib/virtualbox/com/interface/3.1.x/nsiexception.rb +23 -0
  54. data/lib/virtualbox/com/interface/3.1.x/nsisupports.rb +15 -0
  55. data/lib/virtualbox/com/interface/3.1.x/parallel_port.rb +17 -0
  56. data/lib/virtualbox/com/interface/3.1.x/port_mode.rb +11 -0
  57. data/lib/virtualbox/com/interface/3.1.x/progress.rb +63 -0
  58. data/lib/virtualbox/com/interface/3.1.x/serial_port.rb +19 -0
  59. data/lib/virtualbox/com/interface/3.1.x/session.rb +18 -0
  60. data/lib/virtualbox/com/interface/3.1.x/session_state.rb +11 -0
  61. data/lib/virtualbox/com/interface/3.1.x/session_type.rb +11 -0
  62. data/lib/virtualbox/com/interface/3.1.x/shared_folder.rb +17 -0
  63. data/lib/virtualbox/com/interface/3.1.x/snapshot.rb +20 -0
  64. data/lib/virtualbox/com/interface/3.1.x/storage_bus.rb +11 -0
  65. data/lib/virtualbox/com/interface/3.1.x/storage_controller.rb +23 -0
  66. data/lib/virtualbox/com/interface/3.1.x/storage_controller_type.rb +11 -0
  67. data/lib/virtualbox/com/interface/3.1.x/system_properties.rb +37 -0
  68. data/lib/virtualbox/com/interface/3.1.x/usb_controller.rb +20 -0
  69. data/lib/virtualbox/com/interface/3.1.x/usb_device.rb +24 -0
  70. data/lib/virtualbox/com/interface/3.1.x/usb_device_filter.rb +23 -0
  71. data/lib/virtualbox/com/interface/3.1.x/usb_device_filter_action.rb +11 -0
  72. data/lib/virtualbox/com/interface/3.1.x/usb_device_state.rb +11 -0
  73. data/lib/virtualbox/com/interface/3.1.x/virtual_box_error_info.rb +17 -0
  74. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description.rb +19 -0
  75. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_type.rb +14 -0
  76. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_value_type.rb +11 -0
  77. data/lib/virtualbox/com/interface/3.1.x/virtualbox.rb +67 -0
  78. data/lib/virtualbox/com/interface/3.1.x/vrdp_auth_type.rb +11 -0
  79. data/lib/virtualbox/com/interface/3.1.x/vrdp_server.rb +19 -0
  80. data/lib/virtualbox/com/interface/3.2.x/appliance.rb +22 -0
  81. data/lib/virtualbox/com/interface/3.2.x/audio_adapter.rb +15 -0
  82. data/lib/virtualbox/com/interface/3.2.x/audio_controller_type.rb +11 -0
  83. data/lib/virtualbox/com/interface/3.2.x/audio_driver_type.rb +11 -0
  84. data/lib/virtualbox/com/interface/3.2.x/bios_boot_menu_mode.rb +11 -0
  85. data/lib/virtualbox/com/interface/3.2.x/bios_settings.rb +21 -0
  86. data/lib/virtualbox/com/interface/3.2.x/clipboard_mode.rb +11 -0
  87. data/lib/virtualbox/com/interface/3.2.x/console.rb +50 -0
  88. data/lib/virtualbox/com/interface/3.2.x/cpu_property_type.rb +11 -0
  89. data/lib/virtualbox/com/interface/3.2.x/device_type.rb +11 -0
  90. data/lib/virtualbox/com/interface/3.2.x/dhcp_server.rb +22 -0
  91. data/lib/virtualbox/com/interface/3.2.x/firmware_type.rb +11 -0
  92. data/lib/virtualbox/com/interface/3.2.x/guest.rb +13 -0
  93. data/lib/virtualbox/com/interface/3.2.x/guest_os_type.rb +33 -0
  94. data/lib/virtualbox/com/interface/3.2.x/host.rb +43 -0
  95. data/lib/virtualbox/com/interface/3.2.x/host_network_interface.rb +30 -0
  96. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_medium_type.rb +11 -0
  97. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_status.rb +11 -0
  98. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_type.rb +11 -0
  99. data/lib/virtualbox/com/interface/3.2.x/host_usb_device.rb +13 -0
  100. data/lib/virtualbox/com/interface/3.2.x/host_usb_device_filter.rb +13 -0
  101. data/lib/virtualbox/com/interface/3.2.x/hw_virt_ex_property_type.rb +11 -0
  102. data/lib/virtualbox/com/interface/3.2.x/keyboard_hid_type.rb +11 -0
  103. data/lib/virtualbox/com/interface/3.2.x/machine.rb +118 -0
  104. data/lib/virtualbox/com/interface/3.2.x/machine_state.rb +14 -0
  105. data/lib/virtualbox/com/interface/3.2.x/medium.rb +51 -0
  106. data/lib/virtualbox/com/interface/3.2.x/medium_attachment.rb +18 -0
  107. data/lib/virtualbox/com/interface/3.2.x/medium_format.rb +18 -0
  108. data/lib/virtualbox/com/interface/3.2.x/medium_state.rb +11 -0
  109. data/lib/virtualbox/com/interface/3.2.x/medium_type.rb +11 -0
  110. data/lib/virtualbox/com/interface/3.2.x/medium_variant.rb +11 -0
  111. data/lib/virtualbox/com/interface/3.2.x/nat_alias_mode.rb +11 -0
  112. data/lib/virtualbox/com/interface/3.2.x/nat_engine.rb +27 -0
  113. data/lib/virtualbox/com/interface/3.2.x/nat_protocol.rb +11 -0
  114. data/lib/virtualbox/com/interface/3.2.x/network_adapter.rb +34 -0
  115. data/lib/virtualbox/com/interface/3.2.x/network_adapter_type.rb +11 -0
  116. data/lib/virtualbox/com/interface/3.2.x/network_attachment_type.rb +11 -0
  117. data/lib/virtualbox/com/interface/3.2.x/nsiexception.rb +23 -0
  118. data/lib/virtualbox/com/interface/3.2.x/nsisupports.rb +15 -0
  119. data/lib/virtualbox/com/interface/3.2.x/parallel_port.rb +17 -0
  120. data/lib/virtualbox/com/interface/3.2.x/pointing_hid_type.rb +11 -0
  121. data/lib/virtualbox/com/interface/3.2.x/port_mode.rb +11 -0
  122. data/lib/virtualbox/com/interface/3.2.x/progress.rb +63 -0
  123. data/lib/virtualbox/com/interface/3.2.x/serial_port.rb +19 -0
  124. data/lib/virtualbox/com/interface/3.2.x/session.rb +18 -0
  125. data/lib/virtualbox/com/interface/3.2.x/session_state.rb +11 -0
  126. data/lib/virtualbox/com/interface/3.2.x/session_type.rb +11 -0
  127. data/lib/virtualbox/com/interface/3.2.x/shared_folder.rb +17 -0
  128. data/lib/virtualbox/com/interface/3.2.x/snapshot.rb +20 -0
  129. data/lib/virtualbox/com/interface/3.2.x/storage_bus.rb +11 -0
  130. data/lib/virtualbox/com/interface/3.2.x/storage_controller.rb +24 -0
  131. data/lib/virtualbox/com/interface/3.2.x/storage_controller_type.rb +11 -0
  132. data/lib/virtualbox/com/interface/3.2.x/system_properties.rb +42 -0
  133. data/lib/virtualbox/com/interface/3.2.x/usb_controller.rb +21 -0
  134. data/lib/virtualbox/com/interface/3.2.x/usb_device.rb +24 -0
  135. data/lib/virtualbox/com/interface/3.2.x/usb_device_filter.rb +23 -0
  136. data/lib/virtualbox/com/interface/3.2.x/usb_device_filter_action.rb +11 -0
  137. data/lib/virtualbox/com/interface/3.2.x/usb_device_state.rb +11 -0
  138. data/lib/virtualbox/com/interface/3.2.x/virtual_box_error_info.rb +17 -0
  139. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description.rb +19 -0
  140. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_type.rb +14 -0
  141. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_value_type.rb +11 -0
  142. data/lib/virtualbox/com/interface/3.2.x/virtualbox.rb +67 -0
  143. data/lib/virtualbox/com/interface/3.2.x/vrdp_auth_type.rb +11 -0
  144. data/lib/virtualbox/com/interface/3.2.x/vrdp_server.rb +21 -0
  145. data/lib/virtualbox/com/mscom_interface.rb +9 -4
  146. data/lib/virtualbox/com/nil_interface.rb +7 -0
  147. data/lib/virtualbox/com/util.rb +16 -2
  148. data/lib/virtualbox/com.rb +1 -1
  149. data/lib/virtualbox/cpu.rb +61 -0
  150. data/lib/virtualbox/dhcp_server.rb +89 -0
  151. data/lib/virtualbox/dvd.rb +2 -2
  152. data/lib/virtualbox/exceptions.rb +4 -0
  153. data/lib/virtualbox/ext/platform.rb +2 -2
  154. data/lib/virtualbox/extra_data.rb +5 -6
  155. data/lib/virtualbox/forwarded_port.rb +11 -7
  156. data/lib/virtualbox/global.rb +17 -6
  157. data/lib/virtualbox/hard_drive.rb +129 -66
  158. data/lib/virtualbox/host.rb +71 -0
  159. data/lib/virtualbox/host_network_interface.rb +137 -0
  160. data/lib/virtualbox/hw_virtualization.rb +12 -6
  161. data/lib/virtualbox/lib.rb +2 -2
  162. data/lib/virtualbox/media.rb +2 -2
  163. data/lib/virtualbox/medium.rb +10 -3
  164. data/lib/virtualbox/medium_attachment.rb +2 -2
  165. data/lib/virtualbox/network_adapter.rb +12 -4
  166. data/lib/virtualbox/proxies/collection.rb +26 -6
  167. data/lib/virtualbox/shared_folder.rb +22 -15
  168. data/lib/virtualbox/snapshot.rb +185 -0
  169. data/lib/virtualbox/storage_controller.rb +3 -3
  170. data/lib/virtualbox/system_properties.rb +1 -1
  171. data/lib/virtualbox/usb_controller.rb +8 -4
  172. data/lib/virtualbox/usb_device_filter.rb +74 -0
  173. data/lib/virtualbox/version.rb +12 -1
  174. data/lib/virtualbox/virtual_system_description.rb +4 -4
  175. data/lib/virtualbox/vm.rb +273 -64
  176. data/lib/virtualbox/vrdp_server.rb +59 -0
  177. data/test/test_helper.rb +7 -1
  178. data/test/virtualbox/abstract_model/attributable_test.rb +8 -0
  179. data/test/virtualbox/abstract_model/relatable_test.rb +5 -5
  180. data/test/virtualbox/abstract_model/validatable_test.rb +186 -3
  181. data/test/virtualbox/abstract_model_test.rb +3 -3
  182. data/test/virtualbox/appliance_test.rb +8 -1
  183. data/test/virtualbox/com/abstract_enum_test.rb +1 -0
  184. data/test/virtualbox/com/abstract_implementer_test.rb +4 -3
  185. data/test/virtualbox/com/abstract_interface_test.rb +3 -2
  186. data/test/virtualbox/com/ffi/interface_test.rb +4 -4
  187. data/test/virtualbox/com/ffi/util_test.rb +23 -1
  188. data/test/virtualbox/com/implementer/base_test.rb +4 -3
  189. data/test/virtualbox/com/implementer/ffi_test.rb +18 -10
  190. data/test/virtualbox/cpu_test.rb +103 -0
  191. data/test/virtualbox/dhcp_server_test.rb +165 -0
  192. data/test/virtualbox/extra_data_test.rb +4 -3
  193. data/test/virtualbox/forwarded_port_test.rb +17 -4
  194. data/test/virtualbox/hard_drive_test.rb +54 -5
  195. data/test/virtualbox/host_network_interface_test.rb +254 -0
  196. data/test/virtualbox/host_test.rb +94 -0
  197. data/test/virtualbox/network_adapter_test.rb +30 -1
  198. data/test/virtualbox/proxies/collection_test.rb +63 -21
  199. data/test/virtualbox/shared_folder_test.rb +16 -13
  200. data/test/virtualbox/snapshot_test.rb +231 -0
  201. data/test/virtualbox/storage_controller_test.rb +1 -1
  202. data/test/virtualbox/usb_controller_test.rb +7 -0
  203. data/test/virtualbox/usb_device_filter_test.rb +93 -0
  204. data/test/virtualbox/version_test.rb +13 -1
  205. data/test/virtualbox/vm_test.rb +245 -11
  206. data/test/virtualbox/vrdp_server_test.rb +83 -0
  207. data/virtualbox.gemspec +183 -97
  208. metadata +182 -96
  209. data/TODO +0 -9
  210. data/lib/virtualbox/com/interface/appliance.rb +0 -20
  211. data/lib/virtualbox/com/interface/audio_adapter.rb +0 -13
  212. data/lib/virtualbox/com/interface/audio_controller_type.rb +0 -9
  213. data/lib/virtualbox/com/interface/audio_driver_type.rb +0 -9
  214. data/lib/virtualbox/com/interface/bios_boot_menu_mode.rb +0 -9
  215. data/lib/virtualbox/com/interface/bios_settings.rb +0 -19
  216. data/lib/virtualbox/com/interface/clipboard_mode.rb +0 -9
  217. data/lib/virtualbox/com/interface/console.rb +0 -48
  218. data/lib/virtualbox/com/interface/cpu_property_type.rb +0 -9
  219. data/lib/virtualbox/com/interface/device_type.rb +0 -9
  220. data/lib/virtualbox/com/interface/dhcp_server.rb +0 -20
  221. data/lib/virtualbox/com/interface/firmware_type.rb +0 -9
  222. data/lib/virtualbox/com/interface/guest_os_type.rb +0 -21
  223. data/lib/virtualbox/com/interface/host.rb +0 -40
  224. data/lib/virtualbox/com/interface/host_network_interface.rb +0 -28
  225. data/lib/virtualbox/com/interface/host_network_interface_medium_type.rb +0 -9
  226. data/lib/virtualbox/com/interface/host_network_interface_status.rb +0 -9
  227. data/lib/virtualbox/com/interface/host_network_interface_type.rb +0 -9
  228. data/lib/virtualbox/com/interface/host_usb_device.rb +0 -11
  229. data/lib/virtualbox/com/interface/host_usb_device_filter.rb +0 -11
  230. data/lib/virtualbox/com/interface/hw_virt_ex_property_type.rb +0 -9
  231. data/lib/virtualbox/com/interface/machine.rb +0 -103
  232. data/lib/virtualbox/com/interface/machine_state.rb +0 -12
  233. data/lib/virtualbox/com/interface/medium.rb +0 -48
  234. data/lib/virtualbox/com/interface/medium_attachment.rb +0 -16
  235. data/lib/virtualbox/com/interface/medium_format.rb +0 -16
  236. data/lib/virtualbox/com/interface/medium_state.rb +0 -9
  237. data/lib/virtualbox/com/interface/medium_type.rb +0 -9
  238. data/lib/virtualbox/com/interface/medium_variant.rb +0 -9
  239. data/lib/virtualbox/com/interface/network_adapter.rb +0 -28
  240. data/lib/virtualbox/com/interface/network_adapter_type.rb +0 -9
  241. data/lib/virtualbox/com/interface/network_attachment_type.rb +0 -9
  242. data/lib/virtualbox/com/interface/nsiexception.rb +0 -21
  243. data/lib/virtualbox/com/interface/nsisupports.rb +0 -13
  244. data/lib/virtualbox/com/interface/parallel_port.rb +0 -15
  245. data/lib/virtualbox/com/interface/port_mode.rb +0 -9
  246. data/lib/virtualbox/com/interface/progress.rb +0 -58
  247. data/lib/virtualbox/com/interface/serial_port.rb +0 -17
  248. data/lib/virtualbox/com/interface/session.rb +0 -16
  249. data/lib/virtualbox/com/interface/session_state.rb +0 -9
  250. data/lib/virtualbox/com/interface/session_type.rb +0 -9
  251. data/lib/virtualbox/com/interface/shared_folder.rb +0 -15
  252. data/lib/virtualbox/com/interface/snapshot.rb +0 -18
  253. data/lib/virtualbox/com/interface/storage_bus.rb +0 -9
  254. data/lib/virtualbox/com/interface/storage_controller.rb +0 -21
  255. data/lib/virtualbox/com/interface/storage_controller_type.rb +0 -9
  256. data/lib/virtualbox/com/interface/system_properties.rb +0 -35
  257. data/lib/virtualbox/com/interface/usb_controller.rb +0 -18
  258. data/lib/virtualbox/com/interface/usb_device.rb +0 -22
  259. data/lib/virtualbox/com/interface/usb_device_filter.rb +0 -21
  260. data/lib/virtualbox/com/interface/usb_device_filter_action.rb +0 -9
  261. data/lib/virtualbox/com/interface/usb_device_state.rb +0 -9
  262. data/lib/virtualbox/com/interface/virtual_box_error_info.rb +0 -15
  263. data/lib/virtualbox/com/interface/virtual_system_description.rb +0 -17
  264. data/lib/virtualbox/com/interface/virtual_system_description_type.rb +0 -12
  265. data/lib/virtualbox/com/interface/virtual_system_description_value_type.rb +0 -9
  266. data/lib/virtualbox/com/interface/virtualbox.rb +0 -54
  267. data/lib/virtualbox/com/interface/vrdp_auth_type.rb +0 -9
  268. data/lib/virtualbox/com/interface/vrdp_server.rb +0 -17
@@ -38,6 +38,17 @@ class ValidatableTest < Test::Unit::TestCase
38
38
  @model.clear_errors
39
39
  assert @model.errors.empty?
40
40
  end
41
+
42
+ should "be able to get full error messages" do
43
+ @model.add_error(:foo, "should be bar.")
44
+ assert_equal ['Foo should be bar.'], @model.full_error_messages
45
+ end
46
+
47
+ should "be able to get the errors on a specific field" do
48
+ @model.add_error(:foo, "an error.")
49
+ assert @model.errors_on(:bar).nil?
50
+ assert @model.errors_on(:foo)
51
+ end
41
52
  end
42
53
 
43
54
  context "validity" do
@@ -64,6 +75,30 @@ class ValidatableTest < Test::Unit::TestCase
64
75
  end
65
76
  end
66
77
 
78
+ context "extracting options hash from multi-param functions" do
79
+ setup do
80
+ @model = ValidatableModel.new
81
+ end
82
+
83
+ should "modify the initial fields array" do
84
+ fields = [{}]
85
+ @model.__validates_extract_options(fields, {})
86
+ assert fields.empty?
87
+ end
88
+
89
+ should "not modify the initial fields array if not a hash at the end" do
90
+ fields = [:foo]
91
+ @model.__validates_extract_options(fields, {})
92
+ assert_equal [:foo], fields
93
+ end
94
+
95
+ should "return the defaults hash merged with the given options" do
96
+ fields = [{ :foo => :bar }]
97
+ result = @model.__validates_extract_options(fields, { :foo => 0, :bar => :baz })
98
+ assert_equal({ :foo => :bar, :bar => :baz }, result)
99
+ end
100
+ end
101
+
67
102
  context "specific validations" do
68
103
  setup do
69
104
  @model = ValidatableModel.new
@@ -94,7 +129,7 @@ class ValidatableTest < Test::Unit::TestCase
94
129
 
95
130
  should "validate multiple fields" do
96
131
  @model.bars = nil
97
- @model.validates_presence_of([:foos, :bars])
132
+ @model.validates_presence_of(:foos, :bars)
98
133
 
99
134
  assert !@model.valid?
100
135
  assert @model.errors[:bars]
@@ -112,13 +147,161 @@ class ValidatableTest < Test::Unit::TestCase
112
147
 
113
148
  should "return false if any are invalid on multiple fields" do
114
149
  @model.bars = nil
115
- assert !@model.validates_presence_of([:foos, :bars])
150
+ assert !@model.validates_presence_of(:foos, :bars)
116
151
  end
117
152
 
118
153
  should "return true if all fields are valid" do
119
154
  @model.foos = "foo"
120
155
  @model.bars = "bar"
121
- assert @model.validates_presence_of([:foos, :bars])
156
+ assert @model.validates_presence_of(:foos, :bars)
157
+ end
158
+
159
+ should "add error message if invalid" do
160
+ @model.foos = nil
161
+ assert !@model.validates_presence_of(:foos)
162
+ assert_equal "can't be blank.", @model.errors[:foos].first
163
+ end
164
+
165
+ should "use custom error message if given" do
166
+ @model.foos = nil
167
+ assert !@model.validates_presence_of(:foos, :message => "can't be nil.")
168
+ assert_equal "can't be nil.", @model.errors[:foos].first
169
+ end
170
+ end
171
+
172
+ context "validates_format_of" do
173
+ setup do
174
+ @model.foos = "foo"
175
+ @model.bars = "bar"
176
+ end
177
+
178
+ should "not add an error if formatted properly" do
179
+ @model.validates_format_of(:foos, :with => /^foo$/)
180
+ assert @model.valid?
181
+ end
182
+
183
+ should "add an error if not formatted properly" do
184
+ @model.validates_format_of(:bars, :with => /^foo$/)
185
+ assert !@model.valid?
186
+ end
187
+
188
+ should "not add an error for a nil field" do
189
+ @model.foos = nil
190
+ @model.validates_format_of(:foos, :with => /^foo$/)
191
+ assert @model.valid?
192
+ end
193
+
194
+ should "validate multiple fields" do
195
+ @model.validates_format_of(:foos, :bars, :with => /^foo$/)
196
+ assert !@model.valid?
197
+ assert @model.errors[:bars]
198
+ end
199
+
200
+ should "return false on invalid" do
201
+ assert !@model.validates_format_of(:bars, :with => /^foo$/)
202
+ end
203
+
204
+ should "return true on valid" do
205
+ assert @model.validates_format_of(:foos, :with => /^foo$/)
206
+ end
207
+
208
+ should "return false if any are invalid on multiple fields" do
209
+ assert !@model.validates_format_of(:foos, :bars, :with => /^foo$/)
210
+ end
211
+
212
+ should "return true if all fields are valid" do
213
+ assert @model.validates_format_of(:foos, :bars, :with => /^\w+$/)
214
+ end
215
+ end
216
+
217
+ context "validates_numericality_of" do
218
+ setup do
219
+ @model.foos = 1
220
+ @model.bars = "1"
221
+ end
222
+
223
+ should "not add an error if a number" do
224
+ @model.validates_numericality_of(:foos)
225
+ assert @model.valid?
226
+ end
227
+
228
+ should "add an error if not a number" do
229
+ @model.validates_numericality_of(:bars)
230
+ assert !@model.valid?
231
+ end
232
+
233
+ should "not add an error for a nil field" do
234
+ @model.foos = nil
235
+ @model.validates_numericality_of(:foos)
236
+ assert @model.valid?
237
+ end
238
+
239
+ should "validate multiple fields" do
240
+ @model.validates_numericality_of(:foos, :bars)
241
+ assert !@model.valid?
242
+ assert @model.errors[:bars]
243
+ end
244
+
245
+ should "return false on invalid" do
246
+ assert !@model.validates_numericality_of(:bars)
247
+ end
248
+
249
+ should "return true on valid" do
250
+ assert @model.validates_numericality_of(:foos)
251
+ end
252
+
253
+ should "return false if any are invalid on multiple fields" do
254
+ assert !@model.validates_numericality_of(:foos, :bars)
255
+ end
256
+
257
+ should "return true if all fields are valid" do
258
+ @model.bars = 2
259
+ assert @model.validates_numericality_of(:foos, :bars)
260
+ end
261
+ end
262
+
263
+ context "validates_inclusion_of" do
264
+ setup do
265
+ @model.foos = 1
266
+ @model.bars = 2
267
+ end
268
+
269
+ should "not add an error if value is included" do
270
+ @model.validates_inclusion_of(:foos, :in => [1])
271
+ assert @model.valid?
272
+ end
273
+
274
+ should "add an error if value is not included" do
275
+ @model.validates_inclusion_of(:bars, :in => [1])
276
+ assert !@model.valid?
277
+ end
278
+
279
+ should "not add an error for a nil field" do
280
+ @model.foos = nil
281
+ @model.validates_inclusion_of(:foos, :in => [1,2])
282
+ assert @model.valid?
283
+ end
284
+
285
+ should "validate multiple fields" do
286
+ @model.validates_inclusion_of(:foos, :bars, :in => [1,3])
287
+ assert !@model.valid?
288
+ assert @model.errors[:bars]
289
+ end
290
+
291
+ should "return false on invalid" do
292
+ assert !@model.validates_inclusion_of(:bars, :in => [1])
293
+ end
294
+
295
+ should "return true on valid" do
296
+ assert @model.validates_inclusion_of(:foos, :in => [1])
297
+ end
298
+
299
+ should "return false if any are invalid on multiple fields" do
300
+ assert !@model.validates_inclusion_of(:foos, :bars, :in => [1,3])
301
+ end
302
+
303
+ should "return true if all fields are valid" do
304
+ assert @model.validates_inclusion_of(:foos, :bars, :in => [1,2])
122
305
  end
123
306
  end
124
307
  end
@@ -111,8 +111,8 @@ class AbstractModelTest < Test::Unit::TestCase
111
111
  end
112
112
 
113
113
  should "turn attributes which are AbstractInterfaces into classes" do
114
- @model.foo = VirtualBox::COM::Interface::VirtualBox.new(VirtualBox::COM::Implementer::Nil)
115
- assert_equal "#<AbstractModelTest::FakeModel :bar=nil, :bars=..., :foo=#<VirtualBox::COM::Interface::VirtualBox>, :foos=...>", @model.inspect
114
+ @model.foo = VirtualBox::COM::Util.versioned_interface(:VirtualBox).new(VirtualBox::COM::Implementer::Nil, nil)
115
+ assert_equal "#<AbstractModelTest::FakeModel :bar=nil, :bars=..., :foo=#<VirtualBox::COM::Interface::Version_3_1_X::VirtualBox>, :foos=...>", @model.inspect
116
116
  end
117
117
  end
118
118
 
@@ -400,4 +400,4 @@ class AbstractModelTest < Test::Unit::TestCase
400
400
  @model.write_attribute(:foo, "foo2")
401
401
  end
402
402
  end
403
- end
403
+ end
@@ -147,6 +147,13 @@ class ApplianceTest < Test::Unit::TestCase
147
147
  @machine_interface.expects(:export).with(@interface).once
148
148
  @instance.add_machine(@machine)
149
149
  end
150
+
151
+ should "add to the description for each option given" do
152
+ sys = mock("sys")
153
+ @machine_interface.expects(:export).with(@interface).once.returns(sys)
154
+ sys.expects(:add_description).with(:foo, :bar, :bar)
155
+ @instance.add_machine(@machine, { :foo => :bar })
156
+ end
150
157
  end
151
158
  end
152
- end
159
+ end
@@ -12,6 +12,7 @@ class COMAbstractEnumTest < Test::Unit::TestCase
12
12
  assert_equal :a, @enum[0]
13
13
  assert_equal :b, @enum[1]
14
14
  assert_equal :c, @enum[2]
15
+ assert_equal [:a, :b, :c], @enum.map
15
16
  end
16
17
 
17
18
  should "do the reverse mapping of value to index" do
@@ -4,18 +4,19 @@ class AbstractImplementerTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = VirtualBox::COM::AbstractImplementer
6
6
  @interface = mock("interface")
7
+ @lib = mock("lib")
7
8
  end
8
9
 
9
10
  context "initialization" do
10
11
  should "make the interface accessible" do
11
- instance = @klass.new(@interface)
12
+ instance = @klass.new(@interface, @lib)
12
13
  assert_equal @interface, instance.interface
13
14
  end
14
15
  end
15
16
 
16
17
  context "base methods" do
17
18
  setup do
18
- @instance = @klass.new(@interface)
19
+ @instance = @klass.new(@interface, @lib)
19
20
  end
20
21
 
21
22
  should "implement the read_property function" do
@@ -36,4 +37,4 @@ class AbstractImplementerTest < Test::Unit::TestCase
36
37
  }
37
38
  end
38
39
  end
39
- end
40
+ end
@@ -91,7 +91,8 @@ class AbstractInterfaceTest < Test::Unit::TestCase
91
91
 
92
92
  context "instance methods" do
93
93
  setup do
94
- @interface = BasicAITest.new(@impl)
94
+ @lib = VirtualBox::COM::NilInterface.new
95
+ @interface = BasicAITest.new(@impl, @lib)
95
96
  end
96
97
 
97
98
  context "checking for property existence" do
@@ -136,4 +137,4 @@ class AbstractInterfaceTest < Test::Unit::TestCase
136
137
  end
137
138
  end
138
139
  end
139
- end
140
+ end
@@ -10,13 +10,13 @@ class COMFFIInterfaceTest < Test::Unit::TestCase
10
10
  context "specifying a com interface" do
11
11
  setup do
12
12
  @com_interface = mock("com_interface")
13
- VirtualBox::COM::Interface.stubs(:const_get).returns(@com_interface)
13
+ VirtualBox::COM::Util.stubs(:versioned_interface).returns(@com_interface)
14
14
  @klass.stubs(:define_vtbl_parent_for_interface)
15
15
  @klass.stubs(:define_vtbl_for_interface)
16
16
  end
17
17
 
18
18
  should "get the interface with respect to the COM interfaces" do
19
- VirtualBox::COM::Interface.expects(:const_get).with(@interface).returns(@com_interface)
19
+ VirtualBox::COM::Util.expects(:versioned_interface).with(@interface).returns(@com_interface)
20
20
  @klass.com_interface(@interface, @parent)
21
21
  end
22
22
 
@@ -94,7 +94,7 @@ class COMFFIInterfaceTest < Test::Unit::TestCase
94
94
  should "get the class in the context of the FFI namespace" do
95
95
  name = :foo
96
96
  klass = mock("klass")
97
- Object.expects(:module_eval).with("::VirtualBox::COM::FFI::#{name}::Vtbl").returns(klass)
97
+ Object.expects(:module_eval).with("::VirtualBox::COM::FFI::#{VirtualBox::COM::Util.version_const}::#{name}::Vtbl").returns(klass)
98
98
  @klass.layout_args.expects(:<<).with([:superklass, klass])
99
99
  @klass.define_interface_parent(name)
100
100
  end
@@ -228,7 +228,7 @@ class COMFFIInterfaceTest < Test::Unit::TestCase
228
228
  context "initializing vtbl" do
229
229
  setup do
230
230
  @pointer = mock("pointer")
231
- @klass = VirtualBox::COM::FFI::VirtualBox
231
+ @klass = VirtualBox::COM::FFI::Util.versioned_interface(:VirtualBox)
232
232
  end
233
233
 
234
234
  should "initialize the VtblParent then the Vtbl" do
@@ -5,6 +5,26 @@ class COMFFIUtilTest < Test::Unit::TestCase
5
5
  @klass = VirtualBox::COM::FFI::Util
6
6
  end
7
7
 
8
+ context "interface class" do
9
+ should "return the result from getting from the COM util" do
10
+ interface = mock("interface")
11
+ result = mock("result")
12
+ VirtualBox::COM::Util.expects(:versioned_interface).with(interface).returns(result)
13
+ assert_equal result, @klass.interface_klass(interface)
14
+ end
15
+ end
16
+
17
+ context "versioned interface" do
18
+ should "get the current FFI interface associated with the current version" do
19
+ result = mock("result")
20
+ version_module = mock("vmod")
21
+ interface = mock("interface")
22
+ VirtualBox::COM::FFI.expects(:const_get).with(::VirtualBox::COM::Util.version_const).returns(version_module)
23
+ version_module.expects(:const_get).with(interface).returns(result)
24
+ assert_equal result, @klass.versioned_interface(interface)
25
+ end
26
+ end
27
+
8
28
  context "converting function specs to FFI parameter lists" do
9
29
  def assert_spec(spec, expected)
10
30
  result = @klass.spec_to_ffi(spec)
@@ -75,7 +95,9 @@ class COMFFIUtilTest < Test::Unit::TestCase
75
95
  "ip_address" => "IPAddress",
76
96
  "max_vdi_size" => "MaxVDISize",
77
97
  "cpu_count" => "CPUCount",
78
- "recommended_hdd" => "RecommendedHDD"
98
+ "recommended_hdd" => "RecommendedHDD",
99
+ "rtc_use_utc" => "RTCUseUTC",
100
+ "use_host_io_cache" => "UseHostIOCache"
79
101
  }
80
102
 
81
103
  tests.each do |arg, expected|
@@ -4,11 +4,12 @@ class COMImplementerBaseTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @klass = VirtualBox::COM::Implementer::Base
6
6
  @interface = mock("interface")
7
+ @lib = mock("lib")
7
8
  end
8
9
 
9
10
  context "with an instance" do
10
11
  setup do
11
- @instance = @klass.new(@interface)
12
+ @instance = @klass.new(@interface, @lib)
12
13
  end
13
14
 
14
15
  context "inferring types" do
@@ -29,9 +30,9 @@ class COMImplementerBaseTest < Test::Unit::TestCase
29
30
  should "get from COM::Interface and return" do
30
31
  result = mock("result")
31
32
  type_name = :foo
32
- VirtualBox::COM::Interface.expects(:const_get).with(type_name).returns(result)
33
+ VirtualBox::COM::FFI::Util.expects(:interface_klass).with(type_name).returns(result)
33
34
  assert_equal result, @instance.interface_klass(type_name)
34
35
  end
35
36
  end
36
37
  end
37
- end
38
+ end
@@ -8,7 +8,7 @@ class COMImplementerFFITest < Test::Unit::TestCase
8
8
  context "initializing" do
9
9
  setup do
10
10
  @interface = mock("interface")
11
- @interface.stubs(:class).returns(VirtualBox::COM::Interface::Session)
11
+ @interface.stubs(:class).returns(VirtualBox::COM::Util.versioned_interface(:Session))
12
12
 
13
13
  @ffi = mock("ffi")
14
14
 
@@ -17,7 +17,7 @@ class COMImplementerFFITest < Test::Unit::TestCase
17
17
 
18
18
  should "initialize the FFI interface associated with the AbstractInterface" do
19
19
  result = mock("result")
20
- VirtualBox::COM::FFI::Session.expects(:new).with(@pointer).once.returns(result)
20
+ VirtualBox::COM::FFI::Util.versioned_interface(:Session).expects(:new).with(@pointer).once.returns(result)
21
21
  instance = @klass.new(@interface, @ffi, @pointer)
22
22
  assert_equal result, instance.ffi_interface
23
23
  end
@@ -79,8 +79,7 @@ class COMImplementerFFITest < Test::Unit::TestCase
79
79
  @formal = [:foo]
80
80
 
81
81
  @instance.expects(:spec_to_args).with(@spec, @args).returns(@formal)
82
- @vtbl.expects(:[]).with(@name).returns(@proc)
83
- @instance.expects(:call_and_check).with(@proc, @vtbl_parent, *@formal)
82
+ @instance.expects(:call_and_check).with(@name, @vtbl_parent, *@formal)
84
83
  @instance.expects(:values_from_formal_args).with(@spec, @formal).returns(result)
85
84
  assert_equal result, @instance.call_vtbl_function(@name, @spec, @args)
86
85
  end
@@ -90,33 +89,37 @@ class COMImplementerFFITest < Test::Unit::TestCase
90
89
  setup do
91
90
  @function = mock("function")
92
91
  @function.stubs(:call).returns(0)
92
+
93
+ @name = :foo
94
+ @vtbl = { @name => @function}
95
+ @ffi_interface.stubs(:vtbl).returns(@vtbl)
93
96
  end
94
97
 
95
98
  should "raise an exception if an error occurred" do
96
99
  @function.expects(:call).returns(0x8000_4002)
97
100
  assert_raises(VirtualBox::Exceptions::FFIException) {
98
- @instance.call_and_check(@function)
101
+ @instance.call_and_check(@name)
99
102
  }
100
103
  end
101
104
 
102
105
  should "not raise an exception if an error did not occur" do
103
106
  @function.expects(:call).returns(0x0000_0000)
104
107
  assert_nothing_raised {
105
- @instance.call_and_check(@function)
108
+ @instance.call_and_check(@name)
106
109
  }
107
110
  end
108
111
 
109
112
  should "not raise an exception for NS_ERROR_NOT_IMPLEMENTED" do
110
113
  @function.expects(:call).returns(0x8000_4001)
111
114
  assert_nothing_raised {
112
- @instance.call_and_check(@function)
115
+ @instance.call_and_check(@name)
113
116
  }
114
117
  end
115
118
 
116
119
  should "forward arguments" do
117
120
  @function.expects(:call).with(1,2,3).returns(0)
118
121
  assert_nothing_raised {
119
- @instance.call_and_check(@function, 1, 2, 3)
122
+ @instance.call_and_check(@name, 1, 2, 3)
120
123
  }
121
124
  end
122
125
  end
@@ -173,7 +176,12 @@ class COMImplementerFFITest < Test::Unit::TestCase
173
176
  assert_equal [1], @instance.spec_to_args(spec, args)
174
177
  end
175
178
 
176
- should "replace array types with two parameters" do
179
+ should "replace in array types with two parameters" do
180
+ @array = [true, false, false]
181
+ assert_equal [@array.length, [1, 0, 0]], @instance.spec_to_args([[VirtualBox::COM::T_BOOL]], [@array])
182
+ end
183
+
184
+ should "replace out array types with two parameters" do
177
185
  @counter_pointer = mock("count_pointer")
178
186
  @pointer = mock("pointer")
179
187
 
@@ -516,4 +524,4 @@ class COMImplementerFFITest < Test::Unit::TestCase
516
524
  end
517
525
  end
518
526
  end
519
- end
527
+ end
@@ -0,0 +1,103 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class CPUTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = VirtualBox::CPU
6
+ @interface = mock("interface")
7
+ @parent = mock("parent")
8
+ end
9
+
10
+ context "class methods" do
11
+ context "populating relationship" do
12
+ setup do
13
+ @instance = mock("instance")
14
+ @klass.stubs(:new).returns(@instance)
15
+ end
16
+
17
+ should "call new for the interface" do
18
+ @klass.expects(:new).with(nil, @interface).once.returns(@instance)
19
+ assert_equal @instance, @klass.populate_relationship(nil, @interface)
20
+ end
21
+ end
22
+
23
+ context "saving relationship" do
24
+ should "call save with the interface on the instance" do
25
+ instance = mock("instance")
26
+ instance.expects(:save).once
27
+
28
+ @klass.save_relationship(nil, instance)
29
+ end
30
+ end
31
+ end
32
+
33
+ context "initializing" do
34
+ setup do
35
+ @klass.any_instance.stubs(:load_interface_attributes)
36
+ end
37
+
38
+ should "load interface attribtues" do
39
+ @klass.any_instance.expects(:load_interface_attributes).with(@interface).once
40
+ @klass.new(@parent, @interface)
41
+ end
42
+
43
+ should "not be dirty" do
44
+ @instance = @klass.new(@parent, @interface)
45
+ assert !@instance.changed?
46
+ end
47
+
48
+ should "be existing record" do
49
+ @instance = @klass.new(@parent, @interface)
50
+ assert !@instance.new_record?
51
+ end
52
+ end
53
+
54
+ context "instance methods" do
55
+ setup do
56
+ @klass.any_instance.stubs(:load_interface_attributes)
57
+
58
+ @parent = mock("parent")
59
+ @interface = mock("interface")
60
+ @instance = @klass.new(@parent, @interface)
61
+ end
62
+
63
+ context "getting a property" do
64
+ setup do
65
+ @key = :foo
66
+ end
67
+
68
+ should "call proper function on interface" do
69
+ result = mock("result")
70
+ @interface.expects(:get_cpu_property).with(@key).returns(result)
71
+ assert_equal result, @instance.get_property(@interface, @key)
72
+ end
73
+ end
74
+
75
+ context "setting a property" do
76
+ setup do
77
+ @key = :foo
78
+ @value = :bar
79
+ end
80
+
81
+ should "call proper function on interface" do
82
+ @interface.expects(:set_cpu_property).with(@key, @value).once
83
+ @instance.set_property(@interface, @key, @value)
84
+ end
85
+ end
86
+
87
+ context "saving" do
88
+ setup do
89
+ @bios_settings = mock("bios_settings")
90
+ @session = mock("session")
91
+ @machine = mock("machine")
92
+ @session.stubs(:machine).returns(@machine)
93
+ @parent.stubs(:with_open_session).yields(@session)
94
+ end
95
+
96
+ should "save the interface settings with the new bios settings" do
97
+ save_seq = sequence("save_seq")
98
+ @instance.expects(:save_changed_interface_attributes).with(@machine).once.in_sequence(save_seq)
99
+ @instance.save
100
+ end
101
+ end
102
+ end
103
+ end