forked from skiptools/swift-android-native
-
Notifications
You must be signed in to change notification settings - Fork 2
Add AndroidConfigurationTests
#16
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1c965ba
Add `AndroidConfigurationTests`
colemancda 6e659ca
Update `Configuration.init()`
colemancda 5f0ca01
Update `StorageManager.init()`
colemancda 0264a33
Update `AndroidFileManagerError`
colemancda 9255d8c
Update `ObbFile.init(path:)`
colemancda 6939a39
Disable `Configuration.screenRound` setter
colemancda 52c37d0
Updated unit tests
colemancda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
Tests/AndroidConfigurationTests/AndroidConfigurationTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftAndroidNative open source project | ||
| // | ||
| // Copyright (c) 2024-2026 Skip.dev and SwiftAndroidNative project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftAndroidNative project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import Testing | ||
| import AndroidFileManager | ||
|
|
||
| struct AndroidConfigurationTests { | ||
|
|
||
| @Test func testProperties() throws { | ||
| var config = Configuration() | ||
|
|
||
| config.mobileCountryCode = 310 | ||
| #expect(config.mobileCountryCode == 310) | ||
|
|
||
| config.mobileNetworkCode = 260 | ||
| #expect(config.mobileNetworkCode == 260) | ||
|
|
||
| config.languageCode = "en" | ||
| #expect(config.languageCode == "en") | ||
|
|
||
| config.countryCode = "US" | ||
| #expect(config.countryCode == "US") | ||
|
|
||
| config.orientation = .portrait | ||
| #expect(config.orientation == .portrait) | ||
|
|
||
| config.touchscreen = .finger | ||
| #expect(config.touchscreen == .finger) | ||
|
|
||
| config.density = .xHigh | ||
| #expect(config.density == .xHigh) | ||
|
|
||
| config.keyboard = .qwerty | ||
| #expect(config.keyboard == .qwerty) | ||
|
|
||
| config.navigation = .dpad | ||
| #expect(config.navigation == .dpad) | ||
|
|
||
| config.keysHidden = .hidden | ||
| #expect(config.keysHidden == .hidden) | ||
|
|
||
| config.navHidden = .hidden | ||
| #expect(config.navHidden == .hidden) | ||
|
|
||
| config.sdkVersion = 33 | ||
| #expect(config.sdkVersion == 33) | ||
|
|
||
| config.screenSize = .large | ||
| #expect(config.screenSize == .large) | ||
|
|
||
| config.screenLong = .long | ||
| #expect(config.screenLong == .long) | ||
|
|
||
| config.uiModeType = .normal | ||
| #expect(config.uiModeType == .normal) | ||
|
|
||
| config.uiModeNight = .dark | ||
| #expect(config.uiModeNight == .dark) | ||
|
|
||
| config.screenWidthDp = 1080 | ||
| #expect(config.screenWidthDp == 1080) | ||
|
|
||
| config.screenHeightDp = 1920 | ||
| #expect(config.screenHeightDp == 1920) | ||
|
|
||
| config.smallestScreenWidthDp = 360 | ||
| #expect(config.smallestScreenWidthDp == 360) | ||
|
|
||
| if #available(Android 17, *) { | ||
| config.layoutDirection = .rightToLeft | ||
| #expect(config.layoutDirection == .rightToLeft) | ||
| } | ||
|
|
||
| if #available(Android 30, *) { | ||
| //config.screenRound = .round | ||
| #expect(config.screenRound == .any) | ||
| } | ||
|
|
||
| if #available(Android 34, *) { | ||
| config.grammaticalGender = .feminine | ||
| #expect(config.grammaticalGender == .feminine) | ||
| } | ||
| } | ||
|
|
||
| @Test func testMatches() throws { | ||
| // Two default configurations should match each other | ||
| let a = Configuration() | ||
| let b = Configuration() | ||
| let defaultsMatch = a.matches(b) | ||
| #expect(defaultsMatch) | ||
|
|
||
| // A portrait configuration should match a portrait request | ||
| var portrait = Configuration() | ||
| portrait.orientation = .portrait | ||
| var requestedPortrait = Configuration() | ||
| requestedPortrait.orientation = .portrait | ||
| let portraitMatch = portrait.matches(requestedPortrait) | ||
| #expect(portraitMatch) | ||
|
|
||
| // A portrait configuration should not match a landscape request | ||
| var requestedLandscape = Configuration() | ||
| requestedLandscape.orientation = .landscape | ||
| let landscapeMismatch = portrait.matches(requestedLandscape) | ||
| #expect(!landscapeMismatch) | ||
| } | ||
|
|
||
| @Test func testDiff() throws { | ||
| // Two default configurations should have no differences | ||
| let a = Configuration() | ||
| let b = Configuration() | ||
| let zeroDiff = a.diff(b) | ||
| #expect(zeroDiff == 0) | ||
|
|
||
| // Configurations differing by MCC should produce a non-zero diff | ||
| var c = Configuration() | ||
| c.mobileCountryCode = 310 | ||
| let mccDiff = a.diff(c) | ||
| #expect(mccDiff != 0) | ||
|
|
||
| // Multiple differing fields should each contribute to the diff mask | ||
| var d = Configuration() | ||
| d.orientation = .landscape | ||
| d.uiModeNight = .dark | ||
| let mask = a.diff(d) | ||
| #expect(mask != 0) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why you changed "AndroidAssetManager" to "AndroidFileManager"? I think either is fine, but assets and files aren't really the same thing…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the reason was to make it encompass the AssetManager, StorageManager (ObbFiles) and the Configuration which for some reason is tied to
AssetManager. I feltAndroidFileManagerwas generic enough for those 3 types. We could break it into 3 targets but they all seem related to file management.