Skip to content

Commit

Permalink
Testing decoding of defaults.
Browse files Browse the repository at this point in the history
  • Loading branch information
esstrifork committed Jul 6, 2011
1 parent 132d91a commit a7d95a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/protobuffs_generic.erl
Expand Up @@ -209,7 +209,6 @@ to_record(RecordInfo, FieldList) ->
end.

add_record_field(Field, Record, RecordFields) ->
io:format("add_record_field ~p\n", [{Record, Field, RecordFields}]),
Name = element(2, Field),
Index = 1 + index_of_name_in_list(Name, RecordFields),
NewValue =
Expand Down
13 changes: 12 additions & 1 deletion test/protobuffs_tests.erl
Expand Up @@ -249,7 +249,7 @@ parse_extend_in_reserved_range_test_() ->
[?_assertEqual(out_of_range, Error)].


should_encode_to_empty_test_() ->
defaults_should_encode_to_empty_test_() ->
DataDir = "../test/erlang_protobuffs_SUITE_data",
Path = filename:absname(filename:join([DataDir,"hasdefault.proto"])),
ok = protobuffs_compile:scan_file(Path),
Expand All @@ -262,6 +262,17 @@ should_encode_to_empty_test_() ->
[?_assertEqual(<<>>, hasdefault_pb:encode_optionalwithdefault(R))
|| R <- [EncodeToEmpty1 | EncodeToEmpties]].

empty_should_decode_to_defaults_test_() ->
DataDir = "../test/erlang_protobuffs_SUITE_data",
Path = filename:absname(filename:join([DataDir,"hasdefault.proto"])),
ok = protobuffs_compile:scan_file(Path),

RecordWithDefaults = {optionalwithdefault,
1.0, 2.0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
true, "test"},
[?_assertEqual(RecordWithDefaults,
hasdefault_pb:decode(optionalwithdefault, <<>>))].

absent_list_should_decode_to_nil_test_() ->
DataDir = "../test/erlang_protobuffs_SUITE_data",
Path = filename:absname(filename:join([DataDir,"addressbook.proto"])),
Expand Down

0 comments on commit a7d95a7

Please sign in to comment.