csharp: Fix to return ArgumentException
authorkj7.sung <kj7.sung@samsung.com>
Tue, 25 Apr 2017 07:28:27 +0000 (16:28 +0900)
committerkj7.sung <kj7.sung@samsung.com>
Thu, 27 Apr 2017 06:39:13 +0000 (15:39 +0900)
Change-Id: I7fe82b8664aa1413d7324fecc43b4a64c99404a2
Signed-off-by: kj7.sung <kj7.sung@samsung.com>
src/Tizen.Location/Tizen.Location/GpsSatellite.cs
src/Tizen.Location/Tizen.Location/Location.cs
src/Tizen.Location/Tizen.Location/LocationBoundary.cs

index 751c456..f32db04 100755 (executable)
@@ -198,6 +198,12 @@ namespace Tizen.Location
         public GpsSatellite(Locator locator)
         {
             Log.Info(Globals.LogTag, "Calling GpsSatellite constructor");
+            if (locator == null)
+            {
+                Log.Error(Globals.LogTag, "locator is null");
+                throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
+            }
+
             LocationType method = locator.LocationType;
             if (method.Equals(LocationType.Gps) || method.Equals(LocationType.Hybrid))
             {
index ae52873..61b5a27 100755 (executable)
@@ -50,6 +50,7 @@ namespace Tizen.Location
         /// <param name="direction"> Device direction with respect to north.</param>
         /// <param name="timestamp"> Time when the measurement took place.</param>
         /// </summary>
+        /// <exception cref="ArgumentException">Thrown when an invalid argument is used</exception>
         public Location(double latitude, double longitude, double altitude, double speed, double direction, double accuracy, int timestamp)
         {
             _latitude = latitude;
@@ -68,11 +69,21 @@ namespace Tizen.Location
         {
             get
             {
+                Log.Info(Globals.LogTag, "Getting the latitude");
                 return _latitude;
             }
             set
             {
-                _latitude = value;
+                Log.Info(Globals.LogTag, "Setting the latitude");
+                if (value >= -90.0 && value <= 90.0)
+                {
+                    _latitude = value;
+                }
+                else
+                {
+                    Log.Error(Globals.LogTag, "Error setting latitude");
+                    throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
+                }
             }
         }
 
@@ -83,11 +94,21 @@ namespace Tizen.Location
         {
             get
             {
+                Log.Info(Globals.LogTag, "Getting the longitude");
                 return _longitude;
             }
             set
             {
-                _longitude = value;
+                Log.Info(Globals.LogTag, "Setting the longitude");
+                if (value >= -180.0 && value <= 180.0)
+                {
+                    _longitude = value;
+                }
+                else
+                {
+                    Log.Error(Globals.LogTag, "Error setting longitude");
+                    throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
+                }
             }
         }
 
index e503e19..b17de00 100755 (executable)
@@ -264,6 +264,12 @@ namespace Tizen.Location
         public PolygonBoundary(IList<Coordinate> coordinates)
         {
             Log.Info(Globals.LogTag, "Calling PolygonBoundary Constructor");
+            if (coordinates == null)
+            {
+                Log.Error(Globals.LogTag, "coordingtes list is null");
+                throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
+            }
+
             BoundaryType = BoundaryType.Polygon;
             IntPtr listPointer = Marshal.AllocHGlobal(Marshal.SizeOf(coordinates[0]) * coordinates.Count);
             IntPtr boundsHandle;