Граф коммитов

159 Коммитов

Автор SHA1 Сообщение Дата
Rolf Bjarne Kvinge 36af029204
Change all null checking expressions to use 'is' and 'is not'. (#18176)
Change all null checking expressions to use 'is null' and 'is not null'
instead of '== null' and '!= null'.

This was mostly done with sed, so code can probably be improved in many
other ways with manual inspection, but that will come over time.

Also add code to the autoformat script to automatically fix these issues in the future.
2023-05-05 17:52:19 +02:00
Rolf Bjarne Kvinge d75b697ebc
[tests] Adjust UrlSessionTests to ignore more failure scenarios in CI. (#17649)
Should fix random test failures like this:

    MonoTouchFixtures.Foundation.UrlSessionTest
        [FAIL] CreateDataTaskAsync :   CreateDataTask a Exception
            Expected: null
            But was:  <Foundation.NSErrorException: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=57, NSUnderlyingError=0x6000011f4990 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x600003deaa80 [0x7ff865b1f1c0]>{length = 16, capacity = 16, bytes = 0x100201bb6007a9b70000000000000000}, _kCFStreamErrorCodeKey=57, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <5E766082-B379-491A-BCB0-EA1B36E54A8B>.<15>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDataTask <5E766082-B379-491A-BCB0-EA1B36E54A8B>.<15>"), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://www.microsoft.com/, NSErrorFailingURLKey=https://www.microsoft.com/, _kCFStreamErrorDomainKey=1}
                at MonoTouchFixtures.Foundation.UrlSessionTest+<>c__DisplayClass1_0.<CreateDataTaskAsync>b__0 () [0x00039] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/monotouch-test/Foundation/UrlSessionTest.cs:64 >
                at MonoTouchFixtures.Foundation.UrlSessionTest.CreateDataTaskAsync () [0x000b7] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/monotouch-test/Foundation/UrlSessionTest.cs:71
2023-03-02 10:38:41 +01:00
Rolf Bjarne Kvinge 8e98350e0a
[XKit] Fix creating NSTextLists with custom formats in .NET. Fixes #15766. (#17123)
In .NET, we changed the API for creating a NSTextList with a specified
NSTextListMarkerFormats, making NSTextListMarkerFormats a strongly typed enum,
and not allowing any other value except those in NSTextListMarkerFormats.

This was a mistake, because NSTextList can be created with other format values
than those available in NSTextListMarkerFormats.

So fix this by:

* Adding another NSTextListMarkerFormats enum value that specifies that the
  actual format is a custom one (NSTextListMarkerFormats.CustomString).
* Resurface an 'NSTextListMarkerFormats(string)' constructor that can be used
  to create an NSTextListMarkerFormats with a custom string.
* Add a NSTextListMarkerFormats.CustomMarkerFormat property that always
  retrieves the underlying string value for the format.
* Add a NSTextListOptions.None enum value, which means no options (since
  NSTextListOptions is a set of flags, it should be possible to specify no
  flags).
* Add two convenience constructors that don't take a NSTextListOptions value,
  defaulting to NSTextListOptions.None.
* Add tests!

Fixes https://github.com/xamarin/xamarin-macios/issues/15766.
2023-01-10 08:28:47 +01:00
Rolf Bjarne Kvinge b3cb85c0ad
[tests] Allow for timeouts in CI in a few tests. (#16945)
Also add some exception handling.

Hopefully fixes more issues with broken network in CI.
2022-12-05 08:53:33 +01:00
Rolf Bjarne Kvinge e4c940cdb8
[Foundation] Fix NSDate's explicit conversion operators with DateTime. (#16872)
We recently tried to fix NSDate's conversion operators with DateTime
(3c65ab1756), but unfortunately a corner case
was missed.

The new approach in the above-mentioned commit would get the individual
date/time components for a given date and use the appropriate constructor for
the other type to re-construct the date/time in question.

However, one case was missed: when converting from NSDate to DateTime, we'd
get a fractional number of milliseconds. This fractional number could be
something like 999.99 milliseconds, and when converting that to the int the
DateTime constructor expected for the number of milliseconds, then DateTime
would throw an exception, because the number of milliseconds could only be
between 0 and 999.

I've solved this by not using floating-point math in the computations. We're
now getting the number of nanoseconds from the NSDate (which is a natural
number, and represents the total number of nanoseconds less than a whole
second), and then converting that to the number of milliseconds, microseconds
and ticks that can be used with DateTime using integral math. Unfortunately
DateTime doesn't have a constructor that takes the remaining number of ticks
after all the other fields have been provided, but that can be added
afterwards.

I've also made a few other improvements:

* Improve the validation for the NSDate -> DateTime conversion to detect BC
  dates by using the NSDate's Era component (to throw because DateTime only
  supports AC dates). Also don't allow a tick later than year 10.000 (DateTime
  only supports up to a tick before year 10.000) - but explicitly support
  exactly year 10.000, and convert it to DateTime.MaxValue (this is because
  due to precision errors NSDate can't actually express 'a tick before year
  10.000', it ends up being rounded up to year 10.000 exactly). This means
  there are no more magical values in the range validation checks.
* Increase precision in the DateTime -> NSDate conversion by starting with the
  sub-second amount of ticks from the DateTime instance (instead of the number
  of milliseconds). This allows us to compute the nanoseconds NSDate expects
  with much higher precision.
* More tests!

Fixes this test:

    MonoTouchFixtures.Foundation.DateTest.DateTimeToNSDate : 2 ms
        [FAIL] Precision32022 : System.ArgumentOutOfRangeException : Valid values are between 0 and 999, inclusive.
            Parameter name: millisecond
            at System.DateTime..ctor (System.Int32 year, System.Int32 month, System.Int32 day, System.Int32 hour, System.Int32 minute, System.Int32 second, System.Int32 millisecond, System.DateTimeKind kind) [0x0002d] in <4d40c65adfc14d7fb19bad9310f3eb2a>:0
            at Foundation.NSDate.op_Explicit (Foundation.NSDate d) [0x000b8] in <9cb1e1018c034b75ba5f4ed7b83ba2f2>:0
            at MonoTouchFixtures.Foundation.DateTest.Precision32022 () [0x0000c] in <c44b5df5f7b84b69b737e9fd61bddaed>:0
            at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
            at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <4d40c65adfc14d7fb19bad9310f3eb2a>:0

Fixes https://github.com/xamarin/maccore/issues/2632.

Date and time is difficult.

Ref: https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca
Ref: the rest of internet...
2022-11-23 07:55:22 +01:00
Rolf Bjarne Kvinge 6f45caa84d
[autoformat] Add monotouch-test (#16701) 2022-11-10 17:59:26 +01:00
Rolf Bjarne Kvinge ceaa0171da
Merge net7.0-xcode14.1 into main. (#16555)
This merges .NET 7 + Xcode 14.1 support into main.
2022-11-04 08:36:25 +01:00
Whitney Schmidt 3c65ab1756
Fix DateTime -> NSDate conversion (#7404)
Update conversions from `NSDate` to `DateTime` and `DateTime` to `NSDate` to use date components instead of `SecondsSinceReferenceDate`.

The number of seconds since reference date is inconsistent between `NSDate` and `DateTime`. See the associated bug - converting `DateTime` 1/1/1 to `NSDate` ends up giving you an `NSDate` a couple days off :(

Fixes https://github.com/xamarin/xamarin-macios/issues/6993.

Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-11-03 21:11:00 +01:00
Rolf Bjarne Kvinge cdc62aeae9 Merge remote-tracking branch 'origin/net7.0-xcode14.1' into main-net7.0-xcode14.1 2022-11-03 08:21:55 +01:00
Haritha Mohan f160ec03c9
[Foundation] Implement IEquatable and IComparable for NSOperatingSystemVersion (#16308)
Implemented the interfaces for NSOperatingSystemVersion, can now compare
instances and check for equality using operators.

Fixes #15721

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2022-10-18 10:25:28 -07:00
Rolf Bjarne Kvinge 45b97d838e Merge main into xcode14.1. 2022-10-06 13:59:29 +02:00
Rolf Bjarne Kvinge 273c2fa51a
[Foundation] Add NSArray.ToArray and implement IEnumerable<NSObject>. (#16252)
For NSArray, implement:

* A ToArray () method that returns an NSArray[].
* A ToArray<T> () method that returns a T[].
* The IEnumerable<NSObject> interface.

For NSArray<T>, implement:

* A ToArray () method that returns a T[].

This should make NSArray much better to work with from managed code.
2022-10-06 08:37:02 +02:00
Rolf Bjarne Kvinge 9c3458dc33 Merge main into xcode14.1. 2022-09-26 22:46:59 +02:00
Rolf Bjarne Kvinge b82b1685a7
Use Environment.SpecialFolder.UserProfile, not SpecialFolder.Personal. (#16017)
Context: dotnet/runtime#68610
Context: https://github.com/xamarin/xamarin-android-tools/commit/0be567a9

In Mono and .NET prior to .NET 8, the
[`System.Environment.SpecialFolder`][0]`.Personal` enum value would refer to
`$HOME` on Unix platforms.

This will be changing in .NET 8, such that
`Environment.SpecialFolder.Personal` will instead refer to
`$XDG_DOCUMENTS_DIR` (if set) or `$HOME/Documents`.  This is for "semantic
compatibility" with .NET on Windows.

Replace usage of `Environment.SpecialFolder.Personal` with
`Environment.SpecialFolder.UserProfile`, so that our code continues to work as
expected under .NET 8.

[0]: https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-6.0
2022-09-23 16:29:19 +02:00
Chris Hamons 3c359f5838
[foundation] Xcode 13 & Xcode 14 beta 1-3 bindings (#15579)
- Xcode 13 section Based upon https://github.com/xamarin/xamarin-macios/pull/13328- 
- Some disabled due to https://github.com/xamarin/maccore/issues/2608
2022-08-01 10:22:39 -05:00
Manuel de la Pena 46af411d1c
[Foundation] Allow null parameters when creating a NSUrl from a string. (#14603)
The headers do not say that a null parameter is allowed, but the
documentation and tests state otherwise:

https://developer.apple.com/documentation/foundation/nsurl/1572047-urlwithstring

The URL string with which to initialize the NSURL object. Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808.
2022-04-02 15:13:52 -04:00
Rolf Bjarne Kvinge ddb16120f9
[monotouch-test] Fix UbiquitousKeyValueStoreTest to work on newer versions of macOS. (#14267)
Fixes:

    MonoTouchFixtures.Foundation.NSUbiquitousKeyValueStoreTest
        [FAIL] Indexer :   key 1
            Expected: <value>
            But was:  null
2022-02-28 22:36:05 +01:00
Sebastien Pouliot c918142101
[objcruntime] Fix some `IntPtr` -> `NativeHandle` inside `Class` (#14174)
* Using `NativeHandle` avoids implicit casts [1]
* Do not expose `IntPtr` as the type for the `SuperClass` handle

[1] likely not an issue with JIT/AOT optimization, less sure for the
interpreter. No harm in not having those in the product assembly.
2022-02-23 20:45:43 +01:00
Filip Navara 0622ae4af2
Fix GC issue on CoreCLR where finalized objects are returned by Runtime.GetNSObject (#14070)
Fixes race condition where finalized objects are resurrected by the finalizer and for a brief moment `Runtime.TryGetNSObject`/`Runtime.GetNSObject` would return them even though a new instance is supposed to be used. In multi-threaded scenarios this would result in reused objects (same native handle) to suddenly become invalid when the UI thread processes the delayed finalization.

Fixes #13921
2022-02-08 11:08:44 +01:00
Marius Ungureanu dc9e080828
Implement IEquatable<T> on NSRange (#14083)
This avoids poor performance of GetHashCode and Equals that are used for the struct using reflection on the first field.
2022-02-07 07:52:45 +01:00
Rolf Bjarne Kvinge 534bf839c2
[Foundation] Fix signature for NSAttributedString.LowLevelGetAttributes to support no effectiveRange output. Fixes #13569. (#14069)
This makes it possible to override LowLevelGetAttributes to provide an
implementation, and be called with a NULL effectiveRange pointer.

Fixes https://github.com/xamarin/xamarin-macios/issues/13569.
2022-02-04 18:40:19 +01:00
Rolf Bjarne Kvinge b1ce33ba51
[Foundation/ObjCRuntime] Use 'ObjCException' as the native exception type name for all platforms in .NET. Fixes #13855. (#13915)
* Use 'ObjCException' instead of 'MonoTouchException' as the managed exception
  type wrapping an NSException for all platforms in .NET (that was already the
  case for macOS, so no change there).
* Make the ObjCException class behave like the MonoTouchException class does.
* Move the ObjCException type to the ObjCRuntime namespace in .NET.

Fixes https://github.com/xamarin/xamarin-macios/issues/13855.

Co-authored-by: TJ Lambert <50846373+tj-devel709@users.noreply.github.com>
2022-02-01 17:24:57 +01:00
Sebastien Pouliot 25fab0b74e
[net][coregraphics] Match native strings representation for structs (#13802)
* Use the native `NSStringFrom*` API so we can, eventually, use the
native code to parse them from `NSString` and also ensure increased
compatibility with any code that expects the native string representation

* Add unit tests for `ToString` methods

Also use [`System.HashCode`](https://docs.microsoft.com/en-us/dotnet/api/system.hashcode?view=net-6.0) to generate the hash code
2022-01-21 08:46:25 +01:00
Rolf Bjarne Kvinge f5cf33858b
[Foundation] Fix the NSMetadataItem.UbiquitousItemDownloadingStatus property name for .NET. (#13753) 2022-01-18 10:51:34 +01:00
Rolf Bjarne Kvinge 04a77c56dc
[Foundation] Fix a few method names to follow naming guidelines for .NET. (#13763) 2022-01-18 10:39:04 +01:00
Rolf Bjarne Kvinge 97dcd69d41
[Foundation] Remove some obsolete API in .NET. (#13678) 2022-01-17 20:58:46 +01:00
Rolf Bjarne Kvinge ce86f7746b
[Foundation] Remove some obsolete NSObject API in .NET (#13719)
Remove badly named API (or with typos) in .NET.
2022-01-17 09:45:44 +01:00
Rolf Bjarne Kvinge ed02a212bf
[Foundation] Replace broken version of NSRegularExpression.GetMatches with a working version for .NET. (#13732) 2022-01-17 09:34:26 +01:00
Rolf Bjarne Kvinge 1ee7a63412
[Foundation] Remove the NSDateComponentsWrappingBehavior in .NET. (#13713)
It's our own enum, and all the API using it have been obsoleted/removed.

There doesn't seem to be any other usage of it on GitHub either (only our own
source code and documentation).
2022-01-14 07:27:08 +01:00
Rolf Bjarne Kvinge 76cd53fe4d
[Foundation] Rename the NSLinguisticTagUnit enum to NSLinguisticTag in .NET. (#13706) 2022-01-13 22:30:44 +01:00
Alex Soto dfe6c2b5ab
[main] Add Xcode 13.2 Support (#13643)
* [Xcode13.2] Bump to Xcode 13.2 RC (#13497)

* [Xcode13.2] Bump to Xcode 13.2 Beta 2

Breaking changes addressed for legacy
* HomeKit
* CallKit
* CoreLocation

* [xcode13.2] Bump to Xcode 13.2 RC and apply feedback

* [AppKit] Fix missing Notifications

* Fix xtro

* [xcode13.2] Bump versions and use stable Xcode 13.2

* [monotouch-tests] Make TestAddingByComponents work on the last day of the year

Happy New Year!!

* NO BOM PLZ!
2022-01-03 09:28:00 -05:00
Rolf Bjarne Kvinge b169c806fc
[dotnet] Remove Runtime.Arch and ObjCRuntime.Arch from Mac Catalyst. Fixes #10312. (#13562)
Remove Runtime.Arch and ObjCRuntime.Arch from Mac Catalyst, because they don't
apply for a Mac Catalyst app (which is neither a simulator environment, nor a
device environment).

This means that code using these APIs will have to be re-evaluated to
determine what's the correct behavior for Mac Catalyst.

Also update our tests accordingly.

Fixes https://github.com/xamarin/xamarin-macios/issues/10312.
2021-12-15 22:32:14 +01:00
Rolf Bjarne Kvinge 0bd6cf095c
[tests] Remove a few Assert.Inconclusive calls that won't be executed anymore. (#13557)
Don't conditionally ignore tests that fail on Snow Leopard (or earlier),
because we're always executing on a later OS now.
2021-12-14 17:06:09 +01:00
Rolf Bjarne Kvinge 39bdae2b7f
[monotouch-test] Ignore a few tests in non-ARM64 simulators. (#13487)
* [monotouch-test] Ignore a few tests in non-ARM64 simulators.

Some tests fail when running on an M1, but in a x64_86 mode, so just ignore
those unless we're running on ARM64 (this will currently exclude them on
x86_64 hardware too, but that'll eventually not be a problem anymore when
there's no more x86_64 hardware, and just checking for ARM64 is easier than
checking for x86_64 mode on an ARM64 CPU).

* Make more legacy projects unsafe.
2021-12-07 21:10:39 +01:00
Rolf Bjarne Kvinge 19c2765156 [tests][monotouch-test] Adjust code to cope with NativeHandle. 2021-11-26 14:25:21 +01:00
Rolf Bjarne Kvinge 66e596e9d9
[tests] Change TestRuntime.CheckSystemVersion to take a ApplePlatform value instead of a PlatformName enum. (#13350)
The PlatformName enum will be removed from .NET soon.
2021-11-15 08:06:36 +01:00
Manuel de la Pena 3b47f94f94
[Tests] Remove not needed usings in the Foundation tests. (#13233) 2021-11-03 10:33:17 -04:00
Manuel de la Pena b20ca55943
[Foundation] Remove warning due to the Equals accepting a null value. (#12839)
Removes the following warning during the builds:

```
warning CS8767: Nullability of reference types in type of parameter 'host' of 'bool NSHost.Equals(NSHost host)' doesn't match implicitly implemented member 'bool IEquatable<NSHost>.Equals(NSHost? other)' (possibly because of nullability attributes)
```

Test was added to ensure that we did not throw an exception.
2021-09-28 08:11:07 -04:00
Rolf Bjarne Kvinge a78700bb40
[tests] Add additional test to try to narrow down #xamarin/maccore@2443. (#12384) 2021-09-16 15:00:06 +02:00
Rolf Bjarne Kvinge 71d2edbc80
[tests] Add debug spew to try to track down random test failure in NSMutableDictionary2Test.AddEntries. (#12711)
Ref: https://github.com/xamarin/maccore/issues/1605
2021-09-13 17:13:40 +02:00
Rolf Bjarne Kvinge 2972e1b715
Fix some whitespace issues in various files. (#12399)
* Remove BOM
* Add EOL at end of file.
2021-08-11 10:06:46 +02:00
Rolf Bjarne Kvinge 5b23ea83b1
[monotouch-test] Use unique file names to avoid issues when multiple proceseses of monotouch-test are running simultaneously. Fixes #xamarin/maccore@2461. (#12395)
Fixes https://github.com/xamarin/maccore/issues/2461.
2021-08-11 09:52:02 +02:00
Rolf Bjarne Kvinge 3766cf8fa2
[monotouch-test] Use the same timezone for the calendar as we do for the time (UTC) in CalendarTest.DateComponentsTest. Fixes #xamarin/maccore@2481. (#12304)
Fixes https://github.com/xamarin/maccore/issues/2481.
2021-07-30 16:02:36 +02:00
Rolf Bjarne Kvinge d24b2203af
[monotouch-test] No need to ignore NSTimeZoneTest.All_28300 anymore. (#12241) 2021-07-28 15:01:28 +02:00
Rolf Bjarne Kvinge 7986b2f2af
[dotnet] Globalization works for Mac Catalyst now. Fixes #11392. (#12247)
Fixes https://github.com/xamarin/xamarin-macios/issues/11392.
2021-07-28 09:12:22 +02:00
Rolf Bjarne Kvinge 600ce3290b
[monotouch-test] Adjust CalendarTest.DateComponentsTest to use a specific time zone. (#12249)
Hopefully avoids random test failures like https://github.com/xamarin/maccore/issues/2471#issuecomment-887517838.
2021-07-28 09:08:52 +02:00
Rolf Bjarne Kvinge 52ad560f3b
[monotouch-test] Make CalendarTest.TestOrdinality location-agnostic. Fixes #xamarin/maccore@2471. (#12192)
Modifying the test to use UTC datetimes instead of local datetimes + specify
the timezone for the NSCalendar to make the results predictable everywhere and
at all times.

Fixes https://github.com/xamarin/maccore/issues/2471.
2021-07-27 07:37:15 +02:00
Rolf Bjarne Kvinge ab10456117 [monotouch-test] Ignore NSTimeZoneTest.All_28300 on Mac Catalyst.
Due to https://github.com/dotnet/runtime/issues/55941.
2021-07-20 14:54:02 +02:00
Sebastien Pouliot b4dcee199b
Revert "[tests][monotouch-test] Ignore NSTimeZoneTest / All_28300 on dotnet as it hangs" (#11975)
This reverts commit 5fdd4e2dec.
2021-06-17 20:53:26 -04:00
Sebastien Pouliot 2ecbb07068
[tests] Re-enable tests ignored due to dotnet/runtime #36897 (#11939)
They should now work (even if some tests required more changes) and
will be able to validate other changes.

ref: https://github.com/dotnet/runtime/issues/36897
2021-06-16 09:41:27 -04:00