1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 1998-2016. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20
21%%
22%%%----------------------------------------------------------------------
23%%% Purpose : This is the test module to be used in with the test cases
24%%%           in the debugger test document.
25%%%----------------------------------------------------------------------
26
27-module(debugger_test).
28
29
30-export ([installation_ok/0,
31	  list/0,
32	  fac/1,
33	  c_break/1]).
34
35
36-define (INT_DIR, "misc").      % The directory of the Interpreter directory
37-define (INT, "interpreter").   % The Interpreter directory name.
38-define (DBG, "debugger").      % Debugger name
39
40
41%%% installation_ok  /0
42%%%
43
44installation_ok () ->
45    debugger_ok (),
46    interpreter_ok ().
47
48
49
50%%% debugger_ok  /0
51%%%
52
53debugger_ok () ->
54    L = code:get_path (),
55
56    case debugger_in_codepath (L) of
57	{true, Msg} ->
58	    out_put (Msg);
59
60	Other ->
61	    out_put (Other)
62    end.
63
64
65
66%%% debugger_in_codepath  /2
67%%%
68
69debugger_in_codepath ([]) ->
70    Msg = io_lib:format ("False: ~s not in code path", [?DBG]),
71    lists:flatten (Msg);
72
73debugger_in_codepath ([Path | T]) ->
74    case string:str (Path, ?DBG) =/= 0 of
75	true ->
76	    Msg = io_lib:format ("Ok: ~s in code path (~s)", [?DBG, Path]),
77	    Msg1 = lists:flatten (Msg),
78	    {true, Msg1};
79
80	_Other ->
81	    debugger_in_codepath (T)
82    end.
83
84
85
86%%% interpreter_ok  /0
87%%%
88
89interpreter_ok () ->
90    Root_dir = code:root_dir (),
91    Misc_dir = filename:join (Root_dir, ?INT_DIR),
92
93    In_misc = case file:list_dir (Misc_dir) of
94		  {ok, L} ->
95		      lists:member (?INT, L);
96
97		  Other ->
98		      Other
99	      end,
100
101    case In_misc of
102	true ->
103	    Msg =  io_lib:format ("Ok: ~s is in ~s", [?INT, ?INT_DIR]),
104	    Msg1 = lists:flatten (Msg),
105	    out_put (Msg1);
106
107	Other1 ->
108	    Msg = io_lib:format ("Error: interpreter in misc - ~s", [Other1]),
109	    Msg1 = lists:flatten (Msg),
110	    out_put (Msg1)
111    end.
112
113
114
115%%% list  /0
116%%%
117
118list () ->
119    A = [1, 2, 3, 4, 5],
120    B = [a, b, c, d, e],
121    lists:append (A, B).
122
123
124
125%%% fac  /1
126%%%
127
128fac (0) ->
129    1;
130
131
132fac (N) ->
133    N * fac (N - 1).
134
135
136
137%%% c_break  /1
138%%%
139
140c_break (Bindings) ->
141    case int:get_binding ('N', Bindings) of
142	{value, 3} ->
143	    true;
144
145	_Other ->
146	    false
147    end.
148
149
150
151%%% out_put  /1
152%%%
153
154out_put (X) ->
155    io:format ("~n~p~n", [X]).
156