# iOS Testing Guide for ProofMode
This guide provides comprehensive testing procedures for the ProofMode iOS integration.
## Pre-Testing Setup
### 1. Build Environment Verification
```bash
# Verify Xcode installation
xcodebuild -version
# Verify iOS simulators available
xcrun simctl list devices
# Verify iOS targets installed
### 2. Build the Framework
```bash
# Run the setup script
./scripts/setup-ios.sh
# Verify XCFramework was created
ls -la target/xcframework/ProofMode.xcframework
# Verify Swift bindings were generated
ls -la bindings/ios/*.swift
```
### 3. Xcode Project Setup
```bash
# Open the project
cd ios-example
open ProofModeExample.xcodeproj
```
## Unit Testing
### Core Library Tests
1. **Initialization Tests**
```swift
func testProofModeInitialization() {
let proofMode = ProofMode()
let expectation = XCTestExpectation(description: "Initialize ProofMode")
Task {
do {
try proofMode.initialize(
storagePath: "/tmp/proofs",
email: "test@example.com",
passphrase: "test123"
)
expectation.fulfill()
} catch {
XCTFail("Initialization failed: \(error)")
}
}
wait(for: [expectation], timeout: 5.0)
}
```
2. **Proof Generation Tests**
```swift
func testProofGeneration() {
// Test with sample image data
let imageData = UIImage(systemName: "photo")!.pngData()!
Task {
let hash = try proofMode.generateProof(
mediaData: imageData,
metadata: ["description": "Test image"]
)
XCTAssertFalse(hash.isEmpty)
XCTAssertEqual(hash.count, 64) // SHA-256 hash length
}
}
```
3. **Proof Verification Tests**
```swift
func testProofVerification() {
// Generate a proof first
let hash = try proofMode.generateProof(mediaData: testImageData, metadata: nil)
// Then verify it
let isValid = try proofMode.verifyProof(hash: hash)
XCTAssertTrue(isValid)
}
```
### Integration Tests
1. **Location Integration**
```swift
func testLocationIntegration() {
let locationProvider = LocationProvider()
// Mock location for testing
let testLocation = CLLocation(
coordinate: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
altitude: 100,
horizontalAccuracy: 5,
verticalAccuracy: 5,
timestamp: Date()
)
locationProvider.currentLocation = testLocation
// Test that location is included in proof
// ... test implementation
}
```
2. **Permission Handling**
```swift
func testPermissionHandling() {
let permissionService = PermissionService()
// Test camera permission
let cameraExpectation = XCTestExpectation(description: "Camera permission")
permissionService.requestCameraPermission { granted in
// Handle permission result
cameraExpectation.fulfill()
}
wait(for: [cameraExpectation], timeout: 10.0)
}
```
## UI Testing
### Simulator Tests
1. **App Launch**
- [ ] App launches without crashing
- [ ] Initial UI loads correctly
- [ ] Tab navigation works
- [ ] No memory leaks on launch
2. **Photo Selection**
- [ ] Camera button shows camera interface (mock in simulator)
- [ ] Photo library button opens photo picker
- [ ] Selected photos display correctly
- [ ] Image orientation handled properly
3. **Proof Generation**
- [ ] Generate button enabled only when image selected
- [ ] Progress indicator shows during generation
- [ ] Success message appears after generation
- [ ] Generated hash displays correctly
- [ ] Proof files created in storage directory
4. **Settings and Permissions**
- [ ] Permission prompts appear when needed
- [ ] Settings toggle correctly
- [ ] App handles denied permissions gracefully
- [ ] Privacy controls work as expected
### Device Tests
1. **Camera Integration**
- [ ] Camera opens and captures photos
- [ ] Flash and camera controls work
- [ ] Different camera modes supported
- [ ] Photos saved to app storage correctly
2. **Location Services**
- [ ] GPS location captured when permitted
- [ ] Location accuracy acceptable
- [ ] Works in different locations
- [ ] Handles location services disabled
3. **Storage and Files**
- [ ] Proof files saved to correct location
- [ ] File permissions set correctly
- [ ] Storage usage reasonable
- [ ] Files persist across app launches
4. **Background Processing**
- [ ] App handles background/foreground transitions
- [ ] Location updates continue in background (if configured)
- [ ] Memory usage acceptable
- [ ] No crashes when suspended/resumed
## Performance Testing
### Memory Tests
```bash
# Use Xcode Instruments to test:
# 1. Launch Instruments
# 2. Select "Leaks" template
# 3. Run your app through typical usage
# 4. Check for memory leaks and excessive usage
```
### CPU Usage Tests
- [ ] Proof generation doesn't block UI
- [ ] Reasonable CPU usage during processing
- [ ] No spinning or frozen UI
- [ ] Efficient use of background queues
### Storage Tests
- [ ] Proof files are reasonable size
- [ ] No excessive temporary files
- [ ] Storage cleanup works correctly
- [ ] Large batches handled efficiently
## Security Testing
### Key Management
- [ ] PGP keys generated securely
- [ ] Private keys stored in Keychain
- [ ] Keys not logged or exposed
- [ ] Key rotation works if implemented
### Data Protection
- [ ] Image data not cached insecurely
- [ ] Location data only stored when permitted
- [ ] Metadata properly sanitized
- [ ] No sensitive data in logs
### Network Security (if applicable)
- [ ] HTTPS used for all network requests
- [ ] Certificate validation working
- [ ] No sensitive data in network logs
- [ ] Proper error handling for network failures
## Compatibility Testing
### iOS Versions
- [ ] iOS 16.0 (minimum supported)
- [ ] iOS 17.0
- [ ] Latest iOS version
- [ ] Beta versions (if available)
### Device Types
- [ ] iPhone (various sizes)
- [ ] iPad (if supported)
- [ ] Different screen resolutions
- [ ] Different performance levels
### Accessibility
- [ ] VoiceOver compatibility
- [ ] Dynamic Type support
- [ ] High Contrast mode
- [ ] Assistive Touch compatibility
## Regression Testing
After any code changes, run through:
1. **Core Functionality**
- [ ] Proof generation still works
- [ ] Verification still works
- [ ] UI remains responsive
- [ ] No new crashes introduced
2. **Integration Points**
- [ ] Camera integration unaffected
- [ ] Location services unaffected
- [ ] File storage unaffected
- [ ] Permission handling unaffected
3. **Performance**
- [ ] No performance regressions
- [ ] Memory usage unchanged
- [ ] Battery usage acceptable
- [ ] App size reasonable
## Automated Testing
### Continuous Integration
Create automated tests that run on every build:
```yaml
# .github/workflows/ios-tests.yml
name: iOS Tests
on: [push, pull_request]
jobs:
ios-tests:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: aarch64-apple-ios
- name: Build iOS Framework
run: ./scripts/setup-ios.sh
- name: Run iOS Tests
run: |
cd ios-example
xcodebuild test \
-project ProofModeExample.xcodeproj \
-scheme ProofModeExample \
-destination 'platform=iOS Simulator,name=iPhone 15'
```
### Test Data Management
- Create test image sets of various formats and sizes
- Include edge cases (very large images, corrupted data)
- Test with different metadata combinations
- Verify handling of empty or invalid inputs
## Debugging Guide
### Common Issues and Solutions
1. **"No such module 'ProofMode'"**
- Check XCFramework is properly embedded
- Verify framework search paths
- Clean build folder and rebuild
2. **Crash on proof generation**
- Check image data validity
- Verify ProofMode initialization
- Review device logs for specific errors
3. **Location not captured**
- Verify location permissions granted
- Check Info.plist usage descriptions
- Test on physical device (simulator has limited location)
4. **Performance issues**
- Profile with Instruments
- Check for main thread blocking
- Optimize image processing pipeline
5. **Memory leaks**
- Use Xcode Memory Debugger
- Check callback retention cycles
- Verify proper cleanup in deinit
### Logging and Diagnostics
```swift
// Enable detailed logging for debugging
#if DEBUG
import os.log
let proofModeLogger = Logger(subsystem: "com.yourapp.proofmode", category: "ProofMode")
// Use throughout your code:
proofModeLogger.info("Starting proof generation for image of size \(imageData.count)")
proofModeLogger.error("Proof generation failed: \(error.localizedDescription)")
#endif
```
## Test Completion Checklist
Before releasing:
- [ ] All unit tests pass
- [ ] All integration tests pass
- [ ] UI testing completed on simulator and device
- [ ] Performance benchmarks meet requirements
- [ ] Security review completed
- [ ] Accessibility testing passed
- [ ] Documentation updated
- [ ] Test coverage > 80%
- [ ] No known critical bugs
- [ ] Beta testing feedback addressed
## Reporting Issues
When reporting issues, include:
1. iOS version and device model
2. App version and build number
3. Steps to reproduce
4. Expected vs actual behavior
5. Console logs and crash reports
6. Screenshots or videos if UI-related
This comprehensive testing approach ensures the ProofMode iOS integration is robust, secure, and provides a great user experience across all supported devices and iOS versions.