chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1789139 - in /chemistry/portcmis/trunk: PortCMIS/binding/browser/BrowserBinding.cs PortCMIS/binding/browser/json/Json.cs PortCMIS/client/ClientImpl.cs PortCMISTests/JsonTest.cs PortCMISTests/Properties/AssemblyInfo.cs
Date Tue, 28 Mar 2017 13:44:33 GMT
Author: fmui
Date: Tue Mar 28 13:44:33 2017
New Revision: 1789139

URL: http://svn.apache.org/viewvc?rev=1789139&view=rev
Log:
PortCMIS: fixed value formatting issues

Modified:
    chemistry/portcmis/trunk/PortCMIS/binding/browser/BrowserBinding.cs
    chemistry/portcmis/trunk/PortCMIS/binding/browser/json/Json.cs
    chemistry/portcmis/trunk/PortCMIS/client/ClientImpl.cs
    chemistry/portcmis/trunk/PortCMISTests/JsonTest.cs
    chemistry/portcmis/trunk/PortCMISTests/Properties/AssemblyInfo.cs

Modified: chemistry/portcmis/trunk/PortCMIS/binding/browser/BrowserBinding.cs
URL: http://svn.apache.org/viewvc/chemistry/portcmis/trunk/PortCMIS/binding/browser/BrowserBinding.cs?rev=1789139&r1=1789138&r2=1789139&view=diff
==============================================================================
--- chemistry/portcmis/trunk/PortCMIS/binding/browser/BrowserBinding.cs (original)
+++ chemistry/portcmis/trunk/PortCMIS/binding/browser/BrowserBinding.cs Tue Mar 28 13:44:33
2017
@@ -500,6 +500,10 @@ namespace PortCMIS.Binding.Browser
             {
                 return null;
             }
+            else if (value is string)
+            {
+                return (string)value;
+            }
             else if (value is DateTime)
             {
                 if (DateTimeFormat == DateTimeFormat.Extended)
@@ -513,15 +517,48 @@ namespace PortCMIS.Binding.Browser
             }
             else if (value is decimal)
             {
-                return ((decimal)value).ToString("#", CultureInfo.InvariantCulture);
+                return ((decimal)value).ToString("g", CultureInfo.InvariantCulture);
             }
             else if (value is BigInteger)
             {
                 return ((BigInteger)value).ToString("0", CultureInfo.InvariantCulture);
             }
+            else if (value is Boolean)
+            {
+                return (Boolean)value ? "true" : "false";
+            }
+            else if (value is Double)
+            {
+                if (Double.IsInfinity((Double)value) || Double.IsNaN((Double)value))
+                {
+                    return "null";
+                }
+                else
+                {
+                    return ((Double)value).ToString("g", CultureInfo.InvariantCulture);
+                }
+            }
+            else if (value is Single)
+            {
+                if (Single.IsInfinity((Single)value) || Single.IsNaN((Single)value))
+                {
+                    return "null";
+                }
+                else
+                {
+                    return ((Single)value).ToString("g", CultureInfo.InvariantCulture);
+                }
+            }
             else
             {
-                return value.ToString();
+                try
+                {
+                    return Convert.ToInt64(value).ToString("0", CultureInfo.InvariantCulture);
+                }
+                catch (Exception)
+                {
+                    return value.ToString();
+                }
             }
         }
     }

Modified: chemistry/portcmis/trunk/PortCMIS/binding/browser/json/Json.cs
URL: http://svn.apache.org/viewvc/chemistry/portcmis/trunk/PortCMIS/binding/browser/json/Json.cs?rev=1789139&r1=1789138&r2=1789139&view=diff
==============================================================================
--- chemistry/portcmis/trunk/PortCMIS/binding/browser/json/Json.cs (original)
+++ chemistry/portcmis/trunk/PortCMIS/binding/browser/json/Json.cs Tue Mar 28 13:44:33 2017
@@ -64,6 +64,24 @@ namespace PortCMIS.Binding.Browser.Json
                 return;
             }
 
+            if (value is decimal)
+            {
+                writer.Write(((decimal)value).ToString("g", CultureInfo.InvariantCulture));
+                return;
+            }
+
+            if (value is BigInteger)
+            {
+                writer.Write(((BigInteger)value).ToString("0", CultureInfo.InvariantCulture));
+                return;
+            }
+
+            if (value is Boolean)
+            {
+                writer.Write((Boolean)value ? "true" : "false");
+                return;
+            }
+
             if (value is Double)
             {
                 if (Double.IsInfinity((Double)value) || Double.IsNaN((Double)value))
@@ -72,7 +90,7 @@ namespace PortCMIS.Binding.Browser.Json
                 }
                 else
                 {
-                    writer.Write(((Double)value).ToString("#", CultureInfo.InvariantCulture));
+                    writer.Write(((Double)value).ToString("g", CultureInfo.InvariantCulture));
                 }
                 return;
             }
@@ -85,29 +103,11 @@ namespace PortCMIS.Binding.Browser.Json
                 }
                 else
                 {
-                    writer.Write(((Single)value).ToString("0", CultureInfo.InvariantCulture));
+                    writer.Write(((Single)value).ToString("g", CultureInfo.InvariantCulture));
                 }
                 return;
             }
 
-            if (value is decimal)
-            {
-                writer.Write(((decimal)value).ToString("#", CultureInfo.InvariantCulture));
-                return;
-            }
-
-            if (value is BigInteger)
-            {
-                writer.Write(((BigInteger)value).ToString("0", CultureInfo.InvariantCulture));
-                return;
-            }
-
-            if (value is Boolean)
-            {
-                writer.Write(value.ToString());
-                return;
-            }
-
             if (value is IJsonStreamAware)
             {
                 ((IJsonStreamAware)value).WriteJsonString(writer);
@@ -858,7 +858,7 @@ namespace PortCMIS.Binding.Browser.Json
         private const int ZzPushbackTooBig = 2;
 
         // error messages for the codes above
-        private static readonly string[] ZZ_ERROR_MSG = { 
+        private static readonly string[] ZZ_ERROR_MSG = {
                                               "Unknown internal scanner error",
                                               "Error: could not match input",
                                               "Error: pushback value was too large"

Modified: chemistry/portcmis/trunk/PortCMIS/client/ClientImpl.cs
URL: http://svn.apache.org/viewvc/chemistry/portcmis/trunk/PortCMIS/client/ClientImpl.cs?rev=1789139&r1=1789138&r2=1789139&view=diff
==============================================================================
--- chemistry/portcmis/trunk/PortCMIS/client/ClientImpl.cs (original)
+++ chemistry/portcmis/trunk/PortCMIS/client/ClientImpl.cs Tue Mar 28 13:44:33 2017
@@ -1652,7 +1652,7 @@ namespace PortCMIS.Client.Impl
             StringListBuilder slb = new StringListBuilder(",");
             foreach (decimal n in num)
             {
-                slb.Add(n.ToString("#", CultureInfo.InvariantCulture));
+                slb.Add(n.ToString("g", CultureInfo.InvariantCulture));
             }
 
             parametersDict[parameterIndex] = slb.ToString();

Modified: chemistry/portcmis/trunk/PortCMISTests/JsonTest.cs
URL: http://svn.apache.org/viewvc/chemistry/portcmis/trunk/PortCMISTests/JsonTest.cs?rev=1789139&r1=1789138&r2=1789139&view=diff
==============================================================================
--- chemistry/portcmis/trunk/PortCMISTests/JsonTest.cs (original)
+++ chemistry/portcmis/trunk/PortCMISTests/JsonTest.cs Tue Mar 28 13:44:33 2017
@@ -28,14 +28,28 @@ namespace PortCMISTests
     [TestClass]
     public class JsonTest
     {
+        private TestContext testContextInstance;
+
+        public TestContext TestContext
+        {
+            get
+            {
+                return testContextInstance;
+            }
+            set
+            {
+                testContextInstance = value;
+            }
+        }
+
         [TestMethod]
         public void TestBasicJson()
         {
             JsonParser jp = new JsonParser();
-            
+
             // ---
             string json1 = "{ \"test\":\"test-value\" }";
-            JsonObject jo1 = (JsonObject) jp.Parse(new StringReader(json1));
+            JsonObject jo1 = (JsonObject)jp.Parse(new StringReader(json1));
 
             Assert.AreEqual("test-value", jo1["test"]);
 
@@ -44,17 +58,52 @@ namespace PortCMISTests
             Assert.AreEqual("{\"test\":\"test-value\"}", writer.ToString());
 
             // ---
-            string json2 = "{ \"s\":\"test\", \"i\":42, \"b\":true, \"d\":123.456, \"n\":null}";
+            string json2 = "{ \"s\":\"test\", \"i\":42, \"i0\":0, \"b\":true, \"d\":123.456,
\"d0\": 0.0, \"n\":null}";
             JsonObject jo2 = (JsonObject)jp.Parse(new StringReader(json2));
 
             Assert.AreEqual("test", jo2["s"]);
             Assert.AreEqual(new BigInteger(42), jo2["i"]);
+            Assert.AreEqual(BigInteger.Zero, jo2["i0"]);
             Assert.AreEqual(true, jo2["b"]);
             Assert.AreEqual(new Decimal(123.456), jo2["d"]);
+            Assert.AreEqual(new Decimal(0), jo2["d0"]);
             Assert.IsNull(jo2["n"]);
         }
 
         [TestMethod]
+        public void TestCreateJson()
+        {
+            JsonObject jo1 = new JsonObject();
+            jo1.Add("s", "test");
+            jo1.Add("i", 42);
+            jo1.Add("i0", 0);
+            jo1.Add("i1", new BigInteger(21));
+            jo1.Add("b-true", true);
+            jo1.Add("b-false", false);
+            jo1.Add("d", new decimal(123.456));
+            jo1.Add("d0", new decimal(0.0));
+            jo1.Add("f", 98.76);
+            jo1.Add("n", null);
+
+            string jsonStr = jo1.ToString();
+            TestContext.WriteLine("{0}", jsonStr);
+
+            JsonParser jp = new JsonParser();
+            JsonObject jo2 = (JsonObject)jp.Parse(new StringReader(jsonStr));
+
+            Assert.AreEqual(jo1["s"], jo2["s"]);
+            Assert.AreEqual(new BigInteger((int)jo1["i"]), jo2["i"]);
+            Assert.AreEqual(new BigInteger((int)jo1["i0"]), jo2["i0"]);
+            Assert.AreEqual(jo1["i1"], jo2["i1"]);
+            Assert.AreEqual(jo1["b-true"], jo2["b-true"]);
+            Assert.AreEqual(jo1["b-false"], jo2["b-false"]);
+            Assert.AreEqual(jo1["d"], jo2["d"]);
+            Assert.AreEqual(jo1["d0"], new decimal((int)((BigInteger)jo2["d0"])));
+            Assert.AreEqual(new decimal((double)jo1["f"]), jo2["f"]);
+            Assert.AreEqual(jo1["n"], jo2["n"]);
+        }
+
+        [TestMethod]
         public void TestArray()
         {
             JsonParser jp = new JsonParser();

Modified: chemistry/portcmis/trunk/PortCMISTests/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/chemistry/portcmis/trunk/PortCMISTests/Properties/AssemblyInfo.cs?rev=1789139&r1=1789138&r2=1789139&view=diff
==============================================================================
--- chemistry/portcmis/trunk/PortCMISTests/Properties/AssemblyInfo.cs (original)
+++ chemistry/portcmis/trunk/PortCMISTests/Properties/AssemblyInfo.cs Tue Mar 28 13:44:33
2017
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers 
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.2.0.0")]
-[assembly: AssemblyFileVersion("0.2.0.0")]
+[assembly: AssemblyVersion("0.3.0.0")]
+[assembly: AssemblyFileVersion("0.3.0.0")]



Mime
View raw message