Committed by
GitHub
Merge pull request #814 from navaronbracke/reorganise_classes
feat: Unit tests for enhanced enums
Showing
25 changed files
with
562 additions
and
77 deletions
| @@ -82,16 +82,10 @@ class _BarcodeListScannerWithControllerState | @@ -82,16 +82,10 @@ class _BarcodeListScannerWithControllerState | ||
| 82 | children: [ | 82 | children: [ |
| 83 | IconButton( | 83 | IconButton( |
| 84 | color: Colors.white, | 84 | color: Colors.white, |
| 85 | - icon: ValueListenableBuilder( | 85 | + icon: ValueListenableBuilder<TorchState>( |
| 86 | valueListenable: controller.torchState, | 86 | valueListenable: controller.torchState, |
| 87 | builder: (context, state, child) { | 87 | builder: (context, state, child) { |
| 88 | - if (state == null) { | ||
| 89 | - return const Icon( | ||
| 90 | - Icons.flash_off, | ||
| 91 | - color: Colors.grey, | ||
| 92 | - ); | ||
| 93 | - } | ||
| 94 | - switch (state as TorchState) { | 88 | + switch (state) { |
| 95 | case TorchState.off: | 89 | case TorchState.off: |
| 96 | return const Icon( | 90 | return const Icon( |
| 97 | Icons.flash_off, | 91 | Icons.flash_off, |
| @@ -134,13 +128,10 @@ class _BarcodeListScannerWithControllerState | @@ -134,13 +128,10 @@ class _BarcodeListScannerWithControllerState | ||
| 134 | ), | 128 | ), |
| 135 | IconButton( | 129 | IconButton( |
| 136 | color: Colors.white, | 130 | color: Colors.white, |
| 137 | - icon: ValueListenableBuilder( | 131 | + icon: ValueListenableBuilder<CameraFacing>( |
| 138 | valueListenable: controller.cameraFacingState, | 132 | valueListenable: controller.cameraFacingState, |
| 139 | builder: (context, state, child) { | 133 | builder: (context, state, child) { |
| 140 | - if (state == null) { | ||
| 141 | - return const Icon(Icons.camera_front); | ||
| 142 | - } | ||
| 143 | - switch (state as CameraFacing) { | 134 | + switch (state) { |
| 144 | case CameraFacing.front: | 135 | case CameraFacing.front: |
| 145 | return const Icon(Icons.camera_front); | 136 | return const Icon(Icons.camera_front); |
| 146 | case CameraFacing.back: | 137 | case CameraFacing.back: |
| @@ -85,16 +85,10 @@ class _BarcodeScannerWithControllerState | @@ -85,16 +85,10 @@ class _BarcodeScannerWithControllerState | ||
| 85 | } | 85 | } |
| 86 | return IconButton( | 86 | return IconButton( |
| 87 | color: Colors.white, | 87 | color: Colors.white, |
| 88 | - icon: ValueListenableBuilder( | 88 | + icon: ValueListenableBuilder<TorchState>( |
| 89 | valueListenable: controller.torchState, | 89 | valueListenable: controller.torchState, |
| 90 | builder: (context, state, child) { | 90 | builder: (context, state, child) { |
| 91 | - if (state == null) { | ||
| 92 | - return const Icon( | ||
| 93 | - Icons.flash_off, | ||
| 94 | - color: Colors.grey, | ||
| 95 | - ); | ||
| 96 | - } | ||
| 97 | - switch (state as TorchState) { | 91 | + switch (state) { |
| 98 | case TorchState.off: | 92 | case TorchState.off: |
| 99 | return const Icon( | 93 | return const Icon( |
| 100 | Icons.flash_off, | 94 | Icons.flash_off, |
| @@ -140,13 +134,10 @@ class _BarcodeScannerWithControllerState | @@ -140,13 +134,10 @@ class _BarcodeScannerWithControllerState | ||
| 140 | ), | 134 | ), |
| 141 | IconButton( | 135 | IconButton( |
| 142 | color: Colors.white, | 136 | color: Colors.white, |
| 143 | - icon: ValueListenableBuilder( | 137 | + icon: ValueListenableBuilder<CameraFacing>( |
| 144 | valueListenable: controller.cameraFacingState, | 138 | valueListenable: controller.cameraFacingState, |
| 145 | builder: (context, state, child) { | 139 | builder: (context, state, child) { |
| 146 | - if (state == null) { | ||
| 147 | - return const Icon(Icons.camera_front); | ||
| 148 | - } | ||
| 149 | - switch (state as CameraFacing) { | 140 | + switch (state) { |
| 150 | case CameraFacing.front: | 141 | case CameraFacing.front: |
| 151 | return const Icon(Icons.camera_front); | 142 | return const Icon(Icons.camera_front); |
| 152 | case CameraFacing.back: | 143 | case CameraFacing.back: |
| @@ -101,16 +101,10 @@ class _BarcodeScannerReturningImageState | @@ -101,16 +101,10 @@ class _BarcodeScannerReturningImageState | ||
| 101 | children: [ | 101 | children: [ |
| 102 | IconButton( | 102 | IconButton( |
| 103 | color: Colors.white, | 103 | color: Colors.white, |
| 104 | - icon: ValueListenableBuilder( | 104 | + icon: ValueListenableBuilder<TorchState>( |
| 105 | valueListenable: controller.torchState, | 105 | valueListenable: controller.torchState, |
| 106 | builder: (context, state, child) { | 106 | builder: (context, state, child) { |
| 107 | - if (state == null) { | ||
| 108 | - return const Icon( | ||
| 109 | - Icons.flash_off, | ||
| 110 | - color: Colors.grey, | ||
| 111 | - ); | ||
| 112 | - } | ||
| 113 | - switch (state as TorchState) { | 107 | + switch (state) { |
| 114 | case TorchState.off: | 108 | case TorchState.off: |
| 115 | return const Icon( | 109 | return const Icon( |
| 116 | Icons.flash_off, | 110 | Icons.flash_off, |
| @@ -154,13 +148,10 @@ class _BarcodeScannerReturningImageState | @@ -154,13 +148,10 @@ class _BarcodeScannerReturningImageState | ||
| 154 | ), | 148 | ), |
| 155 | IconButton( | 149 | IconButton( |
| 156 | color: Colors.white, | 150 | color: Colors.white, |
| 157 | - icon: ValueListenableBuilder( | 151 | + icon: ValueListenableBuilder<CameraFacing>( |
| 158 | valueListenable: controller.cameraFacingState, | 152 | valueListenable: controller.cameraFacingState, |
| 159 | builder: (context, state, child) { | 153 | builder: (context, state, child) { |
| 160 | - if (state == null) { | ||
| 161 | - return const Icon(Icons.camera_front); | ||
| 162 | - } | ||
| 163 | - switch (state as CameraFacing) { | 154 | + switch (state) { |
| 164 | case CameraFacing.front: | 155 | case CameraFacing.front: |
| 165 | return const Icon(Icons.camera_front); | 156 | return const Icon(Icons.camera_front); |
| 166 | case CameraFacing.back: | 157 | case CameraFacing.back: |
| @@ -65,16 +65,10 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> | @@ -65,16 +65,10 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> | ||
| 65 | children: [ | 65 | children: [ |
| 66 | IconButton( | 66 | IconButton( |
| 67 | color: Colors.white, | 67 | color: Colors.white, |
| 68 | - icon: ValueListenableBuilder( | 68 | + icon: ValueListenableBuilder<TorchState>( |
| 69 | valueListenable: controller.torchState, | 69 | valueListenable: controller.torchState, |
| 70 | builder: (context, state, child) { | 70 | builder: (context, state, child) { |
| 71 | - if (state == null) { | ||
| 72 | - return const Icon( | ||
| 73 | - Icons.flash_off, | ||
| 74 | - color: Colors.grey, | ||
| 75 | - ); | ||
| 76 | - } | ||
| 77 | - switch (state as TorchState) { | 71 | + switch (state) { |
| 78 | case TorchState.off: | 72 | case TorchState.off: |
| 79 | return const Icon( | 73 | return const Icon( |
| 80 | Icons.flash_off, | 74 | Icons.flash_off, |
| @@ -123,13 +117,10 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> | @@ -123,13 +117,10 @@ class _BarcodeScannerWithZoomState extends State<BarcodeScannerWithZoom> | ||
| 123 | ), | 117 | ), |
| 124 | IconButton( | 118 | IconButton( |
| 125 | color: Colors.white, | 119 | color: Colors.white, |
| 126 | - icon: ValueListenableBuilder( | 120 | + icon: ValueListenableBuilder<CameraFacing>( |
| 127 | valueListenable: controller.cameraFacingState, | 121 | valueListenable: controller.cameraFacingState, |
| 128 | builder: (context, state, child) { | 122 | builder: (context, state, child) { |
| 129 | - if (state == null) { | ||
| 130 | - return const Icon(Icons.camera_front); | ||
| 131 | - } | ||
| 132 | - switch (state as CameraFacing) { | 123 | + switch (state) { |
| 133 | case CameraFacing.front: | 124 | case CameraFacing.front: |
| 134 | return const Icon(Icons.camera_front); | 125 | return const Icon(Icons.camera_front); |
| 135 | case CameraFacing.back: | 126 | case CameraFacing.back: |
| @@ -6,7 +6,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev | @@ -6,7 +6,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev | ||
| 6 | version: 0.0.1 | 6 | version: 0.0.1 |
| 7 | 7 | ||
| 8 | environment: | 8 | environment: |
| 9 | - sdk: '>=2.17.0 <4.0.0' | 9 | + sdk: '>=2.18.0 <4.0.0' |
| 10 | 10 | ||
| 11 | # Dependencies specify other packages that your package needs in order to work. | 11 | # Dependencies specify other packages that your package needs in order to work. |
| 12 | # To automatically upgrade your package dependencies to the latest versions | 12 | # To automatically upgrade your package dependencies to the latest versions |
| @@ -13,13 +13,14 @@ enum AddressType { | @@ -13,13 +13,14 @@ enum AddressType { | ||
| 13 | 13 | ||
| 14 | factory AddressType.fromRawValue(int value) { | 14 | factory AddressType.fromRawValue(int value) { |
| 15 | switch (value) { | 15 | switch (value) { |
| 16 | + case 0: | ||
| 17 | + return AddressType.unknown; | ||
| 16 | case 1: | 18 | case 1: |
| 17 | return AddressType.work; | 19 | return AddressType.work; |
| 18 | case 2: | 20 | case 2: |
| 19 | return AddressType.home; | 21 | return AddressType.home; |
| 20 | - case 0: | ||
| 21 | default: | 22 | default: |
| 22 | - return AddressType.unknown; | 23 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); |
| 23 | } | 24 | } |
| 24 | } | 25 | } |
| 25 | 26 |
| @@ -49,6 +49,8 @@ enum BarcodeFormat { | @@ -49,6 +49,8 @@ enum BarcodeFormat { | ||
| 49 | 49 | ||
| 50 | factory BarcodeFormat.fromRawValue(int value) { | 50 | factory BarcodeFormat.fromRawValue(int value) { |
| 51 | switch (value) { | 51 | switch (value) { |
| 52 | + case -1: | ||
| 53 | + return BarcodeFormat.unknown; | ||
| 52 | case 0: | 54 | case 0: |
| 53 | return BarcodeFormat.all; | 55 | return BarcodeFormat.all; |
| 54 | case 1: | 56 | case 1: |
| @@ -77,9 +79,8 @@ enum BarcodeFormat { | @@ -77,9 +79,8 @@ enum BarcodeFormat { | ||
| 77 | return BarcodeFormat.pdf417; | 79 | return BarcodeFormat.pdf417; |
| 78 | case 4096: | 80 | case 4096: |
| 79 | return BarcodeFormat.aztec; | 81 | return BarcodeFormat.aztec; |
| 80 | - case -1: | ||
| 81 | default: | 82 | default: |
| 82 | - return BarcodeFormat.unknown; | 83 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); |
| 83 | } | 84 | } |
| 84 | } | 85 | } |
| 85 | 86 |
| @@ -43,6 +43,8 @@ enum BarcodeType { | @@ -43,6 +43,8 @@ enum BarcodeType { | ||
| 43 | 43 | ||
| 44 | factory BarcodeType.fromRawValue(int value) { | 44 | factory BarcodeType.fromRawValue(int value) { |
| 45 | switch (value) { | 45 | switch (value) { |
| 46 | + case 0: | ||
| 47 | + return BarcodeType.unknown; | ||
| 46 | case 1: | 48 | case 1: |
| 47 | return BarcodeType.contactInfo; | 49 | return BarcodeType.contactInfo; |
| 48 | case 2: | 50 | case 2: |
| @@ -67,9 +69,8 @@ enum BarcodeType { | @@ -67,9 +69,8 @@ enum BarcodeType { | ||
| 67 | return BarcodeType.calendarEvent; | 69 | return BarcodeType.calendarEvent; |
| 68 | case 12: | 70 | case 12: |
| 69 | return BarcodeType.driverLicense; | 71 | return BarcodeType.driverLicense; |
| 70 | - case 0: | ||
| 71 | default: | 72 | default: |
| 72 | - return BarcodeType.unknown; | 73 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); |
| 73 | } | 74 | } |
| 74 | } | 75 | } |
| 75 | 76 |
| @@ -8,6 +8,17 @@ enum CameraFacing { | @@ -8,6 +8,17 @@ enum CameraFacing { | ||
| 8 | 8 | ||
| 9 | const CameraFacing(this.rawValue); | 9 | const CameraFacing(this.rawValue); |
| 10 | 10 | ||
| 11 | + factory CameraFacing.fromRawValue(int value) { | ||
| 12 | + switch (value) { | ||
| 13 | + case 0: | ||
| 14 | + return CameraFacing.front; | ||
| 15 | + case 1: | ||
| 16 | + return CameraFacing.back; | ||
| 17 | + default: | ||
| 18 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 11 | /// The raw value for the camera facing direction. | 22 | /// The raw value for the camera facing direction. |
| 12 | final int rawValue; | 23 | final int rawValue; |
| 13 | } | 24 | } |
| @@ -3,23 +3,34 @@ enum DetectionSpeed { | @@ -3,23 +3,34 @@ enum DetectionSpeed { | ||
| 3 | /// The scanner will only scan a barcode once, and never again until another | 3 | /// The scanner will only scan a barcode once, and never again until another |
| 4 | /// barcode has been scanned. | 4 | /// barcode has been scanned. |
| 5 | /// | 5 | /// |
| 6 | - /// NOTE: This mode does analyze every frame in order to check if the value | ||
| 7 | - /// has changed. | 6 | + /// Bear in mind that this mode analyzes every frame, |
| 7 | + /// in order to check if the value has changed. | ||
| 8 | noDuplicates(0), | 8 | noDuplicates(0), |
| 9 | 9 | ||
| 10 | - /// The barcode scanner will scan one barcode, and wait 250 Miliseconds before | ||
| 11 | - /// scanning again. This will prevent memory issues on older devices. | ||
| 12 | - /// | ||
| 13 | - /// You can change the timeout duration with [detectionTimeout] parameter. | 10 | + /// The barcode scanner will scan barcodes, |
| 11 | + /// while respecting the configured scan timeout between individual scans. | ||
| 14 | normal(1), | 12 | normal(1), |
| 15 | 13 | ||
| 16 | - /// Let the scanner detect barcodes without restriction. | 14 | + /// The barcode scanner will scan barcodes, without any restrictions. |
| 17 | /// | 15 | /// |
| 18 | - /// NOTE: This can cause memory issues with older devices. | 16 | + /// Bear in mind that this mode can cause memory issues on older devices. |
| 19 | unrestricted(2); | 17 | unrestricted(2); |
| 20 | 18 | ||
| 21 | const DetectionSpeed(this.rawValue); | 19 | const DetectionSpeed(this.rawValue); |
| 22 | 20 | ||
| 21 | + factory DetectionSpeed.fromRawValue(int value) { | ||
| 22 | + switch (value) { | ||
| 23 | + case 0: | ||
| 24 | + return DetectionSpeed.noDuplicates; | ||
| 25 | + case 1: | ||
| 26 | + return DetectionSpeed.normal; | ||
| 27 | + case 2: | ||
| 28 | + return DetectionSpeed.unrestricted; | ||
| 29 | + default: | ||
| 30 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); | ||
| 31 | + } | ||
| 32 | + } | ||
| 33 | + | ||
| 23 | /// The raw value for the detection speed. | 34 | /// The raw value for the detection speed. |
| 24 | final int rawValue; | 35 | final int rawValue; |
| 25 | } | 36 | } |
| @@ -13,13 +13,14 @@ enum EmailType { | @@ -13,13 +13,14 @@ enum EmailType { | ||
| 13 | 13 | ||
| 14 | factory EmailType.fromRawValue(int value) { | 14 | factory EmailType.fromRawValue(int value) { |
| 15 | switch (value) { | 15 | switch (value) { |
| 16 | + case 0: | ||
| 17 | + return EmailType.unknown; | ||
| 16 | case 1: | 18 | case 1: |
| 17 | return EmailType.work; | 19 | return EmailType.work; |
| 18 | case 2: | 20 | case 2: |
| 19 | return EmailType.home; | 21 | return EmailType.home; |
| 20 | - case 0: | ||
| 21 | default: | 22 | default: |
| 22 | - return EmailType.unknown; | 23 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); |
| 23 | } | 24 | } |
| 24 | } | 25 | } |
| 25 | 26 |
| @@ -16,15 +16,16 @@ enum EncryptionType { | @@ -16,15 +16,16 @@ enum EncryptionType { | ||
| 16 | 16 | ||
| 17 | factory EncryptionType.fromRawValue(int value) { | 17 | factory EncryptionType.fromRawValue(int value) { |
| 18 | switch (value) { | 18 | switch (value) { |
| 19 | + case 0: | ||
| 20 | + return EncryptionType.none; | ||
| 19 | case 1: | 21 | case 1: |
| 20 | return EncryptionType.open; | 22 | return EncryptionType.open; |
| 21 | case 2: | 23 | case 2: |
| 22 | return EncryptionType.wpa; | 24 | return EncryptionType.wpa; |
| 23 | case 3: | 25 | case 3: |
| 24 | return EncryptionType.wep; | 26 | return EncryptionType.wep; |
| 25 | - case 0: | ||
| 26 | default: | 27 | default: |
| 27 | - return EncryptionType.none; | 28 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); |
| 28 | } | 29 | } |
| 29 | } | 30 | } |
| 30 | 31 |
| @@ -19,6 +19,8 @@ enum PhoneType { | @@ -19,6 +19,8 @@ enum PhoneType { | ||
| 19 | 19 | ||
| 20 | factory PhoneType.fromRawValue(int value) { | 20 | factory PhoneType.fromRawValue(int value) { |
| 21 | switch (value) { | 21 | switch (value) { |
| 22 | + case 0: | ||
| 23 | + return PhoneType.unknown; | ||
| 22 | case 1: | 24 | case 1: |
| 23 | return PhoneType.work; | 25 | return PhoneType.work; |
| 24 | case 2: | 26 | case 2: |
| @@ -27,9 +29,8 @@ enum PhoneType { | @@ -27,9 +29,8 @@ enum PhoneType { | ||
| 27 | return PhoneType.fax; | 29 | return PhoneType.fax; |
| 28 | case 4: | 30 | case 4: |
| 29 | return PhoneType.mobile; | 31 | return PhoneType.mobile; |
| 30 | - case 0: | ||
| 31 | default: | 32 | default: |
| 32 | - return PhoneType.unknown; | 33 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); |
| 33 | } | 34 | } |
| 34 | } | 35 | } |
| 35 | 36 |
| @@ -8,6 +8,17 @@ enum TorchState { | @@ -8,6 +8,17 @@ enum TorchState { | ||
| 8 | 8 | ||
| 9 | const TorchState(this.rawValue); | 9 | const TorchState(this.rawValue); |
| 10 | 10 | ||
| 11 | + factory TorchState.fromRawValue(int value) { | ||
| 12 | + switch (value) { | ||
| 13 | + case 0: | ||
| 14 | + return TorchState.off; | ||
| 15 | + case 1: | ||
| 16 | + return TorchState.on; | ||
| 17 | + default: | ||
| 18 | + throw ArgumentError.value(value, 'value', 'Invalid raw value.'); | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + | ||
| 11 | /// The raw value for the torch state. | 22 | /// The raw value for the torch state. |
| 12 | final int rawValue; | 23 | final int rawValue; |
| 13 | } | 24 | } |
| @@ -49,11 +49,13 @@ class MobileScannerController { | @@ -49,11 +49,13 @@ class MobileScannerController { | ||
| 49 | /// WARNING: DetectionSpeed.unrestricted can cause memory issues on some devices | 49 | /// WARNING: DetectionSpeed.unrestricted can cause memory issues on some devices |
| 50 | final DetectionSpeed detectionSpeed; | 50 | final DetectionSpeed detectionSpeed; |
| 51 | 51 | ||
| 52 | - /// Sets the timeout of scanner. | ||
| 53 | - /// The timeout is set in miliseconds. | 52 | + /// Sets the timeout, in milliseconds, of the scanner. |
| 54 | /// | 53 | /// |
| 55 | - /// NOTE: The timeout only works if the [detectionSpeed] is set to | ||
| 56 | - /// [DetectionSpeed.normal] (which is the default value). | 54 | + /// This timeout is ignored if the [detectionSpeed] |
| 55 | + /// is not set to [DetectionSpeed.normal]. | ||
| 56 | + /// | ||
| 57 | + /// By default this is set to `250` milliseconds, | ||
| 58 | + /// which prevents memory issues on older devices. | ||
| 57 | final int detectionTimeoutMs; | 59 | final int detectionTimeoutMs; |
| 58 | 60 | ||
| 59 | /// Automatically start the mobileScanner on initialization. | 61 | /// Automatically start the mobileScanner on initialization. |
test/enums/address_type_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/address_type.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$AddressType tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, AddressType>{ | ||
| 8 | + 0: AddressType.unknown, | ||
| 9 | + 1: AddressType.work, | ||
| 10 | + 2: AddressType.home, | ||
| 11 | + }; | ||
| 12 | + | ||
| 13 | + for (final MapEntry<int, AddressType> entry in values.entries) { | ||
| 14 | + final AddressType result = AddressType.fromRawValue(entry.key); | ||
| 15 | + | ||
| 16 | + expect(result, entry.value); | ||
| 17 | + } | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + test('invalid raw value throws argument error', () { | ||
| 21 | + const int negative = -1; | ||
| 22 | + const int outOfRange = 3; | ||
| 23 | + | ||
| 24 | + expect(() => AddressType.fromRawValue(negative), throwsArgumentError); | ||
| 25 | + expect(() => AddressType.fromRawValue(outOfRange), throwsArgumentError); | ||
| 26 | + }); | ||
| 27 | + | ||
| 28 | + test('can be converted to raw value', () { | ||
| 29 | + const values = <AddressType, int>{ | ||
| 30 | + AddressType.unknown: 0, | ||
| 31 | + AddressType.work: 1, | ||
| 32 | + AddressType.home: 2, | ||
| 33 | + }; | ||
| 34 | + | ||
| 35 | + for (final MapEntry<AddressType, int> entry in values.entries) { | ||
| 36 | + final int result = entry.key.rawValue; | ||
| 37 | + | ||
| 38 | + expect(result, entry.value); | ||
| 39 | + } | ||
| 40 | + }); | ||
| 41 | + }); | ||
| 42 | +} |
test/enums/barcode_format_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/barcode_format.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$BarcodeFormat tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, BarcodeFormat>{ | ||
| 8 | + -1: BarcodeFormat.unknown, | ||
| 9 | + 0: BarcodeFormat.all, | ||
| 10 | + 1: BarcodeFormat.code128, | ||
| 11 | + 2: BarcodeFormat.code39, | ||
| 12 | + 4: BarcodeFormat.code93, | ||
| 13 | + 8: BarcodeFormat.codebar, | ||
| 14 | + 16: BarcodeFormat.dataMatrix, | ||
| 15 | + 32: BarcodeFormat.ean13, | ||
| 16 | + 64: BarcodeFormat.ean8, | ||
| 17 | + 128: BarcodeFormat.itf, | ||
| 18 | + 256: BarcodeFormat.qrCode, | ||
| 19 | + 512: BarcodeFormat.upcA, | ||
| 20 | + 1024: BarcodeFormat.upcE, | ||
| 21 | + 2048: BarcodeFormat.pdf417, | ||
| 22 | + 4096: BarcodeFormat.aztec, | ||
| 23 | + }; | ||
| 24 | + | ||
| 25 | + for (final MapEntry<int, BarcodeFormat> entry in values.entries) { | ||
| 26 | + final BarcodeFormat result = BarcodeFormat.fromRawValue(entry.key); | ||
| 27 | + | ||
| 28 | + expect(result, entry.value); | ||
| 29 | + } | ||
| 30 | + }); | ||
| 31 | + | ||
| 32 | + test('invalid raw value throws argument error', () { | ||
| 33 | + const int negative = -2; | ||
| 34 | + const int outOfRange = 4097; | ||
| 35 | + | ||
| 36 | + expect(() => BarcodeFormat.fromRawValue(negative), throwsArgumentError); | ||
| 37 | + expect(() => BarcodeFormat.fromRawValue(outOfRange), throwsArgumentError); | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + test('can be converted to raw value', () { | ||
| 41 | + const values = <BarcodeFormat, int>{ | ||
| 42 | + BarcodeFormat.unknown: -1, | ||
| 43 | + BarcodeFormat.all: 0, | ||
| 44 | + BarcodeFormat.code128: 1, | ||
| 45 | + BarcodeFormat.code39: 2, | ||
| 46 | + BarcodeFormat.code93: 4, | ||
| 47 | + BarcodeFormat.codebar: 8, | ||
| 48 | + BarcodeFormat.dataMatrix: 16, | ||
| 49 | + BarcodeFormat.ean13: 32, | ||
| 50 | + BarcodeFormat.ean8: 64, | ||
| 51 | + BarcodeFormat.itf: 128, | ||
| 52 | + BarcodeFormat.qrCode: 256, | ||
| 53 | + BarcodeFormat.upcA: 512, | ||
| 54 | + BarcodeFormat.upcE: 1024, | ||
| 55 | + BarcodeFormat.pdf417: 2048, | ||
| 56 | + BarcodeFormat.aztec: 4096, | ||
| 57 | + }; | ||
| 58 | + | ||
| 59 | + for (final MapEntry<BarcodeFormat, int> entry in values.entries) { | ||
| 60 | + final int result = entry.key.rawValue; | ||
| 61 | + | ||
| 62 | + expect(result, entry.value); | ||
| 63 | + } | ||
| 64 | + }); | ||
| 65 | + }); | ||
| 66 | +} |
test/enums/barcode_type_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/barcode_type.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$BarcodeType tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, BarcodeType>{ | ||
| 8 | + 0: BarcodeType.unknown, | ||
| 9 | + 1: BarcodeType.contactInfo, | ||
| 10 | + 2: BarcodeType.email, | ||
| 11 | + 3: BarcodeType.isbn, | ||
| 12 | + 4: BarcodeType.phone, | ||
| 13 | + 5: BarcodeType.product, | ||
| 14 | + 6: BarcodeType.sms, | ||
| 15 | + 7: BarcodeType.text, | ||
| 16 | + 8: BarcodeType.url, | ||
| 17 | + 9: BarcodeType.wifi, | ||
| 18 | + 10: BarcodeType.geo, | ||
| 19 | + 11: BarcodeType.calendarEvent, | ||
| 20 | + 12: BarcodeType.driverLicense, | ||
| 21 | + }; | ||
| 22 | + | ||
| 23 | + for (final MapEntry<int, BarcodeType> entry in values.entries) { | ||
| 24 | + final BarcodeType result = BarcodeType.fromRawValue(entry.key); | ||
| 25 | + | ||
| 26 | + expect(result, entry.value); | ||
| 27 | + } | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + test('invalid raw value throws argument error', () { | ||
| 31 | + const int negative = -1; | ||
| 32 | + const int outOfRange = 13; | ||
| 33 | + | ||
| 34 | + expect(() => BarcodeType.fromRawValue(negative), throwsArgumentError); | ||
| 35 | + expect(() => BarcodeType.fromRawValue(outOfRange), throwsArgumentError); | ||
| 36 | + }); | ||
| 37 | + | ||
| 38 | + test('can be converted to raw value', () { | ||
| 39 | + const values = <BarcodeType, int>{ | ||
| 40 | + BarcodeType.unknown: 0, | ||
| 41 | + BarcodeType.contactInfo: 1, | ||
| 42 | + BarcodeType.email: 2, | ||
| 43 | + BarcodeType.isbn: 3, | ||
| 44 | + BarcodeType.phone: 4, | ||
| 45 | + BarcodeType.product: 5, | ||
| 46 | + BarcodeType.sms: 6, | ||
| 47 | + BarcodeType.text: 7, | ||
| 48 | + BarcodeType.url: 8, | ||
| 49 | + BarcodeType.wifi: 9, | ||
| 50 | + BarcodeType.geo: 10, | ||
| 51 | + BarcodeType.calendarEvent: 11, | ||
| 52 | + BarcodeType.driverLicense: 12, | ||
| 53 | + }; | ||
| 54 | + | ||
| 55 | + for (final MapEntry<BarcodeType, int> entry in values.entries) { | ||
| 56 | + final int result = entry.key.rawValue; | ||
| 57 | + | ||
| 58 | + expect(result, entry.value); | ||
| 59 | + } | ||
| 60 | + }); | ||
| 61 | + }); | ||
| 62 | +} |
test/enums/camera_facing_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/camera_facing.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$CameraFacing tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, CameraFacing>{ | ||
| 8 | + 0: CameraFacing.front, | ||
| 9 | + 1: CameraFacing.back, | ||
| 10 | + }; | ||
| 11 | + | ||
| 12 | + for (final MapEntry<int, CameraFacing> entry in values.entries) { | ||
| 13 | + final CameraFacing result = CameraFacing.fromRawValue(entry.key); | ||
| 14 | + | ||
| 15 | + expect(result, entry.value); | ||
| 16 | + } | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + test('invalid raw value throws argument error', () { | ||
| 20 | + const int negative = -1; | ||
| 21 | + const int outOfRange = 2; | ||
| 22 | + | ||
| 23 | + expect(() => CameraFacing.fromRawValue(negative), throwsArgumentError); | ||
| 24 | + expect(() => CameraFacing.fromRawValue(outOfRange), throwsArgumentError); | ||
| 25 | + }); | ||
| 26 | + | ||
| 27 | + test('can be converted to raw value', () { | ||
| 28 | + const values = <CameraFacing, int>{ | ||
| 29 | + CameraFacing.front: 0, | ||
| 30 | + CameraFacing.back: 1, | ||
| 31 | + }; | ||
| 32 | + | ||
| 33 | + for (final MapEntry<CameraFacing, int> entry in values.entries) { | ||
| 34 | + final int result = entry.key.rawValue; | ||
| 35 | + | ||
| 36 | + expect(result, entry.value); | ||
| 37 | + } | ||
| 38 | + }); | ||
| 39 | + }); | ||
| 40 | +} |
test/enums/detection_speed_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/detection_speed.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$DetectionSpeed tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, DetectionSpeed>{ | ||
| 8 | + 0: DetectionSpeed.noDuplicates, | ||
| 9 | + 1: DetectionSpeed.normal, | ||
| 10 | + 2: DetectionSpeed.unrestricted, | ||
| 11 | + }; | ||
| 12 | + | ||
| 13 | + for (final MapEntry<int, DetectionSpeed> entry in values.entries) { | ||
| 14 | + final DetectionSpeed result = DetectionSpeed.fromRawValue(entry.key); | ||
| 15 | + | ||
| 16 | + expect(result, entry.value); | ||
| 17 | + } | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + test('invalid raw value throws argument error', () { | ||
| 21 | + const int negative = -1; | ||
| 22 | + const int outOfRange = 3; | ||
| 23 | + | ||
| 24 | + expect(() => DetectionSpeed.fromRawValue(negative), throwsArgumentError); | ||
| 25 | + expect( | ||
| 26 | + () => DetectionSpeed.fromRawValue(outOfRange), | ||
| 27 | + throwsArgumentError, | ||
| 28 | + ); | ||
| 29 | + }); | ||
| 30 | + | ||
| 31 | + test('can be converted to raw value', () { | ||
| 32 | + const values = <DetectionSpeed, int>{ | ||
| 33 | + DetectionSpeed.noDuplicates: 0, | ||
| 34 | + DetectionSpeed.normal: 1, | ||
| 35 | + DetectionSpeed.unrestricted: 2, | ||
| 36 | + }; | ||
| 37 | + | ||
| 38 | + for (final MapEntry<DetectionSpeed, int> entry in values.entries) { | ||
| 39 | + final int result = entry.key.rawValue; | ||
| 40 | + | ||
| 41 | + expect(result, entry.value); | ||
| 42 | + } | ||
| 43 | + }); | ||
| 44 | + }); | ||
| 45 | +} |
test/enums/email_type_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/email_type.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$EmailType tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, EmailType>{ | ||
| 8 | + 0: EmailType.unknown, | ||
| 9 | + 1: EmailType.work, | ||
| 10 | + 2: EmailType.home, | ||
| 11 | + }; | ||
| 12 | + | ||
| 13 | + for (final MapEntry<int, EmailType> entry in values.entries) { | ||
| 14 | + final EmailType result = EmailType.fromRawValue(entry.key); | ||
| 15 | + | ||
| 16 | + expect(result, entry.value); | ||
| 17 | + } | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + test('invalid raw value throws argument error', () { | ||
| 21 | + const int negative = -1; | ||
| 22 | + const int outOfRange = 3; | ||
| 23 | + | ||
| 24 | + expect(() => EmailType.fromRawValue(negative), throwsArgumentError); | ||
| 25 | + expect(() => EmailType.fromRawValue(outOfRange), throwsArgumentError); | ||
| 26 | + }); | ||
| 27 | + | ||
| 28 | + test('can be converted to raw value', () { | ||
| 29 | + const values = <EmailType, int>{ | ||
| 30 | + EmailType.unknown: 0, | ||
| 31 | + EmailType.work: 1, | ||
| 32 | + EmailType.home: 2, | ||
| 33 | + }; | ||
| 34 | + | ||
| 35 | + for (final MapEntry<EmailType, int> entry in values.entries) { | ||
| 36 | + final int result = entry.key.rawValue; | ||
| 37 | + | ||
| 38 | + expect(result, entry.value); | ||
| 39 | + } | ||
| 40 | + }); | ||
| 41 | + }); | ||
| 42 | +} |
test/enums/encryption_type_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/encryption_type.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$EncryptionType tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, EncryptionType>{ | ||
| 8 | + 0: EncryptionType.none, | ||
| 9 | + 1: EncryptionType.open, | ||
| 10 | + 2: EncryptionType.wpa, | ||
| 11 | + 3: EncryptionType.wep, | ||
| 12 | + }; | ||
| 13 | + | ||
| 14 | + for (final MapEntry<int, EncryptionType> entry in values.entries) { | ||
| 15 | + final EncryptionType result = EncryptionType.fromRawValue(entry.key); | ||
| 16 | + | ||
| 17 | + expect(result, entry.value); | ||
| 18 | + } | ||
| 19 | + }); | ||
| 20 | + | ||
| 21 | + test('invalid raw value throws argument error', () { | ||
| 22 | + const int negative = -1; | ||
| 23 | + const int outOfRange = 4; | ||
| 24 | + | ||
| 25 | + expect(() => EncryptionType.fromRawValue(negative), throwsArgumentError); | ||
| 26 | + expect( | ||
| 27 | + () => EncryptionType.fromRawValue(outOfRange), | ||
| 28 | + throwsArgumentError, | ||
| 29 | + ); | ||
| 30 | + }); | ||
| 31 | + | ||
| 32 | + test('can be converted to raw value', () { | ||
| 33 | + const values = <EncryptionType, int>{ | ||
| 34 | + EncryptionType.none: 0, | ||
| 35 | + EncryptionType.open: 1, | ||
| 36 | + EncryptionType.wpa: 2, | ||
| 37 | + EncryptionType.wep: 3, | ||
| 38 | + }; | ||
| 39 | + | ||
| 40 | + for (final MapEntry<EncryptionType, int> entry in values.entries) { | ||
| 41 | + final int result = entry.key.rawValue; | ||
| 42 | + | ||
| 43 | + expect(result, entry.value); | ||
| 44 | + } | ||
| 45 | + }); | ||
| 46 | + }); | ||
| 47 | +} |
test/enums/mobile_scanner_state_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/mobile_scanner_state.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$MobileScannerState tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = { | ||
| 8 | + 0: MobileScannerState.undetermined, | ||
| 9 | + 1: MobileScannerState.authorized, | ||
| 10 | + 2: MobileScannerState.denied, | ||
| 11 | + }; | ||
| 12 | + | ||
| 13 | + for (final MapEntry<int, MobileScannerState> entry in values.entries) { | ||
| 14 | + final MobileScannerState result = MobileScannerState.fromRawValue( | ||
| 15 | + entry.key, | ||
| 16 | + ); | ||
| 17 | + | ||
| 18 | + expect(result, entry.value); | ||
| 19 | + } | ||
| 20 | + }); | ||
| 21 | + | ||
| 22 | + test('invalid raw value throws argument error', () { | ||
| 23 | + const int negative = -1; | ||
| 24 | + const int outOfRange = 3; | ||
| 25 | + | ||
| 26 | + expect( | ||
| 27 | + () => MobileScannerState.fromRawValue(negative), | ||
| 28 | + throwsArgumentError, | ||
| 29 | + ); | ||
| 30 | + expect( | ||
| 31 | + () => MobileScannerState.fromRawValue(outOfRange), | ||
| 32 | + throwsArgumentError, | ||
| 33 | + ); | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | + test('can be converted to raw value', () { | ||
| 37 | + const values = <MobileScannerState, int>{ | ||
| 38 | + MobileScannerState.undetermined: 0, | ||
| 39 | + MobileScannerState.authorized: 1, | ||
| 40 | + MobileScannerState.denied: 2, | ||
| 41 | + }; | ||
| 42 | + | ||
| 43 | + for (final MapEntry<MobileScannerState, int> entry in values.entries) { | ||
| 44 | + final int result = entry.key.rawValue; | ||
| 45 | + | ||
| 46 | + expect(result, entry.value); | ||
| 47 | + } | ||
| 48 | + }); | ||
| 49 | + }); | ||
| 50 | +} |
test/enums/phone_type_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/phone_type.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$PhoneType tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, PhoneType>{ | ||
| 8 | + 0: PhoneType.unknown, | ||
| 9 | + 1: PhoneType.work, | ||
| 10 | + 2: PhoneType.home, | ||
| 11 | + 3: PhoneType.fax, | ||
| 12 | + 4: PhoneType.mobile, | ||
| 13 | + }; | ||
| 14 | + | ||
| 15 | + for (final MapEntry<int, PhoneType> entry in values.entries) { | ||
| 16 | + final PhoneType result = PhoneType.fromRawValue(entry.key); | ||
| 17 | + | ||
| 18 | + expect(result, entry.value); | ||
| 19 | + } | ||
| 20 | + }); | ||
| 21 | + | ||
| 22 | + test('invalid raw value throws argument error', () { | ||
| 23 | + const int negative = -1; | ||
| 24 | + const int outOfRange = 5; | ||
| 25 | + | ||
| 26 | + expect(() => PhoneType.fromRawValue(negative), throwsArgumentError); | ||
| 27 | + expect(() => PhoneType.fromRawValue(outOfRange), throwsArgumentError); | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + test('can be converted to raw value', () { | ||
| 31 | + const values = <PhoneType, int>{ | ||
| 32 | + PhoneType.unknown: 0, | ||
| 33 | + PhoneType.work: 1, | ||
| 34 | + PhoneType.home: 2, | ||
| 35 | + PhoneType.fax: 3, | ||
| 36 | + PhoneType.mobile: 4, | ||
| 37 | + }; | ||
| 38 | + | ||
| 39 | + for (final MapEntry<PhoneType, int> entry in values.entries) { | ||
| 40 | + final int result = entry.key.rawValue; | ||
| 41 | + | ||
| 42 | + expect(result, entry.value); | ||
| 43 | + } | ||
| 44 | + }); | ||
| 45 | + }); | ||
| 46 | +} |
test/enums/torch_state_test.dart
0 → 100644
| 1 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 2 | +import 'package:mobile_scanner/src/enums/torch_state.dart'; | ||
| 3 | + | ||
| 4 | +void main() { | ||
| 5 | + group('$TorchState tests', () { | ||
| 6 | + test('can be created from raw value', () { | ||
| 7 | + const values = <int, TorchState>{ | ||
| 8 | + 0: TorchState.off, | ||
| 9 | + 1: TorchState.on, | ||
| 10 | + }; | ||
| 11 | + | ||
| 12 | + for (final MapEntry<int, TorchState> entry in values.entries) { | ||
| 13 | + final TorchState result = TorchState.fromRawValue(entry.key); | ||
| 14 | + | ||
| 15 | + expect(result, entry.value); | ||
| 16 | + } | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + test('invalid raw value throws argument error', () { | ||
| 20 | + const int negative = -1; | ||
| 21 | + const int outOfRange = 2; | ||
| 22 | + | ||
| 23 | + expect(() => TorchState.fromRawValue(negative), throwsArgumentError); | ||
| 24 | + expect(() => TorchState.fromRawValue(outOfRange), throwsArgumentError); | ||
| 25 | + }); | ||
| 26 | + | ||
| 27 | + test('can be converted to raw value', () { | ||
| 28 | + const values = <TorchState, int>{ | ||
| 29 | + TorchState.off: 0, | ||
| 30 | + TorchState.on: 1, | ||
| 31 | + }; | ||
| 32 | + | ||
| 33 | + for (final MapEntry<TorchState, int> entry in values.entries) { | ||
| 34 | + final int result = entry.key.rawValue; | ||
| 35 | + | ||
| 36 | + expect(result, entry.value); | ||
| 37 | + } | ||
| 38 | + }); | ||
| 39 | + }); | ||
| 40 | +} |
-
Please register or login to post a comment