Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/2.2.x' into 2.2.x
- Loading branch information
Showing
17 changed files
with
282 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use English qw(-no_match_vars); | ||
use Test::More; | ||
|
||
BEGIN { | ||
# use mock modules for non-available ones | ||
push @INC, 't/fake/windows' if $OSNAME ne 'MSWin32'; | ||
} | ||
|
||
use FusionInventory::Agent::Task::Inventory::Input::Win32::Printers; | ||
|
||
my %tests = ( | ||
xppro1 => { | ||
USB001 => [ '6&397bdcac&0', '49R8Ka' ], | ||
USB002 => [ '6&2ad9257f&0', '5&19d1ce61&0&2' ], | ||
USB003 => [ '6&1605722f&0', '5&2377f6ef&0&2' ], | ||
}, | ||
xppro2 => { | ||
USB001 => [ '6&1086615&0', 'J5J126789' ], | ||
USB003 => [ '6&159b6df2&0', 'JV40VNJ' ], | ||
USB004 => [ '7&20bd29b5&0', '6&28e27c3d&0&0000' ], | ||
}, | ||
7 => { | ||
USB001 => [ '7&17e8a3c3&0', 'MY26K1K34C2L' ], | ||
} | ||
); | ||
|
||
my $plan = 0; | ||
foreach my $test (keys %tests) { | ||
$plan += 2 * scalar (keys $tests{$test}); | ||
} | ||
plan tests => $plan; | ||
|
||
foreach my $test (keys %tests) { | ||
my $printKey = load_registry("resources/win32/registry/$test-USBPRINT.reg"); | ||
my $usbKey = load_registry("resources/win32/registry/$test-USB.reg"); | ||
foreach my $port (keys $tests{$test}) { | ||
my $prefix = FusionInventory::Agent::Task::Inventory::Input::Win32::Printers::_getUSBPrefix($printKey, $port); | ||
my $serial = FusionInventory::Agent::Task::Inventory::Input::Win32::Printers::_getUSBSerial($usbKey, $prefix); | ||
|
||
is($prefix, $tests{$test}->{$port}->[0], "prefix for printer $port"); | ||
is($serial, $tests{$test}->{$port}->[1], "serial for printer $port"); | ||
} | ||
} | ||
|
||
sub load_registry { | ||
my ($file) = @_; | ||
|
||
my $root_offset; | ||
my $root_key = {}; | ||
my $current_key; | ||
|
||
open (my $handle, '<', $file) or die "can't open $file: $ERRNO"; | ||
|
||
# this is a windows file | ||
binmode $handle, ':encoding(UTF-16LE)'; | ||
binmode $handle, ':crlf'; | ||
|
||
while (my $line = <$handle>) { | ||
|
||
if ($line =~ /^ \[ ([^]]+) \] $/x) { | ||
my $path = $1; | ||
my @path = split(/\\/, $path); | ||
|
||
if ($root_offset) { | ||
splice @path, 0, $root_offset; | ||
$current_key = $root_key; | ||
foreach my $element (@path) { | ||
my $key_path = $element . '/'; | ||
|
||
if (!defined $current_key->{$key_path}) { | ||
my $new_key = {}; | ||
$current_key->{$key_path} = $new_key; | ||
} | ||
|
||
$current_key = $current_key->{$key_path}; | ||
} | ||
} else { | ||
$root_offset = scalar @path; | ||
} | ||
next; | ||
} | ||
|
||
if ($line =~ /^ " ([^"]+) " = dword:(\d+)/x) { | ||
$current_key->{'/' . $1} = "0x$2"; | ||
next; | ||
} | ||
|
||
if ($line =~ /^ " ([^"]+) " = " ([^"]+) "/x) { | ||
$current_key->{'/' . $1} = $2; | ||
next; | ||
} | ||
|
||
} | ||
close $handle; | ||
|
||
return $root_key; | ||
} |
Oops, something went wrong.