1/* 2 * Copyright 2014, Haiku, inc. 3 * Distributed under the terms of the MIT licence 4 */ 5 6 7#include "GeolocationTest.h" 8 9#include <Geolocation.h> 10 11#include <cppunit/TestCaller.h> 12#include <cppunit/TestSuite.h> 13 14 15using namespace BPrivate::Network; 16 17 18GeolocationTest::GeolocationTest() 19{ 20} 21 22 23void 24GeolocationTest::TestLocateSelf() 25{ 26 BGeolocation locator(BUrl( 27 "https://location.services.mozilla.com/v1/geolocate?key=test"), BUrl()); 28 float latitude, longitude; 29 status_t result = locator.LocateSelf(latitude, longitude); 30 31 CPPUNIT_ASSERT_EQUAL(B_OK, result); 32 printf("Your position is: %f %f\n", latitude, longitude); 33} 34 35 36void 37GeolocationTest::TestCountry() 38{ 39 BGeolocation geocoder(BUrl(""), BUrl("https://secure.geonames.org/?username=demo")); 40 BCountry country; 41 status_t result = geocoder.Country(47.03f, 10.2f, country); 42 CPPUNIT_ASSERT_EQUAL(B_OK, result); 43 CPPUNIT_ASSERT_EQUAL(B_OK, country.InitCheck()); 44 CPPUNIT_ASSERT_EQUAL(BString("AT"), BString(country.Code())); 45} 46 47 48/* static */ void 49GeolocationTest::AddTests(BTestSuite& parent) 50{ 51 CppUnit::TestSuite& suite = *new CppUnit::TestSuite("GeolocationTest"); 52 53 suite.addTest(new CppUnit::TestCaller<GeolocationTest>( 54 "GeolocationTest::LocateSelf", &GeolocationTest::TestLocateSelf)); 55 suite.addTest(new CppUnit::TestCaller<GeolocationTest>( 56 "GeolocationTest::Country", &GeolocationTest::TestCountry)); 57 58 parent.addTest("GeolocationTest", &suite); 59}; 60