Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/objective-c-xcode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ jobs:
run: |
xcodebuild build -scheme CoreZen -project CoreZen.xcodeproj

- name: Test
run: |
xcodebuild test -scheme CoreZen -project CoreZen.xcodeproj

- name: Analyze
run: |
xcodebuild analyze -scheme CoreZen -project CoreZen.xcodeproj
36 changes: 33 additions & 3 deletions CoreZen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@
0D8B0E7E4B2D6D25D9EE6309 /* libavutil.60.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 37C6CE60E6FAE7A41E5758F2 /* libavutil.60.dylib */; };
A648515826063B25A687BEE2 /* libmpv.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 14B85B4A23B3B9E64D362517 /* libmpv.2.dylib */; };
7BBED1C0448E642D02061408 /* libswscale.9.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AF2CEA40DF73E47475E7F86E /* libswscale.9.dylib */; };
CC00000228860A0000000001 /* NodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC00000128860A0000000001 /* NodeTests.m */; };
CC00000228860A0000000002 /* QueueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC00000128860A0000000002 /* QueueTests.m */; };
CC00000228860A0000000003 /* DomainTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC00000128860A0000000003 /* DomainTests.m */; };
CC00000228860A0000000004 /* TestDTO.m in Sources */ = {isa = PBXBuildFile; fileRef = CC00000128860A0000000005 /* TestDTO.m */; };
CC00000228860A0000000005 /* TestTable.m in Sources */ = {isa = PBXBuildFile; fileRef = CC00000128860A0000000007 /* TestTable.m */; };
CC00000228860A0000000006 /* TestDomainObject.m in Sources */ = {isa = PBXBuildFile; fileRef = CC00000128860A0000000009 /* TestDomainObject.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -515,6 +521,15 @@
9215CC53E9C2CED004BBB718 /* render.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = render.h; sourceTree = "<group>"; };
79D0AF2EFC89B99015EE993D /* render_gl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = render_gl.h; sourceTree = "<group>"; };
53170EA3BE67D827F0B5181C /* stream_cb.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stream_cb.h; sourceTree = "<group>"; };
CC00000128860A0000000001 /* NodeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NodeTests.m; sourceTree = "<group>"; };
CC00000128860A0000000002 /* QueueTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QueueTests.m; sourceTree = "<group>"; };
CC00000128860A0000000003 /* DomainTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DomainTests.m; sourceTree = "<group>"; };
CC00000128860A0000000004 /* TestDTO.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestDTO.h; sourceTree = "<group>"; };
CC00000128860A0000000005 /* TestDTO.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestDTO.m; sourceTree = "<group>"; };
CC00000128860A0000000006 /* TestTable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestTable.h; sourceTree = "<group>"; };
CC00000128860A0000000007 /* TestTable.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestTable.m; sourceTree = "<group>"; };
CC00000128860A0000000008 /* TestDomainObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestDomainObject.h; sourceTree = "<group>"; };
CC00000128860A0000000009 /* TestDomainObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestDomainObject.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -586,9 +601,12 @@
children = (
5350F8B52886079F00F8CA68 /* Classes */,
5309C3B82885A1DC00BC0AAE /* CoreZenTests.m */,
5350F8B62886080500F8CA68 /* CategoryTests.m */,
5350F8A32886020500F8CA68 /* DatabaseTests.m */,
CC00000128860A0000000003 /* DomainTests.m */,
CC00000128860A0000000001 /* NodeTests.m */,
5350F8B32886074F00F8CA68 /* ObjectCacheTests.m */,
5350F8B62886080500F8CA68 /* CategoryTests.m */,
CC00000128860A0000000002 /* QueueTests.m */,
);
path = CoreZenTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -726,8 +744,14 @@
5350F8B52886079F00F8CA68 /* Classes */ = {
isa = PBXGroup;
children = (
CC00000128860A0000000008 /* TestDomainObject.h */,
CC00000128860A0000000009 /* TestDomainObject.m */,
CC00000128860A0000000004 /* TestDTO.h */,
CC00000128860A0000000005 /* TestDTO.m */,
538E052C2885FB5400CE9DE7 /* TestIdentifiable.h */,
538E052D2885FB5400CE9DE7 /* TestIdentifiable.m */,
CC00000128860A0000000006 /* TestTable.h */,
CC00000128860A0000000007 /* TestTable.m */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -1284,10 +1308,16 @@
buildActionMask = 2147483647;
files = (
5309C3B92885A1DC00BC0AAE /* CoreZenTests.m in Sources */,
5350F8A42886020500F8CA68 /* DatabaseTests.m in Sources */,
538E052E2885FB5400CE9DE7 /* TestIdentifiable.m in Sources */,
5350F8B72886080500F8CA68 /* CategoryTests.m in Sources */,
5350F8A42886020500F8CA68 /* DatabaseTests.m in Sources */,
CC00000228860A0000000003 /* DomainTests.m in Sources */,
CC00000228860A0000000001 /* NodeTests.m in Sources */,
5350F8B42886074F00F8CA68 /* ObjectCacheTests.m in Sources */,
CC00000228860A0000000002 /* QueueTests.m in Sources */,
CC00000228860A0000000004 /* TestDTO.m in Sources */,
CC00000228860A0000000006 /* TestDomainObject.m in Sources */,
538E052E2885FB5400CE9DE7 /* TestIdentifiable.m in Sources */,
CC00000228860A0000000005 /* TestTable.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
12 changes: 12 additions & 0 deletions CoreZen.xcodeproj/xcshareddata/xcschemes/CoreZen.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5309C3B22885A1DC00BC0AAE"
BuildableName = "CoreZenTests.xctest"
BlueprintName = "CoreZenTests"
ReferencedContainer = "container:CoreZen.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
92 changes: 74 additions & 18 deletions CoreZenTests/CategoryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,24 @@ @interface CategoryTests : XCTestCase

@implementation CategoryTests

- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
#pragma mark - NSURL+CoreZen

- (void)testRelativePath {
NSURL *urlOne = [NSURL fileURLWithPath:@"/Users/CoreZen" isDirectory:YES];
NSURL *base = [NSURL fileURLWithPath:@"/Users/CoreZen" isDirectory:YES];
NSURL *child = [NSURL fileURLWithPath:@"/Users/CoreZen/Documents/foo.pdf"];

NSString *relativePath = @"Documents/foo.pdf";
NSURL *urlTwo = [NSURL URLWithString:relativePath relativeToURL:urlOne];
NSString *relativePath = [base zen_relativePathToURL:child];
XCTAssertNotNil(relativePath, @"Should produce a relative path");
// Implementation strips base path prefix, leaving the separator
XCTAssertEqualObjects(relativePath, @"/Documents/foo.pdf");
}

- (void)testRelativePathReturnsNilForUnrelatedURLs {
NSURL *urlOne = [NSURL fileURLWithPath:@"/Users/Alpha" isDirectory:YES];
NSURL *urlTwo = [NSURL fileURLWithPath:@"/Users/Beta/file.txt"];

NSString *anotherRelativePath = [urlOne zen_relativePathToURL:urlTwo];
if (anotherRelativePath) {
XCTAssert([relativePath isEqualToString:anotherRelativePath], @"Relative paths should match, %@ != %@", relativePath, anotherRelativePath);
} else {
XCTFail(@"NSURL zen_relativePathToURL: failed, %@ vs %@", urlOne, urlTwo);
}
NSString *relativePath = [urlOne zen_relativePathToURL:urlTwo];
XCTAssertNil(relativePath, @"Unrelated URLs should not produce a relative path");
}

- (void)testVolumeInfo {
Expand All @@ -49,8 +47,8 @@ - (void)testVolumeInfo {
NSURL *anotherVolumeURL;

if ([NSURL zen_volumeInfoForUUID:volumeUUID volumeName:&anotherVolumeName volumeURL:&anotherVolumeURL]) {
XCTAssert([volumeName isEqual:anotherVolumeName], @"Volume names should match, %@ != %@", volumeName, anotherVolumeName);
XCTAssert([volumeURL isEqual:anotherVolumeURL]);
XCTAssertEqualObjects(volumeName, anotherVolumeName, @"Volume names should match");
XCTAssertEqualObjects(volumeURL, anotherVolumeURL, @"Volume URLs should match");
} else {
XCTFail(@"NSURL zen_volumeInfoForUUID:volumeName:volumeURL: failed, UUID: %@", volumeUUID);
}
Expand All @@ -59,4 +57,62 @@ - (void)testVolumeInfo {
}
}

- (void)testFileSizeReturnsZeroForNonexistentFile {
NSURL *url = [NSURL fileURLWithPath:@"/tmp/corezen_nonexistent_test_file.xyz"];
NSUInteger size = [url zen_fileSize];
XCTAssertEqual(size, 0u, @"File size of a nonexistent file should be 0");
}

- (void)testFileSizeForRealFile {
NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"corezen_size_test.txt"];
NSData *data = [@"Hello CoreZen" dataUsingEncoding:NSUTF8StringEncoding];
[data writeToFile:tmpPath atomically:YES];

NSURL *url = [NSURL fileURLWithPath:tmpPath];
NSUInteger size = [url zen_fileSize];
XCTAssertEqual(size, data.length, @"File size should match the data written");

[[NSFileManager defaultManager] removeItemAtPath:tmpPath error:nil];
}

#pragma mark - NSNumber+CoreZen

- (void)testRandomIntegerReturnsValues {
NSInteger a = [NSNumber zen_randomInteger];
NSInteger b = [NSNumber zen_randomInteger];
// Probability of collision on 64-bit random values is negligible
XCTAssertNotEqual(a, b, @"Two random integers should differ (statistically)");
}

#pragma mark - NSFileManager+CoreZen

- (void)testFindOrCreateDirectoryInTemp {
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error;
NSURL *url = [fm zen_findOrCreateURLForDirectory:NSCachesDirectory
inDomain:NSUserDomainMask
appendPathComponent:@"CoreZenTestDir"
create:YES
error:&error];
XCTAssertNotNil(url, @"Should return a URL, error: %@", error);

BOOL isDir = NO;
BOOL exists = [fm fileExistsAtPath:url.path isDirectory:&isDir];
XCTAssertTrue(exists, @"Directory should exist");
XCTAssertTrue(isDir, @"Path should be a directory");

[fm removeItemAtURL:url error:nil];
}

- (void)testFindOrCreateDirectoryWithoutAppend {
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error;
NSURL *url = [fm zen_findOrCreateURLForDirectory:NSCachesDirectory
inDomain:NSUserDomainMask
appendPathComponent:nil
create:NO
error:&error];
XCTAssertNotNil(url, @"Should return the caches directory, error: %@", error);
}

@end
14 changes: 14 additions & 0 deletions CoreZenTests/Classes/TestDTO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TestDTO.h
// CoreZenTests
//

#import <CoreZen/DataTransferObject.h>

@interface ZENTestDTO : ZENDataTransferObject

@property (nonatomic, copy) NSString *name;

- (instancetype)initWithIdentifier:(ZENIdentifier)identifier name:(NSString *)name;

@end
18 changes: 18 additions & 0 deletions CoreZenTests/Classes/TestDTO.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// TestDTO.m
// CoreZenTests
//

#import "TestDTO.h"

@implementation ZENTestDTO

- (instancetype)initWithIdentifier:(ZENIdentifier)identifier name:(NSString *)name {
self = [super initWithIdentifier:identifier];
if (self) {
_name = [name copy];
}
return self;
}

@end
12 changes: 12 additions & 0 deletions CoreZenTests/Classes/TestDomainObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// TestDomainObject.h
// CoreZenTests
//

#import <CoreZen/DomainObject.h>

@interface ZENTestDomainObject : ZENDomainObject

@property (nonatomic, copy, readonly) NSString *name;

@end
20 changes: 20 additions & 0 deletions CoreZenTests/Classes/TestDomainObject.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// TestDomainObject.m
// CoreZenTests
//

#import "TestDomainObject.h"
#import "TestDTO.h"

@implementation ZENTestDomainObject

- (instancetype)initWithDTO:(ZENDataTransferObject *)dto {
self = [super initWithDTO:dto];
if (self) {
ZENTestDTO *testDTO = (ZENTestDTO *)dto;
_name = [testDTO.name copy];
}
return self;
}

@end
11 changes: 11 additions & 0 deletions CoreZenTests/Classes/TestTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// TestTable.h
// CoreZenTests
//

#import <Foundation/Foundation.h>
#import <CoreZen/DatabaseTable.h>

@interface ZENTestTable : NSObject <ZENDatabaseTable>

@end
71 changes: 71 additions & 0 deletions CoreZenTests/Classes/TestTable.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// TestTable.m
// CoreZenTests
//

#import "TestTable.h"
#import "TestDTO.h"

@import CoreZen;

@implementation ZENTestTable

+ (NSString *)tableName {
return @"test_objects";
}

+ (BOOL)updateSchema:(ZENDatabase *)database version:(NSUInteger)version {
if (version == 1) {
[database executeUpdate:
@"CREATE TABLE IF NOT EXISTS test_objects ("
"identifier INTEGER PRIMARY KEY, "
"name TEXT"
");"];
return YES;
}
return NO;
}

- (BOOL)insertDTO:(ZENDataTransferObject *)dto database:(ZENDatabase *)database {
ZENTestDTO *testDTO = (ZENTestDTO *)dto;
return [database executeUpdate:@"INSERT INTO test_objects (identifier, name) VALUES (?, ?);"
withArgumentsInArray:@[@(testDTO.identifier), testDTO.name ?: [NSNull null]]];
}

- (BOOL)updateDTO:(ZENDataTransferObject *)dto database:(ZENDatabase *)database {
ZENTestDTO *testDTO = (ZENTestDTO *)dto;
return [database executeUpdate:@"UPDATE test_objects SET name = ? WHERE identifier = ?;"
withArgumentsInArray:@[testDTO.name ?: [NSNull null], @(testDTO.identifier)]];
}

- (BOOL)deleteByIdentifier:(ZENIdentifier)identifier database:(ZENDatabase *)database {
return [database executeUpdate:@"DELETE FROM test_objects WHERE identifier = ?;"
withArgumentsInArray:@[@(identifier)]];
}

- (ZENDataTransferObject *)dtoFromRow:(ZENResultSet *)row {
ZENIdentifier identifier = [row longLongIntForColumnIndex:0];
NSString *name = [row stringForColumnIndex:1];
return [[ZENTestDTO alloc] initWithIdentifier:identifier name:name];
}

- (ZENResultSet *)allRows:(ZENDatabase *)database {
return [database executeQuery:@"SELECT identifier, name FROM test_objects ORDER BY identifier;"];
}

- (ZENResultSet *)rowByIdentifier:(ZENIdentifier)identifier database:(ZENDatabase *)database {
return [database executeQuery:@"SELECT identifier, name FROM test_objects WHERE identifier = ?;"
withArgumentsInArray:@[@(identifier)]];
}

- (NSUInteger)countAllRows:(ZENDatabase *)database {
ZENResultSet *rs = [database executeQuery:@"SELECT COUNT(*) FROM test_objects;"];
NSUInteger count = 0;
if ([rs next]) {
count = (NSUInteger)[rs longLongIntForColumnIndex:0];
}
[rs close];
return count;
}

@end
Loading
Loading