Пример #1
0
        public void UnicodeBytes()
        {
            Assert.AreEqual((byte)105, Test1.GetNonUnicodeBytes() [1], "#N01");
            Assert.AreEqual((byte)32, Test1.GetNonUnicodeBytes() [5], "#N02");

            Assert.AreEqual((byte)70, Test1.GetUnicodeBytes() [0], "#N03");
            Assert.AreEqual((byte)70, Test1.GetNonUnicodeBytes() [0], "#N03b");
            Assert.AreEqual((byte)0, Test1.GetUnicodeBytes() [1], "#N03c");
            Assert.AreEqual((byte)105, Test1.GetNonUnicodeBytes() [1], "#N03d");
            Assert.AreEqual((byte)105, Test1.GetUnicodeBytes() [2], "#N03e");
            Assert.AreEqual((byte)114, Test1.GetNonUnicodeBytes() [2], "#N03f");
            Assert.AreEqual((byte)0, Test1.GetUnicodeBytes() [3], "#N03g");
            Assert.AreEqual((byte)115, Test1.GetNonUnicodeBytes() [3], "#N03h");
            Assert.AreEqual((byte)114, Test1.GetUnicodeBytes() [4], "#N03i");
            Assert.AreEqual((byte)116, Test1.GetNonUnicodeBytes() [4], "#N03j");

            Assert.AreEqual((byte)105, Test1.GetUnicodeBytes() [2], "#N04");

            try {
                byte test = Test1.GetUnicodeBytes() [105];
                Assert.Fail("#N05");
            } catch (Exception e) {
#if TARGET_JVM
                Assert.IsTrue(typeof(IndexOutOfRangeException).IsAssignableFrom(e.GetType()), "#N06");
#else
                Assert.AreEqual(typeof(IndexOutOfRangeException), e.GetType(), "#N06");
#endif
            }
        }
Пример #2
0
        public void UnicodeBytes()
        {
            Assert.Equal((byte)105, _test1.GetNonUnicodeBytes()[1]);
            Assert.Equal((byte)32, _test1.GetNonUnicodeBytes()[5]);

            Assert.Equal((byte)70, _test1.GetUnicodeBytes()[0]);
            Assert.Equal((byte)70, _test1.GetNonUnicodeBytes()[0]);
            Assert.Equal((byte)0, _test1.GetUnicodeBytes()[1]);
            Assert.Equal((byte)105, _test1.GetNonUnicodeBytes()[1]);
            Assert.Equal((byte)105, _test1.GetUnicodeBytes()[2]);
            Assert.Equal((byte)114, _test1.GetNonUnicodeBytes()[2]);
            Assert.Equal((byte)0, _test1.GetUnicodeBytes()[3]);
            Assert.Equal((byte)115, _test1.GetNonUnicodeBytes()[3]);
            Assert.Equal((byte)114, _test1.GetUnicodeBytes()[4]);
            Assert.Equal((byte)116, _test1.GetNonUnicodeBytes()[4]);

            Assert.Equal((byte)105, _test1.GetUnicodeBytes()[2]);

            try
            {
                byte test = _test1.GetUnicodeBytes()[105];
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(IndexOutOfRangeException), e.GetType());
            }
        }
Пример #3
0
        public void UnicodeBytes()
        {
            Assert.Equal((byte)105, _test1.GetNonUnicodeBytes()[1]);
            Assert.Equal((byte)32, _test1.GetNonUnicodeBytes()[5]);

            Assert.Equal((byte)70, _test1.GetUnicodeBytes()[0]);
            Assert.Equal((byte)70, _test1.GetNonUnicodeBytes()[0]);
            Assert.Equal((byte)0, _test1.GetUnicodeBytes()[1]);
            Assert.Equal((byte)105, _test1.GetNonUnicodeBytes()[1]);
            Assert.Equal((byte)105, _test1.GetUnicodeBytes()[2]);
            Assert.Equal((byte)114, _test1.GetNonUnicodeBytes()[2]);
            Assert.Equal((byte)0, _test1.GetUnicodeBytes()[3]);
            Assert.Equal((byte)115, _test1.GetNonUnicodeBytes()[3]);
            Assert.Equal((byte)114, _test1.GetUnicodeBytes()[4]);
            Assert.Equal((byte)116, _test1.GetNonUnicodeBytes()[4]);

            Assert.Equal((byte)105, _test1.GetUnicodeBytes()[2]);

            Assert.Throws <IndexOutOfRangeException>(() => _test1.GetUnicodeBytes()[105]);
        }
Пример #4
0
        public string ColUniCode(string colName, byte errorMode = 1, int colNumber = 99999)
        {
            try
            {
                if (colNumber >= 0 && colNumber <= 88888)
                {
                    colNo = colNumber;
                }
                else
                {
                    colNo = dataReader.GetOrdinal(colName);
                }

                if (dataReader.IsDBNull(colNo))
                {
                    return("");
                }

                SqlString str     = dataReader.GetSqlString(colNo);
                byte[]    uniCode = str.GetUnicodeBytes();
                return(Encoding.Unicode.GetString(uniCode));

/*
 *                      string    pre     = "\\u";
 *                      SqlString str1    = dataReader.GetSqlString(colNo);
 *                      string    str2    = str1.ToString();
 *
 *                      byte[]    uniCodeA = str1.GetUnicodeBytes();
 *                      byte[]    uniCodeB = Encoding.Unicode.GetBytes(str2);
 *                      byte[]    uniCodeC = Encoding.UTF8.GetBytes(str2);
 *
 *                      string    retA1    = "";
 *                      string    retA2    = "";
 *                      string    retA3    = "";
 *                      string    retB1    = "";
 *                      string    retB2    = "";
 *                      string    retB3    = "";
 *                      string    retC1    = "";
 *                      string    retC2    = "";
 *                      string    retC3    = "";
 *
 * //			if ( uniCode.Length < 1 )
 * //				return "";
 *
 *                      for ( int k = 0 ; k < uniCodeA.Length ; k ++ )
 *                              retA1 = retA1 + pre + uniCodeA[k];
 *
 *                      retA2 = Encoding.UTF8.GetString(uniCodeA);
 *                      retA3 = Encoding.Unicode.GetString(uniCodeA);
 *
 *                      for ( int k = 0 ; k < uniCodeB.Length ; k ++ )
 *                              retB1 = retB1 + pre + uniCodeB[k];
 *
 *                      retB2 = Encoding.UTF8.GetString(uniCodeB);
 *                      retB3 = Encoding.Unicode.GetString(uniCodeB);
 *
 *                      for ( int k = 0 ; k < uniCodeC.Length ; k ++ )
 *                              retC1 = retC1 + pre + uniCodeC[k];
 *
 *                      retC2 = Encoding.UTF8.GetString(uniCodeC);
 *                      retC3 = Encoding.Unicode.GetString(uniCodeC);
 *
 *                      string retD1 = System.Text.UnicodeEncoding.Unicode.GetString(uniCodeA);
 *                      string retD2 = System.Text.UnicodeEncoding.Unicode.GetString(uniCodeB);
 *                      string retD3 = System.Text.UnicodeEncoding.Unicode.GetString(uniCodeC);
 *
 *                      if ( errorMode == 29 )
 *                      {
 *                              Tools.LogInfo ( ModuleName("DBConn.ColUniCode/A"), "retA1 = '" + retA1 + "', retA2 = '" + retA2 + "', retA3 = '" + retA3 + "'", 255 );
 *                              Tools.LogInfo ( ModuleName("DBConn.ColUniCode/B"), "retB1 = '" + retB1 + "', retB2 = '" + retB2 + "', retB3 = '" + retB3 + "'", 255 );
 *                              Tools.LogInfo ( ModuleName("DBConn.ColUniCode/C"), "retC1 = '" + retC1 + "', retC2 = '" + retC2 + "', retC3 = '" + retC3 + "'", 255 );
 *                              Tools.LogInfo ( ModuleName("DBConn.ColUniCode/D"), "retD1 = '" + retD1 + "', retD2 = '" + retD2 + "', retD3 = '" + retD3 + "'", 255 );
 *                      }
 *                      return retB1;
 */
            }
            catch (Exception ex)
            {
                if (errorMode == 1)
                {
                    Tools.LogException(ModuleName("DBConn.ColUniCode"), "ColName=" + colName, ex);
                }
            }
            return("");
        }
Пример #5
0