~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/erl_interface/test/erl_match_SUITE_data/match_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 * 
 
4
 * Copyright Ericsson AB 1997-2009. All Rights Reserved.
 
5
 * 
 
6
 * The contents of this file are subject to the Erlang Public License,
 
7
 * Version 1.1, (the "License"); you may not use this file except in
 
8
 * compliance with the License. You should have received a copy of the
 
9
 * Erlang Public License along with this software. If not, it can be
 
10
 * retrieved online at http://www.erlang.org/.
 
11
 * 
 
12
 * Software distributed under the License is distributed on an "AS IS"
 
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
 * the License for the specific language governing rights and limitations
 
15
 * under the License.
 
16
 * 
 
17
 * %CopyrightEnd%
 
18
 */
 
19
 
 
20
/*
 
21
 * Purpose: Tests the erl_match() function.
 
22
 * Author:  Bjorn Gustavsson
 
23
 */
 
24
 
 
25
#include "runner.h"
 
26
 
 
27
TESTCASE(erl_match_server)
 
28
{
 
29
    erl_init(NULL, 0);
 
30
 
 
31
    for (;;) {
 
32
        ETERM* pattern;
 
33
        ETERM* term;
 
34
 
 
35
        pattern = get_term();
 
36
        if (pattern == NULL) {
 
37
            report(1);
 
38
            return;
 
39
        } else {
 
40
            term = get_term();
 
41
            if (term == NULL) {
 
42
                fail("Unexpected EOF term");
 
43
            } else {
 
44
                send_term(erl_mk_int(erl_match(pattern, term)));
 
45
                erl_free_term(pattern);
 
46
                erl_free_term(term);
 
47
            }
 
48
        }
 
49
    }
 
50
 
 
51
}
 
52
 
 
53
TESTCASE(erl_match_bind)
 
54
{
 
55
  erl_init(NULL, 0);
 
56
 
 
57
  for (;;) {
 
58
    char* pattern;
 
59
    ETERM* term;
 
60
 
 
61
    pattern=read_packet(NULL);
 
62
 
 
63
    switch (pattern[0]) {
 
64
    case 'e':
 
65
      free(pattern);
 
66
      report(1);
 
67
      return;
 
68
 
 
69
    case 'b':
 
70
      {
 
71
        ETERM* patt_term;
 
72
 
 
73
        /*
 
74
         * Get the pattern string and convert it using erl_format().
 
75
         *
 
76
         * Note that the call to get_term() below destroys the buffer
 
77
         * that the pattern variable points to.  Therefore, it is
 
78
         * essential to call erl_format() here, before 
 
79
         * calling get_term().
 
80
         */
 
81
 
 
82
        message("Pattern: %s", pattern+1);
 
83
        patt_term = erl_format(pattern+1);
 
84
        free(pattern);
 
85
 
 
86
        if (patt_term == NULL) {
 
87
          fail("erl_format() failed");
 
88
        }
 
89
 
 
90
        /*
 
91
         * Get the term and send back the result of the erl_match()
 
92
         * call.
 
93
         */
 
94
 
 
95
        term = get_term();
 
96
        if (term == NULL) {
 
97
          fail("Unexpected eof term");
 
98
        }
 
99
        else {
 
100
          send_term(erl_mk_int(erl_match(patt_term, term)));
 
101
        }
 
102
        erl_free_term(patt_term);
 
103
        erl_free_term(term);
 
104
      }
 
105
    break;
 
106
 
 
107
    default:
 
108
      free(pattern);
 
109
      fail("Illegal character received");
 
110
    }
 
111
      
 
112
  }
 
113
}