libopenraw
teststream.cpp
1 /*
2  * libopenraw - teststream.cpp
3  *
4  * Copyright (C) 2006 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
23 #include <string.h>
24 
25 #include <iostream>
26 #include <cstdlib>
27 
28 #include "stream.h"
29 #include "file.h"
30 #include "streamclone.h"
31 
32 using namespace OpenRaw;
33 
34 int main (int /*argc*/, char ** /*argv*/)
35 {
36  IO::File *file = new IO::File("testfile.tmp");
37  char buf1[128];
38  int ret = file->open();
39  if (ret != 0) {
40  std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl;
41  std::cerr << "Couldn't open test file. Test skipped.\n";
42  exit(0);
43  }
44 
45  size_t r = file->read(buf1, 6);
46  if (r != 6) {
47  std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl;
48  exit(1);
49  }
50 
51  IO::StreamClone * clone = new IO::StreamClone(file, 2);
52 
53  ret = clone->open();
54  if (ret != 0) {
55  std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl;
56  exit(1);
57  }
58  char buf2[128];
59  r = file->read(buf2, 4);
60  if (r != 4) {
61  std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl;
62  exit(1);
63  }
64 
65  if (strncmp(buf1 + 2, buf2, 4) != 0) {
66  std::cerr << "failed: " __FILE__ ": " << __LINE__ << std::endl;
67  exit(1);
68  }
69  clone->close();
70 
71  file->close();
72 }
cloned stream. Allow reading from a different offset
Definition: streamclone.h:35
virtual int read(void *buf, size_t count)
Definition: file.cpp:59
virtual Error open()
Definition: file.cpp:40
virtual Error open()
Definition: streamclone.cpp:42
virtual int close()
Definition: file.cpp:49