Skip to content

Commit 7f13dbb

Browse files
Copilotrolfbjarne
andcommitted
Revert using declarations back to using blocks in CGImageProperties tests
Co-authored-by: rolfbjarne <249268+rolfbjarne@users.noreply.github.com>
1 parent 2d591b0 commit 7f13dbb

File tree

5 files changed

+151
-140
lines changed

5 files changed

+151
-140
lines changed

tests/monotouch-test/CoreGraphics/CGImagePropertiesExifTest.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,38 @@ public void ConstructorAndBasicPropertiesTest ()
4343
[Test]
4444
public void ConstructorWithDictionaryTest ()
4545
{
46-
using var dict = new NSMutableDictionary ();
47-
var exif = new CGImagePropertiesExif (dict);
48-
Assert.That (exif, Is.Not.Null, "Constructor with dictionary should create a valid instance");
46+
using (var dict = new NSMutableDictionary ()) {
47+
var exif = new CGImagePropertiesExif (dict);
48+
Assert.That (exif, Is.Not.Null, "Constructor with dictionary should create a valid instance");
49+
}
4950
}
5051

5152
[Test]
5253
public void IntegrationWithCGImagePropertiesTest ()
5354
{
5455
// Test that CGImageProperties can access Exif properties
55-
var file = Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png");
56-
57-
using var url = NSUrl.FromFilename (file);
58-
using var ci = CIImage.FromUrl (url);
59-
var imageProps = ci.Properties;
60-
Assert.That (imageProps, Is.Not.Null, "Image properties should be available");
61-
62-
// Note: The test image may not have EXIF data, so Exif property could be null
63-
// This test mainly verifies the property access doesn't throw exceptions
64-
var exif = imageProps.Exif;
65-
// exif may be null for PNG files without EXIF data, which is expected
56+
string file = Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png");
57+
58+
using (var url = NSUrl.FromFilename (file))
59+
using (var ci = CIImage.FromUrl (url)) {
60+
var imageProps = ci.Properties;
61+
Assert.That (imageProps, Is.Not.Null, "Image properties should be available");
62+
63+
// Note: The test image may not have EXIF data, so Exif property could be null
64+
// This test mainly verifies the property access doesn't throw exceptions
65+
var exif = imageProps.Exif;
66+
// exif may be null for PNG files without EXIF data, which is expected
67+
}
6668
}
6769

6870
[Test]
6971
public void ExposureProgramTest ()
7072
{
7173
var exif = new CGImagePropertiesExif ();
72-
74+
7375
exif.ExposureProgram = 1; // Manual mode
7476
Assert.That (exif.ExposureProgram, Is.EqualTo (1), "ExposureProgram should be settable and gettable");
75-
77+
7678
exif.ExposureProgram = 2; // Aperture priority
7779
Assert.That (exif.ExposureProgram, Is.EqualTo (2), "ExposureProgram should accept different values");
7880
}
@@ -81,20 +83,20 @@ public void ExposureProgramTest ()
8183
public void FloatingPointPropertiesTest ()
8284
{
8385
var exif = new CGImagePropertiesExif ();
84-
86+
8587
// Test various floating point properties
8688
exif.Brightness = 0.5f;
8789
Assert.That (exif.Brightness, Is.EqualTo (0.5f).Within (0.001f), "Brightness should be settable");
88-
90+
8991
exif.DigitalZoomRatio = 2.0f;
9092
Assert.That (exif.DigitalZoomRatio, Is.EqualTo (2.0f).Within (0.001f), "DigitalZoomRatio should be settable");
91-
93+
9294
exif.ExposureBias = -1.5f;
9395
Assert.That (exif.ExposureBias, Is.EqualTo (-1.5f).Within (0.001f), "ExposureBias should accept negative values");
94-
96+
9597
exif.FlashEnergy = 10.0f;
9698
Assert.That (exif.FlashEnergy, Is.EqualTo (10.0f).Within (0.001f), "FlashEnergy should be settable");
97-
99+
98100
exif.SubjectDistance = 5.2f;
99101
Assert.That (exif.SubjectDistance, Is.EqualTo (5.2f).Within (0.001f), "SubjectDistance should be settable");
100102
}
@@ -103,7 +105,7 @@ public void FloatingPointPropertiesTest ()
103105
public void ISOSpeedRatingsTest ()
104106
{
105107
var exif = new CGImagePropertiesExif ();
106-
108+
107109
// ISOSpeedRatings is read-only in the current implementation
108110
// This test verifies it doesn't throw when accessed
109111
var isoRatings = exif.ISOSpeedRatings;
@@ -114,14 +116,14 @@ public void ISOSpeedRatingsTest ()
114116
public void NullablePropertiesTest ()
115117
{
116118
var exif = new CGImagePropertiesExif ();
117-
119+
118120
// Test that nullable properties can be set to null
119121
exif.Aperture = null;
120122
Assert.That (exif.Aperture, Is.Null, "Aperture should be nullable");
121-
123+
122124
exif.ExposureTime = null;
123125
Assert.That (exif.ExposureTime, Is.Null, "ExposureTime should be nullable");
124-
126+
125127
exif.Flash = null;
126128
Assert.That (exif.Flash, Is.Null, "Flash should be nullable");
127129
}

tests/monotouch-test/CoreGraphics/CGImagePropertiesGPSTest.cs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ public void LongitudeRefAndLatitudeRefTest ()
2525
string expectedLongitudeRef = "W";
2626
string file = Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08_with_loc.png");
2727

28-
using var url = NSUrl.FromFilename (file);
29-
using var ci = CIImage.FromUrl (url);
30-
var gps = ci.Properties.Gps;
31-
Assert.That (gps.Latitude, Is.EqualTo (expectedLatitude).Within (0.0001f), "Invalid or no Latitude value found.");
32-
Assert.That (gps.Longitude, Is.EqualTo (expectedLongitude).Within (0.0001f), "Invalid or no Longitude value found.");
33-
Assert.That (gps.LatitudeRef, Is.EqualTo (expectedLatitudeRef), "Invalid or no LatitudeRef value found.");
34-
Assert.That (gps.LongitudeRef, Is.EqualTo (expectedLongitudeRef), "Invalid or no LongitudeRef value found.");
28+
using (var url = NSUrl.FromFilename (file))
29+
using (var ci = CIImage.FromUrl (url)) {
30+
var gps = ci.Properties.Gps;
31+
Assert.That (gps.Latitude, Is.EqualTo (expectedLatitude).Within (0.0001f), "Invalid or no Latitude value found.");
32+
Assert.That (gps.Longitude, Is.EqualTo (expectedLongitude).Within (0.0001f), "Invalid or no Longitude value found.");
33+
Assert.That (gps.LatitudeRef, Is.EqualTo (expectedLatitudeRef), "Invalid or no LatitudeRef value found.");
34+
Assert.That (gps.LongitudeRef, Is.EqualTo (expectedLongitudeRef), "Invalid or no LongitudeRef value found.");
35+
}
3536
}
3637

3738
[Test]
@@ -61,39 +62,41 @@ public void ConstructorAndBasicPropertiesTest ()
6162
[Test]
6263
public void ConstructorWithDictionaryTest ()
6364
{
64-
using var dict = new NSMutableDictionary ();
65-
var gps = new CGImagePropertiesGps (dict);
66-
Assert.That (gps, Is.Not.Null, "Constructor with dictionary should create a valid instance");
65+
using (var dict = new NSMutableDictionary ()) {
66+
var gps = new CGImagePropertiesGps (dict);
67+
Assert.That (gps, Is.Not.Null, "Constructor with dictionary should create a valid instance");
68+
}
6769
}
6870

6971
[Test]
7072
public void IntegrationWithCGImagePropertiesTest ()
7173
{
7274
// Test that CGImageProperties can access GPS properties
7375
string file = Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png");
74-
75-
using var url = NSUrl.FromFilename (file);
76-
using var ci = CIImage.FromUrl (url);
77-
var imageProps = ci.Properties;
78-
Assert.That (imageProps, Is.Not.Null, "Image properties should be available");
79-
80-
// Note: The regular PNG may not have GPS data, so Gps property could be null
81-
// This test mainly verifies the property access doesn't throw exceptions
82-
var gps = imageProps.Gps;
83-
// gps may be null for PNG files without GPS data, which is expected
76+
77+
using (var url = NSUrl.FromFilename (file))
78+
using (var ci = CIImage.FromUrl (url)) {
79+
var imageProps = ci.Properties;
80+
Assert.That (imageProps, Is.Not.Null, "Image properties should be available");
81+
82+
// Note: The regular PNG may not have GPS data, so Gps property could be null
83+
// This test mainly verifies the property access doesn't throw exceptions
84+
var gps = imageProps.Gps;
85+
// gps may be null for PNG files without GPS data, which is expected
86+
}
8487
}
8588

8689
[Test]
8790
public void NegativeCoordinatesTest ()
8891
{
8992
var gps = new CGImagePropertiesGps ();
90-
93+
9194
// Test negative coordinates (southern hemisphere and western longitude)
9295
gps.Latitude = -33.8688f; // Sydney latitude
9396
gps.Longitude = 151.2093f; // Sydney longitude
9497
Assert.That (gps.Latitude, Is.EqualTo (-33.8688f).Within (0.0001f), "Should handle negative latitude");
9598
Assert.That (gps.Longitude, Is.EqualTo (151.2093f).Within (0.0001f), "Should handle positive longitude");
96-
99+
97100
gps.LatitudeRef = "S";
98101
gps.LongitudeRef = "E";
99102
Assert.That (gps.LatitudeRef, Is.EqualTo ("S"), "Should handle southern hemisphere");
@@ -104,14 +107,14 @@ public void NegativeCoordinatesTest ()
104107
public void AltitudeTest ()
105108
{
106109
var gps = new CGImagePropertiesGps ();
107-
110+
108111
// Test various altitude values
109112
gps.Altitude = 0; // Sea level
110113
Assert.That (gps.Altitude, Is.EqualTo (0), "Should handle sea level altitude");
111-
114+
112115
gps.Altitude = 8849; // Mount Everest height in meters
113116
Assert.That (gps.Altitude, Is.EqualTo (8849), "Should handle high altitude");
114-
117+
115118
gps.Altitude = -400; // Below sea level
116119
Assert.That (gps.Altitude, Is.EqualTo (-400), "Should handle negative altitude");
117120
}
@@ -120,20 +123,20 @@ public void AltitudeTest ()
120123
public void NullablePropertiesTest ()
121124
{
122125
var gps = new CGImagePropertiesGps ();
123-
126+
124127
// Test that nullable properties can be set to null
125128
gps.Latitude = null;
126129
Assert.That (gps.Latitude, Is.Null, "Latitude should be nullable");
127-
130+
128131
gps.Longitude = null;
129132
Assert.That (gps.Longitude, Is.Null, "Longitude should be nullable");
130-
133+
131134
gps.Altitude = null;
132135
Assert.That (gps.Altitude, Is.Null, "Altitude should be nullable");
133-
136+
134137
gps.LatitudeRef = null;
135138
Assert.That (gps.LatitudeRef, Is.Null, "LatitudeRef should be nullable");
136-
139+
137140
gps.LongitudeRef = null;
138141
Assert.That (gps.LongitudeRef, Is.Null, "LongitudeRef should be nullable");
139142
}
@@ -142,13 +145,13 @@ public void NullablePropertiesTest ()
142145
public void EdgeCaseCoordinatesTest ()
143146
{
144147
var gps = new CGImagePropertiesGps ();
145-
148+
146149
// Test edge case coordinates
147150
gps.Latitude = 90.0f; // North pole
148151
gps.Longitude = 180.0f; // International date line
149152
Assert.That (gps.Latitude, Is.EqualTo (90.0f).Within (0.0001f), "Should handle north pole latitude");
150153
Assert.That (gps.Longitude, Is.EqualTo (180.0f).Within (0.0001f), "Should handle international date line longitude");
151-
154+
152155
gps.Latitude = -90.0f; // South pole
153156
gps.Longitude = -180.0f; // International date line (west)
154157
Assert.That (gps.Latitude, Is.EqualTo (-90.0f).Within (0.0001f), "Should handle south pole latitude");

tests/monotouch-test/CoreGraphics/CGImagePropertiesIptcTest.cs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,39 @@ public void ConstructorAndBasicPropertiesTest ()
4040
[Test]
4141
public void ConstructorWithDictionaryTest ()
4242
{
43-
using var dict = new NSMutableDictionary ();
44-
var iptc = new CGImagePropertiesIptc (dict);
45-
Assert.That (iptc, Is.Not.Null, "Constructor with dictionary should create a valid instance");
43+
using (var dict = new NSMutableDictionary ()) {
44+
var iptc = new CGImagePropertiesIptc (dict);
45+
Assert.That (iptc, Is.Not.Null, "Constructor with dictionary should create a valid instance");
46+
}
4647
}
4748

4849
[Test]
4950
public void IntegrationWithCGImagePropertiesTest ()
5051
{
5152
// Test that CGImageProperties can access IPTC properties
5253
string file = Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png");
53-
54-
using var url = NSUrl.FromFilename (file);
55-
using var ci = CIImage.FromUrl (url);
56-
var imageProps = ci.Properties;
57-
Assert.That (imageProps, Is.Not.Null, "Image properties should be available");
58-
59-
// Note: The test image may not have IPTC data, so Iptc property could be null
60-
// This test mainly verifies the property access doesn't throw exceptions
61-
var iptc = imageProps.Iptc;
62-
// iptc may be null for PNG files without IPTC data, which is expected
54+
55+
using (var url = NSUrl.FromFilename (file))
56+
using (var ci = CIImage.FromUrl (url)) {
57+
var imageProps = ci.Properties;
58+
Assert.That (imageProps, Is.Not.Null, "Image properties should be available");
59+
60+
// Note: The test image may not have IPTC data, so Iptc property could be null
61+
// This test mainly verifies the property access doesn't throw exceptions
62+
var iptc = imageProps.Iptc;
63+
// iptc may be null for PNG files without IPTC data, which is expected
64+
}
6365
}
6466

6567
[Test]
6668
public void LocationPropertiesTest ()
6769
{
6870
var iptc = new CGImagePropertiesIptc ();
69-
71+
7072
// Test location-related properties
7173
iptc.ContentLocationName = "Golden Gate Bridge";
7274
Assert.That (iptc.ContentLocationName, Is.EqualTo ("Golden Gate Bridge"), "ContentLocationName should be settable");
73-
75+
7476
iptc.CountryPrimaryLocationName = "United States";
7577
Assert.That (iptc.CountryPrimaryLocationName, Is.EqualTo ("United States"), "CountryPrimaryLocationName should be settable");
7678
}
@@ -79,17 +81,17 @@ public void LocationPropertiesTest ()
7981
public void CopyrightAndCreditPropertiesTest ()
8082
{
8183
var iptc = new CGImagePropertiesIptc ();
82-
84+
8385
// Test copyright and credit properties
8486
iptc.CopyrightNotice = "© 2023 Test Photographer";
8587
Assert.That (iptc.CopyrightNotice, Is.EqualTo ("© 2023 Test Photographer"), "CopyrightNotice should be settable");
86-
88+
8789
iptc.Credit = "Test News Agency";
8890
Assert.That (iptc.Credit, Is.EqualTo ("Test News Agency"), "Credit should be settable");
89-
91+
9092
iptc.Source = "Test Photo Source";
9193
Assert.That (iptc.Source, Is.EqualTo ("Test Photo Source"), "Source should be settable");
92-
94+
9395
iptc.WriterEditor = "Test Editor";
9496
Assert.That (iptc.WriterEditor, Is.EqualTo ("Test Editor"), "WriterEditor should be settable");
9597
}
@@ -98,14 +100,14 @@ public void CopyrightAndCreditPropertiesTest ()
98100
public void NullablePropertiesTest ()
99101
{
100102
var iptc = new CGImagePropertiesIptc ();
101-
103+
102104
// Test that nullable string properties can be set to null
103105
iptc.Byline = null;
104106
Assert.That (iptc.Byline, Is.Null, "Byline should be nullable");
105-
107+
106108
iptc.CaptionAbstract = null;
107109
Assert.That (iptc.CaptionAbstract, Is.Null, "CaptionAbstract should be nullable");
108-
110+
109111
iptc.City = null;
110112
Assert.That (iptc.City, Is.Null, "City should be nullable");
111113
}
@@ -114,11 +116,11 @@ public void NullablePropertiesTest ()
114116
public void EmptyStringPropertiesTest ()
115117
{
116118
var iptc = new CGImagePropertiesIptc ();
117-
119+
118120
// Test that empty strings work correctly
119121
iptc.Byline = "";
120122
Assert.That (iptc.Byline, Is.EqualTo (""), "Byline should accept empty strings");
121-
123+
122124
iptc.CopyrightNotice = "";
123125
Assert.That (iptc.CopyrightNotice, Is.EqualTo (""), "CopyrightNotice should accept empty strings");
124126
}

0 commit comments

Comments
 (0)