Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin committed Mar 4, 2024
1 parent bd1d16b commit 32d1571
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# import "SentrySwift.h"
# import "SentryInternalDefines.h"
# import "SentrySwift.h"
# import "SentryLog.h"
# import "SentryProfiler+Private.h"
# include <mutex>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# import "SentryFormatter.h"
# import "SentryFramesTracker.h"
# import "SentryHub+Private.h"
# import "SentryId.h"
# import "SentrySwift.h"
# import "SentryInternalDefines.h"
# import "SentryLog.h"
# import "SentryMetricProfiler.h"
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentrySerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data
SentryId *eventId = nil;
NSString *eventIdAsString = headerDictionary[@"event_id"];
if (nil != eventIdAsString) {
eventId = [[SentryId alloc] initWithUUIDString:eventIdAsString];
eventId = [[SentryId alloc] initWithUuidString:eventIdAsString];
}

SentrySdkInfo *sdkInfo = nil;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryTraceContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ - (instancetype)initWithTraceId:(SentryId *)traceId

- (nullable instancetype)initWithDict:(NSDictionary<NSString *, id> *)dictionary
{
SentryId *traceId = [[SentryId alloc] initWithUUIDString:dictionary[@"trace_id"]];
SentryId *traceId = [[SentryId alloc] initWithUuidString:dictionary[@"trace_id"]];
NSString *publicKey = dictionary[@"public_key"];
if (traceId == nil || publicKey == nil)
return nil;
Expand Down
3 changes: 1 addition & 2 deletions Sources/Sentry/include/SentryProfiledTracerConcurrency.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#import "SentryCompiler.h"
#import "SentrySwift.h"
#import "SentryProfilingConditionals.h"
#import <Foundation/Foundation.h>

@class SentryProfiler;
@class SentryProfiler, SentryId;

#if SENTRY_TARGET_PROFILING_SUPPORTED

Expand Down
5 changes: 5 additions & 0 deletions Sources/Sentry/include/SentrySwift.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#ifndef SentrySwift_h
#define SentrySwift_h


#ifdef __cplusplus
#import <MetricKit/MetricKit.h>
#endif

#if __has_include("Sentry-Swift.h")
# import "Sentry-Swift.h"
#else
Expand Down
37 changes: 25 additions & 12 deletions Sources/Swift/Protocol/SentryId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import Foundation

@objcMembers
public class SentryId : NSObject {

/**
* A @c SentryId with an empty UUID "00000000000000000000000000000000".
*/
static var empty = SentryId(UUIDString: "00000000-0000-0000-0000-000000000000")
public static var empty = SentryId(uuidString: "00000000-0000-0000-0000-000000000000")

/**
* Returns a 32 lowercase character hexadecimal string description of the @c SentryId, such as
* "12c2d058d58442709aa2eca08bf20986".
*/
var sentryIdString : String {
public var sentryIdString : String {
return id.uuidString.replacingOccurrences(of: "-", with: "").lowercased()
}

Expand All @@ -40,20 +40,33 @@ public class SentryId : NSObject {
* "12c2d058-d584-4270-9aa2-eca08bf20986".
* @return SentryId.empty for invalid strings.
*/
public init?(UUIDString : String) {
if let id = UUID(uuidString: UUIDString) {
public init(uuidString : String) {
if let id = UUID(uuidString: uuidString) {
self.id = id
return
}

if UUIDString.count != 32 {
return nil
if uuidString.count == 32 {
let dashedUUID = "\(uuidString[0..<8])-\(uuidString[8..<12])-\(uuidString[12..<16])-\(uuidString[16..<20])-\(uuidString[20...])"
if let id = UUID(uuidString: dashedUUID) {
self.id = id
return
}
}

let dashedUUID = "\(UUIDString[0..<8])-\(UUIDString[8..<12])-\(UUIDString[12..<16])-\(UUIDString[16...])"
guard let id = UUID(uuidString: dashedUUID) else {
return nil
}
self.id = id
self.id = UUID(uuidString: "00000000-0000-0000-0000-000000000000")!
}

override public func isEqual(_ object: Any?) -> Bool {
guard let other = object as? SentryId else { return false }
return other.id == self.id
}

override public var description: String {
sentryIdString
}

override public var hash: Int {
id.hashValue
}
}
2 changes: 1 addition & 1 deletion Tests/SentryTests/Protocol/SentryEventTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Sentry
@testable import Sentry
import SentryTestUtils
import XCTest

Expand Down

0 comments on commit 32d1571

Please sign in to comment.