Skip to content

Commit e90cbd3

Browse files
committed
add tests for GetStringTaskType to validate behavior with valid and invalid JSON input
1 parent 7cbb1f6 commit e90cbd3

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

modules/core/task/tests/task_tests.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,27 @@ TEST(TaskTest, Destructor_InvalidPipelineOrderTerminates) {
212212
ASSERT_DEATH_IF_SUPPORTED({ test_func(); }, "");
213213
}
214214

215+
// Make sure this sucker writes proper JSON so GetStringTaskType doesn't choke
216+
TEST(TaskTest, GetStringTaskType_UnknownType_ValidJSON) {
217+
std::string path = "settings_valid.json";
218+
std::ofstream file(path);
219+
file << "{\"tasks\": {\"all\": \"enabled\", \"stl\": \"enabled\", \"omp\": \"enabled\", \"mpi\": \"enabled\", \"tbb\": \"enabled\", \"seq\": \"enabled\"}}";
220+
file.close();
221+
auto result = GetStringTaskType(ppc::core::TypeOfTask::kALL, path);
222+
EXPECT_TRUE(result.find("all") != std::string::npos);
223+
}
224+
225+
// Feed it garbage JSON and watch it crash like it should
226+
TEST(TaskTest, GetStringTaskType_ThrowsOnBadJSON) {
227+
std::string path = "bad_settings.json";
228+
std::ofstream file(path);
229+
file << "{"; // broken trash
230+
file.close();
231+
EXPECT_THROW({
232+
GetStringTaskType(ppc::core::TypeOfTask::kALL, path);
233+
}, std::exception);
234+
}
235+
215236
int main(int argc, char **argv) {
216237
testing::InitGoogleTest(&argc, argv);
217238
return RUN_ALL_TESTS();

0 commit comments

Comments
 (0)