1 #region Copyright notice and license 2 // Protocol Buffers - Google's data interchange format 3 // Copyright 2008 Google Inc. All rights reserved. 4 // 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file or at 7 // https://developers.google.com/open-source/licenses/bsd 8 #endregion 9 10 using Google.Protobuf.Reflection; 11 using NUnit.Framework; 12 using System; 13 using System.Linq; 14 15 namespace Google.Protobuf.Test.Reflection; 16 17 public class FeatureSetDescriptorTest 18 { 19 // Canonical serialized form of the edition defaults, generated by embed_edition_defaults. 20 // TODO: Update this automatically. 21 private const string DefaultsBase64 = 22 "ChMY5gciDAgBEAIYAiADKAEwAioAChMY5wciDAgCEAEYASACKAEwASoAChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH"; 23 24 [Test] 25 [TestCase(Edition.Proto2)] 26 [TestCase(Edition.Proto3)] 27 [TestCase(Edition._2023)] DefaultsMatchCanonicalSerializedForm(Edition edition)28 public void DefaultsMatchCanonicalSerializedForm(Edition edition) 29 { 30 var canonicalDefaults = FeatureSetDefaults.Parser 31 .WithDiscardUnknownFields(true) // Discard language-specific extensions. 32 .ParseFrom(Convert.FromBase64String(DefaultsBase64)); 33 var canonicalEditionDefaults = new FeatureSet(); 34 canonicalEditionDefaults.MergeFrom( 35 canonicalDefaults.Defaults.Single(def => def.Edition == edition).FixedFeatures); 36 canonicalEditionDefaults.MergeFrom( 37 canonicalDefaults.Defaults.Single(def => def.Edition == edition).OverridableFeatures); 38 var candidateEditionDefaults = FeatureSetDescriptor.GetEditionDefaults(edition).Proto; 39 40 Assert.AreEqual(canonicalEditionDefaults, candidateEditionDefaults); 41 } 42 } 43