I have a problem in getting comparing two binary files ( PDF, JPEJ ,bmp etc.) in Egg Plant (3.0) . These files lies at some physical location . I have to verify whether these files match or not . If I get the variance factor then it will be a bonus for me.
You can use Eggplant to compare binary files, but keep in mind that SenseTalk can’t directly access files on the SUT unless the SUT’s file system is mounted locally across the network. If a remote filesystem is mounted on the Eggplant machine, then SenseTalk’s file access commands can be used to read remote files just as easily as files on the local Eggplant machine.
SenseTalk’s simple file access mechanism (accessing a file directly as a container) works well for text files but not so well for binary files. To compare binary files (assuming they are mounted on the local system) you’ll need to do something like this:
if binaryFilesAreEqual("/path/to/file1.jpg", "/path/to/file2.jpg") then
put "Files are the same"
else
put "Files are different"
end if
function binaryFilesAreEqual binary1, binary2
set count1 to the size of file binary1
set count2 to the size of file binary2
if count1 is not count2 then
return false -- files are different sizes
end if
open file binary1
read count1 8-bit integers from file binary1 into list1
close file binary1
open file binary2
read count2 8-bit integers from file binary2 into list2
close file binary2
if list1 = list2 then
return true -- Files are the same
else
return false -- Files are different
end if
end binaryFilesAreEqual
This isn’t a terribly fast approach, but if you like, you can expand this to examine the contents of list1 and list2 to see which bytes of the file are different.
For large files a more efficient approach would probably be to use the shell function to call the Unix command-line ‘diff’ tool to compare the files.