Skip to content

Commit c097cec

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

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

modules/core/task/tests/task_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,26 @@ 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\", "
220+
"\"tbb\": \"enabled\", \"seq\": \"enabled\"}}";
221+
file.close();
222+
auto result = GetStringTaskType(ppc::core::TypeOfTask::kALL, path);
223+
EXPECT_TRUE(result.find("all") != std::string::npos);
224+
}
225+
226+
// Feed it garbage JSON and watch it crash like it should
227+
TEST(TaskTest, GetStringTaskType_ThrowsOnBadJSON) {
228+
std::string path = "bad_settings.json";
229+
std::ofstream file(path);
230+
file << "{"; // broken trash
231+
file.close();
232+
EXPECT_THROW({ GetStringTaskType(ppc::core::TypeOfTask::kALL, path); }, std::exception);
233+
}
234+
215235
int main(int argc, char **argv) {
216236
testing::InitGoogleTest(&argc, argv);
217237
return RUN_ALL_TESTS();

0 commit comments

Comments
 (0)