blob: 693b68ecc904c4cf127246637f2ce18cb1304b39 [file] [log] [blame]
Jens Geyer6e16c2b2020-06-24 23:51:01 +02001// Licensed to the Apache Software Foundation(ASF) under one
2// or more contributor license agreements.See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18using System;
19using System.Collections.Generic;
20using System.Diagnostics;
21using System.Linq;
22using System.Text;
23using Microsoft.VisualStudio.TestPlatform.ObjectModel;
24using Microsoft.VisualStudio.TestTools.UnitTesting;
25using OptReqDefTest;
26using Thrift.Collections;
27
28namespace Thrift.Tests.DataModel
29{
30 // ReSharper disable once InconsistentNaming
31 [TestClass]
32 public class Thrift_5238
33 {
34 private void CheckInstance(RaceDetails instance)
35 {
36 // object
37 Assert.IsTrue(instance.__isset.def_nested);
38 Assert.IsTrue(instance.__isset.opt_nested);
39 Assert.IsNull(instance.Def_nested);
40 Assert.IsNull(instance.Opt_nested);
41
42 // string
43 Assert.IsTrue(instance.__isset.def_four);
44 Assert.IsTrue(instance.__isset.opt_four);
45 Assert.IsNull(instance.Req_four);
46 Assert.IsNull(instance.Def_four);
47 Assert.IsNull(instance.Opt_four);
48
49 // byte[]
50 Assert.IsTrue(instance.__isset.def_five);
51 Assert.IsTrue(instance.__isset.opt_five);
52 Assert.IsNull(instance.Req_five);
53 Assert.IsNull(instance.Def_five);
54 Assert.IsNull(instance.Opt_five);
55
56 // list<>
57 Assert.IsTrue(instance.__isset.def_six);
58 Assert.IsTrue(instance.__isset.opt_six);
59 Assert.IsNull(instance.Req_six);
60 Assert.IsNull(instance.Opt_six);
61 Assert.IsNull(instance.Def_six);
62 }
63
64 [TestMethod]
65 public void Thrift_5238_ProperNullChecks()
66 {
67 var instance = new OptReqDefTest.RaceDetails();
68
69 // object
70 instance.Def_nested = null;
71 instance.Opt_nested = null;
72
73 // string
74 instance.Req_four = null;
75 instance.Def_four = null;
76 instance.Opt_four = null;
77
78 // byte[]
79 instance.Req_five = null;
80 instance.Def_five = null;
81 instance.Opt_five = null;
82
83 // list<>
84 instance.Req_six = null;
85 instance.Opt_six = null;
86 instance.Def_six = null;
87
88 // test the setup
89 CheckInstance(instance);
90
91 // validate proper null checks , any of these throws if not
92 instance.ToString();
93 instance.GetHashCode();
94
95 // validate proper null checks , any of these throws if not
96 var copy = instance.DeepCopy();
97 CheckInstance(copy);
98 }
99
100 }
101}