Refactor LoRa airtime tests and add new functionality
- 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.
This commit is contained in:
1 parent
d5f54dfa11
commit
d74587c167
105 files changed
+6419
-2072
No files matched your search
@@ -6,7 +6,7 @@ import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
void main() {
|
||||
// Frame layout per the doc comment on buildUpdateContactPathFrame:
|
||||
// [cmd][pub_key x32][type][flags][path_len][path x64][name x32]
|
||||
// [timestamp x4][Lat? x4, Lon? x4][timestamp? x4]
|
||||
// [last_advert x4][Lat? x4, Lon? x4][lastmod? x4]
|
||||
//
|
||||
// Base (mandatory) bytes:
|
||||
// 1 cmd + 32 pubKey + 1 type + 1 flags + 1 pathLen + 64 path
|
||||
@@ -101,5 +101,77 @@ void main() {
|
||||
expect(latBytes.getInt32(0, Endian.little), (49.123456 * 1e6).round());
|
||||
expect(lonBytes.getInt32(0, Endian.little), (-123.123456 * 1e6).round());
|
||||
});
|
||||
|
||||
int lastAdvertField(Uint8List frame) => ByteData.sublistView(
|
||||
frame,
|
||||
baseFrameLength - 4,
|
||||
baseFrameLength,
|
||||
).getUint32(0, Endian.little);
|
||||
|
||||
test('writes the contact advert timestamp, not the phone clock', () {
|
||||
final advert = DateTime.utc(2025, 6, 1, 12);
|
||||
final frame = buildUpdateContactPathFrame(
|
||||
pubKey,
|
||||
path,
|
||||
path.length,
|
||||
lastAdvert: advert,
|
||||
lastModified: DateTime.utc(2026, 1, 2),
|
||||
);
|
||||
|
||||
expect(lastAdvertField(frame), advert.millisecondsSinceEpoch ~/ 1000);
|
||||
expect(
|
||||
ByteData.sublistView(
|
||||
frame,
|
||||
baseFrameLength + 8,
|
||||
).getUint32(0, Endian.little),
|
||||
DateTime.utc(2026, 1, 2).millisecondsSinceEpoch ~/ 1000,
|
||||
);
|
||||
});
|
||||
|
||||
test('writes 0 for last advert when unknown', () {
|
||||
final frame = buildUpdateContactPathFrame(pubKey, path, path.length);
|
||||
expect(lastAdvertField(frame), 0);
|
||||
});
|
||||
});
|
||||
|
||||
group('auto-add / repeat freq frames', () {
|
||||
test('SET_AUTOADD_CONFIG appends max hops only when given', () {
|
||||
final withoutHops = buildSetAutoAddConfigFrame(
|
||||
autoAddChat: true,
|
||||
autoAddRepeater: false,
|
||||
autoAddRoomServer: false,
|
||||
autoAddSensor: false,
|
||||
overwriteOldest: true,
|
||||
);
|
||||
expect(withoutHops, [
|
||||
cmdSetAutoAddConfig,
|
||||
autoAddChatFlag | autoAddOverwriteOldestFlag,
|
||||
]);
|
||||
|
||||
final withHops = buildSetAutoAddConfigFrame(
|
||||
autoAddChat: false,
|
||||
autoAddRepeater: false,
|
||||
autoAddRoomServer: false,
|
||||
autoAddSensor: false,
|
||||
overwriteOldest: false,
|
||||
maxHops: 3,
|
||||
);
|
||||
expect(withHops, [cmdSetAutoAddConfig, 0, 3]);
|
||||
});
|
||||
|
||||
test('parses RESP_ALLOWED_REPEAT_FREQ ranges', () {
|
||||
final data = ByteData(1 + 16);
|
||||
data.setUint8(0, respCodeAllowedRepeatFreq);
|
||||
data.setUint32(1, 433000, Endian.little);
|
||||
data.setUint32(5, 433000, Endian.little);
|
||||
data.setUint32(9, 869495, Endian.little);
|
||||
data.setUint32(13, 869600, Endian.little);
|
||||
final ranges = parseAllowedRepeatFreqFrame(data.buffer.asUint8List());
|
||||
expect(ranges, [
|
||||
(lowKHz: 433000, highKHz: 433000),
|
||||
(lowKHz: 869495, highKHz: 869600),
|
||||
]);
|
||||
expect(buildGetAllowedRepeatFreqFrame(), [cmdGetAllowedRepeatFreq]);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
Uint8List _contactFrame(int code, Uint8List key, String name) {
|
||||
final data = ByteData(1 + 32 + 3 + 64 + 32 + 4 + 12);
|
||||
final bytes = data.buffer.asUint8List();
|
||||
bytes[0] = code;
|
||||
bytes.setRange(1, 33, key);
|
||||
bytes[33] = advTypeChat;
|
||||
bytes[35] = 0xFF; // path unknown
|
||||
bytes.setRange(100, 100 + name.length, name.codeUnits);
|
||||
data.setUint32(132, 1700000000, Endian.little);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
});
|
||||
|
||||
final key = Uint8List.fromList(List<int>.generate(32, (i) => i + 1));
|
||||
|
||||
test('NEW_ADVERT is discovered only, not a firmware contact', () {
|
||||
final connector = MeshCoreConnector();
|
||||
connector.handleFrameForTest(_contactFrame(pushCodeNewAdvert, key, 'Bob'));
|
||||
|
||||
expect(connector.contacts, isEmpty);
|
||||
expect(connector.discoveredContacts.map((c) => c.name), contains('Bob'));
|
||||
});
|
||||
|
||||
test('CONTACT_DELETED removes the firmware contact', () {
|
||||
final connector = MeshCoreConnector();
|
||||
connector.handleFrameForTest(_contactFrame(respCodeContact, key, 'Bob'));
|
||||
expect(connector.contacts.length, 1);
|
||||
|
||||
connector.handleFrameForTest([pushCodeContactDeleted, ...key]);
|
||||
expect(connector.contacts, isEmpty);
|
||||
});
|
||||
|
||||
test('CONTACTS_FULL raises the storage-full signal', () async {
|
||||
final connector = MeshCoreConnector();
|
||||
final events = connector.contactsFullEvents.first;
|
||||
connector.handleFrameForTest([pushCodeContactsFull]);
|
||||
|
||||
expect(connector.contactsStorageFull, isTrue);
|
||||
await events;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import 'package:meshcore_open/connector/pending_command_replies.dart';
|
||||
|
||||
void main() {
|
||||
Uint8List frame(List<int> bytes) => Uint8List.fromList(bytes);
|
||||
final keyA = Uint8List.fromList(List<int>.generate(32, (i) => i + 1));
|
||||
final keyB = Uint8List.fromList(List<int>.generate(32, (i) => i + 100));
|
||||
|
||||
PendingCommandReplies newQueue() =>
|
||||
PendingCommandReplies(staleAfter: const Duration(seconds: 10));
|
||||
|
||||
test('ERR goes to the oldest pending command (firmware order)', () {
|
||||
final queue = newQueue();
|
||||
final time = queue.track(buildSetDeviceTimeFrame(1));
|
||||
queue.track(buildSetAdvertNameFrame('x'));
|
||||
|
||||
final failed = queue.takeErr(6);
|
||||
expect(failed, same(time));
|
||||
expect(queue.takeOk()?.commandCode, cmdSetAdvertName);
|
||||
expect(queue.length, 0);
|
||||
});
|
||||
|
||||
test('OK skips commands whose success is a specific RESP_CODE', () {
|
||||
final queue = newQueue();
|
||||
queue.track(buildSendTextMsgFrame(keyA, 'hi'));
|
||||
queue.track(buildRemoveContactFrame(keyA));
|
||||
|
||||
expect(queue.takeOk()?.commandCode, cmdRemoveContact);
|
||||
expect(queue.completeReply(frame([respCodeSent, 0, 0, 0, 0, 0])), isTrue);
|
||||
expect(queue.length, 0);
|
||||
});
|
||||
|
||||
test('specific replies clear their entry so a later ERR is not misread', () {
|
||||
final queue = newQueue();
|
||||
queue.track(buildGetChannelFrame(0));
|
||||
queue.track(buildSetChannelFrame(1, 'c', Uint8List(16)));
|
||||
|
||||
expect(queue.completeReply(frame([respCodeChannelInfo, 0])), isTrue);
|
||||
expect(queue.takeErr(2)?.commandCode, cmdSetChannel);
|
||||
});
|
||||
|
||||
test('CONTACT only completes GET_CONTACT_BY_KEY for the same key', () {
|
||||
final queue = newQueue();
|
||||
queue.track(buildGetContactByKeyFrame(keyA));
|
||||
|
||||
expect(queue.completeReply(frame([respCodeContact, ...keyB])), isFalse);
|
||||
expect(queue.completeReply(frame([respCodeContact, ...keyA])), isTrue);
|
||||
expect(queue.length, 0);
|
||||
});
|
||||
|
||||
test('untracked commands are not enrolled', () {
|
||||
final queue = newQueue();
|
||||
expect(queue.track(buildSyncNextMessageFrame()), isNull);
|
||||
expect(queue.track(buildRebootFrame()), isNull);
|
||||
expect(queue.takeErr(1), isNull);
|
||||
});
|
||||
|
||||
test('awaited command completes with error on ERR', () async {
|
||||
final queue = newQueue();
|
||||
final pending = queue.track(
|
||||
buildSetRadioParamsFrame(869525, 250000, 11, 5),
|
||||
waitForReply: true,
|
||||
);
|
||||
queue.takeErr(6);
|
||||
await expectLater(pending!.completer!.future, throwsException);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user