Stream selection and control

These predicates link an external source/sink with a Prolog stream, its stream-term and stream alias. They enable the source/sink to be opened and closed, and its properties found during execution.

The following predicates do not have examples to automate in this test:

1. open/4, open/3

open(Source_sink, Mode, Stream, Options) is true.

The predicate open/3 provides a similar functionality to open/4 except that a goal open(Source_sink, Mode, Stream) opens the source/sink Source_sink with an empty list of stream-options.

Templates and modes for the predicate are as follows:

open(@source_sink, @io_mode, -stream, @stream_options)
open(@source_sink, @io_mode, -stream)

1.1 Example tests

Let's start with some simple tests verifying success of failure of single goals.

fit.ActionFixture
start alice.tuprolog.EngineFixture
enter query open('/user/roger/data', read, D, [type(binary)]).
check hasSolution true It opens the binary file /user/roger/data for input, and unifies D with a stream-term for the stream
enter query open('/user/scowen', write, D, [alias(editor)]).
check hasSolution true It opens the text file /user/scowen for output, unifies D with a stream-term for the stream, and associates the alias editor with the stream
enter query open('/user/dave/data', read, DD, []).
check hasSolution true It opens the text file /user/dave/data for input, and unifies DD with a stream-term for the stream

2. stream_property/2

stream_property(Stream, Property) is true iff the stream associated with the stream-term Stream has stream property Property.

stream_property(Stream, Property) is re-executable.

Templates and modes for the predicate are as follows:

stream_property(?stream, ?stream_property)

2.1 Example tests

Let's start with some simple tests verifying success of failure of single goals.

fit.ActionFixture
start alice.tuprolog.EngineFixture
enter query stream_property(S, file_name(F)).
check hasSolution true Unifies S with a stream-term and F with the name of the file to which it is connected
check hasAnotherSolution true On re-execution, succeeds in turn with each stream that is connected to a file
enter query stream_property(S, output).
check hasSolution true Unifies S with a stream-term which is open for output
check hasAnotherSolution true On re-execution, succeeds in turn with each stream that is open for output

Run the tests!


The results of the tests for Stream selection and control are as follows:

fit.Summary