[locale] Additional test application for GeoIP processing
This commit is contained in:
parent
76e37402b3
commit
1340613ef5
@ -1,9 +1,8 @@
|
|||||||
find_package(ECM ${ECM_VERSION} NO_MODULE)
|
find_package(ECM ${ECM_VERSION} NO_MODULE)
|
||||||
if( ECM_FOUND )
|
if( ECM_FOUND AND BUILD_TESTING )
|
||||||
include( ECMAddTests )
|
include( ECMAddTests )
|
||||||
endif()
|
|
||||||
|
|
||||||
find_package( Qt5 COMPONENTS Core Test REQUIRED )
|
find_package( Qt5 COMPONENTS Core Test REQUIRED )
|
||||||
|
endif()
|
||||||
|
|
||||||
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
|
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ calamares_add_plugin( locale
|
|||||||
SHARED_LIB
|
SHARED_LIB
|
||||||
)
|
)
|
||||||
|
|
||||||
if( ECM_FOUND )
|
if( ECM_FOUND AND BUILD_TESTING )
|
||||||
ecm_add_test(
|
ecm_add_test(
|
||||||
GeoIPTests.cpp
|
GeoIPTests.cpp
|
||||||
${geoip_src}
|
${geoip_src}
|
||||||
@ -55,3 +54,8 @@ if( ECM_FOUND )
|
|||||||
)
|
)
|
||||||
set_target_properties( geoiptest PROPERTIES AUTOMOC TRUE )
|
set_target_properties( geoiptest PROPERTIES AUTOMOC TRUE )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if( BUILD_TESTING )
|
||||||
|
add_executable( test_geoip test_geoip.cpp ${geoip_src} )
|
||||||
|
target_link_libraries( test_geoip calamaresui Qt5::Network ${geoip_libs} ${YAMLCPP_LIBRARY} )
|
||||||
|
endif()
|
||||||
|
73
src/modules/locale/test_geoip.cpp
Normal file
73
src/modules/locale/test_geoip.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2018, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a test-application that does one GeoIP parse.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "GeoIPFreeGeoIP.h"
|
||||||
|
#ifdef HAVE_XML
|
||||||
|
#include "GeoIPXML.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using std::cerr;
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
cerr << "Usage: curl url | test_geoip <format>\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
GeoIP* handler = nullptr;
|
||||||
|
if ( QLatin1String( "json" ) == argv[1] )
|
||||||
|
handler = new FreeGeoIP;
|
||||||
|
#ifdef HAVE_XML
|
||||||
|
else if ( QLatin1String( "xml" ) == argv[1] )
|
||||||
|
handler = new XMLGeoIP;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ( !handler )
|
||||||
|
{
|
||||||
|
cerr << "Unknown format '" << argv[1] << "'\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray ba;
|
||||||
|
while( !std::cin.eof() ) {
|
||||||
|
char arr[1024];
|
||||||
|
std::cin.read(arr,sizeof(arr));
|
||||||
|
int s = std::cin.gcount();
|
||||||
|
ba.append(arr, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto tz = handler->processReply( ba );
|
||||||
|
if ( tz.first.isEmpty() )
|
||||||
|
{
|
||||||
|
std::cout << "No TimeZone determined from input.\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "TimeZone Region=" << tz.first.toLatin1().constData() << "\nTimeZone Zone=" << tz.second.toLatin1().constData() << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user