Sophie

Sophie

distrib > Fedora > 17 > i386 > media > updates > by-pkgid > 675c8c8167236dfcf8d66da674f931e8 > files > 1474

erlang-doc-R15B-03.3.fc17.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css">
<title>Erlang -- Examples</title>
</head>
<body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container">
<script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript">
            <!--
              function getWinHeight() {
                var myHeight = 0;
                if( typeof( window.innerHeight ) == 'number' ) {
                  //Non-IE
                  myHeight = window.innerHeight;
                } else if( document.documentElement && ( document.documentElement.clientWidth ||
                                                         document.documentElement.clientHeight ) ) {
                  //IE 6+ in 'standards compliant mode'
                  myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                  //IE 4 compatible
                  myHeight = document.body.clientHeight;
                }
                return myHeight;
              }

              function setscrollpos() {
                var objf=document.getElementById('loadscrollpos');
                 document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2;
              }

              function addEvent(obj, evType, fn){
                if (obj.addEventListener){
                obj.addEventListener(evType, fn, true);
                return true;
              } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
              } else {
                return false;
              }
             }

             addEvent(window, 'load', setscrollpos);

             //--></script><div id="leftnav"><div class="innertube">
<img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/test_server-3.5.3.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>Test Server</strong><br><strong>User's Guide</strong><br><small>Version 3.5.3</small></p>
<br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p>
<ul class="flipMenu" imagepath="../../../../doc/js/flipmenu">
<li id="no" title="Test Server Basics" expanded="false">Test Server Basics<ul>
<li><a href="basics_chapter.html">
              Top of chapter
            </a></li>
<li title="Introduction"><a href="basics_chapter.html#id56984">Introduction</a></li>
<li title="Getting started"><a href="basics_chapter.html#id56907">Getting started</a></li>
<li title="Definition of terms"><a href="basics_chapter.html#id61500">Definition of terms</a></li>
</ul>
</li>
<li id="no" title="Test Structure and Test Specifications" expanded="false">Test Structure and Test Specifications<ul>
<li><a href="test_spec_chapter.html">
              Top of chapter
            </a></li>
<li title="Test structure"><a href="test_spec_chapter.html#id62057">Test structure</a></li>
<li title="Test specifications"><a href="test_spec_chapter.html#id57989">Test specifications</a></li>
<li title="Test Specification Files"><a href="test_spec_chapter.html#id63174">Test Specification Files</a></li>
<li title="Configuration cases"><a href="test_spec_chapter.html#id60965">Configuration cases</a></li>
<li title="The parallel property and nested configuration cases"><a href="test_spec_chapter.html#id56819">The parallel property and nested configuration cases</a></li>
<li title="Repeated execution of test cases"><a href="test_spec_chapter.html#id56843">Repeated execution of test cases</a></li>
<li title="Shuffled test case order"><a href="test_spec_chapter.html#id59974">Shuffled test case order</a></li>
<li title="Skipping test cases"><a href="test_spec_chapter.html#id60025">Skipping test cases</a></li>
</ul>
</li>
<li id="no" title="Writing Test Suites" expanded="false">Writing Test Suites<ul>
<li><a href="write_test_chapter.html">
              Top of chapter
            </a></li>
<li title="Support for test suite authors"><a href="write_test_chapter.html#id62420">Support for test suite authors</a></li>
<li title="Test suites"><a href="write_test_chapter.html#id62477">Test suites</a></li>
<li title="Init per test case"><a href="write_test_chapter.html#id62508">Init per test case</a></li>
<li title="Test cases"><a href="write_test_chapter.html#id62581">Test cases</a></li>
<li title="Data and Private Directories"><a href="write_test_chapter.html#id62718">Data and Private Directories</a></li>
<li title="Execution environment"><a href="write_test_chapter.html#id62776">Execution environment</a></li>
</ul>
</li>
<li id="no" title="Running Test Suites" expanded="false">Running Test Suites<ul>
<li><a href="run_test_chapter.html">
              Top of chapter
            </a></li>
<li title="Using the test server controller"><a href="run_test_chapter.html#id62898">Using the test server controller</a></li>
</ul>
</li>
<li id="no" title="Write you own test server framework" expanded="false">Write you own test server framework<ul>
<li><a href="write_framework_chapter.html">
              Top of chapter
            </a></li>
<li title="Introduction"><a href="write_framework_chapter.html#id62979">Introduction</a></li>
<li title="Interfacing the test server controller from Erlang"><a href="write_framework_chapter.html#id62997">Interfacing the test server controller from Erlang</a></li>
<li title="Interfacing the test server controller from the operating system."><a href="write_framework_chapter.html#id63107">Interfacing the test server controller from the operating system.</a></li>
<li title="Framework callback functions"><a href="write_framework_chapter.html#id63412">Framework callback functions</a></li>
<li title="Other concerns"><a href="write_framework_chapter.html#id63442">Other concerns</a></li>
</ul>
</li>
<li id="loadscrollpos" title="Examples" expanded="true">Examples<ul>
<li><a href="example_chapter.html">
              Top of chapter
            </a></li>
<li title="Test suite"><a href="example_chapter.html#id63550">Test suite</a></li>
<li title="Test specification file"><a href="example_chapter.html#id63589">Test specification file</a></li>
</ul>
</li>
</ul>
</div></div>
<div id="content">
<div class="innertube">
<h1>6 Examples</h1>
  

  <h3><a name="id63550">6.1 
        Test suite</a></h3>
    
    <div class="example"><pre>
-module(my_SUITE).

-export([all/1,
         not_started/1, not_started_func1/1, not_started_func2/1,
         start/1, stop/1,
         func1/1, func2/1 
        ]).

-export([init_per_testcase/2, end_per_testcase/2]).

-include("test_server.hrl").

-define(default_timeout, ?t:minutes(1)).

init_per_testcase(_Case, Config) -&gt;
    ?line Dog=?t:timetrap(?default_timeout),
    [{watchdog, Dog}|Config].
end_per_testcase(_Case, Config) -&gt;
    Dog=?config(watchdog, Config),
    ?t:timetrap_cancel(Dog),
    ok.

all(suite) -&gt; 
    %% Test specification on test suite level
    [not_started,
     {conf, start, [func1, func2], stop}].

not_started(suite) -&gt;
    %% Test specification on test case level
    [not_started_func1, not_started_func2];
not_started(doc) -&gt;
    ["Testing all functions when application is not started"].
%% No execution clause unless the specification clause returns [].


not_started_func1(suite) -&gt;
    [];
not_started_func1(doc) -&gt;
    ["Testing function 1 when application is not started"].
not_started_func1(Config) when list(Config) -&gt;
    ?line {error, not_started} = myapp:func1(dummy_ref,1),
    ?line {error, not_started} = myapp:func1(dummy_ref,2),
    ok.

not_started_func2(suite) -&gt;
    [];
not_started_func2(doc) -&gt;
    ["Testing function 2 when application is not started"].
not_started_func2(Config) when list(Config) -&gt;
    ?line {error, not_started} = myapp:func2(dummy_ref,1),
    ?line {error, not_started} = myapp:func2(dummy_ref,2),
    ok.


%% No specification clause needed for an init function in a conf case!!!
start(doc) -&gt;
    ["Testing start of my application."];
start(Config) when list(Config) -&gt;
    ?line Ref = myapp:start(),
    case erlang:whereis(my_main_process) of
      Pid when pid(Pid) -&gt; 
         [{myapp_ref,Ref}|Config];
      undefined -&gt; 
         %% Since this is the init function in a conf case, the rest of the 
         %% cases in the conf case will be skipped if this case fails.
         ?t:fail("my_main_process did not start")
    end.

func1(suite) -&gt;
    [];
func1(doc) -&gt;
    ["Test that func1 returns ok when argument is 1 and error if argument is 2"];
func1(Config) when list(Config) -&gt;
    ?line Ref = ?config(myapp_ref,Config),
    ?line ok = myapp:func1(Ref,1),
    ?line error = myapp:func1(Ref,2),
    ok.

func2(suite) -&gt;
    [];
func2(doc) -&gt;
    ["Test that func1 returns ok when argument is 3 and error if argument is 4"];
func2(Config) when list(Config) -&gt;
    ?line Ref = ?config(myapp_ref,Config),
    ?line ok = myapp:func2(Ref,3),
    ?line error = myapp:func2(Ref,4),
    ok.

%% No specification clause needed for a cleanup function in a conf case!!!
stop(doc) -&gt;
    ["Testing termination of my application"];
stop(Config) when list(Config) -&gt;
    ?line Ref = ?config(myapp_ref,Config),
    ?line ok = myapp:stop(Ref),
    case erlang:whereis(my_main_process) of
      undefined -&gt; 
         lists:keydelete(myapp_ref,1,Config);
      Pid when pid(Pid) -&gt; 
         ?t:fail("my_main_process did not stop")
    end.
    </pre></div>
  

  <h3><a name="id63589">6.2 
        Test specification file</a></h3>
    
    <p><strong><span class="code">myapp.spec:</span></strong></p>
    <div class="example"><pre>
{topcase, {dir, "../myapp_test"}}. % Test specification on top level    </pre></div>
    <p><strong><span class="code">myapp.spec.vxworks:</span></strong></p>
    <div class="example"><pre>
{topcase, {dir, "../myapp_test"}}. % Test specification on top level
{skip,{my_SUITE,func2,"Not applicable on VxWorks"}}.    </pre></div>
  
</div>
<div class="footer">
<hr>
<p>Copyright © 2002-2012 Ericsson AB. All Rights Reserved.</p>
</div>
</div>
</div></body>
</html>