1 /*
2 * Copyright (C) 2009 Tommi Maekitalo
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
12 * NON-INFRINGEMENT. See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 */
19
20 #include <stdexcept>
21 #ifdef _WIN32
22 #include <windows.h>
23 #include <fcntl.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <io.h>
27 #include <fileapi.h>
28 #endif
29
30 #include <iostream>
31 #include <sstream>
32
33 #include "gtest/gtest.h"
34
35 #include <zim/fileheader.h>
36
37 #include "../src/buffer.h"
38 #include "../src/buffer_reader.h"
39
40 #include "tools.h"
41
42 namespace
43 {
44
45 using zim::unittests::TempFile;
46 using zim::unittests::write_to_buffer;
47
TEST(HeaderTest,read_write_header)48 TEST(HeaderTest, read_write_header)
49 {
50 zim::Fileheader header;
51 header.setUuid("1234567890abcdef");
52 header.setArticleCount(4711);
53 header.setUrlPtrPos(12345);
54 header.setTitleIdxPos(23456);
55 header.setClusterCount(14);
56 header.setClusterPtrPos(45678);
57 header.setMainPage(11);
58 header.setLayoutPage(13);
59 header.setMimeListPos(72);
60
61 ASSERT_EQ(header.getUuid(), "1234567890abcdef");
62 ASSERT_EQ(header.getArticleCount(), 4711U);
63 ASSERT_EQ(header.getUrlPtrPos(), 12345U);
64 ASSERT_EQ(header.getTitleIdxPos(), 23456U);
65 ASSERT_EQ(header.getClusterCount(), 14U);
66 ASSERT_EQ(header.getClusterPtrPos(), 45678U);
67 ASSERT_EQ(header.getMainPage(), 11U);
68 ASSERT_EQ(header.getLayoutPage(), 13U);
69 ASSERT_EQ(header.getMimeListPos(), 72U);
70
71 auto buffer = write_to_buffer(header);
72 zim::Fileheader header2;
73 header2.read(zim::BufferReader(buffer));
74
75 ASSERT_EQ(header2.getUuid(), "1234567890abcdef");
76 ASSERT_EQ(header2.getArticleCount(), 4711U);
77 ASSERT_EQ(header2.getUrlPtrPos(), 12345U);
78 ASSERT_EQ(header2.getTitleIdxPos(), 23456U);
79 ASSERT_EQ(header2.getClusterCount(), 14U);
80 ASSERT_EQ(header2.getClusterPtrPos(), 45678U);
81 ASSERT_EQ(header2.getMainPage(), 11U);
82 ASSERT_EQ(header2.getLayoutPage(), 13U);
83 }
84
85 } // namespace
86