File: test_tiffheader.cpp

package info (click to toggle)
exiv2 0.27.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 54,956 kB
  • sloc: cpp: 80,713; python: 4,360; sh: 1,497; makefile: 320; javascript: 237; awk: 92; ansic: 78; sed: 16
file content (64 lines) | stat: -rw-r--r-- 1,673 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <tiffimage_int.hpp>

#include "gtestwrapper.h"
#include <sstream>

using namespace Exiv2;

static const byte tiffLittleEndian[] = {0x49, 0x49, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00};

class ATiffHeader: public ::testing::Test
{
public:
    Internal::TiffHeader header;
};

TEST_F(ATiffHeader, hasExpectedValuesAfterCreation)
{
    ASSERT_EQ(8u, header.size());
    ASSERT_EQ(42, header.tag());
    ASSERT_EQ(8u, header.offset());
    ASSERT_EQ(littleEndian, header.byteOrder());
}

TEST_F(ATiffHeader, canBeWrittenAndItsSizeIs8Bytes)
{
    DataBuf buffer = header.write();
    ASSERT_EQ(header.size(), buffer.size_);
    ASSERT_EQ(8u, header.size());
}

TEST_F(ATiffHeader, readDataFromBufferWithCorrectSize)
{
    ASSERT_TRUE(header.read(tiffLittleEndian, 8));
}

TEST_F(ATiffHeader, failToReadDataFromBufferWithCorrectSizeButNull)
{
    ASSERT_FALSE(header.read(NULL, 8));
}

TEST_F(ATiffHeader, failToReadDataFromBufferWithSizeDifferentThan8)
{
    ASSERT_FALSE(header.read(NULL, 7));
    ASSERT_FALSE(header.read(NULL, 9));
}

TEST_F(ATiffHeader, failToReadDataFromBufferWithInvalidByteOrder)
{
    static const byte bufferInvalidByteOrder[] =  {0x88, 0x49, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00};
    ASSERT_FALSE(header.read(bufferInvalidByteOrder, 8));
}

TEST_F(ATiffHeader, failToReadDataFromBufferWithInvalidTag)
{
    static const byte bufferInvalidTag[] = {0x49, 0x49, 0x29, 0x00, 0x10, 0x00, 0x00, 0x00};
    ASSERT_FALSE(header.read(bufferInvalidTag, 8));
}

TEST_F(ATiffHeader, printsDefaultValues)
{
    std::ostringstream str;
    header.print(str, "");
    ASSERT_STREQ("TIFF header, offset = 0x00000008, little endian encoded\n", str.str().c_str());
}