virtualbox 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/.gitignore +2 -1
  2. data/Gemfile +1 -1
  3. data/Rakefile +1 -1
  4. data/Readme.md +5 -21
  5. data/VERSION +1 -1
  6. data/docs/WhatsNew.md +9 -47
  7. data/lib/virtualbox.rb +7 -30
  8. data/lib/virtualbox/abstract_model.rb +25 -5
  9. data/lib/virtualbox/abstract_model/attributable.rb +5 -1
  10. data/lib/virtualbox/abstract_model/dirty.rb +2 -0
  11. data/lib/virtualbox/abstract_model/interface_attributes.rb +96 -0
  12. data/lib/virtualbox/abstract_model/relatable.rb +19 -8
  13. data/lib/virtualbox/appliance.rb +59 -0
  14. data/lib/virtualbox/audio_adapter.rb +44 -0
  15. data/lib/virtualbox/bios.rb +44 -0
  16. data/lib/virtualbox/com.rb +23 -0
  17. data/lib/virtualbox/com/abstract_enum.rb +42 -0
  18. data/lib/virtualbox/com/abstract_implementer.rb +43 -0
  19. data/lib/virtualbox/com/abstract_interface.rb +165 -0
  20. data/lib/virtualbox/com/ffi/interface.rb +141 -0
  21. data/lib/virtualbox/com/ffi/interfaces.rb +42 -0
  22. data/lib/virtualbox/com/ffi/util.rb +101 -0
  23. data/lib/virtualbox/com/ffi/vboxxpcomc.rb +31 -0
  24. data/lib/virtualbox/com/ffi_interface.rb +65 -0
  25. data/lib/virtualbox/com/implementer/base.rb +52 -0
  26. data/lib/virtualbox/com/implementer/ffi.rb +350 -0
  27. data/lib/virtualbox/com/implementer/mscom.rb +165 -0
  28. data/lib/virtualbox/com/implementer/nil.rb +10 -0
  29. data/lib/virtualbox/com/interface/appliance.rb +20 -0
  30. data/lib/virtualbox/com/interface/audio_adapter.rb +13 -0
  31. data/lib/virtualbox/com/interface/audio_controller_type.rb +9 -0
  32. data/lib/virtualbox/com/interface/audio_driver_type.rb +9 -0
  33. data/lib/virtualbox/com/interface/bios_boot_menu_mode.rb +9 -0
  34. data/lib/virtualbox/com/interface/bios_settings.rb +19 -0
  35. data/lib/virtualbox/com/interface/clipboard_mode.rb +9 -0
  36. data/lib/virtualbox/com/interface/console.rb +48 -0
  37. data/lib/virtualbox/com/interface/cpu_property_type.rb +9 -0
  38. data/lib/virtualbox/com/interface/device_type.rb +9 -0
  39. data/lib/virtualbox/com/interface/dhcp_server.rb +20 -0
  40. data/lib/virtualbox/com/interface/firmware_type.rb +9 -0
  41. data/lib/virtualbox/com/interface/guest_os_type.rb +21 -0
  42. data/lib/virtualbox/com/interface/host.rb +40 -0
  43. data/lib/virtualbox/com/interface/host_network_interface.rb +28 -0
  44. data/lib/virtualbox/com/interface/host_network_interface_medium_type.rb +9 -0
  45. data/lib/virtualbox/com/interface/host_network_interface_status.rb +9 -0
  46. data/lib/virtualbox/com/interface/host_network_interface_type.rb +9 -0
  47. data/lib/virtualbox/com/interface/host_usb_device.rb +11 -0
  48. data/lib/virtualbox/com/interface/host_usb_device_filter.rb +11 -0
  49. data/lib/virtualbox/com/interface/hw_virt_ex_property_type.rb +9 -0
  50. data/lib/virtualbox/com/interface/machine.rb +103 -0
  51. data/lib/virtualbox/com/interface/machine_state.rb +12 -0
  52. data/lib/virtualbox/com/interface/medium.rb +48 -0
  53. data/lib/virtualbox/com/interface/medium_attachment.rb +16 -0
  54. data/lib/virtualbox/com/interface/medium_format.rb +16 -0
  55. data/lib/virtualbox/com/interface/medium_state.rb +9 -0
  56. data/lib/virtualbox/com/interface/medium_type.rb +9 -0
  57. data/lib/virtualbox/com/interface/medium_variant.rb +9 -0
  58. data/lib/virtualbox/com/interface/network_adapter.rb +28 -0
  59. data/lib/virtualbox/com/interface/network_adapter_type.rb +9 -0
  60. data/lib/virtualbox/com/interface/network_attachment_type.rb +9 -0
  61. data/lib/virtualbox/com/interface/nsiexception.rb +21 -0
  62. data/lib/virtualbox/com/interface/nsisupports.rb +13 -0
  63. data/lib/virtualbox/com/interface/parallel_port.rb +15 -0
  64. data/lib/virtualbox/com/interface/port_mode.rb +9 -0
  65. data/lib/virtualbox/com/interface/progress.rb +58 -0
  66. data/lib/virtualbox/com/interface/serial_port.rb +17 -0
  67. data/lib/virtualbox/com/interface/session.rb +16 -0
  68. data/lib/virtualbox/com/interface/session_state.rb +9 -0
  69. data/lib/virtualbox/com/interface/session_type.rb +9 -0
  70. data/lib/virtualbox/com/interface/shared_folder.rb +15 -0
  71. data/lib/virtualbox/com/interface/snapshot.rb +18 -0
  72. data/lib/virtualbox/com/interface/storage_bus.rb +9 -0
  73. data/lib/virtualbox/com/interface/storage_controller.rb +21 -0
  74. data/lib/virtualbox/com/interface/storage_controller_type.rb +9 -0
  75. data/lib/virtualbox/com/interface/system_properties.rb +35 -0
  76. data/lib/virtualbox/com/interface/usb_controller.rb +18 -0
  77. data/lib/virtualbox/com/interface/usb_device.rb +22 -0
  78. data/lib/virtualbox/com/interface/usb_device_filter.rb +21 -0
  79. data/lib/virtualbox/com/interface/usb_device_filter_action.rb +9 -0
  80. data/lib/virtualbox/com/interface/usb_device_state.rb +9 -0
  81. data/lib/virtualbox/com/interface/virtual_box_error_info.rb +15 -0
  82. data/lib/virtualbox/com/interface/virtual_system_description.rb +17 -0
  83. data/lib/virtualbox/com/interface/virtual_system_description_type.rb +12 -0
  84. data/lib/virtualbox/com/interface/virtual_system_description_value_type.rb +9 -0
  85. data/lib/virtualbox/com/interface/virtualbox.rb +54 -0
  86. data/lib/virtualbox/com/interface/vrdp_auth_type.rb +9 -0
  87. data/lib/virtualbox/com/interface/vrdp_server.rb +17 -0
  88. data/lib/virtualbox/com/mscom_interface.rb +22 -0
  89. data/lib/virtualbox/com/util.rb +18 -0
  90. data/lib/virtualbox/dvd.rb +7 -94
  91. data/lib/virtualbox/exceptions.rb +24 -0
  92. data/lib/virtualbox/ext/glob_loader.rb +22 -0
  93. data/lib/virtualbox/ext/logger.rb +38 -0
  94. data/lib/virtualbox/ext/platform.rb +1 -1
  95. data/lib/virtualbox/extra_data.rb +25 -37
  96. data/lib/virtualbox/forwarded_port.rb +35 -13
  97. data/lib/virtualbox/global.rb +22 -80
  98. data/lib/virtualbox/hard_drive.rb +30 -97
  99. data/lib/virtualbox/lib.rb +82 -0
  100. data/lib/virtualbox/media.rb +7 -6
  101. data/lib/virtualbox/medium.rb +138 -0
  102. data/lib/virtualbox/medium_attachment.rb +61 -0
  103. data/lib/virtualbox/network_adapter.rb +134 -0
  104. data/lib/virtualbox/shared_folder.rb +53 -78
  105. data/lib/virtualbox/storage_controller.rb +76 -20
  106. data/lib/virtualbox/system_properties.rb +74 -0
  107. data/lib/virtualbox/usb_controller.rb +55 -0
  108. data/lib/virtualbox/version.rb +15 -0
  109. data/lib/virtualbox/virtual_system_description.rb +47 -0
  110. data/lib/virtualbox/vm.rb +160 -272
  111. data/test/test_helper.rb +0 -108
  112. data/test/virtualbox/abstract_model/attributable_test.rb +7 -1
  113. data/test/virtualbox/abstract_model/dirty_test.rb +1 -1
  114. data/test/virtualbox/abstract_model/interface_attributes_test.rb +169 -0
  115. data/test/virtualbox/abstract_model/relatable_test.rb +20 -0
  116. data/test/virtualbox/abstract_model_test.rb +40 -5
  117. data/test/virtualbox/appliance_test.rb +152 -0
  118. data/test/virtualbox/audio_adapter_test.rb +83 -0
  119. data/test/virtualbox/bios_test.rb +83 -0
  120. data/test/virtualbox/com/abstract_enum_test.rb +48 -0
  121. data/test/virtualbox/com/abstract_implementer_test.rb +39 -0
  122. data/test/virtualbox/com/abstract_interface_test.rb +139 -0
  123. data/test/virtualbox/com/ffi/interface_test.rb +249 -0
  124. data/test/virtualbox/com/ffi/util_test.rb +86 -0
  125. data/test/virtualbox/com/ffi_interface_test.rb +42 -0
  126. data/test/virtualbox/com/implementer/base_test.rb +37 -0
  127. data/test/virtualbox/com/implementer/ffi_test.rb +519 -0
  128. data/test/virtualbox/com/implementer/mscom_test.rb +208 -0
  129. data/test/virtualbox/com/mscom_interface_test.rb +17 -0
  130. data/test/virtualbox/com/util_test.rb +17 -0
  131. data/test/virtualbox/dvd_test.rb +4 -95
  132. data/test/virtualbox/ext/platform_test.rb +8 -0
  133. data/test/virtualbox/extra_data_test.rb +78 -102
  134. data/test/virtualbox/forwarded_port_test.rb +57 -7
  135. data/test/virtualbox/global_test.rb +25 -115
  136. data/test/virtualbox/hard_drive_test.rb +49 -212
  137. data/test/virtualbox/lib_test.rb +93 -0
  138. data/test/virtualbox/medium_attachment_test.rb +147 -0
  139. data/test/virtualbox/medium_test.rb +192 -0
  140. data/test/virtualbox/network_adapter_test.rb +160 -0
  141. data/test/virtualbox/shared_folder_test.rb +144 -160
  142. data/test/virtualbox/storage_controller_test.rb +166 -45
  143. data/test/virtualbox/system_properties_test.rb +87 -0
  144. data/test/virtualbox/usb_controller_test.rb +104 -0
  145. data/test/virtualbox/version_test.rb +34 -0
  146. data/test/virtualbox/virtual_system_description_test.rb +61 -0
  147. data/test/virtualbox/vm_test.rb +288 -322
  148. data/test/virtualbox_test.rb +1 -9
  149. data/virtualbox.gemspec +139 -23
  150. metadata +143 -27
  151. data/lib/virtualbox/attached_device.rb +0 -249
  152. data/lib/virtualbox/command.rb +0 -109
  153. data/lib/virtualbox/image.rb +0 -137
  154. data/lib/virtualbox/nic.rb +0 -111
  155. data/lib/virtualbox/system_property.rb +0 -55
  156. data/lib/virtualbox/usb.rb +0 -72
  157. data/test/virtualbox/attached_device_test.rb +0 -303
  158. data/test/virtualbox/command_test.rb +0 -152
  159. data/test/virtualbox/image_test.rb +0 -190
  160. data/test/virtualbox/nic_test.rb +0 -76
  161. data/test/virtualbox/system_property_test.rb +0 -71
  162. data/test/virtualbox/usb_test.rb +0 -35
data/test/test_helper.rb CHANGED
@@ -18,112 +18,4 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'virtualbox')
18
18
 
19
19
  # Data
20
20
  class Test::Unit::TestCase
21
- def mock_xml_doc
22
- Nokogiri::XML(mock_xml)
23
- end
24
-
25
- def mock_xml
26
- <<-xml
27
- <?xml version="1.0"?>
28
- <VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.9-macosx">
29
- <Machine uuid="{8710d3db-d96a-46ed-9004-59fa891fda90}" name="foo" OSType="Ubuntu" currentSnapshot="{f1e6edb3-6e12-4615-9642-a80a3a1ad115}" lastStateChange="2010-02-07T20:01:20Z">
30
- <Description>This is a description</Description>
31
- <ExtraData>
32
- <ExtraDataItem name="GUI/AutoresizeGuest" value="on"/>
33
- <ExtraDataItem name="GUI/Fullscreen" value="off"/>
34
- <ExtraDataItem name="GUI/LastWindowPostion" value="1040,171,720,422"/>
35
- <ExtraDataItem name="GUI/MiniToolBarAlignment" value="bottom"/>
36
- <ExtraDataItem name="GUI/MiniToolBarAutoHide" value="on"/>
37
- <ExtraDataItem name="GUI/SaveMountedAtRuntime" value="yes"/>
38
- <ExtraDataItem name="GUI/Seamless" value="off"/>
39
- <ExtraDataItem name="GUI/ShowMiniToolBar" value="yes"/>
40
- <ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" value="23"/>
41
- <ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" value="2222"/>
42
- <ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" value="TCP"/>
43
- </ExtraData>
44
- <Hardware version="2">
45
- <CPU count="1">
46
- <HardwareVirtEx enabled="true" exclusive="false"/>
47
- <HardwareVirtExNestedPaging enabled="false"/>
48
- <HardwareVirtExVPID enabled="false"/>
49
- <PAE enabled="true"/>
50
- </CPU>
51
- <Memory RAMSize="360"/>
52
- <Boot>
53
- <Order position="1" device="Floppy"/>
54
- <Order position="2" device="DVD"/>
55
- <Order position="3" device="HardDisk"/>
56
- <Order position="4" device="None"/>
57
- </Boot>
58
- <Display VRAMSize="12" monitorCount="1" accelerate3D="false" accelerate2DVideo="false"/>
59
- <RemoteDisplay enabled="false" port="3389" authType="Null" authTimeout="5000"/>
60
- <BIOS>
61
- <ACPI enabled="true"/>
62
- <IOAPIC enabled="false"/>
63
- <Logo fadeIn="true" fadeOut="true" displayTime="0"/>
64
- <BootMenu mode="MessageAndMenu"/>
65
- <TimeOffset value="0"/>
66
- <PXEDebug enabled="false"/>
67
- </BIOS>
68
- <USBController enabled="true" enabledEhci="true">
69
- <DeviceFilter name="Apple, Inc Apple Keyboard [0069]" active="true" vendorId="05ac" productId="0220" revision="0069" manufacturer="Apple, Inc" product="Apple Keyboard" remote="no"/>
70
- <DeviceFilter name="Micron Built-in iSight [0189]" active="false" vendorId="05ac" productId="8501" revision="0189" manufacturer="Micron" product="Built-in iSight" remote="no"/>
71
- </USBController>
72
- <Network>
73
- <Adapter slot="0" enabled="true" MACAddress="0800279C2E41" cable="true" speed="0" type="Am79C973">
74
- <NAT/>
75
- </Adapter>
76
- <Adapter slot="1" enabled="false" MACAddress="0800277D1707" cable="true" speed="0" type="Am79C973"/>
77
- <Adapter slot="2" enabled="false" MACAddress="080027FB5229" cable="true" speed="0" type="Am79C973"/>
78
- <Adapter slot="3" enabled="false" MACAddress="080027DE7343" cable="true" speed="0" type="Am79C973"/>
79
- <Adapter slot="4" enabled="false" MACAddress="0800277989CB" cable="true" speed="0" type="Am79C973"/>
80
- <Adapter slot="5" enabled="false" MACAddress="08002768E43B" cable="true" speed="0" type="Am79C973"/>
81
- <Adapter slot="6" enabled="false" MACAddress="080027903DF3" cable="true" speed="0" type="Am79C973"/>
82
- <Adapter slot="7" enabled="false" MACAddress="0800276A0A7D" cable="true" speed="0" type="Am79C973"/>
83
- </Network>
84
- <UART>
85
- <Port slot="0" enabled="false" IOBase="0x3f8" IRQ="4" hostMode="Disconnected"/>
86
- <Port slot="1" enabled="false" IOBase="0x3f8" IRQ="4" hostMode="Disconnected"/>
87
- </UART>
88
- <LPT>
89
- <Port slot="0" enabled="false" IOBase="0x378" IRQ="4"/>
90
- <Port slot="1" enabled="false" IOBase="0x378" IRQ="4"/>
91
- </LPT>
92
- <AudioAdapter controller="AC97" driver="CoreAudio" enabled="false"/>
93
- <SharedFolders>
94
- <SharedFolder name="foo" hostPath="/foo" writable="true"/>
95
- <SharedFolder name="bar" hostPath="/bar" writable="true"/>
96
- </SharedFolders>
97
- <Clipboard mode="Bidirectional"/>
98
- <Guest memoryBalloonSize="0" statisticsUpdateInterval="0"/>
99
- <GuestProperties>
100
- <GuestProperty name="/VirtualBox/GuestInfo/OS/Product" value="Linux" timestamp="1265440664974640000" flags=""/>
101
- <GuestProperty name="/VirtualBox/GuestInfo/OS/Release" value="2.6.24-26-virtual" timestamp="1265440664974987000" flags=""/>
102
- <GuestProperty name="/VirtualBox/GuestInfo/OS/Version" value="#1 SMP Tue Dec 1 20:00:30 UTC 2009" timestamp="1265440664975592000" flags=""/>
103
- <GuestProperty name="/VirtualBox/GuestInfo/OS/ServicePack" value="" timestamp="1265440664976342000" flags=""/>
104
- <GuestProperty name="/VirtualBox/GuestAdd/Revision" value="3.1.2" timestamp="1265440664977228000" flags=""/>
105
- <GuestProperty name="/VirtualBox/GuestAdd/Version" value="56127" timestamp="1265440664977917000" flags=""/>
106
- <GuestProperty name="/VirtualBox/GuestInfo/OS/LoggedInUsers" value="1" timestamp="1265441395765168000" flags=""/>
107
- <GuestProperty name="/VirtualBox/GuestInfo/Net/Count" value="1" timestamp="1265441395765770000" flags=""/>
108
- <GuestProperty name="/VirtualBox/GuestInfo/Net/0/V4/IP" value="10.0.2.15" timestamp="1265441395765987000" flags=""/>
109
- <GuestProperty name="/VirtualBox/GuestInfo/Net/0/V4/Broadcast" value="10.0.2.255" timestamp="1265441395766412000" flags=""/>
110
- <GuestProperty name="/VirtualBox/GuestInfo/Net/0/V4/Netmask" value="255.255.255.0" timestamp="1265441395766827000" flags=""/>
111
- <GuestProperty name="/VirtualBox/GuestInfo/Net/0/Status" value="Up" timestamp="1265441395767109000" flags=""/>
112
- <GuestProperty name="/VirtualBox/GuestInfo/OS/NoLoggedInUsers" value="false" timestamp="1265440815142014000" flags=""/>
113
- <GuestProperty name="/VirtualBox/HostInfo/GUI/LanguageID" value="en_US" timestamp="1265440628402728000" flags=""/>
114
- <GuestProperty name="/VirtualBox/GuestInfo/OS/LoggedInUsersList" value="hobo" timestamp="1265441395763755000" flags=""/>
115
- </GuestProperties>
116
- </Hardware>
117
- <StorageControllers>
118
- <StorageController name="foo" type="PIIX4" PortCount="2">
119
- <AttachedDevice type="HardDisk" port="0" device="0">
120
- <Image uuid="{2c16dd48-4cf1-497e-98fa-84ed55cfe71f}"/>
121
- </AttachedDevice>
122
- <AttachedDevice type="DVD" port="1" device="0"/>
123
- </StorageController>
124
- </StorageControllers>
125
- </Machine>
126
- </VirtualBox>
127
- xml
128
- end
129
21
  end
@@ -164,7 +164,7 @@ class AttributableTest < Test::Unit::TestCase
164
164
  @model = AttributeModel.new
165
165
  @model.populate_attributes({
166
166
  :foo => "foo",
167
- :bar => "bar"
167
+ :bar => false
168
168
  })
169
169
 
170
170
  @checkstring = "HEY"
@@ -189,6 +189,12 @@ class AttributableTest < Test::Unit::TestCase
189
189
  }
190
190
  end
191
191
 
192
+ should "understand false values" do
193
+ assert_nothing_raised {
194
+ assert_equal false, @model.bar
195
+ }
196
+ end
197
+
192
198
  should "raise an error if attempting to write an undefined attribute" do
193
199
  assert_raises(NoMethodError) { @model.baz = @check_string }
194
200
  end
@@ -10,7 +10,7 @@ class DirtyTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def foo=(value)
13
- set_dirty!(:foo, @foo, value)
13
+ set_dirty!("foo", @foo, value)
14
14
  @foo = value
15
15
  end
16
16
 
@@ -0,0 +1,169 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
2
+
3
+ class InterfaceAttributesTest < Test::Unit::TestCase
4
+ class EmptyInterfaceAttributeModel
5
+ include VirtualBox::AbstractModel::Attributable
6
+ include VirtualBox::AbstractModel::InterfaceAttributes
7
+ end
8
+
9
+ class InterfaceAttributeModel < EmptyInterfaceAttributeModel
10
+ attribute :foo
11
+ attribute :foo2, :property_getter => :get_foo, :property_setter => :set_foo
12
+ attribute :foo3, :property => :grab_foo3, :readonly => true
13
+ attribute :foo4, :property => :put_foo4
14
+ attribute :bar, :property => false
15
+ end
16
+
17
+ context "converting spec to a proc" do
18
+ setup do
19
+ @instance = EmptyInterfaceAttributeModel.new
20
+ @interface = mock("interface")
21
+ end
22
+
23
+ context "symbols" do
24
+ should "convert to a proc which calls the symbol on the interface" do
25
+ result = mock("result")
26
+ proc = @instance.spec_to_proc(:foo)
27
+ @interface.expects(:foo).once.returns(result)
28
+ assert_equal result, proc.call(@interface)
29
+ end
30
+
31
+ should "forward all parameters" do
32
+ result = mock("result")
33
+ proc = @instance.spec_to_proc(:foo)
34
+ @interface.expects(:foo).with(1, 2, 3).once.returns(result)
35
+ assert_equal result, proc.call(@interface, 1, 2, 3)
36
+ end
37
+ end
38
+
39
+ context "procs" do
40
+ should "leave proc as is" do
41
+ result = mock("result")
42
+ proc = Proc.new { |m| result }
43
+ converted = @instance.spec_to_proc(proc)
44
+ assert_equal proc, converted
45
+ assert_equal result, converted.call(@interface)
46
+ end
47
+ end
48
+ end
49
+
50
+ context "loading a single interface attribute" do
51
+ setup do
52
+ @instance = InterfaceAttributeModel.new
53
+ @interface = mock("interface")
54
+ @interface.stubs(:foo).returns("foo")
55
+ end
56
+
57
+ should "return immediately if not a valid attribute" do
58
+ @proc.expects(:call).never
59
+ @instance.load_interface_attribute(:baz, @interface)
60
+ end
61
+
62
+ should "return immediately if is marked as a non-property" do
63
+ @proc.expects(:call).never
64
+ @instance.load_interface_attribute(:bar, @interface)
65
+ end
66
+
67
+ should "use the getter specified if exists" do
68
+ key = :foo2
69
+ @interface.expects(:get_foo).returns(:bar)
70
+ @instance.expects(:write_attribute).with(key, :bar)
71
+ @instance.load_interface_attribute(key, @interface)
72
+ end
73
+
74
+ should "use the property specified first" do
75
+ key = :foo3
76
+ @interface.expects(:grab_foo3).returns(:bar)
77
+ @instance.expects(:write_attribute).with(key, :bar)
78
+ @instance.load_interface_attribute(key, @interface)
79
+ end
80
+
81
+ should "use the attribute name if no getter is specified" do
82
+ key = :foo
83
+ @interface.expects(:foo).returns(:bar)
84
+ @instance.expects(:write_attribute).with(key, :bar)
85
+ @instance.load_interface_attribute(key, @interface)
86
+ end
87
+
88
+ should "write the attribute with the value of the proc" do
89
+ key = :foo
90
+ @instance.expects(:write_attribute).with(key, "foo").once
91
+ @instance.load_interface_attribute(key, @interface)
92
+ end
93
+ end
94
+
95
+ context "saving a single interface attribute" do
96
+ setup do
97
+ @instance = InterfaceAttributeModel.new
98
+ @interface = mock("interface")
99
+
100
+ @value = :bar
101
+ @instance.stubs(:read_attribute).with(anything).returns(@value)
102
+ end
103
+
104
+ should "return immediately if not a valid attribute" do
105
+ @proc.expects(:call).never
106
+ @instance.save_interface_attribute(:baz, @interface)
107
+ end
108
+
109
+ should "return immediately if attribute doesn't have an interface setter" do
110
+ @proc.expects(:call).never
111
+ @instance.save_interface_attribute(:bar, @interface)
112
+ end
113
+
114
+ should "save the attribute with the value of the proc" do
115
+ key = :foo
116
+ @interface.expects(:foo=).with(@value).once
117
+ @instance.save_interface_attribute(key, @interface)
118
+ end
119
+
120
+ should "use the property specified first" do
121
+ key = :foo4
122
+ @interface.expects(:put_foo4).returns(:bar)
123
+ @instance.save_interface_attribute(key, @interface)
124
+ end
125
+
126
+ should "use the setter if it exists" do
127
+ key = :foo2
128
+ @interface.expects(:set_foo).with(@value).once
129
+ @instance.save_interface_attribute(key, @interface)
130
+ end
131
+
132
+ should "not save readonly attributes" do
133
+ key = :foo3
134
+ @interface.expects(:foo3=).never
135
+ @instance.save_interface_attribute(key, @interface)
136
+ end
137
+ end
138
+
139
+ context "loading all interface attributes" do
140
+ setup do
141
+ @instance = InterfaceAttributeModel.new
142
+ @interface = mock('interface')
143
+ end
144
+
145
+ should "load each" do
146
+ load_seq = sequence("load_seq")
147
+ InterfaceAttributeModel.attributes.each do |key, options|
148
+ @instance.expects(:load_interface_attribute).with(key, @interface)
149
+ end
150
+
151
+ @instance.load_interface_attributes(@interface)
152
+ end
153
+ end
154
+
155
+ context "saving all interface attributes" do
156
+ setup do
157
+ @instance = InterfaceAttributeModel.new
158
+ @interface = mock('interface')
159
+ end
160
+
161
+ should "save each" do
162
+ InterfaceAttributeModel.attributes.each do |key, options|
163
+ @instance.expects(:save_interface_attribute).with(key, @interface)
164
+ end
165
+
166
+ @instance.save_interface_attributes(@interface)
167
+ end
168
+ end
169
+ end
@@ -6,6 +6,7 @@ class RelatableTest < Test::Unit::TestCase
6
6
  "FOO"
7
7
  end
8
8
  end
9
+
9
10
  class BarRelatee
10
11
  def self.set_relationship(caller, old_value, new_value)
11
12
  end
@@ -243,6 +244,25 @@ class RelatableTest < Test::Unit::TestCase
243
244
  end
244
245
  end
245
246
 
247
+ context "determining the class of relationships" do
248
+ class ClassRelatableModel < EmptyRelatableModel
249
+ relationship :foo, Relatee
250
+ relationship :bar, "RelatableTest::Relatee"
251
+ end
252
+
253
+ setup do
254
+ @model = ClassRelatableModel.new
255
+ end
256
+
257
+ should "just return the class for Class types" do
258
+ assert_equal Relatee, @model.relationship_class(:foo)
259
+ end
260
+
261
+ should "turn string into class" do
262
+ assert_equal Relatee, @model.relationship_class(:bar)
263
+ end
264
+ end
265
+
246
266
  context "populating relationships" do
247
267
  setup do
248
268
  @model = RelatableModel.new
@@ -13,7 +13,7 @@ class AbstractModelTest < Test::Unit::TestCase
13
13
  class Bar; end
14
14
 
15
15
  class FakeModel < VirtualBox::AbstractModel
16
- attribute :foo
16
+ attribute :foo, :property => false
17
17
  attribute :bar
18
18
  relationship :foos, Foo
19
19
  relationship :bars, Bar, :dependent => :destroy
@@ -109,6 +109,11 @@ class AbstractModelTest < Test::Unit::TestCase
109
109
  @model.foo = @model.dup
110
110
  assert_equal "#<AbstractModelTest::FakeModel :bar=nil, :bars=..., :foo=#<AbstractModelTest::FakeModel>, :foos=...>", @model.inspect
111
111
  end
112
+
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
116
+ end
112
117
  end
113
118
 
114
119
  context "validation" do
@@ -323,15 +328,45 @@ class AbstractModelTest < Test::Unit::TestCase
323
328
  end
324
329
  end
325
330
 
331
+ context "integrating interface attributes" do
332
+ setup do
333
+ @model = FakeModel.new
334
+ end
335
+
336
+ should "clear the dirty state of an attribute after saving" do
337
+ key = :foo
338
+ interface = :bar
339
+ @model.expects(:clear_dirty!).with(key).once
340
+ @model.save_interface_attribute(key, interface)
341
+ end
342
+ end
343
+
326
344
  context "integrating relatable" do
327
345
  setup do
328
346
  @model = FakeModel.new
329
347
  end
330
348
 
331
- should "set dirty state when a relationship is set" do
332
- assert !@model.changed?
333
- @model.foos = "foo"
334
- assert @model.changed?
349
+ context "saving all changed interface attributes" do
350
+ setup do
351
+ @changes = [[:a, []], [:b, []], [:c, []]]
352
+ @model.stubs(:changes).returns(@changes)
353
+ end
354
+
355
+ should "save each" do
356
+ @model.changes.each do |key, options|
357
+ @model.expects(:save_interface_attribute).with(key, @interface)
358
+ end
359
+
360
+ @model.save_changed_interface_attributes(@interface)
361
+ end
362
+ end
363
+
364
+ context "with dirty" do
365
+ should "set dirty state when a relationship is set" do
366
+ assert !@model.changed?
367
+ @model.foos = "foo"
368
+ assert @model.changed?
369
+ end
335
370
  end
336
371
  end
337
372
 
@@ -0,0 +1,152 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class ApplianceTest < Test::Unit::TestCase
4
+ setup do
5
+ @klass = VirtualBox::Appliance
6
+ @interface = mock("interface")
7
+ @parent = mock("parent")
8
+ @path = "foo.rb"
9
+
10
+ @appliance = mock("appliance")
11
+ @virtualbox = mock("virtualbox")
12
+ @lib = mock("lib")
13
+ VirtualBox::Lib.stubs(:lib).returns(@lib)
14
+ @lib.stubs(:virtualbox).returns(@virtualbox)
15
+ @virtualbox.stubs(:create_appliance).returns(@appliance)
16
+ end
17
+
18
+ context "class methods" do
19
+
20
+ end
21
+
22
+ context "initializing" do
23
+ should "load interface attribtues" do
24
+ @klass.any_instance.expects(:initialize_from_path).with(@path).once
25
+ @klass.new(@path)
26
+ end
27
+
28
+ context "initializing from path" do
29
+ setup do
30
+ @progress = mock("progress")
31
+ @appliance.stubs(:read).returns(@progress)
32
+ @appliance.stubs(:interpret)
33
+ @appliance.stubs(:virtual_system_descriptions)
34
+ @progress.stubs(:wait_for_completion)
35
+
36
+ @klass.any_instance.stubs(:populate_relationship)
37
+ @klass.any_instance.stubs(:load_interface_attributes)
38
+ end
39
+
40
+ should "write the interface as the appliance" do
41
+ instance = @klass.new(@path)
42
+ assert_equal @appliance, instance.interface
43
+ end
44
+
45
+ should "mark as an existing record" do
46
+ instance = @klass.new(@path)
47
+ assert !instance.new_record?
48
+ end
49
+
50
+ should "read the appliance then interpret it" do
51
+ init_seq = sequence("init")
52
+ @appliance.expects(:read).with(@path).once.returns(@progress).in_sequence(init_seq)
53
+ @progress.expects(:wait_for_completion).with(-1).in_sequence(init_seq)
54
+ @appliance.expects(:interpret).once.in_sequence(init_seq)
55
+ @klass.any_instance.expects(:load_interface_attributes).with(@appliance).once.in_sequence(init_seq)
56
+
57
+ @klass.new(@path)
58
+ end
59
+ end
60
+
61
+ context "initialize without path" do
62
+ setup do
63
+ @instance = @klass.new
64
+ end
65
+
66
+ should "write the interface as the appliance" do
67
+ assert_equal @appliance, @instance.interface
68
+ end
69
+
70
+ should "be new record" do
71
+ assert @instance.new_record?
72
+ end
73
+
74
+ should "not be dirty" do
75
+ assert !@instance.changed?
76
+ end
77
+ end
78
+ end
79
+
80
+ context "instance methods" do
81
+ setup do
82
+ @klass.any_instance.stubs(:initialize_from_path)
83
+ @instance = @klass.new(@path)
84
+ @instance.stubs(:interface).returns(@interface)
85
+ end
86
+
87
+ context "importing" do
88
+ setup do
89
+ @progress = mock("progress")
90
+
91
+ @interface.stubs(:import_machines).returns(@progress)
92
+ end
93
+
94
+ should "call import on interface and wait for completion" do
95
+ @interface.expects(:import_machines).returns(@progress)
96
+ @progress.expects(:wait)
97
+
98
+ @instance.import
99
+ end
100
+
101
+ should "call wait with block given" do
102
+ proc = mock("proc")
103
+ @progress.expects(:wait).yields(proc)
104
+ proc.expects(:call)
105
+
106
+ @instance.import do |proc|
107
+ proc.call
108
+ end
109
+ end
110
+ end
111
+
112
+ context "exporting" do
113
+ setup do
114
+ @progress = mock("progress")
115
+
116
+ @instance.path = :foo
117
+ @interface.stubs(:write).returns(@progress)
118
+ end
119
+
120
+ should "call write on interface and wait for completion" do
121
+ @interface.expects(:write).with("ovf-1.0", @instance.path).once.returns(@progress)
122
+ @progress.expects(:wait)
123
+
124
+ @instance.export
125
+ end
126
+
127
+ should "call wait with block given" do
128
+ proc = mock("proc")
129
+ @progress.expects(:wait).yields(proc)
130
+ proc.expects(:call)
131
+
132
+ @instance.export do |proc|
133
+ proc.call
134
+ end
135
+ end
136
+ end
137
+
138
+ context "adding a machine" do
139
+ setup do
140
+ @machine = mock("machine")
141
+ @machine_interface = mock("machine_interface")
142
+ @machine.stubs(:interface).returns(@machine_interface)
143
+ @machine_interface.stubs(:export)
144
+ end
145
+
146
+ should "call export on the VM interface with the appliance" do
147
+ @machine_interface.expects(:export).with(@interface).once
148
+ @instance.add_machine(@machine)
149
+ end
150
+ end
151
+ end
152
+ end