File: test_XmpKey.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 (91 lines) | stat: -rw-r--r-- 2,349 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <exiv2/error.hpp>
#include <exiv2/properties.hpp>

#include "gtestwrapper.h"

using namespace Exiv2;

namespace
{
    const std::string expectedFamily("Xmp");
    const std::string expectedPrefix("prefix");
    const std::string expectedProperty("prop");
    const std::string expectedKey(expectedFamily + "." + expectedPrefix + "." + expectedProperty);
    const std::string notRegisteredValidKey("Xmp.noregistered.prop");
}

// Test Fixture which register a namespace with a prefix. This is needed to test the correct
// behavior of the XmpKey class
class AXmpKey : public testing::Test
{
public:
    static void SetUpTestCase()
    {
        XmpProperties::registerNs(expectedFamily, expectedPrefix);
    }

    static void TearDownTestCase()
    {
        XmpProperties::unregisterNs();
    }

    void checkValidity(const XmpKey& key)
    {
        ASSERT_EQ(expectedKey, key.key());
        ASSERT_EQ(expectedFamily, key.familyName());
        ASSERT_EQ(expectedPrefix, key.groupName());
        ASSERT_EQ(expectedProperty, key.tagName());
        ASSERT_EQ(expectedProperty, key.tagLabel());
        ASSERT_EQ(0, key.tag());
        ASSERT_STREQ("Xmp/", key.ns().c_str());
    }
};

TEST_F(AXmpKey, correctlyInstantiateWithValidKey)
{
    XmpKey key(expectedKey);
    checkValidity(key);
}

TEST_F(AXmpKey, correctlyInstantiatedWithValidPrefixAndProperty)
{
    XmpKey key(expectedPrefix, expectedProperty);
    checkValidity(key);
}

TEST_F(AXmpKey, canBeCopiedConstructed)
{
    XmpKey key(expectedPrefix, expectedProperty);
    XmpKey copiedKey(key);
    checkValidity(copiedKey);
}

TEST_F(AXmpKey, canBeCopied)
{
    XmpKey key(expectedPrefix, expectedProperty);
    XmpKey copiedKey("Xmp.prefix.prop2");
    copiedKey = key;
    checkValidity(copiedKey);
}

TEST_F(AXmpKey, canBeCloned)
{
    XmpKey key(expectedPrefix, expectedProperty);
    XmpKey::AutoPtr clonedKey = key.clone();
    checkValidity(*clonedKey);
}

TEST_F(AXmpKey, throwsWithNotRegisteredWellFormedKey)
{
    ASSERT_THROW(XmpKey key(notRegisteredValidKey), std::exception);
}

TEST_F(AXmpKey, throwsWithNotRegisteredPrefix)
{
    ASSERT_THROW(XmpKey key("badPrefix", expectedProperty), std::exception);
}

TEST_F(AXmpKey, throwsWithBadFormedKey)
{
    ASSERT_THROW(XmpKey key(expectedProperty), std::exception);  // It should have the format ns.prefix.key
}