Skip to content

Commit daf304a

Browse files
author
LamNguyen176
committed
write tesing AES(#aes-algorithn)
1 parent 24da4a4 commit daf304a

File tree

6 files changed

+63
-29
lines changed

6 files changed

+63
-29
lines changed

.github/workflows/flutter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
- name: Install dependencies
2525
run: flutter pub get
2626

27-
- name: Run tests
28-
run: flutter test
27+
- name: Run tests & generate coverage
28+
run: flutter test --coverage
2929

3030
- name: Upload coverage to Codecov
3131
uses: codecov/codecov-action@v2

coverage/lcov.info

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
SF:lib/flutter_crypto_algorithm.dart
2+
DA:4,1
23
DA:5,1
3-
DA:6,2
4-
LF:2
5-
LH:2
4+
DA:6,1
5+
DA:9,1
6+
DA:10,1
7+
DA:11,1
8+
LF:6
9+
LH:6
610
end_of_record
711
SF:lib/flutter_crypto_algorithm_platform_interface.dart
812
DA:7,6
@@ -13,12 +17,16 @@ DA:21,1
1317
DA:22,2
1418
DA:26,0
1519
DA:27,0
16-
LF:8
20+
DA:30,0
21+
DA:31,0
22+
LF:10
1723
LH:6
1824
end_of_record
1925
SF:lib/flutter_crypto_algorithm_method_channel.dart
2026
DA:12,1
21-
DA:14,2
22-
LF:2
23-
LH:2
27+
DA:15,3
28+
DA:25,1
29+
DA:28,3
30+
LF:4
31+
LH:4
2432
end_of_record

example/integration_test/plugin_integration_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ void main() {
1717

1818
testWidgets('getPlatformVersion test', (WidgetTester tester) async {
1919
final FlutterCryptoAlgorithm plugin = FlutterCryptoAlgorithm();
20-
final String? version = await plugin.getPlatformVersion();
20+
final String? encryptData = await plugin.encrypt('Hello123', 'Hello');
21+
// final String? version = await plugin.getPlatformVersion();
2122
// The version string depends on the host platform running the test, so
2223
// just assert that some non-empty string is returned.
23-
expect(version?.isNotEmpty, true);
24+
expect(encryptData?.isNotEmpty, true);
2425
});
2526
}

example/lib/main.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class _MyAppState extends State<MyApp> {
4343

4444
if (!mounted) return;
4545

46+
print('encrypt: $encrypt');
47+
4648
setState(() {
4749
_encrypt = encrypt;
4850
_decrypt = decrypt;
@@ -72,20 +74,23 @@ class _MyAppState extends State<MyApp> {
7274

7375
Widget _buildText(String label, String value) {
7476
return Text.rich(
75-
overflow: TextOverflow.ellipsis,
76-
maxLines: 2,
77+
overflow: TextOverflow.ellipsis,
78+
maxLines: 2,
79+
TextSpan(
80+
text: label,
81+
style: const TextStyle(
82+
fontSize: 16, fontWeight: FontWeight.bold, color: Colors.red),
83+
children: [
7784
TextSpan(
78-
text: label,
79-
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.red),
80-
children: [
81-
TextSpan(
82-
text: value,
83-
style: const TextStyle(
84-
fontSize: 16, fontWeight: FontWeight.normal, color: Colors.black),
85-
),
86-
],
85+
text: value,
86+
style: const TextStyle(
87+
fontSize: 16,
88+
fontWeight: FontWeight.normal,
89+
color: Colors.black),
8790
),
88-
);
91+
],
92+
),
93+
);
8994
}
9095
}
9196

test/flutter_crypto_algorithm_method_channel_test.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ void main() {
1212
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
1313
channel,
1414
(MethodCall methodCall) async {
15-
return '42';
15+
switch (methodCall.method) {
16+
case 'encrypt':
17+
return 'IVVM1yR+Cn2Bbxo7RnkAQw==';
18+
case 'decrypt':
19+
return 'Hello123';
20+
}
1621
},
1722
);
1823
});
@@ -21,7 +26,11 @@ void main() {
2126
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
2227
});
2328

24-
test('getPlatformVersion', () async {
25-
expect(await platform.getPlatformVersion(), '42');
29+
test('encrypt', () async {
30+
expect(await platform.encrypt('Hello123', 'Hello', null), 'IVVM1yR+Cn2Bbxo7RnkAQw==');
31+
});
32+
33+
test('decrypt', () async {
34+
expect(await platform.decrypt('IVVM1yR+Cn2Bbxo7RnkAQw==', 'Hello', null), 'Hello123');
2635
});
2736
}

test/flutter_crypto_algorithm_test.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ class MockFlutterCryptoAlgorithmPlatform
99
implements FlutterCryptoAlgorithmPlatform {
1010

1111
@override
12-
Future<String?> getPlatformVersion() => Future.value('42');
12+
Future<String?> encrypt(String value, String privateKey, String? ivKey) => Future.value('IVVM1yR+Cn2Bbxo7RnkAQw==');
13+
14+
@override
15+
Future<String?> decrypt(String value, String privateKey, String? ivKey) => Future.value('Hello123');
1316
}
1417

1518
void main() {
@@ -19,11 +22,19 @@ void main() {
1922
expect(initialPlatform, isInstanceOf<MethodChannelFlutterCryptoAlgorithm>());
2023
});
2124

22-
test('getPlatformVersion', () async {
25+
test('encrypt', () async {
26+
FlutterCryptoAlgorithm flutterCryptoAlgorithmPlugin = FlutterCryptoAlgorithm();
27+
MockFlutterCryptoAlgorithmPlatform fakePlatform = MockFlutterCryptoAlgorithmPlatform();
28+
FlutterCryptoAlgorithmPlatform.instance = fakePlatform;
29+
30+
expect(await flutterCryptoAlgorithmPlugin.encrypt('Hello123', 'Hello'), 'IVVM1yR+Cn2Bbxo7RnkAQw==');
31+
});
32+
33+
test('decrypt', () async {
2334
FlutterCryptoAlgorithm flutterCryptoAlgorithmPlugin = FlutterCryptoAlgorithm();
2435
MockFlutterCryptoAlgorithmPlatform fakePlatform = MockFlutterCryptoAlgorithmPlatform();
2536
FlutterCryptoAlgorithmPlatform.instance = fakePlatform;
2637

27-
expect(await flutterCryptoAlgorithmPlugin.getPlatformVersion(), '42');
38+
expect(await flutterCryptoAlgorithmPlugin.decrypt('IVVM1yR+Cn2Bbxo7RnkAQw==', 'Hello'), 'Hello123');
2839
});
2940
}

0 commit comments

Comments
 (0)