build "core init test/volatile_object"

create_boot_directory

install_config {
	<config>
		<parent-provides>
			<service name="ROM"/>
			<service name="RAM"/>
			<service name="CPU"/>
			<service name="RM"/>
			<service name="CAP"/>
			<service name="PD"/>
			<service name="SIGNAL"/>
			<service name="LOG"/>
		</parent-provides>
		<default-route>
			<any-service> <parent/> <any-child/> </any-service>
		</default-route>
		<start name="test-volatile_object">
			<resource name="RAM" quantum="1M"/>
		</start>
	</config>
}

build_boot_image "core init test-volatile_object"

append qemu_args "-nographic -m 64"

run_genode_until {child exited with exit value 0.*\n} 10

grep_output {-> test-volatile_object}

compare_output_to {
[init -> test-volatile_object] --- test-volatile_object started ---
[init -> test-volatile_object] construct Object 1
[init -> test-volatile_object] construct Object 2
[init -> test-volatile_object] -- create Compound object --
[init -> test-volatile_object] construct Member_with_reference
[init -> test-volatile_object] construct Compound
[init -> test-volatile_object] compound.member.is_constructed returns 1
[init -> test-volatile_object] compound.lazy_member.is_constructed returns 0
[init -> test-volatile_object] -- construct lazy member --
[init -> test-volatile_object] construct Member_with_reference
[init -> test-volatile_object] compound.lazy_member.is_constructed returns 1
[init -> test-volatile_object] -- call method on member (with reference to Object 1) --
[init -> test-volatile_object] const method called on Object 1
[init -> test-volatile_object] -- reconstruct member with Object 2 as reference --
[init -> test-volatile_object] destruct Member_with_reference
[init -> test-volatile_object] construct Member_with_reference
[init -> test-volatile_object] -- call method on member --
[init -> test-volatile_object] const method called on Object 2
[init -> test-volatile_object] -- destruct member --
[init -> test-volatile_object] destruct Member_with_reference
[init -> test-volatile_object] -- try to call method on member, catch exception --
[init -> test-volatile_object] got exception, as expected
[init -> test-volatile_object] -- destruct Compound and Objects 1 and 2 --
[init -> test-volatile_object] destruct Compound
[init -> test-volatile_object] destruct Member_with_reference
[init -> test-volatile_object] destruct Object 2
[init -> test-volatile_object] destruct Object 1
[init -> test-volatile_object] -- construct Throwing object
[init -> test-volatile_object] construct Throwing -> don't throw
[init -> test-volatile_object] destruct Throwing
[init -> test-volatile_object] construct Throwing -> throw exception
[init -> test-volatile_object] -- catched exception as expected
[init -> test-volatile_object] --- test-volatile_object finished ---
}

