Improve .proto options parsing.
[apps/agl-service-can-low-level.git] / tests / Makefile
index 5a5d94a..434819c 100644 (file)
@@ -4,13 +4,16 @@ DEPS=../pb_decode.h ../pb_encode.h ../pb.h person.pb.h callbacks.pb.h unittests.
 TESTS=test_decode1 test_encode1 decode_unittests encode_unittests test_no_messages
 
 # More strict checks for the core part of nanopb
-CFLAGS_CORE=-pedantic -Wextra
+CFLAGS_CORE=-pedantic -Wextra -Wcast-qual -Wlogical-op -Wconversion
 
 all: breakpoints $(TESTS) run_unittests
 
 clean:
        rm -f $(TESTS) person.pb* alltypes.pb* *.o *.gcda *.gcno
 
+%.pb.o: %.pb.c %.pb.h
+       $(CC) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
+
 %.o: %.c
 %.o: %.c $(DEPS)
        $(CC) $(CFLAGS) -c -o $@ $<
@@ -20,6 +23,12 @@ pb_encode.o: ../pb_encode.c $(DEPS)
 pb_decode.o: ../pb_decode.c $(DEPS)
        $(CC) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
 
+pb_encode.cxx.o: ../pb_encode.c $(DEPS)
+       $(CXX) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
+pb_decode.cxx.o: ../pb_decode.c $(DEPS)
+       $(CXX) $(CFLAGS) $(CFLAGS_CORE) -c -o $@ $<
+
+test_cxxcompile: pb_encode.cxx.o pb_decode.cxx.o
 test_decode1: test_decode1.o pb_decode.o person.pb.o
 test_decode2: test_decode2.o pb_decode.o person.pb.o
 test_decode3: test_decode3.o pb_decode.o alltypes.pb.o
@@ -46,7 +55,7 @@ coverage: run_unittests
        gcov pb_encode.gcda
        gcov pb_decode.gcda
 
-run_unittests: decode_unittests encode_unittests test_encode1 test_encode2 test_encode3 test_decode1 test_decode2 test_decode3 test_encode_callbacks test_decode_callbacks test_missing_fields
+run_unittests: decode_unittests encode_unittests test_cxxcompile test_encode1 test_encode2 test_encode3 test_decode1 test_decode2 test_decode3 test_encode_callbacks test_decode_callbacks test_missing_fields test_options
        rm -f *.gcda
        
        ./decode_unittests > /dev/null
@@ -61,13 +70,25 @@ run_unittests: decode_unittests encode_unittests test_encode1 test_encode2 test_
        [ "`./test_encode2 | ./test_decode2`" = \
        "`./test_encode2 | protoc --decode=Person -I. -I../generator -I/usr/include person.proto`" ]
        
+       [ "`./test_decode2 < person_with_extra_field.pb`" = \
+       "`./test_encode2 | ./test_decode2`" ]
+       
        [ "`./test_encode_callbacks | ./test_decode_callbacks`" = \
        "`./test_encode_callbacks | protoc --decode=TestMessage callbacks.proto`" ]
 
        ./test_encode3 | ./test_decode3
-       ./test_encode3 | protoc --decode=AllTypes -I. -I../generator -I/usr/include alltypes.proto >/dev/null
+       ./test_encode3 1 | ./test_decode3 1
+       ./test_encode3 1 | protoc --decode=AllTypes -I. -I../generator -I/usr/include alltypes.proto >/dev/null
        
        ./test_missing_fields
 
+test_options: options.pb.h options.expected
+       for p in $$(grep . options.expected); do \
+           if ! grep -qF "$$p" $<; then \
+               echo Expected: $$p; \
+               exit 1; \
+           fi \
+       done
+
 run_fuzztest: test_decode2
        bash -c 'I=1; while true; do cat /dev/urandom | ./test_decode2 > /dev/null; I=$$(($$I+1)); echo -en "\r$$I"; done'