MCPcopy Create free account
hub / github.com/comaps/comaps / TestRestrictionBuilding

Function TestRestrictionBuilding

generator/generator_tests/restriction_test.cpp:137–187  ·  view source on GitHub ↗

\brief Generates a restriction section, adds it to an empty mwm, loads the restriction section and test loaded restrictions. \param |restrictionPath| comma separated text with restrictions in osm id terms. \param |osmIdsToFeatureIdContent| comma separated text with mapping from osm ids to feature ids.

Source from the content-addressed store, hash-verified

135/// \param |restrictionPath| comma separated text with restrictions in osm id terms.
136/// \param |osmIdsToFeatureIdContent| comma separated text with mapping from osm ids to feature ids.
137void TestRestrictionBuilding(string const & restrictionPath, string const & osmIdsToFeatureIdContent,
138 unique_ptr<IndexGraph> graph, vector<Restriction> & expectedNotUTurn,
139 vector<RestrictionUTurnForTests> & expectedUTurn)
140{
141 Platform & platform = GetPlatform();
142 string const writableDir = platform.WritableDir();
143
144 string const targetDir = base::JoinPath(writableDir, kTestDir);
145 // Building empty mwm.
146 LocalCountryFile country(targetDir, CountryFile(kTestMwm), 0 /* version */);
147 ScopedDir const scopedDir(kTestDir);
148 string const mwmRelativePath = base::JoinPath(kTestDir, kTestMwm + DATA_FILE_EXTENSION);
149 ScopedFile const scopedMwm(mwmRelativePath, ScopedFile::Mode::Create);
150 BuildEmptyMwm(country);
151
152 // Creating a file with restrictions.
153 string const restrictionRelativePath = base::JoinPath(kTestDir, kRestrictionFileName);
154 ScopedFile const restrictionScopedFile(restrictionRelativePath, restrictionPath);
155
156 // Creating osm ids to feature ids mapping.
157 string const mappingRelativePath = base::JoinPath(kTestDir, kOsmIdsToFeatureIdsName);
158 ScopedFile const mappingFile(mappingRelativePath, ScopedFile::Mode::Create);
159 string const & osmIdsToFeatureIdFullPath = mappingFile.GetFullPath();
160 ReEncodeOsmIdsToFeatureIdsMapping(osmIdsToFeatureIdContent, osmIdsToFeatureIdFullPath);
161
162 string const restrictionFullPath = base::JoinPath(writableDir, restrictionRelativePath);
163 string const & mwmFullPath = scopedMwm.GetFullPath();
164
165 // Prepare data to collector.
166 auto restrictionCollector =
167 std::make_unique<routing_builder::RestrictionCollector>(osmIdsToFeatureIdFullPath, *graph);
168
169 TEST(restrictionCollector->Process(restrictionFullPath), ("Bad restrictions were given."));
170
171 // Adding restriction section to mwm.
172 SerializeRestrictions(*restrictionCollector, mwmFullPath);
173
174 // Reading from mwm section and testing restrictions.
175 vector<Restriction> restrictionsFromMwm;
176 vector<RestrictionUTurnForTests> restrictionsUTurnFromMwm;
177 LoadRestrictions(mwmFullPath, restrictionsFromMwm, restrictionsUTurnFromMwm);
178
179 sort(restrictionsFromMwm.begin(), restrictionsFromMwm.end());
180 sort(restrictionsUTurnFromMwm.begin(), restrictionsUTurnFromMwm.end());
181
182 sort(expectedNotUTurn.begin(), expectedNotUTurn.end());
183 sort(expectedUTurn.begin(), expectedUTurn.end());
184
185 TEST_EQUAL(restrictionsFromMwm, expectedNotUTurn, ());
186 TEST_EQUAL(restrictionsUTurnFromMwm, expectedUTurn, ());
187}
188
189// 2 *
190// ↗ ↘

Callers 1

UNIT_TESTFunction · 0.85

Calls 10

JoinPathFunction · 0.85
TESTFunction · 0.85
SerializeRestrictionsFunction · 0.85
LoadRestrictionsFunction · 0.85
BuildEmptyMwmFunction · 0.70
CountryFileClass · 0.50
ProcessMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected