public void UnicodePropWrongLengthTest() { // Set class first, or it will throw an exception. const int hvo = 1; var clidAnal = SilDataAccess.MetaDataCache.GetClassId("ClassE"); SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, clidAnal); // Set its 'UnicodeProp4' property, using the 'BSTR' method. var tag = SilDataAccess.MetaDataCache.GetFieldId("ClassE", "UnicodeProp4", false); const string ec = "ZPI"; SilDataAccess.set_UnicodeProp(hvo, tag, ec); var ec2 = SilDataAccess.get_UnicodeProp(hvo, tag); Assert.AreEqual(ec, ec2, "Wrong Unicode string in cache."); // Set its 'UnicodeProp4' property, using non-bstr method. const string ecNew = "ZPR"; SilDataAccess.SetUnicode(hvo, tag, ecNew, ecNew.Length); int len; SilDataAccess.UnicodePropRgch(hvo, tag, null, 0, out len); Assert.AreEqual(ecNew.Length, len); using (var arrayPtr = MarshalEx.StringToNative(len, true)) { int cch; // Should throw the exception here. SilDataAccess.UnicodePropRgch(hvo, tag, arrayPtr, len, out cch); } }
public void UnicodePropWrongLengthTest() { CheckDisposed(); // Set class first, or it will throw an exception. int hvo = 1; uint clidAnal = SilDataAccess.MetaDataCache.GetClassId("LangProject"); SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, (int)clidAnal); // Set its 'EthnologueCode' property, using the 'BSTR' method. int tag = (int)SilDataAccess.MetaDataCache.GetFieldId("LangProject", "EthnologueCode", false); string ec = "ZPI"; SilDataAccess.set_UnicodeProp(hvo, tag, ec); string ec2 = SilDataAccess.get_UnicodeProp(hvo, tag); Assert.AreEqual(ec, ec2, "Wrong Unicode string in cache."); // Set its 'EthnologueCode' property, using non-bstr method. string ecNew = "ZPR"; SilDataAccess.SetUnicode(hvo, tag, ecNew, ecNew.Length); int len; SilDataAccess.UnicodePropRgch(hvo, tag, null, 0, out len); Assert.AreEqual(ecNew.Length, len); using (ArrayPtr arrayPtr = MarshalEx.StringToNative(len, true)) { int cch; // Should throw the exception here. SilDataAccess.UnicodePropRgch(hvo, tag, arrayPtr, len, out cch); } }