Welcome to mirror list, hosted at ThFree Co, Russian Federation.

xml_feature_test.cpp « editor_tests « editor - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1e6451283421451db30876054f0441033c2609d (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "testing/testing.hpp"

#include "editor/xml_feature.hpp"

#include "geometry/mercator.hpp"

#include "base/timer.hpp"

#include "std/sstream.hpp"

#include "3party/pugixml/src/pugixml.hpp"

using namespace editor;

UNIT_TEST(XMLFeature_RawGetSet)
{
  XMLFeature feature;
  TEST(!feature.HasTag("opening_hours"), ());
  TEST(!feature.HasAttribute("center"), ());

  feature.SetAttribute("FooBar", "foobar");
  TEST_EQUAL(feature.GetAttribute("FooBar"), "foobar", ());

  feature.SetAttribute("FooBar", "foofoo");
  TEST_EQUAL(feature.GetAttribute("FooBar"), "foofoo", ());

  feature.SetTagValue("opening_hours", "18:20-18:21");
  TEST_EQUAL(feature.GetTagValue("opening_hours"), "18:20-18:21", ());

  feature.SetTagValue("opening_hours", "18:20-19:21");
  TEST_EQUAL(feature.GetTagValue("opening_hours"), "18:20-19:21", ());

  auto const expected = R"(<?xml version="1.0"?>
<node
  FooBar="foofoo">
  <tag
    k="opening_hours"
    v="18:20-19:21" />
</node>
)";

  stringstream sstr;
  feature.Save(sstr);
  TEST_EQUAL(expected, sstr.str(), ());
}


UNIT_TEST(XMLFeature_Setters)
{
  XMLFeature feature;

  feature.SetCenter(MercatorBounds::FromLatLon(55.7978998, 37.4745280));
  feature.SetModificationTime(my::StringToTimestamp("2015-11-27T21:13:32Z"));

  feature.SetName("Gorki Park");
  feature.SetName("en", "Gorki Park");
  feature.SetName("ru", "Парк Горького");

  feature.SetHouse("10");
  feature.SetTagValue("opening_hours", "Mo-Fr 08:15-17:30");

  feature.SetType("amenity|atm");
  feature.SetHeader(0xaf);

  stringstream sstr;
  feature.Save(sstr);

  auto const expectedString = R"(<?xml version="1.0"?>
<node
  lat="55.7978998"
  lon="37.474528"
  timestamp="2015-11-27T21:13:32Z">
  <tag
    k="name"
    v="Gorki Park" />
  <tag
    k="name:en"
    v="Gorki Park" />
  <tag
    k="name:ru"
    v="Парк Горького" />
  <tag
    k="addr:housenumber"
    v="10" />
  <tag
    k="opening_hours"
    v="Mo-Fr 08:15-17:30" />
  <tag
    k="amenity"
    v="atm" />
  <mapswithme:header>0xaf</mapswithme:header>
</node>
)";

  TEST_EQUAL(sstr.str(), expectedString, ());
}

UNIT_TEST(XMLFeatureFromXml)
{
  auto const srcString = R"(<?xml version="1.0"?>
<node
  lat="55.7978998"
  lon="37.474528"
  timestamp="2015-11-27T21:13:32Z">
  <tag
    k="name"
    v="Gorki Park" />
  <tag
    k="name:en"
    v="Gorki Park" />
  <tag
    k="name:ru"
    v="Парк Горького" />
  <tag
    k="addr:housenumber"
    v="10" />
  <tag
    k="opening_hours"
    v="Mo-Fr 08:15-17:30" />
  <tag
    k="amenity"
    v="atm" />
  <mapswithme:header>0xaf</mapswithme:header>
</node>
)";

  XMLFeature feature(srcString);

  stringstream sstr;
  feature.Save(sstr);
  TEST_EQUAL(srcString, sstr.str(), ());

  TEST(feature.HasKey("opening_hours"), ());
  TEST(feature.HasKey("lat"), ());
  TEST(feature.HasKey("lon"), ());
  TEST(!feature.HasKey("FooBarBaz"), ());

  TEST_EQUAL(feature.GetHouse(), "10", ());
  TEST_EQUAL(feature.GetCenter(), MercatorBounds::FromLatLon(55.7978998, 37.4745280), ());
  TEST_EQUAL(feature.GetName(), "Gorki Park", ());
  TEST_EQUAL(feature.GetName("default"), "Gorki Park", ());
  TEST_EQUAL(feature.GetName("en"), "Gorki Park", ());
  TEST_EQUAL(feature.GetName("ru"), "Парк Горького", ());
  TEST_EQUAL(feature.GetName("No such language"), "", ());

  TEST_EQUAL(feature.GetTagValue("opening_hours"), "Mo-Fr 08:15-17:30", ());
  TEST_EQUAL(my::TimestampToString(feature.GetModificationTime()), "2015-11-27T21:13:32Z", ());

  TEST_EQUAL(feature.GetType(), "amenity|atm", ());
  TEST_EQUAL(feature.GetHeader(), 0xaf, ());
}