~ubuntu-branches/ubuntu/trusty/unity-scopes-api/trusty-proposed

« back to all changes in this revision

Viewing changes to test/gtest/scopes/Annotation/Annotation_test.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Pawel Stolowski
  • Date: 2014-02-11 17:55:05 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140211175505-av3z0612p7o8w54b
Tags: 0.3.1+14.04.20140211.2-0ubuntu1
[ Pawel Stolowski ]
* [ Pawel Stolowski ]
* Added preliminary API for filters and departments.
* Changes to preview action activation API: support for widget id.
* Changes to Annotation API.
* Return ScopeProxy from Result::target_scope_proxy (replaces activation_scope_name).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <gtest/gtest.h>
20
20
#include <unity/scopes/Annotation.h>
21
21
#include <unity/scopes/Query.h>
22
 
#include <unity/scopes/CategoryRenderer.h>
23
 
#include <unity/scopes/internal/CategoryRegistry.h>
 
22
#include <unity/scopes/internal/QueryImpl.h>
24
23
#include <unity/scopes/internal/AnnotationImpl.h>
25
24
#include <unity/UnityExceptions.h>
26
25
 
121
120
    }
122
121
}
123
122
 
124
 
TEST(Annotation, card)
125
 
{
126
 
    {
127
 
        Query query("scope-A", "foo", "dep1");
128
 
 
129
 
        Annotation annotation(Annotation::Type::Card);
130
 
        annotation.set_icon("icon");
131
 
        annotation.add_link("Link1", query);
132
 
 
133
 
        EXPECT_EQ("icon", annotation.icon());
134
 
        EXPECT_EQ(1, annotation.links().size());
135
 
        auto link = annotation.links().front();
136
 
        EXPECT_EQ("Link1", link->label());
137
 
        EXPECT_EQ(query.scope_name(), link->query().scope_name());
138
 
        EXPECT_EQ(query.department_id(), link->query().department_id());
139
 
        EXPECT_EQ(query.query_string(), link->query().query_string());
140
 
    }
141
 
}
142
 
 
143
 
TEST(Annotation, card_exceptions)
144
 
{
145
 
    {
146
 
        Query query("scope-A", "foo", "dep1");
147
 
 
148
 
        Annotation annotation(Annotation::Type::Card);
149
 
        annotation.set_icon("icon");
150
 
        annotation.add_link("Link1", query);
151
 
 
152
 
        // label currently makes sense for group only, but we shouldn't throw
153
 
        EXPECT_NO_THROW(annotation.set_label("Label"));
154
 
        EXPECT_THROW(annotation.add_link("Link2", query), unity::InvalidArgumentException); // only one link allowed
155
 
        EXPECT_EQ(1, annotation.links().size());
156
 
    }
157
 
}
158
 
 
159
123
TEST(Annotation, serialize)
160
124
{
161
125
    {
171
135
        EXPECT_EQ(1, links.size());
172
136
        auto linkvm = links[0].get_dict();
173
137
        EXPECT_EQ("Link1", linkvm["label"].get_string());
174
 
        Query qout(linkvm["query"].get_dict());
 
138
        Query qout = internal::QueryImpl::create(linkvm["query"].get_dict());
175
139
        EXPECT_EQ("scope-A", qout.scope_name());
176
140
        EXPECT_EQ("foo", qout.query_string());
177
141
        EXPECT_EQ("dep1", qout.department_id());
180
144
 
181
145
TEST(Annotation, deserialize)
182
146
{
183
 
    CategoryRegistry reg;
184
 
    CategoryRenderer rdr;
185
 
    auto cat = reg.register_category("1", "title", "icon", rdr);
186
147
    Query query("scope-A", "foo", "dep1");
187
148
    {
188
149
        Annotation annotation(Annotation::Type::GroupedLink);
189
150
        annotation.set_label("Foo");
190
151
        annotation.add_link("Link1", query);
191
152
        auto var = annotation.serialize();
192
 
        AnnotationImpl impl(reg, var);
 
153
        AnnotationImpl impl(var);
193
154
    }
194
155
    {
195
156
        Annotation annotation(Annotation::Type::Link);
196
157
        annotation.set_icon("Icon");
197
158
        annotation.add_link("Link1", query);
198
159
        auto var = annotation.serialize();
199
 
        AnnotationImpl impl(reg, var);
200
 
    }
201
 
    {
202
 
        Annotation annotation(Annotation::Type::Card);
203
 
        annotation.set_icon("Icon");
204
 
        annotation.set_category(cat);
205
 
        annotation.add_link("Link1", query);
206
 
        auto var = annotation.serialize();
207
 
        AnnotationImpl impl(reg, var);
 
160
        AnnotationImpl impl(var);
208
161
    }
209
162
}
210
163
 
211
164
TEST(Annotation, deserialize_exceptions)
212
165
{
213
166
    {
214
 
        CategoryRegistry reg;
215
 
        CategoryRenderer rdr;
216
167
        Query query("scope-A", "foo", "dep1");
217
 
        auto cat = reg.register_category("1", "title", "icon", rdr);
218
168
        {
219
169
            VariantMap var;
220
170
            try
221
171
            {
222
 
                AnnotationImpl impl(reg, var);
 
172
                AnnotationImpl impl(var);
223
173
                FAIL();
224
174
            }
225
175
            catch (unity::InvalidArgumentException const& e) {}
229
179
            var["type"] = "";
230
180
            try
231
181
            {
232
 
                AnnotationImpl impl(reg, var);
 
182
                AnnotationImpl impl(var);
233
183
                FAIL();
234
184
            }
235
185
            catch (unity::InvalidArgumentException const& e) {}
239
189
            var["type"] = "link";
240
190
            try
241
191
            {
242
 
                AnnotationImpl impl(reg, var);
 
192
                AnnotationImpl impl(var);
243
193
                FAIL();
244
194
            }
245
195
            catch (unity::InvalidArgumentException const& e) {}
249
199
            var["type"] = "groupedlink";
250
200
            try
251
201
            {
252
 
                AnnotationImpl impl(reg, var);
 
202
                AnnotationImpl impl(var);
253
203
                FAIL();
254
204
            }
255
205
            catch (unity::InvalidArgumentException const& e) {}
259
209
            var["type"] = "card";
260
210
            try
261
211
            {
262
 
                AnnotationImpl impl(reg, var);
 
212
                AnnotationImpl impl(var);
263
213
                FAIL();
264
214
            }
265
215
            catch (unity::InvalidArgumentException const& e) {}
271
221
            var["cat_id"] = "unknowncat";
272
222
            try
273
223
            {
274
 
                AnnotationImpl impl(reg, var);
275
 
                FAIL();
276
 
            }
277
 
            catch (unity::InvalidArgumentException const& e) {}
278
 
        }
279
 
        {   // deserialize with unknown category
280
 
            Annotation annotation(Annotation::Type::Card);
281
 
            annotation.set_icon("Icon");
282
 
            annotation.set_category(cat);
283
 
            annotation.add_link("Link1", query);
284
 
            auto var = annotation.serialize();
285
 
            var["cat_id"] = "2";
286
 
            try
287
 
            {
288
 
                AnnotationImpl impl(reg, var);
 
224
                AnnotationImpl impl(var);
289
225
                FAIL();
290
226
            }
291
227
            catch (unity::InvalidArgumentException const& e) {}
297
233
            var["links"] = VariantArray();
298
234
            try
299
235
            {
300
 
                AnnotationImpl impl(reg, var);
 
236
                AnnotationImpl impl(var);
301
237
                FAIL();
302
238
            }
303
239
            catch (unity::InvalidArgumentException const& e) {}