File: test_FileIo.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 (74 lines) | stat: -rw-r--r-- 1,485 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
65
66
67
68
69
70
71
72
73
74
#include "basicio.hpp"

#include <gtest/gtest.h>

using namespace Exiv2;

namespace
{
    const std::string testData(TESTDATA_PATH);
    const std::string imagePath(testData + "/DSC_3079.jpg");
}  // namespace

TEST(AFileIO, canBeInstantiatedWithFilePath)
{
    ASSERT_NO_THROW(FileIo file(imagePath));
}

TEST(AFileIO, canBeOpenInReadBinaryMode)
{
    FileIo file(imagePath);
    ASSERT_EQ(0, file.open());
}

TEST(AFileIO, isOpenDoItsJob)
{
    FileIo file(imagePath);
    ASSERT_FALSE(file.isopen());
    file.open();
    ASSERT_TRUE(file.isopen());
}

TEST(AFileIO, returnsFileSizeIfItsOpened)
{
    FileIo file(imagePath);
    file.open();
    ASSERT_EQ(118685ul, file.size());
}

TEST(AFileIO, returnsFileSizeEvenWhenFileItIsNotOpened)
{
    FileIo file(imagePath);
    ASSERT_EQ(118685ul, file.size());
}

TEST(AFileIO, isOpenedAtPosition0)
{
    FileIo file(imagePath);
    file.open();
    ASSERT_EQ(0, file.tell());
}

TEST(AFileIO, canSeekToExistingPositions)
{
    FileIo file(imagePath);
    file.open();

    ASSERT_EQ(0, file.seek(100, BasicIo::beg));
    ASSERT_EQ(0, file.seek(-50, BasicIo::cur));
    ASSERT_EQ(0, file.seek(-50, BasicIo::end));

    ASSERT_FALSE(file.error());
    ASSERT_FALSE(file.eof());
}

TEST(AFileIO, canSeekBeyondEOF)
{
    FileIo file(imagePath);
    file.open();

    // POSIX allows seeking beyond the existing end of file.
    ASSERT_EQ(0, file.seek(200000, BasicIo::beg));
    ASSERT_FALSE(file.error());
    ASSERT_FALSE(file.eof());
}