summaryrefslogtreecommitdiff
path: root/src/objectvalidation.cpp
blob: 04cd0b65ae96112a8f3277e5b39a0c48ec7a7579 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (C) 2013  Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "objectvalidation.h"

#include "kolabevent.h"
#include "kolabtodo.h"
#include "kolabjournal.h"
#include "kolabcontact.h"
#include "kolabconfiguration.h"
#include "kolabfile.h"
#include "utils.h"

namespace Kolab {

bool isValid(const cDateTime &datetime)
{
    if (!datetime.isValid()) {
        return true;
    }
    const std::string tz = datetime.timezone();
    if (datetime.isUTC() && !tz.empty()) {
        Utils::logMessage("A UTC datetime may not have a timezone", "", 0, Error);
        return false;
    }
    if (tz == "Z") {
        Utils::logMessage("Z is not a valid timezone. Set to UTC instead", "", 0, Error);
        return false;
    }
    return true;
}

#define ASSERT(arg) \
    do {\
        if ( !(arg) ) { \
            Utils::logMessage(#arg " is false", __FILE__, __LINE__, Error); \
        } \
    } while(0)

#define ASSERTEQUAL(arg1, arg2) \
    do {\
        if ( (arg1) != (arg2) ) { \
            Utils::logMessage(#arg1 " != " #arg2, __FILE__, __LINE__, Error); \
        } \
    } while(0)

#define ASSERTEXISTING(arg) \
    do {\
        if ( !(arg).isValid() ) { \
            Utils::logMessage(#arg " is not set", __FILE__, __LINE__, Error); \
        } \
    } while(0)

#define ASSERTVALID(arg) \
    do {\
        if ( (arg).isValid() && !isValid((arg)) ) { \
            Utils::logMessage(#arg " is not valid", __FILE__, __LINE__, Error); \
        } \
    } while(0)

void validate(const Event &event)
{
    ASSERTEXISTING(event.start());
    ASSERTVALID(event.start());
    ASSERTVALID(event.end());
    if (event.end().isValid()) {
        ASSERTEQUAL(event.start().timezone(), event.end().timezone());
    }
}

void validate(const Todo& todo)
{
    ASSERTVALID(todo.start());
    ASSERTVALID(todo.due());
    ASSERTEQUAL(todo.start().timezone(), todo.due().timezone());
}

void validate(const Journal& journal)
{

}

void validate(const Contact& contact)
{

}

void validate(const DistList& distlist)
{

}

void validate(const Freebusy& freebusy)
{

}

void validate(const Note& note)
{

}

void validate(const Configuration& configuration)
{

}

void validate(const File& file)
{

}

}