teststream.cpp

00001 /*
00002  * libopenraw - teststream.cpp
00003  *
00004  * Copyright (C) 2006 Hubert Figuiere
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00023 #include <iostream>
00024 #include <cstdlib>
00025 
00026 #include "stream.h"
00027 #include "file.h"
00028 #include "streamclone.h"
00029 
00030 using namespace OpenRaw;
00031 
00032 int main (int argc, char ** argv)
00033 {
00034     IO::File *file = new IO::File("testfile.tmp");
00035     char buf1[128];
00036     int ret = file->open();
00037     if (ret != 0) {
00038         std::cerr << "failed: " __FILE__ ": "  << __LINE__ << std::endl;
00039         std::cerr << "Couldn't open test file. Test skipped.\n";
00040         exit(0);
00041     }
00042 
00043     size_t r = file->read(buf1, 6);
00044     if (r != 6) {
00045         std::cerr << "failed: "  __FILE__ ": " << __LINE__ << std::endl;
00046         exit(1);
00047     }
00048     
00049     IO::StreamClone * clone = new IO::StreamClone(file, 2);
00050 
00051     ret = clone->open();
00052     if (ret != 0) {
00053         std::cerr << "failed: " __FILE__ ": "  << __LINE__ << std::endl;
00054         exit(1);
00055     }
00056     char buf2[128];
00057     r = file->read(buf2, 4);
00058     if (r != 4) {
00059         std::cerr << "failed: "  __FILE__ ": " << __LINE__ << std::endl;
00060         exit(1);
00061     }
00062 
00063     if (strncmp(buf1 + 2, buf2, 4) != 0) {
00064         std::cerr << "failed: "  __FILE__ ": " << __LINE__ << std::endl;
00065         exit(1);
00066     }
00067     clone->close();
00068 
00069     file->close();
00070 }

Generated on Sat Jan 27 11:36:13 2007 for libopenraw by  doxygen 1.4.7