Commits

Stanisław Pitucha committed 05df693

some updates to scenario processing

Comments (0)

Files changed (2)

 -module(scenario).
+-include("scenario.hrl").
 -include_lib("xmerl/include/xmerl.hrl").
 -export([read/1]).
 
 get_title({#xmlElement{name = scenario, attributes = Attribs}, _}) ->
 	get_title_attr(Attribs).
 
+process_send_attributes(Rec, []) -> Rec;
+process_send_attributes(Rec, [#xmlAttribute{name=start_rtd, value=Val}|As]) -> process_send_attributes(Rec#stepSend{start_rtd=Val}, As);
+process_send_attributes(Rec, [#xmlAttribute{name=rtd, value=Val}|As]) -> process_send_attributes(Rec#stepSend{rtd=Val}, As);
+process_send_attributes(Rec, [#xmlAttribute{name=crlf, value=Val}|As]) -> process_send_attributes(Rec#stepSend{crlf=Val}, As);
+process_send_attributes(Rec, [#xmlAttribute{name=retrans, value=Val}|As]) -> process_send_attributes(Rec#stepSend{retrans=list_to_integer(Val)}, As);
+process_send_attributes(Rec, [#xmlAttribute{name=lost, value=Val}|As]) -> process_send_attributes(Rec#stepSend{lost=list_to_integer(Val)}, As);
+process_send_attributes(_Rec, [#xmlAttribute{name=Name}|_As]) -> throw({unknown_send_attribute, Name}).
+
+create_send(Elem) -> process_send_attributes(#stepSend{}, Elem#xmlElement.attributes).
+
+list_to_boolean("true") -> true;
+list_to_boolean(_) -> false.
+
+process_recv_attributes(Rec, []) -> Rec;
+process_recv_attributes(Rec, [#xmlAttribute{name=start_rtd, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{start_rtd=Val}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=rtd, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{rtd=Val}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=crlf, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{crlf=Val}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=response, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{response=Val}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=request, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{request=Val}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=optional, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{optional=list_to_boolean(Val)}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=rrs, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{rrs=list_to_boolean(Val)}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=auth, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{auth=list_to_boolean(Val)}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=lost, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{lost=list_to_integer(Val)}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=timeout, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{timeout=list_to_integer(Val)}, As);
+process_recv_attributes(Rec, [#xmlAttribute{name=ontimeout, value=Val}|As]) -> process_recv_attributes(Rec#stepRecv{ontimeout=list_to_integer(Val)}, As);
+process_recv_attributes(_Rec, [#xmlAttribute{name=Name}|_As]) -> throw({unknown_recv_attribute, Name}).
+
+create_recv(Elem) -> process_recv_attributes(#stepRecv{}, Elem#xmlElement.attributes).
+
 filter_actions(Acc, []) -> Acc;
-filter_actions(Acc, [#xmlElement{name = send} = Elem|Es]) -> filter_actions([Elem|Acc], Es);
-filter_actions(Acc, [#xmlElement{name = recv} = Elem|Es]) -> filter_actions([Elem|Acc], Es);
+filter_actions(Acc, [#xmlElement{name = send} = Elem|Es]) -> filter_actions([create_send(Elem)|Acc], Es);
+filter_actions(Acc, [#xmlElement{name = recv} = Elem|Es]) -> filter_actions([create_recv(Elem)|Acc], Es);
 filter_actions(Acc, [#xmlElement{name = pause} = Elem|Es]) -> filter_actions([Elem|Acc], Es);
 filter_actions(Acc, [#xmlElement{name = 'ResponseTimeRepartition'} = Elem|Es]) -> filter_actions([Elem|Acc], Es);
 filter_actions(Acc, [#xmlElement{name = 'CallLengthRepartition'} = Elem|Es]) -> filter_actions([Elem|Acc], Es);
 filter_actions(_, [#xmlElement{name = Name}|_]) -> throw({unknown_xml_element, Name});
 filter_actions(_, [E|_]) -> throw({unknown_element, E}).
 
-filter_actions(Es) when is_list(Es) -> filter_actions([], Es).
+filter_actions(Es) when is_list(Es) -> lists:reverse(filter_actions([], Es)).
 
 get_actions({#xmlElement{name = scenario, content = Content}, _}) ->
 	filter_actions(Content).
+-record(stepSend, {crlf, start_rtd, rtd, retrans, lost, packet}). % not implemented: , start_txn, ack_txn].
+-record(stepRecv, {crlf, start_rtd, rtd, response, request, optional, rrs, auth, lost, timeout, ontimeout}). % not implemented: regexp_match, response_txn].
+