mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 09:00:04 +00:00 
			
		
		
		
	Settings manager test
This commit is contained in:
		
							parent
							
								
									1c0140fc98
								
							
						
					
					
						commit
						fd0a148d3e
					
				
					 4 changed files with 113 additions and 4 deletions
				
			
		
							
								
								
									
										97
									
								
								test/source/scwx/qt/manager/settings_manager.test.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								test/source/scwx/qt/manager/settings_manager.test.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,97 @@ | |||
| #include <scwx/qt/manager/settings_manager.hpp> | ||||
| 
 | ||||
| #include <filesystem> | ||||
| #include <fstream> | ||||
| 
 | ||||
| #include <gtest/gtest.h> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace manager | ||||
| { | ||||
| 
 | ||||
| static const std::string DEFAULT_SETTINGS_FILE = | ||||
|    std::string(SCWX_TEST_DATA_DIR) + "/json/settings/settings-default.json"; | ||||
| static const std::string TEMP_SETTINGS_FILE = | ||||
|    std::string(SCWX_TEST_DATA_DIR) + "/json/settings/settings-temp.json"; | ||||
| 
 | ||||
| class DefaultSettingsTest : public testing::TestWithParam<std::string> | ||||
| { | ||||
| }; | ||||
| 
 | ||||
| void VerifyDefaults() | ||||
| { | ||||
|    std::shared_ptr<settings::GeneralSettings> defaultGeneralSettings = | ||||
|       settings::GeneralSettings::Create(); | ||||
| 
 | ||||
|    EXPECT_EQ(*defaultGeneralSettings, *SettingsManager::general_settings()); | ||||
| } | ||||
| 
 | ||||
| void CompareFiles(const std::string& file1, const std::string& file2) | ||||
| { | ||||
|    std::ifstream     ifs1 {file1}; | ||||
|    std::stringstream buffer1; | ||||
|    buffer1 << buffer1.rdbuf(); | ||||
| 
 | ||||
|    std::ifstream     ifs2 {file2}; | ||||
|    std::stringstream buffer2; | ||||
|    buffer2 << buffer2.rdbuf(); | ||||
| 
 | ||||
|    EXPECT_EQ(buffer1.str(), buffer2.str()); | ||||
| } | ||||
| 
 | ||||
| TEST(SettingsManager, CreateJson) | ||||
| { | ||||
|    std::string filename {TEMP_SETTINGS_FILE}; | ||||
| 
 | ||||
|    // Verify file doesn't exist prior to test start
 | ||||
|    EXPECT_EQ(std::filesystem::exists(filename), false); | ||||
| 
 | ||||
|    SettingsManager::ReadSettings(filename); | ||||
| 
 | ||||
|    EXPECT_EQ(std::filesystem::exists(filename), true); | ||||
| 
 | ||||
|    VerifyDefaults(); | ||||
|    CompareFiles(filename, DEFAULT_SETTINGS_FILE); | ||||
| 
 | ||||
|    std::filesystem::remove(filename); | ||||
|    EXPECT_EQ(std::filesystem::exists(filename), false); | ||||
| } | ||||
| 
 | ||||
| TEST(SettingsManager, SettingsKeax) | ||||
| { | ||||
|    std::string filename(std::string(SCWX_TEST_DATA_DIR) + | ||||
|                         "/json/settings/settings-keax.json"); | ||||
| 
 | ||||
|    SettingsManager::ReadSettings(filename); | ||||
| 
 | ||||
|    EXPECT_EQ(SettingsManager::general_settings()->default_radar_site(), "KEAX"); | ||||
| } | ||||
| 
 | ||||
| TEST_P(DefaultSettingsTest, DefaultSettings) | ||||
| { | ||||
|    std::string sourceFile(std::string(SCWX_TEST_DATA_DIR) + "/json/settings/" + | ||||
|                           GetParam()); | ||||
|    std::string filename {TEMP_SETTINGS_FILE}; | ||||
| 
 | ||||
|    std::filesystem::copy_file(sourceFile, filename); | ||||
| 
 | ||||
|    SettingsManager::ReadSettings(filename); | ||||
| 
 | ||||
|    VerifyDefaults(); | ||||
|    CompareFiles(filename, DEFAULT_SETTINGS_FILE); | ||||
| 
 | ||||
|    std::filesystem::remove(filename); | ||||
| } | ||||
| 
 | ||||
| INSTANTIATE_TEST_SUITE_P(SettingsManager, | ||||
|                          DefaultSettingsTest, | ||||
|                          testing::Values("settings-bad-types.json", | ||||
|                                          "settings-empty-groups.json", | ||||
|                                          "settings-empty-object.json")); | ||||
| 
 | ||||
| } // namespace manager
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  | @ -9,19 +9,22 @@ find_package(GTest) | |||
| 
 | ||||
| set(SRC_MAIN source/scwx/wxtest.cpp) | ||||
| set(SRC_COMMON_TESTS source/scwx/common/color_table.test.cpp) | ||||
| set(SRC_QT_MANAGER_TESTS source/scwx/qt/manager/settings_manager.test.cpp) | ||||
| set(SRC_UTIL_TESTS source/scwx/util/rangebuf.test.cpp | ||||
|                    source/scwx/util/vectorbuf.test.cpp) | ||||
| set(SRC_WSR88D_TESTS source/scwx/wsr88d/ar2v_file.test.cpp) | ||||
| 
 | ||||
| add_executable(wxtest ${SRC_MAIN} | ||||
|                       ${SRC_COMMON_TESTS} | ||||
|                       ${SRC_QT_MANAGER_TESTS} | ||||
|                       ${SRC_UTIL_TESTS} | ||||
|                       ${SRC_WSR88D_TESTS}) | ||||
| 
 | ||||
| source_group("Source Files\\main"   FILES ${SRC_MAIN}) | ||||
| source_group("Source Files\\common" FILES ${SRC_COMMON_TESTS}) | ||||
| source_group("Source Files\\util"   FILES ${SRC_UTIL_TESTS}) | ||||
| source_group("Source Files\\wsr88d" FILES ${SRC_WSR88D_TESTS}) | ||||
| source_group("Source Files\\main"        FILES ${SRC_MAIN}) | ||||
| source_group("Source Files\\common"      FILES ${SRC_COMMON_TESTS}) | ||||
| source_group("Source Files\\qt\\manager" FILES ${SRC_QT_MANAGER_TESTS}) | ||||
| source_group("Source Files\\util"        FILES ${SRC_UTIL_TESTS}) | ||||
| source_group("Source Files\\wsr88d"      FILES ${SRC_WSR88D_TESTS}) | ||||
| 
 | ||||
| target_include_directories(wxtest PRIVATE ${GTest_INCLUDE_DIRS}) | ||||
| 
 | ||||
|  | @ -38,4 +41,5 @@ target_compile_definitions(wxtest PRIVATE SCWX_TEST_DATA_DIR="${SCWX_DIR}/test/d | |||
| gtest_discover_tests(wxtest) | ||||
| 
 | ||||
| target_link_libraries(wxtest GTest::gtest | ||||
|                              scwx-qt | ||||
|                              wxdata) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat