anchor.diff:      %% Default errors field but a non-answer-message and only 3xxx
       %% errors detected means diameter sets neither Result-Code nor
       %% Failed-AVP.
  -    #diameter_packet{msg = answer(Req, Caps)};
  -
  -request(send_double_error, Req, Caps) ->
  -    answer(Req, Caps).
  +    {reply, #diameter_packet{msg = answer(Req, Caps)}};
  +
  +request(T, Req, Caps)
  +  when T == send_double_error;
  +       T == send_missing_avp ->
  +    {reply, answer(Req, Caps)};
  +
  +request(send_ignore_missing_avp, Req, Caps) ->
  +    {reply, #diameter_packet{msg = answer(Req, Caps),
  +                             errors = false}}.  %% ignore errors
   
   answer(Req, Caps) ->
       #diameter_base_STR{'Session-Id' = SId}
  
positive.code:     ok = diameter:stop_service(?SERVER),
      ok = diameter:stop_service(?CLIENT).
  
  %% send_unknown_command/1
  %%
  %% Send a unknown command and expect a different result depending on
  %% whether or not the server gets a handle_request callback.
  
  %% Server handle_request discards the request.
  send_unknown_command(callback) ->
      {error, timeout} = call();
  
  %% No handle_request, diameter answers.
  send_unknown_command(answer_3xxx) ->
      #'diameter_base_answer-message'{'Result-Code' = ?UNSUPPORTED_COMMAND}
          = call();
  
  send_unknown_command(Config) ->
      ?testcase(Config),
      send_unknown_command(?group(Config)).
  
  %% send_ok_override/1
  %%
  %% Send a correct STA and expect the same answer from handle_request
  %% in both cases.
  
  send_ok_override(A)
    when is_atom(A) ->
      #diameter_base_STA{'Result-Code' = ?UNKNOWN_SESSION_ID}
          = call();
  
  send_ok_override(Config) ->
      ?testcase(Config),
      send_ok_override(?group(Config)).
  
  %% send_invalid_avp_bits/1
  %%
  %% Send a request with an incorrect length on the optional
  %% Origin-State-Id and expect a callback to ignore the error.
  
  send_invalid_avp_bits(callback) ->
      #diameter_base_STA{'Result-Code' = ?SUCCESS,
                         'Failed-AVP' = []}
          = call();
  
  send_invalid_avp_bits(answer_3xxx) ->
      #'diameter_base_answer-message'{'Result-Code' = ?INVALID_AVP_BITS,
                                      'Failed-AVP' = []}
          = call();
  
  send_invalid_avp_bits(Config) ->
      ?testcase(Config),
      send_invalid_avp_bits(?group(Config)).
  
  %% send_double_error/1
  %%
  %% Send a request with both an incorrect length on the optional
  %% Origin-State-Id and a missing AVP and see that it's answered
  %% differently.
  
  %% diameter answers with the 3xxx error.
  send_double_error(answer_3xxx) ->
      #'diameter_base_answer-message'{'Result-Code' = ?INVALID_AVP_BITS,
                                      'Failed-AVP' = [_]}
          = call();
  
  %% handle_request answers with STA and diameter resets Result-Code.
  send_double_error(callback) ->
      #diameter_base_STA{'Result-Code' = ?MISSING_AVP,
                         'Failed-AVP' = [_]}
          = call();
  
  send_double_error(Config) ->
      ?testcase(Config),
      send_double_error(?group(Config)).
  
  %% ===========================================================================
  
  
negative.code: 
  %% handle_request/3
  
  handle_request(#diameter_packet{header = #diameter_header{application_id = 0},
                                  msg = Msg},
                 ?SERVER,
                 {_, Caps}) ->
      request(Msg, Caps).
  
  request(undefined, _) ->  %% unknown command
      discard;
  
  request(#diameter_base_STR{'Class' = [Name]} = Req, Caps) ->
      request(?A(Name), Req, Caps).
  
  request(send_ok, Req, Caps) ->
      {reply, #diameter_packet{msg = answer(Req, Caps),
                               errors = [5002]}};  %% UNKNOWN_SESSION_ID
  
  request(send_3xxx, _Req, _Caps) ->
      {answer_message, 3999};
  
  request(send_5xxx, _Req, _Caps) ->
      {answer_message, 5999};
  
  request(send_invalid_avp_bits, Req, Caps) ->
      #diameter_base_STR{'Origin-State-Id' = []}
  