libopenraw
|
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 License 00008 * as published by the Free Software Foundation, either version 3 of 00009 * 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, see 00018 * <http://www.gnu.org/licenses/>. 00019 */ 00020 00023 #include <string.h> 00024 00025 #include <iostream> 00026 #include <cstdlib> 00027 00028 #include "stream.h" 00029 #include "file.h" 00030 #include "streamclone.h" 00031 00032 using namespace OpenRaw; 00033 00034 int main (int /*argc*/, char ** /*argv*/) 00035 { 00036 IO::File *file = new IO::File("testfile.tmp"); 00037 char buf1[128]; 00038 int ret = file->open(); 00039 if (ret != 0) { 00040 std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl; 00041 std::cerr << "Couldn't open test file. Test skipped.\n"; 00042 exit(0); 00043 } 00044 00045 size_t r = file->read(buf1, 6); 00046 if (r != 6) { 00047 std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl; 00048 exit(1); 00049 } 00050 00051 IO::StreamClone * clone = new IO::StreamClone(file, 2); 00052 00053 ret = clone->open(); 00054 if (ret != 0) { 00055 std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl; 00056 exit(1); 00057 } 00058 char buf2[128]; 00059 r = file->read(buf2, 4); 00060 if (r != 4) { 00061 std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl; 00062 exit(1); 00063 } 00064 00065 if (strncmp(buf1 + 2, buf2, 4) != 0) { 00066 std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl; 00067 exit(1); 00068 } 00069 clone->close(); 00070 00071 file->close(); 00072 }