Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/2.2.2 #633

Merged
merged 3 commits into from
Aug 16, 2021
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

Version 2.2.2 (2021-08-16)
--------------------------
Fix crash on tvOS caused by access to filesystem (#621)
Fix Session UserID not consistent among tracker instances (#630)

Version 2.2.1 (2021-08-02)
--------------------------
Fix build errors in Xcoce 13 beta 3 when using SPM (#628)
Expand Down
87 changes: 87 additions & 0 deletions Snowplow iOSTests/TestDataPersistence.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// TestDataPersistence.m
// Snowplow-iOSTests
//
// Copyright (c) 2013-2021 Snowplow Analytics Ltd. All rights reserved.
//
// This program is licensed to you under the Apache License Version 2.0,
// and you may not use this file except in compliance with the Apache License
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
// http://www.apache.org/licenses/LICENSE-2.0.
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the Apache License Version 2.0 is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the Apache License Version 2.0 for the specific
// language governing permissions and limitations there under.
//
// Authors: Alex Benini
// Copyright: Copyright (c) 2013-2021 Snowplow Analytics Ltd
// License: Apache License Version 2.0
//

#import <XCTest/XCTest.h>
#import "SPDataPersistence.h"

@interface TestDataPersistence : XCTestCase

@end

@implementation TestDataPersistence

- (void)setUp {
[SPDataPersistence removeDataPersistenceWithNamespace:@"namespace"];
[SPDataPersistence removeDataPersistenceWithNamespace:@"namespace1"];
[SPDataPersistence removeDataPersistenceWithNamespace:@"namespace2"];
}

- (void)testStringFromNamespace {
XCTAssertEqualObjects(@"abc-1_2_3", [SPDataPersistence stringFromNamespace:@"abc 1_2_3"]);
}

- (void)testDataPersistenceForNamespaceWithDifferentNamespaces {
SPDataPersistence *dp1 = [SPDataPersistence dataPersistenceForNamespace:@"namespace1"];
SPDataPersistence *dp2 = [SPDataPersistence dataPersistenceForNamespace:@"namespace2"];
XCTAssertNotEqual(dp1, dp2);
}

- (void)testDataPersistenceForNamespaceWithSameNamespaces {
SPDataPersistence *dp1 = [SPDataPersistence dataPersistenceForNamespace:@"namespace"];
SPDataPersistence *dp2 = [SPDataPersistence dataPersistenceForNamespace:@"namespace"];
XCTAssertEqual(dp1, dp2);
}

- (void)testRemoveDataPersistenceForNamespace {
SPDataPersistence *dp1 = [SPDataPersistence dataPersistenceForNamespace:@"namespace"];
[SPDataPersistence removeDataPersistenceWithNamespace:@"namespace"];
SPDataPersistence *dp2 = [SPDataPersistence dataPersistenceForNamespace:@"namespace"];
XCTAssertNotEqual(dp1, dp2);
}

- (void)testDataIsCorrectlyStored {
SPDataPersistence *dp = [SPDataPersistence dataPersistenceForNamespace:@"namespace"];
NSDictionary<NSString *, NSObject *> *session = @{@"key": @"value"};
dp.session = session;
XCTAssertEqualObjects(session, dp.session);
XCTAssertEqualObjects(session, dp.data[@"session"]);
// Override session
session = @{@"key2": @"value2"};
dp.session = session;
XCTAssertEqualObjects(session, dp.session);
XCTAssertEqualObjects(session, dp.data[@"session"]);
}

- (void)testDataIsStoredWithoutInterference {
SPDataPersistence *dp1 = [SPDataPersistence dataPersistenceForNamespace:@"namespace1"];
SPDataPersistence *dp2 = [SPDataPersistence dataPersistenceForNamespace:@"namespace2"];
NSDictionary<NSString *, NSObject *> *session = @{@"key": @"value"};
dp1.session = session;
// Check dp1
XCTAssertEqualObjects(session, dp1.session);
XCTAssertEqualObjects(session, dp1.data[@"session"]);
// Check dp2
XCTAssertNotEqualObjects(session, dp2.session);
XCTAssertNotEqualObjects(session, dp2.data[@"session"]);
}

@end
82 changes: 82 additions & 0 deletions Snowplow iOSTests/TestMemoryEventStore.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// TestMemoryEventStore.m
// Snowplow
//
// Copyright (c) 2013-2021 Snowplow Analytics Ltd. All rights reserved.
//
// This program is licensed to you under the Apache License Version 2.0,
// and you may not use this file except in compliance with the Apache License
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
// http://www.apache.org/licenses/LICENSE-2.0.
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the Apache License Version 2.0 is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the Apache License Version 2.0 for the specific
// language governing permissions and limitations there under.
//
// Authors: Jonathan Almeida
// Copyright: Copyright (c) 2013-2021 Snowplow Analytics Ltd
// License: Apache License Version 2.0
//

#import <XCTest/XCTest.h>
#import "SPMemoryEventStore.h"
#import "SPPayload.h"

@interface TestMemoryEventStore : XCTestCase
@end

@implementation TestMemoryEventStore

- (void)testInit {
SPMemoryEventStore * eventStore = [[SPMemoryEventStore alloc] init];
XCTAssertNotNil(eventStore);
}

- (void)testInsertPayload {
SPMemoryEventStore * eventStore = [[SPMemoryEventStore alloc] init];
[eventStore removeAllEvents];

// Build an event
SPPayload * payload = [[SPPayload alloc] init];
[payload addValueToPayload:@"pv" forKey:@"e"];
[payload addValueToPayload:@"www.foobar.com" forKey:@"url"];
[payload addValueToPayload:@"Welcome to foobar!" forKey:@"page"];
[payload addValueToPayload:@"MEEEE" forKey:@"refr"];

// Insert an event
[eventStore addEvent:payload];

XCTAssertEqual([eventStore count], 1);
NSArray<SPEmitterEvent *> *events = [eventStore emittableEventsWithQueryLimit:1];
XCTAssertEqualObjects([events[0].payload getAsDictionary], [payload getAsDictionary]);
[eventStore removeEventWithId:0];

XCTAssertEqual([eventStore count], 0);
}

- (void)testInsertManyPayloads {
SPMemoryEventStore * eventStore = [[SPMemoryEventStore alloc] init];
[eventStore removeAllEvents];

// Build an event
SPPayload * payload = [[SPPayload alloc] init];
[payload addValueToPayload:@"pv" forKey:@"e"];
[payload addValueToPayload:@"www.foobar.com" forKey:@"url"];
[payload addValueToPayload:@"Welcome to foobar!" forKey:@"page"];
[payload addValueToPayload:@"MEEEE" forKey:@"refr"];

for (int i = 0; i < 250; i++) {
[eventStore addEvent:payload];
}

XCTAssertEqual([eventStore count], 250);
XCTAssertEqual([eventStore emittableEventsWithQueryLimit:600].count, 250);
XCTAssertEqual([eventStore emittableEventsWithQueryLimit:150].count, 150);

[eventStore removeAllEvents];
XCTAssertEqual([eventStore count], 0);
}

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TestEventStore.m
// TestSQLiteEventStore.m
// Snowplow
//
// Copyright (c) 2013-2021 Snowplow Analytics Ltd. All rights reserved.
Expand All @@ -24,10 +24,10 @@
#import "SPSQLiteEventStore.h"
#import "SPPayload.h"

@interface TestEventStore : XCTestCase
@interface TestSQLiteEventStore : XCTestCase
@end

@implementation TestEventStore
@implementation TestSQLiteEventStore

- (void)setUp {
[SPSQLiteEventStore removeUnsentEventsExceptForNamespaces:@[]];
Expand Down
11 changes: 2 additions & 9 deletions Snowplow iOSTests/TestSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#import <XCTest/XCTest.h>
#import "SPSession.h"
#import "SPDataPersistence.h"
#import "SPTrackerConstants.h"

/// Category needed to make the private methods testable.
Expand All @@ -40,7 +41,6 @@ @implementation TestSession

- (void)setUp {
[super setUp];
[self cleanSessionFileWithNamespace:nil];
[self cleanSessionFileWithNamespace:@"tracker"];
}

Expand Down Expand Up @@ -368,14 +368,7 @@ - (void)testMultipleTrackersUpdateDifferentSessions {
/// Service methods

- (void)cleanSessionFileWithNamespace:(NSString *)namespace {
NSString *sessionFilename = @"session.dict";
if (namespace) {
sessionFilename = [SPSession createSessionFilenameWithNamespace:@"tracker"];
}
NSError *error = nil;
NSURL *sessionFileUrl = [SPSession createSessionFileUrlWithFilename:sessionFilename];
[[NSFileManager defaultManager] removeItemAtURL:sessionFileUrl error:&error];
NSLog(@"%@", error.localizedDescription);
[SPDataPersistence removeDataPersistenceWithNamespace:namespace];
}

@end
Loading