-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ANT-1890] Properly handle playlist_reset in generaldata.ini (#879)
Fix #864 Properly handle data and avoid exception thrown when reading not numerical values with stoi when reading "playlist_reset" entry in general_data.ini --------- Co-authored-by: Florian Omnès <[email protected]>
- Loading branch information
1 parent
6619f9f
commit caf2805
Showing
4 changed files
with
86 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "GeneralDataReader.h" | ||
|
||
//Test for the GeneralDataIniReader class | ||
class GeneralDataIniReaderTests : public testing::TestWithParam<bool> { | ||
public: | ||
GeneralDataIniReaderTests() = default; | ||
~GeneralDataIniReaderTests() override = default; | ||
}; | ||
|
||
INSTANTIATE_TEST_SUITE_P(reset_value, GeneralDataIniReaderTests, | ||
testing::Bool()); | ||
TEST_P(GeneralDataIniReaderTests, ReadPlaylistReset_option) { | ||
auto test_dir = std::filesystem::temp_directory_path() / std::tmpnam(nullptr); | ||
std::filesystem::create_directory(test_dir); | ||
auto ini_file = test_dir / "test.ini"; | ||
std::ofstream file(ini_file); | ||
file << "[general]\n" | ||
"nbyears=10\n" | ||
"user-playlist=true\n" | ||
"[playlist]\n" | ||
"playlist_reset = "; | ||
file << (GetParam() ? "true\n" : "false\n"); | ||
file << "playlist_year += 0\n" | ||
"playlist_year += 5\n" | ||
"playlist_year += 8\n" | ||
"playlist_year -= 1\n" | ||
"playlist_year -= 2\n" | ||
"playlist_year -= 3\n"; | ||
file.close(); | ||
|
||
GeneralDataIniReader reader(ini_file, nullptr); | ||
//GetActiveYears() returns the active years whereas file contains index. year=index+1 | ||
//reset = false => Active playlist (+=) | ||
//rest = true => !inactive playlist (-=) | ||
if (GetParam()) { | ||
EXPECT_EQ(reader.GetActiveYears(), std::vector<int>({1, 5, 6, 7, 8, 9, 10})); | ||
} else { | ||
EXPECT_EQ(reader.GetActiveYears(), std::vector<int>({1, 6, 9})); | ||
} | ||
} |