コード例 #1
0
        public void FetchChars_IchMinGreaterThanIchLim_Throws()
        {
            TsString tss = CreateTwoRunString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(10, true))
                Assert.That(() => tss.FetchChars(25, 24, rgch), Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public void FetchChars_TwoRuns_ReturnsCorrectString()
        {
            TsString tss = CreateTwoRunString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(11, true))
            {
                tss.FetchChars(25, 36, rgch);
                string str = MarshalEx.NativeToString(rgch, 11, true);
                Assert.That(str, Is.EqualTo("una prueba!"));
            }
        }
コード例 #5
0
        public void FetchChars_OneRun_ReturnsCorrectString()
        {
            TsString tss = CreateOneRunString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(6, true))
            {
                tss.FetchChars(1, 7, rgch);
                string str = MarshalEx.NativeToString(rgch, 6, true);
                Assert.That(str, Is.EqualTo("his is"));
            }
        }
コード例 #6
0
        public void FetchChars_Empty_ReturnsEmptyString()
        {
            TsString tss = CreateEmptyString();

            using (ArrayPtr rgch = MarshalEx.StringToNative(0, true))
            {
                tss.FetchChars(0, 0, rgch);
                string str = MarshalEx.NativeToString(rgch, 0, true);
                Assert.That(str, Is.EqualTo(string.Empty));
            }
        }
コード例 #7
0
        public void UnicodeProp_BufferToSmall()
        {
            CheckDisposed();
            string str = "ThirdUnicodeTest";

            m_ISilDataAccess.set_UnicodeProp(1119, 2229, str);
            int cch;

            using (ArrayPtr arrayPtr = MarshalEx.StringToNative(100, true))
            {
                m_ISilDataAccess.UnicodePropRgch(1119, 2229, arrayPtr, 1, out cch);
            }
        }
コード例 #8
0
ファイル: TsStrBase.cs プロジェクト: vkarthim/liblcm
        /// <summary>
        /// Fetches the characters for the specified range.
        /// </summary>
        public void FetchChars(int ichMin, int ichLim, ArrayPtr rgch)
        {
            if (rgch.IntPtr == IntPtr.Zero)
            {
                throw new ArgumentNullException("rgch");
            }
            ThrowIfCharOffsetOutOfRange("ichMin", ichMin, ichLim);
            ThrowIfCharOffsetOutOfRange("ichLim", ichLim, Length);

            string str = GetChars(ichMin, ichLim);

            if (str != null)
            {
                MarshalEx.StringToNative(rgch, str.Length, str, true);
            }
        }
コード例 #9
0
        public void UnicodeProp()
        {
            CheckDisposed();
            string strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);

            Assert.IsNull(strNew);
            Assert.IsFalse(m_ISilDataAccess.IsDirty());

            string str = "UnicodeTest";

            m_ISilDataAccess.SetUnicode(1119, 2229, str, str.Length);
            strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);
            Assert.AreEqual(str, strNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            str = "SecondUnicodeTest";
            m_ISilDataAccess.SetUnicode(1119, 2229, str, str.Length);
            strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);
            Assert.AreEqual(str, strNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            str = "ThirdUnicodeTest";
            m_ISilDataAccess.set_UnicodeProp(1119, 2229, str);
            int cch;

            using (ArrayPtr arrayPtr = MarshalEx.StringToNative(100, true))
            {
                m_ISilDataAccess.UnicodePropRgch(1119, 2229, arrayPtr, 100, out cch);
                strNew = MarshalEx.NativeToString(arrayPtr, cch, true);
                Assert.AreEqual(str, strNew);
                Assert.AreEqual(str.Length, cch);
                Assert.IsTrue(m_ISilDataAccess.IsDirty());

                m_ISilDataAccess.UnicodePropRgch(1119, 2229, ArrayPtr.Null, 0, out cch);
                Assert.AreEqual(str.Length, cch);

                CheckProp(1119, 2229, str, CellarModuleDefns.kcptUnicode);
            }
        }