Add optional parameter to iotest.cpp to create the input file by copying from a remote location.
This commit is contained in:
parent
60d40d0d17
commit
037849ea9e
@ -31,6 +31,7 @@
|
||||
#include <cstdio> // for EOF
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
using Exiv2::byte;
|
||||
using Exiv2::BasicIo;
|
||||
@ -50,81 +51,106 @@ int main(int argc, char* const argv[])
|
||||
::atexit(Exiv2::XmpParser::terminate);
|
||||
|
||||
try {
|
||||
if (argc != 4) {
|
||||
std::cout << "Usage: " << argv[0] << " filein fileout1 fileout2\n";
|
||||
std::cout << "fileouts are overwritten and should match filein exactly\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
FileIo fileIn(argv[1]);
|
||||
if (fileIn.open() != 0) {
|
||||
throw Error(Exiv2::kerDataSourceOpenFailed, fileIn.path(), strError());
|
||||
}
|
||||
|
||||
FileIo fileOut1(argv[2]);
|
||||
if (fileOut1.open("w+b") != 0) {
|
||||
throw Error(Exiv2::kerFileOpenFailed, argv[2], "w+b", strError());
|
||||
}
|
||||
|
||||
MemIo memIo1;
|
||||
|
||||
// Copy to output file through memIo
|
||||
memIo1.write(fileIn);
|
||||
memIo1.seek(0, BasicIo::beg);
|
||||
fileOut1.write(memIo1);
|
||||
|
||||
// Make sure they are all the same size
|
||||
if(fileIn.size() != memIo1.size() || memIo1.size() != fileOut1.size()) {
|
||||
std::cerr << argv[0] <<
|
||||
": Sizes do not match\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read writereadseek test on MemIo
|
||||
MemIo memIo2;
|
||||
int rc = WriteReadSeek(memIo2);
|
||||
if (rc != 0) return rc;
|
||||
|
||||
// Read writereadseek test on FileIo
|
||||
// Create or overwrite the file, then close it
|
||||
FileIo fileTest("iotest.txt");
|
||||
if (fileTest.open("w+b") != 0) {
|
||||
throw Error(Exiv2::kerFileOpenFailed, "iotest.txt", "w+b", strError());
|
||||
}
|
||||
|
||||
fileTest.close();
|
||||
rc = WriteReadSeek(fileTest);
|
||||
if (rc != 0) return rc;
|
||||
|
||||
// Another test of reading and writing
|
||||
fileOut1.seek(0, BasicIo::beg);
|
||||
memIo2.seek(0, BasicIo::beg);
|
||||
FileIo fileOut2(argv[3]);
|
||||
if (fileOut2.open("w+b") != 0) {
|
||||
throw Error(Exiv2::kerFileOpenFailed, argv[3], "w+b", strError());
|
||||
}
|
||||
|
||||
long readCount = 0;
|
||||
byte buf[32];
|
||||
while ((readCount=fileOut1.read(buf, sizeof(buf)))) {
|
||||
if (memIo2.write(buf, readCount) != readCount) {
|
||||
std::cerr << argv[0] <<
|
||||
": MemIo bad write 2\n";
|
||||
return 13;
|
||||
if (argc < 4 || argc > 5 ) {
|
||||
std::cout << "Usage: " << argv[0] << " filein fileout1 fileout2 [remote]\n";
|
||||
std::cout << "fileouts are overwritten and should match filein exactly\n";
|
||||
return 1;
|
||||
}
|
||||
if (fileOut2.write(buf, readCount) != readCount) {
|
||||
std::cerr << argv[0] <<
|
||||
": FileIo bad write 2\n";
|
||||
return 14;
|
||||
}
|
||||
}
|
||||
const char* f0 = argv[1];
|
||||
const char* f1 = argv[2];
|
||||
const char* f2 = argv[3];
|
||||
const char* fr = argv[4];
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (Exiv2::AnyError& e) {
|
||||
std::cerr << "Caught Exiv2 exception '" << e << "'\n";
|
||||
return 20;
|
||||
}
|
||||
if ( argc == 5 ) {
|
||||
// copy fileIn from a remote location.
|
||||
FILE* f = fopen(f0,"wb");
|
||||
if ( !f ) {
|
||||
Error(Exiv2::kerFileOpenFailed, f0, "w+b", strError());
|
||||
}
|
||||
BasicIo::AutoPtr io = Exiv2::ImageFactory::createIo(fr);
|
||||
io->open();
|
||||
int l = 0 ;
|
||||
Exiv2::byte b[10000];
|
||||
int r ;
|
||||
while ( (r=io->read(b,sizeof(b))) > 0 ) {
|
||||
l += r;
|
||||
fwrite(b,r,1,f) ;
|
||||
}
|
||||
fclose(f);
|
||||
if ( !l ) {
|
||||
Error(Exiv2::kerFileOpenFailed, fr, "w+b", strError());
|
||||
}
|
||||
std::cout << argv[4] << " length = " << l << std::endl;
|
||||
}
|
||||
|
||||
FileIo fileIn(f0);
|
||||
if (fileIn.open() != 0) {
|
||||
throw Error(Exiv2::kerDataSourceOpenFailed, fileIn.path(), strError());
|
||||
}
|
||||
|
||||
FileIo fileOut1(f1);
|
||||
if (fileOut1.open("w+b") != 0) {
|
||||
throw Error(Exiv2::kerFileOpenFailed, f1, "w+b", strError());
|
||||
}
|
||||
|
||||
MemIo memIo1;
|
||||
|
||||
// Copy to output file through memIo
|
||||
memIo1.write(fileIn);
|
||||
memIo1.seek(0, BasicIo::beg);
|
||||
fileOut1.write(memIo1);
|
||||
|
||||
// Make sure they are all the same size
|
||||
if(fileIn.size() != memIo1.size() || memIo1.size() != fileOut1.size()) {
|
||||
std::cerr << argv[0] <<
|
||||
": Sizes do not match\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Read writereadseek test on MemIo
|
||||
MemIo memIo2;
|
||||
int rc = WriteReadSeek(memIo2);
|
||||
if (rc != 0) return rc;
|
||||
|
||||
// Read writereadseek test on FileIo
|
||||
// Create or overwrite the file, then close it
|
||||
FileIo fileTest("iotest.txt");
|
||||
if (fileTest.open("w+b") != 0) {
|
||||
throw Error(Exiv2::kerFileOpenFailed, "iotest.txt", "w+b", strError());
|
||||
}
|
||||
|
||||
fileTest.close();
|
||||
rc = WriteReadSeek(fileTest);
|
||||
if (rc != 0) return rc;
|
||||
|
||||
// Another test of reading and writing
|
||||
fileOut1.seek(0, BasicIo::beg);
|
||||
memIo2.seek(0, BasicIo::beg);
|
||||
FileIo fileOut2(f2);
|
||||
if (fileOut2.open("w+b") != 0) {
|
||||
throw Error(Exiv2::kerFileOpenFailed, f2, "w+b", strError());
|
||||
}
|
||||
|
||||
long readCount = 0;
|
||||
byte buf[32];
|
||||
while ((readCount=fileOut1.read(buf, sizeof(buf)))) {
|
||||
if (memIo2.write(buf, readCount) != readCount) {
|
||||
std::cerr << argv[0] <<
|
||||
": MemIo bad write 2\n";
|
||||
return 13;
|
||||
}
|
||||
if (fileOut2.write(buf, readCount) != readCount) {
|
||||
std::cerr << argv[0] <<
|
||||
": FileIo bad write 2\n";
|
||||
return 14;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
} catch (Exiv2::AnyError& e) {
|
||||
std::cerr << "Caught Exiv2 exception '" << e << "'\n";
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user