feat: 饭卡打印助手 Flutter 版(Phase 1/2:协议服务器 + macOS CUPS 真机打印)
- 协议与 C# 版 card-printer-agent 逐字段对齐(38200-38202 顺延、CORS *、串行任务队列、30 分钟保留) - macOS CUPS 后端:lpoptions 队列发现 + lp 参数列表提交(LC_ALL=C 防本地化粘连坑) - --mock 模拟模式 + bin/agent.dart headless 入口 + 测试卡生成工具 - 真机验收:HiTi CS-200e status 就绪 + 真实出卡;macOS 通用二进制构建通过 - App Sandbox 已关闭(服务需绑回环端口并调用 lp 子进程);zaxprint URL scheme 已注册
This commit is contained in:
commit
689a07ca44
46 files changed
+2986
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:desktop_plugin/print/backend.dart';
|
||||
import 'package:desktop_plugin/print/mock_backend.dart';
|
||||
import 'package:desktop_plugin/server/print_queue.dart';
|
||||
import 'package:desktop_plugin/server/protocol.dart';
|
||||
|
||||
void main() {
|
||||
group('协议 DTO', () {
|
||||
test('PrinterStatus.offline 序列化字段与前端约定对齐', () {
|
||||
final json = PrinterStatus.offline('打印机未连接').toJson();
|
||||
expect(json['online'], false);
|
||||
expect(json['status'], 0x80);
|
||||
expect(json['statusText'], '打印机未连接');
|
||||
expect((json['ribbon'] as Map)['remain'], -1);
|
||||
expect(json['cardLeft'], -1);
|
||||
expect(json['connection'], 'USB');
|
||||
});
|
||||
|
||||
test('PrintRequest.fromJson 解析 front/back/copies', () {
|
||||
final req = PrintRequest.fromJson({
|
||||
'copies': 2,
|
||||
'front': {'color': 'data:image/png;base64,AAA', 'k': 'data:image/png;base64,BBB'},
|
||||
'back': {'color': 'data:image/png;base64,CCC'},
|
||||
});
|
||||
expect(req.copies, 2);
|
||||
expect(req.front!.color, 'data:image/png;base64,AAA');
|
||||
expect(req.front!.k, 'data:image/png;base64,BBB');
|
||||
expect(req.back!.color, 'data:image/png;base64,CCC');
|
||||
});
|
||||
});
|
||||
|
||||
group('打印队列', () {
|
||||
test('缺少 front.color 提交即报错', () {
|
||||
final queue = PrintQueue(MockBackend());
|
||||
expect(
|
||||
() => queue.submit(PrintRequest.fromJson({'copies': 1})),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
|
||||
test('mock 任务串行走完 printing -> done', () async {
|
||||
final queue = PrintQueue(MockBackend());
|
||||
final id = queue.submit(PrintRequest.fromJson({
|
||||
'front': {'color': 'data:image/png;base64,AAA'},
|
||||
}));
|
||||
expect(id, 't1');
|
||||
expect(queue.get(id)!.state, 'printing');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 2700));
|
||||
expect(queue.get(id)!.state, 'done');
|
||||
});
|
||||
});
|
||||
|
||||
test('osBackendName 在 mac 上为 cups', () {
|
||||
expect(osBackendName(), anyOf('cups', 'pavo'));
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user