[svn:parrot] r39278 - branches/io_rewiring/t/pmc

Infinoid at svn.parrot.org Infinoid at svn.parrot.org
Sat May 30 16:20:29 UTC 2009


Author: Infinoid
Date: Sat May 30 16:20:29 2009
New Revision: 39278
URL: https://trac.parrot.org/parrot/changeset/39278

Log:
[io] Add a test for the Pipe and PipeHandle PMCs.  It only checks object creation and accessor methods for now.
There's a test which spawns a thread to do a write/read test, but spawning the thread crashes parrot, so that's disabled for now.

Added:
   branches/io_rewiring/t/pmc/pipe.t

Added: branches/io_rewiring/t/pmc/pipe.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/io_rewiring/t/pmc/pipe.t	Sat May 30 16:20:29 2009	(r39278)
@@ -0,0 +1,71 @@
+#! parrot
+# Copyright (C) 2009, Parrot Foundation.
+# $Id$
+
+=head1 NAME
+
+t/pmc/pipe.t - test the Pipe and PipeHandle PMCs
+
+
+=head1 SYNOPSIS
+
+    % prove t/pmc/pipe.t
+
+=head1 DESCRIPTION
+
+Tests the Pipe and PipeHandle PMCs.  Creates some pipes, tries some basic I/O.
+
+=cut
+
+.sub main :main
+.include 'test_more.pir'
+    plan(3)
+    test_new()
+    test_reader_writer_methods()
+#    test_reading_writing() # spawn a thread to write to the pipe, read the data
+#    test_blocking_io()     # same thing, but with a delay in the middle
+.end
+
+.sub test_new
+    .local pmc pipe
+    .local string tmp
+    pipe = new ['Pipe']
+    tmp = typeof pipe
+    is(tmp, 'Pipe', 'typeof(Pipe) == "Pipe"')
+.end
+
+.sub test_reader_writer_methods
+    .local pmc pipe, reader, writer
+    .local string tmp
+    pipe = new ['Pipe']
+    reader = pipe.'reader'()
+    writer = pipe.'writer'()
+    tmp = typeof reader
+    is(tmp, 'PipeHandle', 'typeof(reader) == "PipeHandle"')
+    tmp = typeof writer
+    is(tmp, 'PipeHandle', 'typeof(writer) == "PipeHandle"')
+.end
+
+.sub test_reading_writing
+    .local pmc pipe, reader, writer, writer_thread, writer_thread_func
+    .local string teststr, readstr
+
+    pipe = new ['Pipe']
+    reader = pipe.'reader'()
+    writer = pipe.'writer'()
+    writer_thread_func = get_global 'test_reading_writing_writer'
+    writer_thread = new ['ParrotThread']
+    teststr = 'This is a test string.'
+    writer_thread.'run_clone'(writer_thread_func, writer, teststr)
+    readstr = reader.'read'()
+    writer_thread.'join'()
+    is(teststr, readstr, 'read string matches')
+.end
+
+.sub test_reading_writing_writer
+    .param pmc writer
+    .param string teststr
+    writer.'write'(teststr)
+    writer.'close'() # do this explicitly to force a write-buffer flush
+    returncc         # return, killing the thread
+.end


More information about the parrot-commits mailing list