Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize unit tests 5722 #5724

Merged
merged 4 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2015-2023 Maxar (http://www.maxar.com/)
*/

// Hoot
#include <hoot/core/elements/OsmMap.h>
#include <hoot/core/TestUtils.h>
#include <hoot/core/algorithms/extractors/poi-polygon/PoiPolygonDistanceExtractor.h>
#include <hoot/core/conflate/poi-polygon/PoiPolygonInfoCache.h>
#include <hoot/core/elements/MapProjector.h>
#include <hoot/core/elements/OsmMap.h>
#include <hoot/core/elements/Way.h>
#include <hoot/core/io/OsmXmlReader.h>
#include <hoot/core/io/OsmXmlWriter.h>
#include <hoot/core/elements/MapProjector.h>
#include <hoot/core/conflate/poi-polygon/PoiPolygonInfoCache.h>

using namespace geos::geom;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2018, 2019, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2018-2023 Maxar (http://www.maxar.com/)
*/

// Hoot
Expand Down Expand Up @@ -53,8 +53,7 @@ class PoiPolygonPhoneNumberScoreExtractorTest : public HootTestFixture
PoiPolygonPhoneNumberScoreExtractor uut;
OsmMapPtr map = std::make_shared<OsmMap>();

NodePtr node1 =
std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
NodePtr node1 = std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
WayPtr way1 = std::make_shared<Way>(Status::Unknown2, -1, 15.0);

node1->getTags().set("phone", "(123) 456 7890");
Expand All @@ -67,8 +66,7 @@ class PoiPolygonPhoneNumberScoreExtractorTest : public HootTestFixture
PoiPolygonPhoneNumberScoreExtractor uut;
OsmMapPtr map = std::make_shared<OsmMap>();

NodePtr node1 =
std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
NodePtr node1 = std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
WayPtr way1 = std::make_shared<Way>(Status::Unknown2, -1, 15.0);

node1->getTags().set("phone", "(123) 456 7890");
Expand All @@ -90,8 +88,7 @@ class PoiPolygonPhoneNumberScoreExtractorTest : public HootTestFixture
PoiPolygonPhoneNumberScoreExtractor uut;
OsmMapPtr map = std::make_shared<OsmMap>();

NodePtr node1 =
std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
NodePtr node1 = std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
WayPtr way1 = std::make_shared<Way>(Status::Unknown2, -1, 15.0);

node1->getTags().set("phone", "blah");
Expand All @@ -104,8 +101,7 @@ class PoiPolygonPhoneNumberScoreExtractorTest : public HootTestFixture
PoiPolygonPhoneNumberScoreExtractor uut;
OsmMapPtr map = std::make_shared<OsmMap>();

NodePtr node1 =
std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
NodePtr node1 = std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
WayPtr way1 = std::make_shared<Way>(Status::Unknown2, -1, 15.0);

node1->getTags().set("source:phone", "(123) 456 7890");
Expand Down Expand Up @@ -133,8 +129,7 @@ class PoiPolygonPhoneNumberScoreExtractorTest : public HootTestFixture
PoiPolygonPhoneNumberScoreExtractor uut;
OsmMapPtr map = std::make_shared<OsmMap>();

NodePtr node1 =
std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
NodePtr node1 = std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
WayPtr way1 = std::make_shared<Way>(Status::Unknown2, -1, 15.0);

node1->getTags().set("note", "(123) 456 7890");
Expand All @@ -152,13 +147,10 @@ class PoiPolygonPhoneNumberScoreExtractorTest : public HootTestFixture
PoiPolygonPhoneNumberScoreExtractor uut;
OsmMapPtr map = std::make_shared<OsmMap>();

NodePtr node1 =
std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
NodePtr node1 = std::make_shared<Node>(Status::Unknown1, -1, geos::geom::Coordinate(0.0, 0.0), 15.0);
WayPtr way1 = std::make_shared<Way>(Status::Unknown2, -1, 15.0);

node1->getTags().set(
"phone",
"this is some text with a phone number: (123) 456 7890; and here's another one: 123 456 7890");
node1->getTags().set("phone", "this is some text with a phone number: (123) 456 7890; and here's another one: 123 456 7890");
way1->getTags().set("phone", "123 456 7890");

uut._phoneNumberParser.setRegionCode("US");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2018, 2019, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2018-2023 Maxar (http://www.maxar.com/)
*/

// hoot
Expand All @@ -34,6 +34,7 @@

// libphonenumber
#include <phonenumbers/phonenumberutil.h>

using namespace i18n::phonenumbers;

namespace hoot
Expand All @@ -51,10 +52,9 @@ class NormalizePhoneNumbersVisitorTest : public HootTestFixture

public:

NormalizePhoneNumbersVisitorTest() :
HootTestFixture(
"test-files/visitors/NormalizePhoneNumbersVisitorTest/",
"test-output/visitors/NormalizePhoneNumbersVisitorTest/")
NormalizePhoneNumbersVisitorTest()
: HootTestFixture("test-files/visitors/NormalizePhoneNumbersVisitorTest/",
"test-output/visitors/NormalizePhoneNumbersVisitorTest/")
{
}

Expand Down Expand Up @@ -109,24 +109,19 @@ class NormalizePhoneNumbersVisitorTest : public HootTestFixture
NormalizePhoneNumbersVisitor uut;

uut._phoneNumberNormalizer.setFormat("E164");
CPPUNIT_ASSERT_EQUAL(
PhoneNumberUtil::PhoneNumberFormat::E164, uut._phoneNumberNormalizer._format);
CPPUNIT_ASSERT_EQUAL(PhoneNumberUtil::PhoneNumberFormat::E164, uut._phoneNumberNormalizer._format);

uut._phoneNumberNormalizer.setFormat("INTERNATIONAL");
CPPUNIT_ASSERT_EQUAL(
PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL, uut._phoneNumberNormalizer._format);
CPPUNIT_ASSERT_EQUAL(PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL, uut._phoneNumberNormalizer._format);

uut._phoneNumberNormalizer.setFormat("NATIONAL");
CPPUNIT_ASSERT_EQUAL(
PhoneNumberUtil::PhoneNumberFormat::NATIONAL, uut._phoneNumberNormalizer._format);
CPPUNIT_ASSERT_EQUAL(PhoneNumberUtil::PhoneNumberFormat::NATIONAL, uut._phoneNumberNormalizer._format);

uut._phoneNumberNormalizer.setFormat("RFC3966");
CPPUNIT_ASSERT_EQUAL(
PhoneNumberUtil::PhoneNumberFormat::RFC3966, uut._phoneNumberNormalizer._format);
CPPUNIT_ASSERT_EQUAL(PhoneNumberUtil::PhoneNumberFormat::RFC3966, uut._phoneNumberNormalizer._format);

uut._phoneNumberNormalizer.setFormat("rfc3966");
CPPUNIT_ASSERT_EQUAL(
PhoneNumberUtil::PhoneNumberFormat::RFC3966, uut._phoneNumberNormalizer._format);
CPPUNIT_ASSERT_EQUAL(PhoneNumberUtil::PhoneNumberFormat::RFC3966, uut._phoneNumberNormalizer._format);

QString exceptionMsg;
try
Expand All @@ -137,8 +132,7 @@ class NormalizePhoneNumbersVisitorTest : public HootTestFixture
{
exceptionMsg = e.what();
}
CPPUNIT_ASSERT_EQUAL(
QString("Invalid phone number format: blah").toStdString(), exceptionMsg.toStdString());
CPPUNIT_ASSERT_EQUAL(QString("Invalid phone number format: blah").toStdString(), exceptionMsg.toStdString());
}

void runInvalidRegionCodeTest()
Expand All @@ -156,9 +150,7 @@ class NormalizePhoneNumbersVisitorTest : public HootTestFixture
{
exceptionMsg = e.what();
}
CPPUNIT_ASSERT_EQUAL(
QString("Empty phone number region code.").toStdString(),
exceptionMsg.toStdString());
CPPUNIT_ASSERT_EQUAL(QString("Empty phone number region code.").toStdString(), exceptionMsg.toStdString());

try
{
Expand All @@ -168,9 +160,7 @@ class NormalizePhoneNumbersVisitorTest : public HootTestFixture
{
exceptionMsg = e.what();
}
CPPUNIT_ASSERT_EQUAL(
QString("Invalid phone number region code: BLAH").toStdString(),
exceptionMsg.toStdString());
CPPUNIT_ASSERT_EQUAL(QString("Invalid phone number region code: BLAH").toStdString(), exceptionMsg.toStdString());
}

void runConfigureTest()
Expand Down Expand Up @@ -203,5 +193,3 @@ class NormalizePhoneNumbersVisitorTest : public HootTestFixture
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NormalizePhoneNumbersVisitorTest, "quick");

}


Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2018, 2019, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2018-2023 Maxar (http://www.maxar.com/)
*/

// hoot
Expand All @@ -43,8 +43,8 @@ class PhoneNumberCountVisitorTest : public HootTestFixture

public:

PhoneNumberCountVisitorTest() :
HootTestFixture("test-files/cmd/glacial/PoiPolygonConflateStandaloneTest/", UNUSED_PATH)
PhoneNumberCountVisitorTest()
: HootTestFixture("test-files/cmd/glacial/PoiPolygonConflateStandaloneTest/", UNUSED_PATH)
{
}

Expand All @@ -69,7 +69,7 @@ class PhoneNumberCountVisitorTest : public HootTestFixture
settings.set(ConfigOptions::getPhoneNumberRegionCodeKey(), "US");
settings.set(ConfigOptions::getPhoneNumberAdditionalTagKeysKey(), QStringList());
settings.set(ConfigOptions::getPhoneNumberSearchInTextKey(), false);
uut.setConfiguration(/*conf()*/settings);
uut.setConfiguration(settings);

map->visitRo(uut);

Expand All @@ -80,5 +80,3 @@ class PhoneNumberCountVisitorTest : public HootTestFixture
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PhoneNumberCountVisitorTest, "quick");

}


Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2018, 2019, 2021 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2018-2023 Maxar (http://www.maxar.com/)
*/

// hoot
#include <hoot/core/elements/OsmMap.h>
#include <hoot/core/TestUtils.h>
#include <hoot/core/elements/OsmMap.h>
#include <hoot/core/io/OsmMapReaderFactory.h>
#include <hoot/core/io/OsmMapWriterFactory.h>
#include <hoot/core/visitors/PhoneNumberLocateVisitor.h>
Expand All @@ -46,59 +46,49 @@ class PhoneNumberLocateVisitorTest : public HootTestFixture

public:

PhoneNumberLocateVisitorTest() :
HootTestFixture(
"test-files/visitors/PhoneNumberLocateVisitorTest/",
"test-output/visitors/PhoneNumberLocateVisitorTest/")
PhoneNumberLocateVisitorTest()
: HootTestFixture("test-files/visitors/PhoneNumberLocateVisitorTest/",
"test-output/visitors/PhoneNumberLocateVisitorTest/")
{
setResetType(ResetEnvironment);
}

void runBasicTest()
{
OsmMapPtr map = std::make_shared<OsmMap>();
OsmMapReaderFactory::read(
map,
"test-files/cmd/glacial/PoiPolygonConflateStandaloneTest/PoiPolygon2.osm",
false,
Status::Unknown1);
OsmMapReaderFactory::read(map, _inputPath + "BasicTest.osm", false, Status::Unknown1);

PhoneNumberLocateVisitor uut;
uut._phoneNumberLocator.setRegionCode("US");
map->visitRw(uut);

const QString outputFile = _outputPath + "out.osm";
const QString outputFile = _outputPath + "BasicTestOutput.osm";
OsmMapWriterFactory::write(map, outputFile);

CPPUNIT_ASSERT_EQUAL(12, uut._phoneNumberLocator.getNumLocated());
HOOT_FILE_EQUALS(_inputPath + "gold.osm", outputFile);
HOOT_FILE_EQUALS(_inputPath + "BasicTestExpected.osm", outputFile);
}

void runConfigurationTest()
{
OsmMapPtr map = std::make_shared<OsmMap>();
OsmMapReaderFactory::read(
map,
"test-files/cmd/glacial/PoiPolygonConflateStandaloneTest/PoiPolygon2.osm",
false,
Status::Unknown1);
OsmMapReaderFactory::read(map, _inputPath + "ConfigTest.osm", false, Status::Unknown1);

PhoneNumberLocateVisitor uut;
Settings settings;
settings.set(ConfigOptions::getPhoneNumberRegionCodeKey(), "US");
uut.setConfiguration(settings);
map->visitRw(uut);

const QString outputFile = _outputPath + "out.osm";
const QString outputFile = _outputPath + "ConfigTestOutput.osm";
OsmMapWriterFactory::write(map, outputFile);

CPPUNIT_ASSERT_EQUAL(12, uut._phoneNumberLocator.getNumLocated());
HOOT_FILE_EQUALS(_inputPath + "gold.osm", outputFile);
HOOT_FILE_EQUALS(_inputPath + "ConfigTestExpected.osm", outputFile);
}
};

CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PhoneNumberLocateVisitorTest, "quick");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PhoneNumberLocateVisitorTest, "serial");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2018, 2019, 2021, 2022 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2018-2023 Maxar (http://www.maxar.com/)
*/

#include "PoiPolygonPhoneNumberScoreExtractor.h"
Expand Down Expand Up @@ -72,9 +72,8 @@ double PoiPolygonPhoneNumberScoreExtractor::extract(const OsmMap& /*map*/,
for (const auto& polyNumber : qAsConst(polyPhoneNumbers))
{
_matchAttemptMade = true;
PhoneNumberUtil::MatchType numberMatchType =
PhoneNumberUtil::GetInstance()->IsNumberMatchWithTwoStrings(
poiNumber.tagValue.toStdString(), polyNumber.tagValue.toStdString());
std::lock_guard<std::mutex> libphonenumber_lock(getPhoneNumberMutex());
PhoneNumberUtil::MatchType numberMatchType = PhoneNumberUtil::GetInstance()->IsNumberMatchWithTwoStrings(poiNumber.tagValue.toStdString(), polyNumber.tagValue.toStdString());
LOG_VART(numberMatchType);
if (numberMatchType > PhoneNumberUtil::MatchType::NO_MATCH)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
* This will properly maintain the copyright information. Maxar
* copyrights will be updated automatically.
*
* @copyright Copyright (C) 2018, 2019, 2020, 2021, 2022 Maxar (http://www.maxar.com/)
* @copyright Copyright (C) 2018-2023 Maxar (http://www.maxar.com/)
*/

#ifndef POIPOLYGONPHONENUMBERSCOREEXTRACTOR_H
#define POIPOLYGONPHONENUMBERSCOREEXTRACTOR_H

// hoot
#include <hoot/core/algorithms/extractors/FeatureExtractorBase.h>
#include <hoot/core/util/Configurable.h>
#include <hoot/core/conflate/phone/PhoneNumberBase.h>
#include <hoot/core/conflate/phone/PhoneNumberParser.h>
#include <hoot/core/util/Configurable.h>

namespace hoot
{
Expand All @@ -42,7 +43,7 @@ class OsmMap;
* @brief The PoiPolygonPhoneNumberScoreExtractor class scores phone number similarity between
* features for POI to Polygon conflation.
*/
class PoiPolygonPhoneNumberScoreExtractor : public FeatureExtractorBase, public Configurable
class PoiPolygonPhoneNumberScoreExtractor : public PhoneNumberBase, public FeatureExtractorBase, public Configurable
{
public:

Expand Down
Loading