Example #1
0
        public void SetValue_MapFields()
        {
            IMessage message = new TestMap();
            var      fields  = message.Descriptor.Fields;

            Assert.Throws <InvalidOperationException>(() => fields[TestMap.MapStringStringFieldNumber].Accessor.SetValue(message, new Dictionary <string, string>()));
        }
 private SceneGraph BuildSceneGraph()
 {
     Rectangle viewport = new Rectangle(0, 0, 800, 600);
     Camera camera = new Camera(viewport);
     TestMap map = new TestMap();
     return new SceneGraph(camera, map);
 }
        public void RoundTrip_Maps()
        {
            var message = new TestMap
            {
                MapBoolBool =
                {
                    { false, true  },
                    { true,  false }
                },
                MapInt32Bytes =
                {
                    {  5, ByteString.CopyFrom(6, 7, 8) },
                    { 25, ByteString.CopyFrom(1, 2,3, 4, 5) },
                    { 10, ByteString.Empty }
                },
                MapInt32ForeignMessage =
                {
                    { 0, new ForeignMessage {
                          C = 10
                      } },
                    { 5, new ForeignMessage() },
                },
                MapInt32Enum =
                {
                    {    1, MapEnum.Bar },
                    { 2000, MapEnum.Foo }
                }
            };

            MessageParsingHelpers.AssertWritingMessage(message);

            MessageParsingHelpers.AssertRoundtrip(TestMap.Parser, message);
        }
Example #4
0
 public void Init(App app, TestMap testMap)
 {
     this.app     = app;
     this.testMap = testMap;
     battle.Init(app, this);
     itemSpinner.Init(this);
 }
        public void RoundTrip_Maps()
        {
            var message = new TestMap
            {
                MapBoolBool =
                {
                    { false, true  },
                    { true,  false }
                },
                MapInt32Bytes =
                {
                    {  5, ByteString.CopyFrom(6, 7, 8) },
                    { 25, ByteString.CopyFrom(1, 2,3, 4, 5) },
                    { 10, ByteString.Empty }
                },
                MapInt32ForeignMessage =
                {
                    { 0, new ForeignMessage {
                          C = 10
                      } },
                    { 5, new ForeignMessage() },
                },
                MapInt32Enum =
                {
                    {    1, MapEnum.MAP_ENUM_BAR },
                    { 2000, MapEnum.MAP_ENUM_FOO }
                }
            };

            byte[]  bytes  = message.ToByteArray();
            TestMap parsed = TestMap.Parser.ParseFrom(bytes);

            Assert.AreEqual(message, parsed);
        }
        public void NullValueForMessage()
        {
            var message = new TestMap {
                MapInt32ForeignMessage = { { 10, null } }
            };

            AssertJson("{ 'mapInt32ForeignMessage': { '10': null } }", JsonFormatter.Default.Format(message));
        }
        private SceneGraph BuildSceneGraph()
        {
            Rectangle viewport = new Rectangle(0, 0, 800, 600);
            Camera2D  camera   = new Camera2D(viewport);
            TestMap   map      = new TestMap();

            return(new SceneGraph(camera, map));
        }
Example #8
0
        public void UnknownEnumValueNumeric_MapField()
        {
            var message = new TestMap {
                MapInt32Enum = { { 1, MapEnum.Foo }, { 2, (MapEnum)100 }, { 3, MapEnum.Bar } }
            };

            AssertJson("{ 'mapInt32Enum': { '1': 'MAP_ENUM_FOO', '2': 100, '3': 'MAP_ENUM_BAR' } }", JsonFormatter.Default.Format(message));
        }
        public void NullValueForMessage()
        {
            var message = new TestMap {
                MapInt32ForeignMessage = { { 10, null } }
            };

            Assert.AreEqual("{ \"mapInt32ForeignMessage\": { \"10\": null } }", JsonFormatter.Default.Format(message));
        }
        public void MapNonContiguousEntries()
        {
            var memoryStream = new MemoryStream();
            var output       = new CodedOutputStream(memoryStream);

            // Message structure:
            // Entry for MapInt32Int32
            // Entry for MapStringString
            // Entry for MapInt32Int32

            // First entry
            var key1   = 10;
            var value1 = 20;

            output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
            output.WriteLength(4);
            output.WriteTag(1, WireFormat.WireType.Varint);
            output.WriteInt32(key1);
            output.WriteTag(2, WireFormat.WireType.Varint);
            output.WriteInt32(value1);

            // Second entry
            var key2   = "a";
            var value2 = "b";

            output.WriteTag(TestMap.MapStringStringFieldNumber, WireFormat.WireType.LengthDelimited);
            output.WriteLength(6); // 3 bytes per entry: tag, size, character
            output.WriteTag(1, WireFormat.WireType.LengthDelimited);
            output.WriteString(key2);
            output.WriteTag(2, WireFormat.WireType.LengthDelimited);
            output.WriteString(value2);

            // Third entry
            var key3   = 15;
            var value3 = 25;

            output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
            output.WriteLength(4);
            output.WriteTag(1, WireFormat.WireType.Varint);
            output.WriteInt32(key3);
            output.WriteTag(2, WireFormat.WireType.Varint);
            output.WriteInt32(value3);

            output.Flush();

            MessageParsingHelpers.AssertReadingMessage(
                TestMap.Parser,
                memoryStream.ToArray(),
                parsed =>
            {
                var expected = new TestMap
                {
                    MapInt32Int32   = { { key1, value1 }, { key3, value3 } },
                    MapStringString = { { key2, value2 } }
                };
                Assert.AreEqual(expected, parsed);
            });
        }
Example #11
0
        public void UnknownEnumValueOmitted_MapField()
        {
            // This matches the C++ behaviour.
            var message = new TestMap {
                MapInt32Enum = { { 1, MapEnum.MAP_ENUM_FOO }, { 2, (MapEnum)100 }, { 3, MapEnum.MAP_ENUM_BAR } }
            };

            Assert.AreEqual("{ \"mapInt32Enum\": { \"1\": \"MAP_ENUM_FOO\", \"3\": \"MAP_ENUM_BAR\" } }", JsonFormatter.Default.Format(message));
        }
        public void UnknownEnumValueOmitted_MapField()
        {
            // This matches the C++ behaviour.
            var message = new TestMap {
                MapInt32Enum = { { 1, MapEnum.MAP_ENUM_FOO }, { 2, (MapEnum)100 }, { 3, MapEnum.MAP_ENUM_BAR } }
            };

            AssertJson("{ 'mapInt32Enum': { '1': 'MAP_ENUM_FOO', '3': 'MAP_ENUM_BAR' } }", JsonFormatter.Default.Format(message));
        }
Example #13
0
        public void RegisterClassMap_InvokeExcelClassMap_Success()
        {
            using var importer = Helpers.GetImporter("Primitives.xlsx");
            var map = new TestMap();

            importer.Configuration.RegisterClassMap(map);

            Assert.True(importer.Configuration.TryGetClassMap <int>(out IMap classMap));
            Assert.Same(map, classMap);

            Assert.True(importer.Configuration.TryGetClassMap(typeof(int), out classMap));
            Assert.Same(map, classMap);
        }
Example #14
0
    public void ViewshedContainsNoDuplicates()
    {
        var map = new TestMap(20, 20, Allocator.TempJob,
                              new int2(1, 1),
                              new int2(2, 1));

        FOV.Compute(0, 5, map);

        var points = map.visiblePoints;

        Assert.AreEqual(points.Length, points.ToArray().Distinct().ToArray().Length);

        map.Dispose();
    }
 private async Task InitializeMap(object sender, EventArgs e)
 {
     _logger.LogDebug("Initializing Test map");
     try
     {
         TestMap.Clear();
         TestMap.AddRange(await _staticDataDataAccess.GetBillingTestCodeMappings());
         _logger.LogInformation($"Test map load successful.\n{JsonConvert.SerializeObject(TestMap, Formatting.Indented)}");
     }
     catch (Exception ex)
     {
         _logger.LogCritical($"failed loading test map. \n{ex.Message}\n{ex.StackTrace}");
     }
 }
Example #16
0
        public void GetValue()
        {
            var message = SampleMessages.CreateFullTestAllTypes();
            var fields  = TestAllTypes.Descriptor.Fields;

            Assert.AreEqual(message.SingleBool, fields[TestAllTypes.SingleBoolFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleBytes, fields[TestAllTypes.SingleBytesFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleDouble, fields[TestAllTypes.SingleDoubleFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleFixed32, fields[TestAllTypes.SingleFixed32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleFixed64, fields[TestAllTypes.SingleFixed64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleFloat, fields[TestAllTypes.SingleFloatFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleForeignEnum, fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleForeignMessage, fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleImportEnum, fields[TestAllTypes.SingleImportEnumFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleImportMessage, fields[TestAllTypes.SingleImportMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleInt32, fields[TestAllTypes.SingleInt32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleInt64, fields[TestAllTypes.SingleInt64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleNestedEnum, fields[TestAllTypes.SingleNestedEnumFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleNestedMessage, fields[TestAllTypes.SingleNestedMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SinglePublicImportMessage, fields[TestAllTypes.SinglePublicImportMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleSint32, fields[TestAllTypes.SingleSint32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleSint64, fields[TestAllTypes.SingleSint64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleString, fields[TestAllTypes.SingleStringFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleSfixed32, fields[TestAllTypes.SingleSfixed32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleSfixed64, fields[TestAllTypes.SingleSfixed64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleUint32, fields[TestAllTypes.SingleUint32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleUint64, fields[TestAllTypes.SingleUint64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.OneofBytes, fields[TestAllTypes.OneofBytesFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.OneofString, fields[TestAllTypes.OneofStringFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.OneofNestedMessage, fields[TestAllTypes.OneofNestedMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.OneofUint32, fields[TestAllTypes.OneofUint32FieldNumber].Accessor.GetValue(message));

            // Just one example for repeated fields - they're all just returning the list
            var list = (IList)fields[TestAllTypes.RepeatedInt32FieldNumber].Accessor.GetValue(message);

            Assert.AreEqual(message.RepeatedInt32, list);
            Assert.AreEqual(message.RepeatedInt32[0], list[0]); // Just in case there was any doubt...

            // Just a single map field, for the same reason
            var mapMessage = new TestMap {
                MapStringString = { { "key1", "value1" }, { "key2", "value2" } }
            };

            fields = TestMap.Descriptor.Fields;
            var dictionary = (IDictionary)fields[TestMap.MapStringStringFieldNumber].Accessor.GetValue(mapMessage);

            Assert.AreEqual(mapMessage.MapStringString, dictionary);
            Assert.AreEqual("value1", dictionary["key1"]);
        }
        public void MapWithEmptyEntry()
        {
            var message = new TestMap
            {
                MapInt32Bytes = { { 0, ByteString.Empty } }
            };

            byte[] bytes = message.ToByteArray();
            Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte)

            var parsed = TestMap.Parser.ParseFrom(bytes);

            Assert.AreEqual(1, parsed.MapInt32Bytes.Count);
            Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]);
        }
Example #18
0
    public void TestFOV()
    {
        var map = new TestMap(20, 20, Allocator.TempJob,
                              new int2(1, 1),
                              new int2(2, 1));

        FOV.Compute(0, 5, map);

        var points = map.visiblePoints;

        Assert.False(points.Contains(new int2(3, 3)));
        Assert.True(points.Contains(new int2(2, 1)));
        //Assert.True(points.Contains(new int2(1, 1)));

        map.Dispose();
    }
Example #19
0
        public void RegisterClassMap_InvokeDefault_Success()
        {
            using var importer = Helpers.GetImporter("Primitives.xlsx");
            importer.Configuration.RegisterClassMap <TestMap>();

            Assert.True(importer.Configuration.TryGetClassMap <int>(out IMap classMap));
            TestMap map = Assert.IsType <TestMap>(classMap);

            Assert.Equal(FallbackStrategy.ThrowIfPrimitive, map.EmptyValueStrategy);
            Assert.Equal(typeof(int), map.Type);
            Assert.Empty(map.Properties);

            Assert.True(importer.Configuration.TryGetClassMap(typeof(int), out classMap));
            map = Assert.IsType <TestMap>(classMap);
            Assert.Equal(FallbackStrategy.ThrowIfPrimitive, map.EmptyValueStrategy);
            Assert.Equal(typeof(int), map.Type);
            Assert.Empty(map.Properties);
        }
        public void MapWithEmptyEntry()
        {
            var message = new TestMap
            {
                MapInt32Bytes = { { 0, ByteString.Empty } }
            };

            byte[] bytes = message.ToByteArray();
            Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte)

            MessageParsingHelpers.AssertReadingMessage(
                TestMap.Parser,
                bytes,
                parsed =>
            {
                Assert.AreEqual(1, parsed.MapInt32Bytes.Count);
                Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]);
            });
        }
Example #21
0
        public void GetValue()
        {
            var message = SampleMessages.CreateFullTestAllTypes();
            var fields = TestAllTypes.Descriptor.Fields;
            Assert.AreEqual(message.SingleBool, fields[TestAllTypes.SingleBoolFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleBytes, fields[TestAllTypes.SingleBytesFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleDouble, fields[TestAllTypes.SingleDoubleFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleFixed32, fields[TestAllTypes.SingleFixed32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleFixed64, fields[TestAllTypes.SingleFixed64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleFloat, fields[TestAllTypes.SingleFloatFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleForeignEnum, fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleForeignMessage, fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleImportEnum, fields[TestAllTypes.SingleImportEnumFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleImportMessage, fields[TestAllTypes.SingleImportMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleInt32, fields[TestAllTypes.SingleInt32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleInt64, fields[TestAllTypes.SingleInt64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleNestedEnum, fields[TestAllTypes.SingleNestedEnumFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleNestedMessage, fields[TestAllTypes.SingleNestedMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SinglePublicImportMessage, fields[TestAllTypes.SinglePublicImportMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleSint32, fields[TestAllTypes.SingleSint32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleSint64, fields[TestAllTypes.SingleSint64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleString, fields[TestAllTypes.SingleStringFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleSfixed32, fields[TestAllTypes.SingleSfixed32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleSfixed64, fields[TestAllTypes.SingleSfixed64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleUint32, fields[TestAllTypes.SingleUint32FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.SingleUint64, fields[TestAllTypes.SingleUint64FieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.OneofBytes, fields[TestAllTypes.OneofBytesFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.OneofString, fields[TestAllTypes.OneofStringFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.OneofNestedMessage, fields[TestAllTypes.OneofNestedMessageFieldNumber].Accessor.GetValue(message));
            Assert.AreEqual(message.OneofUint32, fields[TestAllTypes.OneofUint32FieldNumber].Accessor.GetValue(message));

            // Just one example for repeated fields - they're all just returning the list
            var list = (IList) fields[TestAllTypes.RepeatedInt32FieldNumber].Accessor.GetValue(message);
            Assert.AreEqual(message.RepeatedInt32, list);
            Assert.AreEqual(message.RepeatedInt32[0], list[0]); // Just in case there was any doubt...

            // Just a single map field, for the same reason
            var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } };
            fields = TestMap.Descriptor.Fields;
            var dictionary = (IDictionary) fields[TestMap.MapStringStringFieldNumber].Accessor.GetValue(mapMessage);
            Assert.AreEqual(mapMessage.MapStringString, dictionary);
            Assert.AreEqual("value1", dictionary["key1"]);
        }
Example #22
0
        private async Task RetreiveLocation()
        {
            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 20;

            try{
                var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000);

                txtLat.Text  = "Breitengrad: " + position.Latitude.ToString();
                txtLong.Text = "Längengrad: " + position.Longitude.ToString();
                TestMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position.Longitude), Distance.FromKilometers(1)));
            }

            catch (Exception ex)
            {
                //Falls was schiefläuft, z.B. kein GPS aktiviert
                txtLat.Text = ex.Message;
            }
        }
Example #23
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Debug.Log("Instance already exists, destroying object!");
            Destroy(this);
        }


        maps       = new Dictionary <int, Map>();
        mapPrefabs = new Dictionary <int, GameObject>();

        TestMap testMap = new TestMap();

        maps.Add(testMap.GetMapId(), testMap);
        mapPrefabs.Add(testMap.GetMapId(), testMapPrefab);
    }
Example #24
0
    public void UseFOVInsideJob()
    {
        var map = new TestMap(20, 20, Allocator.TempJob,
                              new int2(1, 1),
                              new int2(2, 1));

        new FOVJob
        {
            origin = 0,
            range  = 5,
            map    = map,
        }.Schedule().Complete();

        var points = map.visiblePoints;

        //Assert.False(points.Contains(new int2(3, 3)));
        //Assert.True(points.Contains(new int2(2, 1)));
        //Assert.True(points.Contains(new int2(1, 1)));

        map.Dispose();
    }
Example #25
0

        
Example #26
0
        public void Clear()
        {
            var message = SampleMessages.CreateFullTestAllTypes();
            var fields  = TestAllTypes.Descriptor.Fields;

            fields[TestAllTypes.SingleBoolFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleInt32FieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleStringFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleBytesFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.RepeatedDoubleFieldNumber].Accessor.Clear(message);

            var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes())
            {
                SingleBool           = false,
                SingleInt32          = 0,
                SingleString         = "",
                SingleBytes          = ByteString.Empty,
                SingleForeignEnum    = 0,
                SingleForeignMessage = null,
            };

            expected.RepeatedDouble.Clear();

            Assert.AreEqual(expected, message);

            // Separately, maps.
            var mapMessage = new TestMap {
                MapStringString = { { "key1", "value1" }, { "key2", "value2" } }
            };

            fields = TestMap.Descriptor.Fields;
            fields[TestMap.MapStringStringFieldNumber].Accessor.Clear(mapMessage);
            Assert.AreEqual(0, mapMessage.MapStringString.Count);
        }
        public void MapNonContiguousEntries()
        {
            var memoryStream = new MemoryStream();
            var output = new CodedOutputStream(memoryStream);

            // Message structure:
            // Entry for MapInt32Int32
            // Entry for MapStringString
            // Entry for MapInt32Int32

            // First entry
            var key1 = 10;
            var value1 = 20;
            output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
            output.WriteLength(4);
            output.WriteTag(1, WireFormat.WireType.Varint);
            output.WriteInt32(key1);
            output.WriteTag(2, WireFormat.WireType.Varint);
            output.WriteInt32(value1);

            // Second entry
            var key2 = "a";
            var value2 = "b";
            output.WriteTag(TestMap.MapStringStringFieldNumber, WireFormat.WireType.LengthDelimited);
            output.WriteLength(6); // 3 bytes per entry: tag, size, character
            output.WriteTag(1, WireFormat.WireType.LengthDelimited);
            output.WriteString(key2);
            output.WriteTag(2, WireFormat.WireType.LengthDelimited);
            output.WriteString(value2);

            // Third entry
            var key3 = 15;
            var value3 = 25;
            output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
            output.WriteLength(4);
            output.WriteTag(1, WireFormat.WireType.Varint);
            output.WriteInt32(key3);
            output.WriteTag(2, WireFormat.WireType.Varint);
            output.WriteInt32(value3);

            output.Flush();
            var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
            var expected = new TestMap
            {
                MapInt32Int32 = { { key1, value1 }, { key3, value3 } },
                MapStringString = { { key2, value2 } }
            };
            Assert.AreEqual(expected, parsed);
        }
        public void MapWithEmptyEntry()
        {
            var message = new TestMap
            {
                MapInt32Bytes = { { 0, ByteString.Empty } }
            };

            byte[] bytes = message.ToByteArray();
            Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte)

            var parsed = TestMap.Parser.ParseFrom(bytes);
            Assert.AreEqual(1, parsed.MapInt32Bytes.Count);
            Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]);
        }
        public void RoundTrip_Maps()
        {
            var message = new TestMap
            {
                MapBoolBool = {
                    { false, true },
                    { true, false }
                },
                MapInt32Bytes = {
                    { 5, ByteString.CopyFrom(6, 7, 8) },
                    { 25, ByteString.CopyFrom(1, 2, 3, 4, 5) },
                    { 10, ByteString.Empty }
                },
                MapInt32ForeignMessage = {
                    { 0, new ForeignMessage { C = 10 } },
                    { 5, null },
                },
                MapInt32Enum = {
                    { 1, MapEnum.MAP_ENUM_BAR },
                    { 2000, MapEnum.MAP_ENUM_FOO }
                }
            };

            byte[] bytes = message.ToByteArray();
            TestMap parsed = TestMap.Parser.ParseFrom(bytes);
            Assert.AreEqual(message, parsed);
        }
Example #30
0
 public void UnknownEnumValueOmitted_MapField()
 {
     // This matches the C++ behaviour.
     var message = new TestMap { MapInt32Enum = { { 1, MapEnum.MAP_ENUM_FOO }, { 2, (MapEnum) 100 }, { 3, MapEnum.MAP_ENUM_BAR } } };
     Assert.AreEqual("{ \"mapInt32Enum\": { \"1\": \"MAP_ENUM_FOO\", \"3\": \"MAP_ENUM_BAR\" } }", JsonFormatter.Default.Format(message));
 }
Example #31
0
 public void NullValueForMessage()
 {
     var message = new TestMap { MapInt32ForeignMessage = { { 10, null } } };
     Assert.AreEqual("{ \"mapInt32ForeignMessage\": { \"10\": null } }", JsonFormatter.Default.Format(message));
 }
 public void Setup()
 {
     _testMap = new TestMap(_testMapData);
 }
Example #33
0
 public void NullValueForMessage()
 {
     var message = new TestMap { MapInt32ForeignMessage = { { 10, null } } };
     AssertJson("{ 'mapInt32ForeignMessage': { '10': null } }", JsonFormatter.Default.Format(message));
 }
Example #34
0
 public void UnknownEnumValueOmitted_MapField()
 {
     // This matches the C++ behaviour.
     var message = new TestMap { MapInt32Enum = { { 1, MapEnum.MAP_ENUM_FOO }, { 2, (MapEnum) 100 }, { 3, MapEnum.MAP_ENUM_BAR } } };
     AssertJson("{ 'mapInt32Enum': { '1': 'MAP_ENUM_FOO', '3': 'MAP_ENUM_BAR' } }", JsonFormatter.Default.Format(message));
 }
Example #35
0
 public void SetValue_MapFields()
 {
     IMessage message = new TestMap();
     var fields = message.Descriptor.Fields;
     Assert.Throws<InvalidOperationException>(() => fields[TestMap.MapStringStringFieldNumber].Accessor.SetValue(message, new Dictionary<string, string>()));
 }
Example #36
0
        public void Clear()
        {
            var message = SampleMessages.CreateFullTestAllTypes();
            var fields = TestAllTypes.Descriptor.Fields;
            fields[TestAllTypes.SingleBoolFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleInt32FieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleStringFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleBytesFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.Clear(message);
            fields[TestAllTypes.RepeatedDoubleFieldNumber].Accessor.Clear(message);

            var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes())
            {
                SingleBool = false,
                SingleInt32 = 0,
                SingleString = "",
                SingleBytes = ByteString.Empty,
                SingleForeignEnum = 0,
                SingleForeignMessage = null,
            };
            expected.RepeatedDouble.Clear();

            Assert.AreEqual(expected, message);

            // Separately, maps.
            var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } };
            fields = TestMap.Descriptor.Fields;
            fields[TestMap.MapStringStringFieldNumber].Accessor.Clear(mapMessage);
            Assert.AreEqual(0, mapMessage.MapStringString.Count);
        }
Example #37
0
 public void UnknownEnumValueNumeric_MapField()
 {
     var message = new TestMap { MapInt32Enum = { { 1, MapEnum.Foo }, { 2, (MapEnum) 100 }, { 3, MapEnum.Bar } } };
     AssertJson("{ 'mapInt32Enum': { '1': 'MAP_ENUM_FOO', '2': 100, '3': 'MAP_ENUM_BAR' } }", JsonFormatter.Default.Format(message));
 }
        public override void Excute(EventContext context)
        {
            const string spriteName        = "open_scene_sprite";
            const string spriteTitleName   = "open_scene_title_sprite";
            const string spriteTitleBgName = "open_scene_title_bg_sprite";
            const string spriteContentName = "open_scene_content_name";

            context.Push(new BGMEvent("Musics/BGMs/1.Metal max", AudioManager.AudioEvent.Play));

            context.Push(new InstantiateUISpriteEvent(m_openSceneSprite, spriteName)
            {
                Position = Vector3.zero,
                Rotation = Quaternion.identity,
            });

            m_playAnimationEvent = new PlayAnimationEvent((cxt) => cxt[spriteName].GetComponent <Animation>(), "Logo", PlayMode.StopSameLayer)
            {
                OnForceStoped = (ctx2) =>
                {
                }
            }
            .Then((ctx) =>
            {
                ctx.Push(new InstantiateUISpriteEvent(m_openSceneTitleSprite, spriteTitleName));

                m_playAnimationEvent = new PlayAnimationEvent(
                    (cxt2) => cxt2[spriteTitleName].GetComponent <Animation>(),
                    "Logo_Title", PlayMode.StopSameLayer)
                {
                    OnForceStoped = (ctx3) => { }
                };

                ctx.Push(new DestroySpriteEvent(spriteName));

                return(m_playAnimationEvent);
            }
                  )
            .Then((ctx) =>
            {
                ctx.Push(new InstantiateUISpriteEvent(m_openSceneTitleBgSprite, spriteTitleBgName));

                m_playAnimationEvent = new PlayAnimationEvent(
                    (cxt2) => cxt2[spriteTitleBgName].GetComponent <Animation>(),
                    "Logo_Bg", PlayMode.StopSameLayer)
                {
                    OnForceStoped = (ctx3) => { }
                };

                return(m_playAnimationEvent);
            }
                  )
            .Then((ctx) =>
            {
                ctx.Push(new InstantiateUISpriteEvent(m_openSceneContentSprite, spriteContentName));

                m_playAnimationEvent = new PlayAnimationEvent(
                    (cxt2) => cxt2[spriteContentName].GetComponent <Animation>(),
                    "Logo_Content", PlayMode.StopSameLayer)
                {
                    OnForceStoped = (ctx2) => { }
                };

                return(m_playAnimationEvent);
            }
                  ).Then((ctx) =>
            {
                var map = new TestMap();
                map.Load();
                ctx.Push(new SwitchMapEvent(map));
                return(null);
            }
                         );

            context.Push(m_playAnimationEvent);
        }