|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +#include <QtTest> |
| 7 | + |
| 8 | +#include "macOS/fileproviderxpc_mac_utils.h" |
| 9 | + |
| 10 | +#import <FileProvider/FileProvider.h> |
| 11 | + |
| 12 | +@interface TestFileProviderService : NSObject |
| 13 | +@property (nonatomic, copy) NSString *name; |
| 14 | +@end |
| 15 | + |
| 16 | +@implementation TestFileProviderService |
| 17 | +@end |
| 18 | + |
| 19 | +@interface TestFileProviderManager : NSObject |
| 20 | +@property (nonatomic, retain) NSFileProviderService *service; |
| 21 | +@end |
| 22 | + |
| 23 | +@implementation TestFileProviderManager |
| 24 | + |
| 25 | +- (void)getServiceWithName:(NSFileProviderServiceName)serviceName |
| 26 | + itemIdentifier:(NSFileProviderItemIdentifier)itemIdentifier |
| 27 | + completionHandler:(void (^)(NSFileProviderService *service, NSError *error))completionHandler |
| 28 | +{ |
| 29 | + dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{ |
| 30 | + completionHandler(self.service, nil); |
| 31 | + }); |
| 32 | +} |
| 33 | + |
| 34 | +@end |
| 35 | + |
| 36 | +class TestFileProviderXPCUtils : public QObject |
| 37 | +{ |
| 38 | + Q_OBJECT |
| 39 | + |
| 40 | +private Q_SLOTS: |
| 41 | + void concurrentServiceLookupsCanBeCollected() |
| 42 | + { |
| 43 | + constexpr auto managerCount = 128; |
| 44 | + NSMutableArray<NSFileProviderManager *> * const managers = NSMutableArray.array; |
| 45 | + |
| 46 | + for (auto index = 0; index < managerCount; ++index) { |
| 47 | + const auto service = [TestFileProviderService new]; |
| 48 | + service.name = [NSString stringWithFormat:@"service-%d", index]; |
| 49 | + |
| 50 | + const auto manager = [TestFileProviderManager new]; |
| 51 | + manager.service = (NSFileProviderService *)service; |
| 52 | + [managers addObject:(NSFileProviderManager *)manager]; |
| 53 | + [service release]; |
| 54 | + [manager release]; |
| 55 | + } |
| 56 | + |
| 57 | + const auto services = OCC::Mac::FileProviderXPCUtils::getFileProviderServices(managers); |
| 58 | + QCOMPARE(services.count, managerCount); |
| 59 | + } |
| 60 | + |
| 61 | + void serviceWithoutNameIsIgnored() |
| 62 | + { |
| 63 | + const auto service = [TestFileProviderService new]; |
| 64 | + const auto manager = [TestFileProviderManager new]; |
| 65 | + manager.service = (NSFileProviderService *)service; |
| 66 | + |
| 67 | + const auto services = OCC::Mac::FileProviderXPCUtils::getFileProviderServices(@[(NSFileProviderManager *)manager]); |
| 68 | + QCOMPARE(services.count, 0); |
| 69 | + |
| 70 | + [service release]; |
| 71 | + [manager release]; |
| 72 | + } |
| 73 | +}; |
| 74 | + |
| 75 | +QTEST_APPLESS_MAIN(TestFileProviderXPCUtils) |
| 76 | +#include "testfileproviderxpcutils.moc" |
0 commit comments