mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-29 22:40:06 +00:00 
			
		
		
		
	Add map provider layer test
This commit is contained in:
		
							parent
							
								
									3d3318a032
								
							
						
					
					
						commit
						9c27b2cd29
					
				
					 6 changed files with 196 additions and 2 deletions
				
			
		
							
								
								
									
										3
									
								
								.github/workflows/ci.yml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.github/workflows/ci.yml
									
										
									
									
										vendored
									
									
								
							|  | @ -191,4 +191,7 @@ jobs: | |||
| 
 | ||||
|     - name: Test Supercell Wx | ||||
|       working-directory: ${{ github.workspace }}/build | ||||
|       env: | ||||
|         MAPBOX_API_KEY:   ${{ secrets.MAPBOX_API_KEY }} | ||||
|         MAPTILER_API_KEY: ${{ secrets.MAPTILER_API_KEY }} | ||||
|       run: ctest -C ${{ matrix.build_type }} --exclude-regex mbgl-test-runner | ||||
|  |  | |||
|  | @ -8,7 +8,7 @@ class SupercellWxConan(ConanFile): | |||
|                   "geographiclib/1.52", | ||||
|                   "glew/2.2.0", | ||||
|                   "glm/cci.20220420", | ||||
|                   "gtest/cci.20210126", | ||||
|                   "gtest/1.13.0", | ||||
|                   "libcurl/7.86.0", | ||||
|                   "libxml2/2.10.3", | ||||
|                   "openssl/3.1.0", | ||||
|  |  | |||
							
								
								
									
										153
									
								
								test/source/scwx/qt/map/map_provider.test.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								test/source/scwx/qt/map/map_provider.test.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,153 @@ | |||
| #include <scwx/qt/map/map_provider.hpp> | ||||
| #include <scwx/util/environment.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <regex> | ||||
| 
 | ||||
| #include <QCoreApplication> | ||||
| #include <QMapLibreGL/QMapLibreGL> | ||||
| #include <QTimer> | ||||
| 
 | ||||
| #include <gtest/gtest.h> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace map | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ {"scwx::qt::map::map_provider.test"}; | ||||
| static const auto        logger_ = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| class ByMapProviderTest : | ||||
|     public testing::TestWithParam<std::pair<MapProvider, std::string>> | ||||
| { | ||||
| }; | ||||
| 
 | ||||
| TEST_P(ByMapProviderTest, MapProviderLayers) | ||||
| { | ||||
|    auto& [mapProvider, apiKeyName] = GetParam(); | ||||
| 
 | ||||
|    // Configure API key
 | ||||
|    std::string apiKey = scwx::util::GetEnvironment(apiKeyName); | ||||
|    if (apiKey.empty()) | ||||
|    { | ||||
|       logger_->info("API key not set, skipping test"); | ||||
|       EXPECT_EQ(true, true); | ||||
|       return; | ||||
|    } | ||||
| 
 | ||||
|    // Setup QCoreApplication
 | ||||
|    int              argc   = 1; | ||||
|    const char*      argv[] = {"arg", nullptr}; | ||||
|    QCoreApplication application(argc, const_cast<char**>(argv)); | ||||
| 
 | ||||
|    // Configure map provider
 | ||||
|    const MapProviderInfo& mapProviderInfo = GetMapProviderInfo(mapProvider); | ||||
| 
 | ||||
|    // Configure QMapLibreGL
 | ||||
|    QMapLibreGL::Settings mapSettings {}; | ||||
|    mapSettings.resetToTemplate(mapProviderInfo.settingsTemplate_); | ||||
|    mapSettings.setApiKey(QString::fromStdString(apiKey)); | ||||
| 
 | ||||
|    QMapLibreGL::Map map(nullptr, mapSettings, QSize(1, 1)); | ||||
|    application.processEvents(); | ||||
| 
 | ||||
|    // Connect style load completion signal
 | ||||
|    QObject::connect( | ||||
|       &map, | ||||
|       &QMapLibreGL::Map::mapChanged, | ||||
|       [&](QMapLibreGL::Map::MapChange mapChange) | ||||
|       { | ||||
|          if (mapChange == | ||||
|              QMapLibreGL::Map::MapChange::MapChangeDidFinishLoadingStyle) | ||||
|          { | ||||
|             application.exit(); | ||||
|          } | ||||
|       }); | ||||
| 
 | ||||
|    // Connect timeout timer
 | ||||
|    bool   timeout = false; | ||||
|    QTimer timeoutTimer {}; | ||||
|    timeoutTimer.setSingleShot(true); | ||||
|    QObject::connect(&timeoutTimer, | ||||
|                     &QTimer::timeout, | ||||
|                     [&]() | ||||
|                     { | ||||
|                        // Reached timeout
 | ||||
|                        logger_->warn("Timed out waiting for style change"); | ||||
|                        timeout = true; | ||||
| 
 | ||||
|                        application.exit(); | ||||
|                     }); | ||||
| 
 | ||||
|    // Iterate through each style
 | ||||
|    for (const auto& mapStyle : mapProviderInfo.mapStyles_) | ||||
|    { | ||||
|       using namespace std::chrono_literals; | ||||
| 
 | ||||
|       // Load style
 | ||||
|       timeout = false; | ||||
|       map.setStyleUrl(QString::fromStdString(mapStyle.url_)); | ||||
|       timeoutTimer.start(5000ms); | ||||
|       application.exec(); | ||||
|       timeoutTimer.stop(); | ||||
| 
 | ||||
|       // Check result
 | ||||
|       if (!timeout) | ||||
|       { | ||||
|          // Print layer names for debug
 | ||||
|          std::string layerIdsString = map.layerIds().join(", ").toStdString(); | ||||
|          logger_->debug("{} Layers: [{}]", mapStyle.name_, layerIdsString); | ||||
| 
 | ||||
|          // Search layer list
 | ||||
|          bool foundMatch = false; | ||||
|          for (const QString& qlayer : map.layerIds()) | ||||
|          { | ||||
|             const std::string layer = qlayer.toStdString(); | ||||
| 
 | ||||
|             // Draw below layers defined in map style
 | ||||
|             auto it = std::find_if( | ||||
|                mapStyle.drawBelow_.cbegin(), | ||||
|                mapStyle.drawBelow_.cend(), | ||||
|                [&layer](const std::string& styleLayer) -> bool | ||||
|                { | ||||
|                   std::regex re {styleLayer, std::regex_constants::icase}; | ||||
|                   return std::regex_match(layer, re); | ||||
|                }); | ||||
| 
 | ||||
|             if (it != mapStyle.drawBelow_.cend()) | ||||
|             { | ||||
|                foundMatch = true; | ||||
|                break; | ||||
|             } | ||||
|          } | ||||
| 
 | ||||
|          // Check match
 | ||||
|          EXPECT_EQ(foundMatch, true); | ||||
| 
 | ||||
|          if (!foundMatch) | ||||
|          { | ||||
|             logger_->error("Could not find drawBelow in style {}", | ||||
|                            mapStyle.name_); | ||||
|          } | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|          EXPECT_EQ(timeout, false); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    EXPECT_EQ(false, false); | ||||
| } | ||||
| 
 | ||||
| INSTANTIATE_TEST_SUITE_P( | ||||
|    MapProviderTest, | ||||
|    ByMapProviderTest, | ||||
|    testing::Values(std::make_pair(MapProvider::Mapbox, "MAPBOX_API_KEY"), | ||||
|                    std::make_pair(MapProvider::MapTiler, "MAPTILER_API_KEY"))); | ||||
| 
 | ||||
| } // namespace map
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  | @ -23,6 +23,7 @@ set(SRC_QT_CONFIG_TESTS source/scwx/qt/config/county_database.test.cpp | |||
|                         source/scwx/qt/config/radar_site.test.cpp) | ||||
| set(SRC_QT_MANAGER_TESTS source/scwx/qt/manager/settings_manager.test.cpp | ||||
|                          source/scwx/qt/manager/update_manager.test.cpp) | ||||
| set(SRC_QT_MAP_TESTS source/scwx/qt/map/map_provider.test.cpp) | ||||
| set(SRC_QT_MODEL_TESTS source/scwx/qt/model/imgui_context_model.test.cpp) | ||||
| set(SRC_QT_SETTINGS_TESTS source/scwx/qt/settings/settings_container.test.cpp | ||||
|                           source/scwx/qt/settings/settings_variable.test.cpp) | ||||
|  | @ -44,6 +45,7 @@ add_executable(wxtest ${SRC_MAIN} | |||
|                       ${SRC_PROVIDER_TESTS} | ||||
|                       ${SRC_QT_CONFIG_TESTS} | ||||
|                       ${SRC_QT_MANAGER_TESTS} | ||||
|                       ${SRC_QT_MAP_TESTS} | ||||
|                       ${SRC_QT_MODEL_TESTS} | ||||
|                       ${SRC_QT_SETTINGS_TESTS} | ||||
|                       ${SRC_QT_UTIL_TESTS} | ||||
|  | @ -58,6 +60,7 @@ source_group("Source Files\\network"      FILES ${SRC_NETWORK_TESTS}) | |||
| source_group("Source Files\\provider"     FILES ${SRC_PROVIDER_TESTS}) | ||||
| source_group("Source Files\\qt\\config"   FILES ${SRC_QT_CONFIG_TESTS}) | ||||
| source_group("Source Files\\qt\\manager"  FILES ${SRC_QT_MANAGER_TESTS}) | ||||
| source_group("Source Files\\qt\\map"      FILES ${SRC_QT_MAP_TESTS}) | ||||
| source_group("Source Files\\qt\\model"    FILES ${SRC_QT_MODEL_TESTS}) | ||||
| source_group("Source Files\\qt\\settings" FILES ${SRC_QT_SETTINGS_TESTS}) | ||||
| source_group("Source Files\\qt\\util"     FILES ${SRC_QT_UTIL_TESTS}) | ||||
|  |  | |||
|  | @ -7,7 +7,8 @@ namespace scwx | |||
| namespace util | ||||
| { | ||||
| 
 | ||||
| void SetEnvironment(const std::string& name, const std::string& value); | ||||
| std::string GetEnvironment(const std::string& name); | ||||
| void        SetEnvironment(const std::string& name, const std::string& value); | ||||
| 
 | ||||
| } // namespace util
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -13,6 +13,40 @@ namespace util | |||
| static const std::string logPrefix_ {"scwx::util::environment"}; | ||||
| static const auto        logger_ = util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| std::string GetEnvironment(const std::string& name) | ||||
| { | ||||
|    std::string value {}; | ||||
| 
 | ||||
| #ifdef _WIN32 | ||||
|    std::size_t       requiredSize; | ||||
|    std::vector<char> data {}; | ||||
| 
 | ||||
|    // Determine environment variable size
 | ||||
|    getenv_s(&requiredSize, nullptr, 0, name.c_str()); | ||||
|    if (requiredSize == 0) | ||||
|    { | ||||
|       // Environment variable is not set
 | ||||
|       return value; | ||||
|    } | ||||
| 
 | ||||
|    // Request environment variable
 | ||||
|    data.resize(requiredSize); | ||||
|    getenv_s(&requiredSize, data.data(), requiredSize, name.c_str()); | ||||
| 
 | ||||
|    // Store environment variable
 | ||||
|    value = data.data(); | ||||
| #else | ||||
|    const char* data = getenv(name.c_str()); | ||||
| 
 | ||||
|    if (data != nullptr) | ||||
|    { | ||||
|       value = data; | ||||
|    } | ||||
| #endif | ||||
| 
 | ||||
|    return value; | ||||
| } | ||||
| 
 | ||||
| void SetEnvironment(const std::string& name, const std::string& value) | ||||
| { | ||||
| #ifdef _WIN32 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat