Clean up PROTOC_VERSION checks.

Protoc versions older than 3.0.0 aren't supported anymore anyway,
so no point having checks for them in test cases. Also the checks
weren't consistently applied in all newer tests.
diff --git a/tests/SConstruct b/tests/SConstruct
index 5961f84..880f49e 100644
--- a/tests/SConstruct
+++ b/tests/SConstruct
@@ -71,7 +71,19 @@
         context.Result(result)
         return result
     
-    conf = Configure(env, custom_tests = {'CheckCCFLAGS': check_ccflags})
+    def check_protocversion(context):
+        context.Display("Checking protoc version... ")
+        status, output = context.TryAction('$PROTOC --version > $TARGET')
+        if status:
+            context.Result(str(output.strip()))
+        else:
+            context.Display("error: %s\n" % output.strip())
+            context.did_show_result = 1
+            context.Result("3.6.1") # Assumption
+
+    conf = Configure(env, custom_tests =
+                     {'CheckCCFLAGS': check_ccflags,
+                      'CheckProtocVersion': check_protocversion})
 
     # If the platform doesn't support C99, use our own header file instead.
     stdbool = conf.CheckCHeader('stdbool.h')
@@ -92,18 +104,11 @@
         if stdlib: conf.env.Append(CPPDEFINES = {'HAVE_STDLIB_H': 1})
         if limits: conf.env.Append(CPPDEFINES = {'HAVE_LIMITS_H': 1})
     
-    # Check if we can use pkg-config to find protobuf include path
-    status, output = conf.TryAction('pkg-config protobuf --variable=includedir > $TARGET')
-    if status:
-        conf.env.Append(PROTOCPATH = output.strip())
-    else:
-        conf.env.Append(PROTOCPATH = '/usr/include')
-    
     # Check protoc version
-    status, output = conf.TryAction('$PROTOC --version > $TARGET')
-    if status:
-        conf.env['PROTOC_VERSION'] = output
+    conf.env['PROTOC_VERSION'] = conf.CheckProtocVersion()
 
+    # Initialize compiler arguments with defaults, unless overridden on
+    # command line.
     if not env.get('NODEFARGS'):
         # Check if libmudflap is available (only with GCC)
         if 'gcc' in env['CC']:
diff --git a/tests/alltypes_proto3/SConscript b/tests/alltypes_proto3/SConscript
index 4c2388e..d9db7be 100644
--- a/tests/alltypes_proto3/SConscript
+++ b/tests/alltypes_proto3/SConscript
@@ -2,44 +2,33 @@
 
 Import("env")
 
-import re
-match = None
-if 'PROTOC_VERSION' in env:
-    match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION'])
+env.NanopbProto(["alltypes", "alltypes.options"])
+enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"])
+dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"])
 
-if match:
-    version = list(map(int, match.groups()))
+# Test the round-trip from nanopb encoder to nanopb decoder
+env.RunTest(enc)
+env.RunTest([dec, "encode_alltypes.output"])
 
-# proto3 syntax is supported by protoc >= 3.0.0
-if env.GetOption('clean') or (match and version[0] >= 3):
+# Re-encode the data using protoc, and check that the results from nanopb
+# match byte-per-byte to the protoc output.
+env.Decode("encode_alltypes.output.decoded",
+           ["encode_alltypes.output", "alltypes.proto"],
+           MESSAGE='AllTypes')
+env.Encode("encode_alltypes.output.recoded",
+           ["encode_alltypes.output.decoded", "alltypes.proto"],
+           MESSAGE='AllTypes')
+env.Compare(["encode_alltypes.output", "encode_alltypes.output.recoded"])
 
-    env.NanopbProto(["alltypes", "alltypes.options"])
-    enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"])
-    dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"])
-
-    # Test the round-trip from nanopb encoder to nanopb decoder
-    env.RunTest(enc)
-    env.RunTest([dec, "encode_alltypes.output"])
-
-    # Re-encode the data using protoc, and check that the results from nanopb
-    # match byte-per-byte to the protoc output.
-    env.Decode("encode_alltypes.output.decoded",
-               ["encode_alltypes.output", "alltypes.proto"],
-               MESSAGE='AllTypes')
-    env.Encode("encode_alltypes.output.recoded",
-               ["encode_alltypes.output.decoded", "alltypes.proto"],
-               MESSAGE='AllTypes')
-    env.Compare(["encode_alltypes.output", "encode_alltypes.output.recoded"])
-
-    # Do the same checks with the optional fields present.
-    env.RunTest("optionals.output", enc, ARGS = ['1'])
-    env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1'])
-    env.Decode("optionals.output.decoded",
-               ["optionals.output", "alltypes.proto"],
-               MESSAGE='AllTypes')
-    env.Encode("optionals.output.recoded",
-               ["optionals.output.decoded", "alltypes.proto"],
-               MESSAGE='AllTypes')
-    env.Compare(["optionals.output", "optionals.output.recoded"])
+# Do the same checks with the optional fields present.
+env.RunTest("optionals.output", enc, ARGS = ['1'])
+env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1'])
+env.Decode("optionals.output.decoded",
+           ["optionals.output", "alltypes.proto"],
+           MESSAGE='AllTypes')
+env.Encode("optionals.output.recoded",
+           ["optionals.output.decoded", "alltypes.proto"],
+           MESSAGE='AllTypes')
+env.Compare(["optionals.output", "optionals.output.recoded"])
 
 
diff --git a/tests/anonymous_oneof/SConscript b/tests/anonymous_oneof/SConscript
index 20fd1cc..50b9ba5 100644
--- a/tests/anonymous_oneof/SConscript
+++ b/tests/anonymous_oneof/SConscript
@@ -2,29 +2,18 @@
 
 Import('env')
 
-import re
+# Anonymous oneofs are supported by clang and gcc
+if 'clang' in env['CC'] or 'gcc' in env['CC']:
+    env2 = env.Clone()
+    if '-pedantic' in env2['CFLAGS']:
+        env2['CFLAGS'].remove('-pedantic')
+    env2.NanopbProto('oneof')
 
-match = None
-if 'PROTOC_VERSION' in env:
-    match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION'])
+    dec = env2.Program(['decode_oneof.c',
+                        'oneof.pb.c',
+                        '$COMMON/pb_decode.o',
+                        '$COMMON/pb_common.o'])
 
-if match:
-    version = list(map(int, match.groups()))
-
-# Oneof is supported by protoc >= 2.6.0
-if env.GetOption('clean') or (match and (version[0] > 2 or (version[0] == 2 and version[1] >= 6))):
-    # Anonymous oneofs are supported by clang and gcc
-    if 'clang' in env['CC'] or 'gcc' in env['CC']:
-        env2 = env.Clone()
-        if '-pedantic' in env2['CFLAGS']:
-            env2['CFLAGS'].remove('-pedantic')
-        env2.NanopbProto('oneof')
-
-        dec = env2.Program(['decode_oneof.c',
-                            'oneof.pb.c',
-                            '$COMMON/pb_decode.o',
-                            '$COMMON/pb_common.o'])
-
-        env2.RunTest("message1.txt", [dec, '$BUILD/oneof/message1.pb'], ARGS = ['1'])
-        env2.RunTest("message2.txt", [dec, '$BUILD/oneof/message2.pb'], ARGS = ['2'])
-        env2.RunTest("message3.txt", [dec, '$BUILD/oneof/message3.pb'], ARGS = ['3'])
+    env2.RunTest("message1.txt", [dec, '$BUILD/oneof/message1.pb'], ARGS = ['1'])
+    env2.RunTest("message2.txt", [dec, '$BUILD/oneof/message2.pb'], ARGS = ['2'])
+    env2.RunTest("message3.txt", [dec, '$BUILD/oneof/message3.pb'], ARGS = ['3'])
diff --git a/tests/field_size_16_proto3/SConscript b/tests/field_size_16_proto3/SConscript
index 4a8e16d..1bb6fd9 100644
--- a/tests/field_size_16_proto3/SConscript
+++ b/tests/field_size_16_proto3/SConscript
@@ -2,33 +2,22 @@
 
 Import("env")
 
-import re
-match = None
-if 'PROTOC_VERSION' in env:
-    match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION'])
+env.NanopbProto(["alltypes", "alltypes.options"])
 
-if match:
-    version = list(map(int, match.groups()))
+# Define the compilation options
+opts = env.Clone()
+opts.Append(CPPDEFINES = {'PB_FIELD_16BIT': 1})
 
-# proto3 syntax is supported by protoc >= 3.0.0
-if env.GetOption('clean') or (match and version[0] >= 3):
+# Build new version of core
+strict = opts.Clone()
+strict.Append(CFLAGS = strict['CORECFLAGS'])
+strict.Object("pb_decode_fields16.o", "$NANOPB/pb_decode.c")
+strict.Object("pb_encode_fields16.o", "$NANOPB/pb_encode.c")
+strict.Object("pb_common_fields16.o", "$NANOPB/pb_common.c")
 
-    env.NanopbProto(["alltypes", "alltypes.options"])
+# Now build and run the test normally.
+enc = opts.Program(["encode_alltypes.c", "alltypes.pb.c", "pb_encode_fields16.o", "pb_common_fields16.o"])
+dec = opts.Program(["decode_alltypes.c", "alltypes.pb.c", "pb_decode_fields16.o", "pb_common_fields16.o"])
 
-    # Define the compilation options
-    opts = env.Clone()
-    opts.Append(CPPDEFINES = {'PB_FIELD_16BIT': 1})
-
-    # Build new version of core
-    strict = opts.Clone()
-    strict.Append(CFLAGS = strict['CORECFLAGS'])
-    strict.Object("pb_decode_fields16.o", "$NANOPB/pb_decode.c")
-    strict.Object("pb_encode_fields16.o", "$NANOPB/pb_encode.c")
-    strict.Object("pb_common_fields16.o", "$NANOPB/pb_common.c")
-
-    # Now build and run the test normally.
-    enc = opts.Program(["encode_alltypes.c", "alltypes.pb.c", "pb_encode_fields16.o", "pb_common_fields16.o"])
-    dec = opts.Program(["decode_alltypes.c", "alltypes.pb.c", "pb_decode_fields16.o", "pb_common_fields16.o"])
-
-    env.RunTest(enc)
-    env.RunTest([dec, "encode_alltypes.output"])
+env.RunTest(enc)
+env.RunTest([dec, "encode_alltypes.output"])
diff --git a/tests/oneof/SConscript b/tests/oneof/SConscript
index 928ce63..cbd6abc 100644
--- a/tests/oneof/SConscript
+++ b/tests/oneof/SConscript
@@ -2,32 +2,21 @@
 
 Import('env')
 
-import re
+env.NanopbProto('oneof')
 
-match = None
-if 'PROTOC_VERSION' in env:
-    match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION'])
+enc = env.Program(['encode_oneof.c',
+                'oneof.pb.c',
+                '$COMMON/pb_encode.o',
+                '$COMMON/pb_common.o'])
 
-if match:
-    version = list(map(int, match.groups()))
+dec = env.Program(['decode_oneof.c',
+                'oneof.pb.c',
+                '$COMMON/pb_decode.o',
+                '$COMMON/pb_common.o'])
 
-# Oneof is supported by protoc >= 2.6.0
-if env.GetOption('clean') or (match and (version[0] > 2 or (version[0] == 2 and version[1] >= 6))):
-    env.NanopbProto('oneof')
-
-    enc = env.Program(['encode_oneof.c',
-                    'oneof.pb.c',
-                    '$COMMON/pb_encode.o',
-                    '$COMMON/pb_common.o'])
-
-    dec = env.Program(['decode_oneof.c',
-                    'oneof.pb.c',
-                    '$COMMON/pb_decode.o',
-                    '$COMMON/pb_common.o'])
-
-    env.RunTest("message1.pb", enc, ARGS = ['1'])
-    env.RunTest("message1.txt", [dec, 'message1.pb'], ARGS = ['1'])
-    env.RunTest("message2.pb", enc, ARGS = ['2'])
-    env.RunTest("message2.txt", [dec, 'message2.pb'], ARGS = ['2'])
-    env.RunTest("message3.pb", enc, ARGS = ['3'])
-    env.RunTest("message3.txt", [dec, 'message3.pb'], ARGS = ['3'])
+env.RunTest("message1.pb", enc, ARGS = ['1'])
+env.RunTest("message1.txt", [dec, 'message1.pb'], ARGS = ['1'])
+env.RunTest("message2.pb", enc, ARGS = ['2'])
+env.RunTest("message2.txt", [dec, 'message2.pb'], ARGS = ['2'])
+env.RunTest("message3.pb", enc, ARGS = ['3'])
+env.RunTest("message3.txt", [dec, 'message3.pb'], ARGS = ['3'])