- Updated LoRa airtime calculations in `lora_airtime_test.dart` to reflect new reference values. - Introduced new tests for LDRO behavior and preamble symbol calculations. - Added `contact_path_width_test.dart` to validate path hash width handling in contacts. - Enhanced `model_changes_test.dart` to ensure legacy data migration works correctly. - Created `remote_node_stats_test.dart` to decode and validate remote node statistics. - Implemented `map_marker_parse_test.dart` for parsing marker text with coordinate validation. - Developed `map_tile_cache_key_test.dart` to ensure API keys are excluded from cache keys. - Added `message_retry_failure_test.dart` to test message retry service behavior on failures. - Extended `path_history_service_test.dart` to preserve learned state across path attempts. - Enhanced `received_image_store_test.dart` to handle concurrent writes and review fixes. - Implemented `repeater_command_service_test.dart` to validate command response handling. - Created `store_tolerant_parsing_test.dart` to ensure stores skip malformed records gracefully. - Cleared untranslated JSON file for localization updates.
122 lines
3.5 KiB
Dart
122 lines
3.5 KiB
Dart
import 'dart:async';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
|
import 'package:meshcore_open/models/contact.dart';
|
|
import 'package:meshcore_open/models/path_selection.dart';
|
|
import 'package:meshcore_open/services/repeater_command_service.dart';
|
|
|
|
class _FakeConnector extends MeshCoreConnector {
|
|
@override
|
|
Future<PathSelection> preparePathForContactSend(Contact contact) async =>
|
|
const PathSelection(pathBytes: [], hopCount: -1, useFlood: true);
|
|
|
|
@override
|
|
Future<void> sendFrame(
|
|
Uint8List data, {
|
|
String? channelSendQueueId,
|
|
bool expectsGenericAck = false,
|
|
bool waitForGenericAck = false,
|
|
}) async {}
|
|
}
|
|
|
|
Contact _repeater(int seed) => Contact(
|
|
publicKey: Uint8List.fromList(List<int>.generate(32, (i) => seed + i)),
|
|
name: 'R$seed',
|
|
type: 2,
|
|
pathLength: -1,
|
|
path: Uint8List(0),
|
|
lastSeen: DateTime.now(),
|
|
);
|
|
|
|
void main() {
|
|
group('normalizeRepeaterClockSyncCommand', () {
|
|
test('translates "clock sync" to explicit time command', () {
|
|
final result = normalizeRepeaterClockSyncCommand(
|
|
'clock sync',
|
|
nowSeconds: 1787900000,
|
|
);
|
|
expect(result, 'time 1787900000');
|
|
});
|
|
|
|
test('is case-insensitive and tolerates surrounding whitespace', () {
|
|
expect(
|
|
normalizeRepeaterClockSyncCommand(' Clock Sync ', nowSeconds: 1),
|
|
'time 1',
|
|
);
|
|
});
|
|
|
|
test('passes other commands through unchanged', () {
|
|
expect(
|
|
normalizeRepeaterClockSyncCommand('clock', nowSeconds: 1),
|
|
'clock',
|
|
);
|
|
expect(
|
|
normalizeRepeaterClockSyncCommand('get radio', nowSeconds: 1),
|
|
'get radio',
|
|
);
|
|
expect(
|
|
normalizeRepeaterClockSyncCommand('time 123', nowSeconds: 1),
|
|
'time 123',
|
|
);
|
|
});
|
|
|
|
test('uses current time when nowSeconds is omitted', () {
|
|
final before = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
final result = normalizeRepeaterClockSyncCommand('clock sync');
|
|
final after = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
|
|
expect(result, startsWith('time '));
|
|
final epoch = int.parse(result.substring('time '.length));
|
|
expect(epoch, inInclusiveRange(before, after));
|
|
});
|
|
});
|
|
|
|
group('RepeaterCommandService.handleResponse', () {
|
|
late RepeaterCommandService service;
|
|
|
|
setUp(() => service = RepeaterCommandService(_FakeConnector()));
|
|
tearDown(() => service.dispose());
|
|
|
|
test('unknown prefix does not complete the pending command', () async {
|
|
final repeater = _repeater(1);
|
|
String? result;
|
|
unawaited(
|
|
service
|
|
.sendCommand(repeater, 'ver', retries: 1)
|
|
.then((r) => result = r, onError: (_) {}),
|
|
);
|
|
await pumpEventQueue();
|
|
|
|
service.handleResponse(repeater, 'FE|late reply');
|
|
await pumpEventQueue();
|
|
expect(result, isNull);
|
|
|
|
service.handleResponse(repeater, '00|v1.0');
|
|
await pumpEventQueue();
|
|
expect(result, 'v1.0');
|
|
});
|
|
|
|
test('prefix owned by another repeater is ignored', () async {
|
|
final a = _repeater(1);
|
|
final b = _repeater(100);
|
|
String? result;
|
|
unawaited(
|
|
service
|
|
.sendCommand(a, 'ver', retries: 1)
|
|
.then((r) => result = r, onError: (_) {}),
|
|
);
|
|
await pumpEventQueue();
|
|
|
|
service.handleResponse(b, '00|wrong');
|
|
await pumpEventQueue();
|
|
expect(result, isNull);
|
|
|
|
service.handleResponse(a, 'unprefixed');
|
|
await pumpEventQueue();
|
|
expect(result, 'unprefixed');
|
|
});
|
|
});
|
|
}
|