Automated testing infrastructure for ImageWriter application.
ImageWriter.exe ΡΠ΅ΠΏΠ΅ΡΡ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ Worker Mode!
Starting from this version, ImageWriter.exe includes command-line argument support through Worker Mode (previously only in ImageWriterPro.exe):
# Worker Mode syntax
ImageWriter.exe --worker --pipe <name> --operation <0|1|2> --device <path> --file <path> [options]
# Parameters:
# --operation: 0=Read, 1=Write, 2=Verify
# --device: Device path (e.g., E:\ or \\.\PhysicalDrive2)
# --file: Image file path (.img, .gz, .zip)
# --bs: Block size (default: 512)
# --count: Number of blocks
# --checksize: Verify device size
# --verifyhash: Calculate MD5 hash
# --persistent: Run as persistent daemonKey Feature: ImageWriter automatically creates .gz and .zip archives based on file extension - no external compression tools needed!
run_tests.ps1 - Basic smoke tests (~0.15 seconds, safe)
.\run_tests.ps1 -JsonOutput -Verbose
# Run with archive format tests (2-3 min)
.\run_tests.ps1 -ArchiveTests -Verbose
# Run with partition detection tests (< 1 min)
.\run_tests.ps1 -PartitionTests -Verbose
# Run all extended tests
.\run_tests.ps1 -AllTests -Verbose- Detects USB devices via WMI
- Verifies fixed disk protection
- Checks ZLib library availability
- NEW: Archive format testing (GZIP, ZIP, XZ, BZIP2, 7z, TAR.GZ, TAR.XZ)
- NEW: Partition table detection (MBR/GPT from images and archives)
- Results:
test-results.json
Test-ArchiveFormats.ps1 - Comprehensive archive format testing
.\Test-ArchiveFormats.ps1 -Verbose
# Skip write tests (recognition only)
.\Test-ArchiveFormats.ps1 -SkipWriteTests- Tests all 7 supported archive formats
- Phase 1: Device β Archive (Read tests)
- GZIP (.img.gz)
- ZIP (.zip)
- XZ (.img.xz)
- BZIP2 (.img.bz2)
- 7-Zip (.7z)
- TAR.GZ (.tar.gz)
- TAR.XZ (.tar.xz)
- Phase 2: Archive β Device (Recognition tests, non-destructive)
- Verifies magic bytes for each format
- ImageWriter creates all archives
- Results:
test-data/archives/directory
Test-PartitionInfo.ps1 - Partition detection testing
# Create test images and run tests
.\Test-PartitionInfo.ps1 -CreateTestImages -Verbose
# Use existing test images
.\Test-PartitionInfo.ps1 -Verbose- Creates test MBR and GPT disk images
- Tests partition detection from raw images
- Tests partition detection from archives (GZIP, ZIP)
- Verifies MBR signature (0x55AA)
- Verifies GPT signature ("EFI PART")
- Validates partition table parsing
- Results:
test-data/partition-tests/directory - Features:
- MBR test image: 2 partitions (NTFS bootable + FAT32)
- GPT test image: 2 partitions (EFI System + Microsoft Basic Data)
- Archive compression: GZIP and ZIP formats
- Full partition structure verification
IntegrationTests.ps1 - GUI automation tests (2-3 min, safe)
.\IntegrationTests.ps1- Launches real ImageWriter.exe and controls via UI Automation API
- Tests reading to IMG/GZ/ZIP formats
- ImageWriter creates archives - script just passes
.gz/.zippaths - Non-destructive (read-only tests)
- Results:
temp_gui/directory
ImageWriterCLI.ps1 - CLI wrapper for automation
# Read 100MB to compressed GZ (ImageWriter creates archive)
.\ImageWriterCLI.ps1 -Operation Read -Device E:\ -ImageFile backup.img.gz -Count 100
# Write image to USB
.\ImageWriterCLI.ps1 -Operation Write -Device E:\ -ImageFile image.img- Controls ImageWriter.exe via UI Automation
- ImageWriter handles all compression based on file extension
- Used internally by integration tests
Inspect-ImageWriterGUI.ps1 - GUI debugging utility
.\Inspect-ImageWriterGUI.ps1- Scans UI element tree for test development
- Shows control names, types, classes
run_tests.bat - Compile and run DUnit tests
run_tests.batImageWriterTests.dpr - Main test runner
- Requires Delphi 7 + DUnit framework
- Includes:
DeviceDetectionTests.pas- USB/disk enumerationSafeOperationsTests.pas- Safety mechanismsZLibTests.pas- Compression functionality
- Read tests are safe (no data modification)
- Write tests DESTROY ALL DATA on selected USB device
- Fixed disks (C:, D:, etc.) are protected
- Write tests require explicit user confirmation (YES + CONFIRM)
- Windows with PowerShell 5.1+
- ImageWriter.exe (compiled)
- At least one removable USB device
- Administrator rights for device access
- Optional: Delphi 7 for Pascal tests
# 1. Basic smoke tests (safe, 0.15s)
.\run_tests.ps1 -JsonOutput
# 2. GUI automation tests (safe, 2-3 min)
.\IntegrationTests.ps1
# 3. CLI wrapper example
.\ImageWriterCLI.ps1 -Operation Read -Device E:\ -ImageFile test.img.gz -Count 100- ImageWriter creates archives - Scripts pass file paths with
.gz/.zipextensions, ImageWriter.exe handles all compression internally - No manual archiving - No
Compress-Archiveor ZLib calls from PowerShell - Real program testing - All tests control actual ImageWriter.exe via UI Automation API
- Safe by default - Write tests removed (were destructive and complex)
- run_tests.ps1:
test-results.json - IntegrationTests.ps1:
temp_gui/*.img,temp_gui/*.gz,temp_gui/*.zip - DUnit tests: Console output
- All test data is gitignored (
tests/test-data/,tests/temp_gui/)
tests/
βββ run_tests.ps1 # Main test runner with extended tests
βββ run_extended_tests.bat # Batch runner for all extended tests
β
βββ IntegrationTests.ps1 # GUI automation (UI Automation API)
βββ Test-ArchiveFormats.ps1 # β¨ NEW: All archive formats testing
βββ Test-PartitionInfo.ps1 # β¨ NEW: Partition detection testing
βββ Test-PartitionDetection.ps1 # Legacy partition test (manual)
β
βββ ImageWriterCLI.ps1 # CLI wrapper (uses UI Automation)
βββ Inspect-ImageWriterGUI.ps1 # GUI debugging utility
β
βββ ImageWriterTests.dpr # DUnit test runner (Delphi 7)
βββ DeviceDetectionTests.pas # Device enumeration tests (11 tests)
βββ SafeOperationsTests.pas # Safety mechanism tests (8 tests)
βββ ZLibTests.pas # Compression library tests (5 tests)
βββ BatchLogHelperTests.pas # β¨ NEW (23.12.2025): Log batching tests (7 tests)
βββ ArchivePartitionReaderTests.pas # β¨ NEW (23.12.2025): Partition analysis tests (6 tests)
βββ DeviceBenchmarkTests.pas # β¨ NEW (23.12.2025): Device benchmarking tests (7 tests)
βββ OperationUIHelperTests.pas # β¨ NEW (23.12.2025): UI helper function tests (8 tests)
βββ ArchiveIntegrationTests.pas # Archive handling tests
βββ IPCIntegrationTests.pas # IPC communication tests
βββ run_tests.bat # DUnit compilation script
β
βββ test-data/
βββ archives/ # Archive format test files
βββ partition-tests/ # MBR/GPT test images
Test-ArchiveFormats.ps1 provides comprehensive testing for all supported archive formats:
- GZIP (.img.gz) - Standard GNU Zip compression
- ZIP (.zip) - PKZip archive format
- XZ (.img.xz) - LZMA2 compression
- BZIP2 (.img.bz2) - Burrows-Wheeler compression
- 7-Zip (.7z) - 7z archive format
- TAR.GZ (.tar.gz) - Tarball with GZIP
- TAR.XZ (.tar.xz) - Tarball with XZ
-
Phase 1: Device β Archive (Read Tests)
- ImageWriter reads from device and creates archive
- Tests each format's magic bytes verification
- Validates compression and file integrity
-
Phase 2: Archive β Device (Recognition Tests)
- ImageWriter loads and recognizes archive format
- Non-destructive (no actual writing to device)
- Verifies format detection and metadata parsing
# Full test suite
.\Test-ArchiveFormats.ps1 -Verbose
# Skip write tests (recognition only)
.\Test-ArchiveFormats.ps1 -SkipWriteTests
# Run via main test runner
.\run_tests.ps1 -ArchiveTestsEach format is validated by checking its signature:
- GZIP:
0x1F 0x8B - ZIP:
0x50 0x4B(PK) - XZ:
0xFD 0x37 0x7A 0x58 0x5A 0x00 - BZIP2:
0x42 0x5A 0x68(BZh) - 7-Zip:
0x37 0x7A 0xBC 0xAF 0x27 0x1C
Test-PartitionInfo.ps1 provides automated testing for partition table detection:
-
MBR Test Image (100MB)
- Partition 1: NTFS, Bootable, 50MB (LBA 2048)
- Partition 2: FAT32, 50MB (LBA 104448)
- Valid MBR signature: 0x55AA
-
GPT Test Image (100MB)
- Protective MBR with 0xEE type
- GPT Header with "EFI PART" signature
- Partition 1: EFI System Partition (LBA 2048-104447)
- Partition 2: Microsoft Basic Data (LBA 104448-204799)
-
Direct Image Testing
- Load .img file in ImageWriter
- Verify partition table detection (MBR/GPT)
- Check partition count and metadata
-
Archive Testing
- Create GZIP/ZIP archives of test images
- Load archive in ImageWriter
- Verify partition detection from compressed source
- Tests stream-based analysis (no full extraction)
# Create test images and run all tests
.\Test-PartitionInfo.ps1 -CreateTestImages -Verbose
# Use existing test images
.\Test-PartitionInfo.ps1
# Run via main test runner
.\run_tests.ps1 -PartitionTestsImageWriter should display in partition preview area:
MBR Image:
- Partition table: MBR detected
- Found 2 partition(s)
- Partition 1: Type: 0x07 - NTFS/exFAT, Bootable
- Partition 2: Type: 0x0B - FAT32
GPT Image:
- Partition table: GPT detected
- Found 2 partition(s)
- Partition 1: EFI System Partition
- Partition 2: Microsoft Basic Data
The partition detection from archives uses ImageWriter's efficient stream-based approach:
- Only reads first 64KB from archive for analysis
- No full archive extraction required
- Supports all 7 archive formats
- 99.998% memory savings vs full extraction
GUI Automation Flow:
- Script starts ImageWriter.exe
- Uses UI Automation API to find window (
TMainForm) - Sets file path with desired extension (
.img,.gz, or.zip) - Clicks Read/Write button
- Monitors log control for completion
- ImageWriter.exe creates compressed archives automatically
- Script verifies output file exists and has correct format
No Manual Compression:
- β Scripts do NOT call
Compress-Archive - β Scripts do NOT use
GZipStreamdirectly - β ImageWriter.exe detects file extension and creates archive
- β Scripts only pass paths and control UI
To add new tests:
-
Use
Inspect-ImageWriterGUI.ps1to find UI element names -
Add test function to
IntegrationTests.ps1 -
Follow UI Automation pattern (find control β set value β invoke)
[PASS] TestZLibDynamicLoading [PASS] TestZLibAvailable [PASS] TestCompressionDecompression
## No Removable Device Available
If no removable device is connected, some tests will be **SKIPPED**:
WARNING: No removable devices found - some tests will be skipped SKIP: No removable device found
This is normal and safe. Device-specific tests cannot run without hardware.
## Adding New Tests
To add new tests:
1. Create new unit in `tests\` directory
2. Inherit from `TTestCase`
3. Mark test methods with `published` keyword
4. Register test in `initialization` section:
```pascal
unit MyNewTests;
interface
uses TestFramework;
type
TMyNewTest = class(TTestCase)
published
procedure TestSomething;
end;
implementation
procedure TMyNewTest.TestSomething;
begin
CheckTrue(True, 'Test passed');
end;
initialization
RegisterTest(TMyNewTest.Suite);
end.
- Add unit to
ImageWriterTests.dpruses clause
When writing new tests:
- ALWAYS verify device type before write operations
- NEVER write to fixed disks in automated tests
- PREFER read-only operations
- USE small test data (KB, not MB/GB)
- VERIFY device is removable:
GetDriveType() = DRIVE_REMOVABLE - SKIP tests gracefully if no removable device available
For CI/CD pipelines:
test:
script:
- cd tests
- dcc32 -B ImageWriterTests.dpr
- ImageWriterTests.exe
artifacts:
when: always
paths:
- tests/*.dcu
- tests/*.exe- Ensure Delphi 7 is installed
- Add Delphi\Bin to PATH:
set PATH=%PATH%;C:\Program Files\Borland\Delphi7\Bin
- Run tests as Administrator
- Some device operations require elevated privileges
- DUnit should be included with Delphi 7
- Check Delphi7\Source\ToolsAPI directory
- Connect a removable USB device
- Ensure device is recognized by Windows
- Check Device Manager
These tests are part of ImageWriter and licensed under GNU GPL v3.0.
Author: Anton Zelenov tixset@gmail.com
GitHub: https://github.com/tixset/ImageWriter