diff --git a/.travis.yml b/.travis.yml index dd28c8b..fb54809 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,26 @@ -sudo: false +sudo: true language: cpp compiler: - gcc os: - linux +before_install: +- sudo apt-add-repository ppa:bruun/hayai -y +- sudo apt-get update +- sudo apt-get install libhayai-dev +install: +- CURRENT=`pwd` +- sudo apt-get install libgtest-dev +- cd /usr/src/gtest +- sudo cmake CMakeLists.txt +- sudo make +- sudo cp *.a /usr/lib +- cd $CURRENT +#before_script: +#- sudo apt-get install valgrind script: - cmake . - make all +- cd test && ctest . diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f59bf5..a01ff25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,10 +7,12 @@ set (CPPROUTE4ME_VERSION_MINOR 0) # Checking for dependencies FIND_PACKAGE(CURL REQUIRED) +FIND_PACKAGE(GTest REQUIRED) # Set up include pathes INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${CPPROUTE4ME_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) # Set up output paths set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) @@ -18,4 +20,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) # Set up source directories ADD_SUBDIRECTORY(src bin) -ADD_SUBDIRECTORY(test test) \ No newline at end of file +ADD_SUBDIRECTORY(examples examples) +ADD_SUBDIRECTORY(test test) +ADD_SUBDIRECTORY(benchmarks benchmarks) diff --git a/benchmarks/ActivitiesBenchmark.cpp b/benchmarks/ActivitiesBenchmark.cpp new file mode 100644 index 0000000..39bfea8 --- /dev/null +++ b/benchmarks/ActivitiesBenchmark.cpp @@ -0,0 +1,31 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(ActivitiesFixture, ActivitiesTest, 10, 10) +{ + pRoute->get_all_activities(); +} + +BENCHMARK(ActivitiesFixture, ActivitiesByTeam, 10, 10) +{ + const char *route_id = "CA902292134DBC134EAF8363426BD247"; + pRoute->get_team_activities(route_id); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/AddressBookBenchmark.cpp b/benchmarks/AddressBookBenchmark.cpp new file mode 100644 index 0000000..df18d61 --- /dev/null +++ b/benchmarks/AddressBookBenchmark.cpp @@ -0,0 +1,31 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(AddressBookFixture, GetAllContacts, 10, 10) +{ + pRoute->get_address_book_contacts(); +} + +BENCHMARK(AddressBookFixture, GetOneContact, 10, 10) +{ + const char *id = "Wall"; + int ret = pRoute->get_address_book_contacts_by_text(id); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/AvoidanceZonesBenchmark.cpp b/benchmarks/AvoidanceZonesBenchmark.cpp new file mode 100644 index 0000000..b3eec59 --- /dev/null +++ b/benchmarks/AvoidanceZonesBenchmark.cpp @@ -0,0 +1,25 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(AvoidanceZonesFixture, GetAllZones, 10, 10) +{ + pRoute->get_avoidance_zones(); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt new file mode 100644 index 0000000..2ea51cb --- /dev/null +++ b/benchmarks/CMakeLists.txt @@ -0,0 +1,42 @@ + +ADD_EXECUTABLE(ActivitiesBenchmark ActivitiesBenchmark.cpp) +TARGET_LINK_LIBRARIES(ActivitiesBenchmark route4me) + +ADD_EXECUTABLE(OptimizationBenchmark OptimizationBenchmark.cpp) +TARGET_LINK_LIBRARIES(OptimizationBenchmark route4me) + +ADD_EXECUTABLE(AddressBookBenchmark AddressBookBenchmark.cpp) +TARGET_LINK_LIBRARIES(AddressBookBenchmark route4me) + +ADD_EXECUTABLE(ConfigBenchmark ConfigBenchmark.cpp) +TARGET_LINK_LIBRARIES(ConfigBenchmark route4me) + +ADD_EXECUTABLE(GeocoderBenchmark GeocoderBenchmark.cpp) +TARGET_LINK_LIBRARIES(GeocoderBenchmark route4me) + +ADD_EXECUTABLE(GPSBenchmark GPSBenchmark.cpp) +TARGET_LINK_LIBRARIES(GPSBenchmark route4me) + +ADD_EXECUTABLE(NotesBenchmark NotesBenchmark.cpp) +TARGET_LINK_LIBRARIES(NotesBenchmark route4me) + +ADD_EXECUTABLE(OrdersBenchmark OrdersBenchmark.cpp) +TARGET_LINK_LIBRARIES(OrdersBenchmark route4me) + +ADD_EXECUTABLE(RoutesBenchmark RoutesBenchmark.cpp) +TARGET_LINK_LIBRARIES(RoutesBenchmark route4me) + +ADD_EXECUTABLE(SessionBenchmark SessionBenchmark.cpp) +TARGET_LINK_LIBRARIES(SessionBenchmark route4me) + +ADD_EXECUTABLE(StreetsBenchmark StreetsBenchmark.cpp) +TARGET_LINK_LIBRARIES(StreetsBenchmark route4me) + +ADD_EXECUTABLE(TerritoriesBenchmark TerritoriesBenchmark.cpp) +TARGET_LINK_LIBRARIES(TerritoriesBenchmark route4me) + +ADD_EXECUTABLE(TrackingBenchmark TrackingBenchmark.cpp) +TARGET_LINK_LIBRARIES(TrackingBenchmark route4me) + +ADD_EXECUTABLE(UsersBenchmark UsersBenchmark.cpp) +TARGET_LINK_LIBRARIES(UsersBenchmark route4me) diff --git a/benchmarks/ConfigBenchmark.cpp b/benchmarks/ConfigBenchmark.cpp new file mode 100644 index 0000000..9699f27 --- /dev/null +++ b/benchmarks/ConfigBenchmark.cpp @@ -0,0 +1,25 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(ConfigFixture, GetAllConfigs, 10, 10) +{ + pRoute->get_config(); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/GPSBenchmark.cpp b/benchmarks/GPSBenchmark.cpp new file mode 100644 index 0000000..fac28e2 --- /dev/null +++ b/benchmarks/GPSBenchmark.cpp @@ -0,0 +1,36 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(GPSFixture, Set, 10, 10) +{ + Json::Value params(Json::objectValue); + params["route_id"] = "AC16E7D338B551013FF34266FE81A5EE"; + params["format"] = CRoute4Me::Csv; + params["lat"] = 33.14384; + params["lng"] = -83.22466; + params["course"] = 1; + params["speed"] = 120; + params["device_type"] = CRoute4Me::IPhone; + params["device_guid"] = "TEST_GPS"; + params["device_timestamp"] = "2014-06-14 17:43:35"; + params["member_id"] = 1; + int ret = pRoute->set_gps(params); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/GeocoderBenchmark.cpp b/benchmarks/GeocoderBenchmark.cpp new file mode 100644 index 0000000..5d213f4 --- /dev/null +++ b/benchmarks/GeocoderBenchmark.cpp @@ -0,0 +1,34 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(GeocoderFixture, BatchGeocoding, 10, 10) +{ + const char* addrs = "Los20%Angeles20%International20%Airport,20%CA"; + const char* format = "json"; + int ret = pRoute->batch_geocoding(addrs, format); +} + +BENCHMARK(GeocoderFixture, ReverseGeocoding, 10, 10) +{ + const char* addrs = "33.945705,-118.391105"; + const char* format = "json"; + int ret = pRoute->reverse_geocoding(addrs, format); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/NotesBenchmark.cpp b/benchmarks/NotesBenchmark.cpp new file mode 100644 index 0000000..9364f29 --- /dev/null +++ b/benchmarks/NotesBenchmark.cpp @@ -0,0 +1,27 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(AddressBookFixture, GetAllContacts, 10, 10) +{ + const char *route_id = "CA902292134DBC134EAF8363426BD247"; + const char *route_destination_id = "174405709A"; + pRoute->get_route_notes(route_id, route_destination_id); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/OptimizationBenchmark.cpp b/benchmarks/OptimizationBenchmark.cpp new file mode 100644 index 0000000..7720567 --- /dev/null +++ b/benchmarks/OptimizationBenchmark.cpp @@ -0,0 +1,32 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(OptimizationFixture, GetOptimization, 10, 10) +{ + const char *id = "2FB5F91365317758045DB9F19DF5A522"; + pRoute->get_optimization(id); +} + +BENCHMARK(OptimizationFixture, Reoptimize, 10, 10) +{ + const char *id = "c46648541ca5d716a31ffae6f405a37d"; + int ret = pRoute->reoptimize(id); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/OrdersBenchmark.cpp b/benchmarks/OrdersBenchmark.cpp new file mode 100644 index 0000000..e4d933f --- /dev/null +++ b/benchmarks/OrdersBenchmark.cpp @@ -0,0 +1,25 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(OrdersFixture, GetAllOrders, 10, 10) +{ + pRoute->get_all_orders(); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/RoutesBenchmark.cpp b/benchmarks/RoutesBenchmark.cpp new file mode 100644 index 0000000..8fdbc02 --- /dev/null +++ b/benchmarks/RoutesBenchmark.cpp @@ -0,0 +1,41 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; +const char *route_id = "CA902292134DBC134EAF8363426BD247"; + +BENCHMARK(RoutesFixture, GetAllRoutes, 10, 10) +{ + pRoute->get_multiple_routes(); +} + +BENCHMARK(RoutesFixture, ByPointPath, 10, 10) +{ + int ret = pRoute->get_route_path_points(route_id, "Points"); +} + +BENCHMARK(RoutesFixture, ByiD, 10, 10) +{ + int ret = pRoute->get_route_by_id(route_id); +} + +BENCHMARK(RoutesFixture, ByDirection, 10, 10) +{ + int ret = pRoute->get_route_directions(route_id, 1); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/SessionBenchmark.cpp b/benchmarks/SessionBenchmark.cpp new file mode 100644 index 0000000..a87296a --- /dev/null +++ b/benchmarks/SessionBenchmark.cpp @@ -0,0 +1,27 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(SessionFixture, Validate, 10, 10) +{ + const char* session_id="4552222222"; + const char* member_id="787544566"; + int ret = pRoute->validate_session(session_id, member_id); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/StreetsBenchmark.cpp b/benchmarks/StreetsBenchmark.cpp new file mode 100644 index 0000000..5e781aa --- /dev/null +++ b/benchmarks/StreetsBenchmark.cpp @@ -0,0 +1,31 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(StreetsFixture, GetAllStreets, 10, 10) +{ + pRoute->get_all_streets(); +} + +BENCHMARK(StreetsFixture, GetOneStreet, 10, 10) +{ + int seqno = 1; + int ret = pRoute->get_street_address(seqno); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/TerritoriesBenchmark.cpp b/benchmarks/TerritoriesBenchmark.cpp new file mode 100644 index 0000000..e4f6e30 --- /dev/null +++ b/benchmarks/TerritoriesBenchmark.cpp @@ -0,0 +1,25 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(TerritoriesFixture, GetAllTerritories, 10, 10) +{ + pRoute->get_all_territories(); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/TrackingBenchmark.cpp b/benchmarks/TrackingBenchmark.cpp new file mode 100644 index 0000000..bc45fdf --- /dev/null +++ b/benchmarks/TrackingBenchmark.cpp @@ -0,0 +1,26 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(TrackingFixture, Track, 10, 10) +{ + const char *id = "Q7G9P1L9"; + int ret = pRoute->asset_tracking(id); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/benchmarks/UsersBenchmark.cpp b/benchmarks/UsersBenchmark.cpp new file mode 100644 index 0000000..2caf16b --- /dev/null +++ b/benchmarks/UsersBenchmark.cpp @@ -0,0 +1,25 @@ +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +BENCHMARK(UsersFixture, GetAllUsers, 10, 10) +{ + pRoute->get_users(); +} + +int main() +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + hayai::ConsoleOutputter consoleOutputter; + + hayai::Benchmarker::AddOutputter(consoleOutputter); + hayai::Benchmarker::RunAllTests(); + + pRoute->cleanup(); + return 0; +} diff --git a/test/Activities.cpp b/examples/Activities.cpp similarity index 100% rename from test/Activities.cpp rename to examples/Activities.cpp diff --git a/test/ActivitiesByType.cpp b/examples/ActivitiesByType.cpp similarity index 100% rename from test/ActivitiesByType.cpp rename to examples/ActivitiesByType.cpp diff --git a/examples/ActivitiesTest.cpp b/examples/ActivitiesTest.cpp new file mode 100644 index 0000000..c30b5eb --- /dev/null +++ b/examples/ActivitiesTest.cpp @@ -0,0 +1,21 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +TEST(ActvitiesTest, GetAll) +{ + CRoute4Me::init(); + CRoute4Me route(KEY); + int ret = route.get_all_activities(); + ASSERT_EQ(0, ret); + route.cleanup(); +} + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + return 0; +} diff --git a/test/AddAddressToOptimization.cpp b/examples/AddAddressToOptimization.cpp similarity index 100% rename from test/AddAddressToOptimization.cpp rename to examples/AddAddressToOptimization.cpp diff --git a/test/AddConfig.cpp b/examples/AddConfig.cpp similarity index 100% rename from test/AddConfig.cpp rename to examples/AddConfig.cpp diff --git a/test/AddOrder.cpp b/examples/AddOrder.cpp similarity index 100% rename from test/AddOrder.cpp rename to examples/AddOrder.cpp diff --git a/test/AddressBook.cpp b/examples/AddressBook.cpp similarity index 100% rename from test/AddressBook.cpp rename to examples/AddressBook.cpp diff --git a/test/AssetTracking.cpp b/examples/AssetTracking.cpp similarity index 100% rename from test/AssetTracking.cpp rename to examples/AssetTracking.cpp diff --git a/test/AvoidanceZones.cpp b/examples/AvoidanceZones.cpp similarity index 100% rename from test/AvoidanceZones.cpp rename to examples/AvoidanceZones.cpp diff --git a/test/BatchGeocoding.cpp b/examples/BatchGeocoding.cpp similarity index 100% rename from test/BatchGeocoding.cpp rename to examples/BatchGeocoding.cpp diff --git a/examples/BulkGeocoding.cpp b/examples/BulkGeocoding.cpp new file mode 100644 index 0000000..c2108d3 --- /dev/null +++ b/examples/BulkGeocoding.cpp @@ -0,0 +1,37 @@ +#include +#include +#include "../include/route4me.h" + +#define KEY "11111111111111111111111111111111" + +using namespace std; + +int main() +{ + // global init + CRoute4Me::init(); + + CRoute4Me route(KEY, true); + + ifstream inf("bulk_geocoding_data.json"); + if(!inf.is_open()) { + cout << "Cannot find file bulk_geocoding_data.json" << endl; + return -1; + } + Json::Value data; + inf >> data; + + if(route.json_geocoding(data) == 0) + { + cout << "Geocoding done:" << endl << Json::FastWriter().write(route.get_json_resp()) << endl; + } + else + { + cout << "Geocoding failed: " << route.get_err_code() << ": " << route.get_err_msg() << endl; + } + + // global cleanup + CRoute4Me::cleanup(); + + return 0; +} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..04ca74e --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,177 @@ +ADD_EXECUTABLE(RouteManifest RouteManifest.cpp) +TARGET_LINK_LIBRARIES(RouteManifest route4me) + +ADD_EXECUTABLE(GetRoute GetRoute.cpp) +TARGET_LINK_LIBRARIES(GetRoute route4me) + +ADD_EXECUTABLE(DuplicateRoute DuplicateRoute.cpp) +TARGET_LINK_LIBRARIES(DuplicateRoute route4me) + +ADD_EXECUTABLE(GetRouteByPoints GetRouteByPoints.cpp) +TARGET_LINK_LIBRARIES(GetRouteByPoints route4me) + +ADD_EXECUTABLE(GetRouteByDirections GetRouteByDirections.cpp) +TARGET_LINK_LIBRARIES(GetRouteByDirections route4me) + +ADD_EXECUTABLE(GetRouteByText GetRouteByText.cpp) +TARGET_LINK_LIBRARIES(GetRouteByText route4me) + +ADD_EXECUTABLE(UpdateRoute UpdateRoute.cpp) +TARGET_LINK_LIBRARIES(UpdateRoute route4me) + +ADD_EXECUTABLE(RouteDestinations RouteDestinations.cpp) +TARGET_LINK_LIBRARIES(RouteDestinations route4me) + +ADD_EXECUTABLE(AddressBook AddressBook.cpp) +TARGET_LINK_LIBRARIES(AddressBook route4me) + +ADD_EXECUTABLE(Notes Notes.cpp) +TARGET_LINK_LIBRARIES(Notes route4me) + +ADD_EXECUTABLE(Users Users.cpp) +TARGET_LINK_LIBRARIES(Users route4me) + +ADD_EXECUTABLE(Orders Orders.cpp) +TARGET_LINK_LIBRARIES(Orders route4me) + +ADD_EXECUTABLE(GetOrders GetOrdersByDate.cpp) +TARGET_LINK_LIBRARIES(GetOrders route4me) + +ADD_EXECUTABLE(GetCustomOrders GetCustomOrders.cpp) +TARGET_LINK_LIBRARIES(GetCustomOrders route4me) + +ADD_EXECUTABLE(GetOrdersQuery GetOrdersQuery.cpp) +TARGET_LINK_LIBRARIES(GetOrdersQuery route4me) + +ADD_EXECUTABLE(AddOrder AddOrder.cpp) +TARGET_LINK_LIBRARIES(AddOrder route4me) + +ADD_EXECUTABLE(TeamActivities TeamActivities.cpp) +TARGET_LINK_LIBRARIES(TeamActivities route4me) + +ADD_EXECUTABLE(LogActivities LogActivities.cpp) +TARGET_LINK_LIBRARIES(LogActivities route4me) + +ADD_EXECUTABLE(Activities Activities.cpp) +TARGET_LINK_LIBRARIES(Activities route4me) + +ADD_EXECUTABLE(Zones AvoidanceZones.cpp) +TARGET_LINK_LIBRARIES(Zones route4me) + +ADD_EXECUTABLE(Territory Territory.cpp) +TARGET_LINK_LIBRARIES(Territory route4me) + +ADD_EXECUTABLE(GetAllRoutes GetMultipleRoutes.cpp) +TARGET_LINK_LIBRARIES(GetAllRoutes route4me) + +ADD_EXECUTABLE(RouteStatus RouteStatus.cpp) +TARGET_LINK_LIBRARIES(RouteStatus route4me) + +ADD_EXECUTABLE(DeleteRoute DeleteRoute.cpp) +TARGET_LINK_LIBRARIES(DeleteRoute route4me) + +ADD_EXECUTABLE(SetGPSPosition SetGPSPosition.cpp) +TARGET_LINK_LIBRARIES(SetGPSPosition route4me) + +ADD_EXECUTABLE(TrackDeviceLastLocationHistory TrackDeviceLastLocationHistory.cpp) +TARGET_LINK_LIBRARIES(TrackDeviceLastLocationHistory route4me) + +ADD_EXECUTABLE(SingleDriverRoundTrip SingleDriverRoundTrip.cpp) +TARGET_LINK_LIBRARIES(SingleDriverRoundTrip route4me) + +ADD_EXECUTABLE(SingleDriverRoute10Stops SingleDriverRoute10Stops.cpp) +TARGET_LINK_LIBRARIES(SingleDriverRoute10Stops route4me) + +ADD_EXECUTABLE(MultipleDepotMultipleDriver MultipleDepotMultipleDriver.cpp) +TARGET_LINK_LIBRARIES(MultipleDepotMultipleDriver route4me) + +ADD_EXECUTABLE(MultipleDepotMultipleDriverTimeWindows MultipleDepotMultipleDriverTimeWindows.cpp) +TARGET_LINK_LIBRARIES(MultipleDepotMultipleDriverTimeWindows route4me) + +ADD_EXECUTABLE(ReOptimization ReOptimization.cpp) +TARGET_LINK_LIBRARIES(ReOptimization route4me) + +ADD_EXECUTABLE(GetOptimization GetOptimization.cpp) +TARGET_LINK_LIBRARIES(GetOptimization route4me) + +ADD_EXECUTABLE(GetOptimizations GetOptimizations.cpp) +TARGET_LINK_LIBRARIES(GetOptimizations route4me) + +ADD_EXECUTABLE(RemoveOptimization RemoveOptimization.cpp) +TARGET_LINK_LIBRARIES(RemoveOptimization route4me) + +ADD_EXECUTABLE(OptimizeAndReoptimize OptimizeAndReoptimize.cpp) +TARGET_LINK_LIBRARIES(OptimizeAndReoptimize route4me) + +ADD_EXECUTABLE(Login Login.cpp) +TARGET_LINK_LIBRARIES(Login route4me) + +ADD_EXECUTABLE(Register Register.cpp) +TARGET_LINK_LIBRARIES(Register route4me) + +ADD_EXECUTABLE(EditMember EditMember.cpp) +TARGET_LINK_LIBRARIES(EditMember route4me) + +ADD_EXECUTABLE(DeleteMember DeleteMember.cpp) +TARGET_LINK_LIBRARIES(DeleteMember route4me) + +ADD_EXECUTABLE(ActivitiesByType ActivitiesByType.cpp) +TARGET_LINK_LIBRARIES(ActivitiesByType route4me) + +ADD_EXECUTABLE(AssetTracking AssetTracking.cpp) +TARGET_LINK_LIBRARIES(AssetTracking route4me) + +ADD_EXECUTABLE(GetLocationHistory GetLocationHistory.cpp) +TARGET_LINK_LIBRARIES(GetLocationHistory route4me) + +ADD_EXECUTABLE(AddAddressToOptimization AddAddressToOptimization.cpp) +TARGET_LINK_LIBRARIES(AddAddressToOptimization route4me) + +ADD_EXECUTABLE(MergeRoutes MergeRoutes.cpp) +TARGET_LINK_LIBRARIES(MergeRoutes route4me) + +ADD_EXECUTABLE(ShareRoutes ShareRoutes.cpp) +TARGET_LINK_LIBRARIES(ShareRoutes route4me) + +ADD_EXECUTABLE(BatchGeocoding BatchGeocoding.cpp) +TARGET_LINK_LIBRARIES(BatchGeocoding route4me) + +ADD_EXECUTABLE(ReverseGeocoding ReverseGeocoding.cpp) +TARGET_LINK_LIBRARIES(ReverseGeocoding route4me) + +ADD_EXECUTABLE(GetSingleStreet GetSingleStreet.cpp) +TARGET_LINK_LIBRARIES(GetSingleStreet route4me) + +ADD_EXECUTABLE(GetAllStreets GetAllStreets.cpp) +TARGET_LINK_LIBRARIES(GetAllStreets route4me) + +ADD_EXECUTABLE(GetStreetsLimited GetStreetsLimited.cpp) +TARGET_LINK_LIBRARIES(GetStreetsLimited route4me) + +ADD_EXECUTABLE(GetStreetsZipHouse GetStreetsZipHouse.cpp) +TARGET_LINK_LIBRARIES(GetStreetsZipHouse route4me) + +ADD_EXECUTABLE(PurchaseLicense PurchaseLicense.cpp) +TARGET_LINK_LIBRARIES(PurchaseLicense route4me) + +ADD_EXECUTABLE(GetSubUsers GetSubUsers.cpp) +TARGET_LINK_LIBRARIES(GetSubUsers route4me) + +ADD_EXECUTABLE(ValidateSession ValidateSession.cpp) +TARGET_LINK_LIBRARIES(ValidateSession route4me) + +ADD_EXECUTABLE(AddConfig AddConfig.cpp) +TARGET_LINK_LIBRARIES(AddConfig route4me) + +ADD_EXECUTABLE(GetConfig GetConfig.cpp) +TARGET_LINK_LIBRARIES(GetConfig route4me) + +ADD_EXECUTABLE(GetVehicles GetVehicles.cpp) +TARGET_LINK_LIBRARIES(GetVehicles route4me) + +ADD_EXECUTABLE(PreviewFile PreviewFile.cpp) +TARGET_LINK_LIBRARIES(PreviewFile route4me) + +ADD_EXECUTABLE(UploadFile UploadFile.cpp) +TARGET_LINK_LIBRARIES(UploadFile route4me) + diff --git a/test/DeleteMember.cpp b/examples/DeleteMember.cpp similarity index 100% rename from test/DeleteMember.cpp rename to examples/DeleteMember.cpp diff --git a/test/DeleteRoute.cpp b/examples/DeleteRoute.cpp similarity index 100% rename from test/DeleteRoute.cpp rename to examples/DeleteRoute.cpp diff --git a/test/DuplicateRoute.cpp b/examples/DuplicateRoute.cpp similarity index 100% rename from test/DuplicateRoute.cpp rename to examples/DuplicateRoute.cpp diff --git a/test/EditMember.cpp b/examples/EditMember.cpp similarity index 100% rename from test/EditMember.cpp rename to examples/EditMember.cpp diff --git a/test/GetAllStreets.cpp b/examples/GetAllStreets.cpp similarity index 100% rename from test/GetAllStreets.cpp rename to examples/GetAllStreets.cpp diff --git a/test/GetConfig.cpp b/examples/GetConfig.cpp similarity index 100% rename from test/GetConfig.cpp rename to examples/GetConfig.cpp diff --git a/test/GetCustomOrders.cpp b/examples/GetCustomOrders.cpp similarity index 100% rename from test/GetCustomOrders.cpp rename to examples/GetCustomOrders.cpp diff --git a/test/GetLocationHistory.cpp b/examples/GetLocationHistory.cpp similarity index 100% rename from test/GetLocationHistory.cpp rename to examples/GetLocationHistory.cpp diff --git a/test/GetMultipleRoutes.cpp b/examples/GetMultipleRoutes.cpp similarity index 100% rename from test/GetMultipleRoutes.cpp rename to examples/GetMultipleRoutes.cpp diff --git a/test/GetOptimization.cpp b/examples/GetOptimization.cpp similarity index 100% rename from test/GetOptimization.cpp rename to examples/GetOptimization.cpp diff --git a/test/GetOptimizations.cpp b/examples/GetOptimizations.cpp similarity index 100% rename from test/GetOptimizations.cpp rename to examples/GetOptimizations.cpp diff --git a/test/GetOrdersByDate.cpp b/examples/GetOrdersByDate.cpp similarity index 100% rename from test/GetOrdersByDate.cpp rename to examples/GetOrdersByDate.cpp diff --git a/test/GetOrdersQuery.cpp b/examples/GetOrdersQuery.cpp similarity index 100% rename from test/GetOrdersQuery.cpp rename to examples/GetOrdersQuery.cpp diff --git a/test/GetRoute.cpp b/examples/GetRoute.cpp similarity index 100% rename from test/GetRoute.cpp rename to examples/GetRoute.cpp diff --git a/test/GetRouteByDirections.cpp b/examples/GetRouteByDirections.cpp similarity index 100% rename from test/GetRouteByDirections.cpp rename to examples/GetRouteByDirections.cpp diff --git a/test/GetRouteByPoints.cpp b/examples/GetRouteByPoints.cpp similarity index 100% rename from test/GetRouteByPoints.cpp rename to examples/GetRouteByPoints.cpp diff --git a/test/GetRouteByText.cpp b/examples/GetRouteByText.cpp similarity index 100% rename from test/GetRouteByText.cpp rename to examples/GetRouteByText.cpp diff --git a/test/GetSingleStreet.cpp b/examples/GetSingleStreet.cpp similarity index 100% rename from test/GetSingleStreet.cpp rename to examples/GetSingleStreet.cpp diff --git a/test/GetStreetsLimited.cpp b/examples/GetStreetsLimited.cpp similarity index 100% rename from test/GetStreetsLimited.cpp rename to examples/GetStreetsLimited.cpp diff --git a/test/GetStreetsZipHouse.cpp b/examples/GetStreetsZipHouse.cpp similarity index 100% rename from test/GetStreetsZipHouse.cpp rename to examples/GetStreetsZipHouse.cpp diff --git a/test/GetSubUsers.cpp b/examples/GetSubUsers.cpp similarity index 100% rename from test/GetSubUsers.cpp rename to examples/GetSubUsers.cpp diff --git a/test/GetVehicles.cpp b/examples/GetVehicles.cpp similarity index 100% rename from test/GetVehicles.cpp rename to examples/GetVehicles.cpp diff --git a/test/LogActivities.cpp b/examples/LogActivities.cpp similarity index 100% rename from test/LogActivities.cpp rename to examples/LogActivities.cpp diff --git a/test/Login.cpp b/examples/Login.cpp similarity index 100% rename from test/Login.cpp rename to examples/Login.cpp diff --git a/examples/MarkVisited.cpp b/examples/MarkVisited.cpp new file mode 100644 index 0000000..983e982 --- /dev/null +++ b/examples/MarkVisited.cpp @@ -0,0 +1,31 @@ +#include +#include "../include/route4me.h" + +#define KEY "11111111111111111111111111111111" + +using namespace std; + +int main() +{ + // global init + CRoute4Me::init(); + + CRoute4Me route(KEY, true); + + const char* route_id = "5C15E83A4BE005BCD1537955D28D51D7"; + const char* address_id = "5C15E83A4BE005BCD1537955D28D51D7"; + + if(route.mark_address_visited(route_id, address_id, true,1) == 0) + { + cout << "Marked:" << endl << Json::FastWriter().write(route.get_json_resp()) << endl; + } + else + { + cout << "Failed to mark: " << route.get_err_code() << ": " << route.get_err_msg() << endl; + } + + // global cleanup + CRoute4Me::cleanup(); + + return 0; +} diff --git a/test/MergeRoutes.cpp b/examples/MergeRoutes.cpp similarity index 87% rename from test/MergeRoutes.cpp rename to examples/MergeRoutes.cpp index 71639dc..f671adf 100644 --- a/test/MergeRoutes.cpp +++ b/examples/MergeRoutes.cpp @@ -12,7 +12,8 @@ int main() CRoute4Me route(KEY, true); - const char* route_ids="075594D31563C05ACCEBCAA77D026B2D,6AF79B603C1B6C5AAC714CDD76687CC6"; + const char* route_ids="075594D31563C05ACCEBCAA77D026B2D"; + //6AF79B603C1B6C5AAC714CDD76687CC6"; const char* depot_address="11921 N Dickinson Dr, Fredericksburg, VA 22407, USA"; MapPoint point; diff --git a/test/MultipleDepotMultipleDriver.cpp b/examples/MultipleDepotMultipleDriver.cpp similarity index 100% rename from test/MultipleDepotMultipleDriver.cpp rename to examples/MultipleDepotMultipleDriver.cpp diff --git a/test/MultipleDepotMultipleDriverTimeWindows.cpp b/examples/MultipleDepotMultipleDriverTimeWindows.cpp similarity index 100% rename from test/MultipleDepotMultipleDriverTimeWindows.cpp rename to examples/MultipleDepotMultipleDriverTimeWindows.cpp diff --git a/test/Notes.cpp b/examples/Notes.cpp similarity index 100% rename from test/Notes.cpp rename to examples/Notes.cpp diff --git a/test/OptimizeAndReoptimize.cpp b/examples/OptimizeAndReoptimize.cpp similarity index 98% rename from test/OptimizeAndReoptimize.cpp rename to examples/OptimizeAndReoptimize.cpp index 4c14431..bbb3177 100644 --- a/test/OptimizeAndReoptimize.cpp +++ b/examples/OptimizeAndReoptimize.cpp @@ -22,7 +22,7 @@ int main() // global init CRoute4Me::init(); - CRoute4Me route(KEY); + CRoute4Me route(KEY, true); Json::Value params(Json::objectValue); params["route_name"] = "Single Driver Round Trip"; params["algorithm_type"] = CRoute4Me::TSP; diff --git a/test/Orders.cpp b/examples/Orders.cpp similarity index 100% rename from test/Orders.cpp rename to examples/Orders.cpp diff --git a/test/PreviewFile.cpp b/examples/PreviewFile.cpp similarity index 100% rename from test/PreviewFile.cpp rename to examples/PreviewFile.cpp diff --git a/test/PurchaseLicense.cpp b/examples/PurchaseLicense.cpp similarity index 100% rename from test/PurchaseLicense.cpp rename to examples/PurchaseLicense.cpp diff --git a/test/ReOptimization.cpp b/examples/ReOptimization.cpp similarity index 99% rename from test/ReOptimization.cpp rename to examples/ReOptimization.cpp index 76d63ac..7e89e25 100644 --- a/test/ReOptimization.cpp +++ b/examples/ReOptimization.cpp @@ -35,4 +35,4 @@ int main() CRoute4Me::cleanup(); return ret; -} \ No newline at end of file +} diff --git a/test/Register.cpp b/examples/Register.cpp similarity index 100% rename from test/Register.cpp rename to examples/Register.cpp diff --git a/test/RemoveOptimization.cpp b/examples/RemoveOptimization.cpp similarity index 100% rename from test/RemoveOptimization.cpp rename to examples/RemoveOptimization.cpp diff --git a/test/ReverseGeocoding.cpp b/examples/ReverseGeocoding.cpp similarity index 100% rename from test/ReverseGeocoding.cpp rename to examples/ReverseGeocoding.cpp diff --git a/test/RouteDestinations.cpp b/examples/RouteDestinations.cpp similarity index 100% rename from test/RouteDestinations.cpp rename to examples/RouteDestinations.cpp diff --git a/test/RouteManifest.cpp b/examples/RouteManifest.cpp similarity index 100% rename from test/RouteManifest.cpp rename to examples/RouteManifest.cpp diff --git a/test/RouteStatus.cpp b/examples/RouteStatus.cpp similarity index 100% rename from test/RouteStatus.cpp rename to examples/RouteStatus.cpp diff --git a/test/SetGPSPosition.cpp b/examples/SetGPSPosition.cpp similarity index 97% rename from test/SetGPSPosition.cpp rename to examples/SetGPSPosition.cpp index 9b5e288..2f1db97 100644 --- a/test/SetGPSPosition.cpp +++ b/examples/SetGPSPosition.cpp @@ -14,7 +14,7 @@ int main() // global init CRoute4Me::init(); - CRoute4Me route(KEY); + CRoute4Me route(KEY, true); Json::Value params(Json::objectValue); params["route_id"] = "AC16E7D338B551013FF34266FE81A5EE"; params["format"] = CRoute4Me::Csv; @@ -42,4 +42,4 @@ int main() CRoute4Me::cleanup(); return ret; -} \ No newline at end of file +} diff --git a/test/ShareRoutes.cpp b/examples/ShareRoutes.cpp similarity index 100% rename from test/ShareRoutes.cpp rename to examples/ShareRoutes.cpp diff --git a/test/SingleDriverRoundTrip.cpp b/examples/SingleDriverRoundTrip.cpp similarity index 100% rename from test/SingleDriverRoundTrip.cpp rename to examples/SingleDriverRoundTrip.cpp diff --git a/test/SingleDriverRoute10Stops.cpp b/examples/SingleDriverRoute10Stops.cpp similarity index 100% rename from test/SingleDriverRoute10Stops.cpp rename to examples/SingleDriverRoute10Stops.cpp diff --git a/test/TeamActivities.cpp b/examples/TeamActivities.cpp similarity index 100% rename from test/TeamActivities.cpp rename to examples/TeamActivities.cpp diff --git a/test/Territory.cpp b/examples/Territory.cpp similarity index 100% rename from test/Territory.cpp rename to examples/Territory.cpp diff --git a/test/TrackDeviceLastLocationHistory.cpp b/examples/TrackDeviceLastLocationHistory.cpp similarity index 100% rename from test/TrackDeviceLastLocationHistory.cpp rename to examples/TrackDeviceLastLocationHistory.cpp diff --git a/test/UpdateRoute.cpp b/examples/UpdateRoute.cpp similarity index 100% rename from test/UpdateRoute.cpp rename to examples/UpdateRoute.cpp diff --git a/test/UploadFile.cpp b/examples/UploadFile.cpp similarity index 100% rename from test/UploadFile.cpp rename to examples/UploadFile.cpp diff --git a/test/Users.cpp b/examples/Users.cpp similarity index 100% rename from test/Users.cpp rename to examples/Users.cpp diff --git a/test/ValidateSession.cpp b/examples/ValidateSession.cpp similarity index 100% rename from test/ValidateSession.cpp rename to examples/ValidateSession.cpp diff --git a/test/add_account_data.json b/examples/add_account_data.json similarity index 100% rename from test/add_account_data.json rename to examples/add_account_data.json diff --git a/test/add_address_to_route.json b/examples/add_address_to_route.json similarity index 100% rename from test/add_address_to_route.json rename to examples/add_address_to_route.json diff --git a/test/add_order.json b/examples/add_order.json similarity index 100% rename from test/add_order.json rename to examples/add_order.json diff --git a/test/add_order_data.json b/examples/add_order_data.json similarity index 100% rename from test/add_order_data.json rename to examples/add_order_data.json diff --git a/test/add_order_to_route.json b/examples/add_order_to_route.json similarity index 100% rename from test/add_order_to_route.json rename to examples/add_order_to_route.json diff --git a/test/add_order_to_route_data.json b/examples/add_order_to_route_data.json similarity index 100% rename from test/add_order_to_route_data.json rename to examples/add_order_to_route_data.json diff --git a/test/addr.json b/examples/addr.json similarity index 100% rename from test/addr.json rename to examples/addr.json diff --git a/test/address_for_optimization.json b/examples/address_for_optimization.json similarity index 100% rename from test/address_for_optimization.json rename to examples/address_for_optimization.json diff --git a/test/app_purchase_user_license_data.json b/examples/app_purchase_user_license_data.json similarity index 100% rename from test/app_purchase_user_license_data.json rename to examples/app_purchase_user_license_data.json diff --git a/test/member_create_v4_data.json b/examples/member_create_v4_data.json similarity index 100% rename from test/member_create_v4_data.json rename to examples/member_create_v4_data.json diff --git a/test/member_delete_data.json b/examples/member_delete_data.json similarity index 100% rename from test/member_delete_data.json rename to examples/member_delete_data.json diff --git a/test/member_edit_data.json b/examples/member_edit_data.json similarity index 100% rename from test/member_edit_data.json rename to examples/member_edit_data.json diff --git a/test/poly.json b/examples/poly.json similarity index 100% rename from test/poly.json rename to examples/poly.json diff --git a/test/territory.json b/examples/territory.json similarity index 100% rename from test/territory.json rename to examples/territory.json diff --git a/test/update_route_data.json b/examples/update_route_data.json similarity index 100% rename from test/update_route_data.json rename to examples/update_route_data.json diff --git a/test/update_route_destination_custom_data.json b/examples/update_route_destination_custom_data.json similarity index 100% rename from test/update_route_destination_custom_data.json rename to examples/update_route_destination_custom_data.json diff --git a/include/route4me.h b/include/route4me.h index b53f00f..25cf431 100644 --- a/include/route4me.h +++ b/include/route4me.h @@ -8,7 +8,8 @@ #define __cpproute4me_route4me__ #include -#include +//#include +#include "json/json.h" class CAddressArray; @@ -624,9 +625,18 @@ class CRoute4Me */ int upload_file(const char* file_name, const char* format = "json"); + /** \brief Upload geocoding + * \param - id + * \return \c 0 if the response was successfully received, \c error code if an error occurred. + */ int upload_geocoding(const char* id); - // TODO section: + /** \brief Upload JSON geocoding + * \param - body - JSON data + * \return \c 0 if the response was successfully received, \c error code if an error occurred. + */ + int json_geocoding(Json::Value& body); + /** * \brief mark address as visited * \param route_id @@ -635,25 +645,50 @@ class CRoute4Me * \param member * \return \c 0 if the response was successfully received, \c error code if an error occurred. */ - int mark_address_visited(const char* route_id, const char* address_id, bool visited, int member_id); + int mark_address_visited(const char* route_id, const char* address_id, bool visited, int member_id, Json::Value& body); + + /** + * \brief mark address as departed + * \param route_id + * \param address_id + * \param visited + * \param member + * \return \c 0 if the response was successfully received, \c error code if an error occurred. + */ + int mark_address_departed(const char* route_id, const char* address_id, bool departed, int member_id, Json::Value& body); - int mark_address_departed(const char* route_id, const char* address_id, bool departed, int member_id); + /** + * \brief mark address as detected + * \param route_id + * \param address_id + * \param visited + * \param member + * \return \c 0 if the response was successfully received, \c error code if an error occurred. + */ + int mark_address_detected(const char* route_id, const char* route_destination_id, Json::Value& body); + /** + * \brief get hybrid route + * \param target scheduled date + * \param timezone offset in minutes + * \return \c 0 if the response was successfully received, \c error code if an error occurred. + */ + int get_hybrid_route(const char* target_date_string, int tz_offset); protected: bool validate(const Json::Value& v, const CRoute4Me::key2tp *p = 0, int n = 0, const char **required = 0, int rn = 0); - bool request(CRoute4Me::ReqType method, const char *url, Json::Value& props, Json::Value& content); + bool request(CRoute4Me::ReqType method, const char *serviceURL, Json::Value& props, Json::Value& content, const char* altURL = NULL); public: static key2tp get_route_q_req[], set_gps_req[], get_route_address_req[],\ get_address_notes_req[], get__multiple_routes_req[], update_route_req[], update_route_data_req[], \ duplicate_route_req[], delete_route_req[], add_address_req[], add_address_notes_req[],\ get_address_book_contact_req[]; - static const char *R4_API_HOST, *R4_SHOW_ROUTE_HOST, *R4_DUPLICATE_ROUTE_HOST, *R4_ROUTE_HOST, *R4_SET_GPS_HOST, + static const char *MAIN_HOST, *RAPID_HOST, *R4_API_HOST, *R4_SHOW_ROUTE_HOST, *R4_DUPLICATE_ROUTE_HOST, *R4_ROUTE_HOST, *R4_SET_GPS_HOST, *R4_ADDRESS_HOST, *R4_ADD_ROUTE_NOTES, *R4_ADDRESS_BOOK, *R4_AVOIDANCE_HOST, *R4_ORDER_HOST, *R4_ACTIVITIES, *R4_USERS, *R4_TERRITORY_HOST, *AUTHENTICATION_SERVICE, *REGISTRATION_SERVICE, *TRACKING_SERVICE, *LOCATION_SERVICE, *MERGE_SERVICE, *SHARE_SERVICE, *ADDRESS_VISITED_SERVICE, *GEOCODER, *STREET_SERVICE, *USER_LICENSE_SERVICE, *DEVICE_LICENSE_SERVICE, *USER_SERVICE, *VALIDATE_SESSION, *CONFIG_SERVICE, *VEHICLES_SERVICE, - *PREVIEW_SERVICE, *UPLOAD_SERVICE, *UPLOAD_GEOCODING; + *PREVIEW_SERVICE, *UPLOAD_SERVICE, *UPLOAD_GEOCODING, *JSON_GEOCODING, *DEPARTED_SERVICE, *HYBRID_SERVICE; static const char *Driving, *Walking, *Trucking; // TravelMode static const char *MI, *KM; // DistanceUnit static const char *Highways, *Tolls, *MinimizeHighways, *MinimizeTolls, *None; // Avoid diff --git a/src/route4me.cpp b/src/route4me.cpp index 1639673..6ee0988 100644 --- a/src/route4me.cpp +++ b/src/route4me.cpp @@ -13,38 +13,43 @@ /////////////////////////////////////////////////////////////////////////////// // Constants - -const char *CRoute4Me::R4_API_HOST = "https://www.route4me.com/api.v4/optimization_problem.php"; -const char *CRoute4Me::R4_SHOW_ROUTE_HOST = "https://www.route4me.com/route4me.php"; -const char *CRoute4Me::R4_ROUTE_HOST = "https://www.route4me.com/api.v4/route.php"; -const char *CRoute4Me::R4_SET_GPS_HOST = "https://www.route4me.com/track/set.php"; -const char *CRoute4Me::R4_ADDRESS_HOST = "https://www.route4me.com/api.v4/address.php"; -const char *CRoute4Me::R4_DUPLICATE_ROUTE_HOST = "https://www.route4me.com/actions/duplicate_route.php"; -const char *CRoute4Me::R4_ADD_ROUTE_NOTES = "https://www.route4me.com/actions/addRouteNotes.php"; -const char *CRoute4Me::R4_ADDRESS_BOOK = "https://www.route4me.com/api.v4/address_book.php"; -const char *CRoute4Me::R4_AVOIDANCE_HOST = "https://www.route4me.com/api.v4/avoidance.php"; -const char *CRoute4Me::R4_ORDER_HOST = "https://www.route4me.com/api.v4/order.php"; -const char *CRoute4Me::R4_ACTIVITIES = "https://www.route4me.com/api/get_activities.php"; -const char *CRoute4Me::R4_USERS = "https://www.route4me.com/api/member/view_users.php"; -const char *CRoute4Me::R4_TERRITORY_HOST = "https://route4me.com/api.v4/territory.php"; -const char *CRoute4Me::AUTHENTICATION_SERVICE = "https://www.route4me.com/actions/authenticate.php"; -const char *CRoute4Me::REGISTRATION_SERVICE = "https://www.route4me.com/actions/register_action.php"; -const char *CRoute4Me::TRACKING_SERVICE = "https://route4me.com/api.v4/status.php"; -const char *CRoute4Me::LOCATION_SERVICE = "https://www.route4me.com/api/track/get_device_location.php"; -const char *CRoute4Me::MERGE_SERVICE = "https://www.route4me.com/actions/merge_routes.php"; -const char *CRoute4Me::SHARE_SERVICE = "https://www.route4me.com/actions/route/share_route.php"; -const char *CRoute4Me::ADDRESS_VISITED_SERVICE = "https://www.route4me.com/api/address/update_address_visited.php"; -const char *CRoute4Me::GEOCODER = "https://www.route4me.com/api/geocoder.php"; -const char *CRoute4Me::STREET_SERVICE = "https://rapid.route4me.com/street_data/"; -const char *CRoute4Me::USER_LICENSE_SERVICE = "https://www.route4me.com/api/member/user_license.php"; -const char *CRoute4Me::DEVICE_LICENSE_SERVICE = "https://www.route4me.com/api/device/verify_device_license.php"; -const char *CRoute4Me::USER_SERVICE = "https://www.route4me.com/api.v4/user.php"; -const char *CRoute4Me::VALIDATE_SESSION = "https://www.route4me.com/datafeed/session/validate_session.php"; -const char *CRoute4Me::CONFIG_SERVICE = "https://route4me.com/api.v4/configuration-settings.php"; -const char *CRoute4Me::VEHICLES_SERVICE = "https://www.route4me.com/api/vehicles/view_vehicles.php"; -const char *CRoute4Me::PREVIEW_SERVICE = "https://www.route4me.com/actions/upload/csv-xls-preview.php"; -const char *CRoute4Me::UPLOAD_SERVICE = "https://www.route4me.com/actions/upload/upload.php"; -const char *CRoute4Me::UPLOAD_GEOCODING = "https://www.route4me.com/actions/upload/csv-xls-geocode.php"; +const char *CRoute4Me::MAIN_HOST = "https://www.route4me.com/"; +const char *CRoute4Me::RAPID_HOST = "https://rapid.route4me.com/"; + +const char *CRoute4Me::R4_API_HOST = "api.v4/optimization_problem.php"; +const char *CRoute4Me::R4_SHOW_ROUTE_HOST = "route4me.php"; +const char *CRoute4Me::R4_ROUTE_HOST = "api.v4/route.php"; +const char *CRoute4Me::R4_SET_GPS_HOST = "track/set.php"; +const char *CRoute4Me::R4_ADDRESS_HOST = "api.v4/address.php"; +const char *CRoute4Me::R4_DUPLICATE_ROUTE_HOST = "actions/duplicate_route.php"; +const char *CRoute4Me::R4_ADD_ROUTE_NOTES = "actions/addRouteNotes.php"; +const char *CRoute4Me::R4_ADDRESS_BOOK = "api.v4/address_book.php"; +const char *CRoute4Me::R4_AVOIDANCE_HOST = "api.v4/avoidance.php"; +const char *CRoute4Me::R4_ORDER_HOST = "api.v4/order.php"; +const char *CRoute4Me::R4_ACTIVITIES = "api/get_activities.php"; +const char *CRoute4Me::R4_USERS = "api/member/view_users.php"; +const char *CRoute4Me::R4_TERRITORY_HOST = "api.v4/territory.php"; +const char *CRoute4Me::AUTHENTICATION_SERVICE = "actions/authenticate.php"; +const char *CRoute4Me::REGISTRATION_SERVICE = "actions/register_action.php"; +const char *CRoute4Me::TRACKING_SERVICE = "api.v4/status.php"; +const char *CRoute4Me::LOCATION_SERVICE = "api/track/get_device_location.php"; +const char *CRoute4Me::MERGE_SERVICE = "actions/merge_routes.php"; +const char *CRoute4Me::SHARE_SERVICE = "actions/route/share_route.php"; +const char *CRoute4Me::ADDRESS_VISITED_SERVICE = "api/address/update_address_visited.php"; +const char *CRoute4Me::GEOCODER = "api/geocoder.php"; +const char *CRoute4Me::STREET_SERVICE = "street_data/"; +const char *CRoute4Me::USER_LICENSE_SERVICE = "api/member/user_license.php"; +const char *CRoute4Me::DEVICE_LICENSE_SERVICE = "api/device/verify_device_license.php"; +const char *CRoute4Me::USER_SERVICE = "api.v4/user.php"; +const char *CRoute4Me::VALIDATE_SESSION = "datafeed/session/validate_session.php"; +const char *CRoute4Me::CONFIG_SERVICE = "api.v4/configuration-settings.php"; +const char *CRoute4Me::VEHICLES_SERVICE = "api/vehicles/view_vehicles.php"; +const char *CRoute4Me::PREVIEW_SERVICE = "actions/upload/csv-xls-preview.php"; +const char *CRoute4Me::UPLOAD_SERVICE = "actions/upload/upload.php"; +const char *CRoute4Me::UPLOAD_GEOCODING = "actions/upload/csv-xls-geocode.php"; +const char *CRoute4Me::JSON_GEOCODING = "actions/upload/json-geocode.php"; +const char *CRoute4Me::DEPARTED_SERVICE = "api/route/mark_address_departed.php"; +const char *CRoute4Me::HYBRID_SERVICE = "api.v4/hybrid_date_optimization.php"; const char *CRoute4Me::Driving = "Driving"; const char *CRoute4Me::Walking = "Walking"; @@ -359,8 +364,41 @@ int CRoute4Me::remove_address_from_route(const char* route_id, const char* route int CRoute4Me::merge_routes(const char *route_ids, const char *depot_address, MapPoint point, bool remove_origin) { - //TODO: Implement missing functionality - return -1; + Json::Value props(Json::objectValue); + + props["api_key"] = m_key; + struct curl_httppost *lastptr=NULL; + + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "route_ids", + CURLFORM_COPYCONTENTS, route_ids, + CURLFORM_END); + + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "depot_address", + CURLFORM_COPYCONTENTS, depot_address, + CURLFORM_END); + + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "depot_lat", + CURLFORM_COPYCONTENTS, &point.lat, + CURLFORM_END); + + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "depot_lng", + CURLFORM_COPYCONTENTS, &point.lng, + CURLFORM_END); + + + if (!validate(props)) + return m_err_code; + Json::Value null; + request(CRoute4Me::REQ_POST, CRoute4Me::MERGE_SERVICE, props, null); + return m_err_code; } int CRoute4Me::share_routes(const char *route_id, const char *email, const char *format) @@ -445,7 +483,7 @@ int CRoute4Me::update_address_book_contacts(const char* address_id, Json::Value if (!validate(props)) { return m_err_code; } - request(CRoute4Me::REQ_GET, CRoute4Me::R4_ADDRESS_BOOK, props, body); + request(CRoute4Me::REQ_PUT, CRoute4Me::R4_ADDRESS_BOOK, props, body); return m_err_code; } @@ -975,14 +1013,24 @@ int CRoute4Me::modify_member(Json::Value& body, ReqType method) int CRoute4Me::purchase_user_license(Json::Value &body) { - // TODO: Implement missing functionality - return -1; + Json::Value props(Json::objectValue); + props["api_key"] = m_key; + if (!validate(props)) { + return m_err_code; + } + request(CRoute4Me::REQ_POST, CRoute4Me::USER_LICENSE_SERVICE, props, body); + return m_err_code; } int CRoute4Me::purchase_device_license(Json::Value &body) { - // TODO: Implement missing functionality - return -1; + Json::Value props(Json::objectValue); + props["api_key"] = m_key; + if (!validate(props)) { + return m_err_code; + } + request(CRoute4Me::REQ_POST, CRoute4Me::DEVICE_LICENSE_SERVICE, props, body); + return m_err_code; } int CRoute4Me::asset_tracking(const char *id) @@ -1067,7 +1115,7 @@ int CRoute4Me::get_street_address(int seqno) std::string url = std::string(CRoute4Me::STREET_SERVICE ); append_url(url, seqno); Json::Value null; - request(CRoute4Me::REQ_GET, url.c_str(), props, null); + request(CRoute4Me::REQ_GET, url.c_str(), props, null, url.c_str()); return m_err_code; } @@ -1234,6 +1282,17 @@ int CRoute4Me::upload_geocoding(const char *id) return m_err_code; } +int CRoute4Me::json_geocoding(Json::Value &body) +{ + Json::Value props(Json::objectValue); + props["api_key"] = m_key; + if (!validate(props)) { + return m_err_code; + } + request(CRoute4Me::REQ_POST, CRoute4Me::JSON_GEOCODING, props, body); + return m_err_code; +} + /////////////////////////////////////////////////////////////////////////////// // CURL wrapper @@ -1304,22 +1363,35 @@ static size_t read_http_resp(void *contents, size_t size, size_t nmemb, void *us { size_t realsize = size * nmemb; struct CRoute4Me::http_resp *mem = (struct CRoute4Me::http_resp *)userp; - mem->memory = (char*) std::realloc(mem->memory, mem->size + realsize + 1); - if(mem->memory == NULL) return 0; + char* upd_memory = (char*) std::realloc(mem->memory, mem->size + realsize + 1); + if(upd_memory == NULL) + return 0; + else + mem->memory = upd_memory; std::memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = 0; return realsize; } -bool CRoute4Me::request(CRoute4Me::ReqType method, const char *url, Json::Value& props, Json::Value& content) +bool CRoute4Me::request(CRoute4Me::ReqType method, const char *serviceURL, Json::Value& props, Json::Value& content, + const char* altUrl) { long http_code = 0; std::string payload; struct CRoute4Me::http_resp chunk; // prepare buffer for lubcurl http response chunk.memory = (char*) malloc(1); chunk.size = 0; - std::string req = make_arg(m_curl, url, props); // prepare url with parameters + std::string url; + if (altUrl) + { + url = std::string(altUrl); + } + else + { + url = std::string(MAIN_HOST) + std::string(serviceURL); + } + std::string req = make_arg(m_curl, url.c_str(), props); // prepare url with parameters curl_easy_reset(m_curl); curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &http_code); curl_easy_setopt(m_curl, CURLOPT_URL, req.c_str()); @@ -1499,4 +1571,57 @@ int CRoute4Me::get_address(const char* route_id, const char* dest_id) request(CRoute4Me::REQ_GET, CRoute4Me::R4_ROUTE_HOST, props, null); return m_err_code; } + +int CRoute4Me::mark_address_departed(const char *route_id, const char *address_id, bool departed, int member_id, + Json::Value& body) +{ + Json::Value props(Json::objectValue); + props["api_key"] = m_key; + props["route_id"] = route_id; + props["address_id"] = address_id; + props["is_departed"] = departed; + props["member_id"] = member_id; + + request(CRoute4Me::REQ_PUT, CRoute4Me::DEPARTED_SERVICE, props, body); + return m_err_code; +} + +int CRoute4Me::mark_address_visited(const char *route_id, const char *address_id, bool visited, int member_id, + Json::Value& body) +{ + Json::Value props(Json::objectValue); + props["api_key"] = m_key; + props["route_id"] = route_id; + props["address_id"] = address_id; + props["is_visited"] = visited; + props["member_id"] = member_id; + + request(CRoute4Me::REQ_PUT, CRoute4Me::ADDRESS_VISITED_SERVICE, props, body); + return m_err_code; +} + +int CRoute4Me::mark_address_detected(const char *route_id, const char *route_destination_id, + Json::Value& body) +{ + Json::Value props(Json::objectValue); + props["api_key"] = m_key; + props["route_id"] = route_id; + props["route_destination_id"] = route_destination_id; + + request(CRoute4Me::REQ_PUT, CRoute4Me::R4_ADDRESS_HOST, props, body); + return m_err_code; +} + +int CRoute4Me::get_hybrid_route(const char *target_date_string, int tz_offset) +{ + Json::Value props(Json::objectValue); + props["api_key"] = m_key; + props["target_date_string"] = target_date_string; + props["timezone_offset_minutes"] = tz_offset; + + Json::Value null; + request(CRoute4Me::REQ_GET, CRoute4Me::HYBRID_SERVICE, props, null); + return m_err_code; +} + /////////////////////////////////////////////////////////////////////////////// diff --git a/test/ActivitiesTest.cpp b/test/ActivitiesTest.cpp new file mode 100644 index 0000000..93cc759 --- /dev/null +++ b/test/ActivitiesTest.cpp @@ -0,0 +1,75 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(ActivitiesTest, GetAll) +{ + int ret = pRoute->get_all_activities(); + ASSERT_EQ(0, ret); +} + +TEST(ActivitiesTest, GetByType ) +{ + std::vector types; + + types.push_back("area-added"); + types.push_back("area-removed"); + types.push_back("area-updated"); + types.push_back("delete-destination"); + types.push_back("destination-out-sequence"); + types.push_back("driver-arrived-early"); + types.push_back("driver-arrived-late"); + types.push_back("driver-arrived-on-time"); + types.push_back("geofence-entered"); + types.push_back("geofence-left"); + types.push_back("insert_destination"); + types.push_back("mark-destination-departed"); + types.push_back("mark-destination-visited"); + types.push_back("member-created"); + types.push_back("member-deleted"); + types.push_back("member-modified"); + types.push_back("move-destination"); + types.push_back("note-insert"); + types.push_back("route-delete"); + types.push_back("route-optimized"); + types.push_back("route-owner-changed"); + types.push_back("update-destinations"); + + std::vector foundActivities, missingActivities; + + for (int i = 0; i < types.size(); ++i) { + const char* type = types[i].c_str(); + if (pRoute->get_activities_by_type(type) == 0) + foundActivities.push_back(type); + else + missingActivities.push_back(type); + } + + ASSERT_EQ(22, foundActivities.size()); + ASSERT_EQ(0, missingActivities.size()); +} + +TEST(ActivitiesTest, GetByTeam) +{ + const char *route_id = "CA902292134DBC134EAF8363426BD247"; + int ret = pRoute->get_team_activities(route_id); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/AddressBookTest.cpp b/test/AddressBookTest.cpp new file mode 100644 index 0000000..ccef76a --- /dev/null +++ b/test/AddressBookTest.cpp @@ -0,0 +1,32 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(AddressBookTest, GetAllContacts) +{ + int ret = pRoute->get_address_book_contacts(); + ASSERT_EQ(0, ret); +} + +TEST(AddressBookTest, GetOneContact) +{ + int ret = pRoute->get_address_book_contacts_by_text("Wall"); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/AvoidanceZonesTest.cpp b/test/AvoidanceZonesTest.cpp new file mode 100644 index 0000000..e6d0e03 --- /dev/null +++ b/test/AvoidanceZonesTest.cpp @@ -0,0 +1,41 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +//TODO: Make this test really positive +TEST(AvoidanceZonesTest, GetZonePositive) +{ + const char *id = "A1"; + int ret = pRoute->get_avoidance_zone(id); + ASSERT_EQ(-9, ret); +} + +TEST(AvoidanceZonesTest, GetZoneNegative) +{ + int ret = pRoute->get_avoidance_zone("fake"); + ASSERT_EQ(-9, ret); +} + +TEST(AvoidanceZonesTest, GetZones) +{ + int ret = pRoute->get_avoidance_zones(); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + ::testing::InitGoogleTest(&argc, argv); + + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 04ca74e..2923a34 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,177 +1,65 @@ -ADD_EXECUTABLE(RouteManifest RouteManifest.cpp) -TARGET_LINK_LIBRARIES(RouteManifest route4me) -ADD_EXECUTABLE(GetRoute GetRoute.cpp) -TARGET_LINK_LIBRARIES(GetRoute route4me) +ENABLE_TESTING() -ADD_EXECUTABLE(DuplicateRoute DuplicateRoute.cpp) -TARGET_LINK_LIBRARIES(DuplicateRoute route4me) +ADD_EXECUTABLE(ActivitiesTest ActivitiesTest.cpp) +TARGET_LINK_LIBRARIES(ActivitiesTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(ActivitiesTest ActivitiesTest) -ADD_EXECUTABLE(GetRouteByPoints GetRouteByPoints.cpp) -TARGET_LINK_LIBRARIES(GetRouteByPoints route4me) +ADD_EXECUTABLE(TrackingTest TrackingTest.cpp) +TARGET_LINK_LIBRARIES(TrackingTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(TrackingTest TrackingTest) -ADD_EXECUTABLE(GetRouteByDirections GetRouteByDirections.cpp) -TARGET_LINK_LIBRARIES(GetRouteByDirections route4me) +ADD_EXECUTABLE(AvoidanceZonesTest AvoidanceZonesTest.cpp) +TARGET_LINK_LIBRARIES(AvoidanceZonesTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(AvoidanceZonesTest AvoidanceZonesTest) -ADD_EXECUTABLE(GetRouteByText GetRouteByText.cpp) -TARGET_LINK_LIBRARIES(GetRouteByText route4me) +ADD_EXECUTABLE(AddressBookTest AddressBookTest.cpp) +TARGET_LINK_LIBRARIES(AddressBookTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(AddressBookTest AddressBookTest) -ADD_EXECUTABLE(UpdateRoute UpdateRoute.cpp) -TARGET_LINK_LIBRARIES(UpdateRoute route4me) +ADD_EXECUTABLE(StreetsTest StreetsTest.cpp) +TARGET_LINK_LIBRARIES(StreetsTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(StreetsTest StreetsTest) -ADD_EXECUTABLE(RouteDestinations RouteDestinations.cpp) -TARGET_LINK_LIBRARIES(RouteDestinations route4me) +ADD_EXECUTABLE(RoutesTest RoutesTest.cpp) +TARGET_LINK_LIBRARIES(RoutesTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(RoutesTest RoutesTest) -ADD_EXECUTABLE(AddressBook AddressBook.cpp) -TARGET_LINK_LIBRARIES(AddressBook route4me) +ADD_EXECUTABLE(NotesTest NotesTest.cpp) +TARGET_LINK_LIBRARIES(NotesTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(NotesTest NotesTest) -ADD_EXECUTABLE(Notes Notes.cpp) -TARGET_LINK_LIBRARIES(Notes route4me) +ADD_EXECUTABLE(ConfigTest ConfigTest.cpp) +TARGET_LINK_LIBRARIES(ConfigTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(ConfigTest ConfigTest) -ADD_EXECUTABLE(Users Users.cpp) -TARGET_LINK_LIBRARIES(Users route4me) +ADD_EXECUTABLE(TerritoriesTest TerritoriesTest.cpp) +TARGET_LINK_LIBRARIES(TerritoriesTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(TerritoriesTest TerritoriesTest) -ADD_EXECUTABLE(Orders Orders.cpp) -TARGET_LINK_LIBRARIES(Orders route4me) +ADD_EXECUTABLE(OrdersTest OrdersTest.cpp) +TARGET_LINK_LIBRARIES(OrdersTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(OrdersTest OrdersTest) -ADD_EXECUTABLE(GetOrders GetOrdersByDate.cpp) -TARGET_LINK_LIBRARIES(GetOrders route4me) +ADD_EXECUTABLE(GeocoderTest GeocoderTest.cpp) +TARGET_LINK_LIBRARIES(GeocoderTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(GeocoderTest GeocoderTest) -ADD_EXECUTABLE(GetCustomOrders GetCustomOrders.cpp) -TARGET_LINK_LIBRARIES(GetCustomOrders route4me) +ADD_EXECUTABLE(UsersTest UsersTest.cpp) +TARGET_LINK_LIBRARIES(UsersTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(UsersTest UsersTest) -ADD_EXECUTABLE(GetOrdersQuery GetOrdersQuery.cpp) -TARGET_LINK_LIBRARIES(GetOrdersQuery route4me) +ADD_EXECUTABLE(OptimizationTest OptimizationTest.cpp) +TARGET_LINK_LIBRARIES(OptimizationTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(OptimizationTest OptimizationTest) -ADD_EXECUTABLE(AddOrder AddOrder.cpp) -TARGET_LINK_LIBRARIES(AddOrder route4me) +ADD_EXECUTABLE(SessionTest SessionTest.cpp) +TARGET_LINK_LIBRARIES(SessionTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(SessionTest SessionTest) -ADD_EXECUTABLE(TeamActivities TeamActivities.cpp) -TARGET_LINK_LIBRARIES(TeamActivities route4me) - -ADD_EXECUTABLE(LogActivities LogActivities.cpp) -TARGET_LINK_LIBRARIES(LogActivities route4me) - -ADD_EXECUTABLE(Activities Activities.cpp) -TARGET_LINK_LIBRARIES(Activities route4me) - -ADD_EXECUTABLE(Zones AvoidanceZones.cpp) -TARGET_LINK_LIBRARIES(Zones route4me) - -ADD_EXECUTABLE(Territory Territory.cpp) -TARGET_LINK_LIBRARIES(Territory route4me) - -ADD_EXECUTABLE(GetAllRoutes GetMultipleRoutes.cpp) -TARGET_LINK_LIBRARIES(GetAllRoutes route4me) - -ADD_EXECUTABLE(RouteStatus RouteStatus.cpp) -TARGET_LINK_LIBRARIES(RouteStatus route4me) - -ADD_EXECUTABLE(DeleteRoute DeleteRoute.cpp) -TARGET_LINK_LIBRARIES(DeleteRoute route4me) - -ADD_EXECUTABLE(SetGPSPosition SetGPSPosition.cpp) -TARGET_LINK_LIBRARIES(SetGPSPosition route4me) - -ADD_EXECUTABLE(TrackDeviceLastLocationHistory TrackDeviceLastLocationHistory.cpp) -TARGET_LINK_LIBRARIES(TrackDeviceLastLocationHistory route4me) - -ADD_EXECUTABLE(SingleDriverRoundTrip SingleDriverRoundTrip.cpp) -TARGET_LINK_LIBRARIES(SingleDriverRoundTrip route4me) - -ADD_EXECUTABLE(SingleDriverRoute10Stops SingleDriverRoute10Stops.cpp) -TARGET_LINK_LIBRARIES(SingleDriverRoute10Stops route4me) - -ADD_EXECUTABLE(MultipleDepotMultipleDriver MultipleDepotMultipleDriver.cpp) -TARGET_LINK_LIBRARIES(MultipleDepotMultipleDriver route4me) - -ADD_EXECUTABLE(MultipleDepotMultipleDriverTimeWindows MultipleDepotMultipleDriverTimeWindows.cpp) -TARGET_LINK_LIBRARIES(MultipleDepotMultipleDriverTimeWindows route4me) - -ADD_EXECUTABLE(ReOptimization ReOptimization.cpp) -TARGET_LINK_LIBRARIES(ReOptimization route4me) - -ADD_EXECUTABLE(GetOptimization GetOptimization.cpp) -TARGET_LINK_LIBRARIES(GetOptimization route4me) - -ADD_EXECUTABLE(GetOptimizations GetOptimizations.cpp) -TARGET_LINK_LIBRARIES(GetOptimizations route4me) - -ADD_EXECUTABLE(RemoveOptimization RemoveOptimization.cpp) -TARGET_LINK_LIBRARIES(RemoveOptimization route4me) - -ADD_EXECUTABLE(OptimizeAndReoptimize OptimizeAndReoptimize.cpp) -TARGET_LINK_LIBRARIES(OptimizeAndReoptimize route4me) - -ADD_EXECUTABLE(Login Login.cpp) -TARGET_LINK_LIBRARIES(Login route4me) - -ADD_EXECUTABLE(Register Register.cpp) -TARGET_LINK_LIBRARIES(Register route4me) - -ADD_EXECUTABLE(EditMember EditMember.cpp) -TARGET_LINK_LIBRARIES(EditMember route4me) - -ADD_EXECUTABLE(DeleteMember DeleteMember.cpp) -TARGET_LINK_LIBRARIES(DeleteMember route4me) - -ADD_EXECUTABLE(ActivitiesByType ActivitiesByType.cpp) -TARGET_LINK_LIBRARIES(ActivitiesByType route4me) - -ADD_EXECUTABLE(AssetTracking AssetTracking.cpp) -TARGET_LINK_LIBRARIES(AssetTracking route4me) - -ADD_EXECUTABLE(GetLocationHistory GetLocationHistory.cpp) -TARGET_LINK_LIBRARIES(GetLocationHistory route4me) - -ADD_EXECUTABLE(AddAddressToOptimization AddAddressToOptimization.cpp) -TARGET_LINK_LIBRARIES(AddAddressToOptimization route4me) - -ADD_EXECUTABLE(MergeRoutes MergeRoutes.cpp) -TARGET_LINK_LIBRARIES(MergeRoutes route4me) - -ADD_EXECUTABLE(ShareRoutes ShareRoutes.cpp) -TARGET_LINK_LIBRARIES(ShareRoutes route4me) - -ADD_EXECUTABLE(BatchGeocoding BatchGeocoding.cpp) -TARGET_LINK_LIBRARIES(BatchGeocoding route4me) - -ADD_EXECUTABLE(ReverseGeocoding ReverseGeocoding.cpp) -TARGET_LINK_LIBRARIES(ReverseGeocoding route4me) - -ADD_EXECUTABLE(GetSingleStreet GetSingleStreet.cpp) -TARGET_LINK_LIBRARIES(GetSingleStreet route4me) - -ADD_EXECUTABLE(GetAllStreets GetAllStreets.cpp) -TARGET_LINK_LIBRARIES(GetAllStreets route4me) - -ADD_EXECUTABLE(GetStreetsLimited GetStreetsLimited.cpp) -TARGET_LINK_LIBRARIES(GetStreetsLimited route4me) - -ADD_EXECUTABLE(GetStreetsZipHouse GetStreetsZipHouse.cpp) -TARGET_LINK_LIBRARIES(GetStreetsZipHouse route4me) - -ADD_EXECUTABLE(PurchaseLicense PurchaseLicense.cpp) -TARGET_LINK_LIBRARIES(PurchaseLicense route4me) - -ADD_EXECUTABLE(GetSubUsers GetSubUsers.cpp) -TARGET_LINK_LIBRARIES(GetSubUsers route4me) - -ADD_EXECUTABLE(ValidateSession ValidateSession.cpp) -TARGET_LINK_LIBRARIES(ValidateSession route4me) - -ADD_EXECUTABLE(AddConfig AddConfig.cpp) -TARGET_LINK_LIBRARIES(AddConfig route4me) - -ADD_EXECUTABLE(GetConfig GetConfig.cpp) -TARGET_LINK_LIBRARIES(GetConfig route4me) - -ADD_EXECUTABLE(GetVehicles GetVehicles.cpp) -TARGET_LINK_LIBRARIES(GetVehicles route4me) - -ADD_EXECUTABLE(PreviewFile PreviewFile.cpp) -TARGET_LINK_LIBRARIES(PreviewFile route4me) - -ADD_EXECUTABLE(UploadFile UploadFile.cpp) -TARGET_LINK_LIBRARIES(UploadFile route4me) +ADD_EXECUTABLE(GPSTest GPSTest.cpp) +TARGET_LINK_LIBRARIES(GPSTest route4me ${GTEST_LIBRARIES} pthread) +ADD_TEST(GPSTest GPSTest) +# No neeed to run valgrind tests for each build. Line below added for example. +# ADD_TEST(GPSTest_valgrind valgrind --read-var-info=yes --leak-check=full --show-leak-kinds=all ./GPSTest) diff --git a/test/ConfigTest.cpp b/test/ConfigTest.cpp new file mode 100644 index 0000000..9750ada --- /dev/null +++ b/test/ConfigTest.cpp @@ -0,0 +1,27 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(NotesTest, GetRouteNotes) +{ + int ret = pRoute->get_config(); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/GPSTest.cpp b/test/GPSTest.cpp new file mode 100644 index 0000000..0e5513f --- /dev/null +++ b/test/GPSTest.cpp @@ -0,0 +1,38 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(GPSTest, SetPosition) +{ + Json::Value params(Json::objectValue); + params["route_id"] = "AC16E7D338B551013FF34266FE81A5EE"; + params["format"] = CRoute4Me::Csv; + params["lat"] = 33.14384; + params["lng"] = -83.22466; + params["course"] = 1; + params["speed"] = 120; + params["device_type"] = CRoute4Me::IPhone; + params["device_guid"] = "TEST_GPS"; + params["device_timestamp"] = "2014-06-14 17:43:35"; + params["member_id"] = 1; + int ret = pRoute->set_gps(params); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY, true); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/GeocoderTest.cpp b/test/GeocoderTest.cpp new file mode 100644 index 0000000..7619ed1 --- /dev/null +++ b/test/GeocoderTest.cpp @@ -0,0 +1,37 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(GeocoderTest, BatchGeocoding) +{ + const char* addrs = "Los20%Angeles20%International20%Airport,20%CA"; + const char* format = "json"; + int ret = pRoute->batch_geocoding(addrs, format); + ASSERT_EQ(0, ret); +} + +TEST(GeocoderTest, ReverseGeocoding) +{ + const char* addrs = "33.945705,-118.391105"; + const char* format = "json"; + int ret = pRoute->reverse_geocoding(addrs, format); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + ::testing::InitGoogleTest(&argc, argv); + + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/NotesTest.cpp b/test/NotesTest.cpp new file mode 100644 index 0000000..89d0530 --- /dev/null +++ b/test/NotesTest.cpp @@ -0,0 +1,29 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; +const char *route_id = "CA902292134DBC134EAF8363426BD247"; +const char *route_destination_id = "174405709A"; + +TEST(NotesTest, GetRouteNotes) +{ + int ret = pRoute->get_route_notes(route_id, route_destination_id); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/OptimizationTest.cpp b/test/OptimizationTest.cpp new file mode 100644 index 0000000..25c3a4f --- /dev/null +++ b/test/OptimizationTest.cpp @@ -0,0 +1,29 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(OptimizationTest, ReOptimize) +{ + const char *id = "c46648541ca5d716a31ffae6f405a37d"; + int ret = pRoute->reoptimize(id); + ASSERT_EQ(0, ret); +} + + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + ::testing::InitGoogleTest(&argc, argv); + + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/OrdersTest.cpp b/test/OrdersTest.cpp new file mode 100644 index 0000000..2a6da38 --- /dev/null +++ b/test/OrdersTest.cpp @@ -0,0 +1,33 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(OrdersTest, GetAllOrders) +{ + int ret = pRoute->get_all_orders(); + ASSERT_EQ(0, ret); +} + +TEST(OrdersTest, GetCustomOrders) +{ + int ret = pRoute->get_custom_orders("order_id,member_id", 0, 100); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/RoutesTest.cpp b/test/RoutesTest.cpp new file mode 100644 index 0000000..2ae6f94 --- /dev/null +++ b/test/RoutesTest.cpp @@ -0,0 +1,68 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; +const char *route_id = "CA902292134DBC134EAF8363426BD247"; + +TEST(RoutesTest, GetByDirections) +{ + int ret = pRoute->get_route_directions(route_id, 1); + ASSERT_EQ(0, ret); +} + +TEST(RoutesTest, GetByPointPath) +{ + int ret = pRoute->get_route_path_points(route_id, "Points"); + ASSERT_EQ(0, ret); +} + +TEST(RoutesTest, GetById) +{ + int ret = pRoute->get_route_by_id(route_id); + ASSERT_EQ(0, ret); +} + +TEST(RoutesTest, GetMultipleRoutes) +{ + int ret = pRoute->get_multiple_routes(); + ASSERT_EQ(0, ret); +} + +TEST(RoutesTest, AddRouteDestinationsInvalidBody) +{ + const char *route_id = "CA902292134DBC134EAF8363426BD247"; + Json::Value addr; + int ret = pRoute->add_route_destinations(route_id, addr); + ASSERT_EQ(-9, ret); + +} + +TEST(RoutesTest, GetRouteManifest) +{ + Json::Value params(Json::objectValue); + params["route_id"] = "AC16E7D338B551013FF34266FE81A5EE"; + params["directions"] = 1; + params["route_path_output"] = CRoute4Me::Points; + params["device_tracking_history"] = 1; + params["limit"] = 10; + params["offset"] = 5; + int ret = pRoute->get_route(params); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/SessionTest.cpp b/test/SessionTest.cpp new file mode 100644 index 0000000..84d3c28 --- /dev/null +++ b/test/SessionTest.cpp @@ -0,0 +1,29 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(SessionTest, Validate) +{ + const char* session_id="4552222222"; + const char* member_id="787544566"; + int ret = pRoute->validate_session(session_id, member_id); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY, true); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/StreetsTest.cpp b/test/StreetsTest.cpp new file mode 100644 index 0000000..4fc0988 --- /dev/null +++ b/test/StreetsTest.cpp @@ -0,0 +1,35 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(StreetsTest, GetAllStreets) +{ + int ret = pRoute->get_all_streets(); + ASSERT_EQ(0, ret); +} + +TEST(StreetsTest, GetOneStreet ) +{ + int seqno = 1; + int ret = pRoute->get_street_address(seqno); + ASSERT_EQ(0, ret); +} + + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/TerritoriesTest.cpp b/test/TerritoriesTest.cpp new file mode 100644 index 0000000..7e8400a --- /dev/null +++ b/test/TerritoriesTest.cpp @@ -0,0 +1,27 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(TerritoriesTest, GetAll) +{ + int ret = pRoute->get_all_territories(); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/TrackingTest.cpp b/test/TrackingTest.cpp new file mode 100644 index 0000000..cbe0291 --- /dev/null +++ b/test/TrackingTest.cpp @@ -0,0 +1,34 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(TrackingTest, AssetTrackingPositive) +{ + const char *id = "Q7G9P1L9"; + int ret = pRoute->asset_tracking(id); + ASSERT_EQ(0, ret); +} + +TEST(TrackingTest, AssetTrackingNegative) +{ + int ret = pRoute->asset_tracking("fake"); + ASSERT_EQ(-9, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + ::testing::InitGoogleTest(&argc, argv); + + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/UsersTest.cpp b/test/UsersTest.cpp new file mode 100644 index 0000000..1aa1993 --- /dev/null +++ b/test/UsersTest.cpp @@ -0,0 +1,27 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(UsersTest, GetUsers) +{ + int ret = pRoute->get_users(); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +} diff --git a/test/VehiclesTest.cpp b/test/VehiclesTest.cpp new file mode 100644 index 0000000..ee79393 --- /dev/null +++ b/test/VehiclesTest.cpp @@ -0,0 +1,27 @@ + +#include +#include + +#define KEY "11111111111111111111111111111111" + +CRoute4Me* pRoute; + +TEST(VehiclesTest, GetAll) +{ + int ret = pRoute->get_vehicles(5, 10); + ASSERT_EQ(0, ret); +} + +int main(int argc, char** argv) +{ + CRoute4Me::init(); + pRoute = new CRoute4Me(KEY, true); + + ::testing::InitGoogleTest(&argc, argv); + RUN_ALL_TESTS(); + + pRoute->cleanup(); + delete pRoute; + + return 0; +}