52 lines
1.7 KiB
Dart
52 lines
1.7 KiB
Dart
|
|
import '../lib/utils/protocol_helper.dart';
|
|
|
|
// Simulated environment for verification
|
|
class MockDatabase {
|
|
final List<Map<String, dynamic>> savedFragments = [];
|
|
Future<void> saveFragment(String phone, String msgId, int index, int total, String body) async {
|
|
savedFragments.add({
|
|
'phone': phone,
|
|
'msgId': msgId,
|
|
'index': index,
|
|
'total': total,
|
|
'body': body,
|
|
});
|
|
print(' [MockDB] Saved fragment $index/$total for $msgId');
|
|
}
|
|
}
|
|
|
|
void main() async {
|
|
print('Verifying Background Message Handling Logic...');
|
|
|
|
final mockDb = MockDatabase();
|
|
final phone = '09123456789';
|
|
|
|
// Test Case 1: Standard Symmetric Message
|
|
print('\nCase 1: Standard Symmetric Message');
|
|
final body1 = '@S:SYM|h1:payload';
|
|
final parsed1 = ProtocolHelper.parseMessage(body1);
|
|
assert(parsed1['type'] == 'sym');
|
|
assert(parsed1['payload'] == 'h1:payload');
|
|
print('✅ Logic: Show "Secure Message Received" notification');
|
|
|
|
// Test Case 2: Fragment Message
|
|
print('\nCase 2: Fragment Message');
|
|
final body2 = '@S:SFRA|msg123|1|3|chunk1';
|
|
final parsed2 = ProtocolHelper.parseMessage(body2);
|
|
assert(parsed2['type'] == 'sfra');
|
|
|
|
// Real logic would be: if (type == 'sfra') { await db.saveFragment(...) }
|
|
if (parsed2['type'] == 'sfra') {
|
|
await mockDb.saveFragment(
|
|
phone, parsed2['packetId'], parsed2['partNo'], parsed2['totalParts'], parsed2['chunk']);
|
|
}
|
|
|
|
assert(mockDb.savedFragments.length == 1);
|
|
assert(mockDb.savedFragments[0]['msgId'] == 'msg123');
|
|
assert(mockDb.savedFragments[0]['index'] == 1);
|
|
print('✅ Logic: Save fragment to DB and show "Receiving part 1/3" notification');
|
|
|
|
print('\nAll background logic checks passed! 🚀');
|
|
}
|