From c72aeb7f587b7d03092ce90e90b8000400998775 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 5 Dec 2024 10:53:42 -0500 Subject: [PATCH] Add Aaru parameters tests --- CHANGELIST.md | 1 + MPF.ExecutionContexts.Test/AaruTests.cs | 418 +++++++++++++++++- MPF.ExecutionContexts/Aaru/CommandStrings.cs | 35 +- .../Aaru/ExecutionContext.cs | 35 +- MPF.ExecutionContexts/Aaru/FlagStrings.cs | 21 +- 5 files changed, 484 insertions(+), 26 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 8c1afc97..62718278 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -34,6 +34,7 @@ - Fix some formatting issues with Input types - Replace Aaru pre-command flags - Use string builders where possible +- Add Aaru parameters tests ### 3.2.4 (2024-11-24) diff --git a/MPF.ExecutionContexts.Test/AaruTests.cs b/MPF.ExecutionContexts.Test/AaruTests.cs index acd4bf6b..0a41046a 100644 --- a/MPF.ExecutionContexts.Test/AaruTests.cs +++ b/MPF.ExecutionContexts.Test/AaruTests.cs @@ -26,9 +26,406 @@ namespace MPF.ExecutionContexts.Test #endregion - /// - /// Ensure pre-command flags can all be set properly - /// + #region Archive Family + + [Theory] + [InlineData("arc info filename.bin")] + [InlineData("arc info \"filename.bin\"")] + [InlineData("archive info filename.bin")] + [InlineData("archive info \"filename.bin\"")] + public void ArchiveInfoTest(string parameters) + { + string? expected = "archive info \"filename.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + #endregion + + #region Database Family + + [Theory] + [InlineData("db stats")] + [InlineData("database stats")] + public void DatabaseStatsTest(string parameters) + { + string? expected = "database stats"; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("db update --clear --clear-all")] + [InlineData("db update --clear true --clear-all true")] + [InlineData("database update --clear --clear-all")] + [InlineData("database update --clear true --clear-all true")] + public void DatabaseUpdateTest(string parameters) + { + string? expected = "database update --clear True --clear-all True"; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + #endregion + + #region Device Family + + [Theory] + [InlineData("dev info -w prefix filename.bin")] + [InlineData("dev info --output-prefix prefix filename.bin")] + [InlineData("device info -w prefix filename.bin")] + [InlineData("device info --output-prefix prefix filename.bin")] + public void DeviceInfoTest(string parameters) + { + string? expected = "device info --output-prefix \"prefix\" filename.bin"; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("dev list localhost")] + [InlineData("device list localhost")] + public void DeviceListTest(string parameters) + { + string? expected = "device list \"localhost\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("dev report -t filename.bin")] + [InlineData("dev report -t true filename.bin")] + [InlineData("dev report --trap-disc filename.bin")] + [InlineData("dev report --trap-disc true filename.bin")] + [InlineData("device report -t filename.bin")] + [InlineData("device report -t true filename.bin")] + [InlineData("device report --trap-disc filename.bin")] + [InlineData("device report --trap-disc true filename.bin")] + public void DeviceReportTest(string parameters) + { + string? expected = "device report --trap-disc True filename.bin"; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + #endregion + + #region Filesystem Family + + [Theory] + [InlineData("fi extract -e enc -x -n ns -O opts input output")] + [InlineData("fi extract -e enc -x true -n ns -O opts input output")] + [InlineData("fi extract --encoding enc --xattrs --namespace ns --options opts input output")] + [InlineData("fi extract --encoding enc --xattrs true --namespace ns --options opts input output")] + [InlineData("fs extract -e enc -x -n ns -O opts input output")] + [InlineData("fs extract -e enc -x true -n ns -O opts input output")] + [InlineData("fs extract --encoding enc --xattrs --namespace ns --options opts input output")] + [InlineData("fs extract --encoding enc --xattrs true --namespace ns --options opts input output")] + [InlineData("filesystem extract -e enc -x -n ns -O opts input output")] + [InlineData("filesystem extract -e enc -x true -n ns -O opts input output")] + [InlineData("filesystem extract --encoding enc --xattrs --namespace ns --options opts input output")] + [InlineData("filesystem extract --encoding enc --xattrs true --namespace ns --options opts input output")] + public void FilesystemExtractTest(string parameters) + { + string? expected = "filesystem extract --xattrs True --encoding \"enc\" --namespace \"ns\" --options \"opts\" \"input\" \"output\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("fi info -e enc -x -n ns -O opts input")] + [InlineData("fi info -e enc -x true -n ns -O opts input")] + [InlineData("fi info --encoding enc --xattrs --namespace ns --options opts input")] + [InlineData("fi info --encoding enc --xattrs true --namespace ns --options opts input")] + [InlineData("fs info -e enc -x -n ns -O opts input")] + [InlineData("fs info -e enc -x true -n ns -O opts input")] + [InlineData("fs info --encoding enc --xattrs --namespace ns --options opts input")] + [InlineData("fs info --encoding enc --xattrs true --namespace ns --options opts input")] + [InlineData("filesystem info -e enc -x -n ns -O opts input")] + [InlineData("filesystem info -e enc -x true -n ns -O opts input")] + [InlineData("filesystem info --encoding enc --xattrs --namespace ns --options opts input")] + [InlineData("filesystem info --encoding enc --xattrs true --namespace ns --options opts input")] + public void FilesystemInfoTest(string parameters) + { + string? expected = "filesystem info --xattrs True --encoding \"enc\" --namespace \"ns\" --options \"opts\" \"input\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("fi ls -e enc -f -l -p input")] + [InlineData("fi list -e enc -f -l -p input")] + [InlineData("fi ls -e enc -f true -l true -p true input")] + [InlineData("fi list -e enc -f true -l true -p true input")] + [InlineData("fi ls --encoding enc --filesystems --long-format --partitions input")] + [InlineData("fi list --encoding enc --filesystems --long-format --partitions input")] + [InlineData("fi ls --encoding enc --filesystems true --long-format true --partitions true input")] + [InlineData("fi list --encoding enc --filesystems true --long-format true --partitions true input")] + [InlineData("fs ls -e enc -f -l -p input")] + [InlineData("fs list -e enc -f -l -p input")] + [InlineData("fs ls -e enc -f true -l true -p true input")] + [InlineData("fs list -e enc -f true -l true -p true input")] + [InlineData("fs ls --encoding enc --filesystems --long-format --partitions input")] + [InlineData("fs list --encoding enc --filesystems --long-format --partitions input")] + [InlineData("fs ls --encoding enc --filesystems true --long-format true --partitions true input")] + [InlineData("fs list --encoding enc --filesystems true --long-format true --partitions true input")] + [InlineData("filesystem ls -e enc -f -l -p input")] + [InlineData("filesystem list -e enc -f -l -p input")] + [InlineData("filesystem ls -e enc -f true -l true -p true input")] + [InlineData("filesystem list -e enc -f true -l true -p true input")] + [InlineData("filesystem ls --encoding enc --filesystems --long-format --partitions input")] + [InlineData("filesystem list --encoding enc --filesystems --long-format --partitions input")] + [InlineData("filesystem ls --encoding enc --filesystems true --long-format true --partitions true input")] + [InlineData("filesystem list --encoding enc --filesystems true --long-format true --partitions true input")] + public void FilesystemListTest(string parameters) + { + string? expected = "filesystem list --filesystems True --long-format True --partitions True --encoding \"enc\" \"input\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("fi options")] + [InlineData("fs options")] + [InlineData("filesystem options")] + public void FilesystemOptionsTest(string parameters) + { + string? expected = "filesystem options"; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + #endregion + + #region Image Family + + [Theory] + [InlineData("i chk -a --crc16 -c --crc64 --fletcher16 --fletcher32 -m -t -s --sha256 --sha384 --sha512 -f -w filename.bin")] + [InlineData("i chk -a true --crc16 true -c true --crc64 true --fletcher16 true --fletcher32 true -m true -t true -s true --sha256 true --sha384 true --sha512 true -f true -w true filename.bin")] + [InlineData("i chk --adler32 --crc16 --crc32 --crc64 --fletcher16 --fletcher32 --md5 --separated-tracks --sha1 --sha256 --sha384 --sha512 --spamsum --whole-disc filename.bin")] + [InlineData("i chk --adler32 true --crc16 true --crc32 true --crc64 true --fletcher16 true --fletcher32 true --md5 true --separated-tracks true --sha1 true --sha256 true --sha384 true --sha512 true --spamsum true --whole-disc true filename.bin")] + [InlineData("i checksum -a --crc16 -c --crc64 --fletcher16 --fletcher32 -m -t -s --sha256 --sha384 --sha512 -f -w filename.bin")] + [InlineData("i checksum -a true --crc16 true -c true --crc64 true --fletcher16 true --fletcher32 true -m true -t true -s true --sha256 true --sha384 true --sha512 true -f true -w true filename.bin")] + [InlineData("i checksum --adler32 --crc16 --crc32 --crc64 --fletcher16 --fletcher32 --md5 --separated-tracks --sha1 --sha256 --sha384 --sha512 --spamsum --whole-disc filename.bin")] + [InlineData("i checksum --adler32 true --crc16 true --crc32 true --crc64 true --fletcher16 true --fletcher32 true --md5 true --separated-tracks true --sha1 true --sha256 true --sha384 true --sha512 true --spamsum true --whole-disc true filename.bin")] + [InlineData("image chk -a --crc16 -c --crc64 --fletcher16 --fletcher32 -m -t -s --sha256 --sha384 --sha512 -f -w filename.bin")] + [InlineData("image chk -a true --crc16 true -c true --crc64 true --fletcher16 true --fletcher32 true -m true -t true -s true --sha256 true --sha384 true --sha512 true -f true -w true filename.bin")] + [InlineData("image chk --adler32 --crc16 --crc32 --crc64 --fletcher16 --fletcher32 --md5 --separated-tracks --sha1 --sha256 --sha384 --sha512 --spamsum --whole-disc filename.bin")] + [InlineData("image chk --adler32 true --crc16 true --crc32 true --crc64 true --fletcher16 true --fletcher32 true --md5 true --separated-tracks true --sha1 true --sha256 true --sha384 true --sha512 true --spamsum true --whole-disc true filename.bin")] + [InlineData("image checksum -a --crc16 -c --crc64 --fletcher16 --fletcher32 -m -t -s --sha256 --sha384 --sha512 -f -w filename.bin")] + [InlineData("image checksum -a true --crc16 true -c true --crc64 true --fletcher16 true --fletcher32 true -m true -t true -s true --sha256 true --sha384 true --sha512 true -f true -w true filename.bin")] + [InlineData("image checksum --adler32 --crc16 --crc32 --crc64 --fletcher16 --fletcher32 --md5 --separated-tracks --sha1 --sha256 --sha384 --sha512 --spamsum --whole-disc filename.bin")] + [InlineData("image checksum --adler32 true --crc16 true --crc32 true --crc64 true --fletcher16 true --fletcher32 true --md5 true --separated-tracks true --sha1 true --sha256 true --sha384 true --sha512 true --spamsum true --whole-disc true filename.bin")] + public void ImageChecksumTest(string parameters) + { + string? expected = "image checksum --adler32 True --crc16 True --crc32 True --crc64 True --fletcher16 True --fletcher32 True --md5 True --separated-tracks True --sha1 True --sha256 True --sha384 True --sha512 True --spamsum True --whole-disc True \"filename.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i cmp input1.bin input2.bin")] + [InlineData("i compare input1.bin input2.bin")] + [InlineData("image cmp input1.bin input2.bin")] + [InlineData("image compare input1.bin input2.bin")] + public void ImageCompareTest(string parameters) + { + string? expected = "image compare \"input1.bin\" \"input2.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i convert --comments co -c 0 --creator cr --drive-manufacturer dm --drive-model dm --drive-revision dr --drive-serial ds --fix-subchannel --fix-subchannel-crc --fix-subchannel-position -f -p fmt --generate-subchannels -g geo --media-barcode mb --media-lastsequence 0 --media-manufacturer mm --media-model mm --media-partnumber mpn --media-sequence 0 --media-serial ms --media-title mt -O opt -r resume -x cicm input1.bin input2.bin")] + [InlineData("i convert --comments co -c 0 --creator cr --drive-manufacturer dm --drive-model dm --drive-revision dr --drive-serial ds --fix-subchannel true --fix-subchannel-crc true --fix-subchannel-position true -f true -p fmt --generate-subchannels true -g geo --media-barcode mb --media-lastsequence 0 --media-manufacturer mm --media-model mm --media-partnumber mpn --media-sequence 0 --media-serial ms --media-title mt -O opt -r resume -x cicm input1.bin input2.bin")] + [InlineData("i convert --comments co --count 0 --creator cr --drive-manufacturer dm --drive-model dm --drive-revision dr --drive-serial ds --fix-subchannel --fix-subchannel-crc --fix-subchannel-position --force --format fmt --generate-subchannels --geometry geo --media-barcode mb --media-lastsequence 0 --media-manufacturer mm --media-model mm --media-partnumber mpn --media-sequence 0 --media-serial ms --media-title mt --options opt --resume-file resume --cicm-xml cicm input1.bin input2.bin")] + [InlineData("i convert --comments co --count 0 --creator cr --drive-manufacturer dm --drive-model dm --drive-revision dr --drive-serial ds --fix-subchannel true --fix-subchannel-crc true --fix-subchannel-position true --force true --format fmt --generate-subchannels true --geometry geo --media-barcode mb --media-lastsequence 0 --media-manufacturer mm --media-model mm --media-partnumber mpn --media-sequence 0 --media-serial ms --media-title mt --options opt --resume-file resume --cicm-xml cicm input1.bin input2.bin")] + [InlineData("image convert --comments co -c 0 --creator cr --drive-manufacturer dm --drive-model dm --drive-revision dr --drive-serial ds --fix-subchannel --fix-subchannel-crc --fix-subchannel-position -f -p fmt --generate-subchannels -g geo --media-barcode mb --media-lastsequence 0 --media-manufacturer mm --media-model mm --media-partnumber mpn --media-sequence 0 --media-serial ms --media-title mt -O opt -r resume -x cicm input1.bin input2.bin")] + [InlineData("image convert --comments co -c 0 --creator cr --drive-manufacturer dm --drive-model dm --drive-revision dr --drive-serial ds --fix-subchannel true --fix-subchannel-crc true --fix-subchannel-position true -f true -p fmt --generate-subchannels true -g geo --media-barcode mb --media-lastsequence 0 --media-manufacturer mm --media-model mm --media-partnumber mpn --media-sequence 0 --media-serial ms --media-title mt -O opt -r resume -x cicm input1.bin input2.bin")] + [InlineData("image convert --comments co --count 0 --creator cr --drive-manufacturer dm --drive-model dm --drive-revision dr --drive-serial ds --fix-subchannel --fix-subchannel-crc --fix-subchannel-position --force --format fmt --generate-subchannels --geometry geo --media-barcode mb --media-lastsequence 0 --media-manufacturer mm --media-model mm --media-partnumber mpn --media-sequence 0 --media-serial ms --media-title mt --options opt --resume-file resume --cicm-xml cicm input1.bin input2.bin")] + [InlineData("image convert --comments co --count 0 --creator cr --drive-manufacturer dm --drive-model dm --drive-revision dr --drive-serial ds --fix-subchannel true --fix-subchannel-crc true --fix-subchannel-position true --force true --format fmt --generate-subchannels true --geometry geo --media-barcode mb --media-lastsequence 0 --media-manufacturer mm --media-model mm --media-partnumber mpn --media-sequence 0 --media-serial ms --media-title mt --options opt --resume-file resume --cicm-xml cicm input1.bin input2.bin")] + public void ImageConvertTest(string parameters) + { + string? expected = "image convert --fix-subchannel True --fix-subchannel-crc True --fix-subchannel-position True --force True --generate-subchannels True --count 0 --media-lastsequence 0 --media-sequence 0 --comments \"co\" --creator \"cr\" --drive-manufacturer \"dm\" --drive-model \"dm\" --drive-revision \"dr\" --drive-serial \"ds\" --format \"fmt\" --geometry \"geo\" --media-barcode \"mb\" --media-manufacturer \"mm\" --media-model \"mm\" --media-partnumber \"mpn\" --media-serial \"ms\" --media-title \"mt\" --options \"opt\" --resume-file \"resume\" --cicm-xml \"cicm\" \"input1.bin\" \"input2.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i create-sidecar -b 0 -e enc -t filename.bin")] + [InlineData("i create-sidecar -b 0 -e enc -t true filename.bin")] + [InlineData("i create-sidecar --block-size 0 --encoding enc --tape filename.bin")] + [InlineData("i create-sidecar --block-size 0 --encoding enc --tape true filename.bin")] + [InlineData("image create-sidecar -b 0 -e enc -t filename.bin")] + [InlineData("image create-sidecar -b 0 -e enc -t true filename.bin")] + [InlineData("image create-sidecar --block-size 0 --encoding enc --tape filename.bin")] + [InlineData("image create-sidecar --block-size 0 --encoding enc --tape true filename.bin")] + public void ImageCreateSidecarTest(string parameters) + { + string? expected = "image create-sidecar --tape True --block-size 0 --encoding \"enc\" \"filename.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i decode -f -l all -p -s 0 filename.bin")] + [InlineData("i decode -f true -l all -p true -s 0 filename.bin")] + [InlineData("i decode --disk-tags --length all --sector-tags --start 0 filename.bin")] + [InlineData("i decode --disk-tags true --length all --sector-tags true --start 0 filename.bin")] + [InlineData("image decode -f -l all -p -s 0 filename.bin")] + [InlineData("image decode -f true -l all -p true -s 0 filename.bin")] + [InlineData("image decode --disk-tags --length all --sector-tags --start 0 filename.bin")] + [InlineData("image decode --disk-tags true --length all --sector-tags true --start 0 filename.bin")] + public void ImageDecodeTest(string parameters) + { + string? expected = "image decode --disk-tags True --sector-tags True --length all --start 0 \"filename.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i entropy -p -t -w filename.bin")] + [InlineData("i entropy -p true -t true -w true filename.bin")] + [InlineData("i entropy --duplicated-sectors --separated-tracks --whole-disc filename.bin")] + [InlineData("i entropy --duplicated-sectors true --separated-tracks true --whole-disc true filename.bin")] + [InlineData("image entropy -p -t -w filename.bin")] + [InlineData("image entropy -p true -t true -w true filename.bin")] + [InlineData("image entropy --duplicated-sectors --separated-tracks --whole-disc filename.bin")] + [InlineData("image entropy --duplicated-sectors true --separated-tracks true --whole-disc true filename.bin")] + public void ImageEntropyTest(string parameters) + { + string? expected = "image entropy --duplicated-sectors True --separated-tracks True --whole-disc True \"filename.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i info filename.bin")] + [InlineData("image info filename.bin")] + public void ImageInfoTest(string parameters) + { + string? expected = "image info \"filename.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i options")] + [InlineData("image options")] + public void ImageOptionsTest(string parameters) + { + string? expected = "image options"; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i print -l 0 -r -s 0 -w 0 filename.bin")] + [InlineData("i print -l 0 -r true -s 0 -w 0 filename.bin")] + [InlineData("i print --length 0 --long-sectors --start 0 --width 0 filename.bin")] + [InlineData("i print --length 0 --long-sectors true --start 0 --width 0 filename.bin")] + [InlineData("image print -l 0 -r -s 0 -w 0 filename.bin")] + [InlineData("image print -l 0 -r true -s 0 -w 0 filename.bin")] + [InlineData("image print --length 0 --long-sectors --start 0 --width 0 filename.bin")] + [InlineData("image print --length 0 --long-sectors true --start 0 --width 0 filename.bin")] + public void ImagePrintTest(string parameters) + { + string? expected = "image print --long-sectors True --width 0 --length 0 --start 0 \"filename.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("i verify -w -s filename.bin")] + [InlineData("i verify -w true -s true filename.bin")] + [InlineData("i verify --verify-disc --verify-sectors filename.bin")] + [InlineData("i verify --verify-disc true --verify-sectors true filename.bin")] + [InlineData("image verify -w -s filename.bin")] + [InlineData("image verify -w true -s true filename.bin")] + [InlineData("image verify --verify-disc --verify-sectors filename.bin")] + [InlineData("image verify --verify-disc true --verify-sectors true filename.bin")] + public void ImageVerifyTest(string parameters) + { + string? expected = "image verify --verify-disc True --verify-sectors True \"filename.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + #endregion + + #region Media Family + + [Theory] + [InlineData("m dump --eject -e enc --first-pregap --fix-offset --fix-subchannel --fix-subchannel-crc --fix-subchannel-position -f --generate-subchannels --max-blocks 0 --metadata -O opt --persistent --private -r -p 0 --retry-subchannel -k 0 --skip-cdiready-hole --speed 0 -s --store-encrypted --subchannel any --title-keys --trim --use-buffered-reads -x cicm input output.bin")] + [InlineData("m dump --eject true -e enc --first-pregap true --fix-offset true --fix-subchannel true --fix-subchannel-crc true --fix-subchannel-position true -f true --generate-subchannels true --max-blocks 0 --metadata true -O opt --persistent true --private true -r true -p 0 --retry-subchannel true -k 0 --skip-cdiready-hole true --speed 0 -s true --store-encrypted true --subchannel any --title-keys true --trim true --use-buffered-reads true -x cicm input output.bin")] + [InlineData("m dump --eject --encoding enc --first-pregap --fix-offset --fix-subchannel --fix-subchannel-crc --fix-subchannel-position --force --generate-subchannels --max-blocks 0 --metadata --options opt --persistent --private --resume --retry-passes 0 --retry-subchannel --skip 0 --skip-cdiready-hole --speed 0 --stop-on-error --store-encrypted --subchannel any --title-keys --trim --use-buffered-reads --cicm-xml cicm input output.bin")] + [InlineData("m dump --eject true --encoding enc --first-pregap true --fix-offset true --fix-subchannel true --fix-subchannel-crc true --fix-subchannel-position true --force true --generate-subchannels true --max-blocks 0 --metadata true --options opt --persistent true --private true --resume true --retry-passes 0 --retry-subchannel true --skip 0 --skip-cdiready-hole true --speed 0 --stop-on-error true --store-encrypted true --subchannel any --title-keys true --trim true --use-buffered-reads true --cicm-xml cicm input output.bin")] + [InlineData("media dump --eject -e enc --first-pregap --fix-offset --fix-subchannel --fix-subchannel-crc --fix-subchannel-position -f --generate-subchannels --max-blocks 0 --metadata -O opt --persistent --private -r -p 0 --retry-subchannel -k 0 --skip-cdiready-hole --speed 0 -s --store-encrypted --subchannel any --title-keys --trim --use-buffered-reads -x cicm input output.bin")] + [InlineData("media dump --eject true -e enc --first-pregap true --fix-offset true --fix-subchannel true --fix-subchannel-crc true --fix-subchannel-position true -f true --generate-subchannels true --max-blocks 0 --metadata true -O opt --persistent true --private true -r true -p 0 --retry-subchannel true -k 0 --skip-cdiready-hole true --speed 0 -s true --store-encrypted true --subchannel any --title-keys true --trim true --use-buffered-reads true -x cicm input output.bin")] + [InlineData("media dump --eject --encoding enc --first-pregap --fix-offset --fix-subchannel --fix-subchannel-crc --fix-subchannel-position --force --generate-subchannels --max-blocks 0 --metadata --options opt --persistent --private --resume --retry-passes 0 --retry-subchannel --skip 0 --skip-cdiready-hole --speed 0 --stop-on-error --store-encrypted --subchannel any --title-keys --trim --use-buffered-reads --cicm-xml cicm input output.bin")] + [InlineData("media dump --eject true --encoding enc --first-pregap true --fix-offset true --fix-subchannel true --fix-subchannel-crc true --fix-subchannel-position true --force true --generate-subchannels true --max-blocks 0 --metadata true --options opt --persistent true --private true --resume true --retry-passes 0 --retry-subchannel true --skip 0 --skip-cdiready-hole true --speed 0 --stop-on-error true --store-encrypted true --subchannel any --title-keys true --trim true --use-buffered-reads true --cicm-xml cicm input output.bin")] + public void MediaDumpTest(string parameters) + { + string? expected = "media dump --eject True --first-pregap True --fix-offset True --fix-subchannel True --fix-subchannel-crc True --fix-subchannel-position True --force True --generate-subchannels True --metadata True --persistent True --private True --resume True --retry-subchannel True --skip-cdiready-hole True --stop-on-error True --store-encrypted True --title-keys True --trim True --use-buffered-reads True --speed 0 --retry-passes 0 --max-blocks 0 --skip 0 --encoding \"enc\" --options \"opt\" --subchannel \"any\" --cicm-xml \"cicm\" input \"output.bin\""; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("m info -w prefix input")] + [InlineData("m info --output-prefix prefix input")] + [InlineData("media info -w prefix input")] + [InlineData("media info --output-prefix prefix input")] + public void MediaInfoTest(string parameters) + { + string? expected = "media info --output-prefix \"prefix\" input"; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("m scan -b ibg -m mhdd --use-buffered-reads input")] + [InlineData("m scan -b ibg -m mhdd --use-buffered-reads true input")] + [InlineData("m scan --ibg-log ibg --mhdd-log mhdd --use-buffered-reads input")] + [InlineData("m scan --ibg-log ibg --mhdd-log mhdd --use-buffered-reads true input")] + [InlineData("media scan -b ibg -m mhdd --use-buffered-reads input")] + [InlineData("media scan -b ibg -m mhdd --use-buffered-reads true input")] + [InlineData("media scan --ibg-log ibg --mhdd-log mhdd --use-buffered-reads input")] + [InlineData("media scan --ibg-log ibg --mhdd-log mhdd --use-buffered-reads true input")] + public void MediaScanTest(string parameters) + { + string? expected = "media scan --use-buffered-reads True --ibg-log \"ibg\" --mhdd-log \"mhdd\" input"; + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + #endregion + + #region Standalone Commands + [Theory] [InlineData("--debug --help --verbose --version formats")] [InlineData("--debug true --help true --verbose true --version true formats")] @@ -39,5 +436,20 @@ namespace MPF.ExecutionContexts.Test string? actual = context.GenerateParameters(); Assert.Equal(expected, actual); } + + [Theory] + [InlineData("configure", "configure")] + [InlineData("formats", "formats")] + [InlineData("list-encodings", "list-encodings")] + [InlineData("list-namespaces", "list-namespaces")] + [InlineData("remote localhost", "remote \"localhost\"")] + public void StandaloneCommandsTest(string parameters, string? expected) + { + var context = new ExecutionContext(parameters); + string? actual = context.GenerateParameters(); + Assert.Equal(expected, actual); + } + + #endregion } } \ No newline at end of file diff --git a/MPF.ExecutionContexts/Aaru/CommandStrings.cs b/MPF.ExecutionContexts/Aaru/CommandStrings.cs index 4b10e3fb..0a234f1b 100644 --- a/MPF.ExecutionContexts/Aaru/CommandStrings.cs +++ b/MPF.ExecutionContexts/Aaru/CommandStrings.cs @@ -7,25 +7,35 @@ namespace MPF.ExecutionContexts.Aaru { public const string NONE = ""; - // Archive Family + #region Archive Family + public const string ArchivePrefixShort = "arc"; public const string ArchivePrefixLong = "archive"; public const string ArchiveInfo = "info"; - // Database Family + #endregion + + #region Database Family + public const string DatabasePrefixShort = "db"; public const string DatabasePrefixLong = "database"; public const string DatabaseStats = "stats"; public const string DatabaseUpdate = "update"; - // Device Family + #endregion + + #region Device Family + public const string DevicePrefixShort = "dev"; public const string DevicePrefixLong = "device"; public const string DeviceInfo = "info"; public const string DeviceList = "list"; public const string DeviceReport = "report"; - // Filesystem Family + #endregion + + #region Filesystem Family + public const string FilesystemPrefixShort = "fi"; public const string FilesystemPrefixShortAlt = "fs"; public const string FilesystemPrefixLong = "filesystem"; @@ -35,7 +45,10 @@ namespace MPF.ExecutionContexts.Aaru public const string FilesystemListLong = "list"; public const string FilesystemOptions = "options"; - // Image Family + #endregion + + #region Image Family + public const string ImagePrefixShort = "i"; public const string ImagePrefixLong = "image"; public const string ImageChecksumShort = "chk"; @@ -51,18 +64,26 @@ namespace MPF.ExecutionContexts.Aaru public const string ImagePrint = "print"; public const string ImageVerify = "verify"; - // Media Family + #endregion + + #region Media Family + public const string MediaPrefixShort = "m"; public const string MediaPrefixLong = "media"; public const string MediaDump = "dump"; public const string MediaInfo = "info"; public const string MediaScan = "scan"; - // Standalone Commands + #endregion + + #region Standalone Commands + public const string Configure = "configure"; public const string Formats = "formats"; public const string ListEncodings = "list-encodings"; public const string ListNamespaces = "list-namespaces"; public const string Remote = "remote"; + + #endregion } } \ No newline at end of file diff --git a/MPF.ExecutionContexts/Aaru/ExecutionContext.cs b/MPF.ExecutionContexts/Aaru/ExecutionContext.cs index fbd66c3b..72770f62 100644 --- a/MPF.ExecutionContexts/Aaru/ExecutionContext.cs +++ b/MPF.ExecutionContexts/Aaru/ExecutionContext.cs @@ -981,7 +981,7 @@ namespace MPF.ExecutionContexts.Aaru { if (LengthValue >= 0) parameters.Append($"{FlagStrings.LengthLong} {LengthValue} "); - else if (LengthValue == -1 && BaseCommand == CommandStrings.ImageDecode) + else if (LengthValue == -1 && BaseCommand == CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageDecode) parameters.Append($"{FlagStrings.LengthLong} all "); } } @@ -1198,7 +1198,7 @@ namespace MPF.ExecutionContexts.Aaru if (InputValue!.Contains(" ")) parameters.Append($"\"{InputValue!.TrimEnd('\\')}\" "); else - parameters.Append(InputValue!.TrimEnd('\\')); + parameters.Append($"{InputValue!.TrimEnd('\\')} "); break; @@ -1226,7 +1226,7 @@ namespace MPF.ExecutionContexts.Aaru if (string.IsNullOrEmpty(InputValue) || string.IsNullOrEmpty(OutputValue)) return null; - parameters.Append(InputValue!.TrimEnd('\\')); + parameters.Append($"{InputValue!.TrimEnd('\\')} "); parameters.Append($"\"{OutputValue}\" "); break; @@ -1429,6 +1429,7 @@ namespace MPF.ExecutionContexts.Aaru // Keep a count of keys to determine if we should break out to command handling or not int keyCount = Keys.Count; + // Match all possible flags foreach (var kvp in _preCommandInputs) { // If the value was not a match @@ -1690,9 +1691,7 @@ namespace MPF.ExecutionContexts.Aaru // Start -- Required value longValue = ProcessInt64Parameter(parts, FlagStrings.StartShort, FlagStrings.StartLong, ref i); - if (longValue == null) - return false; - else if (longValue != long.MinValue) + if (longValue != long.MinValue) StartValue = longValue; #endregion @@ -2055,6 +2054,27 @@ namespace MPF.ExecutionContexts.Aaru break; + case CommandStrings.Configure: + family = null; + command = CommandStrings.Configure; + break; + case CommandStrings.Formats: + family = null; + command = CommandStrings.Formats; + break; + case CommandStrings.ListEncodings: + family = null; + command = CommandStrings.ListEncodings; + break; + case CommandStrings.ListNamespaces: + family = null; + command = CommandStrings.ListNamespaces; + break; + case CommandStrings.Remote: + family = null; + command = CommandStrings.Remote; + break; + default: family = null; command = null; @@ -2062,7 +2082,7 @@ namespace MPF.ExecutionContexts.Aaru } } - // For standalone commands + // For standalone commands with no second input else { family = null; @@ -2072,7 +2092,6 @@ namespace MPF.ExecutionContexts.Aaru CommandStrings.Formats => CommandStrings.Formats, CommandStrings.ListEncodings => CommandStrings.ListEncodings, CommandStrings.ListNamespaces => CommandStrings.ListNamespaces, - CommandStrings.Remote => CommandStrings.Remote, _ => null, }; } diff --git a/MPF.ExecutionContexts/Aaru/FlagStrings.cs b/MPF.ExecutionContexts/Aaru/FlagStrings.cs index 0c27447d..e7d9a61b 100644 --- a/MPF.ExecutionContexts/Aaru/FlagStrings.cs +++ b/MPF.ExecutionContexts/Aaru/FlagStrings.cs @@ -5,6 +5,19 @@ namespace MPF.ExecutionContexts.Aaru /// public static class FlagStrings { + #region Precommand Flags + + public const string DebugShort = "-d"; + public const string DebugLong = "--debug"; + public const string HelpShort = "-h"; + public const string HelpShortAlt = "-?"; + public const string HelpLong = "--help"; + public const string VerboseShort = "-v"; + public const string VerboseLong = "--verbose"; + public const string VersionLong = "--version"; + + #endregion + #region Boolean flags public const string Adler32Short = "-a"; @@ -15,8 +28,6 @@ namespace MPF.ExecutionContexts.Aaru public const string CRC32Short = "-c"; public const string CRC32Long = "--crc32"; public const string CRC64Long = "--crc64"; - public const string DebugShort = "-d"; - public const string DebugLong = "--debug"; public const string DiskTagsShort = "-f"; public const string DiskTagsLong = "--disk-tags"; public const string DuplicatedSectorsShort = "-p"; @@ -36,9 +47,6 @@ namespace MPF.ExecutionContexts.Aaru public const string ForceShort = "-f"; public const string ForceLong = "--force"; public const string GenerateSubchannelsLong = "--generate-subchannels"; - public const string HelpShort = "-h"; - public const string HelpShortAlt = "-?"; - public const string HelpLong = "--help"; public const string LongFormatShort = "-l"; public const string LongFormatLong = "--long-format"; public const string LongSectorsShort = "-r"; @@ -76,13 +84,10 @@ namespace MPF.ExecutionContexts.Aaru public const string TrapDiscLong = "--trap-disc"; public const string TrimLong = "--trim"; public const string UseBufferedReadsLong = "--use-buffered-reads"; - public const string VerboseShort = "-v"; - public const string VerboseLong = "--verbose"; public const string VerifyDiscShort = "-w"; public const string VerifyDiscLong = "--verify-disc"; public const string VerifySectorsShort = "-s"; public const string VerifySectorsLong = "--verify-sectors"; - public const string VersionLong = "--version"; public const string WholeDiscShort = "-w"; public const string WholeDiscLong = "--whole-disc";